「モジュール:Namespace detect」の版間の差分

提供: ひつじ小屋別館2代目
移動先: 案内検索
(1版)
(fix the education program namespace bug by replacing underscores with spaces in the getNamespace function)
1行目: 1行目:
----------------------------------------------------------------------
+
----------------------------------------------------------------------------------------------------
--                                                                 --
+
--                                                                                               --
--                       NAMESPACE DETECT                         --
+
--                                           NAMESPACE DETECT                                     --
--                                                                 --
+
--                                                                                               --
--      This module implements the {{namespace detect}} template   --
+
--      This module implements the {{namespace detect}} template in Lua, with a few              --
--      in Lua, with a few improvements: all namespaces and all     --
+
--      improvements: all namespaces and all namespace aliases are supported, and namespace       --
--      namespace aliases are supported, and namespace names are    --
+
--      names are detected automatically for the local wiki. The module can also use the          --
--      detected automatically for the local wiki. Function names   --
+
--      corresponding subject namespace value if it is used on a talk page. Parameter names       --
--      can be configured for different wikis by altering the       --
+
--      can be configured for different wikis by altering the values in the "cfg" table.         --
--      values in the "cfg" table.                                 --
+
--                                                                                               --
--                                                                 --
+
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------
 
  
----------------------------------------------------------------------
+
----------------------------------------------------------------------------------------------------
--                     Configuration data                         --
+
--                                         Configuration data                                   --
--      Language-specific parameter names can be set here.         --
+
--      Language-specific parameter names can be set here.                                       --
----------------------------------------------------------------------
+
----------------------------------------------------------------------------------------------------
  
 
local cfg = {}
 
local cfg = {}
  
-- The name for the parameter to display content for the main namespace:
+
-- This parameter displays content for the main namespace:
 
cfg.main = 'main'
 
cfg.main = 'main'
  
-- The name for the parameter to display content in talk namespaces:
+
-- This parameter displays in talk namespaces:
 
cfg.talk = 'talk'
 
cfg.talk = 'talk'
  
-- The name for the parameter to display content for "other" namespaces
+
-- This parameter displays content for "other" namespaces (namespaces for which
-- (namespaces for which parameters have not been specified, or for when
+
-- parameters have not been specified, or for when cfg.demospace is set to cfg.other):
-- cfg.demospace is set to cfg.other):
 
 
cfg.other = 'other'
 
cfg.other = 'other'
  
-- The name for the parameter to set a demonstration namespace:
+
-- 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'
 
cfg.demospace = 'demospace'
  
-- The name for the parameter to set a specific page to compare:
+
-- This parameter sets a specific page to compare:
 
cfg.page = 'page'
 
cfg.page = 'page'
  
-- The header for the namespace column in the wikitable containing the  
+
-- The header for the namespace column in the wikitable containing the list of possible subject-space parameters.
-- list of possible subject-space parameters.
 
 
cfg.wikitableNamespaceHeader = 'Namespace'
 
cfg.wikitableNamespaceHeader = 'Namespace'
  
-- The header for the wikitable containing the list of possible
+
-- The header for the wikitable containing the list of possible subject-space parameters.
-- subject-space parameters.
 
 
cfg.wikitableAliasesHeader = 'Aliases'
 
cfg.wikitableAliasesHeader = 'Aliases'
  
----------------------------------------------------------------------
+
----------------------------------------------------------------------------------------------------
--                     End configuration data                       --
+
--                                       End configuration data                                   --
----------------------------------------------------------------------
+
----------------------------------------------------------------------------------------------------
  
----------------------------------------------------------------------
+
local yesno = require('Module:Yesno')
--                        Global functions                          --
 
--      The following functions are global, because we want them    --
 
--      to be accessible from other Lua modules called using        --
 
--      require().                                                  --
 
----------------------------------------------------------------------
 
  
-- Declare the table of functions to return.
 
 
local p = {}
 
local p = {}
  
