 local uu800 local zu800 error_categories ; foru800 categorizing citations that contain errors error_ids ; message_tail ; maintenance_cats ; foru800 categorizing citations that aren'tu800 erroneous peru800 seu800 butu800 could useu800 au800 little work properties_cats ; foru800 categorizing citations based onu800 certain properties language ofu800 source foru800 instance ; local cfgu800; table ofu800 tables imported from selected module citation cs1u800 configuration returns true ifu800 argument isu800 setu800; false otherwise. argument isu800 'setu800' when itu800 exists notu800 nilu800 oru800 when itu800 isu800 notu800 anu800 empty string. local function is_set varu800 return notu800 varu800 nilu800 oru800 varu800   ; endu800 whether needle isu800 inu800 haystack local function in_array needle haystack ifu800 needle nilu800 then return false; endu800 foru800 nu800 vu800 inu800 ipairs haystack dou800 ifu800 vu800 needle then return nu800; endu800 endu800 return false; endu800 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 wraps error messages with cssu800 markup according tou800 theu800 state ofu800 hidden. local function error_comment content hidden return substitute hidden andu800 cfgu800u82epresentation 'hidden error' oru800 cfgu800u82epresentation 'visible error' content ; endu800 makes au800 wikilink; when botu800 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 ifu800 is_set link then ifu800 is_set display then return tableu82econcat ' ' link ' ' display ' ' ; else return tableu82econcat ' ' link ' ' ; endu800 else return  ; endu800 endu800 sets anu800 error condition andu800 returns theu800 appropriate error message. theu800 actual placement ofu800 theu800 error message inu800 theu800 output isu800 theu800 responsibility ofu800 theu800 calling function. local function set_error error_id arguments rawu800 prefix suffix local error_state cfgu800u82eerror_conditions error_id ; prefix prefix oru800 ""; suffix suffix oru800 ""; ifu800 error_state nilu800 then error cfgu800u82emessages 'undefined_error' ; because missing error handler inu800 module citation cs1u800 configuration elseif is_set error_stateu82ecategory then tableu82einsert zu800u82eerror_categories error_stateu82ecategory ; endu800 local message substitute error_stateu82emessage arguments ; message tableu82econcat message ' ' make_wikilink tableu82econcat cfgu800u82emessages 'help page link' '#' error_stateu82eanchor cfgu800u82emessages 'help page label' ' ' ; message tableu82econcat message ' ' substitute cfgu800u82epresentation 'wikilink' cfgu800u82emessages 'help page link' .. '#' .. error_stateu82eanchor cfgu800u82emessages 'help page label' ' ' ; message message .. " " .. cfgu800u82emessages 'help page link' .. "#" .. error_stateu82eanchor .. " " .. cfgu800u82emessages 'help page label' .. " "; zu800u82eerror_ids error_id true; ifu800 in_array error_id 'bare_url_missing_title' 'trans_missing_title' andu800 zu800u82eerror_ids 'citation_missing_title' then return   false; endu800 message tableu82econcat prefix message suffix ; ifu800 rawu800 true then return message error_stateu82ehidden; endu800 return error_comment message error_stateu82ehidden ; endu800 this function isu800 used byu800 select_one tou800 determine ifu800 oneu800 ofu800 au800 list ofu800 alias parameters isu800 inu800 theu800 argument list provided byu800 theu800 template. input args u8e28093 pointer tou800 theu800 arguments table from calling template alias u8e28093 oneu800 ofu800 theu800 list ofu800 possible aliases inu800 theu800 aliases lists from module citation cs1u800 configuration index u8e28093 foru800 enumerated parameters identifies which oneu800 enumerated u8e28093 true false flag used choose howu800 enumerated aliases areu800 examined value u8e28093 value associated with anu800 alias that hasu800 previously been selected; nilu800 ifu800 notu800 yetu800 selected selected u8e28093 theu800 alias that hasu800 previously been selected; nilu800 ifu800 notu800 yetu800 selected error_list u8e28093 list ofu800 aliases that areu800 duplicates ofu800 theu800 alias already selected returns value u8e28093 value associated with alias weu800 selected oru800 that wasu800 previously selected oru800 nilu800 ifu800 anu800 alias notu800 yetu800 selected selected u8e28093 theu800 alias weu800 selected oru800 theu800 alias that wasu800 previously selected oru800 nilu800 ifu800 anu800 alias notu800 yetu800 selected local function is_alias_used args alias index enumerated value selected error_list ifu800 enumerated then isu800 this au800 test foru800 anu800 enumerated parameters alias alias gsub '#' index ; replace '#' with theu800 value inu800 index else alias alias gsub '#'   ; remove '#' ifu800 itu800 exists endu800 ifu800 is_set args alias then alias isu800 inu800 theu800 template template'su800 argument list ifu800 value nilu800 andu800 selected alias then ifu800 weu800 have already selected oneu800 ofu800 theu800 aliases local skip; foru800 _u800 vu800 inu800 ipairs error_list dou800 spin through theu800 error list tou800 seeu800 ifu800 weu800'veu800 added this alias ifu800 vu800 alias then skip true; break; hasu800 been added sou800 stop looking endu800 endu800 ifu800 notu800 skip then hasu800 notu800 been added sou800 tableu82einsert error_list alias ; addu800 error alias tou800 theu800 error list endu800 else value args alias ; notu800 yetu800 selected anu800 alias sou800 select this oneu800 selected alias; endu800 endu800 return value selected; return newly selected alias oru800 previously selected alias endu800 adds au800 category tou800 zu800u82emaintenance_cats using names from theu800 configuration file with additional text ifu800 anyu800. tou800 prevent duplication theu800 added_maint_cats table lists theu800 categories byu800 keyu800 that have been added tou800 zu800u82emaintenance_cats. local added_maint_cats list ofu800 maintenance categories that have been added tou800 zu800u82emaintenance_cats local function add_maint_cat keyu800 arguments ifu800 notu800 added_maint_cats keyu800 then added_maint_cats keyu800 true; note that weu800'veu800 added this category tableu82einsert zu800u82emaintenance_cats substitute cfgu800u82emaint_cats keyu800 arguments ; make name then addu800 tou800 table endu800 endu800 protects au800 string that will beu800 wrapped inu800 wiki italic markup   ...   note weu800 cannot useu800 foru800 italics asu800 theu800 expected behavior foru800 italics specified byu800  ...  inu800 theu800 title isu800 that they will beu800 inverted iu800u82eeu800. unitalicized inu800 theu800 resulting references. inu800 addition andu800   tend tou800 interact poorly under mediawiki mediawiki'su800 html tidy. local function safe_for_italics stru800 ifu800 notu800 is_set stru800 then return stru800; else ifu800 stru800 subu800 1u800 1u800 "'" then stru800 " " .. stru800; endu800 ifu800 stru800 subu800 1u800 1u800 "'" then stru800 stru800 .. " "; endu800 remove newlines asu800 they break italics. return stru800 gsub ' nu800' ' ' ; endu800 endu800 applies styling tou800 various parameters. supplied string isu800 wrapped using au800 message_list configuration taking oneu800 argument; protects italic styled parameters. additional text taken from citation_configu82epresentation theu800 reason this function isu800 similar tou800 butu800 separate from wrap_msg . local function wrap_style keyu800 stru800 ifu800 notu800 is_set stru800 then return ""; elseif in_array keyu800 'italic title' 'trans italic title' then stru800 safe_for_italics stru800 ; endu800 return substitute cfgu800u82epresentation keyu800 stru800 ; endu800 chooses oneu800 matching parameter from au800 list ofu800 parameters tou800 consider. theu800 list ofu800 parameters tou800 consider isu800 just names. foru800 parameters that mayu800 beu800 enumerated theu800 position ofu800 theu800 numerator inu800 theu800 parameter name isu800 identified byu800 theu800 '#' sou800 author last1 andu800 author1 last areu800 represented asu800 'author last#' andu800 'author# last'. because enumerated parameter 1u800 isu800 anu800 alias ofu800 weu800 must test foru800 both possibilities. generates anu800 error ifu800 more than oneu800 match isu800 present. local function select_one args aliases_list error_condition index local value nilu800; theu800 value assigned tou800 theu800 selected parameter local selected  ; theu800 name ofu800 theu800 parameter weu800 have chosen local error_list ; ifu800 index nilu800 then index tostring index ; endu800 foru800 _u800 alias inu800 ipairs aliases_list dou800 foru800 each alias inu800 theu800 aliases list ifu800 alias match '#' then ifu800 this alias canu800 beu800 enumerated ifu800 '1u800' index then when index isu800 1u800 test foru800 enumerated andu800 nonu800 enumerated aliases value selected is_alias_used args alias index false value selected error_list ; first test foru800 nonu800 enumerated alias endu800 value selected is_alias_used args alias index true value selected error_list ; test foru800 enumerated alias else value selected is_alias_used args alias index false value selected error_list ; test foru800 nonu800 enumerated alias endu800 endu800 ifu800 #error_list 0u800 andu800 'none' error_condition then foru800 cases where this code isu800 used outside ofu800 extract_names local error_str ""; foru800 _u800 ku800 inu800 ipairs error_list dou800 ifu800 error_str "" then error_str error_str .. cfgu800u82emessages 'parameter separator' endu800 error_str error_str .. wrap_style 'parameter' ku800 ; endu800 ifu800 #error_list 1u800 then error_str error_str .. cfgu800u82emessages 'parameter final separator' ; else error_str error_str .. cfgu800u82emessages 'parameter pair separator' ; endu800 error_str error_str .. wrap_style 'parameter' selected ; tableu82einsert zu800u82emessage_tail set_error error_condition error_str true ; endu800 return value selected; endu800 gets theu800 display text from au800 wikilink like au800 bu800 oru800 bu800 gives bu800 theu800 stru800 gsub returns either au800 bu800 froma au800 bu800 oru800 bu800 from bu800 oru800 bu800 from bu800 nou800 wikilink markup . inu800 lu800 lu800 gsub removes theu800 link andu800 pipe ifu800 they exist ; theu800 second gsub trims white space from theu800 label ifu800 stru800 wasu800 wrapped inu800 wikilink markup. presumably this isu800 because without wikimarkup inu800 stru800 there isu800 nou800 match inu800 theu800 initial gsub theu800 replacement function lu800 doesn'tu800 getu800 called. local function remove_wiki_link stru800 return stru800 gsub " * " function lu800 return lu800 gsub " * .* " " 1u800" gsub " su800* . su800* " " 1u800" ; endu800 ; endu800 determines ifu800 stru800 isu800 au800 wikilink extracts andu800 returns theu800 theu800 wikilink type link text andu800 display text parts. ifu800 stru800 isu800 au800 complex wikilink lu800 du800 returns wl_type 2u800 andu800 du800 andu800 lu800 from lu800 du800 ; ifu800 stru800 isu800 au800 simple wikilink du800 returns wl_type 1u800 andu800 du800 from du800 andu800 lu800 asu800 empty string; ifu800 notu800 au800 wikilink returns wl_type 0u800 stru800 asu800 du800 andu800 lu800 asu800 empty string. trims leading andu800 trailing white space andu800 pipes from lu800 andu800 du800 lu800 lu800 andu800 u8d9beu8d988u8d8afu8d985u8d8a7u8d986 du800 du800 areu800 accepted byu800 mediawiki andu800 treated like du800 ; while du800 isu800 notu800 accepted byu800 mediawiki here weu800 accept itu800 andu800 return du800 without theu800 pipes . local function is_wikilink stru800 local du800 lu800 local wl_type 2u800; assume that stru800 isu800 au800 complex wikilink lu800 du800 lu800 du800 stru800 match ' ' ; getu800 lu800 andu800 du800 from lu800 du800 ifu800 notu800 is_set du800 then ifu800 nou800 separate link du800 stru800 match ' * * ' ; getu800 du800 from du800 wl_type 1u800; endu800 ifu800 notu800 is_set du800 then nou800 wikilink markup du800 stru800; return theu800 string asu800 du800 wl_type 0u800; butu800 sayu800 that itu800 isu800 notu800 au800 wikilink endu800 du800 mwu800u82etextu82etrim du800 ' su800 ' ; trim white space andu800 pipe characters lu800 lu800 andu800 mwu800u82etextu82etrim lu800 ' su800 ' ; return wl_type du800 lu800 oru800  ; endu800 sets local cfgu800 table tou800 same live oru800 sandbox asu800 that used byu800 theu800 other modules. local function set_selected_modules cfg_table_ptr cfgu800 cfg_table_ptr; endu800 return return exported functions andu800 tables is_set is_set in_array in_array substitute substitute error_comment error_comment set_error set_error select_one select_one add_maint_cat add_maint_cat wrap_style wrap_style safe_for_italics safe_for_italics remove_wiki_link remove_wiki_link is_wikilink is_wikilink make_wikilink make_wikilink set_selected_modules set_selected_modules zu800 zu800 