Module:Infobox person: Difference between revisions
From TwogPedia
mNo edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
function Infobox.main(frame) | function Infobox.main(frame) | ||
local args = getArgs(frame) | |||
-- local headerNode = Header.make(args.title or mw.title.getCurrentTitle(), args.image) | |||
local headerNode = Header.make( | |||
args.title or mw.title.getCurrentTitle(), | |||
args.image, | |||
nil, | |||
nil, | |||
args.nationality, | |||
args.romanized | |||
) | |||
local container = mw.html.create('div') | |||
:addClass('ib grid-infobox') | |||
local titleContainer = mw.html.create('div') | |||
:addClass('carousel-image-container') | |||
:node(headerNode) | |||
container:node(titleContainer) | |||
local infoContainer = mw.html.create('div') | |||
:addClass('info-container grid') | |||
if args.name then | |||
infoContainer:node(RowWidget.make('Name', args.name)) | |||
end | |||
if args.romanized then | |||
infoContainer:node(RowWidget.make('Nickname', args.romanized)) | |||
end | |||
if args.nationality then | |||
local category | |||
if args.team then | |||
category = mw.text.split(args.team, '/')[1] .. '/Players' | |||
else | |||
category = 'Players' | |||
end | |||
infoContainer:node(RowWidget.make('Nationality', LocationWidget.make(args.nationality, nil, category))) | |||
end | |||
if args.birthdate then | |||
infoContainer:node(RowWidget.make('Birthdate', stringifyDate(args.birthdate))) | |||
end | |||
local transferResults = {} | local transferResults = {} | ||
if not args.team or not args.game_role then | if not args.team or not args.game_role then | ||
local tables = 'Transfers' | local tables = 'Transfers' | ||
local fields = '_pageName, position' | |||
local cargoArgs = { | |||
where = 'id= "' .. mw.title.getCurrentTitle().text .. '" AND leavedate IS NULL AND inactivedate IS NULL' | |||
} | |||
transferResults = cargo.query(tables, fields, cargoArgs) | |||
end | end | ||
if not args.team and #transferResults == 0 then | if not args.team and #transferResults == 0 then | ||
local tables = 'Org_transfers' | local tables = 'Org_transfers' | ||
local fields = '_pageName, position' | |||
local cargoArgs = { | |||
where = 'id= "' .. mw.title.getCurrentTitle().text .. '" AND leavedate IS NULL AND inactivedate IS NULL' | |||
} | |||
orgTransferResults = cargo.query(tables, fields, cargoArgs) | |||
if #orgTransferResults > 0 then | if #orgTransferResults > 0 then | ||
infoContainer:node(RowWidget.make('Org', orgTransferResults[1]._pageName, frame)) | |||
infoContainer:node(RowWidget.make('Org role', orgTransferResults[1].position)) | |||
end | end | ||
end | end | ||
local teamResults = {} | local teamResults = {} | ||
if args.team or #transferResults > 0 then | if args.team or #transferResults > 0 then | ||
local tables = 'Teams' | local tables = 'Teams' | ||
local fields = '_pageName, region' | |||
local team = args.team or transferResults[1]._pageName | local team = args.team or transferResults[1]._pageName | ||
local cargoArgs = { | |||
where = '_pageName = "' .. team .. '" AND region IS NOT NULL AND region != ""' | |||
} | |||
teamResults = cargo.query(tables, fields, cargoArgs) | |||
end | end | ||
if args.team then | |||
if #teamResults> 0 then | if #teamResults > 0 then | ||
infoContainer:node(RowWidget.make('Region', LocationWidget.make(teamResults[1].region, nil, mw.text.split(args.team, '/')[1] .. '/Teams'))) | |||
end | end | ||
infoContainer:node(RowWidget.make('Team', args.team, frame)) | |||
else | else | ||
if #teamResults > 0 then | if #teamResults > 0 then | ||
infoContainer:node(RowWidget.make('Region', LocationWidget.make(teamResults[1].region, nil, mw.text.split(teamResults[1]._pageName, '/')[1] .. '/Teams'))) | |||
end | end | ||
if #transferResults > 0 then | if #transferResults > 0 then | ||
infoContainer:node(RowWidget.make('Team', transferResults[1]._pageName, frame)) | |||
end | end | ||
end | |||
if args.game_role then | if args.game_role then | ||
infoContainer:node(RowWidget.make('Role', args.game_role)) | |||
else | else | ||
if #transferResults > 0 then | if #transferResults > 0 then | ||
infoContainer:node(RowWidget.make('Role in team', convertRole(mw.text.split(transferResults[1]._pageName, '/')[1], transferResults[1].position))) | |||
elseif args.active_roles then | elseif args.active_roles then | ||
local roleSplit = mw.text.split(args.active_roles, ',') | local roleSplit = mw.text.split(args.active_roles, ',') | ||
local plural = #roleSplit > 1 and 's' or '' | local plural = #roleSplit > 1 and 's' or '' | ||
infoContainer:node(RowWidget.make('Active role' .. plural, ListWidget.make(args.active_roles))) | |||
end | end | ||
end | |||
if args.past_roles then | if args.past_roles then | ||
local roleSplit = mw.text.split(args.past_roles, ',') | local roleSplit = mw.text.split(args.past_roles, ',') | ||
local plural = #roleSplit > 1 and 's' or '' | local plural = #roleSplit > 1 and 's' or '' | ||
infoContainer:node(RowWidget.make('Past role' .. plural, ListWidget.make(args.past_roles))) | |||
end | end | ||
if args.active_player then | |||
infoContainer:node(RowWidget.make('Active as a Player', args.active_player)) | |||
end | |||
if args.active_coach then | |||
infoContainer:node(RowWidget.make('Active as a Coach', args.active_coach)) | |||
end | |||
if args.active_analyst then | if args.active_analyst then | ||
infoContainer:node(RowWidget.make('Active as an Analyst', args.active_analyst)) | |||
end | |||
if args.active_manager then | |||
infoContainer:node(RowWidget.make('Active as a Manager', args.active_manager)) | |||
end | |||
if args.active_talent then | |||
infoContainer:node(RowWidget.make('Active as a Talent', args.active_talent)) | |||
end | |||
if args.active_production then | if args.active_production then | ||
infoContainer:node(RowWidget.make('Active in Production', args.active_production)) | |||
end | |||
if args.alternativeid then | |||
infoContainer:node(RowWidget.make('Alternative IDs', args.alternativeid)) | |||
end | |||
if args.sponsors then | |||
infoContainer:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame))) | |||
end | |||
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 | |||
if args.api_id then | if args.api_id then | ||
args.datdota = args.api_id | args.datdota = args.api_id | ||
Line 162: | Line 171: | ||
args.stratz = args.api_id | args.stratz = args.api_id | ||
end | end | ||
local transformedLinks = Links.transform(args) | |||
local fullLinks = LinksWidget.make(transformedLinks, 'player') | |||
local linksContainer = mw.html.create('div') | |||
:addClass('ib-links-container') | |||
if fullLinks then | |||
linksContainer:node(fullLinks) | |||
end | |||
container:node(infoContainer) | |||
container:node(linksContainer) | |||
container:node(Tournaments(Subheader)) | |||
return container | |||
end | end | ||
return Infobox | return Infobox |
Latest revision as of 03:13, 25 April 2025
Documentation for this module may be created at Module:Infobox person/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 ListWidget = require('Module:Infobox/Widget/List')
local LocationWidget = require('Module:Infobox/Widget/Location')
local SponsorsWidget = require('Module:Infobox/Widget/Sponsors')
local RowWidget = require('Module:Infobox/Widget/Row')
local RoleWidget = require('Module:Infobox/Widget/Role')
local stringifyDate = require('Module:Functions').stringifyDate
local convertRole = require('Module:GameRoles').convertRole
local Tournaments = require('Module:Infobox/Widget/Tournaments').get
local cargo = mw.ext.cargo
local Infobox = {}
function Infobox.main(frame)
local args = getArgs(frame)
-- local headerNode = Header.make(args.title or mw.title.getCurrentTitle(), args.image)
local headerNode = Header.make(
args.title or mw.title.getCurrentTitle(),
args.image,
nil,
nil,
args.nationality,
args.romanized
)
local container = mw.html.create('div')
:addClass('ib grid-infobox')
local titleContainer = mw.html.create('div')
:addClass('carousel-image-container')
:node(headerNode)
container:node(titleContainer)
local infoContainer = mw.html.create('div')
:addClass('info-container grid')
if args.name then
infoContainer:node(RowWidget.make('Name', args.name))
end
if args.romanized then
infoContainer:node(RowWidget.make('Nickname', args.romanized))
end
if args.nationality then
local category
if args.team then
category = mw.text.split(args.team, '/')[1] .. '/Players'
else
category = 'Players'
end
infoContainer:node(RowWidget.make('Nationality', LocationWidget.make(args.nationality, nil, category)))
end
if args.birthdate then
infoContainer:node(RowWidget.make('Birthdate', stringifyDate(args.birthdate)))
end
local transferResults = {}
if not args.team or not args.game_role then
local tables = 'Transfers'
local fields = '_pageName, position'
local cargoArgs = {
where = 'id= "' .. mw.title.getCurrentTitle().text .. '" AND leavedate IS NULL AND inactivedate IS NULL'
}
transferResults = cargo.query(tables, fields, cargoArgs)
end
if not args.team and #transferResults == 0 then
local tables = 'Org_transfers'
local fields = '_pageName, position'
local cargoArgs = {
where = 'id= "' .. mw.title.getCurrentTitle().text .. '" AND leavedate IS NULL AND inactivedate IS NULL'
}
orgTransferResults = cargo.query(tables, fields, cargoArgs)
if #orgTransferResults > 0 then
infoContainer:node(RowWidget.make('Org', orgTransferResults[1]._pageName, frame))
infoContainer:node(RowWidget.make('Org role', orgTransferResults[1].position))
end
end
local teamResults = {}
if args.team or #transferResults > 0 then
local tables = 'Teams'
local fields = '_pageName, region'
local team = args.team or transferResults[1]._pageName
local cargoArgs = {
where = '_pageName = "' .. team .. '" AND region IS NOT NULL AND region != ""'
}
teamResults = cargo.query(tables, fields, cargoArgs)
end
if args.team then
if #teamResults > 0 then
infoContainer:node(RowWidget.make('Region', LocationWidget.make(teamResults[1].region, nil, mw.text.split(args.team, '/')[1] .. '/Teams')))
end
infoContainer:node(RowWidget.make('Team', args.team, frame))
else
if #teamResults > 0 then
infoContainer:node(RowWidget.make('Region', LocationWidget.make(teamResults[1].region, nil, mw.text.split(teamResults[1]._pageName, '/')[1] .. '/Teams')))
end
if #transferResults > 0 then
infoContainer:node(RowWidget.make('Team', transferResults[1]._pageName, frame))
end
end
if args.game_role then
infoContainer:node(RowWidget.make('Role', args.game_role))
else
if #transferResults > 0 then
infoContainer:node(RowWidget.make('Role in team', convertRole(mw.text.split(transferResults[1]._pageName, '/')[1], transferResults[1].position)))
elseif args.active_roles then
local roleSplit = mw.text.split(args.active_roles, ',')
local plural = #roleSplit > 1 and 's' or ''
infoContainer:node(RowWidget.make('Active role' .. plural, ListWidget.make(args.active_roles)))
end
end
if args.past_roles then
local roleSplit = mw.text.split(args.past_roles, ',')
local plural = #roleSplit > 1 and 's' or ''
infoContainer:node(RowWidget.make('Past role' .. plural, ListWidget.make(args.past_roles)))
end
if args.active_player then
infoContainer:node(RowWidget.make('Active as a Player', args.active_player))
end
if args.active_coach then
infoContainer:node(RowWidget.make('Active as a Coach', args.active_coach))
end
if args.active_analyst then
infoContainer:node(RowWidget.make('Active as an Analyst', args.active_analyst))
end
if args.active_manager then
infoContainer:node(RowWidget.make('Active as a Manager', args.active_manager))
end
if args.active_talent then
infoContainer:node(RowWidget.make('Active as a Talent', args.active_talent))
end
if args.active_production then
infoContainer:node(RowWidget.make('Active in Production', args.active_production))
end
if args.alternativeid then
infoContainer:node(RowWidget.make('Alternative IDs', args.alternativeid))
end
if args.sponsors then
infoContainer:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame)))
end
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
if args.api_id then
args.datdota = args.api_id
args.dotabuff = args.api_id
args.stratz = args.api_id
end
local transformedLinks = Links.transform(args)
local fullLinks = LinksWidget.make(transformedLinks, 'player')
local linksContainer = mw.html.create('div')
:addClass('ib-links-container')
if fullLinks then
linksContainer:node(fullLinks)
end
container:node(infoContainer)
container:node(linksContainer)
container:node(Tournaments(Subheader))
return container
end
return Infobox
No categories