Module:Namespace detect/data: Difference between revisions

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
(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)
Line 6:
 
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()
Line 42 ⟶ 76:
end
 
return {
return {cfg = cfg, mappings = getParamMappings()}
argKeys = getArgKeys(),
cfg = cfg,
return {cfg = cfg, mappings = getParamMappings()}
}
Anonymous user