Modulo:Webarchive/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
entry point per chiamata da modulo
use require('strict') instead of require('Module:No globals')
 
(4 versioni intermedie di un altro utente non mostrate)
Riga 1:
--[[ ----------------------------------
Modulo Lua che implementa il template {{Webarchive}} e offrepermette alcunedi
decifrare la data negli URL di alcuni archivi anche ad altri moduli.
funzionalità ad altri moduli Lua per la gestione degli archivi.
]]
 
require('Module:No globalsstrict')
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Webarchive/Configurazione/sandbox')
Riga 119:
 
--[[--------------------------< decodeWebciteDate >-----------------------
Ricava la data da un URLURI-path a Webcite (es. www.webcitation.org/67xHmVFWP)
]]
local function decodeWebciteDate(urlpath)
local path = mw.uri.new(url).path
local path_elements = mw.text.split(path, '/')
 
Line 133 ⟶ 132:
-- http://www.webcitation.org/getfile.php?fileid=1c46e791d68e89e12d0c2532cc3cf629b8bc8c8e
 
if path == '' or not path_elements[2] or path_elements[2] == '' then
return
elseif mw.ustring.find(path_elements[2], 'query') or
Line 149 ⟶ 148:
 
--[[--------------------------< snapDateToString >-----------------------
Ricava la data da un URLURI-path a Wayback (es. web.archive.org/web/20160901010101/http://example.com ).
Gestisce anche le non cifre come "re_", "-" e "*".
]]
local function decodeWaybackDate(urlpath)
local path = mw.uri.new(url).path
if path == '' then return end
local snapdate = string.gsub(path, '^/all/', '') -- rimuove la sequenza iniziale "/all/"
snapdate = string.gsub(snapdate, '^/w?e?b?/?', '') -- rimuove la sequenza iniziale "/web/" o "/"
Line 174 ⟶ 171:
 
--[[--------------------------< decodeArchiveisDate >-----------------------
Ricava la data dadall'URI-path di un URLlink esteso ad Archive.is (es. https://archive.is/2016.08.28-144552/http://example.com).
Gestisce "." e "-" nella data, rendendo 2016.08.28-144552 uguale a 20160828144552.
]]
local function decodeArchiveisDate(urlpath)
local path = mw.uri.new(url).path
local path_elements = mw.text.split(path, '/')
local snapdate = path_elements[2]
if path == '' or not path_elements[2] or path_elements[2] == '' then return end
snapdate = string.gsub(snapdate, '[%.%-]', '')
if not tonumber(snapdate) then encoded_date = false return end -- formato link breve
Line 199 ⟶ 195:
]]
local function serviceName(url_data, nolink, notail)
local tracking = 'Categoria:Template Webarchive - collegamenti ad altri archivi'
local bracketopen, bracketclose = nolink and '' or '[[', nolink and '' or ']]'
encoded_date = nil -- reset
Line 216 ⟶ 212:
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', 'warning')
end
track[tracking] = 1
Line 271 ⟶ 268:
]]
function p.decodeArchiveDate(url)
local hosturi = mw.uri.new(url).host
local host, path = mw.uri.new(url)host, uri.path
if not url or not host then return end
if not url or not host or path == '' then return end
host = string.gsub(host, 'www%.', '')
for _, servizio in ipairs(cfg.servizi) do
if host == servizio.signature then
if servizio.service == 'wayback' then
return decodeWaybackDate(urlpath)
elseif servizio.service == 'webcite' then
return decodeWebciteDate(urlpath)
elseif servizio.service == 'archiveis' then
return decodeArchiveisDate(urlpath)
end
end
Line 296 ⟶ 294:
local args = getArgs(frame, {
valueFunc = function(key, value)
if key == 'nolink'value then
if key == 'nolink' then
return true
elseif value then
else
value = mw.text.trim(value)
if value ~= '' then return value end
end
end
return nil
Riga 325:
url_data[i] = {}
url_data[i].url = url
url_data[i].hosturi = mw.uri.new(url).host
if not url_data[i].host, thenurl_data[i].path return inlineError('url'= url_data[i].uri. nhost, 'URL non valido') endurl_data[i].uri.path
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)
 
Line 334 ⟶ 337:
if date then
date = formatDate(date)
local udate = url_data[i].service == 'wayback' and decodeWaybackDate(url_data[i].urlpath) or
url_data[i].service == 'webcite' and decodeWebciteDate(url_data[i].urlpath) or
url_data[i].service == 'archiveis' and decodeArchiveisDate(url_data[i].urlpath)
if udate and udate ~= date then
date = date .. ' ' .. inlineRed('Data nell\'URL non combaciante: ' .. udate, 'warning')
Line 343 ⟶ 346:
end
elseif url_data[i].service == 'wayback' then
date = decodeWaybackDate(url_data[i].urlpath)
elseif url_data[i].service == 'webcite' then
date = decodeWebciteDate(url_data[i].urlpath)
elseif url_data[i].service == 'archiveis' then
date = decodeArchiveisDate(url_data[i].urlpath)
else
date = inlineRed('Data mancante', 'warning')