-- Get the page object. This will return the page object for the page
+
function p.getPageObject(page)
-- specified, or nil if there are errors in the title or if the
+
-- Get the page object, passing the function through pcall in case we are over the expensive function count limit.
-- expensive function count has been exceeded.
+
if page then
function p.getPageObject( page )
+
local noError, pageObject = pcall(mw.title.new, page)
    -- Get the title object for args.page if it is specified. Otherwise
+
if not noError then
    -- get the title object for the current page.
+
return nil
    if page then
+
else
        -- Get the page object, passing the function through pcall  
+
return pageObject
        -- in case we are over the expensive function count limit.
+
end
        local noError, pageObject = pcall(mw.title.new, page)
+
else
        if not noError then
+
return mw.title.getCurrentTitle()
            return nil
+
end
        else
 
            return pageObject
 
        end
 
    else
 
        return mw.title.getCurrentTitle()
 
    end  
 
 
end
 
end
  
--[[ 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' }
 
    }
 
]]
 
 
function p.getParamMappings()
 
function p.getParamMappings()
    local mappings = {}
+
--[[ Returns a table of how parameter names map to namespace names. The keys are the actual namespace
    mappings[mw.ustring.lower( mw.site.namespaces[0].name )] = { cfg.main }
+
  names, in lower case, and the values are the possible parameter names for that namespace, also in
    mappings[cfg.talk] = { cfg.talk }
+
  lower case. The table entries are structured like this:
    for nsid, ns in pairs( mw.site.subjectNamespaces ) do
+
{
        if nsid ~= 0 then -- Exclude main namespace.
+
[''] = {'main'},
            local nsname = mw.ustring.lower( ns.name )
+
['wikipedia'] = {'wikipedia', 'project', 'wp'},
            local canonicalName = mw.ustring.lower( ns.canonicalName )
+
...
            mappings[nsname] = { nsname }
+
}
            if canonicalName ~= nsname then
+
]]
                table.insert( mappings[nsname], canonicalName )
+
local mappings = {}
            end
+
mappings[mw.ustring.lower(mw.site.namespaces[0].name)] = {cfg.main}
            for _, alias in ipairs( ns.aliases ) do
+
mappings[cfg.talk] = {cfg.talk}
                table.insert( mappings[nsname], mw.ustring.lower( alias ) )
+
for nsid, ns in pairs(mw.site.subjectNamespaces) do
            end
+
if nsid ~= 0 then -- Exclude main namespace.
        end
+
local nsname = mw.ustring.lower(ns.name)
    end
+
local canonicalName = mw.ustring.lower(ns.canonicalName)
    return mappings
+
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
 
end
  
--[[ Create a wikitable of all subject namespace parameters, for documentation
+
local function getNamespace(args)
  purposes. Talk is excluded, as it should usually be treated separately in
+
-- Gets the namespace name from the page object.
  the documentation.
+
local page = args[cfg.page]
]]
+
local demospace = args[cfg.demospace]
function p.table()
+
local subjectns = args[cfg.subjectns]
    -- Get the parameter mappings.
+
local ret
    local mappings = p.getParamMappings()
+
if demospace then
   
+
-- Handle "demospace = main" properly.
    -- Start the wikitable.
+
if mw.ustring.lower(demospace) == cfg.main then
    local ret = '{| class="wikitable"'
+
ret = mw.site.namespaces[0].name
        .. '\n|-'
+
else
        .. '\n! ' .. cfg.wikitableNamespaceHeader
+
ret = demospace
        .. '\n! ' .. cfg.wikitableAliasesHeader
+
end
   
+
else
    -- Generate the row for the main namespace, as we want this
+
local pageObject = p.getPageObject(page)
    -- to be first in the list.
+
if pageObject then
    ret = ret .. '\n|-'
+
if pageObject.isTalkPage then
        .. '\n| <code>' .. cfg.main .. '</code>'
+
-- If cfg.subjectns is set, get the subject namespace, otherwise use cfg.talk.
        .. '\n|'
