Module:Sandbox/Bradv/Case

This is an old revision of this page, as edited by Bradv (talk | contribs) at 04:49, 5 December 2020 (.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local sub = mw.ustring.sub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local trim = mw.text.trim

--[[function p.list()
	local frame = mw.getCurrentFrame()
	local s = frame:callParserFunction{
		name = '#categorytree', 
		args = {'Wikipedia arbitration cases'}
		}
	mw.log(mw.text.unstrip(s))
end
--]]

local prefix = 'Wikipedia:Arbitration/Requests/Case/'
local ptalk = 'Wikipedia talk:Arbitration/Requests/Case/'

function p.dates( frame )
	local case = frame.args[1] or frame.args.case
	return p._dates( case )
end
function p._dates( case )
	local page = prefix .. case
	local pagecontent = mw.title.new(page):getContent()
	local result = {}
	local re = '\n<big>(.-)</big>'
	for str in gmatch (pagecontent, re) do
		table.insert(result, '*' .. trim(str))
	end
	return table.concat(result, '\n')
end

function p.decision( frame )
	local case = frame.args[1] or frame.args.case
	return p._decision( case )
end
function p._decision( case )
	local page = prefix .. case
	local pagecontent = mw.title.new(page):getContent()
	local fdstart = find(pagecontent, '\n=Final decision')
	local fd = sub(pagecontent, fdstart)
	local result = {}
	local re = '\n==(.-)=='
	for str in gmatch(fd, re) do
		if find(str, '^Enforcement') then
			break
		end
		if find(str, '^=') then
			s = trim(sub(str, 2))
			table.insert(result, '*[[' .. page .. '#' .. s .. '|' .. s .. ']]')
		else
			table.insert(result, "'''" .. str .. "'''")
		end
	end
	local output = table.concat(result, '\n')
	mw.log(output)
	return output
end

function p.arca( frame )
	local case = frame.args[1] or frame.args.case
	return p._arca( case )
end
function p._arca( case )
	local page = ptalk .. case
	local pagecontent = mw.title.new(page):getContent()
	local result = {}
	local re = '\n==(.-)=='
	for str in gmatch (pagecontent, re) do
		str = trim(str)
		if find(str, '^Amendment request')
		or find(str, '^Clarification request') then
			table.insert(result, '*[[' .. page .. '#' .. str .. '|' .. str .. ']]')
		end
	end
	return table.concat(result, '\n')
end

function p.sections( frame )
	local case = frame.args[1] or frame.args.case
	local delim = frame.args[2] or frame.args.delim or '\n'
	return p._sections( case, delim )
end
function p._sections( case, delim )
	local page = prefix .. case
	local talkpage = ptalk .. case
	
	local result = {}
	
	function add (name)
		local path = ''
		if name then
			path = '/' .. name
		else
			name = 'Case'
		end
		
		local title = mw.title.new(page .. path)
		if (title.exists) then
			table.insert(result, 
				'[[' .. page .. path .. '|' .. name .. ']]'
				.. ' (' .. '[[' .. talkpage .. path .. '|' .. 'talk]])'
				) 
		end
	end
	
	add()
	add('Evidence')
	add('Workshop')
	add('Proposed decision')

	return table.concat(result, delim)
end

return p