Modulo:Tracce/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
test parametro durata
 
test abbr
 
(48 versioni intermedie di 2 utenti non mostrate)
Riga 1:
local functioncategories estrai_durata(args,= i){}
local discontinuous_num = '[[Categoria:Voci con template Tracce con numerazione discontinua]]'
local durata = args["Durata" .. i]
local missing_title = '[[Categoria:Voci con template Tracce con titolo mancante]]'
local minuti = 0
local unexpected_markup = '[[Categoria:Voci con template Tracce con markup inaspettato]]'
local secondi = 0
local unknown_format = '[[Categoria:Voci con template Tracce con formato durata sconosciuto]]'
if Durata then
 
local string_minuti, string_secondi = mw.ustring.match(Durata, "(%d+:%d%d")
-- Protegge una stringa che sarà avvolta dal markup wiki '' ... '' del corsivo
minuti = tonumber(string_minuti) or 0
local function safeforitalics(str)
secondi = tonumber(string_secondi) or 0
if str:sub(1,1) == "'" then str = "<span></span>" .. str end
else
if str:sub(-1,-1) == "'" then str = str .. "<span></span>" end
minuti = tonumber(args["Minuti" .. i]) or 0
return str
secondi = tonumber(args["Secondi" .. i]) or 0
end
return minuti * 60 + secondi
end
 
