<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.digitalcellulose.com/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://www.digitalcellulose.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ARedirect"/>
	<link rel="alternate" type="text/html" href="https://www.digitalcellulose.com/wiki/index.php?title=Module:Redirect&amp;action=history"/>
	<updated>2026-07-29T07:38:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://www.digitalcellulose.com/wiki/index.php?title=Module:Redirect&amp;diff=152755&amp;oldid=prev</id>
		<title>Adminsuzy: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://www.digitalcellulose.com/wiki/index.php?title=Module:Redirect&amp;diff=152755&amp;oldid=prev"/>
		<updated>2020-09-13T20:48:20Z</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 20:48, 13 September 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>Adminsuzy</name></author>
		
	</entry>
	<entry>
		<id>https://www.digitalcellulose.com/wiki/index.php?title=Module:Redirect&amp;diff=152754&amp;oldid=prev</id>
		<title>Imported&gt;Verdy p at 09:56, 21 July 2020</title>
		<link rel="alternate" type="text/html" href="https://www.digitalcellulose.com/wiki/index.php?title=Module:Redirect&amp;diff=152754&amp;oldid=prev"/>
		<updated>2020-07-21T09:56:16Z</updated>

		<summary type="html">&lt;p&gt;&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;
local char = mw.ustring.char&lt;br /&gt;
&lt;br /&gt;
-- proxy to load the module lazily, replaced by the actual loaded function&lt;br /&gt;
local getArgs = function(...)&lt;br /&gt;
	getArgs = require('Module:Arguments').getArgs&lt;br /&gt;
	return getArgs(...)&lt;br /&gt;
end&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;
--[[&lt;br /&gt;
Detect hard redirect in wiki page content (not used inside this module)&lt;br /&gt;
]]&lt;br /&gt;
function p.getTargetFromText(text)&lt;br /&gt;
	text = text or ''&lt;br /&gt;
	return text:match('#[Rr][Ee][Dd]...[Cc][Tt][%s:]*%[%[([^]|]-)%s*%]%]')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Detect soft redirect in wiki page content of 'Category:' pages, using template&lt;br /&gt;
	{{Category redirect|target}}&lt;br /&gt;
or one of its known aliases on Commons (there are too many!!!):&lt;br /&gt;
	{{Category Redirect|target}}&lt;br /&gt;
	{{Categoryredirect|target}}&lt;br /&gt;
	{{Cat redirect|target}}&lt;br /&gt;
	{{Catredirect|target}}&lt;br /&gt;
	{{Catredir|target}}&lt;br /&gt;
	{{Cat-redirect|target}}&lt;br /&gt;
	{{Cat-red|target}}&lt;br /&gt;
	{{Redirect category|target}}&lt;br /&gt;
	{{Redirect cat|target}}&lt;br /&gt;
	{{Seecat|target}}&lt;br /&gt;
	{{See cat|target}}&lt;br /&gt;
	{{Endashcatredirect|target}}&lt;br /&gt;
	{{Synonym taxon category redirect|target}}&lt;br /&gt;
	{{Invalid taxon category redirect|target}}&lt;br /&gt;
	{{Monotypic taxon category redirect|target}}&lt;br /&gt;
