<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3APagetype</id>
	<title>Module:Pagetype - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://the-democratika.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3APagetype"/>
	<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Pagetype&amp;action=history"/>
	<updated>2026-04-04T13:04:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://the-democratika.com/wiki/index.php?title=Module:Pagetype&amp;diff=5891&amp;oldid=prev</id>
		<title>&gt;MSGJ: fix for files and interface messages which do exist but are not stored locally</title>
		<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Pagetype&amp;diff=5891&amp;oldid=prev"/>
		<updated>2024-05-21T17:35:20Z</updated>

		<summary type="html">&lt;p&gt;fix for files and interface messages which do exist but are not stored locally&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--------------------------------------------------------------------------------&lt;br /&gt;
--                                                                            --&lt;br /&gt;
--      This meta-module which automatically detects namespaces, and allows   --&lt;br /&gt;
--      for a great deal of customisation. It can easily be ported to other   --&lt;br /&gt;
--      wikis by changing the values in the [[Module:Pagetype/config]].       --&lt;br /&gt;
--                                                                            --&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Load config.&lt;br /&gt;
local cfg = mw.loadData(&amp;#039;Module:Pagetype/config&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
-- Load required modules.&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Look up a namespace argument in the args table.&lt;br /&gt;
local function lookUpNamespaceArg(args, key)&lt;br /&gt;
	local arg = args[key]&lt;br /&gt;
	-- Convert &amp;quot;yes&amp;quot;, &amp;quot;1&amp;quot; etc. to true, &amp;quot;no&amp;quot;, &amp;quot;0&amp;quot; etc. to false, and leave&lt;br /&gt;
	-- other values the same.&lt;br /&gt;
	return yesno(arg, arg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Append multiple values to an array&lt;br /&gt;
local function appendMultiple(target, source)&lt;br /&gt;
	for _, value in ipairs(source) do&lt;br /&gt;
		table.insert(target, value)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get argument keys for a title&amp;#039;s namespace&lt;br /&gt;
local function getNamespaceArgKeys(title)&lt;br /&gt;
	local nsInfo = mw.site.namespaces[title.namespace]&lt;br /&gt;
	local customAliases = cfg.customNamespaceAliases[title.namespace] or {}&lt;br /&gt;
	local keys = {}&lt;br /&gt;
	if nsInfo.name ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		table.insert(keys, nsInfo.name)&lt;br /&gt;
	end&lt;br /&gt;
	if nsInfo.canonicalName ~= nsInfo.name and nsInfo.canonicalName ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		table.insert(keys, nsInfo.canonicalName)&lt;br /&gt;
	end&lt;br /&gt;
	appendMultiple(keys, nsInfo.aliases)&lt;br /&gt;
	appendMultiple(keys, customAliases)&lt;br /&gt;
	return keys&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get the argument for a title&amp;#039;s namespace, if it was specified in the args table.&lt;br /&gt;
local function getNamespaceArg(title, args)&lt;br /&gt;
	if title.isTalkPage then&lt;br /&gt;
		return lookUpNamespaceArg(args, cfg.talk)&lt;br /&gt;
	end&lt;br /&gt;
	for _, key in ipairs(getNamespaceArgKeys(title)) do&lt;br /&gt;
		local arg = lookUpNamespaceArg(args, mw.ustring.lower(key))&lt;br /&gt;
		if arg ~= nil then&lt;br /&gt;
			return arg&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Look up a page type specific to the title&amp;#039;s namespace&lt;br /&gt;
local function getExplicitPageType(title)&lt;br /&gt;
	if title.isTalkPage then&lt;br /&gt;
		return cfg.talkDefault&lt;br /&gt;
	else&lt;br /&gt;
		return cfg.pagetypes[title.namespace]&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get a default page type that is not specific to the title&amp;#039;s namespace&lt;br /&gt;
local function getDefaultPageType(args)&lt;br /&gt;
	local other = lookUpNamespaceArg(args, cfg.other)&lt;br /&gt;
	if type(other) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		return other&lt;br /&gt;
	else&lt;br /&gt;
		return cfg.otherDefault&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function detectRedirects(title, args)&lt;br /&gt;
	local redirect = lookUpNamespaceArg(args, cfg.redirect)&lt;br /&gt;
	if redirect == false then&lt;br /&gt;
		-- Don&amp;#039;t detect redirects if they have been specifically disallowed.&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Allow custom values for redirects.&lt;br /&gt;
	if not title.isRedirect then&lt;br /&gt;
		return nil&lt;br /&gt;
	elseif type(redirect) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		return redirect&lt;br /&gt;
	else&lt;br /&gt;
		return cfg.redirectDefault&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function capitalize(pageType)&lt;br /&gt;
	local first = mw.ustring.sub(pageType, 1, 1)&lt;br /&gt;
	local rest = mw.ustring.sub(pageType, 2)&lt;br /&gt;
	return mw.ustring.upper(first) .. rest&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function pluralize(pageType)&lt;br /&gt;
	if cfg.irregularPlurals[pageType] then&lt;br /&gt;
		return cfg.irregularPlurals[pageType]&lt;br /&gt;
	else&lt;br /&gt;
		return pageType .. cfg.plural -- often &amp;#039;s&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function parseContent(title, args, optionsList)&lt;br /&gt;
	if title.namespace==828 and title.subpageText~=&amp;#039;doc&amp;#039; -- don&amp;#039;t detect modules&lt;br /&gt;
		or not title.exists -- can&amp;#039;t check unless page exists&lt;br /&gt;
	then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local content = title:getContent()&lt;br /&gt;
	if content == nil then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local templates -- lazily evaluated&lt;br /&gt;
	for _, options in next, optionsList do&lt;br /&gt;
		local list, parameter, default, articleOnly = unpack(options, 1, 4)&lt;br /&gt;
		if not articleOnly or title.namespace==0 then -- only check for templates if we should...&lt;br /&gt;
			local out = lookUpNamespaceArg(args, parameter)&lt;br /&gt;
			if type(out) == &amp;quot;string&amp;quot; or (out ~= false and default) then -- ...and if we actually have anything to say about them&lt;br /&gt;
				if not templates then&lt;br /&gt;
					templates = {} -- do our delayed evaluation now that we are required to&lt;br /&gt;
					content = require(&amp;#039;Module:Wikitext Parsing&amp;#039;).PrepareText(content) -- disregard templates which do not have any affect&lt;br /&gt;
					for template in string.gmatch(content, &amp;quot;{{%s*([^|}]-)%s*[|}]&amp;quot;) do&lt;br /&gt;
						templates[#templates+1] = capitalize(template)&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				local wantedTemplates = mw.loadData(&amp;#039;Module:Pagetype/&amp;#039; .. list)&lt;br /&gt;
				local templateFound = false&lt;br /&gt;
				for _, template in next, templates do&lt;br /&gt;
					if wantedTemplates[template] then&lt;br /&gt;
						templateFound = true&lt;br /&gt;
						break&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				if templateFound then&lt;br /&gt;
					if type(out)==&amp;#039;string&amp;#039; then&lt;br /&gt;
						return out&lt;br /&gt;
					elseif out ~= false and default then&lt;br /&gt;
						return default&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Find pages which do not exist&lt;br /&gt;
local function nonExistent(title, args)&lt;br /&gt;
	local arg = lookUpNamespaceArg(args, cfg.ne)&lt;br /&gt;
	if arg == false then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local exists = false&lt;br /&gt;
	if title.exists then -- not an article if it does not exist&lt;br /&gt;
		exists = true&lt;br /&gt;
	elseif title.namespace==8 and mw.message.new(title.text):exists() then&lt;br /&gt;
		exists = true&lt;br /&gt;
	elseif title.namespace==6 and title.fileExists then&lt;br /&gt;
		exists = true&lt;br /&gt;
	end&lt;br /&gt;
	if not exists then&lt;br /&gt;
		if type(arg) == &amp;#039;string&amp;#039; then&lt;br /&gt;
			return arg&lt;br /&gt;
		else&lt;br /&gt;
			return cfg.naDefault&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get page types for mainspaces pages with an explicit class specified&lt;br /&gt;
local function getMainNamespaceClassPageType(title, args)&lt;br /&gt;
	local class = args[1]&lt;br /&gt;
	if type(class) == &amp;#039;string&amp;#039; then	-- Put in lower case so e.g. &amp;quot;na&amp;quot; and &amp;quot;NA&amp;quot; will both match&lt;br /&gt;
		class = mw.ustring.lower(class)&lt;br /&gt;
	end&lt;br /&gt;
	local arg = lookUpNamespaceArg(args, cfg.na)&lt;br /&gt;
	if arg == false then -- don&amp;#039;t check for this class if it is specifically disallowed&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	if cfg.naAliases[class] then&lt;br /&gt;
		if type(arg) == &amp;#039;string&amp;#039; then&lt;br /&gt;
			return arg&lt;br /&gt;
		else&lt;br /&gt;
			return cfg.naDefault&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get page type specified by an explicit namespace argument.&lt;br /&gt;
local function getNamespaceArgPageType(title, args)&lt;br /&gt;
	local namespaceArg = getNamespaceArg(title, args)&lt;br /&gt;
	if namespaceArg == true then&lt;br /&gt;
		-- Namespace has been explicitly enabled, so return the default for&lt;br /&gt;
		-- this namespace&lt;br /&gt;
		return getExplicitPageType(title)&lt;br /&gt;
	elseif namespaceArg == false then&lt;br /&gt;
		-- Namespace has been explicitly disabled&lt;br /&gt;
		return getDefaultPageType(args)&lt;br /&gt;
	elseif namespaceArg then&lt;br /&gt;
		-- This namespaces uses custom text&lt;br /&gt;
		return namespaceArg&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- Get page type not specified or detected by other means&lt;br /&gt;
local function getOtherPageType(title, args)&lt;br /&gt;
-- Whether the title is in the set of default active namespaces which are looked up in cfg.pagetypes.&lt;br /&gt;
	local isInDefaultActiveNamespace = false&lt;br /&gt;
	local defaultNamespacesKey = args[cfg.defaultns]&lt;br /&gt;
	if defaultNamespacesKey == cfg.defaultnsAll then&lt;br /&gt;
		isInDefaultActiveNamespace = true&lt;br /&gt;
	else&lt;br /&gt;
		local defaultNamespaces&lt;br /&gt;
		if defaultNamespacesKey == cfg.defaultnsExtended then&lt;br /&gt;
			defaultNamespaces = cfg.extendedNamespaces&lt;br /&gt;
		elseif defaultNamespacesKey == cfg.defaultnsNone then&lt;br /&gt;
			defaultNamespaces = {}&lt;br /&gt;
		else&lt;br /&gt;
			defaultNamespaces = cfg.defaultNamespaces&lt;br /&gt;
		end&lt;br /&gt;
		isInDefaultActiveNamespace = defaultNamespaces[title.namespace]&lt;br /&gt;
	end&lt;br /&gt;
	if isInDefaultActiveNamespace then&lt;br /&gt;
		return getExplicitPageType(title)&lt;br /&gt;
	else&lt;br /&gt;
		return getDefaultPageType(args)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._main(args)&lt;br /&gt;
	local title&lt;br /&gt;
	if args.page then&lt;br /&gt;
		title = mw.title.new(args.page)&lt;br /&gt;
	else&lt;br /&gt;
		title = mw.title.getCurrentTitle()&lt;br /&gt;
	end&lt;br /&gt;
	if title and not yesno(args.talk, true) and args[cfg.defaultns] ~= cfg.defaultnsAll then&lt;br /&gt;
		title = title.subjectPageTitle&lt;br /&gt;
	end&lt;br /&gt;
	local pageType = detectRedirects(title, args)&lt;br /&gt;
		or nonExistent(title, args)&lt;br /&gt;
		or parseContent(title, args, {&lt;br /&gt;
			{&amp;#039;softredirect&amp;#039;, cfg.softRedirect, cfg.softRedirectDefault},&lt;br /&gt;
			{&amp;#039;setindex&amp;#039;, cfg.sia, cfg.siaDefault, true},&lt;br /&gt;
			{&amp;#039;disambiguation&amp;#039;, cfg.dab, cfg.dabDefault, true},&lt;br /&gt;
			{&amp;#039;rfd&amp;#039;, cfg.rfd, cfg.rfdDefault},&lt;br /&gt;
		})&lt;br /&gt;
		or (title.namespace == 0 and getMainNamespaceClassPageType(title, args))&lt;br /&gt;
		or getNamespaceArgPageType(title, args)&lt;br /&gt;
		or getOtherPageType(title, args)&lt;br /&gt;
	if yesno(args.plural, false) then&lt;br /&gt;
		pageType = pluralize(pageType)&lt;br /&gt;
	end&lt;br /&gt;
	if yesno(args.caps, false) then&lt;br /&gt;
		pageType = capitalize(pageType)&lt;br /&gt;
	end&lt;br /&gt;
	return pageType&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = require(&amp;#039;Module:Arguments&amp;#039;).getArgs(frame)&lt;br /&gt;
	return p._main(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>&gt;MSGJ</name></author>
	</entry>
</feed>