-- Calcola e formatta la durata di una traccia
-- Protects a string that will be wrapped in wiki italic markup '' ... ''
local function safeforitalicsgetTrackLength(args, str i)
local string_durata = args["Durata" .. i]
--[[ Note: We can not use <i> for italics, as the expected behavior for
local minuti, secondi
italics specified by ''...'' in the title is that they will be inverted
if string_durata then
(i.e. unitalicized) in the resulting references. In addition, <i> and ''
local string_minuti, string_secondi = mw.ustring.match(string_durata, "^(%d+):(%d%d)$")
tend to interact poorly under Mediawiki's HTML tidy. ]]
minuti = tonumber(string_minuti)
 
secondi = tonumber(string_secondi)
if str == nil or str == '' then
else
return str;
minuti = tonumber(args["Minuti" .. i])
else
secondi = args["Secondi" .. i] and mw.ustring.match(args["Secondi" .. i], "^%d%d?$") and
if str:sub(1,1) == "'" then str = "<span />" .. str; end
tonumber(args["Secondi" .. i])
if str:sub(-1,-1) == "'" then str = str .. "<span />"; end
end
return str;
local durata = (minuti or 0) * 60 + (secondi or 0)
end
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] or ""
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 = args["Interprete" .. i]" or "") 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
table.insert(row_elements, "''" .. safeforitalics(titolo) .. "''")
(not corsivo and (args["Corsivo" .. i] == "sì" local featuring =or args["FeaturingCorsivo" .. i] or== "si"))
if titolo:find(corsivo and "''" or "'''") then
if featuring ~= "" then table.insert(row_elements, " <small>(feat. " .. featuring .. ")</small>") end
categories[#categories+1] = unexpected_markup
local note = args["Note" .. i] or ""
end
if note ~= "" then table.insert(row_elements, " <small>(" .. note .. ")</small>") end
if corsivo then
local minuti = tonumber(args["Minuti" .. i]) or 0
titolo = "''" .. safeforitalics(titolo) .. "''"
local secondi = tonumber(args["Secondi" .. i]) or 0
end
local durata = minuti * 60 + secondi
table.insert(row_elements, titolo)
if durata > 0 then
local featuring = args["Featuring" .. i]
table.insert(row_elements, " – ")
if featuring then table.insert(row_elements, string.format("%d:%02 <small>(<abbr title=featuring>feat.f</abbr> ", minuti,.. secondifeaturing .. ")</small>") end
local note = args["Note" .. i]
end
if note then table.insert(row_elements, " <small>(" .. note .. ")</small>") end
local AutoreTesto = args["Autore testo" .. i] or ""
if durata then
local AutoreMusica = args["Autore musica" .. i] or ""
table.insert(row_elements, " – ")
local AutoreTestoeMusica = args["Autore testo e musica" .. i] or ""
table.insert(row_elements, durata)
local edizioni = args["Edizioni" .. i] or ""
end
local no_autore = false
local AutoreTesto = args["Autore testo" .. i]
if AutoreTestoeMusica ~= "" then
local AutoreMusica = args["Autore musica" .. i]
table.insert(row_elements, " <small>(" .. AutoreTestoeMusica )
local AutoreTestoeMusica = args["Autore testo e musica" .. i]
elseif AutoreTesto ~= "" then
local edizioni = args["Edizioni" .. i]
table.insert(row_elements, " <small>(")
local no_autore = false
if AutoreMusica ~= "" then
if AutoreTestoeMusica then
table.insert(row_elements, AutoreTesto .. " – " .. AutoreMusica)
table.insert(row_elements, " <small>(" .. AutoreTestoeMusica )
else
elseif AutoreTesto then
table.insert(row_elements, AutoreTesto)
table.insert(row_elements, " <small>(testo: " .. AutoreTesto)
end
elseif if AutoreMusica ~= "" then
table.insert(row_elements, " <small>(– musica: " .. AutoreMusica)
end
else
elseif AutoreMusica then
no_autore = true
table.insert(row_elements, " <small>(musica: " .. AutoreMusica)
end
else
if edizioni ~= "" then
no_autore = true
if no_autore then
end
table.insert(row_elements, " <small>(")
if edizioni then
else
if no_autore then
table.insert(row_elements, ";")
table.insert(row_elements, " <small>(")
end
else
table.insert(row_elements, "edizioni musicali " .. edizioni .. ")</small>")
table.insert(row_elements, "; ")
elseif not no_autore then
end
table.insert(row_elements, ")</small>")
table.insert(row_elements, "edizioni musicali " .. edizioni .. ")</small>")
end
elseif not no_autore then
local extra = args["Extra" .. i] or ""
if extra ~= "" then table.insert(row_elements, ")</small>" .. extra) end
end
table.insert(row_elements, "</li>\n")
local ListaMedleyextra = args["ListaMedleyExtra" .. i] or ""
if ListaMedley ~= ""extra then table.insert(row_elements, '<div style="padding: 0.3em 0px 0.5em 2.5em;">\n' .. ListaMedley .. '</div>'extra) end
return table.concatinsert(row_elements, "</li>\n")
local ListaMedley = args["ListaMedley" .. i]
else
if ListaMedley then table.insert(row_elements, '<div style="padding: 0.3em 0px 0.5em 2.5em;">\n' .. ListaMedley .. '</div>') end
return nil
return table.concat(row_elements), durata
end
end
 
--[[
local function componi_tracce(args, primo_titolo)
Riceve una tabella di parametri e restituisce una stringa contenente
-- compone testata
l'output da inserire nella voce
local tracks = {}
]]--
local testata = ""
local function componi_tracce(args)
local noautore = false
-- array per accumulare le righe della lista man mano che vengono elaborate
local autoreTestoeMusica = args["Autore testi e musiche"] or ""
local tracks = {}
if autoreTestoeMusica ~= "" then
-- compone la testata dell'elenco tracce
testata = "Testi e musiche di " .. autoreTestoeMusica
local testata = ""
else
local no_autore = false
autoreTesti = args["Autore testi"] or ""
local autoreMusicheautoreTestoeMusica = args["Autore testi e musiche"] or ""
if autoreTesti ~= ""autoreTestoeMusica then
testata = "Testi e musiche di " .. autoreTestiautoreTestoeMusica
else
if autoreMusiche ~= "" then testata = testata .. ", musiche di " .. autoreMusiche end
local elseifautoreTesti, autoreMusiche ~= args["Autore testi"], thenargs["Autore musiche"]
if autoreTesti then
testata = "Musiche di " .. autoreMusiche
testata = "Testi di " .. autoreTesti
else
if autoreMusiche then testata = testata .. ", musiche di " .. autoreMusiche end
noAutore = true
elseif autoreMusiche then
end
testata = "Musiche di " .. autoreMusiche
end
else
local edizioni = args["Edizioni"] or ""
no_autore = true
if edizioni ~= "" then
end
if noAutore then
end
testata = "Edizioni musicali " .. edizioni .."."
local edizioni = args["Edizioni"]
else
if edizioni then
testata = testata .. "; edizioni musicali " .. edizioni .. "."
if no_autore then
end
testata = "Edizioni musicali " .. edizioni .."."
elseif not noAutore then
else
testata = testata .. "."
testata = testata .. "; edizioni musicali " .. edizioni .. "."
end
end
table.insert(tracks, testata)
elseif not no_autore then
-- compone la lista dei parametri
testata = testata .. "."
local i = primo_titolo
end
table.insert(tracks, "<ol>")
table.insert(tracks, testata)
local visualizza_durata = args["Visualizza durata totale"] or ""
-- compone la lista dei parametri
local durata = 0
table.insert(tracks, "<ol>")
local somma_durata = false
if local visualizza_durata == args["si"Visualizza thendurata somma_durata = true endtotale"]
local durata = 0
--estrae le tracce dai parametri e inserisci i valori nella tabella tracks
local somma_durata = false
while true do
if visualizza_durata == "si" or visualizza_durata == "sì" then somma_durata = true end
new_track = track(args, i)
local nums = {}
if new_track==nil then break end
local validated_nums = {}
table.insert(tracks, new_track)
for k, v in pairs(args) do
if somma_durata then durata = durata + estrai_durata(args, i) end
local prefix, num = string.match(k, '^(%D+)([0-9]+)$')
i = i + 1
if num and (num == '0' or num:sub(1,1) ~= '0') then
end
-- se il numero viene modificato da tonumber, è troppo alto
table.insert(tracks, "</ol>")
num = tonumber(num)
if somma_durata then
if not args['Titolo' .. num] then
table.insert(tracks, "Durata totale: " .. string.format("%d:%02.f", math.floor(durata/60) , durata % 60) .. "</p>")
categories[#categories+1] = missing_title
end
end
return table.concat(tracks, "\n")
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 (pframe ritorna una pseudotabella, vedi documentazione)
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
args[k] = v
end
inizio, fine = string.find(k, "Titolo", 1, true)
return componi_tracce(args)
if fine ~= nil then
end
numero_titolo = tonumber(string.sub(k, fine+1))
 
if numero_titolo ~= nil and (not primo_titolo or numero_titolo < primo_titolo) then
-- Tavola di conversione per i parametri di en:template:Track_listing non indicizzati
primo_titolo = numero_titolo
local conversion_table = {
end
['all_writing'] = 'Autore testi e musiche',
end
['all_lyrics'] = 'Autore testi',
end
['all_music'] = 'Autore musiche',
if primo_titolo then
['total_length'] = 'Visualizza durata totale'
return componi_tracce(args, primo_titolo)
}
else
 
return ""
-- Tavola di conversione per i parametri di en:template:Track_listing indicizzati
end
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 v ~= nil and v ~= '' then
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
end
if args['Visualizza durata totale'] then args['Visualizza durata totale'] = 'si' end
return componi_tracce(args) -- table.concat(log, '\n*') --
end