Modulo:Immagine sinottico

Info Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Immagine sinottico/man (modifica · cronologia)
Sandbox: Modulo:Immagine sinottico/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Immagine sinottico/test (modifica · cronologia · esegui)

Modulo che implementa il template {{Immagine sinottico}}.



--[[
* Modulo che implementa il template Immagine sinottico.
]]--

require('strict')

local getArgs = require('Modulo:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
local catCompatibile = '[[Categoria:Sinottici con immagini formattate a mano]]'
local catNonCompatibile = '[[Categoria:Sinottici con immagini con formattazione ridondante]]'
local catDidascalia = '[[Categoria:Voci con template Immagine sinottico con didascalia e immagine letta da 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

-- Per l'utilizzo da altro modulo
function p._main(args)
	local userval, wdval, ret

	-- evita letture indesiderate da wikidata
	if args[1] == 'no' then return '' end

	-- controllo quadre in eccesso
	if args[1] and args[1]:sub(1, 1) == '[' then
		local ns0 = mw.title.getCurrentTitle().namespace == 0
		-- con args.compatibile restituisce direttamente args[1] e args[2]
		if args.compatibile then
			local cat = ns0 and catCompatibile or ''
			return args[1] .. (args[2] and ('<br />' .. args[2]) or '') .. cat
		elseif ns0 then
			ret = catNonCompatibile
		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 utente e wikidata
	userval = args[1]
	if not userval and args['proprietà'] then
		wdval = mWikidata._getProperty({ args['proprietà'], n = 1 })
	end

	-- formatta l'immagine
	if userval or wdval then
		ret = (ret or '') .. formatImage(userval or wdval, args)
	end

	-- didascalia
	if userval then
		ret = ret .. (args[2] or (args.didascalia_default or ''))
	elseif wdval then
		-- se l'immagine è letta da Wikidata la didascalia può essere ottenuta
		-- solo dal qualificatore P2096, altrimenti restituirà una categoria di errore
		ret = ret .. (mWikidata._getQualifier({ args['proprietà'], 'P2096', includelang = 'it', n = 1 }) or (args.didascalia_default or ''))
	end

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

-- Funzione per il template {{Immagine sinottico}}
function p.main(frame)
	return p._main(getArgs(frame, { parentOnly = true }))
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.