Jump to content

Module:Arbitration case implementation notes/Proposal/Automatic

From Wikipedia, the free encyclopedia

local getArgs = require('Module:Arguments').getArgs

local p = {}

function p.main( frame )
	local args = getArgs(frame)
	local section = args["section"] or args["anchor"] or args["name"] or "{{{name}}}"
	local pattern = args["pattern"] or "%c:?#.-UTC"
	local ret = args["ret"] or ""
	local text = mw.title.getCurrentTitle():getContent()
	local escape = mw.ustring.gsub( section, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
	local sectionText, matches = mw.ustring.gsub(text, ".-%=%=%= *"..escape.." *%=%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, ":Comments.*", "")
	
	local supportText = mw.ustring.gsub(sectionText, ".*:Support", "Support")
	supportText = mw.ustring.gsub(supportText, ":Oppose.*", "")
	local _, support = mw.ustring.gsub(supportText, pattern, "")
	
	local opposeText = mw.ustring.gsub(sectionText, ".*:Oppose", "Oppose")
	opposeText = mw.ustring.gsub(opposeText, ":Abstain.*", "")
	local _, oppose = mw.ustring.gsub(opposeText, pattern, "")
	
	local abstainText = mw.ustring.gsub(sectionText, ".*:Abstain", "Abstain")
	local _, abstain = mw.ustring.gsub(abstainText, pattern, "")
	
	if matches ~= 1 then
		support = '?</td>'
		..'<td style="background-color: #fdeded">?</td>'
		..'<td style="background-color: #fdeded">?</td>'
		..'<td style="background-color: #ededfd">[[File:Symbol question.svg|20px|link=|alt=]]</td>'
		..'<td style="background-color: #fdeded">?</td>'
		..'<td style="background-color: #ededfd"><span class="error">Error: Found '
		..tostring(matches)
		..' sections with heading<br><code>==='
		..tostring(section)
		..'===</code></span></td></tr><tr style="display:none">'
	end
	
	if ret == "support" then
		return support
	elseif ret == "oppose" then
		return oppose
	elseif ret == "abstain" then
		return abstain
	elseif ret == "text" then
		return text
	elseif ret == "sectionText" then
		return sectionText
	elseif ret == "supportText" then
		return supportText
	elseif ret == "opposeText" then
		return opposeText
	elseif ret == "abstainText" then
		return abstainText
	else
		local template = "Arbitration Committee implementation notes/Proposal"
		local params = {}
		params["anchor"] = args["anchor"] or args["name"] or "{{{name}}}"
		params["name"] = args["name"] or "{{{name}}}"
		params["number"] = args["number"] or "{{{number}}}"
		params["support"] = support
		params["oppose"] = oppose
		params["abstain"] = abstain
		if args["notes"] then
			params["notes"] = args["notes"]
		end
		if args["pass"] then
			params["pass"] = args["pass"]
		end
		if args["active"] then
			params["active"] = args["active"]
		end
		return frame:expandTemplate{title=template, args=params}
	end
end

return p