Modulo:StagioniTV/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica
prova 00981
Riga 6:
local getArgs = require('Modulo:Arguments').getArgs
local errorCategory = '[[Categoria:Errori di compilazione del template Stagioni televisive]]'
local cfg = mw.loadData('Modulo:StagioniTV/Configurazione')
local p = {}
 
Riga 27 ⟶ 28:
local lang = mw.language.getContentLanguage()
local sep = '&nbsp;<b>&middot;</b>&#32;'
if localIDcfg.id[args[1]] ~= nil then
id = cfg.id[args[1]]
tipo = cfg.tipo[args[1]]
etichetta = cfg.etichetta[args[1]]
nome = cfg.nome[args[1]]
preposizione = cfg.preposizione[args[1]]
sitelink = cfg.sitelink[args[1]]
stagioni = cfg.stagioni[args[1]]
else
 
-- Rileva l'identificativo della scheda wikidata collegata alla fiction o al programma TV,
-- se nessun titolo è specificato prova a recuperlo dalla voce della stagione/edizione, se questa ha una sua scheda su wikidata
if not args[1] or args.titolo then
if string.find(mw.title.getCurrentTitle().text, '^Episodi d[ei]') then
localID = wikidata._getProperty({ 'P361', n = 1, from = mw.wikibase.getEntityIdForCurrentPage(), formatting = 'raw' })
localID2 = wikidata._getProperty({ 'P179', n = 1, from = mw.wikibase.getEntityIdForCurrentPage(), formatting = 'raw' })
end
elseif if localID2localID ~= nil then
id = localID
elseif localID2 ~= nil then
id = localID2
end
else
id = mw.wikibase.getEntityIdForTitle( pageTitle )
end
if localID ~= nil then
id = localID
elseif localID2 ~= nil then
id = localID2
end
else
id = mw.wikibase.getEntityIdForTitle( pageTitle )
end
 
-- Identifica il tipo di programma (serie televisiva, serie animata o programma TV generico)
-- ed estrae gli altri dati fondamentali da Wikidata (etichetta in italiano, numero stagioni, sitelink)
-- se uno di essi non è presente è generato un messaggio di errore
local genere = wikidata._getProperty({ 'P136', from = id, formatting = 'raw' })
if wikidata._instanceOf({ 'Q581714', from = id }) or genere ~= nil and string.find(genere, 'Q581714') then
tipo = 'animata'
elseif wikidata._instanceOf({ 'Q5398426', from = id }) then
tipo = 'serie TV'
elseif wikidata._instanceOf({ 'Q15416', from = id }) then
tipo = 'programma'
elseif wikidata._instanceOf({ 'Q526877', from = id }) then
tipo = 'serie TV'
end
if id then
titolo = wikidata._getLink({ id })
etichetta = wikidata._getLabel({ id, 'it'})
sitelink = mw.wikibase.sitelink( id )
stagioni = wikidata._getProperty({ 'P2437', n = 1, from = id, formatting = 'raw' })
else
errore = 'Template non compilato correttamente, controlla le [[Template:Stagioni televisive|istruzioni]]'
end
 
-- Questa parte del codice genere i collegamenti alle singole edizioni/stagioni e la relativa categoria
if not etichetta or not sitelink or not stagioni or not tipo then
errore = 'Template non compilato correttamente, controlla le [[Template:Stagioni televisive|istruzioni]]'
else
---- per rendere l'uso del template più leggero prova a estrarre il nome del programma e la preposizione usata nei link direttamente
---- dalle voci in cui è usato, altrimenti verifica l'esistenza della voce della prima stagione con la sintassi standard
if tipo == 'programma' then
if args[2] ~= 'elenco' and string.find(mw.title.getCurrentTitle().text, '^.+%(%a+edizione%)$') then
nome = string.match(mw.title.getCurrentTitle().text, '^(.+) %(%a+edizione%)$')
preposizione = mw.title.new(string.format('Categoria:Edizioni de %s', nome)).exists and 'de' or 'di'
elseif mw.title.new(string.format('%s (prima edizione)', etichetta)).exists then
nome = etichetta
preposizione = mw.title.new(string.format('Categoria:Edizioni de %s', etichetta)).exists and 'de' or 'di'
else
nome = sitelink
preposizione = mw.title.new(string.format('Categoria:Edizioni de %s', sitelink)).exists and 'de' or 'di'
end
elseif tipo == 'serie TV' or tipo == 'animata' then
if args[2] ~= 'elenco' and string.find(mw.title.getCurrentTitle().text, '^Episodi d[ei] ') then
if string.find(mw.title.getCurrentTitle().text, '^Episodi d[ei].+stagione%)$') then
nome = string.match(mw.title.getCurrentTitle().text, '^Episodi d[ei] (.+) %(%a+ stagione%)$')
preposizione = string.match(mw.title.getCurrentTitle().text, '^Episodi (d[ei])')
elseif string.find(mw.title.getCurrentTitle().text, '^Episodi d[ei].+$') then
nome = string.match(mw.title.getCurrentTitle().text, '^Episodi d[ei] (.+)$')
preposizione = string.match(mw.title.getCurrentTitle().text, '^Episodi (d[ei])')
end
elseif mw.title.new(string.format('Episodi di %s (prima stagione)', etichetta)).exists then
nome = etichetta
preposizione = 'di'
elseif mw.title.new(string.format('Episodi de %s (prima stagione)', etichetta)).exists then
nome = etichetta
preposizione = 'de'
else
nome = sitelink
preposizione = mw.title.new(string.format('Episodi de %s (prima stagione)', sitelink)).exists and 'de' or 'di'
end
elseif mw.title.new(string.format('Episodi di %s (prima stagione)', etichetta)).exists then
nome = etichetta
preposizione = 'di'
elseif mw.title.new(string.format('Episodi de %s (prima stagione)', etichetta)).exists then
nome = etichetta
preposizione = 'de'
else
nome = sitelink
preposizione = mw.title.new(string.format('Episodi de %s (prima stagione)', sitelink)).exists and 'de' or 'di'
end
end
end
 
---- qui vengono generati i link alle stagioni/edizioni e la categoria appropriata
if not etichetta or not sitelink or not stagioni or not tipo then
errore = 'Template non compilato correttamente, controlla le [[Template:Stagioni televisive|istruzioni]]'
else
for i = 1, stagioni do