Module:Webarchive: திருத்தங்களுக்கு இடையிலான வேறுபாடு

உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
sync from sandbox;
synch from sandbox;
வரிசை 5:
A merger of the functionality of three templates: {{wayback}}, {{webcite}} and {{cite archives}}
]]
 
 
--[[--------------------------< D E P E N D E N C I E S >------------------------------------------------------
]]
 
require('Module:No globals');
local getArgs = require ('Module:Arguments').getArgs;
local this_page = mw.title.getCurrentTitle();
 
 
வரி 15 ⟶ 18:
]]
 
local categories = {}; -- category names from ./data
local err_warn_msgsconfig = {}; -- error and warning messagesglobal fromconfiguration ./datasettings
local digits = {}; -- for i18n; table that translates local-wiki digits to western digits
local err_warn_msgs = {}; -- error and warning messages
local excepted_pages = {};
local prefixesmonth_num = {}; -- servicefor provideri18n; table that translates local-wiki tailmonth stringnames prefixesto fromwestern ./datadigits
local servicesprefixes = {}; -- archive service provider datatail fromstring ./dataprefixes
local services = {}; -- archive service provider data from
local s_text = {}; -- table of static text strings used to build final rendering
local uncategorized_namespaces = {}; -- list of namespaces that we should not categorize
local uncategorized_subpages = {}; -- list of subpages that should not be categorized
 
 
local ulx = {}; -- Associative array to hold template data
--[[--------------------------< P A G E S C O P E I D E N T I F I E R S >----------------------------------
]]
 
local non_western_digits; -- boolean flag set true when data.digits.enable is true
local this_page = mw.title.getCurrentTitle();
 
local track = {}; -- Associative array to hold tracking categories
local ulx = {}; -- Associative array to hold template data
 
 
--[[--------------------------< GS L OU B AS L C O N FT I GT U R A T I O N S E T T I N G S >----------------------------------------------------------
 
Populates numbered arguments in a message string using an argument table.
 
]]
 
local function substitute (msg, args)
local maxurls = 10; -- Max number of URLs allowed.
return args and mw.message.newRawMessage (msg, args):plain() or msg;
local tname = 'Webarchive' -- name of calling template. Change if template rename.
end
local verifydates = 'yes' -- See documentation. Set "no" to disable.
 
 
--[[--------------------------< tableLength >-----------------------
 
Given a 1-D table, return number of elements
 
]]
 
local function tableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
 
 
--[=[-------------------------< M A K E _ W I K I L I N K >----------------------------------------------------
 
Makes a wikilink; when both link and display text is provided, returns a wikilink in the form [[L|D]]; if only
link is provided, returns a wikilink in the form [[L]]; if neither are provided or link is omitted, returns an
empty string.
 
]=]
 
local function make_wikilink (link, display, no_link)
if nil == no_link then
if link and ('' ~= link) then
if display and ('' ~= display) then
return table.concat ({'[[', link, '|', display, ']]'});
else
return table.concat ({'[[', link, ']]'});
end
end
return display or ''; -- link not set so return the display text
 
else -- no_link
if display and ('' ~= display) then -- if there is display text
return display; -- return that
else
return link or ''; -- return the target article name or empty string
end
end
end
 
 
--[[--------------------------< createTracking >-----------------------
 
Return data in track[] ie. tracking categories
 
]]
 
local function createTracking()
if not excepted_pages[this_page.fullText] then -- namespace:title/fragment is allowed to be categorized (typically this module's / template's testcases page(s))
if uncategorized_namespaces[this_page.nsText] then
return ''; -- this page not to be categorized so return empty string
end
for _,v in ipairs (uncategorized_subpages) do -- cycle through page name patterns
if this_page.text:match (v) then -- test page name against each pattern
return ''; -- this subpage type not to be categorized so return empty string
end
end
end
 
local out = {};
if tableLength(track) > 0 then
for key, _ in pairs(track) do -- loop through table
table.insert (out, make_wikilink (key)); -- and convert category names to links
end
end
return table.concat (out); -- concat into one big string; empty string if table is empty
 
end
 
 
வரி 39 ⟶ 126:
 
Critical error. Render output completely in red. Add to tracking category.
 
This function called as the last thing before abandoning this module
 
]]
 
