Modulo:Webarchive: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Rollback (credevo che stavo lavorando in sandbox) |
aggiorno dopo refactoring in sandbox |
||
Riga 5:
]]
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local track = {} -- Associative array to hold tracking categories
local maxurls = 10 -- Max number of URLs allowed.
local servizi = {
Riga 76 ⟶ 81:
end
--[[--------------------------< base62 >-----------------------
Riga 139 ⟶ 123:
]]
local function tableLength(
local count = 0
for _ in pairs(
return count
end
Riga 204 ⟶ 188:
local zmonth = month -- month with leading 0
month = month:match("0*(%d+)") -- month without leading 0
if tonumber(month) < 1 or tonumber(month) > 12 then return year end
local nmonth = month_localized[tonumber(month)]
if not nmonth then return year end
local zday = day
day = zday:match("0*(%d+)")
Riga 243 ⟶ 221:
-- http://www.webcitation.org/getfile.php?fileid=1c46e791d68e89e12d0c2532cc3cf629b8bc8c8e
if mw.ustring.find( dt.split[2], "query"
mw.ustring.find( dt.split[2], "cache"
mw.ustring.find( dt.split[2], "getfile"
tonumber(dt.split[2]) then
return "query"
Riga 267 ⟶ 245:
end
local fulldate = makeDate(dt.year, dt.month, dt.day, df)
if not fulldate then
return inlineRed("[Date error] (4)", "error")
Riga 288 ⟶ 266:
local snapdate, snapdatelong, currdate, fulldate
local snapdate = string.gsub(
local safe = snapdate
local
snapdate =
if snapdate == "*" then -- eg. /web/*/http..
return "index"
Riga 329 ⟶ 307:
end
local fulldate = makeDate(year, month, day, df)
if not fulldate then
return inlineRed("[Date error] (7)", "error")
Riga 344 ⟶ 322:
]]
local function serviceName(
local tracking = "Categoria:Template Webarchive - altri archivi"
Riga 354 ⟶ 332:
end
for _,servizio in ipairs(servizi) do
if mw.ustring.find(url_main.host, servizio.signature
if servizio['tailbracket'] then
else
end
tracking = servizio['tracking'] or tracking
break
end
end
if url_main.tail == nil then
url_main.tail = " a " .. url_main.host .. " " .. inlineRed("Errore: URL di servizio di archiviazione sconosciuto")
end
track[tracking] = 1
Riga 374 ⟶ 354:
--[[--------------------------< parseExtraArgs >-----------------------
Parse numbered arguments
e memorized them in a table
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
urlx
Returns the parsed table
]]
local function parseExtraArgs(args, maxurls)
local i,
local ulx = {}
for i = 2, maxurls do
argurl = "url" .. i
if
ulx[
ulx[
if not ulx[
end
ulx[indx]["title"] = args["title" .. i] or args["titolo" .. i]
indx = indx + 1
end
end
return ulx
end
--[[--------------------------< comma >-----------------------
Riga 425 ⟶ 394:
local function comma(date)
local
local
if
if not tonumber(
return ","
else
Riga 463 ⟶ 432:
]]
local function createRendering(url_main, ulx)
local sand, displayheader, displayfield
Riga 470 ⟶ 439:
local period2 = "."
--local url_main = ulx[1]
local indexstr = "archiviato"
if
indexstr = "archivio"
end
-- For {{wayback}}, {{webcite}}
if
if not
sand =
elseif not
if
period1 = "."
period2 = ""
end
sand =
elseif
sand =
elseif
sand = mw.ustring.format("[%s %s]%s (%s %s)", url_main.url, url_main.title, url_main.tail, indexstr, url_main.date)
else
return nil
end
if #ulx
sand = sand .. period2 .. " Archivi aggiuntivi: "
local archives_output = {}
archives_output[#archives_output+1] = mw.ustring.format("[%s %s]", urlx["url"], urlx["title"] or urlx["date"] )
end
sand = sand .. table.concat(archives_output, ", ") .. "."
end
return sand
Riga 516 ⟶ 474:
-- For {{cite archives}}
else
if
displayheader = "Archivi aggiuntivi: "
else -- Multiple pages from the same archive
displayheader = mw.ustring.format("Pagine di archivio
end
local sand = displayheader
local archives_output = {}
displayfield =
if
if not displayfield then displayfield = urlx["date"] end
else
if not displayfield then displayfield = "Pagina " .. indx+1 end
end
archive_ouptut[#archives_output+1] = mw.ustring.format("[%s %s]", urlx["url"], displayfield )
end
sand = mw.ustring.format("%s%s.", sand, table.concat(archive_output, ", "))
return sand
end
end
--[[--------------------------< createRendering >-----------------------
Funzione di interfaccia principale per implementazione di
template:Webarchive
]]
function p.webarchive(frame)
-- carico in args i parametri, se sono nulli sono ignorati, eccetto che per il prametro nolink
local args = getArgs(frame, {
valueFunc = function (key, value)
if key == 'nolink' then
return true
elseif value then
value = mw.text.trim(value)
if value ~= '' then return value end
end
return nil
end
})
local tname = "Webarchive"
local verifydates = "yes" -- See documentation. Set "no" to disable.
-- URL argument (first)
local url1 =
if not url1 then
return inlineError("url", "
end
if mw.ustring.find( url1, "https://web.http"
track["Categoria:Errori di compilazione del template Webarchive"] = 1
return inlineError("url", "https://web.http") .. createTracking()
Riga 572 ⟶ 534:
end
local uri1 = mw.uri.new(
serviceName(url_main, args.nolink)
-- Date argument
local date =
if date == "*" and
date = "index"
elseif date and
local ldf = dateFormat(date)
if ldf then
Riga 595 ⟶ 552:
end
end
elseif date and
local ldf = dateFormat(date)
if ldf then
Riga 604 ⟶ 561:
end
end
elseif not date and
date = decodeWaybackDate( uri1.path, "iso" )
if not date then
date = inlineRed("[Date error] (1)", "error")
end
elseif not date and
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
-- Format argument
local format =
if not format ~= "none" then
if format == "addlpages" then
if not
format = "none"
end
elseif format
format = "none"
end
end
-- Title argument
local ulx = parseExtraArgs(args, maxurls)
--if true then return mw.text.jsonEncode(ulx, mw.text.JSON_PRETTY) end
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:
track["Category:Webarchive template errors"] = 1
end
|