Modulo:Webarchive: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix
m modulo no globals obsoleto
 
(10 versioni intermedie di 4 utenti non mostrate)
Riga 1:
--[[ ----------------------------------
Modulo Lua che implementa il template {{Webarchive}} e permette di
Lua module implementing the {{webarchive}} template.
decifrare la data negli URL di alcuni archivi anche ad altri moduli.
]]
 
require('strict')
A merger of the functionality of three templates: {{wayback}}, {{webcite}} and {{cite archives}}
 
local getArgs = require('Modulo:Arguments').getArgs
]]
local cfg = mw.loadData('Modulo:Webarchive/Configurazione')
 
local p = {}
local track = {} -- array associativo per accumulare le categorie di tracciamento
 
local maxurls = 10 -- massimo numero di URL permessi
local servizi = {
local encoded_date
{ signature = "archive.org", service = "wayback", tailbracket = " all'%sInternet Archive%s", tracking = "Categoria:Template Webarchive - collegamenti all'Internet Archive" },
{ signature = "webcitation.org", service = "webcite", tailbracket = " a %sWebCite%s", tracking = "Categoria:Template Webarchive - collegamenti a WebCite" },
{ signature = "archive.is", service = "archiveis", tailbracket = " a %sArchive.is%s", tracking = "Categoria:Template Webarchive - collegamenti a archive.is" },
{ signature = "archive.fo", service = "archiveis", tailbracket = " a %sArchive.is%s", tracking = "Categoria:Template Webarchive - collegamenti a archive.is" },
{ signature = "archive.today", service = "archiveis", tailbracket = " a %sArchive.is%s", tracking = "Categoria:Template Webarchive - collegamenti a archive.is" },
{ signature = "archive.il", service = "archiveis", tailbracket = " a %sArchive.is%s", tracking = "Categoria:Template Webarchive - collegamenti a archive.is" },
{ signature = "archive.ec", service = "archiveis", tailbracket = " a %sArchive.is%s", tracking = "Categoria:Template Webarchive - collegamenti a archive.is" },
{ signature = "archive[-]it.org", service = "archiveit", tailbracket = " a %sArchive-It%s" },
{ signature = "arquivo.pt", tail = " al Portuguese Web Archive" },
{ signature = "loc.gov", tailbracket = " al %sLibrary of Congress%s" },
{ signature = "webharvest.gov", tailbracket = " al %sNational Archives and Records Administration%s" },
{ signature = "bibalex.org", tail = " alla [[Bibliotheca Alexandrina#Struttura e collezioni|Bibliotheca Alexandrina]]" },
{ signature = "collectionscanada", tail = " al Canadian Government Web Archive" },
{ signature = "haw.nsk", tail = " al Croatian Web Archive (HAW)" },
{ signature = "veebiarhiiv.digar.ee", tail = " all'Estonian Web Archive" },
{ signature = "vefsafn.is", tailbracket = " al %sNational and University Library of Iceland%s]]" },
{ signature = "proni.gov", tailbracket = " al %sPublic Record Office of Northern Ireland%s" },
{ signature = "uni[-]lj.si", tail = " al Slovenian Web Archive" },
{ signature = "stanford.edu", tail = " al [[Stanford University Libraries|Stanford Web Archive]]" },
{ signature = "nationalarchives.gov.uk", tailbracket = " all'%sUK Government Web Archive%s" },
{ signature = "parliament.uk", tailbracket = " all'%sUK Parliament's Web Archive%s" },
{ signature = "webarchive.org.uk", tailbracket = " all'%sUK Web Archive%s" },
{ signature = "nlb.gov.sg", tail = " al Web Archive Singapore" },
{ signature = "pandora.nla.gov.au", tailbracket = " al %sPandora Archive%s" },
{ signature = "perma.cc", tailbracket = " a %sPerma.cc%s" },
{ signature = "perma-archives.cc", tailbracket = " a %sPerma.cc%s" },
{ signature = "screenshots.com", tail = " a Screenshots" },
{ signature = "wikiwix.com", tail = " a Wikiwix" },
{ signature = "freezepage.com", tail = " a Freezepage" },
{ signature = "webcache.googleusercontent.com", tail = " a Google Cache" }
}
 
