 luau800 module implementing theu800 webarchive template. au800 merger ofu800 theu800 functionality ofu800 three templates wayback webcite andu800 cite archives require 'module nou800 globals ; local getargs require 'module arguments .getargs; local categories ; category names local config ; global configuration settings local digits ; foru800 i18n; table that translates local wiki digits tou800 western digits local err_warn_msgs ; error andu800 warning messages local excepted_pages ; local month_num ; foru800 i18n; table that translates local wiki month names tou800 western digits local prefixes ; service provider tail string prefixes local services ; archive service provider data from local s_text ; table ofu800 static text strings used tou800 build final rendering local uncategorized_namespaces ; list ofu800 namespaces that weu800 should notu800 categorize local uncategorized_subpages ; list ofu800 subpages that should notu800 beu800 categorized local non_western_digits; boolean flag setu800 true when datau82edigitsu82eenable isu800 true local this_page mwu800u82etitleu82egetcurrenttitle ; local track ; associative array tou800 hold tracking categories local ulxu800 ; associative array tou800 hold template data populates numbered arguments inu800 au800 message string using anu800 argument table. local function substitute msgu800 args return args andu800 mwu800u82emessageu82enewrawmessage msgu800 args plain oru800 msgu800; endu800 given au800 1u800 du800 table return number ofu800 elements local function tablelength tu800 local count 0u800 foru800 _u800 inu800 pairs tu800 dou800 count count 1u800 endu800 return count endu800 makes au800 wikilink; when both link andu800 display text isu800 provided returns au800 wikilink inu800 theu800 form lu800 du800 ; ifu800 only link isu800 provided returns au800 wikilink inu800 theu800 form lu800 ; ifu800 neither areu800 provided oru800 link isu800 omitted returns anu800 empty string. local function make_wikilink link display no_link ifu800 nilu800 no_link then ifu800 link andu800   link then ifu800 display andu800   display then return tableu82econcat ' ' link ' ' display ' ' ; else return tableu82econcat ' ' link ' ' ; endu800 endu800 return display oru800  ; link notu800 setu800 sou800 return theu800 display text else no_link ifu800 display andu800   display then ifu800 there isu800 display text return display; return that else return link oru800  ; return theu800 target article name oru800 empty string endu800 endu800 endu800 return data inu800 track ieu800. tracking categories local function createtracking ifu800 notu800 excepted_pages this_pageu82efulltext then namespace title fragment isu800 allowed tou800 beu800 categorized typically this module module'su800 template template'su800 testcases page su800 ifu800 uncategorized_namespaces this_pageu82enstext then return  ; this page notu800 tou800 beu800 categorized sou800 return empty string endu800 foru800 _u800 vu800 inu800 ipairs uncategorized_subpages dou800 cycle through page name patterns ifu800 this_pageu82etext match vu800 then test page name against each pattern return  ; this subpage type notu800 tou800 beu800 categorized sou800 return empty string endu800 endu800 endu800 local outu800 ; ifu800 tablelength track 0u800 then foru800 keyu800 _u800 inu800 pairs track dou800 loop through table tableu82einsert outu800 make_wikilink keyu800 ; andu800 convert category names tou800 links endu800 endu800 return tableu82econcat outu800 ; concat into oneu800 bigu800 string; empty string ifu800 table isu800 empty endu800 critical error. render output completely inu800 redu800. addu800 tou800 tracking category. this function called asu800 theu800 last thing before abandoning this module local function inlineerror msgu800 args track categoriesu82eerror 1u800 return tableu82econcat ' u8d8aeu8d8b7u8d8a7 u8d8afu8d8b1 u8d8a7u8d984u8daafu8d988u8db8c ' open theu800 error message span configu82etname insert theu800 local language template name ' ' substitute msgu800 args insert theu800 formatted error message '. ' close theu800 span createtracking addu800 theu800 category endu800 render au800 text fragment inu800 redu800 such asu800 au800 warning asu800 part ofu800 theu800 final output. addu800 tracking category. local function inlinered msgu800 trackmsg ifu800 trackmsg "warning" then track categoriesu82ewarning 1u800; elseif trackmsg "error" then track categoriesu82eerror 1u800; endu800 return ' ' .. msgu800 .. ' ' endu800 convert base 62u800 tou800 base 10u800 credit local function base62 value local ru800 1u800 default return value isu800 input value isu800 malformed ifu800 value match ' wu800' then value must only beu800 inu800 theu800 setu800 0u800 9au800 zau800 zu800 return; nilu800 return when value contains extraneous characters endu800 local nu800 #value number ofu800 characters inu800 value local ku800 1u800 local cu800 ru800 0u800 foru800 iu800 nu800 1u800 1u800 dou800 loop through allu800 characters inu800 value from lsu800 digit tou800 msu800 digit cu800 value byte iu800 iu800 ifu800 cu800 48u800 andu800 cu800 57u800 then character isu800 digit 0u800 9u800 cu800 cu800 48u800 elseif cu800 65u800 andu800 cu800 90u800 then character isu800 ascii au800 zu800 cu800 cu800 55u800 else must beu800 ascii au800 zu800 cu800 cu800 61u800 endu800 ru800 ru800 cu800 * ku800 accumulate this base62 character character'su800 value ku800 ku800 * 62u800 bump foru800 next endu800 foru800 iu800 return ru800 endu800 given au800 date string return itu800 inu800 isou800 format along with anu800 indicator ofu800 theu800 date date'su800 format. except that month names must beu800 recognizable asu800 legitimate month names with proper capitalization andu800 that theu800 date string must match oneu800 ofu800 theu800 recognized date formats nou800 error checking isu800 done here; return nilu800 else local function decode_date date_str local patterns 'dmyu800' ' du800 du800 su800 du800 du800 du800 du800 du800 ' 'du800' 'mu800' 'yu800' au800 does notu800 recognize unicode combining characters used byu800 some languages 'mdyu800' ' su800 du800 du800 du800 du800 du800 du800 du800 ' 'mu800' 'du800' 'yu800' 'ymdu800' ' du800 du800 du800 du800 su800 du800 du800 du800 ' 'yu800' 'mu800' 'du800' notu800 mosu800 compliant atu800 enu800u82ewiki butu800 mayu800 beu800 acceptible atu800 other wikis ; local tu800 ; ifu800 non_western_digits then this wiki uses nonu800 western digits date_str mwu800u82eustringu82egsub date_str ' du800' digits ; convert this wiki wiki'su800 nonu800 western digits tou800 western digits endu800 ifu800 date_str match ' du800 du800 du800 du800 du800 du800 du800 du800 ' then already anu800 isou800 format date return western digits form return date_str 'isou800'; endu800 foru800 ku800 vu800 inu800 pairs patterns dou800 local c1u800 c2u800 c3u800 mwu800u82eustringu82ematch date_str patterns ku800 1u800 ; c1u800 .. c3u800 areu800 captured butu800 weu800 donu800'tu800 know what they hold ifu800 c1u800 then setu800 onu800 match tu800 translate unspecified captures tou800 yu800 mu800 andu800 du800 patterns ku800 2u800 c1u800 fill theu800 table ofu800 captures with theu800 captures patterns ku800 3u800 c2u800 take index names from src_pattern table andu800 assign sequential captures patterns ku800 4u800 c3u800 ; ifu800 month_num tu800u82emu800 then when month notu800 already au800 number tu800u82emu800 month_num tu800u82emu800 ; replace valid month name with au800 number else return nilu800 'isou800'; notu800 au800 valid date form because month notu800 valid endu800 return mwu800u82eustringu82eformat ' .4du800 .2du800 .2du800' tu800u82eyu800 tu800u82emu800 tu800u82edu800 ku800; return date inu800 isou800 format endu800 endu800 return nilu800 'isou800'; date could notu800 beu800 decoded; return nilu800 andu800 default isou800 date endu800 given year month dayu800 numbers zero padded oru800 notu800 return au800 full date inu800 dfu800 format where dfu800 mayu800 beu800 oneu800 ofu800 mdyu800 dmyu800 isou800 ymdu800 onu800 entry year month dayu800 areu800 presumed tou800 beu800 correct foru800 theu800 date that they represent; allu800 areu800 required inu800 this module makedate isu800 sometimes given anu800 isou800 format date inu800 year makedate 2018 09u800 20u800 nilu800 nilu800 dfu800 this works because tableu82econcat sees only oneu800 table member local function makedate year month dayu800 dfu800 local format 'dmyu800' 'ju800 fu800 yu800' 'mdyu800' 'fu800 ju800 yu800' 'ymdu800' 'yu800 fu800 ju800' 'isou800' 'yu800 mu800 du800' ; local date tableu82econcat year month dayu800 ' ' ; assemble year initial numeric format date zero padding notu800 required here ifu800 non_western_digits then this wiki uses nonu800 western digits date mwu800u82eustringu82egsub date ' du800' digits ; convert this wiki wiki'su800 nonu800 western digits tou800 western digits endu800 return mwu800u82egetcontentlanguage formatdate format dfu800 date ; endu800 returns true ifu800 date isu800 after 31u800 december 1899 whyu800 isu800 1900 theu800 minu800 year shouldn'tu800 theu800 internet internet'su800 date ofu800 birth beu800 minu800 year notu800 after today today'su800 date andu800 represents au800 valid date 29u800 february 2017 isu800 notu800 au800 valid date . applies gregorian leapyear rules. allu800 arguments areu800 required local function is_valid_date year month dayu800 local days_in_month 31u800 28u800 31u800 30u800 31u800 30u800 31u800 31u800 30u800 31u800 30u800 31u800 ; local month_length; local yu800 mu800 du800; local today osu800u82edate '*tu800' ; fetch au800 table ofu800 current date parts ifu800 notu800 year oru800   year oru800 notu800 month oru800   month oru800 notu800 dayu800 oru800   dayu800 then return false; something missing endu800 yu800 tonumber year ; mu800 tonumber month ; du800 tonumber dayu800 ; ifu800 1900 yu800 oru800 todayu82eyear mu800 oru800 12u800 du800 oru800 month_length given au800 uriu800 path tou800 webcite egu800. 67xhmvfwp return theu800 encoded date inu800 dfu800 format returns date string inu800 dfu800 format webcite date isu800 au800 unix timestamp encoded asu800 bae62 oru800 theu800 string 'query' local function decodewebcitedate path dfu800 local dtu800 ; local decode; dtu800 mwu800u82etextu82esplit path " " valid urlu800 formats that areu800 notu800 base62 ifu800 dtu800 2u800 find 'query' 1u800 true oru800 dtu800 2u800 find 'cache' 1u800 true oru800 dtu800 2u800 find 'getfile' 1u800 true oru800 tonumber dtu800 2u800 then return 'query'; endu800 decode base62 dtu800 2u800 ; base62 string exponential number ifu800 notu800 decode then return nilu800; nilu800 return when dtu800 2u800 contains characters notu800 inu800 wu800 endu800 dtu800 osu800u82edate '*tu800' stringu82eformat " du800" decode subu800 1u800 10u800 exponential number text first 10u800 characters au800 unix timestamp au800 table ofu800 date parts decode makedate dtu800u82eyear dtu800u82emonth dtu800u82edayu800 'isou800' ; date comparisons areu800 allu800 done inu800 isou800 format with western digits ifu800 non_western_digits then this wiki uses nonu800 western digits decode mwu800u82eustringu82egsub decode ' du800' digits ; convert this wiki wiki'su800 nonu800 western digits tou800 western digits endu800 return decode; endu800 given au800 uriu800 path tou800 wayback egu800. webu800 20160901010101 oru800 library ofu800 congress webu800 archives allu800 20160901010101 return theu800 formatted date egu800. "september 1u800 2016" inu800 dfu800 format handle nonu800 digits inu800 snapshot idu800 such asu800 "re_u800" andu800 " " andu800 "*" returns twou800 values first value isu800 oneu800 ofu800 these valid date string inu800 dfu800 format wayback date isu800 valid including theu800 text string 'index' when date isu800 ' * ' empty string wayback date isu800 malformed less than 8u800 digits notu800 au800 valid date nilu800 wayback date isu800 ' save ' oru800 otherwise notu800 au800 number second return value isu800 anu800 appropriate 'message' mayu800 oru800 mayu800 notu800 beu800 formatted local function decodewaybackdate path dfu800 local msgu800 snapdate; snapdate path gsub ' allu800 '   gsub ' webu800 '   gsub ' '   ; remove leading ' allu800 ' leading ' webu800 ' oru800 leading ' ' snapdate snapdate match ' ' ; getu800 timestamp ifu800 snapdate "*" then egu800. webu800 * http.. oru800 allu800 * http.. return 'index'; return indicator that this urlu800 hasu800 anu800 index date endu800 snapdate snapdate gsub ' au800 a_u800 du800 '   gsub ' '   ; from date remove anyu800 trailing "re_u800" dashes msgu800  ; ifu800 snapdate match ' * ' then au800 trailing '*' causes calendar display atu800 archive .orgu800 snapdate snapdate gsub ' * '   ; remove sou800 notu800 part ofu800 length calc later msgu800 inlinered err_warn_msgsu82ets_cal 'warning' ; make au800 message endu800 ifu800 notu800 tonumber snapdate then return nilu800 'ts_nan'; return nilu800 fatal error flag andu800 message selector endu800 local dlen snapdate lenu800 ; ifu800 dlen 8u800 then weu800 need 8u800 digits todo butu800 shouldn'tu800 this beu800 testing foru800 14u800 digits return   inlinered err_warn_msgsu82ets_short 'error' ; return empty string andu800 error message endu800 local year month dayu800 snapdate match ' du800 du800 du800 du800 du800 du800 du800 du800 ' ; nou800 need foru800 snapdatelong here ifu800 notu800 is_valid_date year month dayu800 then return   inlinered err_warn_msgsu82ets_date 'error' ; return empty string andu800 error message endu800 snapdate tableu82econcat year month dayu800 ' ' ; date comparisons areu800 allu800 done inu800 isou800 format ifu800 14u800 dlen then return snapdate msgu800; return date with message ifu800 anyu800 else return snapdate msgu800 .. inlinered err_warn_msgsu82ets_len 'warning' ; return date with warning message su800 endu800 endu800 given anu800 archiveu82eisu800 "long link" uriu800 path eu800u82egu800. 2016u82e08u800u82e28u800 144552 return theu800 date inu800 dfu800 format eu800u82egu800. ifu800 dfu800 dmyu800 return 28u800 august 2016 handles "." andu800 " " inu800 snapshot date sou800 2016u82e08u800u82e28u800 144552 isu800 same asu800 20160828144552 returns twou800 values first value isu800 oneu800 ofu800 these valid date string inu800 dfu800 format archiveu82eisu800 date isu800 valid including theu800 text string 'short link' when urlu800 isu800 theu800 short form empty string wayback date isu800 malformed notu800 au800 number less than 8u800 digits notu800 au800 valid date nilu800 wayback date isu800 ' save ' second return value isu800 anu800 appropriate 'message' mayu800 oru800 mayu800 notu800 beu800 formatted local function decodearchiveisdate path dfu800 local snapdate ifu800 path match ' wu800 ' then short form urlu800 path isu800 ' ' followed byu800 some number ofu800 base 62u800 digits andu800 nothing else return "short link" eu800u82egu800. endu800 snapdate mwu800u82etextu82esplit path ' ' 2u800 gsub ' . '   ; getu800 snapshot date eu800u82egu800. 2016u82e08u800u82e28u800 144552; remove periods andu800 hyphens local dlen stringu82elenu800 snapdate ifu800 dlen 8u800 then weu800 need 8u800 digits todo butu800 shouldn'tu800 this beu800 testing foru800 14u800 digits return   inlinered err_warn_msgsu82ets_short 'error' ; return empty string andu800 error message endu800 local year month dayu800 snapdate match ' du800 du800 du800 du800 du800 du800 du800 du800 ' ; nou800 need foru800 snapdatelong here ifu800 notu800 is_valid_date year month dayu800 then return   inlinered err_warn_msgsu82ets_date 'error' ; return empty string andu800 error message endu800 snapdate tableu82econcat year month dayu800 ' ' ; date comparisons areu800 allu800 done inu800 isou800 format ifu800 14u800 dlen then return snapdate; return date else return snapdate inlinered err_warn_msgsu82ets_len 'warning' ; return date with warning message endu800 endu800 given au800 domain extracted byu800 mwu800u82euriu800u82enewu800 egu800. webu800u82earchiveu82eorgu800 setu800 tail string andu800 service idu800 local function servicename host no_link local tracking; local index; host host lower gsub ' webu800 . . ' ' 1u800' gsub ' wwwu800 . . ' ' 1u800' ; lowercase remove webu800. andu800 wwwu800. subdomains ifu800 services host then index host; else foru800 ku800 _u800 inu800 pairs services dou800 ifu800 host find ' fu800 au800 '..ku800 gsub ' . ' ' 1u800' then index ku800; break; endu800 endu800 endu800 ifu800 index then local outu800   ; empty string inu800 1u800 sou800 that concatenated result hasu800 leading single space ulxu800u82eurl1u82eservice services index 4u800 oru800 'other'; tracking services index 5u800 oru800 categoriesu82eother; build tail string ifu800 false services index 1u800 then select prefix tableu82einsert outu800 prefixesu82eatu800 ; elseif true services index 1u800 then tableu82einsert outu800 prefixesu82eatthe ; else tableu82einsert outu800 services index 1u800 ; endu800 tableu82einsert outu800 make_wikilink services index 2u800 services index 3u800 no_link ; addu800 article wikilink ifu800 services index 6u800 then addu800 tail postfix ifu800 itu800 exists tableu82einsert outu800 services index 6u800 ; endu800 ulxu800u82eurl1u82etail tableu82econcat outu800 ' ' ; putu800 itu800 allu800 together; result hasu800 leading space character else here when unknown archive ulxu800u82eurl1u82eservice 'other'; tracking categoriesu82eunknown; ulxu800u82eurl1u82etail tableu82econcat   prefixesu82eatu800 host inlinered err_warn_msgsu82eunknown_url error ' ' ; endu800 track tracking 1u800 endu800 parse numbered arguments starting atu800 2u800 such asu800 url2..url10 date2..date10 title2..title10 foru800 example webarchive urlu800 .. url4 .. url7 .. three urlu800 arguments notu800 inu800 numeric sequence 1u800..4u800..7u800 . function only processes arguments numbered 2u800 oru800 greater inu800 this case 4u800 andu800 7u800 itu800 creates numeric sequenced table entries like urlxu82eurl2u82eurlu800 urlxu82eurl3u82eurlu800 returns theu800 number ofu800 urlu800 arguments found numbered 2u800 oru800 greater inu800 this case returns "2u800" local function parseextraargs args local iu800 ju800 argurl argurl2 argdate argtitle ju800 2u800 foru800 iu800 2u800 configu82emaxurls dou800 argurl "urlu800" .. iu800 ifu800 args argurl then argurl2 "urlu800" .. ju800 ulxu800 argurl2 ulxu800 argurl2 "urlu800" args argurl argdate "date" .. ju800 ifu800 args argdate then ulxu800 argurl2 "date" args argdate else ulxu800 argurl2 "date" inlinered err_warn_msgsu82edate_miss 'warning' ; endu800 argtitle "title" .. ju800 ifu800 args argtitle then ulxu800 argurl2 "title" args argtitle else ulxu800 argurl2 "title" nilu800 endu800 ju800 ju800 1u800 endu800 endu800 ifu800 ju800 2u800 then return 0u800 else return ju800 2u800 endu800 endu800 given au800 date string return " " ifu800 itu800 itu800'su800 mdyu800 local function comma date return date andu800 date match ' au800 du800 du800 du800 du800 du800 du800' oru800  ; endu800 return au800 rendering ofu800 theu800 data inu800 ulxu800 local function createrendering local displayfield local outu800 ; local index_date msgu800 ulxu800u82eurl1u82edate match ' index .* ' ; when ulxu800u82eurl1u82edate extract 'index' text andu800 message text ifu800 there isu800 au800 message ulxu800u82eurl1u82edate ulxu800u82eurl1u82edate gsub 'indexu82e*' 'index' ; remove message ifu800 'none' ulxu800u82eurl1u82eformat then foru800 wayback webcite tableu82einsert outu800 ' ' ; open extlink markup tableu82einsert outu800 ulxu800u82eurl1u82eurlu800 ; addu800 urlu800 ifu800 ulxu800u82eurl1u82etitle then tableu82einsert outu800 ' ' theu800 required space tableu82einsert outu800 ulxu800u82eurl1u82etitle theu800 title tableu82einsert outu800 ' ' ; close extlink markup tableu82einsert outu800 ulxu800u82eurl1u82etail ; tail text ifu800 ulxu800u82eurl1u82edate then tableu82einsert outu800 '&#32u800; ' ; open date text; todo whyu800 theu800 html entity replace with regular space tableu82einsert outu800 'index' ulxu800u82eurl1u82edate andu800 s_textu82earchive oru800 s_textu82earchived ; addu800 text tableu82einsert outu800 ' ' ; insert au800 space tableu82einsert outu800 ulxu800u82eurl1u82edate ; addu800 date tableu82einsert outu800 ' ' ; close date text endu800 else nou800 title ifu800 index_date then when urlu800 date isu800 'index' tableu82einsert outu800 tableu82econcat ' ' s_textu82earchive_index ' ' ; addu800 theu800 index link label tableu82einsert outu800 msgu800 oru800   ; addu800 date mismatch message when urlu800 date isu800 * andu800 date hasu800 valid date else tableu82einsert outu800 tableu82econcat ' ' s_textu82earchived ' ' ' u8d8afu8d8b1 ' ; addu800 link label foru800 urlu800 hasu800 timestamp date will include mismatch message ifu800 there isu800 oneu800 endu800 ifu800 ulxu800u82eurl1u82edate then ifu800 'index' ulxu800u82eurl1u82edate then tableu82einsert outu800 ulxu800u82eurl1u82edate ; addu800 date when data isu800 notu800 'index' endu800 tableu82einsert outu800 comma ulxu800u82eurl1u82edate ; addu800 ' ' ifu800 date format isu800 mdyu800 tableu82einsert outu800 ulxu800u82eurl1u82etail ; addu800 tail text else nou800 date tableu82einsert outu800 ulxu800u82eurl1u82etail ; addu800 tail text endu800 endu800 ifu800 0u800 foru800 internaltionalization translate local language parameter names tou800 their english equivalents todo return error message ifu800 multiple aliases ofu800 theu800 same canonical parameter name areu800 found returns twou800 tables new_args holds canonical form parameters andu800 their values either from translation oru800 because theu800 parameter wasu800 already inu800 canonical form origin maps canonical form parameter names tou800 their untranslated local language form foru800 error messaging inu800 theu800 local language unrecognized parameters areu800 ignored local function parameter_name_xlate args params enum_params local name; holds modifiable name ofu800 theu800 parameter name during evaluation local enum; foru800 enumerated parameters holds theu800 enumerator during evaluation local found false; flag used tou800 break outu800 ofu800 nested foru800 loops local new_args ; au800 table that holds canonical andu800 translated parameter ku800 vu800 pairs local origin ; au800 table that maps original local language parameter names tou800 their canonical name foru800 local language error messaging local unnamed_params; setu800 true when unsupported positional parameters areu800 detected foru800 ku800 vu800 inu800 pairs args dou800 loop through allu800 ofu800 theu800 arguments inu800 theu800 args table name ku800; copy ofu800 original parameter name ifu800 'string' type ku800 then ifu800 non_western_digits then true when nonu800 western digits supported atu800 this wiki name mwu800u82eustringu82egsub name ' du800' digits ; convert this wiki wiki'su800 nonu800 western digits tou800 western digits endu800 enum name match ' du800 ' ; getu800 parameter enumerator ifu800 itu800 exists; nilu800 else ifu800 notu800 enum then nou800 enumerator sou800 looking foru800 nonu800 enumnerated parameters todo insert shortcut here ifu800 params name then name holds theu800 canonical parameter name; nou800 need tou800 search further foru800 pname aliases inu800 pairs params dou800 loop through each parameter theu800 params table foru800 _u800 alias inu800 ipairs aliases dou800 loop through each alias inu800 theu800 parameter parameter'su800 aliases table ifu800 name alias then new_args pname vu800; create au800 newu800 entry inu800 theu800 new_args table origin pname ku800; create anu800 entry tou800 make canonical parameter name tou800 original local language parameter name found true; flag sou800 that weu800 canu800 break outu800 ofu800 these nested foru800 loops break; nou800 need tou800 search theu800 rest ofu800 theu800 aliases table foru800 name sou800 gou800 onu800 tou800 theu800 next ku800 vu800 pair endu800 endu800 ifu800 found then true when weu800 found anu800 alias that matched name found false; reset theu800 flag break; gou800 dou800 next args ku800 vu800 pair endu800 endu800 else enumerated parameters name name gsub ' du800 ' '#' ; replace enumeration digits with place holder foru800 table search todo insert shortcut here ifu800 num_params name then name holds theu800 canonical parameter name; nou800 need tou800 search further foru800 pname aliases inu800 pairs enum_params dou800 loop through each parameter theu800 num_params table foru800 _u800 alias inu800 ipairs aliases dou800 loop through each alias inu800 theu800 parameter parameter'su800 aliases table ifu800 name alias then pname pname gsub '# ' enum ; replace theu800 '#' place holder with theu800 actual enumerator new_args pname vu800; create au800 newu800 entry inu800 theu800 new_args table origin pname ku800; create anu800 entry tou800 make canonical parameter name tou800 original local language parameter name found true; flag sou800 that weu800 canu800 break outu800 ofu800 these nested foru800 loops break; nou800 need tou800 search theu800 rest ofu800 theu800 aliases table foru800 name sou800 gou800 onu800 tou800 theu800 next ku800 vu800 pair endu800 endu800 ifu800 found then true when weu800 found anu800 alias that matched name found false; reset theu800 flag break; gou800 dou800 next args ku800 vu800 pair endu800 endu800 endu800 else unnamed_params true; flag foru800 unsupported positional parameters endu800 endu800 foru800 ku800 vu800 return new_args origin unnamed_params; endu800 template entry point local function webarchive frame local args getargs frame ; local data mwu800u82eloaddata tableu82econcat make au800 data module name; sandbox oru800 live 'module webarchive data' frame gettitle find 'sandbox' 1u800 true andu800 ' sandbox' oru800   this instance isu800 . sandbox then append sandbox ; categories datau82ecategories; fill inu800 theu800 forward declarations config datau82econfig; ifu800 datau82edigitsu82eenable then digits datau82edigits; foru800 i18n; table ofu800 digits inu800 theu800 local wiki wiki'su800 language non_western_digits true; use_non_western_digits endu800 err_warn_msgs datau82eerr_warn_msgs; excepted_pages datau82eexcepted_pages; month_num datau82emonth_num; foru800 i18n; table ofu800 month names inu800 theu800 local wiki wiki'su800 language prefixes datau82eprefixes; services datau82eservices; s_text datau82es_text; uncategorized_namespaces datau82euncategorized_namespaces; uncategorized_subpages datau82euncategorized_subpages; local origin ; holds au800 mapu800 ofu800 english tou800 local language parameter names used inu800 theu800 current template; notu800 currently used local unnamed_params; boolean setu800 tou800 true when template call hasu800 unnamed parameters args origin unnamed_params parameter_name_xlate args datau82eparams datau82eenum_params ; translate parameter names inu800 args tou800 english local date format msgu800 udate uriu800 urlu800; local ldfu800 'isou800'; when there isu800 nou800 date parameter render urlu800 dates inu800 isou800 format ifu800 argsu82eurlu800 andu800 argsu82eurl1 then urlu800 argument first return inlineerror datau82ecrit_err_msgsu82econflicting originu82eurlu800 originu82eurl1 ; endu800 urlu800 argsu82eurlu800 oru800 argsu82eurl1; ifu800 notu800 urlu800 then return inlineerror datau82ecrit_err_msgsu82eempty ; endu800 these iabot bugs perportedly fixed; removing these causes luau800 script error atu800 template webarchive testcases production; resolve that before deleting these tests ifu800 mwu800u82eustringu82efind urlu800 " " 1u800 true then track bugu800 todo iabot bugu800; notu800 known ifu800 theu800 bugu800 hasu800 been fixed; deferred track categoriesu82eerror 1u800; return inlineerror datau82ecrit_err_msgsu82eiabot1 ; endu800 ifu800 urlu800 " " then track bugu800 todo iabot bugu800; notu800 known ifu800 theu800 bugu800 hasu800 been fixed; deferred track categoriesu82eerror 1u800; return inlineerror datau82ecrit_err_msgsu82eiabot2 ; endu800 ifu800 notu800 urlu800 lower find ' http' oru800 urlu800 find ' ' then return inlineerror datau82ecrit_err_msgsu82einvalid_url ; endu800 ulxu800u82eurl1 ulxu800u82eurl1u82eurlu800 urlu800 ulxu800u82eurl1u82eextraurls parseextraargs args local good false; good uriu800 pcall mwu800u82euriu800u82enewu800 ulxu800u82eurl1u82eurlu800 ; getu800 au800 table ofu800 uriu800 parts from this urlu800; protected mode tou800 prevent luau800 error when ulxu800u82eurl1u82eurlu800 isu800 malformed ifu800 notu800 good oru800 nilu800 uriu800u82ehost then abandon when ulxu800u82eurl1u82eurlu800 isu800 malformed return inlineerror datau82ecrit_err_msgsu82einvalid_url ; endu800 servicename uriu800u82ehost argsu82enolink ifu800 argsu82edate andu800 argsu82edate1 then date argument return inlineerror datau82ecrit_err_msgsu82econflicting originu82edate originu82edate1 ; endu800 date argsu82edate oru800 argsu82edate1; date date andu800 date gsub ' ' ' ' ; replace multiple spaces with au800 single space ifu800 date andu800 configu82everifydates then ifu800 '*' date then date 'index'; ldfu800 'isou800'; setu800 tou800 default format else date ldfu800 decode_date date ; getu800 anu800 isou800 format date from date andu800 getu800 date date'su800 original format endu800 endu800 ifu800 'wayback' ulxu800u82eurl1u82eservice oru800 'locwebarchives ulxu800u82eurl1u82eservice then ifu800 date then ifu800 configu82everifydates then ifu800 ldfu800 then udate msgu800 decodewaybackdate uriu800u82epath ; getu800 theu800 urlu800 date inu800 isou800 format andu800 format ofu800 date inu800 date ; 'index' when wayback urlu800 date isu800 * ifu800 notu800 udate then this isu800 theu800 only 'fatal' error return return inlineerror datau82ecrit_err_msgs msgu800 ; endu800 ifu800 udate date then date comparison using isou800 format dates date udate; msgu800 tableu82econcat inlinered err_warn_msgsu82emismatch 'warning' addu800 warning message msgu800 addu800 message ifu800 there isu800 oneu800 ; endu800 endu800 endu800 else nou800 date udate msgu800 decodewaybackdate uriu800u82epath ; ifu800 notu800 udate then this isu800 theu800 only 'fatal' error return return inlineerror datau82ecrit_err_msgs msgu800 ; endu800 ifu800   udate then date nilu800; unset else date udate; endu800 endu800 elseif 'webcite' ulxu800u82eurl1u82eservice then ifu800 date then ifu800 configu82everifydates then ifu800 ldfu800 then udate decodewebcitedate uriu800u82epath ; getu800 theu800 urlu800 date inu800 isou800 format ifu800 'query' udate then skip ifu800 query ifu800 udate date then date comparison using isou800 format dates date udate; msgu800 tableu82econcat inlinered err_warn_msgsu82emismatch 'warning' ; endu800 endu800 endu800 endu800 else date decodewebcitedate uriu800u82epath "isou800" ifu800 date "query" then date nilu800; unset msgu800 inlinered err_warn_msgsu82edate_miss 'warning' ; elseif notu800 date then invalid base62 string date inlinered err_warn_msgsu82edate1 'error' ; endu800 endu800 elseif 'archiveis ulxu800u82eurl1u82eservice then ifu800 date then ifu800 configu82everifydates then ifu800 ldfu800 then udate msgu800 decodearchiveisdate uriu800u82epath getu800 theu800 urlu800 date inu800 isou800 format ifu800 'short link' udate then skip ifu800 short link ifu800 udate date then date comparison using isou800 format dates date udate; msgu800 tableu82econcat inlinered err_warn_msgsu82emismatch 'warning' addu800 warning message msgu800 addu800 message ifu800 there isu800 oneu800 ; endu800 endu800 endu800 endu800 else nou800 date udate msgu800 decodearchiveisdate uriu800u82epath "isou800" ifu800 udate "short link" then date nilu800; unset msgu800 inlinered err_warn_msgsu82edate_miss 'warning' ; elseif   udate then date nilu800; unset else date udate; endu800 endu800 else some other service ifu800 notu800 date then msgu800 inlinered err_warn_msgsu82edate_miss 'warning' ; endu800 endu800 ifu800 'index' date then ulxu800u82eurl1u82edate date .. msgu800 oru800   ; create index message ifu800 there isu800 oneu800 elseif date then ulxu800u82eurl1u82edate makedate date nilu800 nilu800 ldfu800 .. msgu800 oru800   ; create au800 date inu800 theu800 wiki wiki'su800 local language message ifu800 there isu800 oneu800 else ulxu800u82eurl1u82edate msgu800; endu800 format argsu82eformat; format argument ifu800 notu800 format then format "none" else foru800 ku800 vu800 inu800 pairs datau82eformat_vals dou800 format accepts twou800 specific values loop through au800 table ofu800 those values local found; declare au800 nilu800 flag foru800 _u800 pu800 inu800 ipairs vu800 dou800 loop through local language variants ifu800 format pu800 then when format value matches format ku800; useu800 name from table keyu800 found true; declare found sou800 that weu800 canu800 break outu800 ofu800 outer foru800 loop break; break outu800 ofu800 inner foru800 loop endu800 endu800 ifu800 found then break; endu800 endu800 ifu800 format "addlpages" then ifu800 notu800 ulxu800u82eurl1u82edate then format "none" endu800 elseif format "addlarchives" then format "addlarchives" else format "none" endu800 endu800 ulxu800u82eurl1u82eformat format ifu800 argsu82etitle andu800 argsu82etitle1 then title argument return inlineerror datau82ecrit_err_msgsu82econflicting originu82etitle originu82etitle1 ; endu800 ulxu800u82eurl1u82etitle argsu82etitle oru800 argsu82etitle1; local rend createrendering ifu800 notu800 rend then return inlineerror datau82ecrit_err_msgsu82eunknown ; endu800 return rend .. unnamed_params andu800 inlinered err_warn_msgsu82eunnamed_params 'warning' oru800   .. createtracking ; endu800 return webarchive webarchive ; 