Modulo:Webarchive/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m taglio formati inutili in italiano
-codice obsoleto o inutile per l'italiano
Riga 88:
elseif c >= 97 and c <= 122 then
c = c - 61
else -- How comes?
r = 1
break -- for i
end
r = r + c * k
k = k * 62
end -- for i
end
return r
Riga 152:
 
--[[--------------------------< decodeWebciteDate >-----------------------
Ricava la data da un URI-path a Webcite (es. /67xHmVFWP).
Restituisce false se l'URL è valido ma in formato senza data.
]]
function p.decodeWebciteDate(path)
Line 169 ⟶ 170:
mw.ustring.find(path_elements[2], "getfile") or
tonumber(path_elements[2]) then
return nilfalse
end
local snapdate = os.date("%Y %m %d", string.sub(string.format("%d", base62(path_elements[2])),1,10))
local dt = mw.text.split(snapdate, " ")
local fulldate = formatUrlDate(dt[1], dt[2], dt[3])
return fulldate or inlineRed("Collegamento non valido", "error")
end
 
--[[--------------------------< snapDateToString >-----------------------
Ricava la data da un URI-path a Wayback (es. /web/20160901010101/http://example.com ).
Gestisce anche le non cifre come "re_", "-" e "*".
]]
function p.decodeWaybackDate(path)
Line 185 ⟶ 186:
local path_elements = mw.text.split(snapdate, "/")
snapdate = path_elements[1]
if snapdate == '*' then return end
return inlineRed("Collegamento non valido", "error")
end
snapdate = string.gsub(snapdate, "[a-z][a-z]_[0-9]?$", "")
snapdate = string.gsub(snapdate, "[-]", "")
Line 199 ⟶ 198:
fulldate = formatUrlDate(year, month, day)
end
return fulldate or inlineRed("Collegamento non valido", "error")
end
 
Line 257 ⟶ 256:
end
return ulx
end
 
--[[--------------------------< comma >-----------------------
Given a date string, return "," if it's MDY
]]
local function comma(date)
local n = mw.text.split(date, " ")
local o = mw.text.split(n[1], "-") -- for ISO
if o[1] == "index" then return "" end
if not tonumber(o[1]) then
return ","
else
return ""
end
end
 
--[[--------------------------< createTracking >-----------------------
Restituisce ile daticategorie di tracciamento inserite in track[], ovvero le categorie di tracciamento
]]
local function createTracking()
-- Procedeprocede solo nel namespace 0
local current_namespace = mw.title.getCurrentTitle().namespace
if current_namespace ~= 0 then return '' end
Line 301 ⟶ 286:
indexstr = "archivio"
end
elseif if not url_main.title and not url_main.date then -- TitleNo title. No date.
-- For {{wayback}}, {{webcite}}
sand = mw.ustring.format("[%s Archiviato]%s", url_main.url, url_main.tail)
if url_main.format == "none" then
if elseif not url_main.title and not url_main.date then -- No title. No dateDate.
if url_main.formatservice == "nonewayback" then
sand = mw.ustring.format("[%s Archiviato]%s", url_main.url, url_main.tail)
period1 = "."
elseif not url_main.title and url_main.date then -- No title. Date.
period2 = ""
if url_main.service == "wayback" then
period1 = "."
period2 = ""
end
sand = mw.ustring.format("[%s Archiviato] il %s%s%s%s", url_main.url, url_main.date, comma(url_main.date), url_main.tail, period1)
elseif url_main.title and not url_main.date then -- Title. No date.
sand = mw.ustring.format("[%s %s]%s", url_main.url, url_main.title, url_main.tail)
elseif url_main.title and url_main.date then -- Title. Date.
sand = mw.ustring.format("[%s %s]%s&#32;(%s %s)", url_main.url, url_main.title, url_main.tail, indexstr, url_main.date)
else
return nil
end
sand = mw.ustring.format("[%s Archiviato] il %s%s%s%s", url_main.url, url_main.date, comma(url_main.date), url_main.tail, period1)
if #ulx > 0 then -- For multiple archive URLs
elseif url_main.title and not url_main.date then -- Title. DateNo date.
sand = sand .. period2 .. " Archivi aggiuntivi: "
sand = mw.ustring.format("[%s %s]%s", url_main.url, url_main.title, url_main.tail)
local archives_output = {}
elseif not url_main.title and url_main.date then -- No titleTitle. Date.
for indx,urlx in ipairs(ulx) do
archives_output[#archives_output+1]sand = mw.ustring.format("[%s %s]%s&#32;(%s %s)", urlx["url_main.url"], urlx["url_main.title"], orurl_main.tail, urlx["indexstr, url_main.date"] )
end
sand = sand .. table.concat(archives_output, ", ") .. "."
end
return sand
 
-- For {{cite archives}}
else
return ","nil
if url_main.format == "addlarchives" then -- Multiple archive services
end
displayheader = "Archivi aggiuntivi: "
else if #ulx --> Multiple0 pagesthen from-- theFor samemultiple archive URLs
sand = sand .. period2 .. " Archivi aggiuntivi: "
displayheader = mw.ustring.format("Pagine di archivio aggiuntive su %s: ", url_main.date)
end
local sand = displayheader
local archives_output = {}
for indx, urlx in ipairs(ulx) do
archive_ouptutarchives_output[#archives_output+1] = mw.ustring.format("[%s %s]", urlx["url"], displayfieldurlx["title"] or urlx["date"] )
displayfield = urlx["title"]
if url_main.format == "addlarchives" then
if not displayfield then displayfield = urlx["date"] end
else
if not displayfield then displayfield = "Pagina " .. indx+1 end
end
archive_ouptut[#archives_output+1] = mw.ustring.format("[%s %s]", urlx["url"], displayfield )
end
sand = mwsand .ustring.format("%s%s.", sand, table.concat(archive_outputarchives_output, ", ")) .. "."
return sand
end
return ""sand
end
 
--[[--------------------------< createRendering >------------------------------------------
Funzione di interfaccia principale per implementazione del
Template:Webarchive
]]
function p.webarchive(frame)
-- caricocarica in args i parametri, e se sono nulli sonoli ignoratiignora, eccetto che per il parametro nolink
local args = getArgs(frame, {
valueFunc = function(key, value)
Line 369 ⟶ 330:
})
 
-- Verificaverifica eventuali errori nel parametro url
local url1 = args.url or args.url1
if not url1 then
return inlineError("'url"', "'vuoto"') .. createTracking()
elseif mw.ustring.find(url1, "'https://web.http"') then
track["'Categoria:Errori di compilazione del template Webarchive"'] = 1
return inlineError("'url"', "'https://web.http"') .. createTracking()
elseif url1 == "'https://web.archive.org/http:/"' then
track["'Categoria:Errori di compilazione del template Webarchive"'] = 1
return inlineError("'url"', "'URL non valido"') .. createTracking()
end
 
local url_main = {}
url_main.url = url1
Line 387 ⟶ 347:
serviceName(url_main, args.nolink)
 
-- Dategestione argumentdelle date
local date = args.date or args.date1 or args.data or args.data1
elseif notif date then
if date and (url_main.service == 'wayback' or url_main.service == 'webcite') then
date = formatDate(date)
local udate = url_main.service == 'wayback' and p.decodeWaybackDate( uri1.path ) or
url_main.service == 'webcite' and p.decodeWebciteDate( uri1.path )
if udate and udate ~= date then
date = dateudate .. inlineRed("'<sup>[Date non combacianti]</sup>"', "'warning"')
end
elseif not date and url_main.service == "'wayback"' then
date = p.decodeWaybackDate( uri1.path,) "iso"or inlineRed('Collegamento non valido', 'error')
elseif not date and url_main.service == "'webcite"' then
date = p.decodeWebciteDate( uri1.path, "iso" )
if date == "query"false then
date = inlineRed("['Data mancante]"', "'warning"')
elseif not date then
date = inlineRed("[Errore'Collegamento nellanon data] (1)]"valido', "'error"')
end
else
elseif not date then
date = inlineRed("['Data mancante]"', "'warning"')
end
url_main.date = date
 
-- Formatgestione argumentdel titolo
local format = args.format or args.formato or "none"
if not format ~= "none" then
if format == "addlpages" then
if not url_main.date then
format = "none"
end
elseif format ~= "addlarchives" then
format = "none"
end
end
url_main.format = format
 
-- Title argument
url_main.title = args.title or args.title1 or args.titolo or args.titolo1
local ulx = parseExtraArgs(args, maxurls)
--if true then return mw.text.jsonEncode(ulx, mw.text.JSON_PRETTY) end
local rend = createRendering(url_main, ulx)
if not rend then