local function inlineError (argmsg, msgargs)
track[categories.error] = 1
return table.concat ({
return '<span style="font-size:100%" class="error citation-comment">Error in webarchive template: Check <code style="color:inherit; border:inherit; padding:inherit;">&#124;' .. arg .. '=</code> value. ' .. msg .. '</span>'
'<span style="font-size:100%" class="error citation-comment">Error in ', -- open the error message span
config.tname, -- insert the local language template name
' template: ',
substitute (msg, args), -- insert the formatted error message
'.</span>', -- close the span
createTracking() -- add the category
})
end
 
வரி 76 ⟶ 172:
local r = 1 -- default return value is input value is malformed
 
if value:match ( "^'%w+$" W') then -- value must only be in the set [0-9a-zA-Z]
local n = #valuereturn; -- numbernil ofreturn characters inwhen value contains extraneous characters
local k = 1
local c
r = 0
for i = n, 1, -1 do -- loop through all characters in value from ls digit to ms digit
c = value:byte( i, i )
if c >= 48 and c <= 57 then -- character is digit 0-9
c = c - 48
elseif c >= 65 and c <= 90 then -- character is ascii a-z
c = c - 55
else -- must be ascii A-Z
c = c - 61
end
r = r + c * k -- accumulate this base62 character's value
k = k * 62 -- bump for next
end -- for i
end
 
local n = #value -- number of characters in value
local k = 1
local c
r = 0
for i = n, 1, -1 do -- loop through all characters in value from ls digit to ms digit
c = value:byte( i, i )
if c >= 48 and c <= 57 then -- character is digit 0-9
c = c - 48
elseif c >= 65 and c <= 90 then -- character is ascii a-z
c = c - 55
else -- must be ascii A-Z
c = c - 61
end
r = r + c * k -- accumulate this base62 character's value
k = k * 62 -- bump for next
end -- for i
 
return r
end
 
 
--[[--------------------------< tableLengthD E C O D E _ D A T E >--------------------------------------------------------
 
Given a date string, return it in iso format along with an indicator of the date's format. Except that month names
Given a 1-D table, return number of elements
must be recognizable as legitimate month names with proper capitalization, and that the date string must match one
of the recognized date formats, no error checking is done here; return nil else
 
]]
 
local function tableLengthdecode_date (Tdate_str)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
 
 
--[[--------------------------< dateFormat >-----------------------
 
Given a date string, return its format: dmy, mdy, iso, ymd
If unable to determine return nil
 
]]
 
local function dateFormat(date)
 
local patterns = {
['dmy'] = {'^(%d%d?) +([^%s%d]+) +(%d%d%d%d)$', 'd', 'm', 'y'}, -- %a does not recognize unicode combining characters used by some languages
['iso'] = '(%d%d%d%d)%-%d%d%-%d%d',
['dmymdy'] = {'^([^%s%d]+) (%d%d? +%a+), +(%d%d%d%d)$', 'm', 'd', 'y'},
['mdyymd'] = {'^(%a+ d%d%d?,%d) +([^%ds%d]+) (%d%d?)$', 'y', 'm', 'd'}, -- not mos compliant at en.wiki but may be acceptible at other wikis
['ymd'] = '(%d%d%d%d) +%a+ %d%d?', -- TODO: not mos compliant; delete?
};
local t = {};
 
if non_western_digits then -- this wiki uses non-western digits?
local form, y;
date_str = mw.ustring.gsub (date_str, '%d', digits); -- convert this wiki's non-western digits to western digits
end
 
if date_str:match ('^%d%d%d%d%-%d%d%-%d%d$') then -- already an iso format date, return western digits form
for k, v in pairs (patterns) do -- loop through the patterns table
return date_str, 'iso';
y = mw.ustring.match (date, v); -- looking for a match
if y then -- not nil when found
form = k; -- save that
break; -- and done
end
end
for k, v in pairs (patterns) do
local c1, c2, c3 = mw.ustring.match (date_str, patterns[k][1]); -- c1 .. c3 are captured but we don't know what they hold
if c1 then -- set on match
t = { -- translate unspecified captures to y, m, and d
[patterns[k][2]] = c1, -- fill the table of captures with the captures
[patterns[k][3]] = c2, -- take index names from src_pattern table and assign sequential captures
[patterns[k][4]] = c3,
};
if month_num[t.m] then -- when month not already a number
t.m = month_num[t.m]; -- replace valid month name with a number
else
return nil; -- not a valid date form because month not valid
end
 
return mw.ustring.format ('%.4d-%.2d-%.2d', t.y, t.m, t.d), k; -- return date in iso format
return (y and (1900 < tonumber(y) and 2200 > tonumber(y))) and form; -- TODO: why 1900? shouldn't that be birth-of-intenet year? why 2200? shouldn't that be current year?
end
end
return nil, 'iso'; -- date could not be decoded; return nil and default iso date
end
 
 
--[[--------------------------< makeDate >-----------------------
 
Given ayear, zero-paddedmonth, 4-digitday yearnumbers, 2(zero-digitpadded monthor and 2-digit day,not) return a full date in df format
where df may be one of:
df = mdy, dmy, iso, ymd
mdy, dmy, iso, ymd
 
on entry, year, month, day are presumed to be correct for the date that they represent; all are required
 
in this module, makeDate() is sometimes given an iso-format date in year:
makeDate (2018-09-20, nil, nil, df)
this works because table.concat() sees only one table member
 
]]
 
local function makeDate (year, month, day, df)
local format = {
['dmy'] = 'j F Y',
வரி 158 ⟶ 266:
};
 
local date = table.concat ({year, month, day}, '-'); -- assemble year-initial numeric-format date (zero padding not required here)
if not year or '' == year or not month or '' == month or not day or '' == day and format[df] then
 
return nil;
if non_western_digits then --this wiki uses non-western digits?
date = mw.ustring.gsub (date, '%d', digits); -- convert this wiki's non-western digits to western digits
end
 
local date = table.concat ({year, month, day}, '-'); -- assemble iso format date
return mw.getContentLanguage():formatDate (format[df], date);
end
வரி 215 ⟶ 324:
 
Given a URI-path to Webcite (eg. /67xHmVFWP) return the encoded date in df format
 
returns date string in df format - webcite date is a unix timestamp encoded as bae62
or the string 'query'
 
]]
வரி 220 ⟶ 332:
local function decodeWebciteDate(path, df)
 
