Module:Arbcom election banner
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 280 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
This module generates banner templates for the annual Arbitration Committee elections. To make a banner template for an Arbcom election, add the links to that year's Arbcom election pages as described below, and set the four date parameters. After that, editors can add voting guides using the guiden
parameters. Voting guides are displayed in a random order.
Syntax
Simple usage:
{{#invoke:Arbcom election banner|main | year = | guide1 = | guide2 = | guide3 = | guide4 = | guide5 = }}
Full syntax:
{{#invoke:Arbcom election banner|main | year = | name = | electionpage = | nomstart = | nomend = | votestart = | voteend = | beforenomlink = | nomlink = | votepage = | votelog = | contact = | discuss = | cguide = | cstatements = | cquestions = | cdiscuss = | guide1 = | guide2 = | guide3 = | guide4 = | guide5 = }}
Parameters
Basic parameters
year
- The year of the Arbcom election, in YYYY format. This defaults to the current year.guide1
,guide2
,guide3
, ... - links to voting guides. These will be displayed in random order.
Advanced parameters
These parameters are used to customize links and poll dates. If you don't need customisation, and Template:Arbitration Committee candidate/data is up to date, you should be able to leave most or all of these parameters blank. Note - in this section, the string YYYY
refers to the year specified by the |year=
parameter.
name
- The name of the template. This is needed to make the navbar work properly. Defaults toACEYYYY
.electionpage
- The main page for the year's Arbcom elections. Defaults to[[Wikipedia:Arbitration Committee Elections December YYYY|YYYY Arbitration Committee Elections]]
.nomstart
- The date that nominations start. This must be in a format accepted by the #time parser function, e.g.November 11
. This defaults to 00:00 on the date specified in Template:Arbitration Committee candidate/data for the election year (the "nombegin" value). If there is no value specified in that template, an error is raised.nomend
- The deadline for nominations, e.g.November 18
. This defaults to 23:59 on the day before the date specified in Template:Arbitration Committee candidate/data for the election year (the "nomend" value). If there is no value specified in that template, an error is raised.votestart
- The date that voting begins, e.g.November 23
. This defaults to 00:00 on the date specified in Template:Arbitration Committee candidate/data for the election year (the "begin" value). If there is no value specified in that template, an error is raised.voteend
- The date that voting ends, e.g.December 5
. This defaults to 23:59 on the day before the date specified in Template:Arbitration Committee candidate/data for the election year (the "end" value). If there is no value specified in that template, an error is raised.beforenomlink
- Text to be displayed before the nomination period begins. Defaults to[[Wikipedia:Requests for comment/Arbitration Committee Elections December YYYY/Electoral Commission|Electoral Commission RFC]]
.nomlink
- Text to be displayed while nominations are underway. Defaults to[[Wikipedia:Arbitration Committee Elections December YYYY/Candidates|Nominate]]
.votepage
- The link to the SecurePoll voting page. Defaults to a SecurePoll link with display text "Vote" made using the poll ID from Template:Arbitration Committee candidate/data for the election year (the "poll" value). If no value is available the greyed-out text "Vote" is used.votelog
- The link to the voting log. Defaults to a SecurePoll voter log link with display text "Voter log" made using the vote wiki ID from Template:Arbitration Committee candidate/data for the election year (the "votewikiid" value). If no value is available the greyed-out text "Voter log" is used.votelink
- A link to display during the voting period. Defaults to the voting page and the voting log, and can safely be left blank.contact
- Link to the coordinator contact page. Defaults to[[WT:COORDYY|Contact the coordinators]]
, whereYY
is the third and fourth digits of the current year.discuss
- Link to the election discussion page. Defaults to[[WT:ACEYYYY|Discuss the elections]]
.cguide
- Link to the candidate guide. Defaults to[[Wikipedia:Arbitration Committee Elections December YYYY/Candidates/Guide|Candidate guide]]
.cstatements
- Link to the candidate statements page. Defaults to[[Wikipedia:Arbitration Committee Elections December YYYY/Candidates|Candidate statements]]
.cquestions
- Link to the candidate questions page. Defaults to[[Wikipedia:Arbitration Committee Elections December YYYY/Questions|Questions for the candidates]]
.cdiscuss
- Link to the candidate discussion page. Defaults to[[Wikipedia:Arbitration Committee Elections December YYYY/Candidates/Discussion|Discuss the candidates]]
.
local messageBox = require('Module:Message box')
local lang = mw.language.getContentLanguage()
local p = {}
local function makeOmbox(omboxArgs)
return messageBox.main('ombox', omboxArgs)
end
local function randomizeArray(t)
-- Iterate through the array backwards, each time swapping the last entry with a random entry.
-- Courtesy of Xinhuan at http://forums.wowace.com/showthread.php?p=279756
for i = #t, 2, -1 do
local r = math.random(i)
t[i], t[r] = t[r], t[i]
end
return t
end
local function getArgNums(args, prefix)
-- Returns a table containing the numbers of the arguments that exist for the specified prefix. For example, if the prefix
-- was 'data', and 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local nums = {}
for k, v in pairs(args) do
k = tostring(k)
local num = mw.ustring.match(k, '^' .. prefix .. '([1-9]%d*)$')
if num then
table.insert(nums, tonumber(num))
end
end
table.sort(nums)
return nums
end
local function countdown(date, event)
if type(event) ~= 'string' then return end
-- Get the current Unix timestamp and the date Unix timestamp.
local success, dateUnix = pcall(lang.formatDate, lang, 'U', date)
if not success then return end
dateUnix = tonumber(dateUnix)
local currentDateUnix = lang:formatDate('U')
currentDateUnix = tonumber(currentDateUnix)
-- Subtract the timestamps to find the time left, and output that in a readable way.
local secondsLeft = dateUnix - currentDateUnix
if secondsLeft <= 0 then return end
local timeLeft = lang:formatDuration(secondsLeft, {'weeks', 'days', 'hours', 'minutes', 'seconds'})
-- Make the numbers red and bold, because that's what {{countdown}} does and it makes them look important.
local timeLeft = mw.ustring.gsub(timeLeft, '(%d+)', '<span style="color: #F00; font-weight: bold;">%1</span>')
-- Make the refresh link, and join it all together.
local refreshLink = mw.title.getCurrentTitle():fullUrl{action = 'purge'}
return mw.ustring.format('There are %s until %s. <small><span class="plainlinks">([%s refresh])</span></small>', timeLeft, event, refreshLink)
end
function p._main(args)
return countdown(args[1], 'foo')
end
function p.main(frame)
-- If called via #invoke, use the args passed into the invoking template, or the args passed to #invoke if any exist.
-- Otherwise assume args are being passed directly in from the debug console or from another Lua module.
local origArgs
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
for k, v in pairs(frame.args) do
origArgs = frame.args
break
end
else
origArgs = frame
end
-- Trim whitespace and remove blank arguments.
local args = {}
for k, v in pairs(origArgs) do
if type(v) == 'string' then
v = mw.text.trim(v)
end
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
return p