<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3APortal</id>
	<title>Module:Portal - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3APortal"/>
	<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Portal&amp;action=history"/>
	<updated>2026-04-06T07:35:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://mindpowe.red/wiki/index.php?title=Module:Portal&amp;diff=1476&amp;oldid=prev</id>
		<title>imported&gt;Primefac: use Module:Yesno for added flexibility (TPER)</title>
		<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Portal&amp;diff=1476&amp;oldid=prev"/>
		<updated>2020-06-20T21:55:57Z</updated>

		<summary type="html">&lt;p&gt;use Module:Yesno for added flexibility (TPER)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[==[ This module is a Lua implementation of the old {{Portal}} template. As of February 2019 it is used on nearly 7,900,000 articles.&lt;br /&gt;
-- Please take care when updating it! It outputs two functions: p.portal, which generates a list of portals, and p.image, which&lt;br /&gt;
-- produces the image name for an individual portal.&lt;br /&gt;
&lt;br /&gt;
-- The portal image data is kept in submodules of [[Module:Portal/images]], listed below:&lt;br /&gt;
-- [[Module:Portal/images/a]]		- for portal names beginning with &amp;quot;A&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/b]]		- for portal names beginning with &amp;quot;B&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/c]]		- for portal names beginning with &amp;quot;C&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/d]]		- for portal names beginning with &amp;quot;D&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/e]]		- for portal names beginning with &amp;quot;E&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/f]]		- for portal names beginning with &amp;quot;F&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/g]]		- for portal names beginning with &amp;quot;G&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/h]]		- for portal names beginning with &amp;quot;H&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/i]]		- for portal names beginning with &amp;quot;I&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/j]]		- for portal names beginning with &amp;quot;J&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/k]]		- for portal names beginning with &amp;quot;K&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/l]]		- for portal names beginning with &amp;quot;L&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/m]]		- for portal names beginning with &amp;quot;M&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/n]]		- for portal names beginning with &amp;quot;N&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/o]]		- for portal names beginning with &amp;quot;O&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/p]]		- for portal names beginning with &amp;quot;P&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/q]]		- for portal names beginning with &amp;quot;Q&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/r]]		- for portal names beginning with &amp;quot;R&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/s]]		- for portal names beginning with &amp;quot;S&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/t]]		- for portal names beginning with &amp;quot;T&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/u]]		- for portal names beginning with &amp;quot;U&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/v]]		- for portal names beginning with &amp;quot;V&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/w]]		- for portal names beginning with &amp;quot;W&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/x]]		- for portal names beginning with &amp;quot;X&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/y]]		- for portal names beginning with &amp;quot;Y&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/z]]		- for portal names beginning with &amp;quot;Z&amp;quot;.&lt;br /&gt;
-- [[Module:Portal/images/other]]	- for portal names beginning with any other letters. This includes numbers,&lt;br /&gt;
-- 									  letters with diacritics, and letters in non-Latin alphabets.&lt;br /&gt;
-- [[Module:Portal/images/aliases]]	- for adding aliases for existing portal names. Use this page for variations&lt;br /&gt;
-- 									  in spelling and diacritics, etc., no matter what letter the portal begins with.&lt;br /&gt;
--&lt;br /&gt;
-- The images data pages are separated by the first letter to reduce server load when images are added, changed, or removed.&lt;br /&gt;
-- Previously all the images were on one data page at [[Module:Portal/images]], but this had the disadvantage that all&lt;br /&gt;
-- 5,000,000 pages using this module needed to be refreshed every time an image was added or removed.&lt;br /&gt;
]==]&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local trackingEnabled = true&lt;br /&gt;
&lt;br /&gt;
local templatestyles = 'Module:Portal/styles.css'&lt;br /&gt;
&lt;br /&gt;
local yesno = require('Module:Yesno')&lt;br /&gt;
&lt;br /&gt;
-- Check whether to do tracking in this namespace&lt;br /&gt;
-- Returns true unless the page is one of the banned namespaces&lt;br /&gt;
local function checkTrackingNamespace()&lt;br /&gt;
	local thisPage = mw.title.getCurrentTitle()&lt;br /&gt;
	if (thisPage.namespace == 1) -- Talk&lt;br /&gt;
		or (thisPage.namespace == 2) -- User&lt;br /&gt;
		or (thisPage.namespace == 3) -- User talk&lt;br /&gt;
		or (thisPage.namespace == 5) -- Wikipedia talk&lt;br /&gt;
		or (thisPage.namespace == 7) -- File talk&lt;br /&gt;
		or (thisPage.namespace == 11) -- Template talk&lt;br /&gt;
		or (thisPage.namespace == 15) -- Category talk&lt;br /&gt;
		or (thisPage.namespace == 101) -- Portal talk&lt;br /&gt;
		or (thisPage.namespace == 109) -- Book talk&lt;br /&gt;
		or (thisPage.namespace == 118) -- Draft&lt;br /&gt;
		or (thisPage.namespace == 119) -- Draft talk&lt;br /&gt;
		or (thisPage.namespace == 829) -- Module talk&lt;br /&gt;
		then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Check whether to do tracking on this pagename&lt;br /&gt;
