Modulo:Webarchive/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m pulizia
riscrivo funzione dateFormat
Riga 108:
end
 
--[[--------------------------< dateFormatformatDate >-----------------------
RestituisceVerifica il formato di una data: (dmy, mdy, iso, ymd) e se lo riconosce
Sela nonriformatta riescein a determinarladmy, altrimenti restituisce nilil valore così com'è
]]
local function dateFormatformatDate(date)
local dty, =m, {}d
local sand = ""try_year
dt.split = {}
dt.local split = mw.text.split(date, "'-"')
 
if tableLength(dt.split) == 3 then
dt.split = mw.text.split(date, "-")
iftry_year = tonumber(dt.split[31]) then
if tableLength(dt.split) == 3 then
if tonumber(dt.split[1])try_year and try_year > 1900 and tonumber(dt.split[1])try_year < 2200 andthen tonumber(dt.split[2])-- and tonumber(dt.split[3]) theniso
y, m, d = split[1], split[2], split[3]
return "iso"
else
return nil
end
else
end
dt. split = mw.text.split(date, "' "')
 
if tableLength(dt.split) == 3 then
dt.split = mw.text.split(date, " ")
try_year = tonumber(split[3])
if tableLength(dt.split) == 3 then
if try_year and try_year > 1900 and try_year < 2200 then
if tonumber(dt.split[3]) then
if tonumber(dt.split[31]) >== 1900'1º' andor tonumber(dt.split[31]) <then 2200-- thendmy
if d, m, y = tonumber(dt.split[1]), thensplit[2], split[3]
returnelse "dmy"-- mdy
m, d, y = split[1], split[2], split[3]
else
return "mdy"
end
else
iftry_year = tonumber(dt.split[1]) then
if tonumber(dt.split[1])try_year and try_year > 1900 and tonumber(dt.split[1])try_year < 2200 then -- ymd
y, m, d = split[1], split[2], split[3]
return "ymd"
end
end
end
end
end
if tonumber(d) == 1 then d = '1º' end
return nil
return y and mw.ustring.format('%s %s %s', d, m, y) or date
end
 
--[[--------------------------< makeDateformatUrlDate >-----------------------
Controlla la data prelevata automaticamente dall'url di un archivio.
Se è valida la formatta in dmy, altrimenti restituisce nil.
]]
local function makeDateformatUrlDate(y, m, d)
local current_year = tonumber(os.date("%Y"))
y, m, d = tonumber(y), tonumber(m), tonumber(d)
Riga 159 ⟶ 156:
m = month_localized[m]
if d == 1 then d = '1º' end
return mw.ustring.format("'%s %s %s"', d, m, y)
end
 
Riga 184 ⟶ 181:
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 = makeDateformatUrlDate(dt[1], dt[2], dt[3])
return fulldate or inlineRed("Collegamento non valido", "error")
end
Riga 208 ⟶ 205:
local month = string.sub(snapdate, 5, 6)
local day = string.sub(snapdate, 7, 8)
fulldate = makeDateformatUrlDate(year, month, day)
end
return fulldate or inlineRed("Collegamento non valido", "error")
Riga 214 ⟶ 211:
 
--[[--------------------------< serviceName >-----------------------
Imposta la stringa di coda e l'ID del servizio in base al dominio
Given a ___domain extracted by mw.uri.new() (eg. web.archive.org) set tail string and service ID
estratto da mw.uri.new() (es. web.archive.org)
]]
local function serviceName(url_main, nolink)
local tracking = "'Categoria:Template Webarchive - altri archivi"'
local bracketopen, bracketclose = "nolink and '' or '[["', nolink and '' or ']]'
url_main.service = "'altri"'
local bracketclose = "]]"
if nolink then
bracketopen = ""
bracketclose = ""
end
 
url_main.service = "altri"
for _,servizio in ipairs(servizi) do
if mw.ustring.find(url_main.host, servizio.signature) then
Riga 291 ⟶ 282:
 
--[[--------------------------< createTracking >-----------------------
ReturnRestituisce datai dati in track[], ovvero le ie.categorie trackingdi categoriestracciamento
]]
local function createTracking()
-- ReturnProcede trackingsolo category only innel namespace 0
local current_namespace = mw.title.getCurrentTitle().namespace
if current_namespace ~= 0 then return '' end
local sand = ''
 
local sand = ""
if tableLength(track) > 0 then
for key,_ in pairs(track) do
sand = sand .. "'[["' .. key .. "']]"'
end
end
Riga 376 ⟶ 366:
-- carico in args i parametri, se sono nulli sono ignorati, eccetto che per il parametro nolink
local args = getArgs(frame, {
valueFunc = function (key, value)
if key == 'nolink' then
return true
Riga 387 ⟶ 377:
})
 
-- Verifica eventuali errori nel parametro url
local tname = "Webarchive" -- name of calling template. Change if template rename.
local verifydates = "yes" -- See documentation. Set "no" to disable.
 
-- URL argument (first)
local url1 = args.url or args.url1
if not url1 then
return inlineError("url", "vuoto") .. createTracking()
ifelseif mw.ustring.find( url1, "https://web.http") then -- track bug
end
if mw.ustring.find( url1, "https://web.http") then -- track bug
track["Categoria:Errori di compilazione del template Webarchive"] = 1
return inlineError("url", "https://web.http") .. createTracking()
ifelseif url1 == "https://web.archive.org/http:/" then -- track bug
end
if url1 == "https://web.archive.org/http:/" then -- track bug
track["Categoria:Errori di compilazione del template Webarchive"] = 1
return inlineError("url", "URL non valido") .. createTracking()
Riga 412 ⟶ 397:
-- Date argument
local date = args.date or args.date1 or args.data or args.data1
if date and (url_main.service == "*"'wayback' andor url_main.service == "wayback"'webcite') then
date = "index"formatDate(date)
elseif local dateudate and= url_main.service == "'wayback"' and verifydatesp.decodeWaybackDate( ==uri1.path "yes") thenor
local udate = p.decodeWebciteDate( uri1.path, ldf )
local ldf = dateFormat(date)
if ldfudate ~= date then
date = udatedate .. inlineRed("<sup>[Date non combacianti]</sup>", "warning")
local udate = p.decodeWaybackDate( uri1.path, ldf )
if udate ~= date then
date = udate .. inlineRed("<sup>[Date non combacianti]</sup>", "warning")
end
end
elseif date and url_main.service == "webcite" and verifydates == "yes" then
local ldf = dateFormat(date)
if ldf then
local udate = p.decodeWebciteDate( uri1.path, ldf )
if udate == "query" then -- skip
elseif udate ~= date then
date = udate .. inlineRed("<sup>[Date non combacianti]</sup>", "warning")
end
end
elseif not date and url_main.service == "wayback" then
Riga 464 ⟶ 437:
local rend = createRendering(url_main, ulx)
if not rend then
rend = mw.ustring.format('<span style="font-size:100%" class="error citation-comment">Errori in [[:Template:%sWebarchive]]: Problemaproblema sconosciuto. Si prega di segnalarlo nella [[Discussioni_template:%sWebarchive|pagina di discussione]] del template.</span>', tname, tname)
track["Category:Webarchive template errors"] = 1
end