Module:Football box
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 depends on the following other modules: |
![]() | This module uses TemplateStyles: |
Implements {{Football box}}
-- Implements [[Template:Football box]]
local p = {}
local lang = mw.getContentLanguage()
local delink = require('Module:Delink')._delink
local eventschema = "http://schema.org/SportsEvent"
local teamschema = "http://schema.org/SportsTeam"
local placeschema = "http://schema.org/Place"
local penalties = '[[Penalty shoot-out (association football)|Penalties]]'
local aet = '[[Overtime (sports)#Association football|a.e.t.]]'
local attendance = 'Attendance:'
local referee = 'Referee:'
local itemscopetype = 'itemtype' -- 'itemscope itemtype' doesn't work?
local function timestamp(d, t)
if d then
return lang:formatDate('c', delink({d .. ' ' .. (t or '')})) or ''
end
return ''
end
local function fmtlist(s)
s = mw.ustring.gsub(s or '', '%[%[ *([%?-]) *%]%]', '%1')
s = mw.ustring.gsub(s, '%[%[ *[%?-] *| *(.-) *%]%]', '%1')
if s:match('^[%*]') or s:match('[\r\n][%*]') then
return '<div class="plainlist">\n' .. s .. '</div>'
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 = require('Module:Arguments').getArgs(frame)
local id = mw.ustring.gsub(args['id'] or '', '^[\'"%s]*(.-?)[\'"%s]*$', '%1')
local d = timestamp(args['date'], args['time'])
if d == '' then d = nil end
local score = 'v'
if args['score1'] or args['score2'] then
score = (args['score1'] or '0') .. '–' .. (args['score2'] or '0')
elseif args['score'] and args['score'] ~= '' then
score = args['score']
end
if args['aet'] then
score = score .. ' (' .. aet .. ')'
end
-- Start box
local root =
mw.html.create('div')
:attr(itemscopetype, eventschema)
:css('width', args['size'])
:css('background-color', args['bg'])
:css('clear', 'both')
:css('overflow', 'auto')
:attr('id', id)
if args['event'] then
root:tag('div')
:css('text-align', 'center')
:css('font-weight', 'bold')
:wikitext(args['event'])
end
-- Start header
local header = root:tag('div')
:addClass('mobile-float-reset')
:css('float', 'left')
:css('width', '15%')
:css('padding', '2px 0')
:css('overflow', 'auto')
local timetag = header:tag('time')
:attr('itemprob', d and 'startDate' or nil)
:attr('datetime', d)
:css('display', 'block')
:css('overflow', 'auto')
timetag:tag('span')
:addClass('mobile-float-reset')
:css('display', 'block')
:css('float', 'right')
:wikitext(args['date'])
if args['time'] then
timetag:tag('span')
:addClass('mobile-float-reset')
:css('display', 'block')
:css('clear', 'right')
:css('float', 'right')
:wikitext(args['time'])
end
if args['round'] then
header:tag('div')
:addClass('mobile-float-reset')
:css('clear', 'right')
:css('float', 'right')
:wikitext(args['round'])
end
-- End header
-- Start table
local rtable = root:tag('table')
:css('float', 'left')
:css('width', '61%')
:css('table-layout', 'fixed')
:css('text-align', 'center')
local row = rtable:tag('tr')
:attr('itemprob', 'name')
:css('vertical-align', 'top')
row:tag('th')
:css('width', '39%')
:css('text-align', 'right')
:css('itemprob', 'homeTeam')
:attr(itemscopetype, teamschema)
:tag('span')
:attr('itemprob', 'name')
:wikitext(args['team1'])
row:tag('th')
:css('width', '22%')
:wikitext(score)
row:tag('th')
:css('width', '39%')
:css('text-align', 'left')
:css('itemprob', 'awayTeam')
:attr(itemscopetype, teamschema)
:tag('span')
:attr('itemprob', 'name')
:wikitext(args['team2'])
row = rtable:tag('tr')
:css('vertical-align', 'top')
:css('font-size', '85%')
row:tag('td')
:css('text-align', 'right')
:wikitext(fmtlist(args['goals1']))
row:tag('td')
:wikitext(makelink(args['report'] or '', 'Report'))
row:tag('td')
:css('text-align', 'left')
:wikitext(fmtlist(args['goals2']))
if args['penaltyscore'] then
rtable
:tag('tr')
:tag('th')
:attr('colspan', 3)
:wikitext(penalties)
row = rtable:tag('tr')
:css('vertical-align', 'top')
:css('font-size', '85%')
row:tag('td')
:css('text-align', 'right')
:wikitext(fmtlist(args['penalties1']))
row:tag('th')
:wikitext(args['penaltyscore'])
row:tag('td')
:css('text-align', 'left')
:wikitext(fmtlist(args['penalties2']))
end
-- End table
-- Start footer
local footer = root:tag('div')
:addClass('mobile-float-reset')
:css('float', 'left')
:css('font-size', '85%')
:css('width', '24%')
:css('padding', '2px 0')
if args['stadium'] then
local sdiv = footer:tag('div')
:attr('itemprob', 'location')
:attr(itemscopetype, placeschema)
if args['location'] then
sdiv:tag('span')
:attr('itemprob', 'name')
:wikitext(args['stadium'])
sdiv:wikitext(', ')
sdiv:tag('span')
:attr('itemprob', 'address')
wikitext(args['location'])
else
sdiv:tag('span')
:attr('itemprob', 'name address')
:wikitext(args['stadium'])
end
end
if args['attendance'] then
footer:tag('div'):wikitext(attendance ..' ' .. args['attendance'])
end
if args['referee'] then
footer:tag('div'):wikitext(referee .. ' ' .. args['referee'])
end
return tostring(root)
end
return p