<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://forgloryorgold.com/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="http://forgloryorgold.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ARedirect_hatnote"/>
	<link rel="alternate" type="text/html" href="http://forgloryorgold.com/index.php?title=Module:Redirect_hatnote&amp;action=history"/>
	<updated>2026-04-11T21:08:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>http://forgloryorgold.com/index.php?title=Module:Redirect_hatnote&amp;diff=269&amp;oldid=prev</id>
		<title>Cilraaz: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://forgloryorgold.com/index.php?title=Module:Redirect_hatnote&amp;diff=269&amp;oldid=prev"/>
		<updated>2015-01-06T19:02:32Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&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;quot;X&amp;quot; redirects here. For other uses, see Y.'&lt;br /&gt;
-- It implements the {{redirect}} template.&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
local mHatnote = require('Module:Hatnote')&lt;br /&gt;
local libraryUtil = require('libraryUtil')&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) == 'number' and k &amp;gt; maxArg then&lt;br /&gt;
			maxArg = k&lt;br /&gt;
		end&lt;br /&gt;
		v = v:match('^%s*(.-)%s*$') -- Trim whitespace&lt;br /&gt;
		if v ~= '' 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;
			'no redirect specified',&lt;br /&gt;
			'Template:Redirect#Errors',&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 ~= 'and' then&lt;br /&gt;
			useTable.use = use&lt;br /&gt;
		end&lt;br /&gt;
		data[iData] = useTable&lt;br /&gt;
		if nextUse ~= 'and' 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 'other uses'&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 = 'other uses'&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;
			'isFirst was set in formatUseTable, but no redirect was supplied',&lt;br /&gt;
			2&lt;br /&gt;
		)&lt;br /&gt;
		pages[1] = pages[1] or redirect .. ' (disambiguation)'&lt;br /&gt;
	else&lt;br /&gt;
		pages[1] = pages[1] or useTable.use .. ' (disambiguation)'&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;
		'For %s, see %s.',&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't bother checking currentTitle, redirectTitle or&lt;br /&gt;
	-- targetTitle, as they are only used in testing.&lt;br /&gt;
	checkType('_redirect', 1, redirect, 'string')&lt;br /&gt;
	checkType('_redirect', 2, data, 'table', true)&lt;br /&gt;
	checkType('_redirect', 3, options, 'table', 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;quot;' .. redirect .. '&amp;quot; redirects here.'&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 ~= 'other uses' 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, ' ')&lt;br /&gt;
	&lt;br /&gt;
	-- Generate the tracking category.&lt;br /&gt;
	-- We don't need a tracking category if the template invocation has been&lt;br /&gt;
	-- copied directly from the docs, or if we aren't in mainspace.&lt;br /&gt;
	local category&lt;br /&gt;
	if not redirect:find('^REDIRECT%d*$') and redirect ~= 'TERM' -- &lt;br /&gt;
		and currentTitle.namespace == 0&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 = 'Missing redirects'&lt;br /&gt;
		elseif not redirectTitle.isRedirect then&lt;br /&gt;
			category = 'Invalid redirects'&lt;br /&gt;
		else&lt;br /&gt;
			local mRedirect = require('Module:Redirect')&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 = 'Invalid redirects'&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	category = category and string.format('[[Category:%s]]', category) or ''&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>Cilraaz</name></author>
	</entry>
</feed>