모듈:Category

최근 편집: 2016년 12월 16일 (금) 01:49
낙엽1124 (토론 | 기여)님의 2016년 12월 16일 (금) 01:49 판 (의도하지 않은 동작)

알려진 문제

순환 참조가 발생했을 시 ?action=edit으로 내용을 변경하기 전까지 문서 로딩이 되지 않습니다.


local p = {}

local function argumentCount(frame) --frame.args의 원수 수를 세어서 반환하는 함수, --더 쉬운 방법이 있다면 알려주세요.
	local count = 0
	for i,v in frame:argumentPairs() do
		count = count+1
	end
	return count
end

function p.category(frame) 
	local argc = argumentCount(frame)
	if argc % 2 ~= 0 then return "매개변수가 짝이 맞지 않습니다." end

	local text = ""
	if (mw.title.getCurrentTitle().text ~= frame.args[1] .. "/" .. frame.args[2]) then
		text = text .. "[[분류:" .. frame.args[1] .. "/" .. frame.args[2] .. "]]"
	end

	for i=1,(argc-2)/2 do
		if mw.title.new("틀:" .. frame.args[(i*2)+1] .. "/" .. frame.args[(i*2)+2] .. " 분류").exists then
			text = text .. frame:expandTemplate{ title = frame.args[(i*2)+1] .. "/" .. frame.args[(i*2)+2] .. " 분류"}
		else
			text = text .. "[[분류:" .. frame.args[(i*2)+1] .. "/" .. frame.args[(i*2)+2] .. "|".. frame.args[(i*2)+2] .."]]"
		end
	end

	return text
end

function p.document(frame)
	local argc = argumentCount(frame)
	if argc % 2 ~= 0 then return "매개변수가 짝이 맞지 않습니다." end

	local text = ""

	text = text .. "* [[:분류:" .. frame.args[1] .. "/" .. frame.args[2] .. "]]\n"
	for i=1,(argc-2)/2 do
		text = text .. "* [[:분류:" .. frame.args[(i*2)+1] .. "/" .. frame.args[(i*2)+2] .. "]]\n"
	end

	return text
end

return p