Module:Sotziedade atlètica

Dae Wikipedia, s'entziclopedia lìbera.

Documentation for this module may be created at Module:Sotziedade atlètica/doc

--[[
* Mòdulu chi implementat su template Sotziedade atlètica.
]]--

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local cfg = mw.loadData('Module:Sotziedade atlètica/Cunfiguratzione')
-- si mancat su primu argumentu
local noparamCategory = '[[Categoria:Funtzionamentos malos de su template atlètica lèbia]]'
-- si sa sotziedade dillindada no esistit
local missingCategory = '[[Categoria:Artìculos cun bandereddas de atlètica lèbia chi mancant]]'
local p = {}

local function titleExists(numene)
	local title = mw.title.new(numene)
	return title and title.exists
end

local function formatSotziedade(sotziedade, args)
	local text = ''
	if args[2] then	
		if titleExists(sotziedade.numene) then
			-- si args2 est diferente dae 'nùmene' creat unu piped wikilink
			if args[2] == 'nùmene' then
				text = string.format('[[%s]]', sotziedade.numene)
			else
				text = string.format('[[%s|%s]]', sotziedade.numene, args[2])
			end
		else
			text = args[2] == 'nùmene' and sotziedade.numene or args[2]
		end
	end
	return string.format('[[File:%s|20px|border]] %s', sotziedade.bandera, text)
end

-- Entry-point pro su template {{Sotziedade atlètica}}
function p.main(frame)
	local args = getArgs(frame, {parentOnly = true})
	local ns0 = mw.title.getCurrentTitle().namespace == 0
	local ret

	local sotziedade = cfg.sotziedade[cfg.alias[args[1]] or args[1]]
	if sotziedade then
		ret = formatSotziedade(sotziedade, args) ..
			  ((args.cat and sotziedade.categoria and ns0) and
			  	string.format('[[Categoria:%s]]', sotziedade.categoria) or '')
	else
		ret = '[[File:Flag of None.svg|20px|border]] ' .. 
			  (args[2] == 'nùmene' and (args[1] or '') or (args[2] or '')) ..
			  (ns0 and missingCategory or '')
	end

	return ret .. ((not args[1] and ns0) and noparamCategory or '')
end

return p