Modulo:Webarchive: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
correzioni varie |
Rollback (credevo che stavo lavorando in sandbox) |
||
Riga 5:
]]
local p = {}
local servizi = {
Line 81 ⟶ 76:
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 >-----------------------
Line 123 ⟶ 139:
]]
local function tableLength(
local count = 0
for _ in pairs(
return count
end
Line 227 ⟶ 243:
-- 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"
Line 251 ⟶ 267:
end
if not fulldate then
return inlineRed("[Date error] (4)", "error")
Line 272 ⟶ 288:
local snapdate, snapdatelong, currdate, fulldate
local safe = path
local
snapdate =
if snapdate == "*" then -- eg. /web/*/http..
return "index"
Line 313 ⟶ 329:
end
if not fulldate then
return inlineRed("[Date error] (7)", "error")
Line 328 ⟶ 344:
]]
local function serviceName(
local tracking = "Categoria:Template Webarchive - altri archivi"
Line 338 ⟶ 354:
end
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(
if servizio['tailbracket'] then
else
end
tracking = servizio['tracking'] or tracking
break
end
end
track[tracking] = 1
Line 371 ⟶ 385:
]]
local function parseExtraArgs(
local i,
for i = 2, maxurls do
argurl = "url" .. i
if trimArg(args[argurl]) then
ulx[
ulx[
ulx[argurl2]["date"] = inlineRed("[Data mancante]", "warning")
end
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 >-----------------------
Line 400 ⟶ 425:
local function comma(date)
local
local
if
if not tonumber(
return ","
else
Line 438 ⟶ 463:
]]
local function createRendering(
local sand, displayheader, displayfield
Line 445 ⟶ 470:
local period2 = "."
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 = "[" ..
else
return nil
end
if
local tot = ulx.url1.extraurls + 1
sand = sand .. period2 .. " Archivi aggiuntivi: "
for i=2,tot do
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
Line 480 ⟶ 516:
-- For {{cite archives}}
else
if
displayheader = "Archivi aggiuntivi: "
else -- Multiple pages from the same archive
displayheader = "Pagine di archivio
end
local tot = 1 + ulx.url1.extraurls
local sand = displayheader
for i=1,tot do
displayfield =
if
if not displayfield then
displayfield = end
else
if not displayfield then
displayfield = "Pagina " .. end
end
sand = sand .. "[" .. ulx[indx]["url"] .. " " .. displayfield .. "]"
if i == tot then
sand = sand .. "."
else
sand = sand .. ", "
end
end
return sand
end
Line 502 ⟶ 547:
function p.webarchive(frame)
if (args[1]==nil) and (args["url"]==nil) then -- if no argument provided than check parent template/module args
args = frame:getParent().args
end
local tname = "Webarchive" -- name of calling template. Change if template rename.
ulx = {} -- Associative array to hold template data
track = {} -- Associative array to hold tracking categories
maxurls = 10 -- Max number of URLs allowed.
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()
Line 535 ⟶ 572:
end
local uri1 = mw.uri.new(ulx.url1.url)
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
date = "index"
elseif date and
local ldf = dateFormat(date)
if ldf then
Line 553 ⟶ 595:
end
end
elseif date and
local ldf = dateFormat(date)
if ldf then
Line 562 ⟶ 604:
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
Line 577 ⟶ 619:
date = inlineRed("[Data mancante]", "warning")
end
-- Format argument
local format = trimArg(args.format) or trimArg(args.formato)
if not format then
format = "none"
else
if format == "addlpages" then
if not
format = "none"
end
Line 594 ⟶ 636:
end
end
-- Title argument
ulx.url1.title = title
local rend = createRendering(
if not rend then
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>'
|