Dokumentado por ĉi tiu modulo povas esti kreata ĉe Modulo:Forigo/dokumentado

--[[ Modulo:Forigo, version 2014-08-11
A module for the template {{Propono de forigo}}
--]]

local p = {}
local limit = 10

function p._request (requests, args)
	local away = args["forigita"]
	local timer = args["tempo"]
	local longer = args["forigitade"]
	
	-- div with formats
	local divbegin = "<div class=\"toccolours itwiki_template_avviso\" style=\"background:"
	if away ~= "" and away ~= nil then
		if away == "jes" or away == "for" or away == "forigita" or away == "farita" then color ="lightgreen"
		elseif away == "ne" or away == "ne farita" or away == "nefarita" or away == "ne forigita" or away == "neforigita" then color = "lightcoral"	
		elseif away == "atendante" or away == "atendas" or away == "komentoj" then color = "lightblue"
		else color ="white"	
		end
	else color = "white"	
	end
	divbegin = divbegin .. color .. "\">"
	local divend = "</div>"	
	
	-- the function works on parameters about articles
	local art = {}
	local count = 1
	-- removes the strange behavior, that "aliaartikolo" appears in the list before ""artikolo"
	if args["aliaartikolo"] ~= "" and args["aliaartikolo"] ~= nil then
		args["alia artikolo"] = args["aliaartikolo"]
		args["aliaartikolo"] = nil
	-- corrects the limit			
		limit = limit + 1
	elseif (args["alia artikolo"] ~= "" and args["alia artikolo"] ~= nil) 
	or (args["aliakialo"] ~= "" and args["aliakialo"] ~= nil) 
	or (args["alia kialo"] ~= "" and args["alia kialo"] ~= nil) then 
		limit = limit + 1
	end
	-- copies the named parameters "artikolo1" till "artikolo10" into "art[1]" till "art[10]"
	for name, value in pairs(args) do
		local article = "artikolo"
		local firstLetters = mw.ustring.sub(name, 1, 8)
		local lastLetters = mw.ustring.sub(name, -8, -1)
		if firstLetters == article or lastLetters == article and value ~= nil and value ~= "" and count <= limit then
			art[count] = value	
			count = count + 1
		end
	end
	local numberArticles = #art -- count
	if numberArticles < 1 then
    	return divbegin .. "<strong class=\"error\">Vi ne difinis iun parametron pri artikolo!</strong>" .. divend
	end
	local art_text = "Artikolo"
	-- the function works on parameters about reasons  
	local reason = {}
	local n = {}
	local count = 1
	-- copies the named parameters "kialo1" till "kialo10" into "reason[1]" till "reason[10]"
	for name, value in pairs(args) do
		local reason2 = "kialo"
		local firstLetters = mw.ustring.sub(name, 1, 5)
		local lastLetters = mw.ustring.sub(name, -5, -1)
		local reason_result = mw.ustring.sub(name,-11,-1)
		local rr = " de rezulto"
		if firstLetters == reason2 and reason_result ~= rr or lastLetters == reason2 and value ~= nil and value ~= "" and count <= limit then
			reason[count] = value
			count = count + 1
		end
	end
	local numberReasons = #reason --count
	if numberReasons < 1 then
    	return divbegin .. "<strong class=\"error\">Vi ne difinis iun parametron pri kialo!</strong>" .. divend
	end
--	local other_reason = args["aliakialo"]
	local signature = args["subskribo"]
	local reason_text = "Kialo"
	local user_text = "Uzanto"
	local articles = ""
	local reasons = ""
	local user = ""
	local result = "Rezulto"
	local result_reason = args["kialo de rezulto"]

	if art[2] ~= "" and art[2] ~= nil then
		plural = "j"
	else plural = ""	
	end	
	
	-- second div with formats, for the time mesage
	if timer ~= "" and timer ~= nil then
		if longer == "" or longer == nil then
			div2 = "<div style=\"float:right\">Se pri forigo konsentis la plej multaj kundiskutantoj post la prezento de la argumentoj por kaj kontraŭ, la artikolo" .. plural .. " estos forigita je '''" .. timer .. "'''</div>"
		else div2 = ""	
		end
	else div2 = ""	
	end
	
	-- texts about the articles
