 local coins ; local is_set in_array remove_wiki_link; functions inu800 module citation cs1u800 utilities local cfgu800; table ofu800 configuration tables that areu800 defined inu800 module citation cs1u800 configuration strip wiki italic andu800 bold markup from argument sou800 that itu800 doesn'tu800 contaminate coins metadata. this function strips common patterns ofu800 apostrophe markup. weu800 presume that editors whou800 have taken theu800 time tou800 markup au800 title have asu800 au800 result provided valid markup. when they donu800'tu800 some single apostrophes areu800 left behind. local function strip_apostrophe_markup argument ifu800 notu800 is_set argument then return argument; endu800 ifu800 argument find " " 1u800 true nilu800 then isu800 there atu800 least oneu800 double apostrophe ifu800 notu800 exit. return argument; endu800 while true dou800 ifu800 argument find " " 1u800 true then bold italic 5u800 argument argument gsub " ' ' ' ' '" "" ; remove allu800 instances ofu800 itu800 elseif argument find " " 1u800 true then italic start andu800 endu800 without content 4u800 argument argument gsub " ' ' ' '" "" ; elseif argument find " " 1u800 true then bold 3u800 argument argument gsub " ' ' '" "" ; elseif argument find " " 1u800 true then italic 2u800 argument argument gsub " ' '" "" ; else break; endu800 endu800 return argument; done endu800 makes au800 title foru800 coins from title andu800 oru800 scripttitle oru800 anyu800 other name script pairs apostrophe markup bold italics isu800 stripped from each value sou800 that theu800 coins metadata isnu800'tu800 corrupted with strings ofu800 27u800 27u800... local function make_coins_title title script ifu800 is_set title then title strip_apostrophe_markup title ; strip anyu800 apostrophe markup else title  ; ifu800 notu800 setu800 make sure title isu800 anu800 empty string endu800 ifu800 is_set script then script script gsub ' lu800 lu800 su800* su800*'   ; remove language prefix ifu800 present script value mayu800 nowu800 beu800 empty string script strip_apostrophe_markup script ; strip anyu800 apostrophe markup else script  ; ifu800 notu800 setu800 make sure script isu800 anu800 empty string endu800 ifu800 is_set title andu800 is_set script then script ' ' .. script; addu800 au800 space before weu800 concatenate endu800 return title .. script; return theu800 concatenation endu800 returns au800 string where allu800 ofu800 luau800 luau800'su800 magic characters have been escaped. this isu800 important because functions like stringu82egsub treat their pattern andu800 replace strings asu800 patterns notu800 literal strings. local function escape_lua_magic_chars argument argument argument gsub " " " " ; replace with argument argument gsub " . * " " 1u800" ; replace allu800 other luau800 magic pattern characters return argument; endu800 extract page numbers from external wikilinks inu800 anyu800 ofu800 theu800 page pages oru800 atu800 parameters foru800 useu800 inu800 coins. local function get_coins_pages pages local pattern; ifu800 notu800 is_set pages then return pages; endu800 ifu800 nou800 page numbers then weu800'reu800 done while true dou800 pattern pages match " wu800* su800 wu800 du800 .* " ; pattern isu800 theu800 opening bracket theu800 urlu800 andu800 following space su800 " urlu800 " ifu800 nilu800 pattern then break; endu800 nou800 more urls pattern escape_lua_magic_chars pattern ; pattern isu800 notu800 au800 literal string; escape luau800 luau800'su800 magic pattern characters pages pages gsub pattern "" ; remove asu800 many instances ofu800 pattern asu800 possible endu800 pages pages gsub " " "" ; remove theu800 brackets pages pages gsub "u8e28093" " " ; replace endashes with hyphens pages pages gsub "& wu800 ;" " " ; andu800 replace html entities &ndash; etcu800. with hyphens; dou800 weu800 need tou800 replace numerical entities like &#32u800; andu800 theu800 like return pages; endu800 there areu800 three options foru800 math markup rendering that depend onu800 theu800 editor editor'su800 math preference settings. these settings areu800 atu800 special preferences#mwu800 prefsection rendering andu800 areu800 pngu800 images texu800 source mathml with svgu800 oru800 pngu800 fallback allu800 three areu800 heavy with html andu800 cssu800 which doesn'tu800 belong inu800 theu800 metadata. without this function theu800 metadata saved inu800 theu800 rawu800 wikitext contained theu800 rendering determined byu800 theu800 settings ofu800 theu800 last editor tou800 save theu800 page. this function gets theu800 rendered form ofu800 anu800 equation according tou800 theu800 editor editor'su800 preference before theu800 page isu800 saved. itu800 then searches theu800 rendering foru800 theu800 text equivalent ofu800 theu800 rendered equation andu800 replaces theu800 rendering with that sou800 that theu800 page isu800 saved without extraneous html cssu800 markup andu800 with au800 reasonably readable text form ofu800 theu800 equation. when au800 replacement isu800 made this function returns true andu800 theu800 value with replacement; otherwise false andu800 theu800 intital value. tou800 replace multipe equations itu800 isu800 necesary tou800 call this function from within au800 loop. local function coins_replace_math_stripmarker value local stripmarker cfgu800u82estripmarkers 'math' ; local rendering value match stripmarker ; isu800 there au800 math stripmarker ifu800 notu800 rendering then when value doesn'tu800 have au800 math stripmarker abandon this test return false value; endu800 rendering mwu800u82etextu82eunstripnowiki rendering ; convert stripmarker into rendered value oru800 nilu800   when math render error ifu800 rendering match 'altu800 " " "' then ifu800 pngu800 math option rendering rendering match 'altu800 " " "' ; extract just theu800 math text elseif rendering match ' su800 . su800 ' then ifu800 texu800 math option; isu800 legit character that isu800 escapes asu800 rendering rendering match ' su800 . su800 ' extract just theu800 math text elseif rendering match ' . ' then ifu800 mathml math option rendering rendering match ' . ' extract just theu800 math text else return false value; hadu800 math stripmarker butu800 notu800 oneu800 ofu800 theu800 three defined forms endu800 return true value gsub stripmarker rendering 1u800 ; endu800 cleanup parameter values foru800 theu800 metadata byu800 removing oru800 replacing invisible characters andu800 certain html entities. 2015 12u800 10u800 there isu800 au800 bugu800 inu800 mwu800u82etextu82eunstripnowiki . itu800 replaces math stripmarkers with theu800 appropriate content when itu800 shouldn'tu800. seeu800 andu800 wikipedia_talk luau800#stripmarkers_and_mwu82etextu82eunstripnowikiu82e28u800u82e29u800 todo move theu800 replacement patterns andu800 replacement values into au800 table inu800 configuration similar tou800 theu800 invisible characters table local function coins_cleanup value local replaced true; default state tou800 getu800 theu800 dou800 loop running while replaced dou800 loop until allu800 math stripmarkers replaced replaced value coins_replace_math_stripmarker value ; replace math stripmarker with text representation ofu800 theu800 equation endu800 value value gsub cfgu800u82estripmarkers 'math' "math render error" ; oneu800 oru800 more couldn'tu800 beu800 replaced; insert vague error message value mwu800u82etextu82eunstripnowiki value ; replace nowiki stripmarkers with their content value value gsub ' &#39u800; su800 ' "' 1u800" ; replace ' oru800 'su800 with simple apostrophe oru800 apostrophe su800 value value gsub '&nbsp;' ' ' ; replace &nbsp; entity with plain space value value gsub ' 226u800 128u800 138u800' ' ' ; replace hair space with plain space ifu800 notu800 mwu800u82eustringu82efind value cfgu800u82eindic_script then donu800'tu800 remove zero width joiner characters from indic script value value gsub '&zwju800;'   ; remove &zwju800; entities value mwu800u82eustringu82egsub value ' 226u800 128u800 141u800 226u800 128u800 139u800 194u800 173u800 '   ; remove zero width joiner zero width space soft hyphen endu800 value value gsub ' 009u800 010u800 013u800 ' ' ' ; replace horizontal tabu800 line feed carriage return with plain space return value; endu800 coins metadata seeu800 allows automated tools tou800 parse theu800 citation information. local function coins data class ifu800 'table' type data oru800 nilu800 next data then return  ; endu800 foru800 ku800 vu800 inu800 pairs data dou800 spin through allu800 ofu800 theu800 metadata parameter values ifu800 'id_list' ku800 andu800 'authors ku800 then except theu800 id_list andu800 author tables author nowiki stripmarker done when author table processed data ku800 coins_cleanup vu800 ; endu800 endu800 local ctx_ver "z39u800u82e88u800 2004"; treat table strictly asu800 anu800 array with only setu800 values. local ocinsoutput setmetatable __newindex function self keyu800 value ifu800 is_set value then rawset self #self 1u800 tableu82econcat keyu800 ' ' mwu800u82euriu800u82eencode remove_wiki_link value ; endu800 endu800 ; ifu800 in_array class 'arxiv' 'biorxiv' 'citeseerx' 'journal' 'news 'magazine' oru800 in_array class 'conference' 'interview' 'mapu800' 'press release' 'webu800' andu800 is_set datau82eperiodical oru800 'citation' class andu800 is_set datau82eperiodical andu800 notu800 is_set datau82eencyclopedia then ocinsoutputu82erft_val_fmt "info ofiu800 fmtu800 kevu800 mtxu800 journal"; journal metadata identifier ifu800 in_array class 'arxiv' 'biorxiv' 'citeseerx' then setu800 genre according tou800 theu800 type ofu800 citation template weu800 areu800 rendering ocinsoutput "rftu800u82egenre" "preprint"; cite arxiv cite biorxiv cite citeseerx elseif 'conference' class then ocinsoutput "rftu800u82egenre" "conference"; cite conference when periodical setu800 elseif 'webu800' class then ocinsoutput "rftu800u82egenre" "unknown"; cite webu800 when periodical setu800 else ocinsoutput "rftu800u82egenre" "article"; journal andu800 other 'periodical' articles endu800 ocinsoutput "rftu800u82ejtitle" datau82eperiodical; journal only ocinsoutput "rftu800u82eatitle" datau82etitle; 'periodical' article titles these used only foru800 periodicals ocinsoutput "rftu800u82essnu800" datau82eseason; keywords winter spring summer fall ocinsoutput "rftu800u82echron" datau82echron; free form date components ocinsoutput "rftu800u82evolume" datau82evolume; does notu800 apply tou800 books ocinsoutput "rftu800u82eissue" datau82eissue; ocinsoutput "rftu800u82epages" datau82epages; also used inu800 book metadata elseif 'thesis class then allu800 others except cite thesis areu800 treated asu800 'book' metadata; genre distinguishes ocinsoutputu82erft_val_fmt "info ofiu800 fmtu800 kevu800 mtxu800 book"; book metadata identifier ifu800 'report' class oru800 'techreport' class then cite report andu800 cite techreport ocinsoutput "rftu800u82egenre" "report"; elseif 'conference' class then cite conference when periodical notu800 setu800 ocinsoutput "rftu800u82egenre" "conference"; ocinsoutput "rftu800u82eatitle" datau82echapter; conference paper asu800 chapter inu800 proceedings book elseif in_array class 'book' 'citation' 'encyclopaedia' 'interview' 'mapu800' then ifu800 is_set datau82echapter then ocinsoutput "rftu800u82egenre" "bookitem"; ocinsoutput "rftu800u82eatitle" datau82echapter; book chapter encyclopedia article interview inu800 au800 book oru800 mapu800 title else ifu800 'mapu800' class oru800 'interview' class then ocinsoutput "rftu800u82egenre" 'unknown'; standalone mapu800 oru800 interview else ocinsoutput "rftu800u82egenre" 'book'; book andu800 encyclopedia endu800 endu800 else 'audio visual' 'avu800 media notes 'dvdu800 notes 'episode' 'interview' 'mailinglist' 'mapu800' 'newsgroup' 'podcast' 'press release' 'serial' 'sign' 'speech' 'webu800' ocinsoutput "rftu800u82egenre" "unknown"; endu800 ocinsoutput "rftu800u82ebtitle" datau82etitle; book only ocinsoutput "rftu800u82eplace" datau82epublicationplace; book only ocinsoutput "rftu800u82eseries" datau82eseries; book only ocinsoutput "rftu800u82epages" datau82epages; book journal ocinsoutput "rftu800u82eedition" datau82eedition; book only ocinsoutput "rftu800u82epubu800" datau82epublishername; book andu800 dissertation else cite thesis ocinsoutputu82erft_val_fmt "info ofiu800 fmtu800 kevu800 mtxu800 dissertation"; dissertation metadata identifier ocinsoutput "rftu800u82etitle" datau82etitle; dissertation also patent butu800 that isu800 notu800 yetu800 supported ocinsoutput "rftu800u82edegree" datau82edegree; dissertation only ocinsoutput 'rftu800u82einst' datau82epublishername; book andu800 dissertation endu800 andu800 nowu800 common parameters asu800 much asu800 possible ocinsoutput "rftu800u82edate" datau82edate; book journal dissertation foru800 ku800 vu800 inu800 pairs datau82eid_list dou800 what tou800 dou800 about these foru800 nowu800 assume that they areu800 common tou800 allu800 ifu800 ku800 'isbn' then vu800 clean_isbn vu800 endu800 ifu800 ku800 'isbn' then vu800 vu800 gsub " 0u800 9xu800 " "" ; endu800 local idu800 cfgu800u82eid_handlers ku800 .coins; ifu800 stringu82esubu800 idu800 oru800 "" 1u800 4u800 'info' then foru800 idsu800 that areu800 inu800 theu800 info registry ocinsoutput "rft_id" tableu82econcat idu800 " " vu800 ; elseif stringu82esubu800 idu800 oru800 "" 1u800 3u800 'rftu800' then foru800 isbn issn eissn etcu800 that have defined coins keywords ocinsoutput idu800 vu800; elseif idu800 then when cfgu800u82eid_handlers ku800 .coins isu800 notu800 nilu800 ocinsoutput "rft_id" tableu82econcat cfgu800u82eid_handlers ku800 .prefix vu800 ; others; provide au800 urlu800 endu800 endu800 foru800 ku800 vu800 inu800 pairs datau82eid_list dou800 what tou800 dou800 about these foru800 nowu800 assume that they areu800 common tou800 allu800 local idu800 value cfgu800u82eid_handlers ku800 .coins; ifu800 ku800 'isbn' then value clean_isbn vu800 ; else value vu800; endu800 ifu800 stringu82esubu800 idu800 oru800 "" 1u800 4u800 'info' then ocinsoutput "rft_id" tableu82econcat idu800 " " vu800 ; else ocinsoutput idu800 value; endu800 endu800 local last first; foru800 ku800 vu800 inu800 ipairs datau82eauthors dou800 last first coins_cleanup vu800u82elast coins_cleanup vu800u82efirst oru800   ; replace anyu800 nowiki strip markers nonu800 printing oru800 invisible characers ifu800 ku800 1u800 then foru800 theu800 first author name only ifu800 is_set last andu800 is_set first then setu800 these coins values ifu800 first andu800 last specify theu800 first author name ocinsoutput "rftu800u82eaulast" last; book journal dissertation ocinsoutput "rftu800u82eaufirst" first; book journal dissertation elseif is_set last then ocinsoutput "rftu800u82eauu800" last; book journal dissertation otherwise useu800 this form foru800 theu800 first name endu800 else foru800 allu800 other authors ifu800 is_set last andu800 is_set first then ocinsoutput "rftu800u82eauu800" tableu82econcat last " " first ; book journal dissertation elseif is_set last then ocinsoutput "rftu800u82eauu800" last; book journal dissertation endu800 endu800 endu800 ocinsoutputu82erft_id datau82eurlu800; ocinsoutputu82erfr_id tableu82econcat "info sidu800 " mwu800u82esiteu82eserver match " * " " " datau82erawpage ; ocinsoutput setmetatable ocinsoutput nilu800 ; sort with version string always first andu800 combine. tableu82esort ocinsoutput ; tableu82einsert ocinsoutput 1u800 "ctx_ver " .. ctx_ver ; such asu800 "z39u800u82e88u800 2004" return tableu82econcat ocinsoutput "&" ; endu800 sets local cfgu800 table andu800 imported functions table tou800 same live oru800 sandbox asu800 that used byu800 theu800 other modules. local function set_selected_modules cfg_table_ptr utilities_page_ptr cfgu800 cfg_table_ptr; is_set utilities_page_ptru82eis_set; import functions from select module citation cs1u800 utilities module in_array utilities_page_ptru82ein_array; remove_wiki_link utilities_page_ptru82eremove_wiki_link; endu800 return make_coins_title make_coins_title get_coins_pages get_coins_pages coins coins set_selected_modules set_selected_modules 