Modulo:FictionTV: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
per neutralizzare altro errore comune
m modulo no globals obsoleto
 
(24 versioni intermedie di 3 utenti non mostrate)
Riga 3:
]]--
 
require('Modulo:No globalsstrict')
 
local getArgs = require('Modulo:Arguments').getArgs
Riga 9:
local p = {}
 
-- Parsifica il parametro annoprimatvanno prima visione
local function parse_annoprimatvannoprimavisione(annoprimatvanno)
local inizio, produzione, incorso, fine, err
 
-- annoprimatvfiction senzatrasmesse in un solo intervalloanno, esempio "2010" o "[[2010]]" (con o senza wikilink)
inizioif = annoprimatvanno:match('^%[?%[?(%d+)%d%d%d%]?%]?$') then
inizio = anno:match('^%[?%[?(%d%d%d%d)%]?%]?$')
-- altrimenti è un intervallo tipo "[[2010]]-[[2015]]" o "[[2010]] - in produzione"
if fine not= inizio then
-- fiction trasmesse su più anni, esempio "[[2010]]-[[2015]]" (con o senza wikilink)
inizio = annoprimatv:match('^%[?%[?(%d+)%]?%]?%s*[–-]')
elseif mw.ustring.match(anno, '^%[?%[?%d%d%d%d%]?%]?%s*[–-]%s*%[?%[?%d%d%d%d%]?%]?$') then
produzione = annoprimatv:match('produzione$')
inizio, fine = mw.ustring.match(anno, '^%[?%[?(%d%d%d%d)%]?%]?%s*[–-]%s*%[?%[?(%d%d%d%d)%]?%]?$')
incorso = annoprimatv:match('corso$')
-- fiction in corso "[[2010]] - in produzione/corso" (con o senza wikilink)
fine = annoprimatv:match('^%[?%[?%d+%]?%]?%s*[–-]%s*%[?%[?(%d+)%]?%]?$')
elseif mw.ustring.match(anno, '^%[?%[?%d%d%d%d%]?%]?%s*[–-]%s*in produzione$') or
mw.ustring.match(anno, '^%[?%[?%d%d%d%d%]?%]?%s*[–-]%s*in corso$') then
inizio = anno:match('^%[?%[?(%d%d%d%d)%]?%]?')
produzione = ' – in produzione'
end
 
-- verifica chel'anno di debutto sia rilevato e gli anni di inizio e fine siano compresi tra 18801900 e 20302050
inizio = inizio and tonumber(inizio)
fine = fine and tonumber(fine)
if not inizio or (inizio and (inizio <= 18801900 or inizio >= 2030))2050 or
(fine and not produzione and not incorso and (fine <= 18801900 or fine >= 20302050)) then
err = true
end
 
return inizio, produzione, incorso, fine, err
end
 