local dt = {};
local decode;
 
dt = mw.text.split(path, "/")
வரி 232 ⟶ 345:
-- http://www.webcitation.org/getfile.php?fileid=1c46e791d68e89e12d0c2532cc3cf629b8bc8c8e
 
if mw.ustring.find( dt[2],:find "('query"', 1, true) or
mw.ustring.find( dt[2],:find "('cache"', 1, true) or
mw.ustring.find( dt[2],:find "('getfile"', 1, true) or
tonumber(dt[2]) then
return "'query"';
end
 
dtdecode = os.date('*t', string.format("%d", base62(dt[2])):sub(1,10)); -- base62 string -> exponential number -> text -> first 10 characters -> a table of date parts
if not decode then
return nil; -- nil return when dt[2] contains characters not in %w
end
dt = os.date('*t', string.format("%d", decode):sub(1,10)) -- exponential number -> text -> first 10 characters (a unix timestamp) -> a table of date parts
 
decode = makeDate (dt.year, dt.month, dt.day, 'iso'); -- date comparisons are all done in iso format with western digits
if non_western_digits then --this wiki uses non-western digits?
decode = mw.ustring.gsub (decode, '%d', digits); -- convert this wiki's non-western digits to western digits
end
 
return decode;
if not is_valid_date (dt.year, dt.month, dt.day) then
return inlineRed(err_warn_msgs.date_err, 'error');
end
return makeDate(dt.year, dt.month, dt.day, df) or inlineRed (err_warn_msgs.date4, 'error');
end
 
வரி 256 ⟶ 373:
return the formatted date eg. "September 1, 2016" in df format
Handle non-digits in snapshot ID such as "re_" and "-" and "*"
 
returns two values:
first value is one of these:
valid date string in df format - wayback date is valid (including the text string 'index' when date is '/*/')
empty string - wayback date is malformed (less than 8 digits, not a valid date)
nil - wayback date is '/save/' or otherwise not a number
second return value is an appropriate 'message' may or may not be formatted
 
]]
வரி 266 ⟶ 391:
snapdate = snapdate:match ('^[^/]+'); -- get timestamp
if snapdate == "*" then -- eg. /web/*/http.. or /all/*/http..
return 'index'; -- return indicator that this url has an index date
return "index"
end
 
வரி 274 ⟶ 399:
if snapdate:match ('%*$') then -- a trailing '*' causes calendar display at archive .org
snapdate = snapdate:gsub ('%*$', ''); -- remove so not part of length calc later
-- msg = inlineRed (err_warn_msgs.ts_cal, 'warning'); -- TODO: enable this -- make a message
end
 
if not tonumber(snapdate) then
return nil, 'ts_nan'; -- return nil (fatal error flag) and message selector
return inlineRed (err_warn_msgs.date2, 'error');
end
 
local dlen = string.len(snapdate)
local dlen = snapdate:len();
if dlen < 8 then -- we need 8 digits TODO: but shouldn't this be testing for 14 digits?
return '', inlineRed (err_warn_msgs.date3ts_short, 'error'); -- return empty string and error message
end
 
வரி 288 ⟶ 414:
 
if not is_valid_date (year, month, day) then
return '', inlineRed (err_warn_msgs.date_errts_date, 'error'); -- return empty string and error message
end
 
snapdate = table.concat ({year, month, day}, '-'); -- date comparisons are all done in iso format
return makeDate(year, month, day, df) or inlineRed (err_warn_msgs.date7, 'error');
if 14 == dlen then
 
return snapdate, msg; -- return date with message if any
--[[ snapdate = makeDate(year, month, day, df); -- TODO: enable this
if snapdate then
if 14 == dlen then
return snapdate, msg; -- return date with message if any
else
return snapdate, msg .. inlineRed(err_warn_msgs.ts_len, 'warning'); -- return date with warning message(s)
end
else
return snapdate, msg .. inlineRed (err_warn_msgs.date7ts_len, 'errorwarning'); -- return errordate with warning message(s)
end
]]
end
 
வரி 312 ⟶ 431:
return the date in df format (e.g. if df = dmy, return 28 August 2016)
Handles "." and "-" in snapshot date, so 2016.08.28-144552 is same as 20160828144552
 
returns two values:
first value is one of these:
valid date string in df format - archive.is date is valid (including the text string 'short link' when url is the short form)
empty string - wayback date is malformed (not a number, less than 8 digits, not a valid date)
nil - wayback date is '/save/'
second return value is an appropriate 'message' may or may not be formatted
 
]]
வரி 326 ⟶ 453:
local dlen = string.len(snapdate)
if dlen < 8 then -- we need 8 digits TODO: but shouldn't this be testing for 14 digits?
return '', inlineRed (err_warn_msgs.date3ts_short, 'error'); -- return empty string and error message
end
 
