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
Lua module implementing the {{webarchive}} template.
funzionalità ad altri moduli Lua per la gestione degli archivi.
 
A merger of the functionality of three templates: {{wayback}}, {{webcite}} and {{cite archives}}
 
]]
 
Riga 10 ⟶ 8:
 
local p = {}
local track = {} -- Associative array toassociativo per accumulare le holdcategorie trackingdi categoriestracciamento
local maxurls = 10 -- Maxmassimo numbernumero ofdi URLsURL allowed.permessi
 
local servizi = {
Riga 51 ⟶ 49:
--[[--------------------------< inlineError >-----------------------
 
CriticalErrore errorcritico. RenderFormatta l'output completelycompletamente in redrosso. AddAggiunge touna trackingcategoria categorydi tracciamento.
 
]]
Riga 64 ⟶ 62:
--[[--------------------------< inlineRed >-----------------------
 
RenderFormatta aun textframmento fragmentdi testo in redrosso, suchquale asad aesempio warningun asavvertimento partda of the finalintegrare nell'output finale.
Aggiunge una categoria di tracciamento.
Add tracking category.
 
]]
Riga 84 ⟶ 82:
--[[--------------------------< base62 >-----------------------
 
ConvertConverte base-62 toin base-10
CreditCrediti: https://de.wikipedia.org/wiki/Modul:Expr
 
]]
Riga 119 ⟶ 117:
--[[--------------------------< tableLength >-----------------------
 
Restituisce il numero di elementi in una tabella
Given a 1-D table, return number of elements
 
]]
Riga 132 ⟶ 130:
--[[--------------------------< dateFormat >-----------------------
 
GivenRestituisce ail dateformato string,di returnuna its formatdata: dmy, mdy, iso, ymd
Se non riesce a determinarla, restituisce nil
If unable to determine return nil
 
]]
Riga 175 ⟶ 173:
--[[--------------------------< makeDate >-----------------------
 
Controlla la data prelevata automaticamente dall'url di un archivio
Given a zero-padded 4-digit year, 2-digit month and 2-digit day, return a full date in df format
Se è valida la formatta, altrimenti restituisce nil
df = mdy, dmy, iso, ymd
 
]]
 
local function makeDate(yeary, monthm, day, dfd)
local current_year = tonumber(os.date("%Y"))
 
y, m, d = tonumber(y), tonumber(m), tonumber(d)
if not year or year == "" or not month or month == "" or not day or day == "" then
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
local zmonth = month -- month with leading 0
return mw.ustring.format("%s %s %s", d, m, y)
month = month:match("0*(%d+)") -- month without leading 0
if tonumber(month) < 1 or tonumber(month) > 12 then return year end
local nmonth = month_localized[tonumber(month)]
if not nmonth then return year end
local zday = day
day = zday:match("0*(%d+)")
if tonumber(day) < 1 or tonumber(day) > 31 then
return mw.ustring.format("%s %s", nmonth, year)
end
if day == "1" then day = "1º" end
return mw.ustring.format("%s %s %s", day, nmonth, year)
end
 
 
--[[--------------------------< decodeWebciteDate >-----------------------
Riga 256 ⟶ 245:
--[[--------------------------< snapDateToString >-----------------------
 
GivenRicava ala data da un URI-path toa Wayback (eges. /web/20160901010101/http://example.com )
Gestisce anche le non cifre come "re_", "-" e "*"
return the formatted date eg. "September 1, 2016" in df format
Handle non-digits in snapshot ID such as "re_" and "-" and "*"
 
]]
function decodeWaybackDate(path)
 
local snapdate = string.gsub(uri.path, "^/w?e?b?/?", "") -- rimuove la sequenza iniziale "/web/" o "/"
local function decodeWaybackDate(path, df)
local path_elements = mw.text.split(snapdate, "/")
 
snapdate = path_elements[1]
local snapdate, snapdatelong, currdate, fulldate
if snapdate == '*' then
 
return inlineRed("Collegamento non valido", "error")
 
end
local snapdate = string.gsub(path, "^/w?e?b?/?", "") -- Remove leading "/web/" or "/"
snapdate = string.gsub(snapdate, "[a-z][a-z]_[0-9]?$", "")
local safe = snapdate
snapdate = string.gsub(snapdate, "[-]", "")
local path_elements = mw.text.split(safe, "/")
snapdate = path_elementsstring.gsub(snapdate, "[1*]$", "")
local fulldate
if snapdate == "*" then -- eg. /web/*/http..
local dlen = string.len(snapdate)
return "index"
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
safe = snapdate
return fulldate or inlineRed("Collegamento non valido", "error")
snapdate = string.gsub(safe, "[a-z][a-z]_[0-9]?$", "") -- Remove any trailing "re_" from date
safe = snapdate
snapdate = string.gsub(safe, "[-]", "") -- Remove dashes from date eg. 2015-01-01
safe = snapdate
snapdate = string.gsub(safe, "[*]$", "") -- Remove trailing "*"
 
if not tonumber(snapdate) then
return inlineRed("[Errore nella data] (2)", "error")
end
local dlen = string.len(snapdate)
if dlen < 4 then
return inlineRed("[Errore nella data] (3)", "error")
end
if dlen < 14 then
snapdatelong = snapdate .. string.rep("0", 14 - dlen)
else
snapdatelong = snapdate
end
local year = string.sub(snapdatelong, 1, 4)
local month = string.sub(snapdatelong, 5, 6)
local day = string.sub(snapdatelong, 7, 8)
if not tonumber(year) or not tonumber(month) or not tonumber(day) then
return inlineRed("[Errore nella data] (4)", "error")
end
if tonumber(month) > 12 or tonumber(day) > 31 or tonumber(month) < 1 then
return inlineRed("[Errore nella data] (5)", "error")
end
currdate = os.date("%Y")
if tonumber(year) > tonumber(currdate) or tonumber(year) < 1900 then
return inlineRed("[Errore nella data] (6)", "error")
end
 
local fulldate = makeDate(year, month, day, df)
if not fulldate then
return inlineRed("[Errore nella data] (7)", "error")
else
return fulldate
end
 
end
 
Riga 503 ⟶ 459:
 
function p.webarchive(frame)
-- carico in args i parametri, se sono nulli sono ignorati, eccetto che per il prametroparametro nolink
local args = getArgs(frame, {
valueFunc = function (key, value)