Module:Immàgine sinòticu

Dae Wikipedia, s'entziclopedia lìbera.

Documentation for this module may be created at Module:Immàgine sinòticu/doc

--[[
* Mòdulu chi implementat su template Immàgine sinòticu.
]]--

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local mWikidata = require('Module:Wikidata')
local catCumpatibile = '[[Categoria:Sinòticos cun immàgines formatadas a manu]]'
local catNonCumpatibile = '[[Categoria:Sinòticos cun immàgines cun una furmatatzione ridondante]]'
local catDidascalia = '[[Categoria:Artìculos cun template Immàgine sinòticu cun didascalia e immàgine leghida dae Wikidata]]'
local p = {}

local function formatImage(file, args)
	local dim = args.dim_utente and
				math.min(args.dim_utente, args.dim_max or args.dim or 260) or
				(args.dim or 260)
	return string.format('[[File:%s|frameless|center|%sx%spx%s%s]]',
						  file, dim, args.dim_vert_max or 300,
						  args.alt and '|alt=' .. args.alt or '',
						  args.desc and '|' .. args.desc or '')
end

-- Pro s'impreu dae un'àteru Mòdulu
function p._main(args)
	local userval, wdval, ret

	-- evitat leghiduras non cheridas dae wikidata
	if args[1] == 'no' then return '' end

	-- verìfica cuadras in prus
	if args[1] and args[1]:sub(1, 1) == '[' then
		local ns0 = mw.title.getCurrentTitle().namespace == 0
		-- cun args.cumpatibile frunit diretamente args[1] e args[2]
		if args.cumpatibile then
			local cat = ns0 and catCumpatibile or ''
			return args[1] .. (args[2] and ('<br />' .. args[2]) or '') .. cat
		elseif ns0 then
			ret = catNonCumpatibile
		end
	end

	args.dim = tonumber(args.dim)
	args.dim_max = tonumber(args.dim_max)
	args.dim_utente	= args.dim_utente and tonumber(mw.text.split(args.dim_utente, 'px')[1])
	args.dim_vert_max = tonumber(args.dim_vert_max)

	-- valore impitadore e wikidata
	userval = args[1]
	if not userval and args['propiedade'] then
		wdval = mWikidata._getProperty({ args['propiedade'], n = 1 })
	end

	-- formatat s'immàgine
	if userval or wdval then
		ret = (ret or '') .. formatImage(userval or wdval, args)
	end

	-- didascalia
	if userval then
		ret = ret .. (args[2] or '')
	elseif wdval then
		-- si s'immàgine benit lèghida dae Wikidata sa didascalia podet èssere otènnida
		-- petzi dae su cualificadore P2096, si nono at a frunire una categoria de faddina
		ret = ret .. (mWikidata._getQualifier({ args['propiedade'], 'P2096', includelang = 'sc', n = 1 }) or '')
	end

	return (ret or '') .. ((args[2] and wdval and not userval) and catDidascalia or '')
end

-- Funtzione pro su template {{Immàgine sinòticu}}
function p.main(frame)
	return p._main(getArgs(frame, { parentOnly = true }))
end

return p