Jump to content

Module:ArbComOpenTasks

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Bradv (talk | contribs) at 18:46, 5 December 2020 (create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

local sub = mw.ustring.sub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local match = mw.ustring.match
local trim = mw.text.trim
local insert = table.insert
local concat = table.concat

function p.caserequests ( frame )
	local rfar = mw.title.new('Wikipedia:Arbitration/Requests/Case'):getContent()
	
	local re = '\n==%f[^=](.-)=='
	local sections = {}
	local count, loc = 0, 0
	repeat
		loc = find(rfar, re, loc+1)
		if (loc) then
			count = count + 1
			sections[count] = {
				id = count, 
				start = loc,
				title = trim(match(rfar, re, loc))
			}
		end
	until not loc
	
	for i=1, count, 1 do
		local sec = sections[i]
		local content = ''
		if sections[i+1] then
			content = sub( rfar, sec.start, sec.endloc )
		else
			content = sub( rfar, sec.start )
		end
		
		local redate = '%d*%s%a*%s%d*%f[(%s%(UTC%)]'
		sec.date = match(content, redate)
		
		local remotion = '\n===([^\n]*[Mm]otion[^\n]*)==='
		local m = match(content, remotion)
		if (m) then 
			sec.motion = trim(m)
		end
		
		local revotes = '\n===[^\n]*<(%d+/%d+/%d+)>%s*==='
		sec.votes = match(content, revotes)
	end

	local result = {}
	for i=1, count, 1 do
		local sec = sections[i]
		local t = {}
		insert(t, '{{ArbComOpenTasks/line|mode=caserequest') 
		insert(t, '|name=' .. sec.title)
		insert(t, '|date=' .. sec.date)
		if (sec.motion) then
			insert(t, '|motion=' .. sec.motion)
		end
		if (sec.votes) then
			insert(t, '|votes=' .. sec.votes)
		end
		insert(t, '}}')
		insert(result, concat(t, '\n'))
	end
	
	return concat(result, '\n')
end

return p