<?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%3APortal</id>
	<title>Module:Portal - 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%3APortal"/>
	<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Portal&amp;action=history"/>
	<updated>2026-04-04T22:32:26Z</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:Portal&amp;diff=6324&amp;oldid=prev</id>
		<title>&gt;Pppery: Changed protection settings for &quot;Module:Portal&quot;: Up to full due to 9 million transclusions - the image modules are split by letter and can stay TPE ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://the-democratika.com/wiki/index.php?title=Module:Portal&amp;diff=6324&amp;oldid=prev"/>
		<updated>2024-11-25T21:42:52Z</updated>

		<summary type="html">&lt;p&gt;Changed protection settings for &amp;quot;&lt;a href=&quot;/wiki/index.php/Module:Portal&quot; title=&quot;Module:Portal&quot;&gt;Module:Portal&lt;/a&gt;&amp;quot;: Up to full due to 9 million transclusions - the image modules are split by letter and can stay TPE ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))&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;
-- determine whether we&amp;#039;re being called from a sandbox&lt;br /&gt;
local isSandbox = mw.getCurrentFrame():getTitle():find(&amp;#039;sandbox&amp;#039;, 1, true)&lt;br /&gt;
local sandbox = isSandbox and &amp;#039;/sandbox&amp;#039; or &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
local function sandboxVersion(s)&lt;br /&gt;
	return isSandbox and s..&amp;#039;-sand&amp;#039; or s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local templatestyles = &amp;#039;Module:Portal&amp;#039;..sandbox..&amp;#039;/styles.css&amp;#039;&lt;br /&gt;
&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
-- List of non-talk namespaces which should not be tracked (Talk pages are never tracked)&lt;br /&gt;
local badNamespaces = {&amp;#039;user&amp;#039;,&amp;#039;template&amp;#039;,&amp;#039;draft&amp;#039;,&amp;#039;wikipedia&amp;#039;}&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 checkTracking(title)&lt;br /&gt;
	local thisPage = title or mw.title.getCurrentTitle()&lt;br /&gt;
	if thisPage.isTalkPage then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	local ns = thisPage.nsText:lower()&lt;br /&gt;
	for _, v in ipairs(badNamespaces) do&lt;br /&gt;
		if ns == v then&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return true&lt;br /&gt;
end&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) ~= &amp;#039;string&amp;#039; 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, &amp;#039;^[a-z]&amp;#039;) then&lt;br /&gt;
		imagePage = &amp;#039;Module:Portal/images/&amp;#039; .. firstLetter .. sandbox&lt;br /&gt;
	else&lt;br /&gt;
		imagePage = &amp;#039;Module:Portal/images/other&amp;#039; .. sandbox&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(&amp;#039;Module:Portal/images/aliases&amp;#039;..sandbox)&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 defaultImage = &amp;#039;Portal-puzzle.svg|link=|alt=&amp;#039;&lt;br /&gt;
&lt;br /&gt;
local function getImageName(s)&lt;br /&gt;
	-- Gets the image name for a given string.&lt;br /&gt;
	if type(s) ~= &amp;#039;string&amp;#039; or #s &amp;lt; 1 then&lt;br /&gt;
		return defaultImage&lt;br /&gt;
	end&lt;br /&gt;
	s = mw.ustring.lower(s)&lt;br /&gt;
	local image = matchImagePage(s) or matchImagePage(getAlias(s)) or defaultImage&lt;br /&gt;
	image = mw.ustring.gsub(image,&amp;#039;^File:&amp;#039;,&amp;#039;&amp;#039;) --- strip mistaken leading File: or Image:&lt;br /&gt;
	image = mw.ustring.gsub(image,&amp;#039;^Image:&amp;#039;,&amp;#039;&amp;#039;)&lt;br /&gt;
	return image&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function exists(title) &lt;br /&gt;
	local success, exists = pcall(function() return title.exists end)&lt;br /&gt;
	-- If success = false, then we&amp;#039;re out of expensive parser function calls and can&amp;#039;t check whether it exists&lt;br /&gt;
	-- in that case, don&amp;#039;t throw a Lua error&lt;br /&gt;
	return not success or exists&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 -- Function to check argument portals for errors, generate tracking categories if needed&lt;br /&gt;
 --     Function first checks for too few/many portals provided&lt;br /&gt;
 --     Then checks the portal list to purge any portals that don&amp;#039;t exist&lt;br /&gt;
 -- Arguments:&lt;br /&gt;
 --   portals: raw list of portals&lt;br /&gt;
 --   args.tracking: is tracking requested? (will not track on bad titles or namespaces)&lt;br /&gt;
 --   args.redlinks: should redlinks be displayed?&lt;br /&gt;
 --   args.minPortals: minimum number of portal arguments&lt;br /&gt;
 --   args.maxPortals: maximum number of portal arguments&lt;br /&gt;
 -- Returns:&lt;br /&gt;
 --   portals = list of portals, with redlinks purged (if args.redlinks=false)&lt;br /&gt;
 --   trackingCat = possible tracking category&lt;br /&gt;
 --   errorMsg = error message&lt;br /&gt;
function p._checkPortals(portals, args)&lt;br /&gt;
	local trackingCat = &amp;#039;&amp;#039;&lt;br /&gt;
	local errMsg = nil&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 &amp;#039;no, &amp;#039;n&amp;#039;, or &amp;#039;false&amp;#039;&lt;br /&gt;
	-- 2/ the current page fails the namespace or pagename tests &lt;br /&gt;
	local trackingEnabled = args.tracking and checkTracking()&lt;br /&gt;
	&lt;br /&gt;
	args.minPortals = args.minPortals or 1&lt;br /&gt;
	args.maxPortals = args.maxPortals or -1&lt;br /&gt;
	-- check for too few portals&lt;br /&gt;
	if #portals &amp;lt; args.minPortals then&lt;br /&gt;
		errMsg = &amp;#039;please specify at least &amp;#039;..args.minPortals..&amp;#039; portal&amp;#039;..(args.minPortals &amp;gt; 1 and &amp;#039;s&amp;#039; or &amp;#039;&amp;#039;)&lt;br /&gt;
		trackingCat = (trackingEnabled and &amp;#039;[[Category:Portal templates with too few portals]]&amp;#039; or &amp;#039;&amp;#039;)&lt;br /&gt;
		return portals, trackingCat, errMsg&lt;br /&gt;
	end&lt;br /&gt;
	-- check for too many portals&lt;br /&gt;
	if args.maxPortals &amp;gt;= 0 and #portals &amp;gt; args.maxPortals then&lt;br /&gt;
		errMsg = &amp;#039;too many portals (maximum = &amp;#039;..args.maxPortals..&amp;#039;)&amp;#039;&lt;br /&gt;
		trackingCat = (trackingEnabled and &amp;#039;[[Category:Portal templates with too many portals]]&amp;#039; or &amp;#039;&amp;#039;)&lt;br /&gt;
		return portals, trackingCat, errMsg&lt;br /&gt;
	end&lt;br /&gt;
	if not args.redlinks or trackingEnabled then&lt;br /&gt;
		-- make new list of portals that exist&lt;br /&gt;
		local existingPortals = {}&lt;br /&gt;
		for _, portal in ipairs(portals) do&lt;br /&gt;
			local portalTitle = mw.title.new(portal,&amp;quot;Portal&amp;quot;)&lt;br /&gt;
			-- if portal exists, put it into list&lt;br /&gt;
			if portalTitle and exists(portalTitle) then&lt;br /&gt;
				table.insert(existingPortals,portal)&lt;br /&gt;
			-- otherwise set tracking cat&lt;br /&gt;
			elseif trackingEnabled then&lt;br /&gt;
				trackingCat = &amp;quot;[[Category:Portal templates with redlinked portals]]&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		-- If redlinks is off, use portal list purged of redlinks&lt;br /&gt;
		portals = args.redlinks and portals or existingPortals&lt;br /&gt;
		-- if nothing left after purge, set tracking cat&lt;br /&gt;
		if #portals == 0 and trackingEnabled then&lt;br /&gt;
			trackingCat = trackingCat..&amp;quot;[[Category:Pages with empty portal template]]&amp;quot; &lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return portals, trackingCat, errMsg&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function portalBox(args)&lt;br /&gt;
	return mw.html.create(&amp;#039;ul&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;role&amp;#039;, &amp;#039;navigation&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;aria-label&amp;#039;, &amp;#039;Portals&amp;#039;)&lt;br /&gt;
		:addClass(&amp;#039;noprint&amp;#039;)&lt;br /&gt;
		:addClass(args.error and &amp;#039;&amp;#039; or sandboxVersion(&amp;#039;portalbox&amp;#039;))&lt;br /&gt;
		:addClass(args.border and sandboxVersion(&amp;#039;portalborder&amp;#039;) or &amp;#039;&amp;#039;)&lt;br /&gt;
		:addClass(sandboxVersion(args.left and &amp;#039;portalleft&amp;#039; or &amp;#039;portalright&amp;#039;))&lt;br /&gt;
		:css(&amp;#039;margin&amp;#039;, args.margin or nil)&lt;br /&gt;
		:newline()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function fillBox(root, contents)&lt;br /&gt;
	for _, item in ipairs(contents) do&lt;br /&gt;
		local entry = root:tag(&amp;#039;li&amp;#039;)&lt;br /&gt;
		entry:addClass(sandboxVersion(&amp;#039;portalbox-entry&amp;#039;))&lt;br /&gt;
		local image = entry:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
		image:addClass(sandboxVersion(&amp;#039;portalbox-image&amp;#039;))&lt;br /&gt;
		image:wikitext(item[1])&lt;br /&gt;
		local link = entry:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
		link:addClass(sandboxVersion(&amp;#039;portalbox-link&amp;#039;))&lt;br /&gt;
		link:wikitext(item[2])&lt;br /&gt;
	end&lt;br /&gt;
	return root&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;
	&lt;br /&gt;
	-- Normalize all arguments&lt;br /&gt;
	if args.redlinks == &amp;#039;include&amp;#039; then args.redlinks = true end&lt;br /&gt;
	args.addBreak = args[&amp;#039;break&amp;#039;]&lt;br /&gt;
	for key, default in pairs({left=false,tracking=true,nominimum=false,&lt;br /&gt;
		                       redlinks=false,addBreak=false,border=true}) do&lt;br /&gt;
		if args[key] == nil then args[key] = default end&lt;br /&gt;
		args[key] = yesno(args[key], default)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local root = portalBox(args)&lt;br /&gt;
&lt;br /&gt;
	local trackingCat = &amp;#039;&amp;#039;&lt;br /&gt;
	local errMsg = nil&lt;br /&gt;
	args.minPortals = args.nominimum and 0 or 1&lt;br /&gt;
	args.maxPortals = -1&lt;br /&gt;
	portals, trackingCat, errMsg = p._checkPortals(portals, args)&lt;br /&gt;
	root:wikitext(trackingCat)&lt;br /&gt;
	-- if error message, put it in the box and return&lt;br /&gt;
	if errMsg then&lt;br /&gt;
		if args.border then -- suppress error message when border=no&lt;br /&gt;
			args.error = true  -- recreate box without fancy formatting&lt;br /&gt;
			root = portalBox(args)&lt;br /&gt;
			root:wikitext(trackingCat)&lt;br /&gt;
			local errTag = root:tag(&amp;#039;strong&amp;#039;)&lt;br /&gt;
			errTag:addClass(&amp;#039;error&amp;#039;)&lt;br /&gt;
			errTag:css(&amp;#039;padding&amp;#039;,&amp;#039;0.2em&amp;#039;)&lt;br /&gt;
			errTag:wikitext(&amp;#039;Error: &amp;#039;..errMsg)&lt;br /&gt;
		end&lt;br /&gt;
		return tostring(root)&lt;br /&gt;
	end&lt;br /&gt;
	-- if no portals (and no error), just return tracking category&lt;br /&gt;
	if #portals == 0 then&lt;br /&gt;
		return trackingCat&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local contents = {}&lt;br /&gt;
	-- Display the portals specified in the positional arguments.&lt;br /&gt;
	local defaultUsed = nil&lt;br /&gt;
	for _, portal in ipairs(portals) do&lt;br /&gt;
		local portalImage = getImageName(portal)&lt;br /&gt;
		if portalImage == defaultImage then&lt;br /&gt;
			defaultUsed = portal&lt;br /&gt;
		end&lt;br /&gt;
		local image = string.format(&amp;#039;[[File:%s|32x28px|class=noviewer]]&amp;#039;,&lt;br /&gt;
			portalImage)&lt;br /&gt;
		local link = string.format(&amp;#039;[[Portal:%s|%s%sportal]]&amp;#039;,&lt;br /&gt;
			portal, portal, args.addBreak and &amp;#039;&amp;lt;br /&amp;gt;&amp;#039; or &amp;#039; &amp;#039;)&lt;br /&gt;
		table.insert(contents, {image, link})&lt;br /&gt;
	end&lt;br /&gt;
	if defaultUsed and args.tracking and checkTracking() then&lt;br /&gt;
		local cat = string.format(&amp;#039;[[Category:Portal templates with default image|%s]]&amp;#039;,&lt;br /&gt;
			                      defaultUsed)&lt;br /&gt;
		root:wikitext(cat)&lt;br /&gt;
	end&lt;br /&gt;
	return tostring(fillBox(root, contents))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._demo(imageList, args)&lt;br /&gt;
	for key, default in pairs({left=false,border=true}) do&lt;br /&gt;
		if args[key] == nil then args[key] = default end&lt;br /&gt;
		args[key] = yesno(args[key], default)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local root = portalBox(args)&lt;br /&gt;
&lt;br /&gt;
	local contents = {}&lt;br /&gt;
	-- Display the portals specified in the positional arguments.&lt;br /&gt;
	for _, fn in ipairs(imageList) do&lt;br /&gt;
		local image = string.format(&amp;#039;[[File:%s|32x28px|class=noviewer]]&amp;#039;,fn)&lt;br /&gt;
		local link = string.format(&amp;#039;[[:File:%s|%s]]&amp;#039;,fn,fn)&lt;br /&gt;
		table.insert(contents,{image,link})&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return tostring(fillBox(root,contents))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._image(portal,keep)&lt;br /&gt;
	-- Wrapper function to allow getImageName() to be accessed through #invoke.&lt;br /&gt;
	-- backward compatibility: if table passed, take first element&lt;br /&gt;
	if type(portal) == &amp;#039;table&amp;#039; then&lt;br /&gt;
		portal = portal[1]&lt;br /&gt;
	end&lt;br /&gt;
	local name = getImageName(portal)&lt;br /&gt;
	-- If keep is yes (or equivalent), then allow all metadata (like image borders) to be returned&lt;br /&gt;
	local keepargs = yesno(keep)&lt;br /&gt;
	local args = mw.text.split(name, &amp;quot;|&amp;quot;, true)&lt;br /&gt;
	local result = {args[1]}  -- the filename always comes first&lt;br /&gt;
	local category = &amp;#039;&amp;#039;&lt;br /&gt;
	-- parse name, looking for category arguments&lt;br /&gt;
	for i = 2,#args do&lt;br /&gt;
		local m = mw.ustring.match(args[i],  &amp;quot;^%s*category%s*=&amp;quot;)&lt;br /&gt;
		if keepargs or m then&lt;br /&gt;
			table.insert(result, args[i])&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- reassemble arguments&lt;br /&gt;
	return table.concat(result,&amp;quot;|&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function getAllImageTable()&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{&amp;#039;a&amp;#039;, &amp;#039;b&amp;#039;, &amp;#039;c&amp;#039;, &amp;#039;d&amp;#039;, &amp;#039;e&amp;#039;, &amp;#039;f&amp;#039;, &amp;#039;g&amp;#039;, &amp;#039;h&amp;#039;, &amp;#039;i&amp;#039;, &amp;#039;j&amp;#039;, &amp;#039;k&amp;#039;, &amp;#039;l&amp;#039;, &amp;#039;m&amp;#039;, &amp;#039;n&amp;#039;, &amp;#039;o&amp;#039;, &amp;#039;p&amp;#039;, &amp;#039;q&amp;#039;, &amp;#039;r&amp;#039;, &amp;#039;s&amp;#039;, &amp;#039;t&amp;#039;, &amp;#039;u&amp;#039;, &amp;#039;v&amp;#039;, &amp;#039;w&amp;#039;, &amp;#039;x&amp;#039;, &amp;#039;y&amp;#039;, &amp;#039;z&amp;#039;, &amp;#039;other&amp;#039;} do&lt;br /&gt;
		local imageTable = mw.loadData(&amp;#039;Module:Portal/images/&amp;#039; .. subpage .. sandbox)&lt;br /&gt;
		for portal, image in pairs(imageTable) do&lt;br /&gt;
			local args = mw.text.split(image,&amp;quot;|&amp;quot;)&lt;br /&gt;
			images[portal] = args[1] -- just use image filename&lt;br /&gt;
		end&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&amp;#039;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;
	portals = portals or {}&lt;br /&gt;
	for portal in pairs(getAllImageTable()) do&lt;br /&gt;
		table.insert(portals,lang:ucfirst(portal))&lt;br /&gt;
	end&lt;br /&gt;
	table.sort(portals)&lt;br /&gt;
	args.redlinks = args.redlinks or &amp;quot;yes&amp;quot;&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 portal, image in pairs(getAllImageTable()) 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(&amp;#039;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;.&amp;#039;, image, image, exists[image], portal))&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if #dupes &amp;lt; 1 then&lt;br /&gt;
		return &amp;#039;No duplicate images found.&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;#039;The following duplicate images were found:\n* &amp;#039; .. table.concat(dupes, &amp;#039;\n* &amp;#039;)&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) == &amp;#039;table&amp;#039; 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) == &amp;#039;number&amp;#039; and type(v) == &amp;#039;string&amp;#039; then -- Make sure we have no non-string portal names.&lt;br /&gt;
			table.insert(portals, k)&lt;br /&gt;
		elseif type(k) ~= &amp;#039;number&amp;#039; 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;
-- Entry point for sorting portals from other named arguments&lt;br /&gt;
function p._processPortalArgs(args)&lt;br /&gt;
	return processPortalArgs(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.image(frame)&lt;br /&gt;
	local origArgs = getArgs(frame)&lt;br /&gt;
	local portals, args = processPortalArgs(origArgs)&lt;br /&gt;
	return p._image(portals[1],args.border)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.demo(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	local styles = frame:extensionTag{ name = &amp;#039;templatestyles&amp;#039;, args = { src = templatestyles} }&lt;br /&gt;
	return styles..p._demo(args,args)&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;
		-- Also: trim whitespace and remove blank arguments&lt;br /&gt;
		local origArgs = getArgs(frame)&lt;br /&gt;
		-- create two tables to pass to func: an array of portal names, and a table of named arguments.&lt;br /&gt;
		local portals, args = processPortalArgs(origArgs)&lt;br /&gt;
		local results = &amp;#039;&amp;#039;&lt;br /&gt;
		if funcName == &amp;#039;_portal&amp;#039; or funcName == &amp;#039;_displayAll&amp;#039; then&lt;br /&gt;
			results = frame:extensionTag{ name = &amp;#039;templatestyles&amp;#039;, args = { src = templatestyles} }&lt;br /&gt;
		end&lt;br /&gt;
		return results .. p[funcName](portals, args) &lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
for _, funcName in ipairs{&amp;#039;portal&amp;#039;, &amp;#039;imageDupes&amp;#039;, &amp;#039;displayAll&amp;#039;} do&lt;br /&gt;
	p[funcName] = makeWrapper(&amp;#039;_&amp;#039; .. funcName)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>&gt;Pppery</name></author>
	</entry>
</feed>