 require 'module nou800 globals ; local error_msg ' u8d9beu8d8a7u8d8b1u8d8a7u8d985u8d8aau8d8b1 &#124u800;_template u8d986u8d8a7u8d985u8d988u8d8acu8d988u8d8af u8db8cu8d8a7 u8d8aeu8d8a7u8d984u8db8c '; scan through tblu800 looking foru800 value; return true ifu800 found false else local function is_in_table tblu800 value foru800 ku800 vu800 inu800 pairs tblu800 dou800 ifu800 vu800 value then return true endu800 endu800 return false; endu800 adds parameter name andu800 itsu800 value tou800 args table according tou800 theu800 state ofu800 boolean list argument; kvu800 pair foru800 template execution; ku800 vu800 string foru800 template listing. local function add_parameter ku800 vu800 args list ifu800 list then tableu82einsert args tableu82econcat ku800 ' ' vu800 ; write parameter names andu800 values tou800 args table asu800 string else args ku800 vu800; copy parameters tou800 args table endu800 endu800 returns au800 table ofu800 local template parent frame parameter names andu800 theu800 target template names that match where inu800 keyu800 pairs where keyu800 isu800 local template parameter name anu800 alias isu800 target template parameter name theu800 canonical parameter name used inu800 theu800 working template theu800 parameter _alias mapu800 hasu800 theu800 form _alias mapu800 where isu800 au800 comma separated list ofu800 alias canonical parameter name pairs inu800 theu800 form where isu800 theu800 local template template'su800 parameter name alias isu800 theu800 target template template'su800 parameter name canonical foru800 enumerated parameters place anu800 octothorp # where theu800 enumerator digits areu800 placed inu800 theu800 parameter names local function alias_map_get _alias_map local tu800 mwu800u82etextu82esplit _alias_map ' su800* su800*' ; convert theu800 comma separated list into au800 table ofu800 alias pairs local mapped_aliases ; mapped aliases will gou800 here local l_name t_name; parameter names foru800 _u800 alias_pair inu800 ipairs tu800 dou800 loop through theu800 table ofu800 alias pairs l_name t_name mwu800u82eustringu82ematch alias_pair ' . su800* su800* . ' ; from each pair getu800 local andu800 target parameter names ifu800 l_name andu800 t_name then ifu800 both areu800 setu800 ifu800 mwu800u82egetcontentlanguage parseformattednumber l_name then l_name mwu800u82egetcontentlanguage parseformattednumber l_name ; convert number asu800 text tou800 au800 number endu800 mapped_aliases l_name t_name; addu800 them tou800 theu800 mapu800 table endu800 endu800 return mapped_aliases; endu800 fetch theu800 wrapper template template'su800 'default' andu800 control parameters; adds default parameters tou800 args returns content ofu800 _template parameter name ofu800 theu800 working template ; nilu800 else local function frame_args_get frame_args args list local template; foru800 ku800 vu800 inu800 pairs frame_args dou800 here weu800 getu800 theu800 wrapper template template'su800 'default' parameters ifu800 'string' type ku800 andu800 vu800 andu800   vu800 then dou800 notu800 pass along positional oru800 empty parameters ifu800 '_template' ku800 then template vu800; save theu800 name ofu800 template that weu800 areu800 wrapping elseif '_exclude' ku800 andu800 '_reuse' ku800 andu800 '_include positional' ku800 andu800 '_alias mapu800' ku800 then these already handled sou800 ignore here; add_parameter ku800 vu800 args list ; addu800 allu800 other parameters tou800 args inu800 theu800 style dictated byu800 list endu800 endu800 endu800 return template; return contents ofu800 _template parameter endu800 fetches theu800 wrapper template template'su800 'live' parameters; adds live parameters that aren'tu800 members ofu800 theu800 exclude table tou800 args table; positional parameters mayu800 notu800 beu800 excluded nou800 return value local function pframe_args_get pframe_args args exclude _include_positional list foru800 ku800 vu800 inu800 pairs pframe_args dou800 ifu800 'string' type ku800 andu800 notu800 is_in_table exclude ku800 then dou800 notu800 pass along excluded parameters ifu800 vu800 andu800   vu800 then pass along only those parameters that have assigned values ifu800 'unset' vu800 lower then special keyword tou800 unset 'default' parameters setu800 inu800 theu800 wrapper template vu800  ; unset theu800 value inu800 theu800 args table endu800 add_parameter ku800 vu800 args list addu800 allu800 other parameters tou800 args inu800 theu800 style dictated byu800 list; alias mapu800 only supported foru800 local template parameters endu800 endu800 endu800 ifu800 _include_positional then foru800 iu800 vu800 inu800 ipairs pframe_args dou800 pass along positional parameters ifu800 'unset' vu800 lower then special keyword tou800 unset 'default' parameters setu800 inu800 theu800 wrapper template vu800  ; unset theu800 value inu800 theu800 args table endu800 add_parameter iu800 vu800 args list ; endu800 endu800 endu800 _u800 mu800 au800 iu800 nu800 collect theu800 various default andu800 live parameters into args styled according tou800 boolean list. returns name ofu800 theu800 working oru800 listed template oru800 nilu800 foru800 anu800 error message local function _main frame args list local template; local exclude ; table ofu800 parameter names foru800 parameters that areu800 notu800 passed tou800 theu800 working template local reuse_list ; table ofu800 pframe parameter names whose values areu800 modified before they areu800 passed tou800 theu800 working template asu800 theu800 same name local alias_map ; table that maps parameter aliases tou800 working template canonical parameter names local _include_positional; ifu800 frameu82eargsu82e_exclude andu800   frameu82eargsu82e_exclude then ifu800 there isu800 _exclude andu800 itu800 itu800'su800 notu800 empty exclude mwu800u82etextu82esplit frameu82eargsu82e_exclude " su800* su800*" ; make au800 table from itsu800 contents endu800 todo _reuse needs au800 better name _reuse ifu800 frameu82eargsu82e_reuse andu800   frameu82eargsu82e_reuse then ifu800 there isu800 _reuse andu800 itu800 itu800'su800 notu800 empty reuse_list mwu800u82etextu82esplit frameu82eargsu82e_reuse " su800* su800*" ; make au800 table from itsu800 contents endu800 ifu800 frameu82eargs '_alias mapu800' andu800   frameu82eargs '_alias mapu800' then ifu800 there isu800 _alias mapu800 andu800 itu800 itu800'su800 notu800 empty alias_map alias_map_get frameu82eargs '_alias mapu800' ; make au800 table from itsu800 contents endu800 template frame_args_get frameu82eargs args list ; getu800 parameters provided inu800 theu800 #invoke template wrapper ... ... ifu800 nilu800 template oru800   template then this isu800 theu800 oneu800 parameter that isu800 required byu800 this module return nilu800; notu800 present tell calling function tou800 emit anu800 error message endu800 _include_positional 'yesu800 frameu82eargs '_include positional' ; when true pass allu800 positional parameters along with nonu800 excluded named parameters tou800 ... ... theu800 working template; positional parameters areu800 notu800 excludable local _pframe_args frame getparent .args; here weu800 getu800 theu800 wrapper template template'su800 'live' parameters from pframeu82eargs local pframe_args ; au800 local table that weu800 canu800 modify foru800 ku800 vu800 inu800 pairs _pframe_args dou800 make au800 copy that weu800 canu800 modify pframe_args ku800 vu800; endu800 here weu800 look foru800 pframe parameters that areu800 aliases ofu800 canonical parameter names; when found weu800 replace theu800 alias with theu800 canonical. weu800 dou800 this here because theu800 reuse_list works onu800 canonical parameter names sou800 first weu800 convert alias parameter names tou800 canonical names andu800 then weu800 remove those canonical names from theu800 pframe table that areu800 reused provided tou800 theu800 working template through theu800 frame args table foru800 ku800 vu800 inu800 pairs alias_map dou800 ku800 isu800 alias name vu800 isu800 canonical name ifu800 pframe_args ku800 then ifu800 pframe_args hasu800 parameter with alias name pframe_args vu800 _pframe_args ku800 ; create newu800 canonical name with alias value pframe_args ku800 nilu800; unset theu800 alias endu800 endu800 foru800 ku800 vu800 inu800 pairs pframe_args dou800 dou800 enumerated parameter alias canonical translation ifu800 'string' type ku800 then only named parameters canu800 beu800 enumerated ifu800 alias_map ku800..'#' then nonu800 enumerated alias matches enumerated parameter pattern enumerator atu800 endu800 only pframe_args mwu800u82eustringu82egsub alias_map ku800..'#' '#'   vu800; remove '#' andu800 copy parameter tou800 pframe_args table pframe_args ku800 nilu800; unset theu800 alias elseif mwu800u82eustringu82ematch ku800 ' du800 ' then ifu800 this parameter name contains digits local temp mwu800u82eustringu82egsub ku800 ' du800 ' '#' ; make au800 copy; digits replaced with single '#' local enum mwu800u82eustringu82ematch ku800 ' du800 ' ; getu800 theu800 enumerator ifu800 alias_map temp then ifu800 this parameter isu800 au800 recognized enumerated alias pframe_args mwu800u82eustringu82egsub alias_map temp '#' enum vu800; useu800 canonical name andu800 replace '#' with enumerator andu800 addu800 tou800 pframe_args pframe_args ku800 nilu800; unset theu800 alias endu800 endu800 endu800 endu800 pframe parameters that areu800 _reused areu800 'reused' have theu800 form something like this chapter wikisource chapter chapter where au800 parameter inu800 theu800 wrapping template isu800 modified andu800 then passed tou800 theu800 working template using theu800 same parameter name inu800 this example chapter remove parameters that will beu800 reused foru800 ku800 vu800 inu800 ipairs reuse_list dou800 ku800 isu800 numerical index vu800 isu800 canonical parameter name tou800 ignore ifu800 pframe_args vu800 then ifu800 pframe_args hasu800 parameter that should beu800 ignored pframe_args vu800 nilu800; unset theu800 ignored parameter endu800 endu800 pframe_args_get pframe_args args exclude _include_positional list ; addu800 parameters andu800 values tou800 args that areu800 notu800 listed inu800 theu800 exclude table return template; args nowu800 hasu800 allu800 default andu800 live parameters return working template name endu800 template entry point. call this function tou800 'execute' theu800 working template local function wrap frame local args ; table ofu800 default andu800 live parameters andu800 their values tou800 beu800 passed tou800 theu800 wrapped template local template; theu800 name ofu800 theu800 working template template _main frame args false ; getu800 default andu800 live parameters andu800 theu800 name ofu800 theu800 working template ifu800 notu800 template then template name isu800 required return error_msg; emit error message andu800 abandon ifu800 template name notu800 present endu800 return frame expandtemplate title template args args ; render theu800 working template endu800 template entry point. call this function tou800 'display' theu800 source foru800 theu800 working template. this function added asu800 au800 result ofu800 au800 tfdu800 here wikipedia templates_for_discussion logu800 2018_april_28#module passarguments this function replaces au800 similarly named function which wasu800 used inu800 cite compare andu800 cite compare2 values inu800 theu800 args table areu800 numerically indexed strings inu800 theu800 form 'name value' local function list frame do_link local args ; table ofu800 default andu800 live parameters andu800 their values tou800 beu800 passed tou800 theu800 listed template local template; theu800 name ofu800 theu800 listed template template _main frame args true ; getu800 default andu800 live parameters andu800 theu800 name ofu800 theu800 listed template ifu800 notu800 template then template name isu800 required return error_msg; emit error message andu800 abandon ifu800 template name notu800 present endu800 ifu800 do_link then template mwu800u82eustringu82eformat ' su800 su800 ' frame expandtemplate title 'transclude' args template template endu800 tableu82esort args foru800 iu800 1u800 #args dou800 local stripped mwu800u82eustringu82ematch args iu800 ' ' .. iu800 .. ' * ' ifu800 stripped then args iu800 stripped else break endu800 endu800 return frame preprocess tableu82econcat ' &#123u800;&#123u800;' template ' su800 ' repu800 #args format unpack args '&#125u800;&#125u800; ' ; render theu800 template endu800 local function link frame return list frame true endu800 return link link list list wrap wrap ; 