--	articles = "\n;" .. art_text .. plural .. " : <span class=\"plainlinks\">[[:" .. art[1] .."]]"
--	articles = articles .. " <small>([{{fullurl:" .. art[1] .."|action=history}} kronologio] · [[Specialaĵo:Kio ligas ĉi tien?/" .. art[1] .. "|ĉi tien]] · [{{fullurl:" .. art[1] .. "|action=delete}} forigu])</small>"
	articles = "\n;" .. art_text .. plural .. " : <span class=\"plainlinks\">"
	for i, a in ipairs(art) do
		if i ~= 1 then
			articles = articles .. "<br />"
		end
		articles = articles .. "[[:" .. art[i] .. "]]" 
		local title=mw.title.new(art[i])
		articles = articles .. " <small>([" .. tostring(mw.uri.fullUrl(title.prefixedText, "action=history")) .. " kronologio] · [[Specialaĵo:Kio ligas ĉi tien?/" .. art[i] .. "|ĉi tien]] · [" .. tostring(mw.uri.fullUrl(title.prefixedText, "action=delete")) .. " forigu])</small>"
	end

	articles = articles .. "</span>"
	
	-- texts about the reasons
	reasons = "\n;" .. reason_text .. " : "
	if reason[2] ~= "" and reason[2] ~= nil then
	--	reasons = reasons .. "\n:*" .. reason[1] .. "\n:*" .. reason[2]
		for i, r in ipairs(reason) do
		    reasons = reasons .. "\n:*" .. reason[i] 
		end
	else
		reasons = reasons .. reason[1]
	end
	
	-- texts about the user
	if signature == "" or signature == nil then
		return divbegin .. "<strong class=\"error\">Vi ne subskribis!</strong> <br />Por fari tion, sufiĉas aldoni: <nowiki>--~~~~</nowiki> aŭ <nowiki>~~~~</nowiki> al la parametro ''subskribo''." .. divend		
	end
	user = "\n;" .. user_text .. " : " .. signature
	
	-- texts about the result
	if away ~= "" and away ~= nil then
	    result = "\n;" .. result .. " : " 
	    if away == "neforigita" or away == "ne forigita" or away == "ne farita" or away == "nefarita" or away == "ne" then 
	    	result = result .. "[[Dosiero:Red x.svg|16px|Ne farita]]&nbsp;'''Ne forigita'''"
	    elseif away == "atendante" or away == "atendas" or away == "komentoj" then
	    	result = result .. "[[Dosiero:Pictogram voting wait.svg|16px|Atendante pliajn komentojn]]&nbsp;'''Atendante pliajn komentojn'''"
	    elseif away == "jes" or away == "forigita" or away == "farita" then
	    	result = result .. "[[Dosiero:Yes check.svg|16px|Farita]]&nbsp;'''Forigita'''"
	    else result = result .. away	
	    end
	    if result_reason ~= "" and result_reason ~= nil then
	    	result = result .. "\n:" .. result_reason
	    end
	else result = ""    
	end
	
	return divbegin .. "\n" .. div2 .. "\n" .. articles .. reasons .. user .. result .. "\n" .. divend .. "\n"
	
end


local function processRequestArgs(args)
	-- This function processes a table of arguments and returns two tables: an array of requests names for processing by ipairs, and a table of
	-- the named arguments that specify style options, etc. We need to use ipairs because we want to list all the portals in the order
	-- they were passed to the template, but we also want to be able to deal with positional arguments passed explicitly, for example
	-- {{portal|2=Politics}}. The behaviour of ipairs is undefined if nil values are present, so we need to make sure they are all removed.
	args = type(args) == 'table' and args or {}
	local requests = {}
	local namedArgs = {}
	for k, v in pairs(args) do
		if type(k) == 'number' and type(v) == 'string' then -- Make sure we have no non-string requests names.
			table.insert(requests, k)
		elseif type(k) ~= 'number' then
			namedArgs[k] = v
		end
	end
	table.sort(requests)
	for i, v in ipairs(requests) do
		requests[i] = args[v]
	end
	return requests, namedArgs
end
 
local function makeWrapper(funcName)
	-- Processes external arguments and sends them to the alia functions.
	return function (frame)
		-- If called via #invoke, use the args passed into the invoking
		-- template, or the args passed to #invoke if any exist. Otherwise
		-- assume args are being passed directly in from the debug console
		-- or from another Lua modulo.
		local origArgs
		if frame == mw.getCurrentFrame() then
			origArgs = frame:getParent().args
			for k, v in pairs(frame.args) do
				origArgs = frame.args
				break
			end
		else
			origArgs = frame
		end
		-- Trim whitespace and remove blank arguments.
		local args = {}
		for k, v in pairs(origArgs) do
			if type(v) == 'string' then
				v = mw.text.trim(v)
			end
			if v ~= '' then
				args[k] = v
			end
		end
		return p[funcName](processRequestArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.
	end
end
 
local funcNames = {'request'}
 
for _, funcName in ipairs(funcNames) do
	p[funcName] = makeWrapper('_' .. funcName)
end

return p