<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.stargatewiki.noip.me/index.php?action=history&amp;feed=atom&amp;title=Module%3ARedirect_hatnote</id>
	<title>Module:Redirect hatnote - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://en.stargatewiki.noip.me/index.php?action=history&amp;feed=atom&amp;title=Module%3ARedirect_hatnote"/>
	<link rel="alternate" type="text/html" href="https://en.stargatewiki.noip.me/index.php?title=Module:Redirect_hatnote&amp;action=history"/>
	<updated>2026-04-07T20:42:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://en.stargatewiki.noip.me/index.php?title=Module:Redirect_hatnote&amp;diff=3309&amp;oldid=prev</id>
		<title>LIMAFOX76: Created page with &quot;-- -- 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...&quot;</title>
		<link rel="alternate" type="text/html" href="https://en.stargatewiki.noip.me/index.php?title=Module:Redirect_hatnote&amp;diff=3309&amp;oldid=prev"/>
		<updated>2016-03-22T12:19:06Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;--[[ -- 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...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&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 libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local checkType = libraryUtil.checkType&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;
	-- Get the args table and work out the maximum arg key.&lt;br /&gt;
	local origArgs = frame:getParent().args&lt;br /&gt;
	local args = {}&lt;br /&gt;
	local maxArg = 0&lt;br /&gt;
	for k, v in pairs(origArgs) do&lt;br /&gt;
		if type(k) == &amp;#039;number&amp;#039; and k &amp;gt; maxArg then&lt;br /&gt;
			maxArg = k&lt;br /&gt;
		end&lt;br /&gt;
		v = v:match(&amp;#039;^%s*(.-)%s*$&amp;#039;) -- Trim whitespace&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;
&lt;br /&gt;
	-- Return an error if no redirect was specified.&lt;br /&gt;
	local redirect = args[1]&lt;br /&gt;
	if not redirect then&lt;br /&gt;
		return mHatnote.makeWikitextError(&lt;br /&gt;
			&amp;#039;no redirect specified&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;
&lt;br /&gt;
	-- Create the data table.&lt;br /&gt;
	local data = {}&lt;br /&gt;
	local iArg = 0&lt;br /&gt;
	local iData = 1&lt;br /&gt;
	repeat&lt;br /&gt;
		iArg = iArg + 2&lt;br /&gt;
		local useTable = data[iData] or {}&lt;br /&gt;
		local pages = useTable.pages or {}&lt;br /&gt;
		local use = args[iArg]&lt;br /&gt;
		local page = args[iArg + 1]&lt;br /&gt;
		local nextUse = args[iArg + 2]&lt;br /&gt;
		pages[#pages + 1] = page&lt;br /&gt;
		useTable.pages = pages&lt;br /&gt;
		if use ~= &amp;#039;and&amp;#039; then&lt;br /&gt;
			useTable.use = use&lt;br /&gt;
		end&lt;br /&gt;
		data[iData] = useTable&lt;br /&gt;
		if nextUse ~= &amp;#039;and&amp;#039; then&lt;br /&gt;
			iData = iData + 1&lt;br /&gt;
		end&lt;br /&gt;
	until iArg &amp;gt;= maxArg - 1&lt;br /&gt;
&lt;br /&gt;
	-- Create the options table.&lt;br /&gt;
	local options = {}&lt;br /&gt;
	options.selfref = args.selfref&lt;br /&gt;
		&lt;br /&gt;
	return p._redirect(redirect, data, options)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function formatUseTable(useTable, isFirst, redirect)&lt;br /&gt;
	-- Formats one use table. Use tables are the tables inside the data array.&lt;br /&gt;
	-- Each one corresponds to one use. (A use might be the word &amp;quot;cats&amp;quot; in the&lt;br /&gt;
	-- phrase &amp;quot;For cats, see [[Felines]]&amp;quot;.)&lt;br /&gt;
	-- Returns a string, or nil if no use was specified.&lt;br /&gt;
	-- The isFirst parameter is used to apply special formatting for the first&lt;br /&gt;
	-- table in the data array. If isFirst is specified, the redirect parameter&lt;br /&gt;
	useTable = useTable or {}&lt;br /&gt;
	local use&lt;br /&gt;
	if isFirst then&lt;br /&gt;
		use = useTable.use or &amp;#039;other uses&amp;#039;&lt;br /&gt;
	elseif not useTable.use then&lt;br /&gt;
		return nil&lt;br /&gt;
	elseif tonumber(useTable.use) == 1 then&lt;br /&gt;
		use = &amp;#039;other uses&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		use = useTable.use&lt;br /&gt;
	end&lt;br /&gt;
	local pages = useTable.pages or {}&lt;br /&gt;
	if isFirst then&lt;br /&gt;
		redirect = redirect or error(&lt;br /&gt;
			&amp;#039;isFirst was set in formatUseTable, but no redirect was supplied&amp;#039;,&lt;br /&gt;
			2&lt;br /&gt;
		)&lt;br /&gt;
		pages[1] = pages[1] or redirect .. &amp;#039; (disambiguation)&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		pages[1] = pages[1] or useTable.use .. &amp;#039; (disambiguation)&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	pages = mHatnote.formatPages(unpack(pages))&lt;br /&gt;
	pages = mw.text.listToText(pages)&lt;br /&gt;
	return string.format(&lt;br /&gt;
		&amp;#039;For %s, see %s.&amp;#039;,&lt;br /&gt;
		use,&lt;br /&gt;
		pages&lt;br /&gt;
	)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._redirect(redirect, data, 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, redirect, &amp;#039;string&amp;#039;)&lt;br /&gt;
	checkType(&amp;#039;_redirect&amp;#039;, 2, data, &amp;#039;table&amp;#039;, true)&lt;br /&gt;
	checkType(&amp;#039;_redirect&amp;#039;, 3, options, &amp;#039;table&amp;#039;, true)&lt;br /&gt;
	data = data or {}&lt;br /&gt;
	options = options or {}&lt;br /&gt;
	currentTitle = currentTitle or mw.title.getCurrentTitle()&lt;br /&gt;
&lt;br /&gt;
	-- Generate the text.&lt;br /&gt;
	local text = {}&lt;br /&gt;
	text[#text + 1] = &amp;#039;&amp;quot;&amp;#039; .. redirect .. &amp;#039;&amp;quot; redirects here.&amp;#039;&lt;br /&gt;
	text[#text + 1] = formatUseTable(data[1] or {}, true, redirect)&lt;br /&gt;
	if data[1] and data[1].use and data[1].use ~= &amp;#039;other uses&amp;#039; then&lt;br /&gt;
		for i = 2, #data do&lt;br /&gt;
			text[#text + 1] = formatUseTable(data[i] or {}, false)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	text = table.concat(text, &amp;#039; &amp;#039;)&lt;br /&gt;
	&lt;br /&gt;
	-- Generate the tracking category.&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 mainspace or category-space.&lt;br /&gt;
	local category&lt;br /&gt;
	if not redirect:find(&amp;#039;^REDIRECT%d*$&amp;#039;) and redirect ~= &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(redirect)&lt;br /&gt;
		if not redirectTitle or not redirectTitle.exists then&lt;br /&gt;
			category = &amp;#039;Missing redirects&amp;#039;&lt;br /&gt;
		elseif not redirectTitle.isRedirect then&lt;br /&gt;
			category = &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;
				category = &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;
	category = category and string.format(&amp;#039;[[Category:%s]]&amp;#039;, category) or &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	-- Generate the options to pass to [[Module:Hatnote]].&lt;br /&gt;
	local mhOptions = {}&lt;br /&gt;
	if currentTitle.namespace == 0&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 a&lt;br /&gt;
		-- 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;
&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>LIMAFOX76</name></author>
	</entry>
</feed>