Modulo:Webarchive/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m semplifico |
use require('strict') instead of require('Module:No globals') |
||
(6 versioni intermedie di un altro utente non mostrate) | |||
Riga 1:
--[[ ----------------------------------
Modulo Lua che implementa il template {{Webarchive}} e
decifrare la data negli URL di alcuni archivi anche ad altri moduli.
]]
require('
local getArgs = require('
local cfg = mw.loadData('Modulo:Webarchive/Configurazione/sandbox')
local p = {}
Line 11 ⟶ 12:
local maxurls = 10 -- massimo numero di URL permessi
local encoded_date
--[[--------------------------< inlineError >-----------------------
Line 129 ⟶ 85:
try_year = tonumber(split[1])
if try_year and try_year > 1900 and try_year < 2200 then -- iso
y, m, d = split[1], cfg.month_localized[tonumber(split[2])], split[3]
end
else
Line 157 ⟶ 113:
return nil
end
m = cfg.month_localized[m]
if d == 1 then d = '1º' end
return mw.ustring.format('%s %s %s', d, m, y)
Line 163 ⟶ 119:
--[[--------------------------< decodeWebciteDate >-----------------------
Ricava la data da un
]]
local function
local path = mw.uri.new(url).path▼
local path_elements = mw.text.split(path, '/')
Line 177 ⟶ 132:
-- http://www.webcitation.org/getfile.php?fileid=1c46e791d68e89e12d0c2532cc3cf629b8bc8c8e
if
return
elseif mw.ustring.find(path_elements[2], 'query') or
Line 193 ⟶ 148:
--[[--------------------------< snapDateToString >-----------------------
Ricava la data da un
Gestisce anche le non cifre come "re_", "-" e "*".
]]
local function
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 218 ⟶ 171:
--[[--------------------------< decodeArchiveisDate >-----------------------
]]
local function
local path_elements = mw.text.split(path, '/')
local snapdate = path_elements[2]
if
snapdate = string.gsub(snapdate, '[%.%-]', '')
if not tonumber(snapdate) then encoded_date = false return end -- formato link breve
Line 243 ⟶ 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
for _,servizio in ipairs(cfg.servizi) do
if string.gsub(url_data.host, 'www%.', '') == servizio.signature then
url_data.service = servizio.service or 'altri'
Line 260 ⟶ 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
end
track[tracking] = 1
Line 282 ⟶ 235:
--[[--------------------------< createRendering >-----------------------
]]
local function createRendering(url_data)
Line 311 ⟶ 264:
--[[--------------------------------------------------------------------
Entry point per chiamata diretta da un modulo.
Funzione di interfaccia principale per implementazione del▼
Riceve l'URL di un archivio e ne restituisce la data se riesce a decodificarla.
Template:Webarchive▼
]]
function p.decodeArchiveDate(url)
▲ 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(path)
elseif servizio.service == 'webcite' then
return decodeWebciteDate(path)
elseif servizio.service == 'archiveis' then
return decodeArchiveisDate(path)
end
end
end
return
end
--[[--------------------------------------------------------------------
]]
function p.webarchive(frame)
Line 318 ⟶ 294:
local args = getArgs(frame, {
valueFunc = function(key, value)
if
if key == 'nolink' then
return true
else
value = mw.text.trim(value) if value ~= '' then return value end
end
end
return nil
Line 347 ⟶ 325:
url_data[i] = {}
url_data[i].url = url
url_data[i].
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 356 ⟶ 337:
if date then
date = formatDate(date)
local udate = url_data[i].service == 'wayback' and
url_data[i].service == 'webcite' and
url_data[i].service == 'archiveis' and
if udate and udate ~= date then
date = date .. ' ' .. inlineRed('Data nell\'URL non combaciante: ' .. udate, 'warning')
Line 365 ⟶ 346:
end
elseif url_data[i].service == 'wayback' then
date =
elseif url_data[i].service == 'webcite' then
date =
elseif url_data[i].service == 'archiveis' then
date =
else
date = inlineRed('Data mancante', 'warning')
|