Modulo:Tracce: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Contenuto cancellato Contenuto aggiunto
m Modificato il livello di protezione per "Modulo:Tracce": Template o modulo usato in maniera estensiva: protezione totale ([Modifica=Consentito solo agli amministratori] (infinito) [Spostamento=Consentito solo agli amministratori] (infinito)) |
indentazione con tab; aggiungo categorie di errore e di tracciamento; abilito numerazione discontinua (vedi discussione) |
||
Riga 1: | Riga 1: | ||
local categories = {} |
|||
-- Protects a string that will be wrapped in wiki italic markup '' ... '' |
|||
local discontinuous_num = '[[Categoria:Voci con template Tracce con numerazione discontinua]]' |
|||
local function safeforitalics( str ) |
|||
local missing_title = '[[Categoria:Voci con template Tracce con titolo mancante]]' |
|||
--[[ Note: We can not use <i> for italics, as the expected behavior for |
|||
local unexpected_markup = '[[Categoria:Voci con template Tracce con markup inaspettato]]' |
|||
italics specified by ''...'' in the title is that they will be inverted |
|||
local unknown_format = '[[Categoria:Voci con template Tracce con formato durata sconosciuto]]' |
|||
(i.e. unitalicized) in the resulting references. In addition, <i> and '' |
|||
tend to interact poorly under Mediawiki's HTML tidy. ]] |
|||
-- Protegge una stringa che sarà avvolta dal markup wiki '' ... '' del corsivo |
|||
if str == nil or str == '' then |
|||
local function safeforitalics(str) |
|||
return str; |
|||
if str:sub(1,1) == "'" then str = "<span></span>" .. str end |
|||
else |
|||
if str:sub(-1,-1) == "'" then str = str .. "<span></span>" end |
|||
return str |
|||
if str:sub(-1,-1) == "'" then str = str .. "<span></span>"; end |
|||
end |
|||
return str; |
|||
end |
|||
-- Calcola e formatta la durata di una traccia |
|||
local function getTrackLength(args, i) |
|||
local string_durata = args["Durata" .. i] |
|||
local minuti, secondi |
|||
if string_durata then |
|||
local string_minuti, string_secondi = mw.ustring.match(string_durata, "^(%d+):(%d%d)$") |
|||
minuti = tonumber(string_minuti) |
|||
secondi = tonumber(string_secondi) |
|||
else |
|||
minuti = tonumber(args["Minuti" .. i]) |
|||
secondi = args["Secondi" .. i] and mw.ustring.match(args["Secondi" .. i], "^%d%d?$") and |
|||
tonumber(args["Secondi" .. i]) |
|||
end |
|||
local durata = (minuti or 0) * 60 + (secondi or 0) |
|||
if (string_durata and durata == 0) or (not minuti and args["Minuti" .. i]) or |
|||
(not secondi and args["Secondi" .. i]) then |
|||
categories[#categories+1] = unknown_format |
|||
end |
|||
return durata, durata > 0 and string.format("%d:%02.f", minuti or 0, secondi or 0) or nil |
|||
end |
end |
||
Riga 20: | Riga 38: | ||
]]-- |
]]-- |
||
local function track(args, i, |
local function track(args, i, durata) |
||
local titolo = args["Titolo" .. i] |
|||
local row_elements = {} |
|||
if titolo ~="" then |
|||
table.insert(row_elements, '<li value="' .. tostring(i) .. '">') |
|||
local row_elements = {} |
|||
local interprete = args["Interprete" .. i] |
|||
table.insert(row_elements, '<li value="' .. tostring(i) .. '">') |
|||
if interprete then table.insert(row_elements, interprete .. " – ") end |
|||
local corsivo = args["Corsivo"] ~= "no" and true or false |
|||
if interprete ~= "" then table.insert(row_elements, interprete .. " – ") end |
|||
corsivo = (corsivo and args["Corsivo" .. i] ~= "no") or |
|||
(not corsivo and (args["Corsivo" .. i] == "sì" or args["Corsivo" .. i] == "si")) |
|||
if titolo:find(corsivo and "''" or "'''") then |
|||
categories[#categories+1] = unexpected_markup |
|||
end |
|||
end |
|||
table.insert(row_elements, titolo) |
|||
if corsivo then |
|||
local featuring = args["Featuring" .. i] or "" |
|||
titolo = "''" .. safeforitalics(titolo) .. "''" |
|||
if featuring ~= "" then table.insert(row_elements, " <small>(feat. " .. featuring .. ")</small>") end |
|||
end |
|||
local note = args["Note" .. i] or "" |
|||
table.insert(row_elements, titolo) |
|||
local featuring = args["Featuring" .. i] |
|||
if featuring then table.insert(row_elements, " <small>(feat. " .. featuring .. ")</small>") end |
|||
if string_durata then |
|||
local note = args["Note" .. i] |
|||
local string_minuti, string_secondi = mw.ustring.match(string_durata, "(%d+):(%d%d)") |
|||
if note then table.insert(row_elements, " <small>(" .. note .. ")</small>") end |
|||
minuti = tonumber(string_minuti) or 0 |
|||
if durata then |
|||
secondi = tonumber(string_secondi) or 0 |
|||
table.insert(row_elements, " – ") |
|||
else |
|||
table.insert(row_elements, durata) |
|||
minuti = tonumber(args["Minuti" .. i]) or 0 |
|||
end |
|||
secondi = tonumber(args["Secondi" .. i]) or 0 |
|||
local AutoreTesto = args["Autore testo" .. i] |
|||
end |
|||
local AutoreMusica = args["Autore musica" .. i] |
|||
local durata = minuti * 60 + secondi |
|||
local AutoreTestoeMusica = args["Autore testo e musica" .. i] |
|||
if durata > 0 then |
|||
local edizioni = args["Edizioni" .. i] |
|||
table.insert(row_elements, " – ") |
|||
local no_autore = false |
|||
table.insert(row_elements, string.format("%d:%02.f", minuti, secondi)) |
|||
if AutoreTestoeMusica then |
|||
end |
|||
table.insert(row_elements, " <small>(" .. AutoreTestoeMusica ) |
|||
local AutoreTesto = args["Autore testo" .. i] or "" |
|||
elseif AutoreTesto then |
|||
local AutoreMusica = args["Autore musica" .. i] or "" |
|||
table.insert(row_elements, " <small>(testo: " .. AutoreTesto) |
|||
local AutoreTestoeMusica = args["Autore testo e musica" .. i] or "" |
|||
if AutoreMusica then |
|||
local edizioni = args["Edizioni" .. i] or "" |
|||
table.insert(row_elements, " – musica: " .. AutoreMusica) |
|||
local no_autore = false |
|||
end |
|||
if AutoreTestoeMusica ~= "" then |
|||
elseif AutoreMusica then |
|||
table.insert(row_elements, " <small>(" .. AutoreTestoeMusica ) |
|||
table.insert(row_elements, " <small>(musica: " .. AutoreMusica) |
|||
elseif AutoreTesto ~= "" then |
|||
else |
|||
table.insert(row_elements, " <small>(testo: " .. AutoreTesto) |
|||
no_autore = true |
|||
if AutoreMusica ~="" then |
|||
end |
|||
table.insert(row_elements, " – musica: " .. AutoreMusica) |
|||
if edizioni then |
|||
end |
|||
if no_autore then |
|||
elseif AutoreMusica ~= "" then |
|||
table.insert(row_elements, " <small>(") |
|||
else |
|||
table.insert(row_elements, "; ") |
|||
no_autore = true |
|||
end |
|||
table.insert(row_elements, "edizioni musicali " .. edizioni .. ")</small>") |
|||
if edizioni ~= "" then |
|||
elseif not no_autore then |
|||
table.insert(row_elements, ")</small>") |
|||
end |
|||
else |
|||
local extra = args["Extra" .. i] |
|||
table.insert(row_elements, "; ") |
|||
if extra then table.insert(row_elements, " – " .. extra) end |
|||
end |
|||
table.insert(row_elements, "</li>\n") |
|||
local ListaMedley = args["ListaMedley" .. i] |
|||
elseif not no_autore then |
|||
if ListaMedley then table.insert(row_elements, '<div style="padding: 0.3em 0px 0.5em 2.5em;">\n' .. ListaMedley .. '</div>') end |
|||
table.insert(row_elements, ")</small>") |
|||
return table.concat(row_elements), durata |
|||
end |
|||
local extra = args["Extra" .. i] or "" |
|||
if extra ~= "" then table.insert(row_elements, " – " .. extra) end |
|||
table.insert(row_elements, "</li>\n") |
|||
local ListaMedley = args["ListaMedley" .. i] or "" |
|||
if ListaMedley ~= "" then table.insert(row_elements, '<div style="padding: 0.3em 0px 0.5em 2.5em;">\n' .. ListaMedley .. '</div>') end |
|||
return table.concat(row_elements), durata |
|||
else |
|||
return nil |
|||
end |
|||
end |
end |
||
--[[ |
--[[ |
||
Riceve una tabella di parametri e |
Riceve una tabella di parametri e restituisce una stringa contenente |
||
l'output da inserire nella voce |
|||
]]-- |
]]-- |
||
local function componi_tracce(args |
local function componi_tracce(args) |
||
-- array per accumulare le righe della lista man mano che vengono elaborate |
|||
local tracks = {} |
|||
-- compone la testata dell'elenco tracce |
|||
local testata = "" |
|||
local no_autore = false |
|||
local autoreTestoeMusica = args["Autore testi e musiche"] |
|||
if autoreTestoeMusica then |
|||
testata = "Testi e musiche di " .. autoreTestoeMusica |
|||
else |
|||
local autoreTesti, autoreMusiche = args["Autore testi"], args["Autore musiche"] |
|||
if autoreTesti then |
|||
autoreMusiche = args["Autore musiche"] or "" |
|||
testata = "Testi di " .. autoreTesti |
|||
if autoreMusiche then testata = testata .. ", musiche di " .. autoreMusiche end |
|||
elseif autoreMusiche then |
|||
if autoreMusiche ~= "" then testata = testata .. ", musiche di " .. autoreMusiche end |
|||
testata = "Musiche di " .. autoreMusiche |
|||
else |
|||
testata = "Musiche di " .. autoreMusiche |
|||
no_autore = true |
|||
else |
|||
end |
|||
noAutore = true |
|||
end |
|||
local edizioni = args["Edizioni"] |
|||
end |
|||
if edizioni then |
|||
if no_autore then |
|||
testata = "Edizioni musicali " .. edizioni .."." |
|||
if noAutore then |
|||
else |
|||
testata = "Edizioni musicali " .. edizioni .."." |
|||
testata = testata .. "; edizioni musicali " .. edizioni .. "." |
|||
else |
|||
end |
|||
testata = testata .. "; edizioni musicali " .. edizioni .. "." |
|||
elseif not no_autore then |
|||
end |
|||
testata = testata .. "." |
|||
elseif not noAutore then |
|||
end |
|||
testata = testata .. "." |
|||
table.insert(tracks, testata) |
|||
end |
|||
-- compone la lista dei parametri |
|||
local corsivo = true |
|||
table.insert(tracks, "<ol>") |
|||
if args["Corsivo"] == "no" then |
|||
local visualizza_durata = args["Visualizza durata totale"] |
|||
corsivo = false |
|||
local durata = 0 |
|||
end |
|||
local somma_durata = false |
|||
table.insert(tracks, testata) |
|||
if visualizza_durata == "si" or visualizza_durata == "sì" then somma_durata = true end |
|||
-- compone la lista dei parametri |
|||
local nums = {} |
|||
local validated_nums = {} |
|||
table.insert(tracks, "<ol>") |
|||
for k, v in pairs(args) do |
|||
local visualizza_durata = args["Visualizza durata totale"] or "" |
|||
local prefix, num = string.match(k, '^(%D+)([0-9]+)$') |
|||
local durata = 0 |
|||
if num and (num == '0' or num:sub(1,1) ~= '0') then |
|||
local somma_durata = false |
|||
-- se il numero viene modificato da tonumber, è troppo alto |
|||
if visualizza_durata == "si" or visualizza_durata == "sì" then somma_durata = true end |
|||
num = tonumber(num) |
|||
--estrae le tracce dai parametri e inserisci i valori nella tabella tracks |
|||
if not args['Titolo' .. num] then |
|||
while true do |
|||
categories[#categories+1] = missing_title |
|||
local new_track, durata_track = track(args, i, corsivo) |
|||
end |
|||
if new_track==nil then break end |
|||
if args[prefix .. num] and not validated_nums[num] then |
|||
table.insert(tracks, new_track) |
|||
validated_nums[num] = true |
|||
if somma_durata then durata = durata + durata_track end |
|||
table.insert(nums, num) |
|||
i = i + 1 |
|||
end |
|||
end |
|||
table.insert(tracks, "</ol>") |
|||
end |
|||
if somma_durata then |
|||
table.sort(nums) |
|||
table.insert(tracks, "Durata totale: " .. string.format("%d:%02.f", math.floor(durata/60) , durata % 60) .. "</p>") |
|||
if #nums == 0 then |
|||
categories[#categories+1] = missing_title |
|||
return table.concat(tracks, "\n") |
|||
-- categoria di tracciamento se la numerazione delle tracce è discontinua |
|||
elseif nums[1] + #nums - 1 ~= nums[#nums] then |
|||
categories[#categories+1] = discontinuous_num |
|||
end |
|||
local tracce = false |
|||
-- estrae le tracce dai parametri e inserisce i valori nella tabella tracks |
|||
for k, num in ipairs(nums) do |
|||
local durata_track, durata_formattata = getTrackLength(args, num) |
|||
if args['Titolo' .. num] then |
|||
tracce = true |
|||
local new_track = track(args, num, durata_formattata) |
|||
table.insert(tracks, new_track) |
|||
end |
|||
if somma_durata then durata = durata + durata_track end |
|||
end |
|||
table.insert(tracks, "</ol>") |
|||
if somma_durata then |
|||
table.insert(tracks, "Durata totale: " .. string.format("%d:%02.f", math.floor(durata/60) , durata % 60) .. "</p>") |
|||
end |
|||
local ns = mw.title.getCurrentTitle().namespace |
|||
return (tracce and table.concat(tracks, "\n") or '') .. (ns == 0 and table.concat(categories) or '') |
|||
end |
end |
||
Riga 158: | Riga 188: | ||
]]-- |
]]-- |
||
function p.tracce(frame) |
function p.tracce(frame) |
||
-- ottiene i parametri del template originale |
|||
local pframe = frame:getParent() |
|||
-- estrae tutti i parametri e li memorizza in una tabella |
|||
local args = {} |
|||
for k, v in pairs(pframe.args) do |
|||
local primo_titolo |
|||
if v ~= nil and v ~= '' then |
|||
local inizio, fine, numero_titolo |
|||
args[k] = v |
|||
for k, v in pairs( pframe.args ) do |
|||
end |
|||
if v ~=nil then args[k] = v end |
|||
end |
|||
-- Se è un titolo confronto con primo_titolo e se è minore lo memorizzo |
|||
return componi_tracce(args) |
|||
pos = string.match(k, "Titolo(%d+)$") |
|||
if pos then |
|||
pos = tonumber(pos) |
|||
if not primo_titolo or pos < primo_titolo then |
|||
primo_titolo = pos |
|||
end |
|||
end |
|||
end |
|||
-- Se primo_titolo è falso non c'è alcun campo titolo |
|||
if primo_titolo then |
|||
return componi_tracce(args, primo_titolo) |
|||
else |
|||
return "" |
|||
end |
|||
end |
end |
||
-- Tavola di conversione per i parametri di en:template:Track_listing non indicizzati |
-- Tavola di conversione per i parametri di en:template:Track_listing non indicizzati |
||
local conversion_table = { |
local conversion_table = { |
||
['all_writing'] = 'Autore testi e musiche', |
|||
['all_lyrics'] = 'Autore testi', |
|||
['all_music'] = 'Autore musiche', |
|||
['total_length'] = 'Visualizza durata totale' |
|||
} |
} |
||
-- Tavola di conversione per i parametri di en:template:Track_listing indicizzati |
-- Tavola di conversione per i parametri di en:template:Track_listing indicizzati |
||
local conversion_table_index ={ |
local conversion_table_index ={ |
||
['title'] = 'Titolo', |
|||
['note'] = 'Note', |
|||
['music'] = 'Autore musica', |
|||
['writer'] = 'Autore testo e musica', |
|||
['lyrics'] = 'Autore testo', |
|||
['length'] = 'Durata', |
|||
['extra'] = 'Extra' |
|||
} |
} |
||
Riga 209: | Riga 226: | ||
]]-- |
]]-- |
||
function p.en_tracks(frame) |
function p.en_tracks(frame) |
||
local pframe = frame:getParent() |
|||
-- estrae tutti i parametri e li memorizza in una tabella (pframe ritorna una pseudotabella, vedi documentazione) |
|||
local args = {} |
|||
local log = {} |
|||
local primo_titolo |
|||
for k,v in pairs(pframe.args) do |
|||
local log ={} |
|||
if conversion_table[k] then -- Controlla se è un parametro non indicizzato |
|||
for k,v in pairs( pframe.args) do |
|||
args[conversion_table[k]] = v |
|||
else |
|||
args[ conversion_table[k]] = v |
|||
-- estrae nome base e indice, se k=title1 allora prefix=title e num=1 |
|||
else |
|||
local prefix, num = string.match(k, "^(%D+)(%d+)$") |
|||
-- estrae nome base e indice, se k=Title1 allora base_key=Title e pos=1 |
|||
if prefix and conversion_table_index[prefix] then -- controlla se è un parametro indicizzato |
|||
local base_key, pos = string.match(k, "(%D+)(%d+)$") |
|||
args[conversion_table_index[prefix] .. num] = v |
|||
elseif not num then -- non è neanche un parametro indicizzato, lo copia così com'è |
|||
args[conversion_table_index[base_key] .. pos] = v |
|||
args[k] = v |
|||
pos = tonumber(pos) |
|||
end |
|||
if base_key == 'title' and (not primo_titolo or pos < primo_titolo) then |
|||
end |
|||
primo_titolo = pos |
|||
end |
|||
end |
|||
if args['Visualizza durata totale'] then args['Visualizza durata totale'] = 'si' end |
|||
else -- non è neanche un parametro indicizzato, lo copia così com'è |
|||
return componi_tracce(args) -- table.concat(log, '\n*') -- |
|||
args[k] = v |
|||
end |
|||
end |
|||
end |
|||
if args['Visualizza durata totale'] then args['Visualizza durata totale'] = 'si' end |
|||
if primo_titolo then |
|||
return componi_tracce(args, primo_titolo) -- table.concat(log, '\n*') -- |
|||
else |
|||
return |
|||
end |
|||
end |
end |
||
Versione delle 17:41, 22 mag 2018
![Info](http://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Lua-Logo.svg/30px-Lua-Logo.svg.png)
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Tracce/man (modifica · cronologia)
Sandbox: Modulo:Tracce/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Tracce/test (modifica · cronologia · Esegui)
Questo modulo serve in appoggio al Template:Tracce per permettere l'inserimento di un numero illimitato di tracce.
Vedi il manuale del template per l'uso.
local categories = {}
local discontinuous_num = '[[Categoria:Voci con template Tracce con numerazione discontinua]]'
local missing_title = '[[Categoria:Voci con template Tracce con titolo mancante]]'
local unexpected_markup = '[[Categoria:Voci con template Tracce con markup inaspettato]]'
local unknown_format = '[[Categoria:Voci con template Tracce con formato durata sconosciuto]]'
-- Protegge una stringa che sarà avvolta dal markup wiki '' ... '' del corsivo
local function safeforitalics(str)
if str:sub(1,1) == "'" then str = "<span></span>" .. str end
if str:sub(-1,-1) == "'" then str = str .. "<span></span>" end
return str
end
-- Calcola e formatta la durata di una traccia
local function getTrackLength(args, i)
local string_durata = args["Durata" .. i]
local minuti, secondi
if string_durata then
local string_minuti, string_secondi = mw.ustring.match(string_durata, "^(%d+):(%d%d)$")
minuti = tonumber(string_minuti)
secondi = tonumber(string_secondi)
else
minuti = tonumber(args["Minuti" .. i])
secondi = args["Secondi" .. i] and mw.ustring.match(args["Secondi" .. i], "^%d%d?$") and
tonumber(args["Secondi" .. i])
end
local durata = (minuti or 0) * 60 + (secondi or 0)
if (string_durata and durata == 0) or (not minuti and args["Minuti" .. i]) or
(not secondi and args["Secondi" .. i]) then
categories[#categories+1] = unknown_format
end
return durata, durata > 0 and string.format("%d:%02.f", minuti or 0, secondi or 0) or nil
end
--[[
Riceve una lista di parametri e l'indice del gruppo di parametri da comporre
in una traccia
]]--
local function track(args, i, durata)
local titolo = args["Titolo" .. i]
local row_elements = {}
table.insert(row_elements, '<li value="' .. tostring(i) .. '">')
local interprete = args["Interprete" .. i]
if interprete then table.insert(row_elements, interprete .. " – ") end
local corsivo = args["Corsivo"] ~= "no" and true or false
corsivo = (corsivo and args["Corsivo" .. i] ~= "no") or
(not corsivo and (args["Corsivo" .. i] == "sì" or args["Corsivo" .. i] == "si"))
if titolo:find(corsivo and "''" or "'''") then
categories[#categories+1] = unexpected_markup
end
if corsivo then
titolo = "''" .. safeforitalics(titolo) .. "''"
end
table.insert(row_elements, titolo)
local featuring = args["Featuring" .. i]
if featuring then table.insert(row_elements, " <small>(feat. " .. featuring .. ")</small>") end
local note = args["Note" .. i]
if note then table.insert(row_elements, " <small>(" .. note .. ")</small>") end
if durata then
table.insert(row_elements, " – ")
table.insert(row_elements, durata)
end
local AutoreTesto = args["Autore testo" .. i]
local AutoreMusica = args["Autore musica" .. i]
local AutoreTestoeMusica = args["Autore testo e musica" .. i]
local edizioni = args["Edizioni" .. i]
local no_autore = false
if AutoreTestoeMusica then
table.insert(row_elements, " <small>(" .. AutoreTestoeMusica )
elseif AutoreTesto then
table.insert(row_elements, " <small>(testo: " .. AutoreTesto)
if AutoreMusica then
table.insert(row_elements, " – musica: " .. AutoreMusica)
end
elseif AutoreMusica then
table.insert(row_elements, " <small>(musica: " .. AutoreMusica)
else
no_autore = true
end
if edizioni then
if no_autore then
table.insert(row_elements, " <small>(")
else
table.insert(row_elements, "; ")
end
table.insert(row_elements, "edizioni musicali " .. edizioni .. ")</small>")
elseif not no_autore then
table.insert(row_elements, ")</small>")
end
local extra = args["Extra" .. i]
if extra then table.insert(row_elements, " – " .. extra) end
table.insert(row_elements, "</li>\n")
local ListaMedley = args["ListaMedley" .. i]
if ListaMedley then table.insert(row_elements, '<div style="padding: 0.3em 0px 0.5em 2.5em;">\n' .. ListaMedley .. '</div>') end
return table.concat(row_elements), durata
end
--[[
Riceve una tabella di parametri e restituisce una stringa contenente
l'output da inserire nella voce
]]--
local function componi_tracce(args)
-- array per accumulare le righe della lista man mano che vengono elaborate
local tracks = {}
-- compone la testata dell'elenco tracce
local testata = ""
local no_autore = false
local autoreTestoeMusica = args["Autore testi e musiche"]
if autoreTestoeMusica then
testata = "Testi e musiche di " .. autoreTestoeMusica
else
local autoreTesti, autoreMusiche = args["Autore testi"], args["Autore musiche"]
if autoreTesti then
testata = "Testi di " .. autoreTesti
if autoreMusiche then testata = testata .. ", musiche di " .. autoreMusiche end
elseif autoreMusiche then
testata = "Musiche di " .. autoreMusiche
else
no_autore = true
end
end
local edizioni = args["Edizioni"]
if edizioni then
if no_autore then
testata = "Edizioni musicali " .. edizioni .."."
else
testata = testata .. "; edizioni musicali " .. edizioni .. "."
end
elseif not no_autore then
testata = testata .. "."
end
table.insert(tracks, testata)
-- compone la lista dei parametri
table.insert(tracks, "<ol>")
local visualizza_durata = args["Visualizza durata totale"]
local durata = 0
local somma_durata = false
if visualizza_durata == "si" or visualizza_durata == "sì" then somma_durata = true end
local nums = {}
local validated_nums = {}
for k, v in pairs(args) do
local prefix, num = string.match(k, '^(%D+)([0-9]+)$')
if num and (num == '0' or num:sub(1,1) ~= '0') then
-- se il numero viene modificato da tonumber, è troppo alto
num = tonumber(num)
if not args['Titolo' .. num] then
categories[#categories+1] = missing_title
end
if args[prefix .. num] and not validated_nums[num] then
validated_nums[num] = true
table.insert(nums, num)
end
end
end
table.sort(nums)
if #nums == 0 then
categories[#categories+1] = missing_title
-- categoria di tracciamento se la numerazione delle tracce è discontinua
elseif nums[1] + #nums - 1 ~= nums[#nums] then
categories[#categories+1] = discontinuous_num
end
local tracce = false
-- estrae le tracce dai parametri e inserisce i valori nella tabella tracks
for k, num in ipairs(nums) do
local durata_track, durata_formattata = getTrackLength(args, num)
if args['Titolo' .. num] then
tracce = true
local new_track = track(args, num, durata_formattata)
table.insert(tracks, new_track)
end
if somma_durata then durata = durata + durata_track end
end
table.insert(tracks, "</ol>")
if somma_durata then
table.insert(tracks, "Durata totale: " .. string.format("%d:%02.f", math.floor(durata/60) , durata % 60) .. "</p>")
end
local ns = mw.title.getCurrentTitle().namespace
return (tracce and table.concat(tracks, "\n") or '') .. (ns == 0 and table.concat(categories) or '')
end
local p = {}
--[[
Funzione di interfaccia con template:Tracce
Legge i parametri e li inserisce nella tabella args, che quindi passa a componi_tracce
per l'elaborazione
]]--
function p.tracce(frame)
-- ottiene i parametri del template originale
local pframe = frame:getParent()
-- estrae tutti i parametri e li memorizza in una tabella
local args = {}
for k, v in pairs(pframe.args) do
if v ~= nil and v ~= '' then
args[k] = v
end
end
return componi_tracce(args)
end
-- Tavola di conversione per i parametri di en:template:Track_listing non indicizzati
local conversion_table = {
['all_writing'] = 'Autore testi e musiche',
['all_lyrics'] = 'Autore testi',
['all_music'] = 'Autore musiche',
['total_length'] = 'Visualizza durata totale'
}
-- Tavola di conversione per i parametri di en:template:Track_listing indicizzati
local conversion_table_index ={
['title'] = 'Titolo',
['note'] = 'Note',
['music'] = 'Autore musica',
['writer'] = 'Autore testo e musica',
['lyrics'] = 'Autore testo',
['length'] = 'Durata',
['extra'] = 'Extra'
}
--[[
Funzione di interfaccia con template:Track_listing
Legge i parametri, li converte nei parametri corrispondenti del template:Tracce
e li inserisce nella tabella args, che quindi passa a componi_tracce
per l'elaborazione
]]--
function p.en_tracks(frame)
local pframe = frame:getParent()
-- estrae tutti i parametri e li memorizza in una tabella (pframe ritorna una pseudotabella, vedi documentazione)
local args = {}
local log = {}
for k,v in pairs(pframe.args) do
if conversion_table[k] then -- Controlla se è un parametro non indicizzato
args[conversion_table[k]] = v
else
-- estrae nome base e indice, se k=title1 allora prefix=title e num=1
local prefix, num = string.match(k, "^(%D+)(%d+)$")
if prefix and conversion_table_index[prefix] then -- controlla se è un parametro indicizzato
args[conversion_table_index[prefix] .. num] = v
elseif not num then -- non è neanche un parametro indicizzato, lo copia così com'è
args[k] = v
end
end
end
if args['Visualizza durata totale'] then args['Visualizza durata totale'] = 'si' end
return componi_tracce(args) -- table.concat(log, '\n*') --
end
return p