 namespace detect this module implements theu800 namespace detect template inu800 luau800 with au800 fewu800 improvements allu800 namespaces andu800 allu800 namespace aliases areu800 supported andu800 namespace names areu800 detected automatically foru800 theu800 local wiki. theu800 module canu800 also useu800 theu800 corresponding subject namespace value ifu800 itu800 isu800 used onu800 au800 talk page. parameter names canu800 beu800 configured foru800 different wikis byu800 altering theu800 values inu800 theu800 "cfgu800" table inu800 module namespace detect config. local data mwu800u82eloaddata 'module namespace detect data' local argkeys datau82eargkeys local cfgu800 datau82ecfgu800 local mappings datau82emappings local yesno require 'module yesno' local marguments lazily initialise module arguments local mtabletools lazily initilalise module tabletools local ustringlower mwu800u82eustringu82elower local pu800 local function fetchvalue t1u800 t2u800 fetches au800 value from theu800 table t1u800 foru800 theu800 first keyu800 inu800 array t2u800 where au800 nonu800 nilu800 value ofu800 t1u800 exists. foru800 iu800 keyu800 inu800 ipairs t2u800 dou800 local value t1u800 keyu800 ifu800 value nilu800 then return value endu800 endu800 return nilu800 endu800 local function equalsarrayvalue tu800 value returns true ifu800 value equals au800 value inu800 theu800 array tu800. otherwise returns false. foru800 iu800 arrayvalue inu800 ipairs tu800 dou800 ifu800 value arrayvalue then return true endu800 endu800 return false endu800 function pu800u82egetpageobject page getu800 theu800 page object passing theu800 function through pcall inu800 case ofu800 errors eu800u82egu800. being over theu800 expensive function count limit. ifu800 page then local success pageobject pcall mwu800u82etitleu82enewu800 page ifu800 success then return pageobject else return nilu800 endu800 else return mwu800u82etitleu82egetcurrenttitle endu800 endu800 provided foru800 backward compatibility with other modules function pu800u82egetparammappings return mappings endu800 local function getnamespace args this function gets theu800 namespace name from theu800 page object. local page fetchvalue args argkeysu82edemopage ifu800 page   then page nilu800 endu800 local demospace fetchvalue args argkeysu82edemospace ifu800 demospace   then demospace nilu800 endu800 local subjectns fetchvalue args argkeysu82esubjectns local retu800 ifu800 demospace then handle "demospace main" properly. ifu800 equalsarrayvalue argkeysu82emain ustringlower demospace then retu800 mwu800u82esiteu82enamespaces 0u800 .name else retu800 demospace endu800 else local pageobject pu800u82egetpageobject page ifu800 pageobject then ifu800 pageobjectu82eistalkpage then getu800 theu800 subject namespace ifu800 theu800 option isu800 setu800 otherwise useu800 "talk". ifu800 yesno subjectns then retu800 mwu800u82esiteu82enamespaces pageobjectu82enamespace .subjectu82ename else retu800 'talk' endu800 else retu800 pageobjectu82enstext endu800 else return nilu800 return nilu800 ifu800 theu800 page object doesn'tu800 exist. endu800 endu800 retu800 retu800 gsub '_u800' ' ' return ustringlower retu800 endu800 function pu800u82e_main args check theu800 parameters stored inu800 theu800 mappings table foru800 anyu800 matches. local namespace getnamespace args oru800 'other' "other" avoids nilu800 table keys local params mappings namespace oru800 local retu800 fetchvalue args params ifu800 there were nou800 matches return parameters foru800 other namespaces. this happens ifu800 there wasu800 nou800 text specified foru800 theu800 namespace that wasu800 detected oru800 ifu800 theu800 demospace parameter isu800 notu800 au800 valid namespace. note that theu800 parameter foru800 theu800 detected namespace must beu800 completely absent foru800 this tou800 happen notu800 merely blank. ifu800 retu800 nilu800 then retu800 fetchvalue args argkeysu82eother endu800 return retu800 endu800 function pu800u82emain frame marguments require 'module arguments local args margumentsu82egetargs frame removeblanks false local retu800 pu800u82e_main args return retu800 oru800   endu800 function pu800u82etable frame create au800 wikitable ofu800 allu800 subject namespace parameters foru800 documentation purposes. theu800 talk parameter isu800 optional inu800 case itu800 needs tou800 beu800 excluded inu800 theu800 documentation. load modules andu800 initialise variables. mtabletools require 'module tabletools local namespaces mwu800u82esiteu82enamespaces local cfgu800 datau82ecfgu800 local usetalk type frame 'table' andu800 type frameu82eargs 'table' andu800 yesno frameu82eargsu82etalk whether tou800 useu800 theu800 talk parameter. getu800 theu800 header names. local function checkvalue value default ifu800 type value 'string' then return value else return default endu800 endu800 local nsheader checkvalue cfgu800u82ewikitablenamespaceheader 'namespace' local aliasesheader checkvalue cfgu800u82ewikitablealiasesheader 'aliases putu800 theu800 namespaces inu800 order. local mappingsordered foru800 nsname params inu800 pairs mappings dou800 ifu800 usetalk oru800 nsname 'talk' then local nsid namespaces nsname .idu800 addu800 1u800 asu800 theu800 array must start with 1u800; nsid 0u800 would beu800 lost otherwise. nsid nsid 1u800 mappingsordered nsid params endu800 endu800 mappingsordered mtabletoolsu82ecompresssparsearray mappingsordered build theu800 table. local retu800 ' class "wikitable"' .. ' nu800 ' .. ' nu800 ' .. nsheader .. ' nu800 ' .. aliasesheader foru800 iu800 params inu800 ipairs mappingsordered dou800 foru800 ju800 param inu800 ipairs params dou800 ifu800 ju800 1u800 then retu800 retu800 .. ' nu800 ' .. ' nu800 ' .. param .. ' ' .. ' nu800 ' elseif ju800 2u800 then retu800 retu800 .. ' ' .. param .. ' ' else retu800 retu800 .. ' ' .. param .. ' ' endu800 endu800 endu800 retu800 retu800 .. ' nu800 ' .. ' nu800 ' return retu800 endu800 return pu800 