Difference between revisions of "Module:Ns has subpages"

From "PTTLink Wiki"
Jump to navigation Jump to search
Mediawiki>Mr. Stradivarius
m (Protected Module:Ns has subpages: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
m (1 revision imported)
Line 1: Line 1:
-- This module implements [[Template:Ns has subpages]].
+
{{<includeonly>safesubst:</includeonly>#invoke:Ns has subpages|main}}<noinclude>
-- While the template is fairly simple, this information is made available to
+
{{documentation}}
-- Lua directly, so using a module means that we don't have to update the
+
<!-- Categories go on the /doc subpage and interwikis go on Wikidata. -->
-- template as new namespaces are added.
+
</noinclude>
 
 
local p = {}
 
 
 
function p._main(ns, frame)
 
-- Get the current namespace if we were not passed one.
 
if not ns then
 
ns = mw.title.getCurrentTitle().namespace
 
end
 
 
 
-- Look up the namespace table from mw.site.namespaces. This should work
 
-- for a majority of cases.
 
local nsTable = mw.site.namespaces[ns]
 
 
 
-- Try using string matching to get the namespace from page names.
 
-- Do a quick and dirty bad title check to try and make sure we do the same
 
-- thing as {{NAMESPACE}} in most cases.
 
if not nsTable and type(ns) == 'string' and not ns:find('[<>|%[%]{}]') then
 
local nsStripped = ns:gsub('^[_%s]*:', '')
 
nsStripped = nsStripped:gsub(':.*$', '')
 
nsTable = mw.site.namespaces[nsStripped]
 
end
 
 
 
-- If we still have no match then try the {{NAMESPACE}} parser function,
 
-- which should catch the remainder of cases. Don't use a mw.title object,
 
-- as this would increment the expensive function count for each new page
 
-- tested.
 
if not nsTable then
 
frame = frame or mw.getCurrentFrame()
 
local nsProcessed = frame:callParserFunction('NAMESPACE', ns)
 
nsTable = nsProcessed and mw.site.namespaces[nsProcessed]
 
end
 
 
return nsTable and nsTable.hasSubpages
 
end
 
 
 
function p.main(frame)
 
local ns = frame:getParent().args[1]
 
if ns then
 
ns = ns:match('^%s*(.-)%s*$') -- trim whitespace
 
ns = tonumber(ns) or ns
 
end
 
local hasSubpages = p._main(ns, frame)
 
return hasSubpages and 'yes' or ''
 
end
 
 
 
return p
 

Revision as of 23:22, 5 September 2021

Script error: No such module "Ns has subpages".

Module documentationcreate · purge ]
This documentation is transcluded from Module:Ns has subpages/doc.