Modul:Namespace detect/data: Unterschied zwischen den Versionen
Modul:Namespace detect/data (Quelltext anzeigen)
Version vom 22. März 2014, 07:41 Uhr
, vor 11 Jahrenadd a getArgKeys function, so that we can have multiple keys for each argument (helpful for localisation) and so that we only have to create that table once per page
(Undid revision 600634263 by Jackmcbarn (talk): Oh, this seems to have been for performance. Still not sure if it's a good idea, but will leave for now) |
(add a getArgKeys function, so that we can have multiple keys for each argument (helpful for localisation) and so that we only have to create that table once per page) |
||
| Zeile 6: | Zeile 6: | ||
local cfg = require('Module:Namespace detect/config') | local cfg = require('Module:Namespace detect/config') | ||
local function addKey(t, key, defaultKey) | |||
if key ~= defaultKey then | |||
t[#t + 1] = key | |||
end | |||
end | |||
local function getArgKeys() | |||
-- Returns a table of parameters to query for each default parameter name. | |||
-- This allows wikis to customise parameter names in the cfg table while | |||
-- ensuring that default parameter names will always work. The cfg table | |||
-- values can be added as a string, or as an array of strings. | |||
local argKeys = { | |||
main = {'main'}, | |||
talk = {'talk'}, | |||
other = {'other'}, | |||
subjectns = {'subjectns'}, | |||
demospace = {'demospace'}, | |||
page = {'page'} | |||
} | |||
for defaultKey, t in pairs(argKeys) do | |||
local cfgValue = cfg[defaultKey] | |||
local cfgValueType = type(cfgValue) | |||
if cfgValueType == 'string' then | |||
addKey(t, cfgValue, defaultKey) | |||
elseif cfgValueType == 'table' then | |||
for i, key in ipairs(cfgValue) do | |||
addKey(t, key, defaultKey) | |||
end | |||
end | |||
cfg[defaultKey] = nil -- Free the cfg value as we don't need it any more. | |||
end | |||
return argKeys | |||
end | |||
local function getParamMappings() | local function getParamMappings() | ||
| Zeile 42: | Zeile 76: | ||
end | end | ||
return {cfg = cfg, mappings = getParamMappings()} | return { | ||
argKeys = getArgKeys(), | |||
cfg = cfg, | |||
mappings = getParamMappings() | |||
} | |||