<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://www.verzauberte-welten.de/index.php?action=history&amp;feed=atom&amp;title=Modul%3ARedirect</id>
	<title>Modul:Redirect - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://www.verzauberte-welten.de/index.php?action=history&amp;feed=atom&amp;title=Modul%3ARedirect"/>
	<link rel="alternate" type="text/html" href="https://www.verzauberte-welten.de/index.php?title=Modul:Redirect&amp;action=history"/>
	<updated>2026-04-06T04:01:44Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Verzauberte Welten e.V.</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.verzauberte-welten.de/index.php?title=Modul:Redirect&amp;diff=452&amp;oldid=prev</id>
		<title>mw&gt;Oetterer: 1 Version</title>
		<link rel="alternate" type="text/html" href="https://www.verzauberte-welten.de/index.php?title=Modul:Redirect&amp;diff=452&amp;oldid=prev"/>
		<updated>2014-09-22T12:16:10Z</updated>

		<summary type="html">&lt;p&gt;1 Version&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&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;
	)&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)&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;
			return targetTitle.prefixedText&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;
			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)&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)&lt;br /&gt;
	local ret = target or rname&lt;br /&gt;
	ret = getTitle(ret)&lt;br /&gt;
	if ret then&lt;br /&gt;
		ret = ret.prefixedText&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) or ''&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Returns &amp;quot;yes&amp;quot; if the specified page is a redirect, and the blank string&lt;br /&gt;
-- otherwise.&lt;br /&gt;
function p.isRedirect(frame)&lt;br /&gt;
	local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})&lt;br /&gt;
	local titleObj = getTitle(args[1])&lt;br /&gt;
	if not titleObj then&lt;br /&gt;
		return ''&lt;br /&gt;
	end&lt;br /&gt;
	if titleObj.isRedirect 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>mw&gt;Oetterer</name></author>
	</entry>
</feed>