Module:Casenav

local p = {} local Frame

local casePath local people, dates

function p.main ( frame ) Frame = frame or mw.getCurrentFrame local title = mw.title.getCurrentTitle local base = mw.title.new(frame:callParserFunction('#titleparts', {title.fullText, 4, 1})) local casename = frame:callParserFunction('#titleparts', {title.fullText, 1, 4}) if title.isTalkPage then casePath = base.subjectPageTitle.fullText else casePath = base.fullText end

local casenav = mw.title.new(casePath .. '/Casenav') retrieveArgs(casenav, frame:getParent.args)

local output = {} table.insert(output, makeShortcut(casename)) table.insert(output, makeCaseNav(casenav)) table.insert(output, frame:expandTemplate{title = 'ArbCom navigation', args = {}}) if title == casenav then table.insert(output, makeArbList) table.insert(output, listAllArbs) table.insert(output, frame:expandTemplate{			title = 'Documentation',			args = {'User:Bradv/sandbox/casenav/doc'}		}) elseif title.isTalkPage then --on all talk pages table.insert(output, makeTalk) --on PD talk if title.subpageText == 'Proposed decision' then table.insert(output, makeArbList) end else --on PD page if title.subpageText == 'Proposed decision' then table.insert(output, makePD) end end

return table.concat(output) end

function retrieveArgs(casenav, frameArgs) --load local args local args = {} for k, v in pairs(frameArgs) do		args[k] = v	end --casenav args override local args if casenav.exists then local content = casenav:getContent local temp = mw.ustring.match(content, '%{%{(.*)%}%}') for str in mw.text.gsplit(temp, '|') do			local pair = mw.text.split(str, '=') if #pair==2 then args[mw.text.trim(pair[1])] = mw.text.trim(pair[2]) end end end --set module variables people = {} people.clerks = users(args['clerks']) people.drafters = users(args['drafters']) people.active = users(args['active']) people.inactive = users(args['inactive']) people.recused = users(args['recused']) dates = {} dates.opened = args['date-opened'] dates.evidence = args['date-evidence'] dates.workshop = args['date-workshop'] dates.pd = args['date-pd'] dates.suspended = args['date-suspended'] dates.closed = args['date-closed']

--support legacy arguments if #people.clerks==0 then for k, v in pairs(args) do			if mw.ustring.find(k, 'clerk')==1 and is_set(v) then table.insert(people.clerks, link('User:' .. v, v)) end end end if #people.drafters==0 then for k, v in pairs(args) do			if mw.ustring.find(k, 'draft')==1 and is_set(v) then table.insert(people.drafters, link('User:' .. v, v)) end end end end

function makeShortcut(casename) return Frame:preprocess("") end

function makeCaseNav(casenav) local div = mw.html.create('div') div :css('width', '100%') :css('background', 'ivory') :css('border', '1px solid #AAA') :css('margin-bottom', '1em') :css('padding', '1em 0') :wikitext(caselinks) :wikitext(casedates) :wikitext(casepeople) :tag('span') :wikitext('[' .. casenav:fullUrl('action=edit&preload=User:Bradv/sandbox/casenav/preload') .. ' edit]') :addClass('plainlinks') :cssText('float: right; font-variant: small-caps; font-size: .8em') :done :done return tostring(div) end

function makePD return Frame:expandTemplate{title = 'Casenav/PD', args = { active = #people.active, inactive = #people.inactive, recused = #people.recused }} end

function makeTalk return Frame:expandTemplate{title = 'Casenav/Talk'} end

function makeArbList local output = {} table.insert(output, "\n==Arbitrators active on this case==\n") table.insert(output, "Active:\n") for i = 1, #people.active do table.insert(output, ':#' .. people.active[i] .. '\n') end table.insert(output, "\nInactive:\n") for i = 1, #people.inactive do table.insert(output, ':#' .. people.inactive[i] .. '\n') end table.insert(output, "\nRecused:\n") for i = 1, #people.recused do table.insert(output, ':#' .. people.recused[i] .. '\n') end table.insert(output, "\n\n") return table.concat(output) end

function listAllArbs local result = {} local acm = mw.title.new('Wikipedia:Arbitration Committee/Members') local content = acm:getContent for str in mw.ustring.gmatch(content, '%{%{user|(.-)%}%}') do		table.insert(result, str) end table.sort(result) return Frame:expandTemplate{title='collapse', args={title='List of all current arbitrators (from WP:AC/M)', content=' ' .. table.concat(result, '\n') .. ' '}} end

function caselinks local result = {} table.insert(result, link(casePath, 'Main case page')) table.insert(result, link(casePath .. '/Evidence', 'Evidence')) table.insert(result, link(casePath .. '/Workshop', 'Workshop')) table.insert(result, link(casePath .. '/Proposed decision', 'Proposed decision')) local div = mw.html.create('div') :css('text-align', 'center') :wikitext(table.concat(result, ' — ')) return tostring(div) end

function casedates (opened, evidence, workshop, pd, suspended, closed) local result if is_set(dates.closed) then result = "Dates: " .. 'Opened ' .. dates.opened .. ' • ' ..			'Closed ' .. dates.closed elseif is_set(dates.suspended) then result = "Case suspended" elseif is_set(dates.opened) then local t = {} table.insert(t, "Target dates: " .. 'Opened ' .. dates.opened) if is_set(dates.evidence) then table.insert(t, 'Evidence due ' .. dates.evidence) end if is_set(dates.workshop) then table.insert(t, 'Workshop closes ' .. dates.workshop) end if is_set(dates.pd) then table.insert(t, 'Proposed decision expected ' .. dates.pd) end result = table.concat(t, ' • ') else return "" end local div = mw.html.create('div') :css('text-align', 'center') :wikitext(result) return tostring(div) end

function casepeople local s = {} if #people.clerks==0 then table.insert(s, "Case clerk: none") elseif #people.clerks==1 then table.insert(s, "Case clerk: " ..	table.concat(people.clerks)) else table.insert(s, "Case clerks: " .. table.concat(people.clerks, ' & ')) end if #people.drafters==0 then table.insert(s, "Drafting arbitrator: none") elseif #people.drafters==1 then table.insert(s, "Drafting arbitrator: " .. table.concat(people.drafters)) else table.insert(s, "Drafting arbitrators: " .. table.concat(people.drafters, ' & ')) end local div = mw.html.create('div') :css('text-align', 'center') :wikitext(table.concat(s, ' — ')) return tostring(div) end

function users ( list ) local result = {} if list then local tbl = mw.text.split(list, '\n') for i = 1, #tbl do			local user = tbl[i] user = mw.text.trim(user) if is_set(user) then table.insert(result, link('User:' .. user, user)) end end end return result end

function link ( path, label ) local title = mw.title.new(path) local small = mw.html.create('small') small :wikitext(' (Talk)') return  .. label ..  .. tostring(small) end

function is_set( var ) return not (var == nil or var == '') end

return p