வரி 332 ⟶ 459:
 
if not is_valid_date (year, month, day) then
return '', inlineRed (err_warn_msgs.date_errts_date, 'error'); -- return empty string and error message
end
 
snapdate = table.concat ({year, month, day}, '-'); -- date comparisons are all done in iso format
------ return makeDate(year, month, day, df) or inlineRed (err_warn_msgs.date7, 'error');
if 14 == dlen then
 
return snapdate; -- return date
snapdate = makeDate(year, month, day, df); -- TODO: enable this
if snapdate then
if 14 == dlen then
return snapdate; -- return date
else
return snapdate, inlineRed(err_warn_msgs.ts_len, 'warning'); -- return date with warning message
end
else
return snapdate, inlineRed (err_warn_msgs.date7ts_len, 'errorwarning'); -- return errordate with warning message
end
end
 
 
--[=[-------------------------< M A K E _ W I K I L I N K >----------------------------------------------------
 
Makes a wikilink; when both link and display text is provided, returns a wikilink in the form [[L|D]]; if only
link is provided, returns a wikilink in the form [[L]]; if neither are provided or link is omitted, returns an
empty string.
 
]=]
 
local function make_wikilink (link, display, no_link)
if nil == no_link then
if link and ('' ~= link) then
if display and ('' ~= display) then
return table.concat ({'[[', link, '|', display, ']]'});
else
return table.concat ({'[[', link, ']]'});
end
end
return display or ''; -- link not set so return the display text
 
else -- no_link
if display and ('' ~= display) then -- if there is display text
return display; -- return that
else
return link or ''; -- return the target article name or empty string
end
end
end
 
 
வரி 425 ⟶ 517:
ulx.url1.service = 'other';
tracking = categories.unknown;
ulx.url1.tail = table.concat ({'', prefixes.at, host, inlineRed (err_warn_msgs.unknown_url, error)}, ' '); -- TODO: call to inlineRed() does not specify 'error' or 'warning'; should it?
end
வரி 450 ⟶ 542:
 
j = 2
for i = 2, config.maxurls do
argurl = "url" .. i
if args[argurl] then
வரி 489 ⟶ 581:
local function comma(date)
return (date and date:match ('%a+ +%d%d?(,) +%d%d%d%d')) or '';
end
 
 
--[[--------------------------< createTracking >-----------------------
 
Return data in track[] ie. tracking categories
 
]]
 
