Difference between revisions of "Module:Namespace detect/config"

From Discordia
Jump to: navigation, search
(Created page with "-------------------------------------------------------------------------------- -- Namespace detect data -- -- This modul...")
 
 
Line 1: Line 1:
 
--------------------------------------------------------------------------------
 
--------------------------------------------------------------------------------
-- Namespace detect data --
+
-- Namespace detect configuration data --
  +
-- --
-- This module holds data for [[Module:Namespace detect]] to be loaded per --
 
-- page, rather than per #invoke, for performance reasons. --
+
-- This module stores configuration data for Module:Namespace detect. Here --
  +
-- you can localise the module to your wiki's language. --
  +
-- --
  +
-- To activate a configuration item, you need to uncomment it. This means --
  +
-- that you need to remove the text "-- " at the start of the line. --
 
--------------------------------------------------------------------------------
 
--------------------------------------------------------------------------------
   
local cfg = require('Module:Namespace detect/config')
+
local cfg = {} -- Don't edit this line.
   
  +
--------------------------------------------------------------------------------
local function addKey(t, key, defaultKey)
 
  +
-- Parameter names --
if key ~= defaultKey then
 
  +
-- These configuration items specify custom parameter names. Values added --
t[#t + 1] = key
 
  +
-- here will work in addition to the default English parameter names. --
end
 
  +
-- To add one extra name, you can use this format: --
end
 
  +
-- --
  +
-- cfg.foo = 'parameter name' --
  +
-- --
  +
-- To add multiple names, you can use this format: --
  +
-- --
  +
-- cfg.foo = {'parameter name 1', 'parameter name 2', 'parameter name 3'} --
  +
--------------------------------------------------------------------------------
   
  +
---- This parameter displays content for the main namespace:
-- Get a table of parameters to query for each default parameter name.
 
  +
-- cfg.main = 'main'
-- 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.
 
   
  +
---- This parameter displays in talk namespaces:
local defaultKeys = {
 
  +
-- cfg.talk = 'talk'
'main',
 
'talk',
 
'other',
 
'subjectns',
 
'demospace',
 
'demopage'
 
}
 
   
  +
---- This parameter displays content for "other" namespaces (namespaces for which
local argKeys = {}
 
  +
---- parameters have not been specified):
for i, defaultKey in ipairs(defaultKeys) do
 
  +
-- cfg.other = 'other'
argKeys[defaultKey] = {defaultKey}
 
end
 
   
  +
---- This parameter makes talk pages behave as though they are the corresponding
for defaultKey, t in pairs(argKeys) do
 
  +
---- subject namespace. Note that this parameter is used with [[Module:Yesno]].
local cfgValue = cfg[defaultKey]
 
  +
---- Edit that module to change the default values of "yes", "no", etc.
local cfgValueType = type(cfgValue)
 
  +
-- cfg.subjectns = 'subjectns'
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
 
   
  +
---- This parameter sets a demonstration namespace:
local function getParamMappings()
 
  +
-- cfg.demospace = 'demospace'
--[[
 
  +
-- Returns a table of how parameter names map to namespace names. The keys
 
  +
---- This parameter sets a specific page to compare:
-- are the actual namespace names, in lower case, and the values are the
 
  +
cfg.demopage = 'page'
-- possible parameter names for that namespace, also in lower case. The
 
  +
-- table entries are structured like this:
 
  +
--------------------------------------------------------------------------------
-- {
 
  +
-- Table configuration --
-- [''] = {'main'},
 
  +
-- These configuration items allow customisation of the "table" function, --
-- ['wikipedia'] = {'wikipedia', 'project', 'wp'},
 
  +
-- used to generate a table of possible parameters in the module --
-- ...
 
  +
-- documentation. --
-- }
 
  +
--------------------------------------------------------------------------------
--]]
 
  +
local mappings = {}
 
  +
---- The header for the namespace column in the wikitable containing the list of
local mainNsName = mw.site.subjectNamespaces[0].name
 
  +
---- possible subject-space parameters.
mainNsName = mw.ustring.lower(mainNsName)
 
  +
-- cfg.wikitableNamespaceHeader = 'Namespace'
mappings[mainNsName] = mw.clone(argKeys.main)
 
  +
mappings['talk'] = mw.clone(argKeys.talk)
 
  +
---- The header for the wikitable containing the list of possible subject-space
for nsid, ns in pairs(mw.site.subjectNamespaces) do
 
  +
---- parameters.
if nsid ~= 0 then -- Exclude main namespace.
 
  +
-- cfg.wikitableAliasesHeader = 'Aliases'
local nsname = mw.ustring.lower(ns.name)
 
  +
local canonicalName = mw.ustring.lower(ns.canonicalName)
 
  +
--------------------------------------------------------------------------------
mappings[nsname] = {nsname}
 
  +
-- End of configuration data --
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
 
   
  +
return cfg -- Don't edit this line.
return {
 
argKeys = argKeys,
 
cfg = cfg,
 
mappings = getParamMappings()
 
}
 

Latest revision as of 18:20, 27 June 2020

Documentation for this module may be created at Module:Namespace detect/config/doc

--------------------------------------------------------------------------------
--                    Namespace detect configuration data                     --
--                                                                            --
-- This module stores configuration data for Module:Namespace detect. Here    --
-- you can localise the module to your wiki's language.                       --
--                                                                            --
-- To activate a configuration item, you need to uncomment it. This means     --
-- that you need to remove the text "-- " at the start of the line.           --
--------------------------------------------------------------------------------

local cfg = {} -- Don't edit this line.

--------------------------------------------------------------------------------
--                              Parameter names                               --
-- These configuration items specify custom parameter names. Values added     --
-- here will work in addition to the default English parameter names.         --
-- To add one extra name, you can use this format:                            --
--                                                                            --
-- cfg.foo = 'parameter name'                                                 --
--                                                                            --
-- To add multiple names, you can use this format:                            --
--                                                                            --
-- cfg.foo = {'parameter name 1', 'parameter name 2', 'parameter name 3'}     --
--------------------------------------------------------------------------------

---- This parameter displays content for the main namespace:
-- cfg.main = 'main'

---- This parameter displays in talk namespaces:
-- cfg.talk = 'talk'

---- This parameter displays content for "other" namespaces (namespaces for which
---- parameters have not been specified):
-- cfg.other = 'other'

---- This parameter makes talk pages behave as though they are the corresponding
---- subject namespace. Note that this parameter is used with [[Module:Yesno]].
---- Edit that module to change the default values of "yes", "no", etc.
-- cfg.subjectns = 'subjectns'

---- This parameter sets a demonstration namespace:
-- cfg.demospace = 'demospace'

---- This parameter sets a specific page to compare:
cfg.demopage = 'page'

--------------------------------------------------------------------------------
--                           Table configuration                              --
-- These configuration items allow customisation of the "table" function,     --
-- used to generate a table of possible parameters in the module              --
-- documentation.                                                             --
--------------------------------------------------------------------------------

---- The header for the namespace column in the wikitable containing the list of
---- possible subject-space parameters.
-- cfg.wikitableNamespaceHeader = 'Namespace'

---- The header for the wikitable containing the list of possible subject-space
---- parameters.
-- cfg.wikitableAliasesHeader = 'Aliases'

--------------------------------------------------------------------------------
--                        End of configuration data                           --
--------------------------------------------------------------------------------

return cfg -- Don't edit this line.