<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.statsape.com/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3ARedirect_hatnote</id>
	<title>模块:Redirect hatnote - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.statsape.com/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E5%9D%97%3ARedirect_hatnote"/>
	<link rel="alternate" type="text/html" href="https://wiki.statsape.com/index.php?title=%E6%A8%A1%E5%9D%97:Redirect_hatnote&amp;action=history"/>
	<updated>2026-04-05T16:17:37Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://wiki.statsape.com/index.php?title=%E6%A8%A1%E5%9D%97:Redirect_hatnote&amp;diff=1541&amp;oldid=prev</id>
		<title>Zeroclanzhang：​创建页面，内容为“-- -- This module produces a &quot;redirect&quot; hatnote. It looks like this: -- &#039;&quot;X&quot; redirects here. For other uses, see Y.&#039; -- It implements the {{redirect}} template. --  local mHatnote = require(&#039;Module:Hatnote&#039;) local mHatList = require(&#039;Module:Hatnote list&#039;) local mArguments --lazily initialize local libraryUtil = require(&#039;libraryUtil&#039;) local checkType = libraryUtil.checkType local checkTypeMulti = libraryUtil.checkTypeMulti  local p = {}  local function getTi…”</title>
		<link rel="alternate" type="text/html" href="https://wiki.statsape.com/index.php?title=%E6%A8%A1%E5%9D%97:Redirect_hatnote&amp;diff=1541&amp;oldid=prev"/>
		<updated>2023-08-09T16:07:12Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“--[[ -- This module produces a &amp;quot;redirect&amp;quot; hatnote. It looks like this: -- &amp;#039;&amp;quot;X&amp;quot; redirects here. For other uses, see Y.&amp;#039; -- It implements the {{redirect}} template. --]]  local mHatnote = require(&amp;#039;Module:Hatnote&amp;#039;) local mHatList = require(&amp;#039;Module:Hatnote list&amp;#039;) local mArguments --lazily initialize local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;) local checkType = libraryUtil.checkType local checkTypeMulti = libraryUtil.checkTypeMulti  local p = {}  local function getTi…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
-- This module produces a &amp;quot;redirect&amp;quot; hatnote. It looks like this:&lt;br /&gt;
-- &amp;#039;&amp;quot;X&amp;quot; redirects here. For other uses, see Y.&amp;#039;&lt;br /&gt;
-- It implements the {{redirect}} template.&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
local mHatnote = require(&amp;#039;Module:Hatnote&amp;#039;)&lt;br /&gt;
local mHatList = require(&amp;#039;Module:Hatnote list&amp;#039;)&lt;br /&gt;
local mArguments --lazily initialize&lt;br /&gt;
local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local checkTypeMulti = libraryUtil.checkTypeMulti&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local function getTitle(...)&lt;br /&gt;
	local success, titleObj = pcall(mw.title.new, ...)&lt;br /&gt;
	if success then&lt;br /&gt;
		return titleObj&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.redirect(frame)&lt;br /&gt;
	mArguments = require(&amp;#039;Module:Arguments&amp;#039;)&lt;br /&gt;
	local args = mArguments.getArgs(frame, {parentOnly=true})&lt;br /&gt;
	--Get number of redirects&lt;br /&gt;
	local numRedirects = tonumber(frame.args[1]) or 1&lt;br /&gt;
	-- Create the options table.&lt;br /&gt;
	local options = {}&lt;br /&gt;
	options.selfref = args.selfref&lt;br /&gt;
	return p._redirect(args, numRedirects, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._redirect(args, numRedirects, options, currentTitle, redirectTitle, targetTitle)&lt;br /&gt;
	-- Validate the input. Don&amp;#039;t bother checking currentTitle, redirectTitle or&lt;br /&gt;
	-- targetTitle, as they are only used in testing.&lt;br /&gt;
	checkType(&amp;#039;_redirect&amp;#039;, 1, args, &amp;#039;table&amp;#039;)&lt;br /&gt;
	checkType(&amp;#039;_redirect&amp;#039;, 2, numRedirects, &amp;#039;number&amp;#039;, true)&lt;br /&gt;
	numRedirects = numRedirects or 1&lt;br /&gt;
	checkType(&amp;#039;_redirect&amp;#039;, 3, options, &amp;#039;table&amp;#039;, true)&lt;br /&gt;
	options = options or {}&lt;br /&gt;
	currentTitle = currentTitle or mw.title.getCurrentTitle()&lt;br /&gt;
	-- Get the table of redirects&lt;br /&gt;
	local redirect = {}&lt;br /&gt;
	for i = 1, numRedirects do&lt;br /&gt;
		-- Return an error if a redirect parameter is missing.&lt;br /&gt;
		if not args[i] then&lt;br /&gt;
			return mHatnote.makeWikitextError(&lt;br /&gt;
				&amp;#039;missing redirect parameter&amp;#039;,&lt;br /&gt;
				&amp;#039;Template:Redirect#Errors&amp;#039;,&lt;br /&gt;
				args.category&lt;br /&gt;
			)&lt;br /&gt;
		end&lt;br /&gt;
		redirect[i] = args[i]&lt;br /&gt;
	end&lt;br /&gt;
	-- Generate the text.&lt;br /&gt;
	local formattedRedirect = {}&lt;br /&gt;
	for k,v in pairs(redirect) do&lt;br /&gt;
		formattedRedirect[k] = &amp;#039;&amp;quot;&amp;#039; .. v .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local text = {&lt;br /&gt;
		mHatList.andList(formattedRedirect) .. &amp;#039; &amp;#039; .. (#redirect == 1 and &amp;#039;redirects&amp;#039; or &amp;#039;redirect&amp;#039;) .. &amp;#039; here.&amp;#039;,&lt;br /&gt;
		mHatList._forSee(args, #redirect + 1, {title = redirect[1], extratext = args.text})&lt;br /&gt;
	}&lt;br /&gt;
	text = table.concat(text, &amp;#039; &amp;#039;)&lt;br /&gt;
	-- Functionality for adding categories	&lt;br /&gt;
	local categoryTable = {}&lt;br /&gt;
	function addCategory(cat)&lt;br /&gt;
		if cat and cat ~= &amp;#039;&amp;#039; then&lt;br /&gt;
			-- Add by index to avoid duplicates&lt;br /&gt;
			categoryTable[string.format(&amp;#039;[[Category:%s]]&amp;#039;, cat)] = true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	--Generate tracking categories&lt;br /&gt;
	local mhOptions = {}&lt;br /&gt;
	for k,v in pairs(redirect) do&lt;br /&gt;
		-- We don&amp;#039;t need a tracking category if the template invocation has been&lt;br /&gt;
		-- copied directly from the docs, or if we aren&amp;#039;t in main- or category-space.&lt;br /&gt;
		if not v:find(&amp;#039;^REDIRECT%d*$&amp;#039;) and v ~= &amp;#039;TERM&amp;#039; -- &lt;br /&gt;
			and currentTitle.namespace == 0 or currentTitle.namespace == 14&lt;br /&gt;
		then&lt;br /&gt;
			redirectTitle = redirectTitle or getTitle(v)&lt;br /&gt;
			if not redirectTitle or not redirectTitle.exists then&lt;br /&gt;
				addCategory(&amp;#039;Missing redirects&amp;#039;)&lt;br /&gt;
			elseif not redirectTitle.isRedirect then&lt;br /&gt;
				addCategory(&amp;#039;Articles with redirect hatnotes needing review&amp;#039;)&lt;br /&gt;
			else&lt;br /&gt;
				local mRedirect = require(&amp;#039;Module:Redirect&amp;#039;)&lt;br /&gt;
				local target = mRedirect.getTarget(redirectTitle)&lt;br /&gt;
				targetTitle = targetTitle or target and getTitle(target)&lt;br /&gt;
				if targetTitle and targetTitle ~= currentTitle then&lt;br /&gt;
					addCategory(&amp;#039;Articles with redirect hatnotes needing review&amp;#039;)&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Generate the options to pass to [[Module:Hatnote]].&lt;br /&gt;
		if currentTitle.namespace == 0 and not mhOptions.selfref&lt;br /&gt;
			and redirectTitle and redirectTitle.namespace ~= 0&lt;br /&gt;
		then&lt;br /&gt;
			-- We are on a mainspace page, and the hatnote starts with something&lt;br /&gt;
			-- like &amp;quot;Wikipedia:Foo redirects here&amp;quot;, so automatically label it as&lt;br /&gt;
			-- a self-reference.&lt;br /&gt;
			mhOptions.selfref = true&lt;br /&gt;
		else&lt;br /&gt;
			mhOptions.selfref = options.selfref&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	--concatenate all the categories&lt;br /&gt;
	local category = &amp;#039;&amp;#039;&lt;br /&gt;
	for k,v in pairs(categoryTable) do&lt;br /&gt;
		category = category .. k&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	mhOptions.icon = &amp;#039;WikimediaUI-ArticleDisambiguation-ltr.svg&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	return mHatnote._hatnote(text, mhOptions) .. category&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Zeroclanzhang</name></author>
	</entry>
</feed>