https://sarkarverse.org/index.php?title=Module:Pagetype&feed=atom&action=historyModule:Pagetype - Revision history2024-03-28T11:37:48ZRevision history for this page on the wikiMediaWiki 1.39.0https://sarkarverse.org/index.php?title=Module:Pagetype&diff=25811&oldid=prevT12: 1 revision2014-06-13T19:39:40Z<p>1 revision</p>
<p><b>New page</b></p><div>--------------------------------------------------------------------------------<br />
-- --<br />
-- PAGETYPE --<br />
-- --<br />
-- This is a meta-module intended to replace {{pagetype}} and similar --<br />
-- templates. It automatically detects namespaces, and allows for a --<br />
-- great deal of customisation. It can easily be ported to other --<br />
-- wikis by changing the values in the [[Module:Pagetype/config]]. --<br />
-- --<br />
--------------------------------------------------------------------------------<br />
<br />
-- Load config.<br />
local cfg = mw.loadData('Module:Pagetype/config')<br />
<br />
-- Load required modules.<br />
local getArgs = require('Module:Arguments').getArgs<br />
local yesno = require('Module:Yesno')<br />
local nsDetectModule = require('Module:Namespace detect')<br />
local nsDetect = nsDetectModule._main<br />
local getParamMappings = nsDetectModule.getParamMappings<br />
local getPageObject = nsDetectModule.getPageObject<br />
<br />
local p = {}<br />
<br />
local function shallowCopy(t)<br />
-- Makes a shallow copy of a table.<br />
local ret = {}<br />
for k, v in pairs(t) do<br />
ret[k] = v<br />
end<br />
return ret<br />
end<br />
<br />
local function checkPagetypeInput(namespace, val)<br />
-- Checks to see whether we need the default value for the given namespace,<br />
-- and if so gets it from the pagetypes table.<br />
-- The yesno function returns true/false for "yes", "no", etc., and returns<br />
-- val for other input.<br />
local ret = yesno(val, val)<br />
if ret and type(ret) ~= 'string' then<br />
ret = cfg.pagetypes[namespace]<br />
end<br />
return ret<br />
end<br />
<br />
local function getPagetypeFromClass(class, param, aliasTable, default)<br />
-- Gets the pagetype from a class specified from the first positional<br />
-- parameter.<br />
param = yesno(param, param)<br />
if param ~= false then -- No check if specifically disallowed.<br />
for _, alias in ipairs(aliasTable) do<br />
if class == alias then<br />
if type(param) == 'string' then<br />
return param<br />
else<br />
return default<br />
end<br />
end<br />
end<br />
end<br />
end<br />
<br />
local function getNsDetectValue(args)<br />
-- Builds the arguments to pass to [[Module:Namespace detect]] and returns<br />
-- the result.<br />
<br />
-- Get the default values.<br />
local ndArgs = {}<br />
local defaultns = args[cfg.defaultns]<br />
if defaultns == cfg.defaultnsAll then<br />
ndArgs = shallowCopy(cfg.pagetypes)<br />
else<br />
local defaultnsArray<br />
if defaultns == cfg.defaultnsExtended then<br />
defaultnsArray = cfg.extendedNamespaces<br />
elseif defaultns == cfg.defaultnsNone then<br />
defaultnsArray = {}<br />
else<br />
defaultnsArray = cfg.defaultNamespaces<br />
end<br />
for _, namespace in ipairs(defaultnsArray) do<br />
ndArgs[namespace] = cfg.pagetypes[namespace]<br />
end<br />
end<br />
<br />
--[[<br />
-- Add custom values passed in from the arguments. These overwrite the<br />
-- defaults. The possible argument names are fetched from<br />
-- Module:Namespace detect automatically in case new namespaces are<br />
-- added. Although we accept namespace aliases as parameters, we only pass<br />
-- the local namespace name as a parameter to Module:Namespace detect.<br />
-- This means that the "image" parameter can overwrite defaults for the<br />
-- File: namespace, which wouldn't work if we passed the parameters through<br />
-- separately.<br />
--]]<br />
local mappings = getParamMappings()<br />
for ns, paramAliases in pairs(mappings) do<br />
-- Copy the aliases table, as # doesn't work with tables returned from<br />
-- mw.loadData.<br />
paramAliases = shallowCopy(paramAliases)<br />
local paramName = paramAliases[1]<br />
-- Iterate backwards along the array so that any values for the local<br />
-- namespace names overwrite those for namespace aliases.<br />
for i = #paramAliases, 1, -1 do<br />
local paramAlias = paramAliases[i]<br />
local ndArg = checkPagetypeInput(paramAlias, args[paramAlias])<br />
if ndArg == false then<br />
-- If any arguments are false, convert them to nil to protect<br />
-- against breakage by future changes to<br />
-- [[Module:Namespace detect]].<br />
ndArgs[paramName] = nil<br />
elseif ndArg then<br />
ndArgs[paramName] = ndArg<br />
end<br />
end<br />
end<br />
-- Check for disambiguation-class and N/A-class pages in mainspace.<br />
if ndArgs.main then<br />
local class = args[1]<br />
if type(class) == 'string' then<br />
-- Put in lower case so e.g. "Dab" and "dab" will both match.<br />
class = mw.ustring.lower(class)<br />
end<br />
local dab = getPagetypeFromClass(<br />
class,<br />
args[cfg.dab],<br />
cfg.dabAliases,<br />
cfg.dabDefault<br />
)<br />
if dab then<br />
ndArgs.main = dab<br />
else<br />
local na = getPagetypeFromClass(<br />
class,<br />
args[cfg.na],<br />
cfg.naAliases,<br />
cfg.naDefault<br />
)<br />
if na then<br />
ndArgs.main = na<br />
end<br />
end<br />
end<br />
-- If there is no talk value specified, use the corresponding subject <br />
-- namespace for talk pages.<br />
if not ndArgs.talk then<br />
ndArgs.subjectns = true<br />
end<br />
-- Add the fallback value. This can also be customised, but it cannot be<br />
-- disabled.<br />
local other = args[cfg.other]<br />
-- We will ignore true/false/nil results from yesno here, but using it<br />
-- anyway for consistency.<br />
other = yesno(other, other)<br />
if type(other) == 'string' then<br />
ndArgs.other = other<br />
else<br />
ndArgs.other = cfg.otherDefault<br />
end<br />
-- Allow custom page values.<br />
ndArgs.page = args.page<br />
return nsDetect(ndArgs)<br />
end<br />
<br />
local function detectRedirects(args)<br />
local redirect = args[cfg.redirect]<br />
-- The yesno function returns true/false for "yes", "no", etc., and returns<br />
-- redirect for other input.<br />
redirect = yesno(redirect, redirect)<br />
if redirect == false then<br />
-- Detect redirects unless they have been explicitly disallowed with<br />
-- "redirect=no" or similar.<br />
return<br />
end<br />
local pageObject = getPageObject(args.page)<br />
-- If we are using subject namespaces elsewhere, do so here as well.<br />
if pageObject<br />
and not yesno(args.talk, true)<br />
and args[cfg.defaultns] ~= cfg.defaultnsAll<br />
then<br />
pageObject = getPageObject(<br />
pageObject.subjectNsText .. ':' .. pageObject.text<br />
)<br />
end<br />
-- Allow custom values for redirects.<br />
if pageObject and pageObject.isRedirect then<br />
if type(redirect) == 'string' then<br />
return redirect<br />
else<br />
return cfg.redirectDefault<br />
end<br />
end<br />
end<br />
<br />
function p._main(args)<br />
local redirect = detectRedirects(args)<br />
if redirect then<br />
return redirect<br />
else<br />
return getNsDetectValue(args)<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
local args = getArgs(frame)<br />
return p._main(args)<br />
end<br />
<br />
return p</div>T12https://sarkarverse.org/index.php?title=Module:Pagetype&diff=17374&oldid=prevT12: 1 revision2014-01-21T09:08:05Z<p>1 revision</p>
<p><b>New page</b></p><div>----------------------------------------------------------------------------------------------------<br />
-- --<br />
-- PAGETYPE --<br />
-- --<br />
-- This is a meta-module intended to replace {{pagetype}} and similar templates. It --<br />
-- automatically detects namespaces, and allows for a great deal of customisation. --<br />
-- It can easily be ported to other wikis by changing the values in the configuration --<br />
-- table. --<br />
-- --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
local cfg = {}<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Configuration data --<br />
-- This module can be localised for other wikis by using the configuration parameters below. --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- This table holds the values to use for "main=true", "user=true", etc. Keys to this table should<br />
-- be namespace parameters that can be used with [[Module:Namespace detect]]. <br />
cfg.pagetypes = {<br />
['main'] = 'article',<br />
['user'] = 'user page',<br />
['project'] = 'project page',<br />
['wikipedia'] = 'project page',<br />
['wp'] = 'project page',<br />
['file'] = 'file',<br />
['image'] = 'file',<br />
['mediawiki'] = 'interface page',<br />
['template'] = 'template',<br />
['help'] = 'help page',<br />
['category'] = 'category',<br />
['portal'] = 'portal',<br />
['book'] = 'book',<br />
['draft'] = 'draft',<br />
['education program'] = 'education program page',<br />
['timedtext'] = 'Timed Text page',<br />
['module'] = 'module',<br />
['talk'] = 'talk page',<br />
['special'] = 'special page',<br />
['media'] = 'file'<br />
}<br />
<br />
-- This table holds the names of the namespaces to be looked up from cfg.pagetypes by default.<br />
cfg.defaultNamespaces = {'main', 'file', 'template', 'category', 'module', 'book'}<br />
<br />
-- This table holds the names of the namespaces to be looked up from cry.pagetypes if cfg.defaultnsExtended is set.<br />
cfg.extendedNamespaces = {'main', 'user', 'project', 'file', 'mediawiki', 'template', 'category', 'help', 'portal', 'module', 'book', 'draft'}<br />
<br />
-- The parameter name to set which default namespace values to be looked up from cfg.pagetypes.<br />
cfg.defaultns = 'defaultns'<br />
<br />
-- The value of cfg.defaultns to set all namespaces, including talk.<br />
cfg.defaultnsAll = 'all'<br />
<br />
-- The value of cfg.defaultns to set the namespaces listed in cfg.extendedNamespaces<br />
cfg.defaultnsExtended = 'extended'<br />
<br />
-- The value of cfg.defaultns to set no default namespaces.<br />
cfg.defaultnsNone = 'none'<br />
<br />
-- The parameter name to use for disambiguation pages page.<br />
cfg.dab = 'dab'<br />
<br />
-- This table holds the different possible aliases for disambiguation-class pages. These should be lower-case.<br />
cfg.dabAliases = {'disambiguation', 'disambig', 'disamb', 'dab'}<br />
<br />
-- The default value for disambiguation pages.<br />
cfg.dabDefault = 'page'<br />
<br />
-- The parameter name to use for N/A-class page.<br />
cfg.na = 'na'<br />
<br />
-- This table holds the different possible aliases for N/A-class pages. These should be lower-case.<br />
cfg.naAliases = {'na', 'n/a'}<br />
<br />
-- The default value for N/A-class pages.<br />
cfg.naDefault = 'page'<br />
<br />
-- The parameter name to use for redirects.<br />
cfg.redirect = 'redirect'<br />
<br />
-- The default value to use for redirects.<br />
cfg.redirectDefault = 'redirect'<br />
<br />
-- The parameter name for undefined namespaces.<br />
cfg.other = 'other'<br />
<br />
-- The value used if the module detects an undefined namespace.<br />
cfg.otherDefault = 'page'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- End configuration data --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- Load required modules.<br />
local getArgs = require('Module:Arguments').getArgs<br />
local yesno = require('Module:Yesno')<br />
local nsDetectModule = require('Module:Namespace detect')<br />
local nsDetect = nsDetectModule._main<br />
local getParamMappings = nsDetectModule.getParamMappings<br />
local getPageObject = nsDetectModule.getPageObject<br />
<br />
local p = {}<br />
<br />
local function checkPagetypeInput(namespace, val)<br />
-- Checks to see whether we need the default value for the given namespace, and if so gets it from the pagetypes table.<br />
local ret = yesno(val, val) -- Returns true/false for "yes", "no", etc., and returns val for other input.<br />
if ret and type(ret) ~= 'string' then<br />
ret = cfg.pagetypes[namespace]<br />
end<br />
return ret<br />
end<br />
<br />
local function getPagetypeFromClass(class, param, aliasTable, default)<br />
-- Gets the pagetype from a class specified from the first positional parameter.<br />
param = yesno(param, param)<br />
if param ~= false then -- Check for classes unless they are specifically disallowed.<br />
for _, alias in ipairs(aliasTable) do<br />
if class == alias then<br />
if type(param) == 'string' then<br />
return param<br />
else<br />
return default<br />
end<br />
end<br />
end<br />
end<br />
end<br />
<br />
local function getNsDetectValue(args)<br />
-- Builds the arguments to pass to [[Module:Namespace detect]] and returns the result.<br />
-- First, get the default values.<br />
local ndArgs = {}<br />
local defaultns = args[cfg.defaultns]<br />
if defaultns == cfg.defaultnsAll then<br />
ndArgs = cfg.pagetypes<br />
else<br />
local defaultnsArray<br />
if defaultns == cfg.defaultnsExtended then<br />
defaultnsArray = cfg.extendedNamespaces<br />
elseif defaultns == cfg.defaultnsNone then<br />
defaultnsArray = {}<br />
else<br />
defaultnsArray = cfg.defaultNamespaces<br />
end<br />
for _, namespace in ipairs(defaultnsArray) do<br />
ndArgs[namespace] = cfg.pagetypes[namespace]<br />
end<br />
end<br />
-- Add custom values passed in from the arguments. These overwrite the defaults.<br />
-- The possible argument names are fetched from [[Module:Namespace detect]] automatically in case new namespaces are added.<br />
-- Although we accept namespace aliases as parameters, we only pass the local namespace name as a parameter to [[Module:Namespace detect]].<br />
-- This means that the "image" parameter can overwrite defaults for the File: namespace, which wouldn't work if we passed the parameters through separately.<br />
local mappings = getParamMappings()<br />
for ns, paramAliases in pairs(mappings) do<br />
local paramName = paramAliases[1] <br />
for i = #paramAliases, 1, -1 do -- Iterate backwards along the array so that any values for the local namespace names overwrite those for namespace aliases.<br />
local paramAlias = paramAliases[i]<br />
local ndArg = checkPagetypeInput(paramAlias, args[paramAlias])<br />
if ndArg == false then<br />
-- If any arguments are false, convert them to nil to protect against breakage by future changes to [[Module:Namespace detect]].<br />
ndArgs[paramName] = nil<br />
elseif ndArg then<br />
ndArgs[paramName] = ndArg<br />
end<br />
end<br />
end<br />
-- Check for disambiguation-class and N/A-class pages in mainspace.<br />
if ndArgs.main then<br />
local class = args[1]<br />
if type(class) == 'string' then<br />
-- Put in lower case so e.g. "Dab" and "dab" will both match.<br />
class = mw.ustring.lower(class)<br />
end<br />
local dab = getPagetypeFromClass(class, args[cfg.dab], cfg.dabAliases, cfg.dabDefault)<br />
if dab then<br />
ndArgs.main = dab<br />
else<br />
local na = getPagetypeFromClass(class, args[cfg.na], cfg.naAliases, cfg.naDefault)<br />
if na then<br />
ndArgs.main = na<br />
end<br />
end<br />
end<br />
-- If there is no talk value specified, use the corresponding subject namespace for talk pages.<br />
if not ndArgs.talk then<br />
ndArgs.subjectns = true<br />
end<br />
-- Add the fallback value. This can also be customised, but it cannot be disabled.<br />
local other = args[cfg.other]<br />
other = yesno(other, other) -- We will ignore true/false/nil results from yesno here, but using it anyway for consistency.<br />
if type(other) == 'string' then<br />
ndArgs.other = other<br />
else<br />
ndArgs.other = cfg.otherDefault<br />
end<br />
-- Allow custom page values.<br />
ndArgs.page = args.page<br />
return nsDetect(ndArgs)<br />
end<br />
<br />
local function detectRedirects(args)<br />
local redirect = args[cfg.redirect]<br />
redirect = yesno(redirect, redirect) -- Returns true/false for "yes", "no", etc., and returns redirect for other input.<br />
if redirect == false then return end -- Detect redirects unless they have been explicitly disallowed with "redirect=no" or similar.<br />
local pageObject = getPageObject(args.page)<br />
-- If we are using subject namespaces elsewhere, do so here as well.<br />
if pageObject and not yesno(args.talk, true) then<br />
pageObject = getPageObject(pageObject.subjectNsText .. ':' .. pageObject.text)<br />
end<br />
-- Allow custom values for redirects.<br />
if pageObject and pageObject.isRedirect then<br />
if type(redirect) == 'string' then<br />
return redirect<br />
else<br />
return cfg.redirectDefault<br />
end<br />
end<br />
end<br />
<br />
function p._main(args)<br />
local redirect = detectRedirects(args)<br />
if redirect then<br />
return redirect<br />
else<br />
return getNsDetectValue(args)<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
local args = getArgs(frame)<br />
return p._main(args)<br />
end<br />
<br />
return p</div>T12https://sarkarverse.org/index.php?title=Module:Pagetype&diff=13859&oldid=prevT12: 1 revision2013-11-21T13:41:09Z<p>1 revision</p>
<p><b>New page</b></p><div>----------------------------------------------------------------------------------------------------<br />
-- --<br />
-- PAGETYPE --<br />
-- --<br />
-- This is a meta-module intended to replace {{pagetype}} and similar templates. It --<br />
-- automatically detects namespaces, and allows for a great deal of customisation. --<br />
-- It can easily be ported to other wikis by changing the values in the configuration --<br />
-- table.<br />
-- --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
local cfg = {}<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- Configuration data --<br />
-- This module can be localised for other wikis by using the configuration parameters below. --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- This table holds the values to use for "main=true", "user=true", etc. Keys to this table should<br />
-- be namespace parameters that can be used with [[Module:Namespace detect]]. <br />
cfg.pagetypes = {<br />
['main'] = 'article',<br />
['user'] = 'user page',<br />
['project'] = 'project page',<br />
['wikipedia'] = 'project page',<br />
['wp'] = 'project page',<br />
['file'] = 'file',<br />
['image'] = 'file',<br />
['mediawiki'] = 'interface page',<br />
['template'] = 'template',<br />
['help'] = 'help page',<br />
['category'] = 'category',<br />
['portal'] = 'portal',<br />
['book'] = 'book',<br />
['education program'] = 'education program page',<br />
['timedtext'] = 'Timed Text page',<br />
['module'] = 'module',<br />
['talk'] = 'talk page',<br />
['special'] = 'special page',<br />
['media'] = 'file'<br />
}<br />
<br />
-- This table holds the names of the namespaces to be looked up from cfg.pagetypes by default.<br />
cfg.defaultNamespaces = {'main', 'file', 'template', 'category', 'module', 'book'}<br />
<br />
-- This table holds the names of the namespaces to be looked up from cry.pagetypes if cfg.defaultnsExtended is set.<br />
cfg.extendedNamespaces = {'main', 'user', 'project', 'file', 'mediawiki', 'template', 'category', 'help', 'portal', 'module', 'book'}<br />
<br />
-- The parameter name to set which default namespace values to be looked up from cfg.pagetypes.<br />
cfg.defaultns = 'defaultns'<br />
<br />
-- The value of cfg.defaultns to set all namespaces, including talk.<br />
cfg.defaultnsAll = 'all'<br />
<br />
-- The value of cfg.defaultns to set the namespaces listed in cfg.extendedNamespaces<br />
cfg.defaultnsExtended = 'extended'<br />
<br />
-- The value of cfg.defaultns to set no default namespaces.<br />
cfg.defaultnsNone = 'none'<br />
<br />
-- The parameter name to use for disambiguation pages page.<br />
cfg.dab = 'dab'<br />
<br />
-- This table holds the different possible aliases for disambiguation-class pages. These should be lower-case.<br />
cfg.dabAliases = {'disambiguation', 'disambig', 'disamb', 'dab'}<br />
<br />
-- The default value for disambiguation pages.<br />
cfg.dabDefault = 'page'<br />
<br />
-- The parameter name to use for N/A-class page.<br />
cfg.na = 'na'<br />
<br />
-- This table holds the different possible aliases for N/A-class pages. These should be lower-case.<br />
cfg.naAliases = {'na', 'n/a'}<br />
<br />
-- The default value for N/A-class pages.<br />
cfg.naDefault = 'page'<br />
<br />
-- The parameter name to use for redirects.<br />
cfg.redirect = 'redirect'<br />
<br />
-- The default value to use for redirects.<br />
cfg.redirectDefault = 'redirect'<br />
<br />
-- The parameter name for undefined namespaces.<br />
cfg.other = 'other'<br />
<br />
-- The value used if the module detects an undefined namespace.<br />
cfg.otherDefault = 'page'<br />
<br />
----------------------------------------------------------------------------------------------------<br />
-- End configuration data --<br />
----------------------------------------------------------------------------------------------------<br />
<br />
-- Load required modules.<br />
local yesno = require('Module:Yesno')<br />
local nsDetectModule = require('Module:Namespace detect')<br />
local nsDetect = nsDetectModule._main<br />
local getParamMappings = nsDetectModule.getParamMappings<br />
local getPageObject = nsDetectModule.getPageObject<br />
<br />
local p = {}<br />
<br />
local function checkPagetypeInput(namespace, val)<br />
-- Checks to see whether we need the default value for the given namespace, and if so gets it from the pagetypes table.<br />
local ret = yesno(val, val) -- Returns true/false for "yes", "no", etc., and returns val for other input.<br />
if ret and type(ret) ~= 'string' then<br />
ret = cfg.pagetypes[namespace]<br />
end<br />
return ret<br />
end<br />
<br />
local function getPagetypeFromClass(class, param, aliasTable, default)<br />
-- Gets the pagetype from a class specified from the first positional parameter.<br />
param = yesno(param, param)<br />
if param ~= false then -- Check for classes unless they are specifically disallowed.<br />
for _, alias in ipairs(aliasTable) do<br />
if class == alias then<br />
if type(param) == 'string' then<br />
return param<br />
else<br />
return default<br />
end<br />
end<br />
end<br />
end<br />
end<br />
<br />
local function getNsDetectValue(args)<br />
-- Builds the arguments to pass to [[Module:Namespace detect]] and returns the result.<br />
-- First, get the default values.<br />
local ndArgs = {}<br />
local defaultns = args[cfg.defaultns]<br />
if defaultns == cfg.defaultnsAll then<br />
ndArgs = cfg.pagetypes<br />
else<br />
local defaultnsArray<br />
if defaultns == cfg.defaultnsExtended then<br />
defaultnsArray = cfg.extendedNamespaces<br />
elseif defaultns == cfg.defaultnsNone then<br />
defaultnsArray = {}<br />
else<br />
defaultnsArray = cfg.defaultNamespaces<br />
end<br />
for _, namespace in ipairs(defaultnsArray) do<br />
ndArgs[namespace] = cfg.pagetypes[namespace]<br />
end<br />
end<br />
-- Add custom values passed in from the arguments. These overwrite the defaults.<br />
-- The possible argument names are fetched from [[Module:Namespace detect]] automatically in case new namespaces are added.<br />
-- Although we accept namespace aliases as parameters, we only pass the local namespace name as a parameter to [[Module:Namespace detect]].<br />
-- This means that the "image" parameter can overwrite defaults for the File: namespace, which wouldn't work if we passed the parameters through separately.<br />
local mappings = getParamMappings()<br />
for ns, paramAliases in pairs(mappings) do<br />
local paramName = paramAliases[1] <br />
for i = #paramAliases, 1, -1 do -- Iterate backwards along the array so that any values for the local namespace names overwrite those for namespace aliases.<br />
local paramAlias = paramAliases[i]<br />
local ndArg = checkPagetypeInput(paramAlias, args[paramAlias])<br />
if ndArg == false then<br />
-- If any arguments are false, convert them to nil to protect against breakage by future changes to [[Module:Namespace detect]].<br />
ndArgs[paramName] = nil<br />
elseif ndArg then<br />
ndArgs[paramName] = ndArg<br />
end<br />
end<br />
end<br />
-- Check for disambiguation-class and N/A-class pages in mainspace.<br />
if ndArgs.main then<br />
local class = args[1]<br />
if type(class) == 'string' then<br />
-- Put in lower case so e.g. "Dab" and "dab" will both match.<br />
class = mw.ustring.lower(class)<br />
end<br />
local dab = getPagetypeFromClass(class, args[cfg.dab], cfg.dabAliases, cfg.dabDefault)<br />
if dab then<br />
ndArgs.main = dab<br />
else<br />
local na = getPagetypeFromClass(class, args[cfg.na], cfg.naAliases, cfg.naDefault)<br />
if na then<br />
ndArgs.main = na<br />
end<br />
end<br />
end<br />
-- If there is no talk value specified, use the corresponding subject namespace for talk pages.<br />
if not ndArgs.talk then<br />
ndArgs.subjectns = true<br />
end<br />
-- Add the fallback value. This can also be customised, but it cannot be disabled.<br />
local other = args[cfg.other]<br />
other = yesno(other, other) -- We will ignore true/false/nil results from yesno here, but using it anyway for consistency.<br />
if type(other) == 'string' then<br />
ndArgs.other = other<br />
else<br />
ndArgs.other = cfg.otherDefault<br />
end<br />
-- Allow custom page values.<br />
ndArgs.page = args.page<br />
return nsDetect(ndArgs)<br />
end<br />
<br />
local function detectRedirects(args)<br />
local redirect = args[cfg.redirect]<br />
redirect = yesno(redirect, redirect) -- Returns true/false for "yes", "no", etc., and returns redirect for other input.<br />
if redirect == false then return end -- Detect redirects unless they have been explicitly disallowed with "redirect=no" or similar.<br />
local pageObject = getPageObject(args.page)<br />
-- If we are using subject namespaces elsewhere, do so here as well.<br />
if pageObject and not yesno(args.talk, true) then<br />
pageObject = getPageObject(pageObject.subjectNsText .. ':' .. pageObject.text)<br />
end<br />
-- Allow custom values for redirects.<br />
if pageObject and pageObject.isRedirect then<br />
if type(redirect) == 'string' then<br />
return redirect<br />
else<br />
return cfg.redirectDefault<br />
end<br />
end<br />
end<br />
<br />
function p._main(args)<br />
local redirect = detectRedirects(args)<br />
if redirect then<br />
return redirect<br />
else<br />
return getNsDetectValue(args)<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
-- If called via #invoke, use the args passed into the invoking template, or the args passed to #invoke if any exist.<br />
-- Otherwise assume args are being passed directly in from the debug console or from another Lua module.<br />
local origArgs<br />
if frame == mw.getCurrentFrame() then<br />
origArgs = frame:getParent().args<br />
for k, v in pairs(frame.args) do<br />
origArgs = frame.args<br />
break<br />
end<br />
else<br />
origArgs = frame<br />
end<br />
-- Trim whitespace and remove blank arguments.<br />
local args = {}<br />
for k, v in pairs(origArgs) do<br />
if type(v) == 'string' then<br />
v = mw.text.trim(v)<br />
end<br />
if v ~= '' then<br />
args[k] = v<br />
end<br />
end<br />
return p._main(args)<br />
end<br />
<br />
return p</div>T12