Module:Infobox location: Difference between revisions

From TwogPedia
No edit summary
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
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 Flags = require('Module:Flags')
Line 14: Line 16:
function Infobox.main(frame)
function Infobox.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
 
local currentTitle = mw.title.getCurrentTitle().text
local currentTitle = mw.title.getCurrentTitle().text
local headerNode
local headerNode
if args.logoAll or args.logoLight or args.logoDark then
 
    if args.logos then
local logoAll = VariablesLua.varexists( 'logoAll' ) and VariablesLua.var('logoAll') or nil
local logoLight = VariablesLua.varexists( 'logoLight' ) and VariablesLua.var('logoLight') or nil
local logoDark = VariablesLua.varexists( 'logoDark' ) and VariablesLua.var('logoDark') or nil
headerNode = Header.make(args.title or mw.title.getCurrentTitle().text, logoLight, logoDark, logoAll)
elseif args.logoAll or args.logoLight or args.logoDark then
headerNode = Header.make(args.title or currentTitle, args.logoLight, args.logoDark, args.logoAll)
headerNode = Header.make(args.title or currentTitle, args.logoLight, args.logoDark, args.logoAll)
elseif args.franchise or args.company then
elseif args.franchise or args.company then
local currentDate = os.date('%Y-%m-%d')
local currentDate = os.date('%Y-%m-%d')
local company = args.franchise or args.company
local company = args.franchise or args.company
        company = 'Companies/' .. company
local tables = 'Logos'
local tables = 'Logos'
local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
Line 69: Line 78:
end
end
if args.franchise and args.nosponsors == nil then
   
container:node(RowWidget.make('Franchise', args.franchise, frame))
if args.franchise then
local tables = 'Sponsors'
        container:node(RowWidget.make('Franchise', args.franchise, frame, 'Companies/' ))
local fields = 'id, startRef, startRefName, endRef, endRefName'
        if  args.nosponsors == 'No' then
local cargoArgs = {
    local tables = 'Sponsors'
where = '_pageName="' ..args.franchise .. '"'
    local fields = 'id, startRef, startRefName, endRef, endRefName'
}
    local cargoArgs = {
local results = cargo.query(tables, fields, cargoArgs)
    where = '_pageName="Companies/' ..args.franchise .. '"'
if #results > 0 then
    }
    container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
    local results = cargo.query(tables, fields, cargoArgs)
end
    if #results > 0 then
        container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
    end
        end
end
end
if args.company then
if args.company then
container:node(RowWidget.make('Company', args.company, true))
container:node(RowWidget.make('Company', args.company, true, 'Companies/'))
end
end


if args.sponsors and args.franchise == nil then
if args.sponsors and args.franchise == nil then
container:node(RowWidget.make('Sponsors', args.sponsors))
container:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame) ))
end
end
if args.locationsponsors then
if args.locationsponsors then
container:node(RowWidget.make('Location specific sponsors', args.locationsponsors))
        local text = args.sponsors ~= nil and 'Location specific sponsors' or 'Sponsors'
container:node(RowWidget.make(text, SponsorsWidget.make(args.locationsponsors , frame)))
end
end

Latest revision as of 12:28, 19 February 2024

Documentation for this module may be created at Module:Infobox location/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 headerNode

    if args.logos then
		local logoAll = VariablesLua.varexists( 'logoAll' ) and VariablesLua.var('logoAll') or nil
		local logoLight = VariablesLua.varexists( 'logoLight' ) and VariablesLua.var('logoLight') or nil
		local logoDark = VariablesLua.varexists( 'logoDark' ) and VariablesLua.var('logoDark') or nil
		headerNode = Header.make(args.title or mw.title.getCurrentTitle().text, logoLight, logoDark, logoAll)
	elseif args.logoAll or args.logoLight or args.logoDark then
		 headerNode = Header.make(args.title or currentTitle, args.logoLight, args.logoDark, args.logoAll)
	elseif args.franchise or args.company then
		local currentDate = os.date('%Y-%m-%d')
		local company = args.franchise or args.company
        company = 'Companies/' .. company
		local tables = 'Logos'
		local fields = '_pageName, logoLight, logoDark, logoAll, start, end'
		local cargoArgs = {
			where = '_pageName="' .. company .. '" 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
	else 
		headerNode = Header.make(args.title or currentTitle)
	end
	
	local container = mw.html.create('div')
		:addClass('ib')
		
	container:node(headerNode):node(Subheader.make('Location Information'))
	
	if args.closed then
		container:node(RowWidget.make('Closed', args.closed or 'TBD'))	
	end
	
	if args.opened then
		container:node(RowWidget.make('Opened', args.opened))
	end
	
	if args.type then
		container:node(RowWidget.make('Type', args.type))
	end
	
	if args.country then
		container:node(RowWidget.make('Location', LocationWidget.make(args.country, args.city, 'Locations', args.state)))
	end
	
	if args.address then
		container:node(RowWidget.make('Address', args.address))
	end
	
	if args.capacity then
		container:node(RowWidget.make('Capacity', args.capacity))
	end
	
    
	if args.franchise then
        container:node(RowWidget.make('Franchise', args.franchise, frame, 'Companies/' ))
        if  args.nosponsors == 'No' then
		    local tables = 'Sponsors'
		    local fields = 'id, startRef, startRefName, endRef, endRefName'
		    local cargoArgs = {
			    where = '_pageName="Companies/' ..args.franchise .. '"'
		    }
		    local results = cargo.query(tables, fields, cargoArgs)
		    if #results > 0 then
	    	    container:node(RowWidget.make('Sponsors', SponsorsWidget.make(results, frame)))
		    end
        end
	end
	
	if args.company then
		container:node(RowWidget.make('Company', args.company, true, 'Companies/'))
	end

	if args.sponsors and args.franchise == nil then
		container:node(RowWidget.make('Sponsors', SponsorsWidget.make(args.sponsors, frame) ))
	end
	
	if args.locationsponsors then
        local text = args.sponsors ~= nil and 'Location specific sponsors' or 'Sponsors'
		container:node(RowWidget.make(text, SponsorsWidget.make(args.locationsponsors , 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