Modulo:Tracce/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m indentazione con tab
test abbr
 
(22 versioni intermedie di un altro utente non mostrate)
Riga 1:
local categories = {}
local discontinuous_num = '[[Categoria:Voci con template Tracce acon numerazione discontinua]]'
local missing_title = '[[Categoria:ErroriVoci di compilazione delcon template Tracce -con titolo mancante]]'
local unexpected_markup = '[[Categoria:ErroriVoci di compilazione delcon template Tracce -con markup inaspettato]]'
local unknown_format = '[[Categoria:ErroriVoci di compilazione delcon template Tracce -con formato durata sconosciuto]]'
 
-- ProtectsProtegge auna stringstringa thatche willsarà beavvolta wrappeddal inmarkup wiki italic markup '' ... '' del corsivo
local function safeforitalics( str )
if str:sub(1,1) ~== nil"'" andthen str ~= ''"<span></span>" then.. str end
if str:sub(-1,-1) == "'" then str = str .. "<span></span>" .. str end
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
 
Line 19 ⟶ 38:
]]--
 
local function track(args, i, corsivodurata)
local titolo = args["Titolo" .. i]
local row_elements = {}
table.insert(row_elements, '<li value="' .. tostring(i) .. '">')
local interprete = args["Interprete" .. i] or ""
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"))
Line 34 ⟶ 54:
end
table.insert(row_elements, titolo)
local featuring = args["Featuring" .. i] or ""
if featuring ~= "" then table.insert(row_elements, " <small>(<abbr title=featuring>feat.</abbr> " .. featuring .. ")</small>") end
local note = args["Note" .. i] or ""
if note ~= "" then table.insert(row_elements, " <small>(" .. note .. ")</small>") end
if durata then
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) or 0
secondi = tonumber(string_secondi) or 0
else
minuti = tonumber(args["Minuti" .. i]) or 0
secondi = tonumber(args["Secondi" .. i]) or 0
end
local durata = minuti * 60 + secondi
if durata > 0 then
table.insert(row_elements, " – ")
table.insert(row_elements, string.format("%d:%02.f", minuti, secondi)durata)
else
local args_durata = string_durata or args["Minuti" .. i]
or args["Secondi" .. i] or ""
if args_durata ~= "" then
categories[#categories+1] = unknown_format
end
end
local AutoreTesto = args["Autore testo" .. i] or ""
local AutoreMusica = args["Autore musica" .. i] or ""
local AutoreTestoeMusica = args["Autore testo e musica" .. i] or ""
local edizioni = args["Edizioni" .. i] or ""
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>(")
Line 86 ⟶ 89:
table.insert(row_elements, ")</small>")
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
end
 
--[[
Riceve una tabella di parametri e l'indicerestituisce deluna primostringa gruppo di parametri del template tracce,contenente
restituisce una stringa contenente l'output da inserire nella voce
]]--
local function componi_tracce(args)
Line 104 ⟶ 107:
local testata = ""
local no_autore = false
local autoreTestoeMusica = args["Autore testi e musiche"] or ""
if autoreTestoeMusica ~= "" then
testata = "Testi e musiche di " .. autoreTestoeMusica
else
local autoreTesti, autoreMusiche = args["Autore testi"], orargs["Autore musiche""]
if autoreTesti then
local autoreMusiche = args["Autore musiche"] or ""
if autoreTesti ~= "" then
testata = "Testi di " .. autoreTesti
if autoreMusiche ~= "" then testata = testata .. ", musiche di " .. autoreMusiche end
elseif autoreMusiche ~= "" then
testata = "Musiche di " .. autoreMusiche
else
Line 119 ⟶ 121:
end
end
local edizioni = args["Edizioni"] or ""
if edizioni ~= "" then
if no_autore then
testata = "Edizioni musicali " .. edizioni .."."
Line 128 ⟶ 130:
elseif not no_autore then
testata = testata .. "."
end
local corsivo = true
if args["Corsivo"] == "no" then
corsivo = false
end
table.insert(tracks, testata)
-- compone la lista dei parametri
table.insert(tracks, "<ol>")
local visualizza_durata = args["Visualizza durata totale"] or ""
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 numero_titoloprefix, num = k:string.match(k, '^(%D+)(%d[0-9]+)$')
if tonumbernum and (numero_titolonum == '0' or num:sub(1,1) ~= '0') then
-- se il numero viene modificato da tonumber, è troppo alto
local titolo = args['Titolo' .. numero_titolo] or ''
num = tonumber(num)
if v ~= '' and titolo == '' then
if not args['Titolo' .. num] then
categories[#categories+1] = missing_title
end
elseif k == 'Titolo' .. numero_titolo and titolo ~= '' then
if args[prefix .. num] and not validated_nums[num] then
table.insert(nums, tonumber(numero_titolo))
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 new_trackdurata_track, durata_trackdurata_formattata = trackgetTrackLength(args, num, corsivo)
if args['Titolo' .. num] then
table.insert(tracks, new_track)
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
if k ~= num then categories[#categories+1] = discontinuous_num end
end
table.insert(tracks, "</ol>")
Line 164 ⟶ 176:
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 table.concat(tracks, "\n") .. table.concat(categories)
return (tracce and table.concat(tracks, "\n") or '') .. (ns == 0 and table.concat(categories) or '')
end
 
Line 179 ⟶ 192:
-- estrae tutti i parametri e li memorizza in una tabella
local args = {}
for k, v in pairs(pframe.args) do
local titles = false
if v ~= nil and v ~= '' then
for k, v in pairs( pframe.args ) do
if v ~= nil then args[k] = v end
end
if k:match("^Titolo(%d+)$") then titles = true end
end
return componi_tracce(args)
-- procede solo se c'è almeno un campo titolo
return titles and componi_tracce(args) or ""
end
 
Line 217 ⟶ 229:
-- estrae tutti i parametri e li memorizza in una tabella (pframe ritorna una pseudotabella, vedi documentazione)
local args = {}
local primo_titololog = {}
for k, v in pairs(pframe.args) do
local log ={}
if v ~= nil and v ~= '' then
for k,v in pairs( pframe.args) do
if conversion_table[k] then -- Controlla sse è un parametro non indicizzato
args[ conversion_table[k]] = v
else
-- estrae nome base e indice, se k=Title1title1 allora base_keyprefix=Titletitle e posnum=1
local base_keyprefix, posnum = string.match(k, "^(%D+)(%d+)$")
if pos and base_keyprefix and conversion_table_index[base_keyprefix] then -- controlla se è un parametro indicizzato
args[conversion_table_index[base_keyprefix] .. posnum] = v
elseif not num then -- non è neanche un parametro indicizzato, lo copia così com'è
pos = tonumber(pos)
args[k] = v
if base_key == 'title' and (not primo_titolo or pos < primo_titolo) then
primo_titolo = pos
end
end
else -- 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*') --
if primo_titolo then
return componi_tracce(args, primo_titolo) -- table.concat(log, '\n*') --
else
return
end
end