Jump to content

Module:National squad

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 14:43, 12 October 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module implements [[Template:National squad]] to avoid articles being
-- added to [[:Category:Pages where template include size is exceeded]]
-- when the template is used many times.
local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local country = args.country or '{{{country}}}'
	local comp = args.comp or '{{{comp}}}'
	local name = args.name or ''
	local gender = (args.gender or '') == 'female' and ' women\'s' or ''
	local titlestyle = 'background-color:' .. (args.bg or 'transparent') .. ';'
		.. 'color:' .. (args.fg or 'inherit') .. ';' 
		.. 'border: 1px solid ' .. (args.bordercolor or '#aaa') .. ';'
	local image = frame:expandTemplate{
		title = 'flagicon', 
		args = {args.country or 'none', args.flagvar or '', size = '50px'}
	}

	local ospan = '<span style="color:' .. (args.fg or 'inherit') .. '">'
	local cspan = '</span>'	
	local title = string.format('[[%s|%s%s%s]] – [[%s|%s%s%s]]', 
		args.teamlink or (country .. gender .. ' national football team'), 
		ospan, args.title or country .. ' squad', cspan, 
		args['comp link'] or comp, ospan, comp, cspan)
	
	local list1 = args.list or ''
	if list1 == '' then
		for k = 1,25 do
			if args['p' .. k] and args['p' .. k] ~= '' then
				list1 = list1 .. string.format(
					'*<small>%d</small>&nbsp;<span class="vcard agent"><span class="fn">%s</span></span>\n',
					k, args['p' .. k])
			end
		end
		if args['coach'] and args['coach'] ~= '' then
			list1 = list1 .. string.format(
				'*<span class="vcard agent"><small class="role">Coach:</small>&nbsp;<span class="fn">%s</span></span>',
				args['coach'])
		end
	end
	local list3 = args.note and ('<small>' .. args.note .. '</small>') or nil
	
	-- Tracking and preview warnings
	local knownargs = {['bg']=1, ['fg']=1, ['bordercolor']=1, ['coach']=1, 
		['comp']=1, ['comp link']=1, ['country']=1, ['flagvar']=1, ['gender']=1, 
		['list']=1, ['name']=1, ['note']=1, ['team link']=1, ['title']=1,
		['p1']=1,['p2']=1,['p3']=1,['p4']=1,['p5']=1,['p6']=1,['p7']=1,['p8']=1,
		['p9']=1,['p10']=1,['p11']=1,['p12']=1,['p13']=1,['p14']=1,['p15']=1,
		['p16']=1,['p17']=1,['p18']=1,['p19']=1,['p20']=1,['p21']=1,['p22']=1,
		['p23']=1,['p24']=1,['p25']=1}
	local badargs = {}
	for k, v in pairs(args) do
		if v and v ~= '' and knownargs[k] == nil then
				table.insert(badargs, k)
		end
	end
	local preview, tracking = '', ''
	if #badargs > 0 then
		for k, v in pairs(badargs) do
			if v == '' then	v = ' '	end
			v = mw.ustring.gsub(v, '[^%w\-_ ]', '?')
			preview = preview .. '<div class="hatnote" style="color:red"><strong>Warning:</strong> '
				.. 'Page using national squad with unknown parameter "' .. v 
				.. '" (this message is shown only in preview).</div>'
			tracking = tracking .. '[[Category:Pages using national squad with unknown parameters|' .. v .. ']]'
		end
		if frame:preprocess( "{{REVISIONID}}" ) ~= "" then
			preview = ''
		end
	end
	if args.country == nil  or args.comp == nil then
		tracking = tracking .. '[[Category:Pages using national squad with unknown parameters|!]]'
	end
	if tracking ~= '' and mw.title.getCurrentTitle().namespace > 0 then tracking = '' end
	return require('Module:Navbox')._navbox({
		name = name ~= '' and name or nil,
		bodystyle = 'text-align: center; clear: both;',
		titlestyle = titlestyle, 
		listclass = 'hlist', bodyclass = 'vcard', titleclass = 'fn org',
		image = image, title = title, list1 = list1, list3 = list3
	}) .. tracking .. preview
end

return p