モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

使用法 編集

  • {{#invoke:Main|main}}

local p = {}

function p.error( message1 )
	return '<strong class="error">エラー:' ..message1 ..'</strong>'
end

function p.rellink( message2 )
	return '<div class="rellink" style="margin-bottom: 0.5em; padding-left: 2em; font-style: italic;">' ..message2 ..'</div>'
end

function p.main( frame )
	local args = require( 'Module:Arguments' ).getArgs( frame, {parentOnly = true} )

	local split = mw.text.split( frame:getParent():getTitle(), ':' )
	local header = '詳細は'
	local footer = 'を'

	if split[2] == 'See' or split[2] == 'See/sandbox' then
		header = ''
	elseif split[2] == 'See also' or split[2] == 'See also/sandbox' then
		header = ''
		footer = 'も'
	end

-- エラー判定
	if args[1] == nil then
		return p.rellink(p.error('記事名が入力されていません'))
	end

-- 使用変数初期化
	local new_args = {}
	local text = ''
	local max = 1
	local isValidPageName = require( 'Module:IsValidPageName' ).isValidPageName
	local temp = ''

-- ここからループ処理
	-- 入力記事名の有無判定 / 最大入力記事数
	for i = 1, 15 do
		if args[i] == nil then
			break
		end

		temp = 'l' ..i
		if isValidPageName( { args = { args[i] } } ) == 'valid' then
			if args[temp] ~= nil then
				new_args[i] = '「[[' ..args[i] ..'|'..args[temp] ..']]」'
			else
				new_args[i] = '「[[' ..args[i] ..']]」'
			end
		else
			new_args[i] = '「' ..args[i] ..'」'
		end
		max = i
	end

	-- 入力記事数が1つのみならそのまま、そうでなければ各記事名末尾に「、」、最終記事名の直前に「および」を付記
	if max == 1 then
		text = text ..new_args[1]
	else
		for i = 1, max -1 do
			text = text ..new_args[i] ..'、'
		end
		text = text ..'および' ..new_args[max]
	end

	-- 記事名入力が15個以上あった場合のエラー判定
	temp = args[16] or '';
	if temp ~= '' then
		text = text ..'…' ..p.error('最大15記事までです。')
	end

	return p.rellink(header ..text ..footer ..'参照')
end

return p