Module:Football manager history
![]() | This Lua module is used on approximately 23,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 Template:Football manager history.
Usage
{{Football manager history
|dissolved =
|name =
|teamname =
|managerlist =
|title =
|state = {{{state|}}}
|bgcolor =
|textcolor =
|bordercolor =
|note =
|list =
|below =
|american_english =
}}
Normally |dissolved=
would not be set; that causes a dash (–) to be added after the from year for the last manager if no to year is given. If the club has been dissolved, enter yes
or the year of dissolution, for example |dissolved=yes
or |dissolved=2010
. No dash is added for the last manager of a dissolved club.
The navigation bar at the top of the navbox includes a link to the |teamname=
page title. The link will display the |title=
text, or teamname
if no title
is given.
By default, the navigation bar will display "managers". If |american_english=
is defined (for example, |american_english=on
), "Head coaches" is displayed instead of "managers".
|state=
defaults to autocollapse.
The |list=
parameter is followed by lines of wikitext, one manager per line. Each line must finish with either a year or a range of years. On each line, the first year must be four digits. If present, the second year must follow "to" and may be 1, 2, 3, or 4 digits, for example:
|list=
[[Levir Culpi|Culpi]] 2005
[[Paulo César Gusmão|PC Gusmão]] 2005 to 06
|note=
may be used to add a note beneath the list.
If information is missing, an alternate syntax is available using from=FROM
and to=TO
. Any text can be used for FROM
and TO
, but there must be no spaces. For example:
|list=
[[Example|Example A]] from=19??
[[Levir Culpi|Culpi]] 2005
[[Paulo César Gusmão|PC Gusmão]] 2005 to 06
[[Example|Example B]] from=2011 to=?
Alternatives to avoid Wikipedia's Post-expand include size limit
Pages with many navboxes may come close to or exceed Wikipedia's Post-expand include size limit. For this reason, consider using Module:Football manager history directly by replacing {{football manager history
with {{#invoke:football manager history|main
.
Examples
{{Football manager history
|name = Cruzeiro Esporte Clube managers
|teamname = Cruzeiro Esporte Clube
|title = Cruzeiro
|state = {{{state|}}}
|bgcolor = #165A9E
|textcolor = white
|bordercolor = #77BBFF
|note = <small>(c) = [[caretaker manager]]</small>
|list =
[[Levir Culpi|Culpi]] 2005
[[Paulo César Gusmão|PC Gusmão]] 2005 to 06
[[Oswaldo de Oliveira|O. Oliveira]] 2006
[[Paulo Autuori|Autuori]] 2007
[[Emerson Ávila|Ávila]]<sup>c</sup> 2007
[[Dorival Júnior|Dorival Jr.]] 2007
[[Adílson Batista|Adílson]] 2008 to 10
}}
produces:
{{Football manager history
|name = Cruzeiro Esporte Clube managers
|teamname = Cruzeiro Esporte Clube
|title = Cruzeiro
|state = {{{state|}}}
|bgcolor = #165A9E
|textcolor = white
|bordercolor = #77BBFF
|note = <small>(c) = [[caretaker manager]]</small>
|list =
[[Example|Example A]] from=19??
[[Levir Culpi|Culpi]] 2005
[[Paulo César Gusmão|PC Gusmão]] 2005 to 06
[[Oswaldo de Oliveira|O. Oliveira]] 2006
[[Paulo Autuori|Autuori]] 2007
[[Emerson Ávila|Ávila]]<sup>c</sup> 2007
[[Dorival Júnior|Dorival Jr.]] 2007
[[Adílson Batista|Adílson]] 2008 to 10
[[Example|Example B]] from=2011 to=?
}}
produces: Lua error at line 71: Invalid line: "Example A from=19??".
-- Implement [[Template:Football manager history]] to avoid articles being
-- added to [[:Category:Pages where template include size is exceeded]]
-- when the template is used many times.
local function collection()
-- Return a table to hold items.
return {
n = 0,
add = function (self, item)
self.n = self.n + 1
self[self.n] = item
end,
addif = function (self, item, fmt)
if item then
self.n = self.n + 1
self[self.n] = fmt and string.format(fmt, item) or item
end
end,
join = function (self, sep)
return table.concat(self, sep)
end,
}
end
local function make_entry(name, from, to, islast)
local result =
'*<span class="vevent">' ..
'<span class="agent attendee vcard">' ..
'<span class="fn org summary">' ..
name ..
'</span></span> (<span class="dtstart">' ..
from ..
'</span>'
if to then
result = result .. '–' .. to
elseif islast then
result = result .. '–'
end
result = result .. ')</span>'
return result
end
local function make_list(text)
-- Return a list of formatted items.
-- Input is a string of multiple lines, one item per line.
-- Each item is 'NAME FROM' TO or 'NAME FROM', where
-- NAME = manager name (any text)
-- FROM = four digits (from year)
-- TO = 1, 2, 3 or 4 digits (to year), or empty
text = text or ''
if text:find('<span class=', 1, true) then
-- To allow a transition period where some navboxes use the old syntax, the
-- given text is used if it appears to have come from the old subtemplates.
return text
end
local lines = collection()
for line in string.gmatch(text .. '\n', '[\t ]*(.-)[\t\r ]*\n') do
if line ~= '' then
lines:add(line)
end
end
if lines.n <= 0 then
return ''
end
local entries = collection()
for i, line in ipairs(lines) do
local name, from, to = line:match('^(..-)%s+(%d%d%d%d)%s+to%s+(%d%d?%d?%d?)$')
if not name then
name, from = line:match('^(..-)%s+(%d%d%d%d)$')
if not name then
error('Invalid line: "' .. line .. '"')
end
end
entries:add(make_entry(name, from, to, i == lines.n))
end
return '<div>\n' .. entries:join('\n') .. '\n</div>'
end
local function clean(text, default)
-- Return text if it is not empty; otherwise return default.
if text and not text:match('^%s*$') then
return text
end
return default -- may be nil
end
local function arg_style(bgcolor, textcolor, bordercolor)
local result = collection()
result:addif(clean(bgcolor), 'background:%s;')
result:addif(clean(textcolor), 'color:%s;')
result:addif(clean(bordercolor), 'border:1px solid %s;')
result:add('width: 87%;')
return result:join(' ')
end
local function arg_title(title, teamname, managerlist, textcolor, american_english)
title = clean(title)
teamname = clean(teamname, 'MISSING "teamname"')
managerlist = clean(managerlist)
textcolor = clean(textcolor)
american_english = clean(american_english)
local spancolor = textcolor and ('<span style="color:' .. textcolor .. ';">') or '<span>'
local mgr = spancolor .. (american_english and 'Head coaches' or 'managers') .. '</span>'
return
'<span class="fn org">[[' .. teamname .. '|' ..
spancolor ..
(title or teamname) .. '</span>]]</span> – ' ..
(managerlist and ('[[' .. managerlist .. '|' .. mgr .. ']]') or mgr)
end
local function main(frame)
-- Return wikitext for a navbox.
-- Code does not do much checking of inputs but will throw an error
-- if input is found to be invalid.
local args = frame:getParent().args
-- Read arguments in order of output (Module:Navbox says this puts
-- reference numbers in the right order).
local _
_ = args.title
_ = args.list
_ = args.below
local style = arg_style(args.bgcolor, args.textcolor, args.bordercolor)
local navargs = {
bodyclass = 'vcard',
name = clean(args.name),
state = clean(args.state, 'autocollapse'),
titlestyle = style,
title = arg_title(args.title, args.teamname, args.managerlist, args.textcolor, args.american_english),
listclass = 'hlist',
list1 = make_list(args.list),
belowstyle = style,
below = clean(args.below),
}
local navbox = require('Module:Navbox')._navbox
return navbox(navargs)
end
return { main = main }