Modulo:Tassobox/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
Moroboshi (discussione | contributi)
avevo modificato una vecchia versione
 
(33 versioni intermedie di 3 utenti non mostrate)
Riga 1:
--[[
Questo modulo è in appoggio al template Tassobox, per il richiamo di un'immagine
di file mancante appropriata al regno/phylum/classe/ordine/ecc della voce in cui è inserito
]]
 
local p = {}
 
local cfg = mw.loadData("Modulo:Tassobox/Configurazione")
local getArgs = require('Module:Arguments').getArgs
 
local function check_value(valore)
return valore returnand cfg.missing_table[mw.ustring.lower(valore)]
if valore == nil then
return nil
else
return cfg.missing_table[mw.ustring.lower(valore)]
end
end
 
--===================================================================
----------------------------------------------------------------------------------
-- Ritorna il nomeRichiamo di un'immagine dadi utilizzarefile se manca l'immaginemancante perappropriata ilal tassobox
di file mancante appropriata al-- regno/phylum/classe/ordine/ecc della voce in cui è inserito
----------------------------------------------------------------------------------
-- il tassobox
--===================================================================
function p.missing_image(frame)
local args = getArgs(frame, {wrapper = 'Template:Tassobox'})
-- Richiama i parametri originali del template
local missing_link
local pframe = frame:getParent()
-- testa in ordine dal più specifico al più generico la classificazione di un essere vivente
for _,test in ipairs(cfg.param_to_check) do
-- se non trova il valore nella tabella ricade nell'immagine di default
missing_link = args[test] and check_value(args[test])
missing_link = check_value(pframe.args["sottordine"]) or check_value(pframe.args["superordine"]) or check_value(pframe.args["ordine"]) or check_value(pframe.args["classe"]) or check_value(pframe.args["superclasse"]) or
if missing_link then break end
check_value(pframe.args["subphylum"]) or check_value(pframe.args["phylum"]) or check_value(pframe.args["divisione"]) or
end
check_value(pframe.args["regno"]) or check_value(pframe.args["dominio"]) or "File:Unknown missing 1.png"
-- se ha non trovatrovato il valore nella tabella ricade nell'immagine di default
return '[[' .. missing_link ..'|220px|Immagine di ' .. mw.title.getCurrentTitle().text .. ' mancante]]'
missing_link = missing_link or "File:Unknown missing 1.png"
return mw.ustring.format('[[' .. missing_link ..'%s|220px|Immagine di %s mancante]]', missing_link, .. mw.title.getCurrentTitle().text .. ' mancante]]')
end
 
Line 36 ⟶ 35:
-- Restituisce una tabella delle ere geologiche presenti in configurazione
local root = mw.html.create('table')
root
:addClass('wikitable sortable')
:tag('tr')
:tag('th'):wikitext('Era'):done()
:tag('th'):wikitext('Inizio'):done()
:tag('th'):wikitext('Successiva'):done()
:tag('th'):wikitext('Colore'):done()
for name, values in pairs(cfg.ere_geologiche) do
local start = values['start'] or "-?"
local next_era = values['next_era'] or "-?"
local color = "-"
if values['color'] then
color = mw.html.create('span')
color = :cssText("display:inline-block;border:solid grey 1px;backgroundwidth:".. values['color'] .. "1em;height:1em")
end
:css('background', values['color'])
root:tag('tr')
:wikitext(' ')
:tag('td'):wikitext(start):done()
else
:tag('td'):wikitext(next_era):done()
color = :tagmw.html.create('tdspan'):wikitext(color):done()
end
root:tag('tr')
:tag('td'):wikitext(startname):done()
:tag('td'):css('text-align', 'right'):wikitext(start):done()
:tag('td'):wikitext(next_era):done()
:tag('td'):css('text-align', 'center'):node(color)
end
return tostring(root)
end
 
--===================================================================
-- Genera lo stato di conservazione di uno specie
--===================================================================
function p.stato_conservazione(frame)
 
local args = getArgs(frame, {wrapper = 'template:Tassobox'})
return tostring(root)
local statocons = args.statocons
if statocons == nil then return end
local iucn = { ['iucn2.3'] = true, ['iucn3.1'] = true}
statocons = mw.ustring.lower(statocons)
statocons = cfg.stato_alias[statocons] or statocons
local row_stato = cfg.stato[statocons]
if valorerow_stato == nil then
local cat_error = ''
if mw.title.getCurrentTitle().namespace == 0 then
cat_error = '[[Categoria:Errori di compilazione del template Tassobox]]'
end
return '<strong class=\"error\">Parametro statocons non valido</div>' .. cat_error
end
local immagine = ''
if row_stato.image then
if row_stato.versione then
local versione = args.statocons_versione or ''
versione = (iucn[versione] and versione) or (statocons == 'ex' and 'none') or 'iucn3.1'
if versione == 'none' then
immagine = 'Status_none_EX.svg'
else
immagine = mw.ustring.format(row_stato.image, versione)
end
else
immagine = row_stato.image
end
immagine = '<div>\[\[Image:' .. immagine .. '|200px\]\]</div>'
end
local ref = args.statocons_ref
ref = (ref and '<span style=font-size:80%>' .. ref .. '</span>') or ''
local dataestinzione = ''
if row_stato.data then
dataestinzione = (row_stato.pre_data and ' ' .. row_stato.pre_data) or dataestinzione
dataestinzione = (args.dataestinzione and mw.ustring.format(row_stato.data, args.dataestinzione)) or dataestinzione
dataestinzione = mw.ustring.format('<span style="color:%s;">%s</span>', row_stato.color_data or row_stato.color, dataestinzione)
end
local base_msg =
'<div style="margin:0 auto; text-align:center;%s">'..
'%s<div style="color:%s;font-weight:bold;">%s%s%s</span></div>' ..
'</div>'
return mw.ustring.format(base_msg, ((immagine and 'background:white;') or ''), immagine, row_stato.color, row_stato.text, dataestinzione, ref)
end