<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ARedirect</id>
	<title>Module:Redirect - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ARedirect"/>
	<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Redirect&amp;action=history"/>
	<updated>2026-04-06T03:49:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://mindpowe.red/wiki/index.php?title=Module:Redirect&amp;diff=282&amp;oldid=prev</id>
		<title>WikiSysop: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Redirect&amp;diff=282&amp;oldid=prev"/>
		<updated>2020-08-07T21:04:26Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 21:04, 7 August 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
		
	</entry>
	<entry>
		<id>https://mindpowe.red/wiki/index.php?title=Module:Redirect&amp;diff=281&amp;oldid=prev</id>
		<title>en&gt;MusikAnimal: Changed protection level for &quot;Module:Redirect&quot;: High-risk template or module; used in system message ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Redirect&amp;diff=281&amp;oldid=prev"/>
		<updated>2019-02-25T22:06:47Z</updated>

		<summary type="html">&lt;p&gt;Changed protection level for &amp;quot;&lt;a href=&quot;/wiki/index.php/Module:Redirect&quot; title=&quot;Module:Redirect&quot;&gt;Module:Redirect&lt;/a&gt;&amp;quot;: &lt;a href=&quot;https://en.wikipedia.org/wiki/High-risk_templates&quot; class=&quot;extiw&quot; title=&quot;wikipedia:High-risk templates&quot;&gt;High-risk template or module&lt;/a&gt;; used in system message ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite))&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module provides functions for getting the target of a redirect page.&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Gets a mw.title object, using pcall to avoid generating script errors if we&lt;br /&gt;
-- are over the expensive function count limit (among other possible causes).&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;
-- Gets the name of a page that a redirect leads to, or nil if it isn't a&lt;br /&gt;
-- redirect.&lt;br /&gt;
function p.getTargetFromText(text)&lt;br /&gt;
	return string.match(&lt;br /&gt;
		text,&lt;br /&gt;
		&amp;quot;^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)%]%]&amp;quot;&lt;br /&gt;
	) or string.match(&lt;br /&gt;
		text,&lt;br /&gt;
		&amp;quot;^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)|[^%[%]]-%]%]&amp;quot;&lt;br /&gt;
	)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Gets the target of a redirect. If the page specified is not a redirect,&lt;br /&gt;
-- returns nil.&lt;br /&gt;
function p.getTarget(page, fulltext)&lt;br /&gt;
	-- Get the title object. Both page names and title objects are allowed&lt;br /&gt;
	-- as input.&lt;br /&gt;
	local titleObj&lt;br /&gt;
	if type(page) == 'string' or type(page) == 'number' then&lt;br /&gt;
		titleObj = getTitle(page)&lt;br /&gt;
	elseif type(page) == 'table' and type(page.getContent) == 'function' then&lt;br /&gt;
		titleObj = page&lt;br /&gt;
	else&lt;br /&gt;
		error(string.format(&lt;br /&gt;
			&amp;quot;bad argument #1 to 'getTarget'&amp;quot;&lt;br /&gt;
				.. &amp;quot; (string, number, or title object expected, got %s)&amp;quot;,&lt;br /&gt;
			type(page)&lt;br /&gt;
		), 2)&lt;br /&gt;
	end&lt;br /&gt;
	if not titleObj or not titleObj.isRedirect then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Find the target by using string matching on the page content.&lt;br /&gt;
	local target = p.getTargetFromText(titleObj:getContent() or &amp;quot;&amp;quot;)&lt;br /&gt;
	if target then&lt;br /&gt;
		local targetTitle = getTitle(target)&lt;br /&gt;
		if targetTitle then&lt;br /&gt;
			if fulltext then&lt;br /&gt;
				return targetTitle.fullText&lt;br /&gt;
			else&lt;br /&gt;
				return targetTitle.prefixedText&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		-- The page is a redirect, but matching failed. This indicates a bug in&lt;br /&gt;
		-- the redirect matching pattern, so throw an error.&lt;br /&gt;
		error(string.format(&lt;br /&gt;
			'could not parse redirect on page &amp;quot;%s&amp;quot;',&lt;br /&gt;
			fulltext and titleObj.fullText or titleObj.prefixedText&lt;br /&gt;
		))&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
-- Given a single page name determines what page it redirects to and returns the&lt;br /&gt;
-- target page name, or the passed page name when not a redirect. The passed&lt;br /&gt;
-- page name can be given as plain text or as a page link.&lt;br /&gt;
-- &lt;br /&gt;
-- Returns page name as plain text, or when the bracket parameter is given, as a&lt;br /&gt;
-- page link. Returns an error message when page does not exist or the redirect&lt;br /&gt;
-- target cannot be determined for some reason.&lt;br /&gt;
--]]&lt;br /&gt;
function p.luaMain(rname, bracket, fulltext)&lt;br /&gt;
	if type(rname) ~= &amp;quot;string&amp;quot; or not rname:find(&amp;quot;%S&amp;quot;) then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	bracket = bracket and &amp;quot;[[%s]]&amp;quot; or &amp;quot;%s&amp;quot;&lt;br /&gt;
	rname = rname:match(&amp;quot;%[%[(.+)%]%]&amp;quot;) or rname&lt;br /&gt;
	local target = p.getTarget(rname, fulltext)&lt;br /&gt;
	local ret = target or rname&lt;br /&gt;
	ret = getTitle(ret)&lt;br /&gt;
	if ret then&lt;br /&gt;
		if fulltext then&lt;br /&gt;
			ret = ret.fullText&lt;br /&gt;
		else&lt;br /&gt;
			ret = ret.prefixedText&lt;br /&gt;
		end&lt;br /&gt;
		return bracket:format(ret)&lt;br /&gt;
	else&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Provides access to the luaMain function from wikitext.&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})&lt;br /&gt;
	return p.luaMain(args[1], args.bracket, args.fulltext) or ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Returns true if the specified page is a redirect, and false otherwise.&lt;br /&gt;
function p.luaIsRedirect(page)&lt;br /&gt;
	local titleObj = getTitle(page)&lt;br /&gt;
	if not titleObj then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	if titleObj.isRedirect then&lt;br /&gt;
		return true&lt;br /&gt;
	else&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Provides access to the luaIsRedirect function from wikitext, returning 'yes'&lt;br /&gt;
-- if the specified page is a redirect, and the blank string otherwise.&lt;br /&gt;
function p.isRedirect(frame)&lt;br /&gt;
	local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})&lt;br /&gt;
	if p.luaIsRedirect(args[1]) then&lt;br /&gt;
		return 'yes'&lt;br /&gt;
	else&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>en&gt;MusikAnimal</name></author>
		
	</entry>
</feed>