Module:Namespace detect/data: Difference between revisions
From the Audiovisual Identity Database, the motion graphics museum
Content deleted Content added
imported>Dreamcast99 Created page with "-------------------------------------------------------------------------------- -- Namespace detect data -- -- This modul..." |
Created page with "-- This module contains the blacklist used by Module:Category handler. -- Pages that match Lua patterns in this list will not be categorised unless -- categorisation is ex..." |
||
Line 1: | Line 1: | ||
-- This module contains the blacklist used by [[Module:Category handler]]. |
|||
-------------------------------------------------------------------------------- |
|||
-- Pages that match Lua patterns in this list will not be categorised unless |
|||
-- Namespace detect data -- |
|||
-- categorisation is explicitly requested. |
|||
-- This module holds data for [[Module:Namespace detect]] to be loaded per -- |
|||
-- page, rather than per #invoke, for performance reasons. -- |
|||
-------------------------------------------------------------------------------- |
|||
⚫ | |||
local cfg = require('Module:Namespace detect/config') |
|||
'^Main Page$', -- don't categorise the main page. |
|||
-- Don't categorise the following pages or their subpages. |
|||
local function addKey(t, key, defaultKey) |
|||
-- "%f[/\0]" matches if the next character is "/" or the end of the string. |
|||
if key ~= defaultKey then |
|||
'^Wikipedia:Cascade%-protected items%f[/\0]', |
|||
t[#t + 1] = key |
|||
'^User:UBX%f[/\0]', -- The userbox "template" space. |
|||
end |
|||
'^User talk:UBX%f[/\0]', |
|||
end |
|||
-- Don't categorise subpages of these pages, but allow |
|||
-- Get a table of parameters to query for each default parameter name. |
|||
-- categorisation of the base page. |
|||
-- This allows wikis to customise parameter names in the cfg table while |
|||
'^Wikipedia:Template index/.*$', |
|||
-- ensuring that default parameter names will always work. The cfg table |
|||
-- values can be added as a string, or as an array of strings. |
|||
-- Don't categorise archives. |
|||
local defaultKeys = { |
|||
' |
'/[aA]rchive', |
||
"^Wikipedia:Administrators' noticeboard/IncidentArchive%d+$", |
|||
'talk', |
|||
'other', |
|||
'subjectns', |
|||
'demospace', |
|||
'demopage' |
|||
} |
|||
local argKeys = {} |
|||
for i, defaultKey in ipairs(defaultKeys) do |
|||
argKeys[defaultKey] = {defaultKey} |
|||
end |
|||
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 |
|||
local function getParamMappings() |
|||
--[[ |
|||
-- Returns a table of how parameter names map to namespace names. The keys |
|||
-- are the actual namespace names, in lower case, and the values are the |
|||
-- possible parameter names for that namespace, also in lower case. The |
|||
-- table entries are structured like this: |
|||
-- { |
|||
-- [''] = {'main'}, |
|||
-- ['wikipedia'] = {'wikipedia', 'project', 'wp'}, |
|||
-- ... |
|||
-- } |
|||
--]] |
|||
local mappings = {} |
|||
local mainNsName = mw.site.subjectNamespaces[0].name |
|||
mainNsName = mw.ustring.lower(mainNsName) |
|||
mappings[mainNsName] = mw.clone(argKeys.main) |
|||
mappings['talk'] = mw.clone(argKeys.talk) |
|||
for nsid, ns in pairs(mw.site.subjectNamespaces) do |
|||
if nsid ~= 0 then -- Exclude main namespace. |
|||
local nsname = mw.ustring.lower(ns.name) |
|||
local canonicalName = mw.ustring.lower(ns.canonicalName) |
|||
mappings[nsname] = {nsname} |
|||
if canonicalName ~= nsname then |
|||
table.insert(mappings[nsname], canonicalName) |
|||
end |
|||
for _, alias in ipairs(ns.aliases) do |
|||
table.insert(mappings[nsname], mw.ustring.lower(alias)) |
|||
end |
|||
end |
|||
end |
|||
return mappings |
|||
end |
|||
⚫ | |||
argKeys = argKeys, |
|||
cfg = cfg, |
|||
mappings = getParamMappings() |
|||
} |
} |
Revision as of 00:31, 4 June 2020
Documentation for this module may be created at Module:Namespace detect/data/doc
-- This module contains the blacklist used by [[Module:Category handler]].
-- Pages that match Lua patterns in this list will not be categorised unless
-- categorisation is explicitly requested.
return {
'^Main Page$', -- don't categorise the main page.
-- Don't categorise the following pages or their subpages.
-- "%f[/\0]" matches if the next character is "/" or the end of the string.
'^Wikipedia:Cascade%-protected items%f[/\0]',
'^User:UBX%f[/\0]', -- The userbox "template" space.
'^User talk:UBX%f[/\0]',
-- Don't categorise subpages of these pages, but allow
-- categorisation of the base page.
'^Wikipedia:Template index/.*$',
-- Don't categorise archives.
'/[aA]rchive',
"^Wikipedia:Administrators' noticeboard/IncidentArchive%d+$",
}