-- Returns false if the page title matches one of the banned strings&lt;br /&gt;
-- Otherwise returns true&lt;br /&gt;
local function checkTrackingPagename()&lt;br /&gt;
	local thisPage = mw.title.getCurrentTitle()&lt;br /&gt;
	local thisPageLC = mw.ustring.lower(thisPage.text)&lt;br /&gt;
	if (string.match(thisPageLC, &amp;quot;/archive&amp;quot;) ~= nil) then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	if (string.match(thisPageLC, &amp;quot;/doc&amp;quot;) ~= nil) then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	if (string.match(thisPageLC, &amp;quot;/test&amp;quot;) ~= nil) then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function matchImagePage(s)&lt;br /&gt;
	-- Finds the appropriate image subpage given a lower-case&lt;br /&gt;
	-- portal name plus the first letter of that portal name.&lt;br /&gt;
	if type(s) ~= 'string' or #s &amp;lt; 1 then return end&lt;br /&gt;
	local firstLetter = mw.ustring.sub(s, 1, 1)&lt;br /&gt;
	local imagePage&lt;br /&gt;
	if mw.ustring.find(firstLetter, '^[a-z]') then&lt;br /&gt;
		imagePage = 'Module:Portal/images/' .. firstLetter&lt;br /&gt;
	else&lt;br /&gt;
		imagePage = 'Module:Portal/images/other'&lt;br /&gt;
	end&lt;br /&gt;
	return mw.loadData(imagePage)[s]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getAlias(s)&lt;br /&gt;
	-- Gets an alias from the image alias data page.&lt;br /&gt;
	local aliasData = mw.loadData('Module:Portal/images/aliases')&lt;br /&gt;
	for portal, aliases in pairs(aliasData) do&lt;br /&gt;
		for _, alias in ipairs(aliases) do&lt;br /&gt;
			if alias == s then&lt;br /&gt;
				return portal&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getImageName(s)&lt;br /&gt;
	-- Gets the image name for a given string.&lt;br /&gt;
	local default = 'Portal-puzzle.svg|link=|alt='&lt;br /&gt;
	if type(s) ~= 'string' or #s &amp;lt; 1 then&lt;br /&gt;
		return default&lt;br /&gt;
	end&lt;br /&gt;
	s = mw.ustring.lower(s)&lt;br /&gt;
	return matchImagePage(s) or matchImagePage(getAlias(s)) or default&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function checkPortalExists(portal)&lt;br /&gt;
	return not (mw.title.makeTitle(100, portal).id == 0)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._portal(portals, args)&lt;br /&gt;
	-- This function builds the portal box used by the {{portal}} template.&lt;br /&gt;
	local root = mw.html.create('div')&lt;br /&gt;
		:attr('role', 'navigation')&lt;br /&gt;
		:attr('aria-label', 'Portals')&lt;br /&gt;
		:addClass('noprint portal plainlist')&lt;br /&gt;
		:addClass(args.left and 'tleft' or 'tright')&lt;br /&gt;
		:css('margin', args.margin or nil)&lt;br /&gt;
		:newline()&lt;br /&gt;
