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
decifrare la data negli URL di alcuni archivi anche ad altri moduli.
]]
require('
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Webarchive/Configurazione/sandbox')
Riga 119:
--[[--------------------------< decodeWebciteDate >-----------------------
Ricava la data da un
]]
local function decodeWebciteDate(
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
return
elseif mw.ustring.find(path_elements[2], 'query') or
Line 149 ⟶ 148:
--[[--------------------------< snapDateToString >-----------------------
Ricava la data da un
Gestisce anche le non cifre come "re_", "-" e "*".
]]
local function decodeWaybackDate(
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
Gestisce "." e "-" nella data, rendendo 2016.08.28-144552 uguale a 20160828144552.
]]
local function decodeArchiveisDate(
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 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
end
track[tracking] = 1
Line 271 ⟶ 268:
]]
function p.decodeArchiveDate(url)
local
▲ 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(
elseif servizio.service == 'webcite' then
return decodeWebciteDate(
elseif servizio.service == 'archiveis' then
return decodeArchiveisDate(
end
end
Line 296 ⟶ 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
Riga 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 334 ⟶ 337:
if date then
date = formatDate(date)
local udate = url_data[i].service == 'wayback' and decodeWaybackDate(url_data[i].
url_data[i].service == 'webcite' and decodeWebciteDate(url_data[i].
url_data[i].service == 'archiveis' and decodeArchiveisDate(url_data[i].
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].
elseif url_data[i].service == 'webcite' then
date = decodeWebciteDate(url_data[i].
elseif url_data[i].service == 'archiveis' then
date = decodeArchiveisDate(url_data[i].
else
date = inlineRed('Data mancante', 'warning')
|