Module:Namespace detect/data: Difference between revisions

Jump to navigation Jump to search
give the argKeys table global scope so that getParamMappings can access it without having to process the cfg table again
(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)
(give the argKeys table global scope so that getParamMappings can access it without having to process the cfg table again)
Line 13:
end
 
-- ReturnsGet a table of parameters to query for each default parameter name.
local function getArgKeys()
-- This allows wikis to customise parameter names in the cfg table while
-- Returns a table of parameters to query for each default parameter name.
-- Thisensuring allowsthat wikis to customisedefault parameter names inwill thealways work. The cfg table while
-- values can be added as a string, or as an array of strings.
-- 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 cfgValueTypecfgValue = type(cfgValue)cfg[defaultKey]
if local cfgValueType == 'string' thentype(cfgValue)
elseif if cfgValueType == 'tablestring' then
addKey(t, cfgValue, defaultKey)
localaddKey(t, cfgValue, = cfg[defaultKey])
elseif cfgValueType == 'table' then
elseif cfgValueType == 'table' then
for i, key in ipairs(cfgValue) do
addKey(tfor i, key, defaultKeyin ipairs(cfgValue) do
addKey(t, cfgValuekey, defaultKey)
end
end
cfg[defaultKey] = nil -- Free the cfg value as we don't need it any more.
end
cfg[defaultKey] = nil -- Free the cfg value as we don't need it any more.
return argKeys
end
 
Line 55 ⟶ 54:
local ustringLower = mw.ustring.lower
local tinsert = table.insert
local talkclone = cfgmw.talkclone
local subjectNamespaces = mw.site.subjectNamespaces
local talk = cfg.talk
local mappings = {}
mappings[ustringLower(subjectNamespaces[0].name)] = {cfgclone(argKeys.main})
mappings['talk'] = {clone(argKeys.talk})
for nsid, ns in pairs(subjectNamespaces) do
if nsid ~= 0 then -- Exclude main namespace.
Line 77 ⟶ 76:
 
return {
argKeys = getArgKeys()argKeys,
cfg = cfg,
mappings = getParamMappings()
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu