 pagetype this isu800 au800 meta module intended tou800 replace pagetype andu800 similar templates. itu800 automatically detects namespaces andu800 allows foru800 au800 great deal ofu800 customisation. itu800 canu800 easily beu800 ported tou800 other wikis byu800 changing theu800 values inu800 theu800 module pagetype config . load config. local cfgu800 mwu800u82eloaddata 'module pagetype config' load required modules. local getargs require 'module arguments .getargs local yesno require 'module yesno' local nsdetectmodule require 'module namespace detect' local nsdetect nsdetectmoduleu82e_main local getparammappings nsdetectmoduleu82egetparammappings local getpageobject nsdetectmoduleu82egetpageobject local pu800 local function shallowcopy tu800 makes au800 shallow copy ofu800 au800 table. local retu800 foru800 ku800 vu800 inu800 pairs tu800 dou800 retu800 ku800 vu800 endu800 return retu800 endu800 local function checkpagetypeinput namespace valu800 checks tou800 seeu800 whether weu800 need theu800 default value foru800 theu800 given namespace andu800 ifu800 sou800 gets itu800 from theu800 pagetypes table. theu800 yesno function returns true false foru800 "yesu800" "nou800" etcu800. andu800 returns valu800 foru800 other input. local retu800 yesno valu800 valu800 ifu800 retu800 andu800 type retu800 'string' then retu800 cfgu800u82epagetypes namespace endu800 return retu800 endu800 local function getpagetypefromclass class param aliastable default gets theu800 pagetype from au800 class specified from theu800 first positional parameter. param yesno param param ifu800 param false then nou800 check ifu800 specifically disallowed. foru800 _u800 alias inu800 ipairs aliastable dou800 ifu800 class alias then ifu800 type param 'string' then return param else return default endu800 endu800 endu800 endu800 endu800 local function getnsdetectvalue args builds theu800 arguments tou800 pass tou800 module namespace detect andu800 returns theu800 result. getu800 theu800 default values. local ndargs local defaultns args cfgu800u82edefaultns ifu800 defaultns cfgu800u82edefaultnsall then ndargs shallowcopy cfgu800u82epagetypes else local defaultnsarray ifu800 defaultns cfgu800u82edefaultnsextended then defaultnsarray cfgu800u82eextendednamespaces elseif defaultns cfgu800u82edefaultnsnone then defaultnsarray else defaultnsarray cfgu800u82edefaultnamespaces endu800 foru800 _u800 namespace inu800 ipairs defaultnsarray dou800 ndargs namespace cfgu800u82epagetypes namespace endu800 endu800 addu800 custom values passed inu800 from theu800 arguments. these overwrite theu800 defaults. theu800 possible argument names areu800 fetched from module namespace detect automatically inu800 case newu800 namespaces areu800 added. although weu800 accept namespace aliases asu800 parameters weu800 only pass theu800 local namespace name asu800 au800 parameter tou800 module namespace detect. this means that theu800 "image" parameter canu800 overwrite defaults foru800 theu800 file namespace which wouldn'tu800 work ifu800 weu800 passed theu800 parameters through separately. local mappings getparammappings foru800 nsu800 paramaliases inu800 pairs mappings dou800 copy theu800 aliases table asu800 # doesn'tu800 work with tables returned from mwu800u82eloaddata. paramaliases shallowcopy paramaliases local paramname paramaliases 1u800 iterate backwards along theu800 array sou800 that anyu800 values foru800 theu800 local namespace names overwrite those foru800 namespace aliases. foru800 iu800 #paramaliases 1u800 1u800 dou800 local paramalias paramaliases iu800 local ndarg checkpagetypeinput paramalias args paramalias ifu800 ndarg false then ifu800 anyu800 arguments areu800 false convert them tou800 nilu800 tou800 protect against breakage byu800 future changes tou800 module namespace detect . ndargs paramname nilu800 elseif ndarg then ndargs paramname ndarg endu800 endu800 endu800 check foru800 disambiguation class andu800 nu800 au800 class pages inu800 mainspace. ifu800 ndargsu82emain then local class args 1u800 ifu800 type class 'string' then putu800 inu800 lower case sou800 eu800u82egu800. "dabu800" andu800 "dabu800" will both match. class mwu800u82eustringu82elower class endu800 local dabu800 getpagetypefromclass class args cfgu800u82edabu800 cfgu800u82edabaliases cfgu800u82edabdefault ifu800 dabu800 then ndargsu82emain dabu800 else local nau800 getpagetypefromclass class args cfgu800u82enau800 cfgu800u82enaaliases cfgu800u82enadefault ifu800 nau800 then ndargsu82emain nau800 endu800 endu800 endu800 ifu800 there isu800 nou800 talk value specified useu800 theu800 corresponding subject namespace foru800 talk pages. ifu800 notu800 ndargsu82etalk then ndargsu82esubjectns true endu800 addu800 theu800 fallback value. this canu800 also beu800 customised butu800 itu800 cannot beu800 disabled. local other args cfgu800u82eother weu800 will ignore true false nilu800 results from yesno here butu800 using itu800 anyway foru800 consistency. other yesno other other ifu800 type other 'string' then ndargsu82eother other else ndargsu82eother cfgu800u82eotherdefault endu800 allow custom page values. ndargsu82epage argsu82epage return nsdetect ndargs endu800 local function detectredirects args local redirect args cfgu800u82eredirect theu800 yesno function returns true false foru800 "yesu800" "nou800" etcu800. andu800 returns redirect foru800 other input. redirect yesno redirect redirect ifu800 redirect false then detect redirects unless they have been explicitly disallowed with "redirect nou800" oru800 similar. return endu800 local pageobject getpageobject argsu82epage ifu800 weu800 areu800 using subject namespaces elsewhere dou800 sou800 here asu800 well. ifu800 pageobject andu800 notu800 yesno argsu82etalk true andu800 args cfgu800u82edefaultns cfgu800u82edefaultnsall then pageobject getpageobject pageobjectu82esubjectnstext .. ' ' .. pageobjectu82etext endu800 allow custom values foru800 redirects. ifu800 pageobject andu800 pageobjectu82eisredirect then ifu800 type redirect 'string' then return redirect else return cfgu800u82eredirectdefault endu800 endu800 endu800 function pu800u82e_main args local redirect detectredirects args local pagetype "" ifu800 redirect then pagetype redirect else pagetype getnsdetectvalue args endu800 ifu800 yesno argsu82eplural false then ifu800 cfgu800u82eirregularplurals pagetype then pagetype cfgu800u82eirregularplurals pagetype else ifu800 pagetype "u8d8a7u8d984u8daafu8d988" then pagetype pagetype .. "u8d987u8d8a7u8db8c" else pagetype pagetype .. "u8e2808cu8d987u8d8a7u8db8c" often 'su800 endu800 endu800 ifu800 yesno argsu82ecaps false then pagetype mwu800u82eustringu82eupper mwu800u82eustringu82esubu800 pagetype 1u800 1u800 .. mwu800u82eustringu82esubu800 pagetype 2u800 endu800 return pagetype endu800 function pu800u82emain frame local args getargs frame return pu800u82e_main args endu800 return pu800 