<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.tachyony.co.uk/w/index.php?action=history&amp;feed=atom&amp;title=Module%3APortal_bar</id>
	<title>Module:Portal bar - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.tachyony.co.uk/w/index.php?action=history&amp;feed=atom&amp;title=Module%3APortal_bar"/>
	<link rel="alternate" type="text/html" href="https://wiki.tachyony.co.uk/w/index.php?title=Module:Portal_bar&amp;action=history"/>
	<updated>2026-05-15T21:53:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://wiki.tachyony.co.uk/w/index.php?title=Module:Portal_bar&amp;diff=4469&amp;oldid=prev</id>
		<title>Tachyony: Created page with &quot;-- This module implements {{portal bar}}.  require(&#039;Module:No globals&#039;)  local getImageName = require( &#039;Module:Portal&#039; ).image local yesno = require( &#039;Module:Yesno&#039; ) local getArgs = require(&#039;Module:Arguments&#039;).getArgs local p = {}  local function sandbox(args, s) 	return args.sandbox and s..&quot;-sand&quot; or s end  local function checkPortalExists(portal) 	return not (mw.title.makeTitle(100, portal).id == 0) end  -- Check whether to do tracking in this namespace -- Returns tru...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.tachyony.co.uk/w/index.php?title=Module:Portal_bar&amp;diff=4469&amp;oldid=prev"/>
		<updated>2021-12-19T05:17:07Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;-- This module implements {{portal bar}}.  require(&amp;#039;Module:No globals&amp;#039;)  local getImageName = require( &amp;#039;Module:Portal&amp;#039; ).image local yesno = require( &amp;#039;Module:Yesno&amp;#039; ) local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs local p = {}  local function sandbox(args, s) 	return args.sandbox and s..&amp;quot;-sand&amp;quot; or s end  local function checkPortalExists(portal) 	return not (mw.title.makeTitle(100, portal).id == 0) end  -- Check whether to do tracking in this namespace -- Returns tru...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module implements {{portal bar}}.&lt;br /&gt;
&lt;br /&gt;
require(&amp;#039;Module:No globals&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local getImageName = require( &amp;#039;Module:Portal&amp;#039; ).image&lt;br /&gt;
local yesno = require( &amp;#039;Module:Yesno&amp;#039; )&lt;br /&gt;
local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local function sandbox(args, s)&lt;br /&gt;
	return args.sandbox and s..&amp;quot;-sand&amp;quot; or s&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;
-- 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 isTrackedNamespace()&lt;br /&gt;
	local thisPageNS = mw.title.getCurrentTitle().namespace&lt;br /&gt;
	return thisPageNS ~= 1 -- Talk&lt;br /&gt;
		and thisPageNS ~= 2 -- User&lt;br /&gt;
		and thisPageNS ~= 3 -- User talk&lt;br /&gt;
		and thisPageNS ~= 5 -- Wikipedia talk&lt;br /&gt;
		and thisPageNS ~= 7 -- File talk&lt;br /&gt;
		and thisPageNS ~= 11 -- Template talk&lt;br /&gt;
		and thisPageNS ~= 15 -- Category talk&lt;br /&gt;
		and thisPageNS ~= 101 -- Portal talk&lt;br /&gt;
		and thisPageNS ~= 118 -- Draft&lt;br /&gt;
		and thisPageNS ~= 119 -- Draft talk&lt;br /&gt;
		and thisPageNS ~= 829 -- Module talk&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 isTrackedPagename()&lt;br /&gt;
	local thisPageLC = mw.ustring.lower(mw.title.getCurrentTitle().text)&lt;br /&gt;
	local match = string.match&lt;br /&gt;
	return match(thisPageLC, &amp;quot;/archive&amp;quot;) == nil&lt;br /&gt;
		and match(thisPageLC, &amp;quot;/doc&amp;quot;) == nil&lt;br /&gt;
		and match(thisPageLC, &amp;quot;/test&amp;quot;) == nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Builds the portal bar used by {{portal bar}}.&lt;br /&gt;
function p._main( portals, args )&lt;br /&gt;
	&lt;br /&gt;
	-- Don&amp;#039;t display a blank navbox if no portals were specified.&lt;br /&gt;
	if #portals &amp;lt; 1 then return &amp;#039;&amp;#039; end&lt;br /&gt;
	&lt;br /&gt;
	args.sandbox = yesno(args.sandbox)&lt;br /&gt;
	local nav = mw.html.create( &amp;#039;div&amp;#039; )&lt;br /&gt;
		:addClass(sandbox(args,&amp;#039;portal-bar&amp;#039;))&lt;br /&gt;
		:addClass( &amp;#039;noprint metadata nomobile&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;
	if yesno( args.border ) == false then&lt;br /&gt;
		nav&lt;br /&gt;
			:addClass(sandbox(args,&amp;#039;portal-bar-unbordered&amp;#039;))&lt;br /&gt;
	else&lt;br /&gt;
		nav&lt;br /&gt;
			:addClass(sandbox(args,&amp;#039;portal-bar-bordered&amp;#039;))&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local trackingEnabled = true&lt;br /&gt;
	local tracking = args.tracking&lt;br /&gt;
	if (tracking == &amp;#039;no&amp;#039; or tracking == &amp;#039;n&amp;#039; or tracking == &amp;#039;false&amp;#039;) or&lt;br /&gt;
		not isTrackedNamespace() or not isTrackedPagename() then&lt;br /&gt;
		trackingEnabled = false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- TODO: This used to say &amp;#039;if no portals are specified&amp;#039;, but we return early&lt;br /&gt;
	-- above. Someone should check whether this is really &amp;#039;portals[1]&amp;#039; or #portals &amp;lt; 0.&lt;br /&gt;
	-- If the first portal is not specified,&lt;br /&gt;
	-- display an error and add the page to a tracking category.&lt;br /&gt;
	if not portals[1] then&lt;br /&gt;
		local nominimum = args.nominimum&lt;br /&gt;
		local warning = mw.html.create()&lt;br /&gt;
		if nominimum ~= &amp;#039;yes&amp;#039; and nominimum ~= &amp;#039;y&amp;#039; and nominimum ~= &amp;#039;true&amp;#039; then&lt;br /&gt;
			warning:tag(&amp;#039;strong&amp;#039;)&lt;br /&gt;
				:addClass(&amp;#039;error&amp;#039;)&lt;br /&gt;
				:wikitext(&amp;#039;No portals specified: please specify at least one portal&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		if trackingEnabled then&lt;br /&gt;
			warning:wikitext(&amp;#039;[[Category:Portal templates without a parameter]]&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		return tostring(warning)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- scan for nonexistent portals, if they exist remove them from the portals&lt;br /&gt;
	-- table. If redlinks=yes, then don&amp;#039;t remove&lt;br /&gt;
	local portallen = #portals&lt;br /&gt;
	-- traverse the list backwards to ensure that no portals are missed&lt;br /&gt;
	-- (table.remove also moves down the portals in the list, so that the next&lt;br /&gt;
	-- portal isn&amp;#039;t checked if going fowards. going backwards allows us to&lt;br /&gt;
	-- 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&lt;br /&gt;
		-- attempting to locate pages when the page name is invalid. if pcall&lt;br /&gt;
		-- 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;
			local redlinks = args.redlinks&lt;br /&gt;
			if redlinks == &amp;#039;yes&amp;#039; or redlinks == &amp;#039;y&amp;#039; or redlinks == &amp;#039;true&amp;#039; or redlinks == &amp;#039;include&amp;#039; then&lt;br /&gt;
				-- if redlinks as been set to yes (or similar), add the cleanup&lt;br /&gt;
				-- category and then break the loop before the portal is removed&lt;br /&gt;
				-- from the list&lt;br /&gt;
				if trackingEnabled then&lt;br /&gt;
					nav:wikitext(&amp;#039;[[Category:Portal templates with redlinked portals]]&amp;#039;)&lt;br /&gt;
				end&lt;br /&gt;
				-- TODO: This looks buggy given the comment above; we will always&lt;br /&gt;
				-- break if redlinks are yes, whether or not tracking is enabled&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&lt;br /&gt;
	-- table, so portals were removed. If this is the case add the cleanup category&lt;br /&gt;
	if portallen ~= #portals then&lt;br /&gt;
		if #portals == 0 then&lt;br /&gt;
        	if trackingEnabled then&lt;br /&gt;
				return &amp;#039;[[Category:Portal templates with all redlinked portals]]&amp;#039;&lt;br /&gt;
			else&lt;br /&gt;
				return &amp;quot;&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
        end&lt;br /&gt;
		if trackingEnabled then&lt;br /&gt;
			nav:wikitext(&amp;#039;[[Category:Portal templates with redlinked portals]]&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local header = nav:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
	header:addClass(sandbox(args,&amp;#039;portal-bar-header&amp;#039;))&lt;br /&gt;
	header:wikitext(&amp;#039;[[Wikipedia:Contents/Portals|Portal]]&amp;#039;)&lt;br /&gt;
	if #portals &amp;gt; 1 then&lt;br /&gt;
		header:wikitext(&amp;#039;s&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	header:wikitext(&amp;#039;:&amp;#039;)&lt;br /&gt;
	local container = nav:tag(&amp;#039;div&amp;#039;)&lt;br /&gt;
	container:addClass(sandbox(args,&amp;#039;portal-bar-content&amp;#039;))&lt;br /&gt;
	for _, portal in ipairs( portals ) do&lt;br /&gt;
		container&lt;br /&gt;
			:tag( &amp;#039;div&amp;#039; )&lt;br /&gt;
			:addClass(sandbox(args,&amp;#039;portal-bar-item&amp;#039;))&lt;br /&gt;
				:tag( &amp;#039;span&amp;#039; )&lt;br /&gt;
					:addClass(sandbox(args,&amp;#039;portal-bar-logo&amp;#039;))&lt;br /&gt;
					:wikitext( string.format(&lt;br /&gt;
						&amp;#039;[[File:%s|21x19px|alt=]]&amp;#039;, getImageName{ portal }&lt;br /&gt;
					) )&lt;br /&gt;
					:done()&lt;br /&gt;
				:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
					:addClass(sandbox(args,&amp;#039;portal-bar-link&amp;#039;))&lt;br /&gt;
					:wikitext( string.format(&amp;#039;[[Portal:%s|%s]]&amp;#039;, portal, portal))&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local styleFile = &amp;#039;Module:Portal bar/&amp;#039;&lt;br /&gt;
	styleFile = styleFile..(args.sandbox and &amp;#039;sandbox/&amp;#039; or &amp;#039;&amp;#039;)&lt;br /&gt;
	styleFile = styleFile..&amp;#039;styles.css&amp;#039;&lt;br /&gt;
	return mw.getCurrentFrame():extensionTag{&lt;br /&gt;
		name = &amp;#039;templatestyles&amp;#039;, args = { src = styleFile }&lt;br /&gt;
	} .. tostring( nav )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Processes external arguments and sends them to the other functions.&lt;br /&gt;
function p.main( frame )&lt;br /&gt;
	local origArgs = getArgs(frame)&lt;br /&gt;
	-- Process the args to make an array of portal names that can be used with&lt;br /&gt;
	-- ipairs. We need to use ipairs because we want to list all the portals in&lt;br /&gt;
	-- the order they were passed to the template, but we also want to be able&lt;br /&gt;
	-- to deal with positional arguments passed explicitly, for example&lt;br /&gt;
	-- {{portal|2=Politics}}. The behaviour of ipairs is undefined if nil values&lt;br /&gt;
	-- are present, so we need to make sure they are all removed.&lt;br /&gt;
	local portals, args = {}, {}&lt;br /&gt;
	for k, v in pairs( origArgs ) do&lt;br /&gt;
		-- Make sure we have no non-string portal names.&lt;br /&gt;
		if type( k ) == &amp;#039;number&amp;#039; and type( v ) == &amp;#039;string&amp;#039; then&lt;br /&gt;
			table.insert(portals, k)&lt;br /&gt;
		elseif type( k ) ~= &amp;#039;number&amp;#039; then -- Separate named arguments from portals.&lt;br /&gt;
			args[ 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;
		-- Swap keys with values&lt;br /&gt;
		portals[ i ] = origArgs[ v ]&lt;br /&gt;
	end&lt;br /&gt;
	return p._main( portals, args )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Tachyony</name></author>
	</entry>
</feed>