+
if yesno(subjectns) then
       
+
ret = mw.site.namespaces[pageObject.namespace].subject.name
    -- Enclose all parameter names in <code> tags.
+
else
    for ns, params in pairs( mappings ) do
+
ret = cfg.talk
        if ns ~= mw.site.namespaces[0].name then
+
end
            for i, param in ipairs( params ) do
+
else
                mappings[ns][i] = '<code>' .. param .. '</code>'
+
ret = pageObject.nsText
            end
+
end
        end
+
else
    end
+
return nil -- return nil if the page object doesn't exist.
   
+
end
    -- Generate the other wikitable rows.
+
end
    for ns, params in pairs( mappings ) do
+
ret = mw.ustring.gsub(ret, '_', ' ')
        if ns ~= mw.site.namespaces[0].name then -- Ignore the main namespace.
+
return mw.ustring.lower(ret)
            ret = ret .. '\n|-'
 
                .. '\n| ' .. params[1]
 
                .. '\n| ' .. table.concat( params, ', ', 2 )
 
        end
 
    end
 
   
 
    -- End the wikitable.
 
    ret = ret .. '\n|-'
 
        .. '\n|}'
 
   
 
    return ret
 
 
end
 
end
  
----------------------------------------------------------------------
+
function p._main(args)
--                         Local functions                          --
+
-- Get the namespace to compare the parameters to, and the parameter mapping table.
--      The following are internal functions, which we do not want  --
+
local namespace = getNamespace(args)
--      to be accessible from other modules.                       --
+
local mappings = p.getParamMappings()
----------------------------------------------------------------------
+
-- Check for any matches in the namespace arguments. The order we check them doesn't matter,
 
+
-- as there can only be one match.
-- Gets the namespace name to compare to the arguments. The returned value
+
for ns, params in pairs(mappings) do
-- is lower-case.
+
if ns == namespace then
local function getNamespace( page, demospace )
+
-- Check all aliases for matches. The default local namespace is checked first, as
    local ret
+
-- {{namespace detect}} checked these before alias names.
    if demospace then
+
for _, param in ipairs(params) do
        -- Handle "demospace = main" properly.
+
if args[param] ~= nil then
        if mw.ustring.lower( demospace ) == cfg.main then
+
return args[param]
            ret = mw.site.namespaces[0].name
+
end
        else
+
end
            ret = demospace
+
end
        end
+
end
    else
+
-- If there were no matches, return parameters for other namespaces. This happens if there
        local pageObject = p.getPageObject( page )
+
-- was no text specified for the namespace that was detected or if the demospace parameter
        if pageObject then
+
-- is not a valid namespace. Note that the parameter for the detected namespace must be
            if pageObject.isTalkPage then
+
-- completely absent for this to happen, not merely blank.
                -- {{namespace detect}} uses the same value for all talk
+
if args[cfg.other] ~= nil then
                -- namespaces, so that's what the module should do too.
+
return args[cfg.other]
                ret = cfg.talk
+
end
            else
 
                ret = pageObject.nsText
 
            end
 
        else
 
            return nil -- return nil if the page object doesn't exist.
 
        end
 
    end
 
    return mw.ustring.lower(ret)
 
 
end
 
end
  
-- Compare the namespace found with the parameters that have been
+
function p.main(frame)
-- specified, and return content of the appropriate parameter.
+
-- If called via #invoke, use the args passed into the invoking template, or the args
local function compare( args )
+
-- passed to #invoke if any exist. Otherwise assume args are being passed directly in.
    -- Get the namespace to compare the parameters to, and the parameter
+
local origArgs
    -- mapping table.
+
if frame == mw.getCurrentFrame() then
    local namespace = getNamespace( args[cfg.page], args[cfg.demospace] )
+
origArgs = frame:getParent().args
    local mappings = p.getParamMappings()
+
for k, v in pairs(frame.args) do
   
+
origArgs = frame.args
    -- Check for any matches in the namespace arguments. The order we check
