Module:Arbcom election banner/sandbox
Tools
Actions
General
Print/export
In other projects
| This is themodule sandbox page forModule:Arbcom election banner (diff). |
| Thismodule is rated asbeta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This Lua module is used onapproximately 280 pages and changes may be widely noticed. Test changes in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. Consider discussing changes on thetalk page before implementing them. |
| This module depends on the following other modules: |
| This module usesTemplateStyles: |
This module generates banner templates for the annualArbitration 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 theguiden parameters. Voting guides are displayed in a random order.
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 = }}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.These parameters are used to customize links and poll dates. If you don't need customisation, andTemplate: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 stringYYYY refers to the year specified by the|year= parameter.
name - The name of the template. This is needed to make thenavbar work properly. Defaults toACEYYYY.electionpage - The main page for the year's Arbcom elections. Defaults to[[Wikipedia:Arbitration Committee Elections DecemberYYYY|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 inTemplate: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 inTemplate: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 inTemplate: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 inTemplate: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 DecemberYYYY/Electoral Commission|Electoral Commission RFC]].nomlink - Text to be displayed while nominations are underway. Defaults to[[Wikipedia:Arbitration Committee Elections DecemberYYYY/Candidates|Nominate]].votepage - The link to the SecurePoll voting page. Defaults to a SecurePoll link with display text "Vote" made using the poll ID fromTemplate: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 fromTemplate: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 DecemberYYYY/Candidates/Guide|Candidate guide]].cstatements - Link to the candidate statements page. Defaults to[[Wikipedia:Arbitration Committee Elections DecemberYYYY/Candidates|Candidate statements]].cquestions - Link to the candidate questions page. Defaults to[[Wikipedia:Arbitration Committee Elections DecemberYYYY/Questions|Questions for the candidates]].cdiscuss - Link to the candidate discussion page. Defaults to[[Wikipedia:Arbitration Committee Elections DecemberYYYY/Candidates/Discussion|Discuss the candidates]].localmessageBox=require('Module:Message box')localnavbarModule=require('Module:Navbar')localhorizontal=require('Module:List').horizontallocalp={}-- Get constants.locallang=mw.language.getContentLanguage()localcurrentUnixDate=tonumber(lang:formatDate('U'))localfunctionerr(msg)returnmw.ustring.format('<span class="ace-banner-error">%s</span>',msg)endlocalfunctiongetUnixDate(date)localsuccess,unixDate=pcall(lang.formatDate,lang,'U',date)ifsuccessthenreturntonumber(unixDate)endendlocalfunctionunixDateError(date)returnerr(tostring(date)..' is not a valid date.')endlocalfunctionrandomizeArray(t)-- Iterate through the array backwards, each time swapping the entry "i" with a random entry.-- Courtesy of Xinhuan at http://forums.wowace.com/showthread.php?p=279756math.randomseed(mw.site.stats.edits)fori=#t,2,-1dolocalr=math.random(i)t[i],t[r]=t[r],t[i]endreturntendlocalfunctiongetArgNums(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}.localnums={}fork,vinpairs(args)dok=tostring(k)localnum=mw.ustring.match(k,'^'..prefix..'([1-9]%d*)$')ifnumthentable.insert(nums,tonumber(num))endendtable.sort(nums)returnnumsendlocalfunctionshowBeforeDate(datePairs)-- Shows a value if it is before a given date.fori,datePairinipairs(datePairs)dolocaldate=datePair.datelocalval=datePair.valifnotdatethen-- No date specified, so assume we have no more dates to process.returnvalendlocalunixDate=getUnixDate(date)ifnotunixDatethenreturnunixDateError(date)endifcurrentUnixDate<unixDatethen-- The specified date is in the future.returnvalendendendlocalfunctioncountdown(date,event)iftype(event)~='string'thenreturnerr('No event name provided.')end-- Get the current date unix timestamp.localunixDate=getUnixDate(date)ifnotunixDatethenreturnunixDateError(date)endunixDate=tonumber(unixDate)-- Subtract the timestamp from the current unix timestamp to find the time left, and output that in a readable way.localsecondsLeft=unixDate-currentUnixDateifsecondsLeft<=0thenreturnendlocaltimeLeft=lang:formatDuration(secondsLeft,{'weeks','days','hours'})-- Find whether we are plural or not.localisOrAreifmw.ustring.match(timeLeft,'^%d+')=='1'thenisOrAre='is'elseisOrAre='are'endlocaltimeLeft=mw.ustring.gsub(timeLeft,'(%d+)','<span class="ace-banner-timeleft">%1</span>')-- Make the refresh link, and join it all together.localrefreshLink=mw.title.getCurrentTitle():fullUrl{action='purge'}refreshLink=mw.ustring.format('<span class="ace-banner-refresh plainlinks">([%s refresh])</span>',refreshLink)returnmw.ustring.format('There %s %s until %s. %s',isOrAre,timeLeft,event,refreshLink)endlocalfunctionformat_guides(args,year)localguideNums=getArgNums(args,'guide')localguides={}for_,numinipairs(guideNums)dotable.insert(guides,args['guide'..tostring(num)])endlocalguide_text=mw.ustring.format('\nThese [[:Category:Wikipedia Arbitration Committee Elections %s voter guides|guides]] '..'represent the thoughts of their authors. All individually written '..'voter guides are eligible for inclusion.\n',year)guides=randomizeArray(guides)guides=horizontal(guides)localret=[=[<div class="mw-collapsible mw-collapsed"><div class="ace-banner-guides-title"><div>Personal voter guides</div></div><div class="mw-collapsible-content">%s%s</div></div>]=]returnmw.ustring.format(ret,guide_text,guides)endlocalfunctiongetElectionInfo(year,key)localframe=mw.getCurrentFrame()localresult=frame:expandTemplate{title='Arbitration Committee candidate/data',args={year,key}}ifresult~=''thenreturnresultelsereturnnilendendlocalfunctiongetStartDate(year,key)localdate=getElectionInfo(year,key)ifnotdatethenreturnnilelsereturn'00:00, '..lang:formatDate('d F Y',date)endendlocalfunctiongetEndDate(year,key)localdate=getElectionInfo(year,key)ifnotdatethenreturnnilelsereturn'23:59, '..lang:formatDate('d F Y',date..' -1 day')endendlocalfunctiongetVotePage(year)localpollId=getElectionInfo(year,'poll')ifpollIdthenreturnstring.format('[https://en.wikipedia.org/wiki/Special:SecurePoll/vote/%s Vote]',pollId)elsereturn'<span class="ace-banner-placeholder">Vote</span>'endendlocalfunctiongetVoteLog(year)localvoteWikiId=getElectionInfo(year,'votewikiid')ifvoteWikiIdthenreturnstring.format('[https://vote.wikimedia.org/wiki/Special:SecurePoll/list/%s Voter log]',voteWikiId)elsereturn'<span class="ace-banner-placeholder">Voter log</span>'endendfunctionp._main(args)-- Get data for the box, plus the box title.localyear=args.yearorlang:formatDate('Y')localname=args.nameor'ACE'..yearlocalnavbar=navbarModule.navbar{name,mini='1'}localelectionpage=args.electionpageormw.ustring.format('[[Wikipedia:Arbitration Committee Elections December %s|%s Arbitration Committee Elections]]',year,year)-- Get nomination or voting link, depending on the date.localbeforenomlink=args.beforenomlinkormw.ustring.format('[[Wikipedia:Requests for comment/Arbitration Committee Elections December %s/Electoral Commission|Electoral Commission RFC]]',year)localnomstart=args.nomstartorgetStartDate(year,'nombegin')orerror('No nomstart date supplied')localnomlink=args.nomlinkormw.ustring.format('[[Wikipedia:Arbitration Committee Elections December %s/Candidates|Nominate]]',year)localnomend=args.nomendorgetEndDate(year,'nomend')orerror('No nomend date supplied')localvotestart=args.votestartorgetStartDate(year,'begin')orerror('No votestart date supplied')localvotepage=args.votepageorgetVotePage(year)localvotelink=args.votelinkormw.ustring.format('<span class="ace-banner-votelink">%s</span>',votepage)localvotelog=args.votelogorgetVoteLog(year)localvoteend=args.voteendorgetEndDate(year,'end')orerror('No voteend date supplied')localvoteendlink=args.voteendlinkorvoteloglocalscheduleText=showBeforeDate{{val=beforenomlink,date=nomstart},{val=nomlink,date=nomend},{val=countdown(votestart,'voting begins'),date=votestart},{val=votelink,date=voteend},{val=voteendlink}}-- support votelog as its own element. must be done after we have scheduleTextifscheduleText~=votelinkthenvotelog=nilend-- Get other links.localcontact=args.contactormw.ustring.format('[[Wikipedia talk:Arbitration Committee Elections December %s/Coordination|Contact the coordinators]]',year)localdiscuss=args.discussormw.ustring.format('[[Wikipedia talk:Arbitration Committee Elections December %s|Discuss the elections]]',year)localcguide=args.cguideormw.ustring.format('[[Wikipedia:Arbitration Committee Elections December %s/Candidates/Guide|Candidate guide]]',year)localcstatements=args.cstatementsormw.ustring.format('[[Wikipedia:Arbitration Committee Elections December %s/Candidates|Candidate statements]]',year)localcquestions=args.cquestionsormw.ustring.format('[[Wikipedia:Arbitration Committee Elections December %s/Questions|Questions for the candidates]]',year)localcdiscuss=args.cdiscussormw.ustring.format('[[Wikipedia:Arbitration Committee Elections December %s/Candidates/Discussion|Discuss the candidates]]',year)localguidecat=args.guidecatormw.ustring.format('')localguides=format_guides(args,year)-- Get the text field of ombox.locallead_links=horizontal({class='ace-banner-lead-links','<span class="ace-banner-mainpage">'..electionpage..'</span>',scheduleText,votelog,contact,discuss,'[[Wikipedia:5-minute guide to ArbCom elections|Quick guide]]'})localcandidate_links=horizontal({class='ace-banner-candidates-links inline',cguide,cstatements,cquestions,cdiscuss,})returnmessageBox.main('ombox',{image=args.imageor'[[File:Judges cupola.svg|50px|ArbCom|link=]]',style=args.styleornil,text=mw.ustring.format('<div class="ace-banner-navbar">%s</div>%s<span class="ace-banner-candidates">Candidates: </span>%s%s',navbar,lead_links,candidate_links,guides),templatestyles='Module:Arbcom election banner/styles.css',class='ace-banner'})endfunctionp.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.localorigArgsifframe==mw.getCurrentFrame()thenorigArgs=frame:getParent().argsfork,vinpairs(frame.args)doorigArgs=frame.argsbreakendelseorigArgs=frameend-- Trim whitespace and remove blank arguments.localargs={}fork,vinpairs(origArgs)doiftype(v)=='string'thenv=mw.text.trim(v)endifv~=''thenargs[k]=vendendreturnp._main(args)endreturnp