モジュール:サンドボックス/Vcvfou698069/202210c

モジュールの解説[作成]
require('strict')

-- {{Tlp}}の簡易版
local function tlp1(name, arg)
	arg = (arg == nil or arg == '') and '' or '|' .. arg
	return mw.ustring.format('{{[[Template:%s|%s]]%s}}', name, name, arg)
end

return {
	main = function(frame)
		local wrapper = mw.title.new('Template:廃止されたテンプレート')
		local getArgs = require('モジュール:Arguments').getArgs
		local args =getArgs(frame, { wrappers = wrapper.prefixedText })
		
		-- 第1引数が空であればエラーメッセージを出力し、関数を抜ける
		if not args[1] then
			return tostring(
				mw.html.create('div')
					:addClass('error')
					:wikitext(tlp1(wrapper.text) .. 'の第1引数が指定されていません。')
			)
			.. '[[Category:廃止されたテンプレート/作業用 (引数なし)]]'
		end
		
		local current = mw.title.getCurrentTitle()
		local yesno = require('モジュール:Yesno')
		local demo = args['demospace'] or yesno(args['demo'])
		local quiet = yesno(args['quiet'])
		local doing = yesno(args['doing']) or yesno(args['移行中'])
		local old_template = mw.title.new(args[1], 'Template')
		
		-- 表示中のページが廃止対象のテンプレートでない場合
		if not mw.title.equals(current, old_template) then
			if quiet then
				-- quietが真なら何も表示しない
				return ''
			end
			local alt = ''
			if args[2] then
				alt = mw.ustring.format('代わりに %s を使用してください。',
					tlp1(args[2], args['arg'])
					)
			end
			local warning_text = mw.ustring.format(
				'警告:テンプレート %s は%s[[Wikipedia:テンプレート・'
				.. 'モジュール作成の目安#廃止・削除|廃止]]%s%s',
				tlp1(args[1]),
				doing and '将来的に' or '',
				doing and 'される予定です。' or 'されました。',
				alt
				)
			mw.addWarning(
				tostring(
					mw.html.create('span')
						:addClass('error')
						:css('font-size','inherit')
						:css('font-weight', 'bold')
						:wikitext(warning_text)
				)
			)
			return doing and '' or '[[Category:廃止されたテンプレートを使用中のページ]]'
		end
		
		local discussion = args['議論ページ']
		if discussion then
			-- 内部リンクにする
			if not mw.ustring.match(discussion, '^%[%[.+%]%]') then
				discussion = '[[' .. discussion .. ']]'
			end
		end
		
		local box_params = { type = 'delete' }
		local alt = '今後新たに使用しないでください。'
		if args[2] then
			alt = mw.ustring.format(
				doing and '現在、 %s への移行作業が行われています。'
					or '代わりに %s を使用してください。',
				tlp1(args[2], args['arg'])
				)
		end
		box_params.text = mw.ustring.format(
			'このテンプレート %s は%s%s[[Wikipedia:テンプレート・モジュール作成の目安#'
				.. '廃止・削除|廃止]]%s%s<small>(このテンプレートの[[特別:リンク元/'
				.. '%s|リンク元]]・[%s  呼び出し元])</small>',
			tlp1(args[1]),
			discussion and '、' .. discussion .. 'での議論を受けて' or '',
			doing and '将来的に' or '',
			doing and 'される予定です。' or 'されました。',
			alt,
			current.prefixedText,
			tostring(mw.uri.fullUrl('特別:リンク元/' .. current.prefixedText,
					'hideredirs=1&hidelinks=1'
					)
				)
			)
		box_params.image = mw.ustring.format('[[File:%s|40px]]',
			doing and 'Nuvola apps important.svg' or 'Dialog-error-round.svg'
			)
		
		local cat = ''
		
		-- ラッパーテンプレートおよびそのサブページ、またはデモ表示の場合には
		-- カテゴリを追加しない
		if current.baseText ~= wrapper.text and not demo then
			if doing then
				cat = '[[Category:移行中のテンプレート|' .. current.text .. ']]'
			else
				cat = '[[Category:廃止されたテンプレート|' .. current.text .. ']]'
				if args[2] then
					cat = cat
						.. '[[Category:移行先のあるテンプレート|'
						.. current.text
						.. ']]'
				end
			end
		end
		
		return require('モジュール:Message box').main('ombox', box_params)
			.. cat
			.. '__NOINDEX__'
	end
}