&lt;br /&gt;
	-- Tracking is on by default.&lt;br /&gt;
	-- It is disabled if any of the following is true&lt;br /&gt;
	-- 1/ the parameter &amp;quot;tracking&amp;quot; is set to 'no, 'n', or 'false'&lt;br /&gt;
	-- 2/ the current page fails the namespace tests in checkTrackingNamespace()&lt;br /&gt;
	-- 3/ the current page fails the pagename tests in checkTrackingPagename()&lt;br /&gt;
	trackingEnabled = yesno(args.tracking, trackingEnabled)&lt;br /&gt;
	if (checkTrackingNamespace() == false) then&lt;br /&gt;
		trackingEnabled = false&lt;br /&gt;
	end&lt;br /&gt;
	if (checkTrackingPagename() == false) then&lt;br /&gt;
		trackingEnabled = false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- If no portals have been specified, display an error and add the page to a tracking category.&lt;br /&gt;
	if not portals[1] then&lt;br /&gt;
		if yesno(args.nominimum) then&lt;br /&gt;
		-- if nominimum as been set to yes (or similar), omit the warning&lt;br /&gt;
			&lt;br /&gt;
		else&lt;br /&gt;
			root:wikitext('&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;No portals specified: please specify at least one portal&amp;lt;/strong&amp;gt;')&lt;br /&gt;
		end&lt;br /&gt;
		if (trackingEnabled) then&lt;br /&gt;
			root:wikitext('[[Category:Portal templates without a parameter]]')&lt;br /&gt;
		end&lt;br /&gt;
		return tostring(root)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- scan for nonexistent portals, if they exist remove them from the portals table. If redlinks=yes, then don't remove&lt;br /&gt;
	local portallen = #portals&lt;br /&gt;
	-- traverse the list backwards to ensure that no portals are missed (table.remove also moves down the portals in the list, so that the next portal isn't checked if going fowards.&lt;br /&gt;
	-- going backwards allows us to circumvent this issue&lt;br /&gt;
	for i=portallen,1,-1 do&lt;br /&gt;
		-- the use of pcall here catches any errors that may occour when attempting to locate pages when the page name is invalid&lt;br /&gt;
		-- if pcall returns true, then rerun the function to find if the page exists&lt;br /&gt;
		if not pcall(checkPortalExists, portals[i]) or not checkPortalExists(portals[i]) then&lt;br /&gt;
			-- Getting here means a redlinked portal has been found&lt;br /&gt;
			if yesno(args.redlinks) or (args.redlinks == 'include') then&lt;br /&gt;
				-- if redlinks as been set to yes (or similar), add the cleanup category and then break the loop before the portal is removed from the list&lt;br /&gt;
				if (trackingEnabled) then&lt;br /&gt;
					root:wikitext('[[Category:Portal templates with redlinked portals]]')&lt;br /&gt;
				end&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
			-- remove the portal (this does not happen if redlinks=yes)&lt;br /&gt;
			table.remove(portals,i)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- if the length of the table is different, then rows were removed from the table, so portals were removed. If this is the case add the cleanup category&lt;br /&gt;
	if not (portallen == #portals) then&lt;br /&gt;
		if (trackingEnabled) then&lt;br /&gt;
			if #portals == 0 then&lt;br /&gt;
				return '[[Category:Portal templates with all redlinked portals]]'&lt;br /&gt;
			else&lt;br /&gt;
				root:wikitext('[[Category:Portal templates with redlinked portals]]')&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Start the list. This corresponds to the start of the wikitext table in the old [[Template:Portal]].&lt;br /&gt;
	local listroot = root:tag('ul')&lt;br /&gt;
		:css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px') or nil)&lt;br /&gt;
&lt;br /&gt;
	-- Display the portals specified in the positional arguments.&lt;br /&gt;
	for _, portal in ipairs(portals) do&lt;br /&gt;
		local image = getImageName(portal)&lt;br /&gt;
&lt;br /&gt;
		-- Generate the html for the image and the portal name.&lt;br /&gt;
		listroot&lt;br /&gt;
			:newline()&lt;br /&gt;
			:tag('li')&lt;br /&gt;
				:tag('span')&lt;br /&gt;
					:wikitext(string.format('[[File:%s|32x28px|class=noviewer]]', image))&lt;br /&gt;
					:done()&lt;br /&gt;
				:tag('span')&lt;br /&gt;
					:wikitext(string.format('[[Portal:%s|%s%sportal]]', portal, portal, args['break'] and '&amp;lt;br /&amp;gt;' or ' '))&lt;br /&gt;
	end&lt;br /&gt;
	return tostring(root)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._image(portals)&lt;br /&gt;
	-- Wrapper function to allow getImageName() to be accessed through #invoke.&lt;br /&gt;
	local name = getImageName(portals[1])&lt;br /&gt;
	return name:match('^(.-)|') or name -- FIXME: use a more elegant way to separate borders etc. from the image name&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getAllImageTables()&lt;br /&gt;
	-- Returns an array containing all image subpages (minus aliases) as loaded by mw.loadData.&lt;br /&gt;
	local images = {}&lt;br /&gt;
	for i, subpage in ipairs{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'other'} do&lt;br /&gt;
		images[i] = mw.loadData('Module:Portal/images/' .. subpage)&lt;br /&gt;
	end&lt;br /&gt;
	return images&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._displayAll(portals, args)&lt;br /&gt;
	-- This function displays all portals that have portal images. This function is for maintenance purposes and should not be used in&lt;br /&gt;
	-- articles, for two reasons: 1) there are over 1500 portals with portal images, and 2) the module doesn't record how the portal&lt;br /&gt;
	-- names are capitalized, so the portal links may be broken.&lt;br /&gt;
	local lang = mw.language.getContentLanguage()&lt;br /&gt;
	local count = 1&lt;br /&gt;
	for _, imageTable in ipairs(getAllImageTables()) do&lt;br /&gt;
		for portal in pairs(imageTable) do&lt;br /&gt;
			portals[count] = lang:ucfirst(portal)&lt;br /&gt;
			count = count + 1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return p._portal(portals, args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._imageDupes()&lt;br /&gt;
	-- This function searches the image subpages to find duplicate images. If duplicate images exist, it is not necessarily a bad thing,&lt;br /&gt;
	-- as different portals might just happen to choose the same image. However, this function is helpful in identifying images that&lt;br /&gt;
	-- should be moved to a portal alias for ease of maintenance.&lt;br /&gt;
	local exists, dupes = {}, {}&lt;br /&gt;
	for _, imageTable in ipairs(getAllImageTables()) do&lt;br /&gt;
		for portal, image in pairs(imageTable) do&lt;br /&gt;
			if not exists[image] then&lt;br /&gt;
				exists[image] = portal&lt;br /&gt;
			else&lt;br /&gt;
				table.insert(dupes, string.format('The image &amp;quot;[[:File:%s|%s]]&amp;quot; is used for both portals &amp;quot;%s&amp;quot; and &amp;quot;%s&amp;quot;.', image, image, exists[image], portal))&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if #dupes &amp;lt; 1 then&lt;br /&gt;
		return 'No duplicate images found.'&lt;br /&gt;
	else&lt;br /&gt;
		return 'The following duplicate images were found:\n* ' .. table.concat(dupes, '\n* ')&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function processPortalArgs(args)&lt;br /&gt;
	-- This function processes a table of arguments and returns two tables: an array of portal names for processing by ipairs, and a table of&lt;br /&gt;
	-- the named arguments that specify style options, etc. We need to use ipairs because we want to list all the portals in the order&lt;br /&gt;
	-- they were passed to the template, but we also want to be able to deal with positional arguments passed explicitly, for example&lt;br /&gt;
	-- {{portal|2=Politics}}. The behaviour of ipairs is undefined if nil values are present, so we need to make sure they are all removed.&lt;br /&gt;
	args = type(args) == 'table' and args or {}&lt;br /&gt;
	local portals = {}&lt;br /&gt;
	local namedArgs = {}&lt;br /&gt;
	for k, v in pairs(args) do&lt;br /&gt;
		if type(k) == 'number' and type(v) == 'string' then -- Make sure we have no non-string portal names.&lt;br /&gt;
			table.insert(portals, k)&lt;br /&gt;
		elseif type(k) ~= 'number' then&lt;br /&gt;
			namedArgs[k] = v&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	table.sort(portals)&lt;br /&gt;
	for i, v in ipairs(portals) do&lt;br /&gt;
		portals[i] = args[v]&lt;br /&gt;
	end&lt;br /&gt;
	return portals, namedArgs&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function makeWrapper(funcName)&lt;br /&gt;
	-- Processes external arguments and sends them to the other functions.&lt;br /&gt;
	return function (frame)&lt;br /&gt;
		-- If called via #invoke, use the args passed into the invoking&lt;br /&gt;
		-- template, or the args passed to #invoke if any exist. Otherwise&lt;br /&gt;
		-- assume args are being passed directly in from the debug console&lt;br /&gt;
		-- or from another Lua module.&lt;br /&gt;
		local origArgs&lt;br /&gt;
		if type(frame.getParent) == 'function' then&lt;br /&gt;
			origArgs = frame:getParent().args&lt;br /&gt;
			for k, v in pairs(frame.args) do&lt;br /&gt;
				origArgs = frame.args&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			origArgs = frame&lt;br /&gt;
		end&lt;br /&gt;
		-- Trim whitespace and remove blank arguments.&lt;br /&gt;
		local args = {}&lt;br /&gt;
		for k, v in pairs(origArgs) do&lt;br /&gt;
			if type(v) == 'string' then&lt;br /&gt;
				v = mw.text.trim(v)&lt;br /&gt;
			end&lt;br /&gt;
			if v ~= '' then&lt;br /&gt;
				args[k] = v&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		local results = ''&lt;br /&gt;
		if funcName == '_portal' or funcName == '_displayAll' then&lt;br /&gt;
			results = frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} }&lt;br /&gt;
		end&lt;br /&gt;
		return results .. p[funcName](processPortalArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments.&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
for _, funcName in ipairs{'portal', 'image', 'imageDupes', 'displayAll'} do&lt;br /&gt;
	p[funcName] = makeWrapper('_' .. funcName)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Primefac</name></author>
		
	</entry>
</feed>