<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FGodNey</id>
	<title>Module:Sandbox/GodNey - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FGodNey"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/GodNey&amp;action=history"/>
	<updated>2026-07-31T13:52:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/GodNey&amp;diff=145468&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/GodNey&amp;diff=145468&amp;oldid=prev"/>
		<updated>2022-10-23T21:08:25Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/research/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&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;strict&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 p = {}&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;
	local nav = mw.html.create( &amp;#039;ul&amp;#039; )&lt;br /&gt;
		:addClass( &amp;#039;portal-bar noprint metadata&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(&amp;#039;portal-bar-unbordered&amp;#039;)&lt;br /&gt;
	else&lt;br /&gt;
		nav&lt;br /&gt;
			:addClass( &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;
	-- I don&amp;#039;t believe the block in the conditional is reachable currently&lt;br /&gt;
	-- because if it were we would probably get a Lua script error because&lt;br /&gt;
	-- warning was previously undefined&lt;br /&gt;
	&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;
	for _, portal in ipairs( portals ) do&lt;br /&gt;
		nav&lt;br /&gt;
			:tag( &amp;#039;li&amp;#039; )&lt;br /&gt;
				:tag( &amp;#039;span&amp;#039; )&lt;br /&gt;
					:wikitext( string.format(&lt;br /&gt;
						&amp;#039;[[File:%s|24x21px|alt=]]&amp;#039;, getImageName{ portal }&lt;br /&gt;
					) )&lt;br /&gt;
					:done()&lt;br /&gt;
				:wikitext( string.format(&lt;br /&gt;
					&amp;#039;[[Portal:%s|%s portal]]&amp;#039;, portal, portal&lt;br /&gt;
				) )&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return mw.getCurrentFrame():extensionTag{&lt;br /&gt;
		name = &amp;#039;templatestyles&amp;#039;, args = { src = &amp;#039;Module:Portal bar/styles.css&amp;#039; }&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;
	-- If called via #invoke, use the args passed into the invoking template, or&lt;br /&gt;
	-- the args passed to #invoke if any exist. Otherwise assume args are being&lt;br /&gt;
	-- passed directly in from the debug console or from another Lua module.&lt;br /&gt;
	local origArgs&lt;br /&gt;
	if type( frame.getParent ) == &amp;#039;function&amp;#039; 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;
	-- 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;
			if mw.ustring.find( v, &amp;#039;%S&amp;#039; ) then -- Remove blank values.&lt;br /&gt;
				table.insert( portals, k )&lt;br /&gt;
				end&lt;br /&gt;
			elseif type( k ) ~= &amp;#039;number&amp;#039; then -- Separate named arguments from portals.&lt;br /&gt;
			if type( v ) == &amp;#039;string&amp;#039; then&lt;br /&gt;
				v = mw.text.trim( v )&lt;br /&gt;
			end&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, trimming whitespace.&lt;br /&gt;
		portals[ i ] = mw.text.trim( 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>imported&gt;Legoktm</name></author>
	</entry>
</feed>