<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Module%3APortal</id>
	<title>Module:Portal - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=Module%3APortal"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Module:Portal&amp;action=history"/>
	<updated>2026-06-25T16:36:52Z</updated>
	<subtitle>在这个wiki上该页的修订历史</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=Module:Portal&amp;diff=2198401&amp;oldid=prev</id>
		<title>imported&gt;Shizhao：​dark mode fix</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=Module:Portal&amp;diff=2198401&amp;oldid=prev"/>
		<updated>2024-06-19T11:40:42Z</updated>

		<summary type="html">&lt;p&gt;dark mode fix&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[==[ This module is a Lua implementation of the old {{Portal}} template. As of August 2013 it is used on nearly 5,000,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/letter]]		&lt;br /&gt;
-- [[Module:Portal/images/chinese]]		&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 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/letter&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		imagePage = &amp;#039;Module:Portal/images/chinese&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	-- Hey, we have a thing called &amp;quot;other&amp;quot;&lt;br /&gt;
	return mw.loadData(imagePage)[s] or&lt;br /&gt;
		   mw.loadData(&amp;#039;Module:Portal/images/other&amp;#039;)[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;)&lt;br /&gt;
	return aliasData[s]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getImageName(s)&lt;br /&gt;
	-- Gets the image name and the un-aliased &amp;quot;normal name&amp;quot; for a given portal.&lt;br /&gt;
	local default = &amp;#039;Portal-puzzle.svg|link=|alt=&amp;#039;&lt;br /&gt;
	if type(s) ~= &amp;#039;string&amp;#039; or #s &amp;lt; 1 then&lt;br /&gt;
		return default&lt;br /&gt;
	end&lt;br /&gt;
	local sl = mw.ustring.lower(s)&lt;br /&gt;
	local sr = s&lt;br /&gt;
	local img = matchImagePage(sl)&lt;br /&gt;
	if not img then&lt;br /&gt;
		sr = getAlias(sl)&lt;br /&gt;
		if sr then&lt;br /&gt;
			img = matchImagePage(mw.ustring.lower(sr))&lt;br /&gt;
		end&lt;br /&gt;
		if not img then&lt;br /&gt;
			img = default&lt;br /&gt;
			sr = s&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return img, sr&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(&amp;#039;div&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 portal plainlist&amp;#039;)&lt;br /&gt;
		:addClass(args.left and &amp;#039;tleft&amp;#039; or &amp;#039;tright&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;margin&amp;#039;, args.margin or (args.left == &amp;#039;yes&amp;#039; and &amp;#039;0.5em 1em 0.5em 0&amp;#039;) or &amp;#039;0.5em 0 0.5em 1em&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border&amp;#039;, &amp;#039;solid #aaa 1px&amp;#039;)&lt;br /&gt;
		:newline()&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;
		-- zhwp compat: name={{{1}}}|image={{{image1}}}&lt;br /&gt;
		-- no tracking needed as no expensive involved&lt;br /&gt;
		if args[&amp;#039;name&amp;#039;] ~= nil then&lt;br /&gt;
			portals[1] = args[&amp;#039;name&amp;#039;]&lt;br /&gt;
			args[&amp;#039;image1&amp;#039;] = args[&amp;#039;image&amp;#039;]&lt;br /&gt;
		else&lt;br /&gt;
			root:wikitext(&amp;#039;&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;未指定主题：请至少添加一个主题&amp;lt;/strong&amp;gt;[[Category:Portal模版没有使用参数]]&amp;#039;)&lt;br /&gt;
			return tostring(root)&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(&amp;#039;ul&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;display&amp;#039;, &amp;#039;table&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;box-sizing&amp;#039;, &amp;#039;border-box&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;padding&amp;#039;, &amp;#039;0.1em&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;max-width&amp;#039;, &amp;#039;175px&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;width&amp;#039;, type(args.boxsize) == &amp;#039;string&amp;#039; and (args.boxsize .. &amp;#039;px&amp;#039;) or nil)&lt;br /&gt;
		:css(&amp;#039;background&amp;#039;, &amp;#039;var(--background-color-base,#f9f9f9)&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;font-size&amp;#039;, &amp;#039;85%&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;line-height&amp;#039;, &amp;#039;110%&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;font-weight&amp;#039;, &amp;#039;bold&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    -- zhwp compatibility: check for |2= as |image1&lt;br /&gt;
    local compat_image1 = false&lt;br /&gt;
    if #portals == 2 and (args[&amp;#039;image1&amp;#039;] == nil) then&lt;br /&gt;
    	local file = portals[2]&lt;br /&gt;
    	local parts = mw.text.split(file, &amp;#039;%.&amp;#039;)&lt;br /&gt;
    	if #parts &amp;gt; 1 then&lt;br /&gt;
	    	local ext = (parts[#parts]):lower()&lt;br /&gt;
	    	-- likely&lt;br /&gt;
	    	if #ext == 3 or #ext == 4 then&lt;br /&gt;
	    		local assume_img = (ext == &amp;#039;png&amp;#039;) or (ext == &amp;#039;jpg&amp;#039;) or (ext == &amp;#039;svg&amp;#039;)&lt;br /&gt;
	    		-- expensive, hence pre-checks &amp;amp; assumption&lt;br /&gt;
	    		if assume_img or mw.title.new(file, &amp;#039;Media&amp;#039;).exists then&lt;br /&gt;
		    		args[&amp;#039;image1&amp;#039;] = portals[2]&lt;br /&gt;
		    		compat_image1 = true&lt;br /&gt;
		    		table.remove(portals, 2)&lt;br /&gt;
	    		end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Display the portals specified in the positional arguments.&lt;br /&gt;
	for i, portal in ipairs(portals) do&lt;br /&gt;
		-- Support |image1= |image2= ...&lt;br /&gt;
		-- Rationale: [[Template:WPBannerMeta]] usage.&lt;br /&gt;
		local image = &amp;#039;&amp;#039;&lt;br /&gt;
		if args[&amp;#039;image&amp;#039; .. tostring(i)] ~= nil then&lt;br /&gt;
			image = args[&amp;#039;image&amp;#039; .. tostring(i)] .. &amp;#039;|alt=&amp;#039; .. portal&lt;br /&gt;
		else&lt;br /&gt;
			-- get the alias too&lt;br /&gt;
			image, portal = getImageName(portal)&lt;br /&gt;
		end&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(&amp;#039;li&amp;#039;)&lt;br /&gt;
				:css(&amp;#039;display&amp;#039;, &amp;#039;table-row&amp;#039;)&lt;br /&gt;
				:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;display&amp;#039;, &amp;#039;table-cell&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;padding&amp;#039;, &amp;#039;0.2em&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;vertical-align&amp;#039;, &amp;#039;middle&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
					:wikitext(string.format(&amp;#039;[[File:%s|32x28px|class=noviewer]]&amp;#039;, image))&lt;br /&gt;
					:done()&lt;br /&gt;
				:tag(&amp;#039;span&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;display&amp;#039;, &amp;#039;table-cell&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;padding&amp;#039;, &amp;#039;0.2em 0.2em 0.2em 0.3em&amp;#039;)&lt;br /&gt;
					:css(&amp;#039;vertical-align&amp;#039;, &amp;#039;middle&amp;#039;)&lt;br /&gt;
					:wikitext(string.format(&amp;#039;[[Portal:%s|%s主题]]&amp;#039;, portal, portal))&lt;br /&gt;
	end&lt;br /&gt;
	local ret = tostring(root)&lt;br /&gt;
	if compat_image1 == true then&lt;br /&gt;
		ret = ret .. &amp;#039;[[Category:使用2號參數傳遞Portal模板圖像的頁面]]&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	return ret&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(&amp;#039;^(.-)|&amp;#039;) 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{&amp;#039;letter&amp;#039;, &amp;#039;chinese&amp;#039;, &amp;#039;other&amp;#039;} do&lt;br /&gt;
		images[i] = mw.loadData(&amp;#039;Module:Portal/images/&amp;#039; .. 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&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;
	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(&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;
	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;
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) == &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;
		-- 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) == &amp;#039;string&amp;#039; then&lt;br /&gt;
				v = mw.text.trim(v)&lt;br /&gt;
			end&lt;br /&gt;
			if v ~= &amp;#039;&amp;#039; then&lt;br /&gt;
				args[k] = v&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return 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{&amp;#039;portal&amp;#039;, &amp;#039;image&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>imported&gt;Shizhao</name></author>
	</entry>
</feed>