Module:Football box collapsible
Appearance
![]() | This Lua module is used on approximately 28,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 uses TemplateStyles: |
![]() | This module depends on the following other modules: |
Implements {{Football box collapsible}}
-- Implements [[Template:Football box collapsible]]
local p = {}
local lang = nil
local delink = require('Module:Delink')._delink
local penalties = '[[Penalty shoot-out (association football)|Penalties]]'
local pen = '[[Penalty shoot-out (association football)|p]]'
local aet = '[[Overtime (sports)#Association football|a.e.t.]]'
local agg = '[[Playoff format#Total points series (aggregate)|agg.]]'
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
local function trim(s)
if isnotempty(s) then
s = s:match('^[\'"%s]*(.-)[\'"%s]*$')
return isnotempty(s) and s or nil
end
return nil
end
local function teamname(team)
local prefix = "";
local suffix = "";
if mw.ustring.sub(team,1,3) ~= "'''" and mw.ustring.sub(team,-3) ~= "'''" then
prefix = "'''" .. '<span class="fn org">';
suffix = "</span>'''";
else
if mw.ustring.sub(team,1,3) == "'''" then
prefix = '<span class="fn org">';
team = mw.ustring.sub(team,4);
else
prefix = '<span class="fn org">' .. "'''";
end
if mw.ustring.sub(team,-3) == "'''" then
suffix = "</span>";
team = mw.ustring.sub(team,1,mw.ustring.len(team)-3);
else
suffix = "'''</span>";
end
end
return prefix .. team .. suffix;
end
local function score(s, a, ag, p)
s = '<span style="white-space:nowrap;display:inline">\'\'\'' .. (s ~= '' and s or 'v') .. '\'\'\'</span>'
if a ~= '' then
s = s .. '<span style="font-size:85%"> (' .. aet .. ')</span>'
end
if ag ~= '' then
ag = '<span style="font-size:85%"> (\'\'\'' .. ag .. '\'\'\' ' .. agg .. ')</span>'
end
if p ~= '' then
p = '<span style="font-size:85%"> (\'\'\'' .. p .. '\'\'\' ' .. pen .. ')</span>'
end
return table.concat({s,ag,p}, '<br>')
end
local function fmtlist(s)
s = mw.ustring.gsub(s or '', '%[%[ *([%?-]) *%]%]', '%1')
s = mw.ustring.gsub(s, '%[%[ *[%?-] *| *(.-) *%]%]', '%1')
if mw.ustring.sub(s, 1, 1) == '*' then
return tostring(mw.html.create('div'):addClass('plainlist'):newline():wikitext(s))
end
return s
end
local function makelink(s,t)
if s:match('^http') then
return '[' .. s .. ' ' .. t .. ']'
end
return s
end
function p.main(frame)
local args = frame:getParent().args
local id = trim(args['id'])
local bars = (args['nobars'] == nil) or (args['bars'] == '')
local class = trim(args['class'] or 'collapsible collapsed') or ''
local width1 = {['1'] = '28%', ['1.1'] = '22%', ['1.2'] = '28%', ['default'] = '19%'}
local width2 = {['1'] = '19%', ['1.1'] = '25%', ['1.2'] = '19%', ['default'] = '23%'}
local width3 = {['1'] = '8%', ['1.1'] = '8%', ['1.2'] = '8%', ['default'] = '12%'}
local width4 = {['1'] = '19%', ['1.1'] = '19%', ['1.2'] = '26%', ['default'] = '23%'}
local width5 = {['1'] = '26%', ['1.1'] = '26%', ['1.2'] = '19%', ['default'] = '23%'}
local location = nil
local extra = {}
if isnotempty(args['stadium']) then
args['stadium'] = tostring(mw.html.create('span'):addClass('location'):wikitext(args['stadium']))
end
if isnotempty(args['location']) then
location = args['location']
if isnotempty(args['stadium']) then
table.insert(extra, 'Stadium: ' .. args['stadium'])
end
elseif isnotempty(args['stadium']) then
location = args['stadium']
end
if isnotempty(args['attendance']) then
table.insert(extra, 'Attendance: ' .. args['attendance'])
end
if isnotempty(args['referee']) then
table.insert(extra, 'Referee: ' .. args['referee'])
end
if isnotempty(args['assistantreferees']) then
table.insert(extra, 'Assistant referees: ' .. args['assistantreferees'])
end
if isnotempty(args['assistantreferee2']) then
table.insert(extra, '<span style="visibility:hidden">Assistant referees: </span>' .. args['assistantreferee2'])
end
if isnotempty(args['fourthofficial']) then
table.insert(extra, 'Fourth official: ' .. args['fourthofficial'])
end
if isnotempty(args['fifthofficial']) then
table.insert(extra, 'Fifth official: ' .. args['fifthofficial'])
end
if isnotempty(args['goallineassistants']) then
table.insert(extra, 'Goal-line assistants: ' .. args['goallineassistants'])
end
if isnotempty(args['goallineassistant2']) then
table.insert(extra, '<span style="visibility:hidden">Goal-line assistants: </span>' .. args['goallineassistant2'])
end
if isnotempty(args['motm']) then
table.insert(extra, 'Man of the Match: ' .. args['motm'])
end
if isnotempty(args['mvp']) then
table.insert(extra, 'MVP: ' .. args['mvp'])
end
-- Start box
local root =
mw.html.create('div')
:addClass('vevent')
:attr('id', id)
root:tag('span')
:class('summary')
:css('display', 'none')
:wikitext((args['team1'] or '{{{team1}}}') .. ' v ' .. (args['team2'] or '{{{team2}}}'))
root:newline()
-- Start table
local rtable = root:tag('table')
:attr('cellspacing', 0)
:addClass(class)
:css('border-top', bars and '1px solid #999')
:css('border-top', bars and '1px solid #999')
:css('margin-bottom', bars and '-1px')
:css('width', args['size'] or '100%')
:css('background-color', background(args['competition'] or 'default', args['result'] or '', args['bg'] or ''))
local row = rtable:tag('tr'):css('vertical-align', 'top')
row:newline()
-- date and round
local cell = row:tag('td')
:css('width', width1[args['format'] or 'default'] or width1['default'])
if isnotempty(args['date']) then
cell:tag('span')
:css('white-space', 'nowrap')
:css('float', 'right')
:css('margin-left', '0.5em')
:wikitext(args['date'])
cell:wikitext(' ')
end
if isnotempty(args['round']) then
cell:tag('span')
:css('font-size', '85%')
:wikitext(args['round'])
end
-- team1
row:tag('td')
:css('width', width2[args['format'] or 'default'] or width2['default'])
:css('text-align', 'right')
:addClass('vcard attendee')
:wikitext(teamname(args['team1'] or '{{{team1}}}'))
-- score
row:tag('td')
:css('width', width3[args['format'] or 'default'] or width3['default'])
:css('text-align', 'center')
:wikitext(score(args['score'] or '', args['aet'] or '', args['aggregatescore'] or '', args['penaltyscore'] or ''))
-- team2
row:tag('td')
:css('width', width4[args['format'] or 'default'] or width4['default'])
:addClass('vcard attendee')
:wikitext(teamname(args['team2'] or '{{{team2}}}'))
-- location, stadium
row:tag('td')
:css('width', width5[args['format'] or 'default'] or width5['default'])
:css('font-size', '85%')
:wikitext(location)
local row = rtable:tag('tr'):css('vertical-align', 'top'):css('font-size:85%')
row:newline()
-- time
row:tag('td')
:css('text-align', 'right')
:wikitext(args['time'])
row:newline()
-- goals1
row:tag('td')
:css('text-align', 'right')
:wikitext(fmtlist(args['goals1']))
row:newline()
-- report
row:tag('td')
:css('text-align', 'center')
:wikitext(makelink(args['report'], 'Report'))
row:newline()
-- goals2
row:tag('td')
:css('text-align', 'right')
:wikitext(fmtlist(args['goals2']))
row:newline()
-- location, stadium
row:tag('td')
:wikitext(#exrtra > 0 and table.concat(extra, '<br>'))
-- fix for empty line ?
row:tag('td'):css('display', 'none')
if isnotempty(args['penalties1']) or isnotempty(args['penalties2']) then
row = rtable:tag('tr')
row:tag('td'):attr('rowspan', 2):wikitext(' ')
row:tag('td'):wikitext(' ')
row:tag('td'):css('text-align', 'center'):wikitext("'''" .. penalties .. "'''")
row = rtable:tag('tr'):css('vertical-align', 'top'):css('font-size', '85%')
row:newline()
row:tag('td')
:css('text-align', 'right')
:wikitext(fmtlist(args['penalties1']))
row:newline()
row:tag('td')
:wikitext(' ')
row:newline()
row:tag('td')
:css('text-align', 'left')
:wikitext(fmtlist(args['penalties2']))
row:newline()
end
notes = {}
if isnotempty(args['note']) then
table.insert(notes, "''Note: " .. args['note'] .. "''")
end
if isnotempty(args['seealso']) then
table.insert(notes, "''See also: " .. args['seealso'] .. "''")
end
if #notes > 0 then
root
:tag('tr')
:tag('td')
:attr('colspan', 7)
:css('text-align', 'left')
:css('font-size', '85%')
:wikitext(table.concat(notes, '<br>'))
end
return tostring(root)
end
return p