The `target` value may be prefixed by 'Category:' or not (implied). For the full list of aliases, see&lt;br /&gt;
	https://commons.wikimedia.org/w/index.php?title=Special:WhatLinksHere/Template:Category_redirect&amp;amp;hidetrans=1&amp;amp;hidelinks=1&lt;br /&gt;
]]&lt;br /&gt;
function p.getTargetFromCatRedirect(content)&lt;br /&gt;
	-- Basic filtering: only in the relevant content shown on target page itself&lt;br /&gt;
	content = (content or '')&lt;br /&gt;
		:gsub('&amp;lt;!%-%-(.-)%-%-&amp;gt;', '') -- discard HTML comments&lt;br /&gt;
		:gsub('&amp;lt;includeonly%s*&amp;gt;(.-)&amp;lt;/includeonly&amp;gt;', '') -- discard 'includeonly' sections and their content&lt;br /&gt;
		:gsub('&amp;lt;includeonly%s*&amp;gt;(.-)$', '') -- discard unclosed 'includeonly' sections&lt;br /&gt;
		:gsub('&amp;lt;[/]?onlyinclude&amp;gt;', '') -- discard 'onlyinclude' opening/closing tags&lt;br /&gt;
		:gsub('&amp;lt;[/]?noinclude&amp;gt;', '') -- discard 'noinclude' opening/closing tags&lt;br /&gt;
		:gsub('&amp;lt;/?nowiki%s*/?&amp;gt;', '') -- discard nowiki opening/closing/selfclosed tags&lt;br /&gt;
	-- Locate the template transclusion, keep their parameters only&lt;br /&gt;
	-- Note: there may potentially be several instances, this should not occur&lt;br /&gt;
	content =&lt;br /&gt;
		content:match('{{[%s_]*[Cc]ategory*[%s_]*[Rr]edirect[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Cc]at[%s_]*[Rr]edirect[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Cc]at-[Rr]edirect[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Cc]at[%s_]*[Rr]edir[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Cc]at-red[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Rr]edirect[%s_]*[Cc]ategory[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Rr]edirect[%s_]*[Cc]at[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Ss]ee[%s_]*[Cc]at[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Ee]ndashcatredirect[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Ss]ynonym[%s_]*taxon[%s_]*category[%s_]*redirect[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Ii]nvalid[%s_]*taxon[%s_]*category[%s_]*redirect[%s_]*|(.-)}}') or&lt;br /&gt;
		content:match('{{[%s_]*[Mm]onotypic[%s_]*taxon[%s_]*category[%s_]*redirect[%s_]*|(.-)}}')&lt;br /&gt;
	if not content then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	do&lt;br /&gt;
		-- Parse template parameters (they may be in arbitrary order)&lt;br /&gt;
		local params, n = {}, 0&lt;br /&gt;
		for param in content:gmatch(&amp;quot;([^|]+)&amp;quot;) do&lt;br /&gt;
			local key&lt;br /&gt;
			local pos = param:find('=')&lt;br /&gt;
			if pos then&lt;br /&gt;
				key = param:sub(1, pos - 1):match('^%s*(.-)%s*$') -- split then trim&lt;br /&gt;
				param = param:sub(pos + 1):match('^%s*(.-)%s*$') -- split then trim&lt;br /&gt;
			else&lt;br /&gt;
				n = n + 1&lt;br /&gt;
				key = tostring(n)&lt;br /&gt;
			end&lt;br /&gt;
			params[key] = param&lt;br /&gt;
		end&lt;br /&gt;
		-- The target is in parameter ['1'] of the template transclusion&lt;br /&gt;
		content = params['1']&lt;br /&gt;
	end&lt;br /&gt;
	-- Check there's an effective target parameter to the template&lt;br /&gt;
	if not content then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	content = content&lt;br /&gt;
		-- The target parameter may contain some known character entities&lt;br /&gt;
		-- (their validity in page names is not checked here, just parsed)&lt;br /&gt;
		:gsub('&amp;amp;([#%d%a]+);', function(entity)&lt;br /&gt;
			if entity:sub(1,1) == '#' then&lt;br /&gt;
				local codepoint&lt;br /&gt;
				if entity:sub(2,2) == 'x' then&lt;br /&gt;
					codepoint = tonumber(entity:sub(3), 16)&lt;br /&gt;
				else&lt;br /&gt;
					codepoint = tonumber(entity:sub(2))&lt;br /&gt;
				end&lt;br /&gt;
				if codepoint and (&lt;br /&gt;
					codepoint &amp;gt;= 0x0009 and codepoint &amp;lt;= 0x000D or -- accept some whitespace C0 controls&lt;br /&gt;
					codepoint &amp;gt;= 0x0020 and codepoint &amp;lt;= 0x10FFFD -- normal range&lt;br /&gt;
						and (codepoint &amp;lt; 0x0080 or codepoint &amp;gt; 0x009F) -- exclude C1 controls&lt;br /&gt;
						and (codepoint &amp;lt; 0xDC00 or codepoint &amp;gt; 0xDFFF) -- exclude surrogates&lt;br /&gt;
						and (codepoint &amp;lt; 0xFDD0 or codepoint &amp;gt; 0xFDEF) -- exclude non-characters in BMP&lt;br /&gt;
						and codepoint % 0x10000 &amp;lt;= 0xFFFD -- exclude non-characters at end of planes&lt;br /&gt;
				) then&lt;br /&gt;
					return char(codepoint)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				if entity == 'amp' then return '&amp;amp;' end&lt;br /&gt;
				if entity == 'gt' then return '&amp;gt;' end&lt;br /&gt;
				if entity == 'lt' then return '&amp;lt;' end&lt;br /&gt;
				if entity == 'quot' then return '&amp;quot;' end&lt;br /&gt;
			end&lt;br /&gt;
			return entity&lt;br /&gt;
		end)&lt;br /&gt;
		-- Normalize spaces in the target according to Mediawiki pagename rules&lt;br /&gt;
		:gsub('[%s_]+', ' ')&lt;br /&gt;
		-- The target parameter should be trimmed by the template&lt;br /&gt;
		:match('^ ?(.-) ?$')&lt;br /&gt;
	-- The target should not be empty and not contain tag delimiters or other character forbidden in full page names&lt;br /&gt;
	-- Note: templates used inside the target parameter of the soft redirect are not expanded (there should be none)&lt;br /&gt;
	-- as this is costly or memory intensive and slow (would require invoking a full mediawiki parser).&lt;br /&gt;
	if content == '' or content:find('[&amp;lt;&amp;gt;%[%]{|}]') then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	-- The 'Category:' namespace is implied (it will be prefixed by a ':' to create a link)&lt;br /&gt;
	return 'Category:' .. (&lt;br /&gt;
		content:match('^:*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy] *: *(.-)$') or&lt;br /&gt;
		content&lt;br /&gt;
	)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get page name that a redirect leads to, or nil if it isn't a redirect.&lt;br /&gt;