local month_localized = { 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno',
'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'}
 
--[[--------------------------< inlineError >-----------------------
Errore critico. Formatta l'output completamente in rosso. Aggiunge una categoria di tracciamento.
 
Critical error. Render output completely in red. Add to tracking category.
 
]]
 
local function inlineError(arg, msg)
track['Categoria:Errori di compilazione del template Webarchive'] = 1
 
return '<span style="font-size:100%" class="error citation-comment">Errore di compilazione del template Webarchive: controllare il valore di <code style="color:inherit; border:inherit; padding:inherit;">&#124;' .. arg .. '=</code> (' .. msg .. ').</span>'
track["Categoria:Errori di compilazione del template Webarchive"] = 1
return '<span style="font-size:100%" class="error citation-comment">Errore nella compilazione del template webarchive: controllare <code style="color:inherit; border:inherit; padding:inherit;">&#124;' .. arg .. '=</code> value. ' .. msg .. '</span>'
 
end
 
--[[--------------------------< inlineRed >-----------------------
Formatta un frammento di testo in rosso, quale ad esempio un avvertimento da integrare nell'output finale.
 
Aggiunge una categoria di tracciamento.
Render a text fragment in red, such as a warning as part of the final output.
Add tracking category.
 
]]
 
local function inlineRed(msg, trackmsg)
if trackmsg == 'warning' then
 
track['Categoria:Errori di compilazione del template Webarchive - Avvisi'] = 1
if trackmsg == "warning" then
elseif trackmsg == 'error' then
track["Categoria:Errori di compilazione del template Webarchive - Avvisi"] = 1
track['Categoria:Errori di compilazione del template Webarchive'] = 1
elseif trackmsg == "error" then
track["Categoria:Errori di compilazione del template Webarchive"] = 1
end
 
return '<span style="font-size:100%" class="error citation-comment">' .. msg .. '</span>'
 
end
 
--[[--------------------------< trimArg >-----------------------
 
trimArg returns nil if arg is "" while trimArg2 returns 'true' if arg is ""
trimArg2 is for args that might accept an empty value, as an on/off switch like nolink=
 
]]
 
local function trimArg(arg)
if arg == "" or arg == nil then
return nil
else
return mw.text.trim(arg)
end
end
local function trimArg2(arg)
if arg == nil then
return nil
else
return mw.text.trim(arg)
end
end
 
--[[--------------------------< base62 >-----------------------
Converte base-62 in base-10
 
Crediti: https://de.wikipedia.org/wiki/Modul:Expr
Convert base-62 to base-10
Credit: https://de.wikipedia.org/wiki/Modul:Expr
 
]]
 
local function base62( value )
 
local r = 1
if value:match('^%w+$') then
 
if value:match( "^%w+$" ) then
local n = #value
local k = 1
Line 116 ⟶ 49:
for i = n, 1, -1 do
c = value:byte( i, i )
if c >= 48 and c <= 57 then
c = c - 48
elseif c >= 65 and c <= 90 then
c = c - 55
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
Line 134 ⟶ 67:
 
--[[--------------------------< tableLength >-----------------------
Restituisce il numero di elementi in una tabella
 
Given a 1-D table, return number of elements
 
]]
local function tableLength(t)
 
local function tableLength(T)
local count = 0
for _ in pairs(Tt) do count = count + 1 end
return count
end
 
