Module:Infobox person: Difference between revisions

From TwogPedia
mNo edit summary
mNo edit summary
Line 104: Line 104:
local transformedLinks = Links.transform(args)
local transformedLinks = Links.transform(args)
local fullLinks = LinksWidget.make(transformedLinks, 'team')
local fullLinks = LinksWidget.make(transformedLinks, 'player')
container:node(fullLinks)
container:node(fullLinks)

Revision as of 16:40, 29 September 2023

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 RowWidget = require('Module:Infobox/Widget/Row')
local RoleWidget = require('Module:Infobox/Widget/Role')
local stringifyDate = require('Module:Functions').stringifyDate
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 or '')
	
	local container = mw.html.create('div')
		:addClass('ib')
		
	container:node(headerNode):node(Subheader.make('Player Information'))
	
	if args.name then
		container:node(RowWidget.make('Name', args.name))
	end
	
	if args.romanized then
		container:node(RowWidget.make('Romanized name', 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
		container:node(RowWidget.make('Nationality', LocationWidget.make(args.nationality, nil, category)))
	end
	
	if args.birthdate then
		container:node(RowWidget.make('Birthdate', stringifyDate(args.birthdate)))
	end
	
	-- add one for "signature" as in signature characters played
	
	if args.team then
        local tables = 'Teams'
	    local fields = 'region'
	    local cargoArgs = {
		    where = '_pageName = "' .. args.team .. '"'
	    }
	    local results = cargo.query(tables, fields, cargoArgs)

        if #results > 0 then
            container:node(RowWidget.make('Region', LocationWidget.make(results[1].region, nil, mw.text.split(args.team, '/')[1] .. '/Teams')))
        end
		container:node(RowWidget.make('Team', args.team, frame))
	end

	if args.active_player then
		container:node(RowWidget.make('Active as a Player', args.active_player))
	end
	if args.active_coach then
		container:node(RowWidget.make('Active as a Coach', args.active_coach))
	end
	if args.active_manager then
		container:node(RowWidget.make('Active as a Manager', args.active_manager))
	end
	if args.active_talent then
		container:node(RowWidget.make('Active as a Talent', args.active_talent))
	end
	
	
	if args.game_role then
		container:node(RowWidget.make('Role', args.game_role))
	end
	
	if args.alternativeid then
		container:node(RowWidget.make('Alternative IDs', args.alternativeid))
	end
	
	
	if args.nicknames then 
		container:node(RowWidget.make('Nicknames', args.nicknames))
	end
	
	if args.sponsors then
		container:node(RowWidget.make('Sponsors', ListWidget.make(args.sponsors)))
	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, 'player')
	
	container:node(fullLinks)
	return container
end

return Infobox