local function createTracking()
if not excepted_pages[this_page.fullText] then -- namespace:title/fragment is allowed to be categorized (typically this module's / template's testcases page(s))
if uncategorized_namespaces[this_page.nsText] then -- TODO: enable this chunk
return ''; -- this page not to be categorized so return empty string
end
for _,v in ipairs (uncategorized_subpages) do -- cycle through page name patterns
if this_page.text:match (v) then -- test page name against each pattern
return ''; -- this subpage type not to be categorized so return empty string
end
end
end
 
local out = {};
if tableLength(track) > 0 then
for key, _ in pairs(track) do -- loop through table
table.insert (out, make_wikilink (key)); -- and convert category names to links
end
end
return table.concat (out); -- concat into one big string; empty string if table is empty
 
end
 
வரி 524 ⟶ 587:
 
Return a rendering of the data in ulx[][]
 
TODO: when archive date is '*' ('index') leading archive extlink should be [<url> Archive index] instead of
[<url> Archived] index; code to support this has been added but is commented out for the time being; look for TODO1
 
]]
வரி 537 ⟶ 597:
local period1 = ''; -- For backwards compat with {{wayback}}
local period2 = '.';
 
local index_date, msg = ulx.url1.date:match ('(index)(.*)'); -- when ulx.url1.date extract 'index' text and message text (if there is a message)
ulx.url1.date = ulx.url1.date:gsub ('index.*', 'index'); -- remove message
 
