Modulo:Webarchive/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m versione corrente |
traduco qualche descrizione; riscrivo funzioni makeDate e decodeWaybackDate |
||
Riga 1:
--[[ ----------------------------------
Modulo Lua che implementa il template {{Webarchive}} e offre alcune
funzionalità ad altri moduli Lua per la gestione degli archivi.
]]
Riga 10 ⟶ 8:
local p = {}
local track = {} --
local maxurls = 10 --
local servizi = {
Riga 51 ⟶ 49:
--[[--------------------------< inlineError >-----------------------
]]
Riga 64 ⟶ 62:
--[[--------------------------< inlineRed >-----------------------
Aggiunge una categoria di tracciamento.
]]
Riga 84 ⟶ 82:
--[[--------------------------< base62 >-----------------------
]]
Riga 119 ⟶ 117:
--[[--------------------------< tableLength >-----------------------
Restituisce il numero di elementi in una tabella
]]
Riga 132 ⟶ 130:
--[[--------------------------< dateFormat >-----------------------
Se non riesce a determinarla, restituisce nil
]]
Riga 175 ⟶ 173:
--[[--------------------------< makeDate >-----------------------
Controlla la data prelevata automaticamente dall'url di un archivio
Se è valida la formatta, altrimenti restituisce nil
]]
local function makeDate(
local current_year = tonumber(os.date("%Y"))
y, m, d = tonumber(y), tonumber(m), tonumber(d)
if not y or y == '' or not m or m == '' or not d or d == '' or d > 31 or
m < 1 or m > 12 or y < 1900 or y > current_year then
return nil
end
m = month_localized[m]
if d == '1' then d = '1º' end
return mw.ustring.format("%s %s %s", d, m, y)
end
--[[--------------------------< decodeWebciteDate >-----------------------
Riga 256 ⟶ 245:
--[[--------------------------< snapDateToString >-----------------------
Gestisce anche le non cifre come "re_", "-" e "*"
]]
function decodeWaybackDate(path)
local snapdate = string.gsub(uri.path, "^/w?e?b?/?", "") -- rimuove la sequenza iniziale "/web/" o "/"
local path_elements = mw.text.split(snapdate, "/")
snapdate = path_elements[1]
if snapdate == '*' then
return inlineRed("Collegamento non valido", "error")
end
snapdate = string.gsub(snapdate, "[a-z][a-z]_[0-9]?$", "")
snapdate = string.gsub(snapdate, "[-]", "")
local fulldate
local dlen = string.len(snapdate)
if tonumber(snapdate) and dlen >= 8 then
local year = string.sub(snapdate, 1, 4)
local month = string.sub(snapdate, 5, 6)
local day = string.sub(snapdate, 7, 8)
if checkDate(year, month, day) then
fulldate = makeDate(year, month, day)
end
end
return fulldate or inlineRed("Collegamento non valido", "error")
end
Riga 503 ⟶ 459:
function p.webarchive(frame)
-- carico in args i parametri, se sono nulli sono ignorati, eccetto che per il
local args = getArgs(frame, {
valueFunc = function (key, value)
|