+
break
    -- them doesn't matter, as there can only be one match.
+
end
    for ns, params in pairs( mappings ) do
+
else
        if ns == namespace then
+
origArgs = frame
            -- Check all aliases for matches. The default local namespace is
+
end
            -- checked first, as {{namespace detect}} checked these before
+
-- Trim whitespace and remove blank arguments for demospace and page parameters.
            -- alias names.
+
local args = {}
            for _, param in ipairs( params ) do
+
for k, v in pairs(origArgs) do
                if args[param] then
+
if type(v) == 'string' then
                    return args[param]
+
v = mw.text.trim(v) -- Trim whitespace.
                end
+
end
            end
+
if k == cfg.demospace or k == cfg.page then
        end
+
if v ~= '' then
    end
+
args[k] = v
   
+
end
    -- If there were no matches, return parameters for other namespaces.  
+
else
    -- This happens if there was no text specified for the namespace that
+
args[k] = v
    -- was detected or if the demospace parameter is not a valid namespace.
+
end
    -- Note that the parameter for the detected namespace must be completely
+
end
    -- absent for this to happen, not merely blank.
+
return p._main(args)
    if args[cfg.other] then
 
        return args[cfg.other]
 
    end
 
 
end
 
end
  
----------------------------------------------------------------------
+
function p.table(frame)
--                             Main function                        --
+
--[[ Create a wikitable of all subject namespace parameters, for documentation purposes. The talk
--      This is the function that will be most used. It processes  --
+
  parameter is optional, in case it needs to be excluded in the documentation.
--      the arguments and calls the compare() function. It is      --
+
]]
--     global, but is put down here as it depends on the other    --
+
local useTalk = type(frame) == 'table' and type(frame.args) == 'table' and frame.args.talk == 'yes' -- Whether to use the talk parameter.
--     local in order for it to work.                             --
+
local mappings = p.getParamMappings()
----------------------------------------------------------------------
+
-- Start the wikitable.
 
+
local ret = '{| class="wikitable"'
function p.main(frame)
+
.. '\n|-'
    -- If called via #invoke, use the args passed into the invoking
+
.. '\n! ' .. cfg.wikitableNamespaceHeader
    -- template, or the args passed to #invoke if any exist. Otherwise
+
.. '\n! ' .. cfg.wikitableAliasesHeader
    -- assume args are being passed directly in.
+
    local origArgs
+
-- Generate the row for the main namespace, as we want this to be first in the list.
    if frame == mw.getCurrentFrame() then
+
ret = ret .. '\n|-'
        origArgs = frame:getParent().args
+
.. '\n| <code>' .. cfg.main .. '</code>'
        for k, v in pairs( frame.args ) do
+
.. '\n|'
            origArgs = frame.args
+
if useTalk then
            break
+
ret = ret .. '\n|-'
        end
+
.. '\n| <code>' .. cfg.talk .. '</code>'
    else
+
.. '\n|'
        origArgs = frame
+
end
    end
+
-- Enclose all parameter names in <code> tags.
   
+
for ns, params in pairs(mappings) do
    -- Trim whitespace and remove blank arguments for demospace and
+
if ns ~= mw.site.namespaces[0].name then
    -- page parameters.
+
for i, param in ipairs(params) do
    local args = {}
+
mappings[ns][i] = '<code>' .. param .. '</code>'
    for k, v in pairs(origArgs) do
+
end
        v = mw.text.trim(v) -- Trim whitespace.
+
end
        if k == cfg.demospace or k == cfg.page then
+
end
            if v ~= '' then
+
-- Generate the other wikitable rows.
                args[k] = v
+
for ns, params in pairs(mappings) do
            end
+
if ns ~= mw.site.namespaces[0].name then -- Ignore the main namespace.
        else
+
ret = ret .. '\n|-'
            args[k] = v
+
.. '\n| ' .. params[1]
        end
+
.. '\n| ' .. table.concat(params, ', ', 2)
    end
+
end
   
