Module:NewsSource

From TwogPedia
Revision as of 11:00, 8 May 2023 by 176.46.108.72 (talk)

Documentation for this module may be created at Module:NewsSource/doc

local getArgs = require('Module:Arguments').getArgs
local NewsSource = {}
local cargo = mw.ext.cargo

function NewsSource.main(frame)
	local args = getArgs(frame)
	
	local span = mw.html.create('span')
	
	local currentDate = os.date('%Y-%m-%d')
	local tables = 'Logos'
	local fields = '_pageName, logoLight, logoDark, logoAll, start, end, iconLight, iconDark, iconAll'
	local cargoArgs = {
		where = '_pageName="Company/' .. args.source .. '" 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
		local result = results[1]
		local icon = result.iconAll or result.iconLight or result.iconDark or result.logoAll or result.logoLight or result.logoDark or 'Team placeholder light.png'
		span:wikitext('[[File:' .. icon .. '|30px|link=' .. args.url .. ']]')
	else 
		span:wikitext('[[File:' .. args.source .. '|30px|link=' .. args.url .. ']]')
	end
	return span
end

return NewsSource