--[[--------------------------< formatDate >-----------------------
 
Verifica il formato di una data (dmy o iso) e se lo riconosce
--[[--------------------------< dateFormat >-----------------------
la riformatta in dmy, altrimenti restituisce il valore così com'è
 
Given a date string, return its format: dmy, mdy, iso, ymd
If unable to determine return nil
 
]]
local function formatDate(date)
 
local functiony, dateFormat(date)m, d
local try_year
 
local dtsplit = {}mw.text.split(date, '-')
dt.if tableLength(split) == 3 {}then
try_year = tonumber(split[1])
 
if try_year and try_year > 1900 and try_year < 2200 then -- iso
dt.split = mw.text.split(date, "-")
y, m, d = split[1], cfg.month_localized[tonumber(split[2])], split[3]
if tableLength(dt.split) == 3 then
if tonumber(dt.split[1]) > 1900 and tonumber(dt.split[1]) < 2200 and tonumber(dt.split[2]) and tonumber(dt.split[3]) then
return "iso"
else
return nil
end
else
end
split = mw.text.split(date, ' ')
 
if tableLength(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 and
if tonumber(dt.split[3]) then
if tonumber (dt.split[31]) >== 1900'1º' andor tonumber(dt.split[31])) <then 2200-- thendmy
ifd, m, y = tonumber(dt.split[1]), thensplit[2], split[3]
return "dmy"
else
return "mdy"
end
else
if tonumber(dt.split[1]) then
if tonumber(dt.split[1]) > 1900 and tonumber(dt.split[1]) < 2200 then
return "ymd"
end
end
end
end
end
d = tonumber(d) or d
return nil
if d == 1 then d = '1º' end
 
return m 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.
Given a zero-padded 4-digit year, 2-digit month and 2-digit day, return a full date in df format
df = mdy, dmy, iso, ymd
 
]]
local function formatUrlDate(y, m, d)
 
local current_year = tonumber(os.date('%Y'))
local function makeDate(year, month, day, df)
y, m, d = tonumber(y), tonumber(m), tonumber(d)
 
if not yeary or yeary == ""'' or not monthm or monthm == ""'' or not dayd or dayd == ""'' thenor d > 31 or
m < 1 or m > 12 or y < 1900 or y > current_year then
return nil
end
m = cfg.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 = os.date("%B", os.time{year=2000, month=month, day=1} ) -- month in name form
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 >-----------------------
Ricava la data da un URI-path a Webcite (es. /67xHmVFWP)
 
Given a URI-path to Webcite (eg. /67xHmVFWP) return the encoded date in df format
 
]]
local function decodeWebciteDate(path, df)
local path_elements = mw.text.split(path, '/')
 
-- formati URL validi che non sono base62:
local dt = {}
dt.split = {}
 
-- http://www.webcitation.org/query?id=1138911916587475
dt.split = mw.text.split(path, "/")
-- http://www.webcitation.org/query?url=http..&date=2012-06-01+21:40:03
 
-- http://www.webcitation.org/1138911916587475
-- valid URL formats that are not base62
-- http://www.webcitation.org/cache/73e53dd1f16cf8c5da298418d2a6e452870cf50e
 
-- http://www.webcitation.org/querygetfile.php?idfileid=11389119165874751c46e791d68e89e12d0c2532cc3cf629b8bc8c8e
-- http://www.webcitation.org/query?url=http..&date=2012-06-01+21:40:03
-- http://www.webcitation.org/1138911916587475
-- http://www.webcitation.org/cache/73e53dd1f16cf8c5da298418d2a6e452870cf50e
-- http://www.webcitation.org/getfile.php?fileid=1c46e791d68e89e12d0c2532cc3cf629b8bc8c8e
 
if mw.ustring.find( dt.split[2], "query", 1, plain) or
mw.ustring.find( dt.split[2], "cache", 1, plain) or
mw.ustring.find( dt.split[2], "getfile", 1, plain) or
tonumber(dt.split[2]) then
return "query"
end
 
dt.full = os.date("%Y %m %d", string.sub(string.format("%d", base62(dt.split[2])),1,10) )
dt.split = mw.text.split(dt.full, " ")
dt.year = dt.split[1]
dt.month = dt.split[2]
dt.day = dt.split[3]
 
if not tonumber(dt.year) or not tonumber(dt.month) or not tonumber(dt.day) then
return inlineRed("[Date error] (1)", "error")
end
 
