Jump to content

Module:Arbitration case implementation notes/Automatic

From Wikipedia, the free encyclopedia

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

local p = {}

function p._transclude( frame )
	local args = getArgs(frame)
	local case = args["case"]
	local autonotes = args["autonotes"] or ""
	if not case then
		case = tostring(mw.title.getCurrentTitle())
		case = mw.ustring.gsub(case, "/Proposed decision.*", "")
		case = mw.ustring.gsub(case, ".*/", "")
	end
	local text = mw.title.new("Wikipedia:Arbitration/Requests/Case/"..case.."/Proposed decision"):getContent()
	local prop = ""
	local sectionText = ""
	local number = ""
	local principles = ""
	local findings = ""
	local remedies = ""
	local enforcement = ""
	
	local function proposals()
		prop = ""
		while "\a"..sectionText ~= mw.ustring.gsub("\a"..sectionText, "\a.-%=%=%= *", "", 1) do
			section = mw.ustring.gsub("\a"..sectionText, "\a.-%=%=%= *", "", 1)
			number = mw.ustring.gsub("\a"..section, "\a.-%=%=%=%s*", "", 1)
			number = mw.ustring.gsub(number, "%).*", "", 1)
			section = mw.ustring.gsub(section, " *%=%=%=.*", "", 1)
			sectionText = mw.ustring.gsub("\a"..sectionText, "\a.-%=%=%=.-%=%=%=%s*.-%)", "\a", 1)
			prop = prop .. frame:expandTemplate{ title = 'ACImplNotes/Proposal/Automatic', args = { name = section, number = number, case = case, autonotes = autonotes } } .. "\n"
		end
	end
	
	sectionText = mw.ustring.gsub(text, ".-%=%= *Proposed principles *%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, "%=%= *Proposed findings of fact *%=%=.*", "")
	proposals()
	principles = prop
	
	sectionText = mw.ustring.gsub(text, ".-%=%= *Proposed findings of fact *%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, "%=%= *Proposed remedies *%=%=.*", "")
	proposals()
	findings = prop
	
	sectionText = mw.ustring.gsub(text, ".-%=%= *Proposed remedies *%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, "%=%= *Proposed enforcement *%=%=.*", "")
	proposals()
	remedies = prop
	
	enforcement = frame:expandTemplate{ title = 'ACImplNotes/Proposal', args = {
		name = "Enforcement of restrictions",
		number = "0",
		support = "0",
		oppose = "0", 
		abstain = "0", 
		notes = "Passes by default", 
		pass = "pass"
	} } .. "\n" .. frame:expandTemplate{ title = 'ACImplNotes/Proposal', args = {
		name = "Appeals and modifications",
		number = "0",
		support = "0",
		oppose = "0", 
		abstain = "0", 
		notes = "Passes by default",
		pass = "pass"
	} }
	
	return frame:expandTemplate{ title = 'ACImplNotes', args = { 
		updated = "automatic template check", 
		principles = principles, 
		findings = findings, 
		remedies = remedies, 
		enforcement = enforcement 
	} }
end

function p._subst( frame )
	local args = getArgs(frame)
	local case = args["case"]
	local autonotes = args["autonotes"] or ""
	local title = tostring(mw.title.getCurrentTitle())
	if not case then
		case = mw.ustring.gsub(title, "/Proposed decision.*", "")
		case = mw.ustring.gsub(case, ".*/", "")
	end
	local caseTitle = "Wikipedia:Arbitration/Requests/Case/"..case.."/Proposed decision"
	local text = mw.title.new(caseTitle):getContent()
	local ret = "{".."{ACImplNotes\n|updated     =automatic template check \n"
	.. "|principles  =\n"
	local sectionText = ""
	local number = ""
	
	if autonotes ~= "" then
		autonotes = " |autonotes="..autonotes
	end
	if title ~= caseTitle then
		case = " |case="..case
	else
		case = ""
	end
	
	local function proposals()
		while "\a"..sectionText ~= mw.ustring.gsub("\a"..sectionText, "\a.-%=%=%= *", "", 1) do
			section = mw.ustring.gsub("\a"..sectionText, "\a.-%=%=%= *", "", 1)
			number = mw.ustring.gsub("\a"..section, "\a.-%=%=%=%s*", "", 1)
			number = mw.ustring.gsub(number, "%).*", "", 1)
			section = mw.ustring.gsub(section, " *%=%=%=.*", "", 1)
			sectionText = mw.ustring.gsub("\a"..sectionText, "\a.-%=%=%=.-%=%=%=%s*.-%)", "\a", 1)
			ret = ret .. "{".."{ACImplNotes/Proposal/Automatic |name="..section.." |number="..number.." |support= |oppose= |abstain="..case..autonotes.." |notes= }}\n"
		end
	end
	
	sectionText = mw.ustring.gsub(text, ".-%=%= *Proposed principles *%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, "%=%= *Proposed findings of fact *%=%=.*", "")
	proposals()
	ret = ret .. "|findings  =\n"
	
	sectionText = mw.ustring.gsub(text, ".-%=%= *Proposed findings of fact *%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, "%=%= *Proposed remedies *%=%=.*", "")
	proposals()
	ret = ret .. "|remedies  =\n"
	
	sectionText = mw.ustring.gsub(text, ".-%=%= *Proposed remedies *%=%=", "")
	sectionText = mw.ustring.gsub(sectionText, "%=%= *Proposed enforcement *%=%=.*", "")
	proposals()
	ret = ret .. "|enforcement  =\n"
	.. "{".."{ACImplNotes/Proposal |name=Enforcement of restrictions |number=0 |support=0 |oppose=0 |abstain=0 |notes=Passes by default |pass=pass }}\n"
	.. "{".."{ACImplNotes/Proposal |name=Appeals and modifications |number=0 |support=0 |oppose=0 |abstain=0 |notes=Passes by default |pass=pass }}\n"
	.. "}}"

	return ret
end

function p.main( frame ) 
	if mw.isSubsting() then
		return p._subst(frame)
	else 
		return p._transclude(frame)
	end
end

return p