if 'none' == ulx.url1.format then -- For {{wayback}}, {{webcite}}
வரி 548 ⟶ 611:
table.insert (out, ulx.url1.tail); -- tail text
if ulx.url1.date then
table.insert (out, '&#32;('); -- open date text; TODO: why the html entity? replace with regular space?
table.insert (out, 'index' == ulx.url1.date and 's_text.archive' or 's_text.archived'); -- add text
table.insert (out, ' '); -- insert a space
table.insert (out, ulx.url1.date); -- add date
வரி 555 ⟶ 618:
end
else -- no title
table.insertif (out,index_date ' Archived]')then -- closewhen extlinkurl markupdate TODO1:is remove this'index' line
--TODO1 table.insert (out, 'index' == ulxtable.url1.date andconcat ({' Archive index]', ors_text.Archive_index, ' Archived]'})); -- beginadd linkthe label-- use this line for correctindex link label when date is 'index'
table.insert (out, msg or ''); -- add date mismatch message when url date is /*/ and |date= has valid date
else
table.insert (out, table.concat ({' ', s_text.Archived, '] '})); -- add link label for url has timestamp date (will include mismatch message if there is one)
end
if ulx.url1.date then
if 'wayback' == ulx.url1.service then
வரி 562 ⟶ 629:
period2 = '';
end
table.insert (out, table.concatif ({' index', ~= ulx.url1.date})); -- add date TODO1: remove this linethen
--[[TODO1 if table.insert 'index' ~=(out, ulx.url1.date then); -- TODO1: add this line -- use this if for correct link labeldate when datedata is not 'index'
end
table.insert (out, ulx.url1.date); -- add date TODO1: add this line -- use this if for correct link label when date is 'index'
table.insert (out, comma(ulx.url1.date)); -- add ',' if date format is mdy
end -- TODO1: add this line -- use this if for correct link label when date is 'index'
]] table.insert (out, comma(ulx.url1.date)); -- add ',' if date format is mdy
table.insert (out, ulx.url1.tail); -- add tail text
table.insert (out, period1); -- terminate
வரி 577 ⟶ 643:
local tot = ulx.url1.extraurls + 1
table.insert (out, period2); -- terminate first url
table.insert (out, table.concat ({' Additional', archivess_text.addlarchives, ': '})); -- add header text
 
for i=2, tot do -- loop through the additionals
வரி 594 ⟶ 660:
else -- For {{cite archives}}
if 'addlarchives' == ulx.url1.format then -- Multiple archive services
table.insert (out, 'Additionaltable.concat archives({s_text.addlarchives, ': '})); -- add header text
else -- Multiple pages from the same archive
table.insert (out, 'Additionaltable.concat pages({s_text.addlpages, archived&nbsp;on' '})); -- add header text
table.insert (out, ulx.url1.date); -- add date to header text
table.insert (out, ': '); -- close header text
வரி 615 ⟶ 681:
else -- must be addlpages
if not displayfield then
displayfield = table.concat ({'s_text.Page, ' ', i});
end
end
வரி 627 ⟶ 693:
 
 
--[[--------------------------< WP EA BR A M E T E R C_ HN IA M E _ X L A VT E >----------------------------------------------------------
 
for internaltionalization, translate local-language parameter names to their English equivalents
template entry point
 
TODO: return error message if multiple aliases of the same canonical parameter name are found?
 
returns two tables:
new_args - holds canonical form parameters and their values either from translation or because the parameter was already in canonical form
origin - maps canonical-form parameter names to their untranslated (local language) form for error messaging in the local language
 
unrecognized parameters are ignored
TODO: deprecate empty |nolink= as a 'positive' assertion that archive service is not to be linked
 
]]
 
local function webarchiveparameter_name_xlate (frameargs, params, enum_params)
local args = getArgs (frame, {name; -- TODO:holds modifiable name of the parameter deletename thisduring assignmentevaluation
local enum; -- for enumerated parameters, holds the enumerator during evaluation
valueFunc = function (key, value) -- this code so that we can detect and handle the oddity that is |nolink=
local found = false; -- flag used to break out of nested for loops
if 'nolink' == key then -- |nolink= is 'set' when present with or without assigned value; TODO: deprecate this peculiar use
local new_args = {}; -- a table that holds canonical and translated parameter k/v pairs
return value; -- don't trim; we don't care (right now) what the value is except when nil and we can't trim nil
local origin = {}; -- a table that maps original (local language) parameter names to their canonical name for local language error messaging
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
local convert_digits = 0 ~= tableLength (digits); -- will we be converting this wiki's digits to western digits? digits table will be filled if we are
if '' ~= value then -- empty string when value was only whitespace or was empty
return value; -- return non-nil, non-empty values
for k, v in pairs (args) do -- loop through all of the arguments in the args table
name = k; -- copy of original parameter name
if convert_digits then
name = mw.ustring.gsub (name, '%d', digits); -- convert this wiki's non-western digits to western digits
end
enum = name:match ('%d+$'); -- get parameter enumerator if it exists; nil else
if not enum then -- no enumerator so looking for non-enumnerated parameters
-- TODO: insert shortcut here? if params[name] then name holds the canonical parameter name; no need to search further
for pname, aliases in pairs (params) do -- loop through each parameter the params table
for _, alias in ipairs (aliases) do -- loop through each alias in the parameter's aliases table
if name == alias then
new_args[pname] = v; -- create a new entry in the new_args table
origin [pname] = k; -- create an entry to make canonical parameter name to original local language parameter name
found = true; -- flag so that we can break out of these nested for loops
break; -- no need to search the rest of the aliases table for name so go on to the next k, v pair
end
end
 
if found then -- true when we found an alias that matched name
found = false; -- reset the flag
break; -- go do next args k/v pair
end
end
else return nil; -- value was nil, empty, or contained onlyenumerated whitespaceparameters
name = name:gsub ('%d$', '#'); -- replace enumeration digits with place holder for table search
end -- end of valueFunc
-- TODO: insert shortcut here? if num_params[name] then name holds the canonical parameter name; no need to search further
});
for pname, aliases in pairs (enum_params) do -- loop through each parameter the num_params table
for _, alias in ipairs (aliases) do -- loop through each alias in the parameter's aliases table
if name == alias then
pname = pname:gsub ('#$', enum); -- replace the '#' place holder with the actual enumerator
new_args[pname] = v; -- create a new entry in the new_args table
origin [pname] = k; -- create an entry to make canonical parameter name to original local language parameter name
found = true; -- flag so that we can break out of these nested for loops
break; -- no need to search the rest of the aliases table for name so go on to the next k, v pair
end
end
 
if found then -- true when we found an alias that matched name
found = false; -- reset the flag
break; -- go do next args k/v pair
end
end
end
end -- for k, v
return new_args, origin;
end
 
 
--[[--------------------------< W E B A R C H I V E >----------------------------------------------------------
 
template entry point
 
]]
 
local function webarchive(frame)
local args = getArgs (frame);
 
-- local args = getArgs (frame); -- TODO: replace the above with this
local data = mw.loadData (table.concat ({ -- make a data module name; sandbox or live
'Module:Webarchive/data',
வரி 657 ⟶ 780:
}));
categories = data.categories; -- fill in the forward declarations
config = data.config;
if data.digits.enable then
digits = data.digits; -- for i18n; table of digits in the local wiki's language
non_western_digits = true; -- use_non_western_digits
end
err_warn_msgs = data.err_warn_msgs;
excepted_pages = data.excepted_pages;
month_num = data.month_num; -- for i18n; table of month names in the local wiki's language
prefixes = data.prefixes;
services = data.services;
s_text = data.s_text;
uncategorized_namespaces = data.uncategorized_namespaces;
uncategorized_subpages = data.uncategorized_subpages;
 
local origin = {}; -- holds a map of English to local language parameter names used in the current template; not currently used
local date, format, msg, uri, url;
args, origin = parameter_name_xlate (args, data.params, data.enum_params); -- translate parameter names in args to English
 
local date, format, msg, udate, uri, url;
local ldf = 'iso'; -- when there is no |date= parameter, render url dates in iso format
verifydates = 'yes' == verifydates; -- convert to boolean
 
if args.url and args.url1 then -- URL argument (first)
return inlineError ("url"data.crit_err_msgs.conflicting, "Conflicting |{origin.url=, and |origin.url1=.") .. createTracking(});
 
end
வரி 676 ⟶ 808:
if not url then
return inlineError ("url", "Emptydata.") crit_err_msgs.. createTracking(empty);
end
-- these iabot bugs perportedly fixed; removing these causes lua script error
--[[ -- at Template:Webarchive/testcases/Production; resolve that before deleting these tests
if mw.ustring.find( url, "https://web.http", 1, true ) then -- track bug - TODO: IAbot bug; not known if the bug has been fixed; deferred
track[categories.error] = 1;
return inlineError ("url", "https://webdata.http") crit_err_msgs.. createTracking(iabot1);
end
if url == "https://web.archive.org/http:/" then -- track bug - TODO: IAbot bug; not known if the bug has been fixed; deferred
track[categories.error] = 1;
return inlineError ("url", "Invalid URL") data.crit_err_msgs. createTracking(iabot2);
end
]]
 
if not (url:lower():find ('^http') or url:find ('^//')) then
return inlineError (data.crit_err_msgs.invalid_url );
end
 
ulx.url1 = {}
ulx.url1.url = url
if not (url:lower():find ('^http') or url:find ('^//')) then -- TODO: is this a good idea? isn't it better to simply throw an error when url is malformed ...
ulx.url1.url = 'http://' .. url -- ... rather than apply this 'fix' that might not fix anything?
end
 
ulx.url1.extraurls = parseExtraArgs(args)
 
local good = false;
uri = mw.uri.new (ulx.url1.url); -- get a table of uri parts from this url
good, uri = pcall (mw.uri.new, ulx.url1.url); -- get a table of uri parts from this url; protected mode to prevent lua error when ulx.url1.url is malformed
if not good then -- abandon when ulx.url1.url is malformed
return inlineError (data.crit_err_msgs.invalid_url);
end
serviceName(uri.host, args.nolink)
 
if args.date and args.date1 then -- Date argument
return inlineError ("date"data.crit_err_msgs.conflicting, "Conflicting |{origin.date=, and |origin.date1=.") .. createTracking(});
end
date = args.date or args.date1;
date = date and date:gsub (' +', ' '); -- replace multiple spaces with a single space
 
if date and config.verifydates then
if 'wayback' == ulx.url1.service or 'locwebarchives' == ulx.url1.service then
if '*' == date then -- TODO: why is this not compared to url date?
date = 'index';
ldf = 'iso'; -- set to default format
else
date, ldf = decode_date (date); -- get an iso format date from date and get date's original format
end
end
 
if 'wayback' == ulx.url1.service or 'locwebarchives' == ulx.url1.service then
if date then
if config.verifydates then
local ldf = dateFormat(date)
if ldf then
local udate, msg = decodeWaybackDate( (uri.path, ldf ); -- get the url date in theiso sameformat and format asof date in |date=; 'index' when wayback url date is *
if not udate ~=then -- datethis thenis the only 'fatal' error return
return inlineError (data.crit_err_msgs[msg]);
date = udate .. inlineRed (err_warn_msgs.mismatch, 'warning') .. (msg or ''); -- mismatch us url date; add message if there is one
elseend
 
date = date .. (msg or ''); -- add message if there is one
if udate ~= date then -- date comparison using iso format dates
date = udate;
msg = table.concat ({
inlineRed (err_warn_msgs.mismatch, 'warning'), -- add warning message
msg, -- add message if there is one
});
end
end
end
else -- no |date=
dateudate, msg = decodeWaybackDate ( uri.path, "iso" );
 
if not date then
if not udate then -- this is the only 'fatal' error return
date = inlineRed (err_warn_msgs.date1, 'error'); -- TODO: change this type of message so that it identifies url as source of error?
return inlineError (data.crit_err_msgs[msg]);
end
 
if '' == udate then
date = nil; -- unset
else
date = udate;
date = date .. (msg or ''); -- add message if there is one
end
end
வரி 731 ⟶ 890:
elseif 'webcite' == ulx.url1.service then
if date then
if config.verifydates then
local ldf = dateFormat(date)
if ldf then
local udate = decodeWebciteDate( (uri.path, ldf ); -- get the url date in the sameiso format as date in |date=
if 'query' ~= udate then -- skip if query
if udate ~= date then -- date comparison using iso format dates
date = udate .. inlineRed (err_warn_msgs.mismatch, 'warning');
msg = table.concat ({
inlineRed (err_warn_msgs.mismatch, 'warning'),
});
end
end
வரி 745 ⟶ 906:
date = decodeWebciteDate( uri.path, "iso" )
if date == "query" then
date = nil; -- unset
date = inlineRed (err_warn_msgs.date_miss, 'warning');
msg = inlineRed (err_warn_msgs.date_miss, 'warning');
elseif not date then
elseif not date then -- invalid base62 string
date = inlineRed (err_warn_msgs.date1, 'error');
end
வரி 753 ⟶ 915:
elseif 'archiveis' == ulx.url1.service then
if date then
if config.verifydates then
local ldf = dateFormat(date)
if ldf then
local udate, msg = decodeArchiveisDate ( uri.path, ldf ) -- get the url date in the sameiso format as date in |date=
if 'short link' ~= udate then -- skip if short link
if udate ~= date then -- date comparison using iso format dates
date = udate;
date = udate .. inlineRed (err_warn_msgs.mismatch, 'warning') .. (msg or ''); -- mismatch: use url date; add message if there is one
else msg = table.concat ({
date = date inlineRed (err_warn_msgs.. (msg ormismatch, 'warning'); , -- add warning message if there is one
msg, -- add message if there is one
});
end
end
வரி 767 ⟶ 930:
end
else -- no |date=
dateudate, msg = decodeArchiveisDate( uri.path, "iso" )
if dateudate == "short link" then
date = nil; -- unset
date = inlineRed (err_warn_msgs.date_miss, 'warning');
msg = inlineRed (err_warn_msgs.date_miss, 'warning');
elseif not date then
elseif '' == udate then
date = inlineRed (err_warn_msgs.date1, 'error');
date = nil; -- unset
else
date = udate;
date = date .. (msg or ''); -- add message if there is one
end
end
வரி 779 ⟶ 943:
else -- some other service
if not date then
datemsg = inlineRed (err_warn_msgs.date_miss, 'warning');
end
end
 
ulx.url1.dateif 'index' == date then
ulx.url1.date = date .. (msg or ''); -- create index + message (if there is one)
elseif date then
ulx.url1.date = makeDate (date, nil, nil, ldf) .. (msg or ''); -- create a date in the wiki's local language + message (if there is one)
else
ulx.url1.date = msg;
end
 
format = args.format; -- Format argument
வரி 790 ⟶ 960:
format = "none"
else
for k, v in pairs (data.format_vals) do -- |format= accepts two specific values loop through a table of those values
local found; -- declare a nil flag
for _, p in ipairs (v) do -- loop through local language variants
if format == p then -- when |format= value matches
format = k; -- use name from table key
found = true; -- declare found so that we can break out of outer for loop
break; -- break out of inner for loop
end
end
if found then
break;
end
end
 
if format == "addlpages" then
if not ulx.url1.date then
வரி 803 ⟶ 988:
 
if args.title and args.title1 then -- Title argument
return inlineError ("title"data.crit_err_msgs.conflicting, "Conflicting |{origin.title=, and |origin.title1=.") .. createTracking(});
end
 
வரி 810 ⟶ 995:
local rend = createRendering()
if not rend then
return inlineError (data.crit_err_msgs.unknown);
rend = '<span style="font-size:100%" class="error citation-comment">Error in [[:Template:' .. tname .. ']]: Unknown problem. Please report on template talk page.</span>'
track[categories.error] = 1;
end
 
"https://tamilar.wiki/w/Module:Webarchive" இலிருந்து மீள்விக்கப்பட்டது