-- Funzione per {{#invoke:FictionTV|categorie_anno}}
-- Restituisce un formato standard per il parametro anno prima visione e le categorie
function p.categorie_anno(frame)
local args, inizio, produzione, incorsofine, finetipofiction, err, cat, finecat
local ret = {}
 
args = getArgs(frame, { parentOnly = true })
 
-- con il parametro nocatperanno restituisce direttamente anno prima visione
-- annoprimatv e tipofiction sono obbligatori
if args.annoprimatvnocatperanno and== args.tipofiction'sì' then
return args['anno prima visione']
inizio, produzione, incorso, fine, err = parse_annoprimatv(args.annoprimatv)
end
 
-- anno prima visione e tipo fiction sono obbligatori
if args['anno prima visione'] and args['tipo fiction'] then
inizio, produzione, fine, err = annoprimavisione(args['anno prima visione'])
tipofiction = args['tipo fiction']:lower()
else
err = true
Riga 49 ⟶ 61:
if err then
cat = errorCategory
elseif args.tipofiction == 'miniserie TVwebserie' and inizio then
-- per le webserie non sono generate categorie
elseif tipofiction == 'miniserie tv' then
cat = 'Miniserie televisive del ' .. inizio
elseif args.tipofiction == 'film TVtv' and inizio then
cat = 'Film per la televisione del ' .. inizio
elseif args.tipofiction == 'serie TVtv' then
if inizio then
cat = 'Serie televisive iniziate nel ' .. inizio
end
if inizio and not produzione and not incorso and not fine then
finecat = 'Serie televisive terminate nel ' .. inizio
elseif produzione or incorso then
finecat = 'Serie televisive in produzione'
elseif fine then
finecat = 'Serie televisive terminate nel ' .. fine
end
elseif args.tipofiction == 'serial TVtv' then
if inizio then
cat = 'Serial televisivi iniziati nel ' .. inizio
end
if inizio and not produzione and not incorso and not fine then
finecat = 'Serial televisivi terminati nel ' .. inizio
elseif produzione or incorso then
finecat = 'Serial televisivi in produzione'
elseif fine then
Riga 77 ⟶ 87:
end
 
if mw.title.getCurrentTitle().namespace == 0 or args.debug then
cat = cat and string.format('[[Categoria:%s]]', cat) or ''
if cat then
finecat = finecat and string.format('[[Categoria:%s]]', finecat) or ''
table.insert(ret, string.format('[[Categoria:%s]]', cat))
 
end
return cat .. finecat
if finecat then
end
table.insert(ret, string.format('[[Categoria:%s]]', finecat))
 
end
-- Funzione per {{#invoke:FictionTV|visualizzazione_anno}}
function p.visualizzazione_anno(frame)
local args, inizio, produzione, incorso, fine, err, annoinizio, annofine, inproduzione
 
args = getArgs(frame, { parentOnly = true })
if args.annoprimatv and args.tipofiction then
inizio, produzione, incorso, fine, err = parse_annoprimatv(args.annoprimatv)
else
err = true
end
if inizio then
table.insert(ret, string.format('[[%s]]', inizio))
if err then
cat = errorCategory
elseif inizio then
annoinizio = inizio
end
if fine and fine ~= inizio then
table.insert(ret, string.format('-[[%s]]', fine))
annofine = fine
elseif produzione or incorso then
inproduzione = ' – in produzione'
end
if produzione then
table.insert(ret, produzione)
annoinizio = annoinizio and string.format('[[%s]]', annoinizio) or ''
annofine = annofine and string.format('-[[%s]]', annofine) or ''
inproduzione = inproduzione and string.format('%s', inproduzione) or ''
 
return annoinizio,annofine,inproduzione
end
 
-- Gestione parametro tipocolore
local function parse_tipocolore(tipocolore)
local colore, BN, nero
colore=tipocolore:match('[Cc]olor')
BN=tipocolore:match('[Bb]%/?[Nn]')
nero=tipocolore:match('nero')
return colore, BN, nero
end
 
function p.tipo_colore(frame)
local args, colore, BN, nero, acolori, biancoenero, misto
 
args = getArgs(frame, { parentOnly = true })
if args.tipocolore then
colore, BN, nero = parse_tipocolore(args.tipocolore)
end
if colore and not BN and not nero then
acolori = '[[Televisione a colori|a colori]]'
elseif BN or nero and not colore then
biancoenero = '[[Bianco e nero|B/N]]'
elseif BN or nero and colore then
misto= '[[Televisione a colori|a colori]] e [[Bianco e nero|B/N]]'
end
acolori = acolori and string.format('%s', acolori) or ''
biancoenero = biancoenero and string.format('%s', biancoenero) or ''
misto = misto and string.format('%s', misto) or ''
 
return args.debug and table.concat(ret):gsub('%[%[Cat(.-)%]%]', '[[:Cat%1]]<br />') or
return acolori, biancoenero, misto
table.concat(ret)
end