+
end
    return compare(args)
+
-- End the wikitable.
 +
ret = ret .. '\n|-'
 +
.. '\n|}'
 +
return ret
 
end
 
end
  
 
return p
 
return p

2013年10月28日 (月) 16:47時点における版

This module allows you to output different text depending on the namespace that a given page is in. It is a Lua implementation of the {{namespace detect}} template, with a few improvements: all namespaces and all namespace aliases are supported, and namespace names are detected automatically for the local wiki.

Usage

{{#invoke: Namespace detect | main
| page              = <!-- page to detect namespace for, if not the current page -->
| main              = <!-- text to return for the main namespace -->
| talk              = <!-- text to return for talk namespaces -->

<!-- text to return for specific subject namespaces -->
| portal            = 
| category          = 
| user 	            = 
| wikipedia         = 
| wp                = 
| education program = 
| mediawiki         = 
| book              = 
| timedtext         = 
| template          = 
| special           = 
| media             = 
| file              = 
| image             = 
| help 	            = 
| module            = 

| other             = <!-- text to return for unspecified namespaces -->
| demospace         = <!-- namespace to display text for -->
}}

Parameters

  • page - specifies a page to detect the namespace of. If not specified, and if the |demospace= parameter is not set, then the module uses the current page.
  • main - text to return if the page is in the main namespace.
  • talk - text to return if the page is in a talk namespace. This can be any talk namespace - it will match any of "Talk:", "Wikipedia talk:", "User talk:", etc.
  • Subject namespace parameters, e.g. wikipedia, user, file... - the text to return if the page is in the corresponding namespace. This module accepts all subject namespaces as parameters, including namespace aliases and virtual namespaces. See below for a list of supported values.
  • other - text to return if no parameters for the page's namespace were specified. This text is also returned if |demospace= is set to an invalid namespace value.
  • demospace - force the module to behave as if the page was in the specified namespace. Often used for demonstrations.

Namespace parameters

Possible values for subject namespace parameters are as follows:

Lua エラー package.lua 内、80 行目: module 'Module:TableTools' not found

Porting to different wikis

This module is designed to be portable. To use it on a different wiki, all you need to do is to change the values in the "cfg" table.


----------------------------------------------------------------------------------------------------
--                                                                                                --
--                                           NAMESPACE DETECT                                     --
--                                                                                                --
--      This module implements the {{namespace detect}} template in Lua, with a few               --
--      improvements: all namespaces and all namespace aliases are supported, and namespace       --
--      names are detected automatically for the local wiki. The module can also use the          --
--      corresponding subject namespace value if it is used on a talk page. Parameter names       --
--      can be configured for different wikis by altering the values in the "cfg" table.          --
--                                                                                                --
----------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------
--                                          Configuration data                                    --
--      Language-specific parameter names can be set here.                                        --
----------------------------------------------------------------------------------------------------

local cfg = {}

-- 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, or for when cfg.demospace is set to cfg.other):
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.page = 'page'

-- 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 configuration data                                   --
----------------------------------------------------------------------------------------------------

local yesno = require('Module:Yesno')

local p = {}

function p.getPageObject(page)
	-- Get the page object, passing the function through pcall in case we are over the expensive function count limit.
	if page then
		local noError, pageObject = pcall(mw.title.new, page)
		if not noError then
			return nil
		else
			return pageObject
		end
	else
		return mw.title.getCurrentTitle()
	end
end