function p.getTargetFrom(obj)&lt;br /&gt;
	--[[&lt;br /&gt;
	obj:getContent() is intensive for large pages, but obj.redirectTarget returns directly&lt;br /&gt;
	the target without needing to load and parse the text content of the wiki page.&lt;br /&gt;
	This works for wiki pages that are hard redirects (content starting by '#REDIRECT').&lt;br /&gt;
	In this case, using p.getTargetFromText(obj:getContent()) is not needed.&lt;br /&gt;
	]]&lt;br /&gt;
	local r = obj.isRedirect and obj.redirectTarget&lt;br /&gt;
	if not r then&lt;br /&gt;
		--[[&lt;br /&gt;
		For pages using soft redirects (like categories), we must detect the template&lt;br /&gt;
		used in the page content itself (this may be costly in memory and slow if not&lt;br /&gt;
		loaded in the cache of page contents).&lt;br /&gt;
		]]&lt;br /&gt;
		if obj:inNamespace('Category') then&lt;br /&gt;
			r = p.getTargetFromCatRedirect(obj:getContent())&lt;br /&gt;
			if r then&lt;br /&gt;
				local obj2 = getTitle(r)&lt;br /&gt;
				if obj2 then -- getTitle may fail&lt;br /&gt;
					obj = obj2 -- true replacement withe the target&lt;br /&gt;
					-- special: the replacement may also be a hard redirect&lt;br /&gt;
					r = obj.isRedirect and obj.redirectTarget&lt;br /&gt;
					-- not done here: second soft redirect detection&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if not r and obj.isRedirect then&lt;br /&gt;
			-- The page is a redirect, but matching failed, which may be a bug&lt;br /&gt;
			-- in 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 obj.fullText or obj.prefixedText&lt;br /&gt;
			))&lt;br /&gt;
		end&lt;br /&gt;
		r = obj.fulltext and obj.fullText or obj.prefixedText&lt;br /&gt;
	end&lt;br /&gt;
	return r&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function fmtTitle(target, fulltext, ensureTitleExists)&lt;br /&gt;
	local titleObj&lt;br /&gt;
	if type(target) == 'string' or type(target) == 'number' then&lt;br /&gt;
		titleObj = getTitle(target)&lt;br /&gt;
	elseif type(target) == 'table' and type(target.getContent) == 'function' then&lt;br /&gt;
		titleObj = target&lt;br /&gt;
	else&lt;br /&gt;
		error(string.format(&amp;quot;bad argument #1 to 'fmtTitle' &amp;quot; ..&lt;br /&gt;
			&amp;quot;(string, number, or title object expected, got %s)&amp;quot;,&lt;br /&gt;
			type(target)&lt;br /&gt;
		), 2)&lt;br /&gt;
	end&lt;br /&gt;
	if titleObj then&lt;br /&gt;
		if not ensureTitleExists or ensureTitleExists and titleObj.exists then&lt;br /&gt;
			return fulltext and titleObj.fullText or titleObj.prefixedText&lt;br /&gt;
		end&lt;br /&gt;
	end&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, rname, fulltext, ensureTitleExists)&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(&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 titleObj and titleObj.exists and&lt;br /&gt;
		(titleObj.isRedirect or titleObj:inNamespace(&amp;quot;Category&amp;quot;))&lt;br /&gt;
	then&lt;br /&gt;
		-- Find the target by using string matching on the page content.&lt;br /&gt;
		return fmtTitle(p.getTargetFrom(titleObj), fulltext, ensureTitleExists)&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, ensureTitleExists)&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;
	rname = rname:match(&amp;quot;%[%[%s*([%]|]-)%s*%]%]&amp;quot;) or rname&lt;br /&gt;
	local ret = p.getTarget(rname, fulltext, ensureTitleExists) or&lt;br /&gt;
		fmtTitle(rname, fulltext, ensureTitleExists)&lt;br /&gt;
	link = bracket and (ret == rname and &amp;quot;[[:%s]]&amp;quot; or &amp;quot;[[:%s|%s]]&amp;quot;) or &amp;quot;%s&amp;quot;&lt;br /&gt;
	return ret and link:format(ret, rname)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function use(x)&lt;br /&gt;
	return x and (x == '1' or x == 't' or x == 'true' or x == 'y' or x == 'yes') or nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Provides access to the luaMain function from wikitext, may return redlinks,&lt;br /&gt;
