mNo edit summary |
mNo edit summary |
||
Line 8: | Line 8: | ||
local RowWidget = require('Module:Infobox/Widget/Row') | local RowWidget = require('Module:Infobox/Widget/Row') | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
VariablesLua = mw.ext.VariablesLua | |||
local Flags = require('Module:Flags') | |||
local Infobox = {} | local Infobox = {} | ||
Line 18: | Line 20: | ||
local headerNode | local headerNode | ||
if args.logos and | -- Just have to access arg.logos for VariablesLua values to get initialized | ||
if args.logos then end | |||
headerNode = Header.make(args.title or | |||
elseif | local logoLight = VariablesLua.varexists('logoLight') and VariablesLua.var('logoLight') or nil | ||
local logoDark = VariablesLua.varexists('logoDark') and VariablesLua.var('logoDark') or nil | |||
local logoAll = VariablesLua.varexists('logoAll') and VariablesLua.var('logoAll') or nil | |||
if logoAll then | |||
headerNode = Header.make(args.title or currentTitle, nil, nil, logoAll) | |||
elseif logoLight or logoDark then | |||
headerNode = Header.make(args.title or currentTitle, logoLight, logoDark) | |||
elseif args.org then | elseif args.org then | ||
local currentDate = os.date('%Y-%m-%d') | local currentDate = os.date('%Y-%m-%d') | ||
local tables = ' | local tables = 'TeamImages' | ||
local fields = '_pageName, logoLight, logoDark, logoAll, start, end' | local fields = '_pageName, logoLight, logoDark, logoAll, start, end' | ||
local cargoArgs = { | local cargoArgs = { | ||
where = '_pageName=" | where = '_pageName="' .. args.org .. '" AND (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")' | ||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
Line 39: | Line 47: | ||
end | end | ||
end | end | ||
end | end | ||
Line 49: | Line 55: | ||
if args.roster then | if args.roster then | ||
container:node(RowWidget.make('Roster', LocationWidget.make(args.roster, | container:node(RowWidget.make('Roster', LocationWidget.make(args.roster, args.city, currentTitleSplit[1] .. '/Teams'))) | ||
end | end | ||
Line 65: | Line 71: | ||
if #results > 0 then | if #results > 0 then | ||
-- For each position, check if the player is in database and has flag info | |||
local flag = '' | |||
tables = 'People' | |||
fields = '_pageName, nationality, name, romanized' | |||
if ( results[1].captain ) then | if ( results[1].captain ) then | ||
container:node(RowWidget.make('Captain', results[1].captain, frame)) | cargoArgs.where = '_pageName="' .. results[1].captain .. '"' | ||
local personResults = cargo.query(tables, fields, cargoArgs) | |||
if #personResults > 0 and personResults[1].nationality then | |||
flag = Flags.icon(personResults[1].nationality) .. ' ' | |||
end | |||
container:node(RowWidget.make('Captain', flag .. results[1].captain, frame)) | |||
end | end | ||
if ( results[1].coach ) then | if ( results[1].coach ) then | ||
container:node(RowWidget. | cargoArgs.where = '_pageName="' .. results[1].coach .. '"' | ||
local personResults = cargo.query(tables, fields, cargoArgs) | |||
if #personResults > 0 and personResults[1].nationality then | |||
flag = Flags.icon(personResults[1].nationality) .. ' ' | |||
end | |||
container:node(RowWidget.person('Coach', results[1].coach, flag)) | |||
end | end | ||
if ( results[1].manager ) then | if ( results[1].manager ) then | ||
container:node(RowWidget.make('Manager', results[1].manager, frame)) | cargoArgs.where = '_pageName="' .. results[1].manager .. '"' | ||
local personResults = cargo.query(tables, fields, cargoArgs) | |||
if #personResults > 0 and personResults[1].nationality then | |||
flag = Flags.icon(personResults[1].nationality) .. ' ' | |||
end | |||
container:node(RowWidget.make('Manager', flag .. results[1].manager, frame)) | |||
end | end | ||
end | end | ||
Line 81: | Line 106: | ||
if args.org then | if args.org then | ||
container:node(RowWidget.make('Organization', | container:node(RowWidget.make('Organization', args.org, frame)) | ||
local tables = 'Sponsors' | local tables = 'Sponsors' | ||
local fields = 'id, startRef, startRefName, endRef, endRefName' | local fields = 'id, startRef, startRefName, endRef, endRefName' | ||
local cargoArgs = { | local cargoArgs = { | ||
where = '_pageName=" | where = '_pageName="' ..args.org .. '"' | ||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
Line 115: | Line 140: | ||
container:node(Subheader.make('Links')) | container:node(Subheader.make('Links')) | ||
-- Check if there is a "links" argument and then do magic to add them all to arguments | |||
if args.links then | |||
local splitLinks = mw.text.split(args.links, ',') | |||
for i = 1, #splitLinks do | |||
local split = mw.text.split(splitLinks[i], '=') | |||
args[split[1]] = split[2] | |||
end | |||
end | |||
local transformedLinks = Links.transform(args) | local transformedLinks = Links.transform(args) |
Revision as of 11:16, 29 September 2023
Documentation for this module may be created at Module:Infobox team/doc
local getArgs = require('Module:Arguments').getArgs
local Links = require('Module:Links')
local Header = require('Module:Infobox/Widget/Header')
local Subheader = require('Module:Infobox/Widget/Subheader')
local LinksWidget = require('Module:Infobox/Widget/Links')
local SponsorsWidget = require('Module:Infobox/Widget/Sponsors')
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local cargo = mw.ext.cargo
VariablesLua = mw.ext.VariablesLua
local Flags = require('Module:Flags')
local Infobox = {}
function Infobox.main(frame)
local args = getArgs(frame)
local currentTitle = mw.title.getCurrentTitle().text
local currentTitleSplit = mw.text.split(currentTitle, '/')
local headerNode
-- Just have to access arg.logos for VariablesLua values to get initialized
if args.logos then end
local logoLight = VariablesLua.varexists('logoLight') and VariablesLua.var('logoLight') or nil
local logoDark = VariablesLua.varexists('logoDark') and VariablesLua.var('logoDark') or nil
local logoAll = VariablesLua.varexists('logoAll') and VariablesLua.var('logoAll') or nil
if logoAll then
headerNode = Header.make(args.title or currentTitle, nil, nil, logoAll)
elseif logoLight or logoDark then
headerNode = Header.make(args.title or currentTitle, logoLight, logoDark)
elseif args.org then
local currentDate = os.date('%Y-%m-%d')
local tables = 'TeamImages'
local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
local cargoArgs = {
where = '_pageName="' .. args.org .. '" AND (start is NULL OR start < "' .. currentDate .. '") AND (end is NULL OR end > "' .. currentDate .. '")'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
if ( results[1].logoAll ) then
headerNode = Header.make(args.title or currentTitle, nil, nil, results[1].logoAll)
else
headerNode = Header.make(args.title or currentTitle, results[1].logoLight, results[1].logoDark)
end
end
end
local container = mw.html.create('div')
:addClass('ib')
container:node(headerNode):node(Subheader.make('Team Information'))
if args.roster then
container:node(RowWidget.make('Roster', LocationWidget.make(args.roster, args.city, currentTitleSplit[1] .. '/Teams')))
end
if args.region then
container:node(RowWidget.make('Region', LocationWidget.make(args.region, nil, currentTitleSplit[1] .. '/Teams')))
end
-- Look up Cargo table for captain, coach and manager
local tables = 'Squads'
local fields = '_pageName, captain, coach, manager'
local cargoArgs = {
where = '_pageName = "' .. mw.title.getCurrentTitle().text .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
-- For each position, check if the player is in database and has flag info
local flag = ''
tables = 'People'
fields = '_pageName, nationality, name, romanized'
if ( results[1].captain ) then
cargoArgs.where = '_pageName="' .. results[1].captain .. '"'
local personResults = cargo.query(tables, fields, cargoArgs)
if #personResults > 0 and personResults[1].nationality then
flag = Flags.icon(personResults[1].nationality) .. ' '
end
container:node(RowWidget.make('Captain', flag .. results[1].captain, frame))
end
if ( results[1].coach ) then
cargoArgs.where = '_pageName="' .. results[1].coach .. '"'
local personResults = cargo.query(tables, fields, cargoArgs)
if #personResults > 0 and personResults[1].nationality then
flag = Flags.icon(personResults[1].nationality) .. ' '
end
container:node(RowWidget.person('Coach', results[1].coach, flag))
end
if ( results[1].manager ) then
cargoArgs.where = '_pageName="' .. results[1].manager .. '"'
local personResults = cargo.query(tables, fields, cargoArgs)
if #personResults > 0 and personResults[1].nationality then
flag = Flags.icon(personResults[1].nationality) .. ' '
end
container:node(RowWidget.make('Manager', flag .. results[1].manager, frame))
end
end
if args.founded then
container:node(RowWidget.make('Founded', args.founded))
end
if args.org then
container:node(RowWidget.make('Organization', args.org, frame))
local tables = 'Sponsors'
local fields = 'id, startRef, startRefName, endRef, endRefName'
local cargoArgs = {
where = '_pageName="' ..args.org .. '"'
}
local results = cargo.query(tables, fields, cargoArgs)
if #results > 0 then
container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
end
end
if args.sponsors and args.org == nil then
container:node(RowWidget.make('Sponsors', args.sponsors))
end
if args.gamesponsors then
container:node(RowWidget.make('Game specific sponsors', args.gamesponsors))
end
if args.coach then
container:node(RowWidget.make('Coach', args.coach, frame))
end
if args.manager then
container:node(RowWidget.make('Manager', args.manager, frame))
end
if args.captain then
container:node(RowWidget.make('Captain', args.captain, frame))
end
container:node(Subheader.make('Links'))
-- Check if there is a "links" argument and then do magic to add them all to arguments
if args.links then
local splitLinks = mw.text.split(args.links, ',')
for i = 1, #splitLinks do
local split = mw.text.split(splitLinks[i], '=')
args[split[1]] = split[2]
end
end
local transformedLinks = Links.transform(args)
local fullLinks = LinksWidget.make(transformedLinks, 'team')
container:node(fullLinks)
return container
end
return Infobox