if tonumber(dt.month) > 12 or tonumber(dt.day) > 31 or tonumber(dt.month) < 1 then
return inlineRed("[Date error] (2)", "error")
end
if tonumber(dt.year) > tonumber(os.date("%Y")) or tonumber(dt.year) < 1900 then
return inlineRed("[Date error] (3)", "error")
end
 
fulldate = makeDate(dt.year, dt.month, dt.day, df)
if not fulldate then
return inlineRed("[Date error] (4)", "error")
else
return fulldate
end
 
if not path_elements[2] or path_elements[2] == '' then
return
elseif mw.ustring.find(path_elements[2], 'query') or
mw.ustring.find(path_elements[2], 'cache') or
mw.ustring.find(path_elements[2], 'getfile') or
tonumber(path_elements[2]) then
encoded_date = false
return
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
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 "*".
Given a URI-path to Wayback (eg. /web/20160901010101/http://example.com )
return the formatted date eg. "September 1, 2016" in df format
Handle non-digits in snapshot ID such as "re_" and "-" and "*"
 
]]
local function decodeWaybackDate(path)
local snapdate = string.gsub(path, '^/all/', '') -- rimuove la sequenza iniziale "/all/"
snapdate = string.gsub(snapdate, '^/w?e?b?/?', '') -- rimuove la sequenza iniziale "/web/" o "/"
local path_elements = mw.text.split(snapdate, '/')
snapdate = path_elements[1]
if snapdate == '*' then return end
snapdate = string.gsub(snapdate, '[a-z][a-z]_[0-9]?$', '')
snapdate = string.gsub(snapdate, '[-]', '')
snapdate = string.gsub(snapdate, '[*]$', '')
local fulldate
if tonumber(snapdate) and string.len(snapdate) >= 8 then
local year = string.sub(snapdate, 1, 4)
local month = string.sub(snapdate, 5, 6)
local day = string.sub(snapdate, 7, 8)
fulldate = formatUrlDate(year, month, day)
end
return fulldate
end
 
--[[--------------------------< decodeArchiveisDate >-----------------------
local function decodeWaybackDate(path, df)
Ricava la data dall'URI-path di un link esteso ad Archive.is (es. /2016.08.28-144552/http://example.com).
 
Gestisce "." e "-" nella data, rendendo 2016.08.28-144552 uguale a 20160828144552.
local snapdate, snapdatelong, currdate, fulldate
]]
 