-- albeit page titles that do not exist in the wiki.&lt;br /&gt;
-- Parameters alt, bracket, fulltext, ensureTitleExists are optional&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = getArgs(frame, {frameOnly = true})&lt;br /&gt;
	local rname = args[1]&lt;br /&gt;
	local alt = args[2] or ''&lt;br /&gt;
	local bracket = use(args.bracket)&lt;br /&gt;
	local fulltext = use(args.fulltext)&lt;br /&gt;
	local ensureTitleExists = use(args.noredlinks)&lt;br /&gt;
&lt;br /&gt;
	return p.luaMain(rname, bracket, fulltext, ensureTitleExists) or alt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- main variant, returns empty string if a redlink would be returned otherwise.&lt;br /&gt;
-- '|noredlinks=true' by default.&lt;br /&gt;
function p.mainE(frame)&lt;br /&gt;
	local args = getArgs(frame, {frameOnly = true})&lt;br /&gt;
	local rname = args[1]&lt;br /&gt;
	local alt = args[2] or ''&lt;br /&gt;
	local bracket = use(args.bracket)&lt;br /&gt;
	local fulltext = use(args.fulltext)&lt;br /&gt;
&lt;br /&gt;
	return p.luaMain(rname, bracket, fulltext, true) or alt&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- main variant, returns args[2] if a redlink would be returned otherwise.&lt;br /&gt;
-- '|bracket=true|noredlinks=true' by default&lt;br /&gt;
function p.mainA(frame)&lt;br /&gt;
	local args = getArgs(frame, {frameOnly = true})&lt;br /&gt;
	local rname = args[1]&lt;br /&gt;
	local alt = args[2] or ''&lt;br /&gt;
	local bracket = use(args.bracket)&lt;br /&gt;
&lt;br /&gt;
	return p.luaMain(rname, bracket, true, true) or alt&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 = 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>Imported&gt;Verdy p</name></author>
		
	</entry>
</feed>