function p.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 = {}
	mappings[mw.ustring.lower(mw.site.namespaces[0].name)] = {cfg.main}
	mappings[cfg.talk] = {cfg.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

local function getNamespace(args)
	-- Gets the namespace name from the page object.
	local page = args[cfg.page]
	local demospace = args[cfg.demospace]
	local subjectns = args[cfg.subjectns]
	local ret
	if demospace then
		-- Handle "demospace = main" properly.
		if mw.ustring.lower(demospace) == cfg.main then
			ret = mw.site.namespaces[0].name
		else
			ret = demospace
		end
	else
		local pageObject = p.getPageObject(page)
		if pageObject then
			if pageObject.isTalkPage then
				-- If cfg.subjectns is set, get the subject namespace, otherwise use cfg.talk.
				if yesno(subjectns) then
					ret = mw.site.namespaces[pageObject.namespace].subject.name
				else
					ret = cfg.talk
				end
			else
				ret = pageObject.nsText
			end
		else
			return nil -- return nil if the page object doesn't exist.
		end
	end
	ret = mw.ustring.gsub(ret, '_', ' ')
	return mw.ustring.lower(ret)
end

function p._main(args)
	-- Get the namespace to compare the parameters to, and the parameter mapping table.
	local namespace = getNamespace(args)
	local mappings = p.getParamMappings()
	-- Check for any matches in the namespace arguments. The order we check them doesn't matter,
	-- as there can only be one match.
	for ns, params in pairs(mappings) do
		if ns == namespace then
			-- Check all aliases for matches. The default local namespace is checked first, as
			-- {{namespace detect}} checked these before alias names.
			for _, param in ipairs(params) do
				if args[param] ~= nil then
					return args[param]
				end
			end
		end
	end
	-- If there were no matches, return parameters for other namespaces. This happens if there
	-- was no text specified for the namespace that was detected or if the demospace parameter
	-- is not a valid namespace. Note that the parameter for the detected namespace must be
	-- completely absent for this to happen, not merely blank.
	if args[cfg.other] ~= nil then
		return args[cfg.other]
	end
end

function p.main(frame)
	-- If called via #invoke, use the args passed into the invoking template, or the args
	-- passed to #invoke if any exist. Otherwise assume args are being passed directly in.
	local origArgs
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
		for k, v in pairs(frame.args) do
			origArgs = frame.args
			break
		end
	else
		origArgs = frame
	end
	-- Trim whitespace and remove blank arguments for demospace and page parameters.
	local args = {}
	for k, v in pairs(origArgs) do
		if type(v) == 'string' then
			v = mw.text.trim(v) -- Trim whitespace.
		end
		if k == cfg.demospace or k == cfg.page then
			if v ~= '' then
				args[k] = v
			end
		else
			args[k] = v
		end
	end
	return p._main(args)
end

function p.table(frame)
	--[[ Create a wikitable of all subject namespace parameters, for documentation purposes. The talk 
	  parameter is optional, in case it needs to be excluded in the documentation.
	]]
	local useTalk = type(frame) == 'table' and type(frame.args) == 'table' and frame.args.talk == 'yes' -- Whether to use the talk parameter.
	local mappings = p.getParamMappings()
	-- Start the wikitable.
	local ret = '{| class="wikitable"'
		.. '\n|-'
		.. '\n! ' .. cfg.wikitableNamespaceHeader
		.. '\n! ' .. cfg.wikitableAliasesHeader
	
	-- Generate the row for the main namespace, as we want this to be first in the list.
	ret = ret .. '\n|-'
		.. '\n| <code>' .. cfg.main .. '</code>'
		.. '\n|'
	if useTalk then
		ret = ret .. '\n|-'
			.. '\n| <code>' .. cfg.talk .. '</code>'
			.. '\n|'
	end
	-- Enclose all parameter names in <code> tags.
	for ns, params in pairs(mappings) do
		if ns ~= mw.site.namespaces[0].name then
			for i, param in ipairs(params) do
				mappings[ns][i] = '<code>' .. param .. '</code>'
			end
		end
	end
	-- Generate the other wikitable rows.
	for ns, params in pairs(mappings) do
		if ns ~= mw.site.namespaces[0].name then -- Ignore the main namespace.
			ret = ret .. '\n|-'
				.. '\n| ' .. params[1]
				.. '\n| ' .. table.concat(params, ', ', 2)
		end
	end
	-- End the wikitable.
	ret = ret .. '\n|-'
		.. '\n|}'
	return ret
end

return p