local safe =function decodeArchiveisDate(path)
local path_elements = mw.text.split(path, '/')
snapdate = string.gsub(safe, "^/w?e?b?/?", "") -- Remove leading "/web/" or "/"
safe = local snapdate = path_elements[2]
if not path_elements[2] or path_elements[2] == '' then return end
local N = mw.text.split(safe, "/")
snapdate = Nstring.gsub(snapdate, '[1%.%-]', '')
if not tonumber(snapdate) then encoded_date == "*"false thenreturn end -- eg.formato link /web/*/http..breve
local fulldate
return "index"
if string.len(snapdate) >= 8 then
end
safelocal year = string.sub(snapdate, 1, 4)
local month = string.sub(snapdate, 5, 6)
snapdate = string.gsub(safe, "[a-z][a-z]_[0-9]?$", "") -- Remove any trailing "re_" from date
safelocal day = string.sub(snapdate, 7, 8)
fulldate = formatUrlDate(year, month, day)
snapdate = string.gsub(safe, "[-]", "") -- Remove dashes from date eg. 2015-01-01
end
safe = snapdate
return fulldate
snapdate = string.gsub(safe, "[*]$", "") -- Remove trailing "*"
end
 
if not tonumber(snapdate) then
return inlineRed("[Date error] (2)", "error")
end
local dlen = string.len(snapdate)
if dlen < 4 then
return inlineRed("[Date error] (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("[Date error] (4)", "error")
end
if tonumber(month) > 12 or tonumber(day) > 31 or tonumber(month) < 1 then
return inlineRed("[Date error] (5)", "error")
end
currdate = os.date("%Y")
if tonumber(year) > tonumber(currdate) or tonumber(year) < 1900 then
return inlineRed("[Date error] (6)", "error")
end
 
fulldate = makeDate(year, month, day, df)
if not fulldate then
return inlineRed("[Date error] (7)", "error")
else
return fulldate
end
 
end
 
--[[--------------------------< serviceName >-----------------------
Imposta la stringa di coda e l'ID del servizio in base al dominio
 
Givenestratto a ___domain extracted byda mw.uri.new() (eges. web.archive.org) set tail string and service ID
 
]]
local function serviceName(url_data, nolink, notail)
 
local tracking = 'Categoria:Template Webarchive - collegamenti ad altri archivi'
local function serviceName(host, nolink)
local bracketopen, bracketclose = nolink and '' or '[[', nolink and '' or ']]'
 
encoded_date = nil -- reset
local tracking = "Categoria:Template Webarchive - altri archivi"
for _,servizio in ipairs(cfg.servizi) do
local bracketopen = "[["
if string.gsub(url_data.host, 'www%.', '') == servizio.signature then
local bracketclose = "]]"
url_data.service = servizio.service or 'altri'
if nolink then
if not notail and servizio.tailbracket then
bracketopen = ""
url_data.tail = mw.ustring.format(servizio.tailbracket, bracketopen, bracketclose)
bracketclose = ""
elseif not notail then
end
url_data.tail = servizio.tail
 
ulx.url1.service = "altri"
ulx.url1.tail = " a " .. ulx.url1.host .. " " .. inlineRed("Errore: URL di servizio di archiviazione sconosciuto")
 
for _,servizio in ipairs(servizi) do
if mw.ustring.find(host, servizio.signature, 1, plain) then
ulx.url1.service = servizio['service'] or ulx.url1.service
if servizio['tailbracket'] then
ulx.url1.tail = mw.ustring.format(servizio.tailbracket, bracketopen, bracketclose)
else
ulx.url1.tail = servizio['tail'] or ulx.url1.tail
end
tracking = servizio['.tracking'] or tracking
encoded_date = servizio.service and true
break
end
end
if url_data.service == nil then
tracking = 'Categoria:Template Webarchive - collegamenti ad archivi sconosciuti'
url_data.tail = ' su ' .. url_data.host .. ' ' .. inlineRed('URL di servizio di archiviazione sconosciuto')
end
track[tracking] = 1
end
 
--[[--------------------------< parseExtraArgs >-----------------------
 
Parse numbered arguments starting at 2, such as url2..url10, date2..date10, title2..title10
For example: {{webarchive |url=.. |url4=.. |url7=..}}
Three url arguments not in numeric sequence (1..4..7).
Function only processes arguments numbered 2 or greater (in this case 4 and 7)
It creates numeric sequenced table entries like:
urlx.url2.url = <argument value for url4>
urlx.url3.url = <argument value for url7>
Returns the number of URL arguments found numbered 2 or greater (in this case returns "2")
 
]]
 
local function parseExtraArgs()
 
local i, j, argurl, argurl2, argdate, argtitle
 
j = 2
for i = 2, maxurls do
argurl = "url" .. i
if trimArg(args[argurl]) then
argurl2 = "url" .. j
ulx[argurl2] = {}
ulx[argurl2]["url"] = args[argurl]
argdate = "date" .. j or "data" .. j
if trimArg(args[argdate]) then
ulx[argurl2]["date"] = args[argdate]
else
ulx[argurl2]["date"] = inlineRed("[Data mancante]", "warning")
end
argtitle = "title" .. j
if trimArg(args[argtitle]) then
ulx[argurl2]["title"] = args[argtitle]
else
ulx[argurl2]["title"] = nil
end
j = j + 1
end
end
 
if j == 2 then
return 0
else
return j - 2
end
 
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 le categorie di tracciamento inserite in track[]
 
Return data in track[] ie. tracking categories
 
]]
 
local function createTracking()
-- procede solo nel namespace 0
 
-- Return tracking category only in 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
return sand
 
end
 
--[[--------------------------< createRendering >-----------------------
Restituisce la resa dei dati in url_data[][]
 
Return a rendering of the data in ulx[][]
 
]]
local function createRendering(url_data)
 
local sand
local function createRendering()
local day = url_data[1].date and mw.ustring.match(url_data[1].date, '^%d+')
 
local article = (day == '8' or day == '11') and 'l\'' or 'il '
local sand, displayheader, displayfield
if not url_data[1].title and not url_data[1].date then
 
sand = mw.ustring.format('[%s Archiviato]%s.', url_data[1].url, url_data[1].tail)
local period1 = "" -- For backwards compat with {{wayback}}
elseif not url_data[1].title and url_data[1].date then
local period2 = "."
sand = mw.ustring.format('[%s Archiviato] %s%s%s.', url_data[1].url, article, url_data[1].date, url_data[1].tail)
 
elseif url_data[1].title and not url_data[1].date then
local indexstr = "archiviato"
sand = mw.ustring.format('[%s %s]%s.', url_data[1].url, url_data[1].title, url_data[1].tail)
if ulx.url1.date == "index" then
elseif url_data[1].title and url_data[1].date then
indexstr = "archivio"
sand = mw.ustring.format('[%s %s]%s&#32;(archiviato %s%s).', url_data[1].url, url_data[1].title, url_data[1].tail, article, url_data[1].date)
else
return nil
end
if #url_data > 1 then -- per più URL di archivio
-- For {{wayback}}, {{webcite}}
sand = sand .. ' Archivi aggiuntivi: '
 
local archives_output = {}
if ulx.url1.format == "none" then
for i = 2, #url_data do
if not ulx.url1.title and not ulx.url1.date then -- No title. No date
archives_output[#archives_output+1] = mw.ustring.format('[%s %s]%s%s', url_data[i].url, url_data[i].title or url_data[i].date, url_data[i].title and (' (' .. url_data[i].date .. ')') or '', url_data[i].tail or '')
sand = "[" .. ulx.url1.url .. " archiviato]" .. ulx.url1.tail
elseif not ulx.url1.title and ulx.url1.date then -- No title. Date.
if ulx.url1.service == "wayback" then
period1 = "."
period2 = ""
end
sand = "[" .. ulx.url1.url .. " archiviato] il " .. ulx.url1.date .. comma(ulx.url1.date) .. ulx.url1.tail .. period1
elseif ulx.url1.title and not ulx.url1.date then -- Title. No date.
sand = "[" .. ulx.url1.url .. " " .. ulx.url1.title .. "]" .. ulx.url1.tail
elseif ulx.url1.title and ulx.url1.date then -- Title. Date.
sand = "[" .. ulx.url1.url .. " " .. ulx.url1.title .. "]" .. ulx.url1.tail .. "&#32;(" .. indexstr .. " " .. ulx.url1.date .. ")"
else
return nil
end
sand = sand .. table.concat(archives_output, ', ') .. '.'
if ulx.url1.extraurls > 0 then -- For multiple archive URLs
end
local tot = ulx.url1.extraurls + 1
return sand
sand = sand .. period2 .. " Archivi aggiuntivi: "
end
for i=2,tot do
local indx = "url" .. i
if ulx[indx]["title"] then
displayfield = "title"
else
displayfield = "date"
end
sand = sand .. "[" .. ulx[indx]["url"] .. " " .. ulx[indx][displayfield] .. "]"
if i == tot then
sand = sand .. "."
else
sand = sand .. ", "
end
end
else
return sand
end
return sand
 
--[[--------------------------------------------------------------------
-- For {{cite archives}}
Entry point per chiamata diretta da un modulo.
else
Riceve l'URL di un archivio e ne restituisce la data se riesce a decodificarla.
if ulx.url1.format == "addlarchives" then -- Multiple archive services
]]
displayheader = "Archivi aggiuntivi: "
function p.decodeArchiveDate(url)
else -- Multiple pages from the same archive
local uri = mw.uri.new(url)
displayheader = "Pagine di archivio aggiuntivie&nbsp;su " .. ulx.url1.date .. ": "
local host, path = uri.host, uri.path
end
if not url or not host or path == '' then return end
local tot = 1 + ulx.url1.extraurls
host = string.gsub(host, 'www%.', '')
local sand = displayheader
for _, servizio in ipairs(cfg.servizi) do
for i=1,tot do
if host == servizio.signature then
local indx = "url" .. i
if servizio.service == 'wayback' then
displayfield = ulx[indx]["title"]
return decodeWaybackDate(path)
if ulx.url1.format == "addlarchives" then
ifelseif notservizio.service displayfield== 'webcite' then
return decodeWebciteDate(path)
displayfield = ulx[indx]["date"]
elseif servizio.service == 'archiveis' then
end
return decodeArchiveisDate(path)
else
if not displayfield then
displayfield = "Pagina " .. i
end
end
sand = sand .. "[" .. ulx[indx]["url"] .. " " .. displayfield .. "]"
if i == tot then
sand = sand .. "."
else
sand = sand .. ", "
end
end
return sand
end
return
end
 
--[[--------------------------------------------------------------------
Funzione di interfaccia principale per implementazione del
Template:Webarchive
]]
function p.webarchive(frame)
-- carica in args i parametri e se sono nulli li ignora, eccetto che per il parametro nolink
args = frame.args
local args = getArgs(frame, {
if (args[1]==nil) and (args["url"]==nil) then -- if no argument provided than check parent template/module args
valueFunc = function(key, value)
args = frame:getParent().args
if value then
end
if key == 'nolink' then
 
return true
local tname = "Webarchive" -- name of calling template. Change if template rename.
else
ulx = {} -- Associative array to hold template data
value = mw.text.trim(value)
track = {} -- Associative array to hold tracking categories
if value ~= '' then return value end
maxurls = 10 -- Max number of URLs allowed.
end
local verifydates = "yes" -- See documentation. Set "no" to disable.
 
-- URL argument (first)
local url1 = trimArg(args.url) or trimArg(args.url1)
if not url1 then
return inlineError("url", "Empty.") .. createTracking()
end
if mw.ustring.find( url1, "https://web.http", 1, plain ) then -- track bug
track["Categoria:Errori di compilazione del template Webarchive"] = 1
return inlineError("url", "https://web.http") .. createTracking()
end
if url1 == "https://web.archive.org/http:/" then -- track bug
track["Categoria:Errori di compilazione del template Webarchive"] = 1
return inlineError("url", "Invalid URL") .. createTracking()
end
 
ulx.url1 = {}
ulx.url1.url = url1
local uri1 = mw.uri.new(ulx.url1.url)
ulx.url1.host = uri1.host
ulx.url1.extraurls = parseExtraArgs()
 
-- Nolink argument
local nolink = trimArg2(args.nolink)
 
serviceName(uri1.host, nolink)
 
-- Date argument
local date = trimArg(args.date) or trimArg(args.date1)
if date == "*" and ulx.url1.service == "wayback" then
date = "index"
elseif date and ulx.url1.service == "wayback" and verifydates == "yes" then
local ldf = dateFormat(date)
if ldf then
local udate = decodeWaybackDate( uri1.path, ldf )
if udate ~= date then
date = udate .. inlineRed("<sup>[Date mismatch]</sup>", "warning")
end
return nil
end
})
elseif date and ulx.url1.service == "webcite" and verifydates == "yes" then
local ldfurl_data = dateFormat(date){}
local i = 1
if ldf then
while true do
local udate = decodeWebciteDate( uri1.path, ldf )
local n = i == 1 and args.url and '' or i
if udate == "query" then -- skip
local url = i == 1 and (args.url or args.url1) or args['url' .. i]
elseif udate ~= date then
 
date = udate .. inlineRed("<sup>[Date mismatch]</sup>", "warning")
-- verifica eventuali errori nel parametro url
end
if i == 1 and not url then
return inlineError('url', 'vuoto') .. createTracking()
elseif not url or i > maxurls then
break
elseif mw.ustring.find(url, 'https://web.http') then
track['Categoria:Errori di compilazione del template Webarchive'] = 1
return inlineError('url' .. n, 'https://web.http') .. createTracking()
elseif url == 'https://web.archive.org/http:/' then
track['Categoria:Errori di compilazione del template Webarchive'] = 1
return inlineError('url' .. n, 'URL non valido') .. createTracking()
end
url_data[i] = {}
elseif not date and ulx.url1.service == "wayback" then
url_data[i].url = url
date = decodeWaybackDate( uri1.path, "iso" )
url_data[i].uri = mw.uri.new(url)
if not date then
url_data[i].host, url_data[i].path = url_data[i].uri.host, url_data[i].uri.path
date = inlineRed("[Date error] (1)", "error")
if not url_data[i].host or url_data[i].path == '' then
return inlineError('url' .. n, 'URL non valido') .. createTracking()
end
serviceName(url_data[i], args.nolink, i > 1 and true)
elseif not date and ulx.url1.service == "webcite" then
date = decodeWebciteDate( uri1.path, "iso" )
if date == "query" then
date = inlineRed("[Data mancante]", "warning")
elseif not date then
date = inlineRed("[Date error] (1)", "error")
end
elseif not date then
date = inlineRed("[Data mancante]", "warning")
end
ulx.url1.date = date
 
-- gestione delle date
-- Format argument
local formatdate = trimArgi == 1 and (args.format)date or trimArg(args.formatodate1 or args.data or args.data1) or
args['date' .. i] or args['data' .. i]
if not format then
if date then
format = "none"
date = formatDate(date)
else
local udate = url_data[i].service == 'wayback' and decodeWaybackDate(url_data[i].path) or
if format == "addlpages" then
url_data[i].service == 'webcite' and decodeWebciteDate(url_data[i].path) or
if not ulx.url1.date then
url_data[i].service == 'archiveis' and decodeArchiveisDate(url_data[i].path)
format = "none"
if udate and udate ~= date then
date = date .. ' ' .. inlineRed('Data nell\'URL non combaciante: ' .. udate, 'warning')
elseif not udate and encoded_date == true then
date = date .. ' ' .. inlineRed('Data nell\'URL indecifrabile', 'error')
end
elseif formaturl_data[i].service == "addlarchives"'wayback' then
date = decodeWaybackDate(url_data[i].path)
format = "addlarchives"
elseif url_data[i].service == 'webcite' then
date = decodeWebciteDate(url_data[i].path)
elseif url_data[i].service == 'archiveis' then
date = decodeArchiveisDate(url_data[i].path)
else
date = inlineRed('Data mancante', 'warning')
format = "none"
end
if not date then
end
date = encoded_date == false and inlineRed('Data mancante', 'warning') or
ulx.url1.format = format
inlineRed('Data nell\'URL indecifrabile', 'error')
end
url_data[i].date = date
 
-- gestione del titolo
-- Title argument
local url_data[i].title = trimArgi == 1 and (args.title) or trimArg(args.title1) or trimArg(args.titolo) or trimArg(args.titolo1) or
args['title' .. i] or args['titolo' .. i]
ulx.url1.title = title
 
i = i + 1
local rend = createRendering()
end
local rend = createRendering(url_data)
if not rend then
track['Categoria:Errori di compilazione del template Webarchive'] = 1
rend = '<span style="font-size:100%" class="error citation-comment">Errori in [[:Template:' .. tname .. ']]: Problema sconosciuto. Si prega di segnalarlo nella [[Discussioni_template:' .. tname .. '|pagina di discussione]] del template.</span>'
rend = '<span style="font-size:100%" class="error citation-comment">Errori in [[:Template:Webarchive]]: problema sconosciuto. Si prega di segnalarlo nella [[Discussioni template:Webarchive|pagina di discussione]] del template.</span>'
track["Category:Webarchive template errors"] = 1
end
 
return rend .. createTracking()
 
end