Module:Football box collapsible
Appearance
From Wikipedia, the free encyclopedia
Warning This Lua module is used on approximately 29,000 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:
Implements {{Football box collapsible }}
The above documentation is transcluded from Module:Football box collapsible/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
-- Implements [[Template:Football box collapsible]] localp={} locallabels={ ['penalties']='[[Penalty shoot-out (association football)|Penalties]]', ['shootout']='[[Penalty shoot-out (association football)#North American experiments|Shootout]]', ['pen']='[[Penalty shoot-out (association football)|p]]', ['so']='[[Penalty shoot-out (association football)|SO]]', ['aet']='[[Overtime (sports)#Association football|a.e.t.]]', ['agg']='[[Playoff format#Total points series (aggregate)|agg.]]', ['stadium']='Stadium:', ['attendance']='Attendance:', ['referee']='Referee:', ['assistantreferees']='Assistant referees:', ['assistantreferee2']='<span style="visibility:hidden">Assistant referees:</span>', ['fourthofficial']='Fourth official:', ['fifthofficial']='Fifth official:', ['goallineassistants']='Goal-line assistants:', ['goallineassistant2']='<span style="visibility:hidden">Goal-line assistants:</span>', ['motm']='Man of the Match:', ['potm']='Player of the Match:', ['mvp']='MVP:', ['note']='Note:', ['seealso']='See also:' } localcolors={ ["W"]="BBF3BB", ["L"]="FFBBBB", ["T"]="D",["D"]="FFFFBB", ["SW"]="PW",["PW"]="BBF3FF", ["V"]="P",["P"]="BBBBBB" } localtracking,preview localfunctioncheckarg(k,v) ifkandtype(k)=='string'then ifk=='id'ork=='team1'ork=='team2'ork=='class'or k=='nobars'ork=='size'or k=='result'ork=='bg'ork=='format'ork=='date'ork=='scorenote'or k=='round'ork=='score'ork=='aet'ork=='aggregatescore'or k=='penaltyscore'ork=='location'ork=='stadium'or k=='time'ork=='goals1'ork=='report'ork=='goals2'or k=='attendance'ork=='referee'ork=='assistantreferees'or k=='assistantreferee2'ork=='fourthofficial'or k=='fifthofficial'ork=='goallineassistants'or k=='goallineassistant2'ork=='potm'ork=='motm'or k=='mvp'ork=='penalties1'ork=='penalties2'ork=='note'or k=='shootoutscore'ork=='shootout1'ork=='shootout2'or k=='seealso'ork=='stack'ork=='section'ork=='transcludedsection'then -- valid and not tracked else -- invalid localvlen=mw.ustring.len(k) k=mw.ustring.sub(k,1,(vlen<25)andvlenor25) k=mw.ustring.gsub(k,'[^%w%-_ ]','?') table.insert(tracking,'[[Category:Pages using football box collapsible with unknown parameters|'..k..']]') table.insert(preview,'"'..k..'"') end end end localfunctionisnotempty(s) returnsands:match('^%s*(.-)%s*$')~='' end localfunctiontrim(s) ifisnotempty(s)then s=s:match('^[\'"%s]*(.-)[\'"%s]*$') returnisnotempty(s)andsornil end returnnil end localfunctionbold(s) ifisnotempty(s)then return"'''"..s.."'''" end return"" end localfunctionitalic(s) ifisnotempty(s)then return"''"..s.."''" end return"" end localfunctionsmall(s) ifisnotempty(s)then return'<small>'..s..'</small>' end return'' end localfunctionnowrap(s) ifisnotempty(s)then return'<span style="white-space:nowrap">'..s..'</span>' end return'' end localfunctionbackground(frame,c,r,bg) localdata=colors localres=data[r:upper()] ifresthen res='#'..(data[res]orres) elseifisnotempty(bg)then res='#'..bg else res='transparent' end returnres end localfunctionteamname(team) localprefix,suffix,b="","","'''"; ifmw.ustring.sub(team,1,3)~=bandmw.ustring.sub(team,-3)~=bthen prefix='<span class="fn org">'..b..' '; suffix=' '..b.."</span>"; else ifmw.ustring.sub(team,1,3)==bthen prefix='<span class="fn org">'; team=mw.ustring.sub(team,4); else prefix='<span class="fn org">'..b; end ifmw.ustring.sub(team,-3)==bthen suffix="</span>"; team=mw.ustring.sub(team,1,mw.ustring.len(team)-3); else suffix=b.."</span>"; end end returnprefix..team..suffix; end localfunctionscore(s,a,ag,p,so) s=nowrap(bold(s~=''andsor'v')) ifa~=''then s=s..small(' ('..labels['aet']..')') end ifag~=''then s=s..'<br>'..small(' ('..bold(ag)..' '..labels['agg']..')') end ifp~=''then s=s..'<br>'..small(' ('..bold(p)..' '..labels['pen']..')') elseifso~=''then s=s..'<br>'..small(' ('..bold(so)..' '..labels['so']..')') end returns end localfunctionfmtlist(s) s=mw.ustring.gsub(sor'','%[%[ *([%?-]) *%]%]','%1') s=mw.ustring.gsub(s,'%[%[ *[%?-] *| *(.-) *%]%]','%1') ifmw.ustring.sub(s,1,1)=='*'then -- could also expand plainlist here returnmw.getCurrentFrame():extensionTag{ name='templatestyles',args={src='Plainlist/styles.css'} }..tostring(mw.html.create('div'):addClass('plainlist'):newline():wikitext(s)) end returns end localfunctionmakelink(s,t) ifs:match('^[Hh][Tt][Tt][Pp][Ss]?:[^ ]*$')then return'['..s..' '..t..']' end returns end functionp.main(frame) -- Exit early if we are using section transclusion for a different section localtsection=frame:getParent().args['transcludesection']orframe:getParent().args['section']or'' localbsection=frame.args['section']or'' if(tsection~=''andbsection~='')then if(tsection~=bsection)then return'' end end localargs=(frame.args['team1']orframe.args['team2'])andframe.argsorframe:getParent().args localid=trim(args['id']) localbars=(args['nobars']==nil)or(args['bars']=='') localclass=trim(args['class']or'mw-collapsible mw-collapsed')or'' localwidth1={['1']='28%',['1.1']='22%',['1.2']='28%',['default']='19%'} localwidth2={['1']='19%',['1.1']='25%',['1.2']='19%',['default']='23%'} localwidth3={['1']='8%',['1.1']='8%',['1.2']='8%',['default']='12%'} localwidth4={['1']='19%',['1.1']='19%',['1.2']='26%',['default']='23%'} localwidth5={['1']='26%',['1.1']='26%',['1.2']='19%',['default']='23%'} locallocation=nil localextra={} localnotes={} tracking,preview={},{} fork,vinpairs(args)do ifv~=''then checkarg(k,v) end end ifargs['class']then ifargs['class']=='collapsible'orargs['class']=='mw-collapsible'orargs['class']=='uncollapsed'then --valid elseifargs['class']==''then table.insert(tracking,'[[Category:Pages using football box collapsible with blank class parameter]]') else table.insert(tracking,'[[Category:Pages using football box collapsible with class parameter]]') end end ifisnotempty(args['stack'])then table.insert(tracking,'[[Category:Pages using football box collapsible with unsupported stack parameter]]') end -- required parameters fori,kinipairs({'team1','team2'})do ifargs[k]==nilthenargs[k]='{{{'..k..'}}}'end end -- vcard for stadium ifisnotempty(args['stadium'])then args['stadium']=tostring(mw.html.create('span'):addClass('location'):wikitext(args['stadium'])) end -- placement of stadium and location information ifisnotempty(args['location'])then location=args['location'] ifisnotempty(args['stadium'])then table.insert(extra,labels['stadium']..' '..args['stadium']) end else location=args['stadium']or' ' end -- remaining extra information fori,kinipairs({'attendance','referee','assistantreferees', 'assistantreferee2','fourthofficial','fifthofficial', 'goallineassistants','goallineassistant2','potm','motm','mvp'})do ifisnotempty(args[k])then table.insert(extra,labels[k]..' '..args[k]) end end -- score localscorestr='' ifargs['score1']orargs['score2']then scorestr=(args['score1']or'0')..'–'..(args['score2']or'0') elseifargs['score']then scorestr=args['score'] end ifargs['scorenote']then scorestr=scorestr..'<br>'..args['scorenote'] end -- notes ifisnotempty(args['note'])then table.insert(notes,"''"..labels['note'].." "..args['note'].."''") end ifisnotempty(args['seealso'])then table.insert(notes,"''"..labels['seealso'].." "..args['seealso'].."''") end -- check if this is a one row table ifclass==''orclass=='uncollapsed'then class='' elseif#extra>0or#notes>0orisnotempty(args['time'])orisnotempty(args['report'])or isnotempty(args['goals1'])orisnotempty(args['goals2'])or isnotempty(args['penalties1'])orisnotempty(args['penalties2'])or isnotempty(args['shootout1'])orisnotempty(args['shootout2'])then elseifclass=='collapsible collapsed'orclass=='mw-collapsible mw-collapsed'then class='' end -- Start box localroot= mw.html.create('div') :addClass('vevent') :attr('id',id) root:tag('span') :addClass('summary') :css('display','none') :wikitext(args['team1']..' v '..args['team2']) root:newline() -- Start table localrClassName='vevent tmpl-football-box-collapsible' localrbg=background(frame,'default',args['result']or'',args['bg']or'') ifrbg=='transparent'then rClassName=rClassName..' tmpl-football-box-collapsible-transparent' end localrtable=root:tag('table') :attr('cellspacing',0) :addClass(class~=''andclassornil) :addClass(rClassName) :css('border-top',barsand'1px solid #999'ornil) :css('border-bottom',barsand'1px solid #999'ornil) :css('margin-bottom',barsand'-1px'ornil) :css('width',args['size']or'100%') :css('background',rbg):css('color','#202122') localrow=rtable:tag('tr'):css('vertical-align','top') -- date and round localcell=row:tag('td') :css('width',width1[args['format']or'default']orwidth1['default']) ifisnotempty(args['date'])then cell:tag('span') :css('white-space','nowrap') :css('float','right') :css('margin-left','0.5em') :wikitext(args['date']) cell:wikitext(' ') end ifisnotempty(args['round'])then cell:wikitext(small(args['round'])) end -- team1 row:tag('td') :css('width',width2[args['format']or'default']orwidth2['default']) :css('text-align','right') :addClass('vcard attendee') :wikitext(teamname(args['team1'])) -- score row:tag('td') :css('width',width3[args['format']or'default']orwidth3['default']) :css('text-align','center') :wikitext(score(scorestr,args['aet']or'',args['aggregatescore']or'',args['penaltyscore']or'',args['shootoutscore']or'')) -- team2 row:tag('td') :css('width',width4[args['format']or'default']orwidth4['default']) :addClass('vcard attendee') :wikitext(teamname(args['team2'])) -- location, stadium row:tag('td') :css('width',width5[args['format']or'default']ornil) :css('font-size',locationand'85%'ornil) :wikitext(location) if#extra>0orisnotempty(args['time'])orisnotempty(args['report'])or isnotempty(args['goals1'])orisnotempty(args['goals2'])then localrow=rtable:tag('tr'):css('vertical-align','top'):css('font-size','85%') -- time row:tag('td') :css('text-align',isnotempty(args['time'])and'right'ornil) :wikitext(args['time']) row:newline() -- goals1 row:tag('td') :css('text-align',isnotempty(args['goals1'])and'right'ornil) :wikitext(fmtlist(args['goals1'])) row:newline() -- report row:tag('td') :css('text-align',isnotempty(args['report'])and'center'ornil) :wikitext(makelink(args['report']or'','Report')) row:newline() -- goals2 row:tag('td') :wikitext(fmtlist(args['goals2'])) row:newline() -- location, stadium row:tag('td') :wikitext(table.concat(extra,'<br>')) end ifisnotempty(args['penalties1'])orisnotempty(args['penalties2'])then row=rtable:tag('tr') row:tag('td'):attr('rowspan',2) row:tag('td'):attr('colspan',3):css('text-align','center'):wikitext(bold(labels['penalties'])) row:tag('td'):attr('rowspan',2) row=rtable:tag('tr'):css('vertical-align','top'):css('font-size','85%') row:newline() row:tag('td') :css('text-align',isnotempty(args['penalties1'])and'right'ornil) :wikitext(fmtlist(args['penalties1'])) row:newline() row:tag('td') row:newline() row:tag('td') :wikitext(fmtlist(args['penalties2'])) row:newline() elseifisnotempty(args['shootout1'])orisnotempty(args['shootout2'])then row=rtable:tag('tr') row:tag('td'):attr('rowspan',2) row:tag('td'):attr('colspan',3):css('text-align','center'):wikitext(bold(labels['shootout'])) row:tag('td'):attr('rowspan',2) row=rtable:tag('tr'):css('vertical-align','top'):css('font-size','85%') row:newline() row:tag('td') :css('text-align',isnotempty(args['shootout1'])and'right'ornil) :wikitext(fmtlist(args['shootout1'])) row:newline() row:tag('td') row:newline() row:tag('td') :wikitext(fmtlist(args['shootout2'])) row:newline() end if#notes>0then row=rtable:tag('tr'):css('font-size','85%') row:tag('td') :attr('colspan',5) :wikitext(table.concat(notes,'<br>')) row:newline() end localtrackstr=(#tracking>0)andtable.concat(tracking,'')or'' if#preview>0then trackstr=require('Module:If preview')._warning({ 'Unknown parameters '..table.concat(preview,'; ')..'.' })..trackstr end returntostring(root)..trackstr end returnp