https://wiki.seshstation.com/index.php?title=Module:Redirect&feed=atom&action=historyModule:Redirect - Revision history2024-03-29T13:32:25ZRevision history for this page on the wikiMediaWiki 1.36.1https://wiki.seshstation.com/index.php?title=Module:Redirect&diff=436&oldid=prevSESHstation: 1 revision imported2021-11-21T11:11:28Z<p>1 revision imported</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:11, 21 November 2021</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>SESHstationhttps://wiki.seshstation.com/index.php?title=Module:Redirect&diff=435&oldid=prevtmpl>Johnuniq: restore p.getTargetFromText which is used by Module:RfD which is causing "Lua error in Module:RfD at line 87: attempt to call upvalue 'getTargetFromText' (a nil value)"2021-09-10T07:46:37Z<p>restore p.getTargetFromText which is used by <a href="/index.php?title=Module:RfD&action=edit&redlink=1" class="new" title="Module:RfD (page does not exist)">Module:RfD</a> which is causing "Lua error in Module:RfD at line 87: attempt to call upvalue 'getTargetFromText' (a nil value)"</p>
<p><b>New page</b></p><div>-- This module provides functions for getting the target of a redirect page.<br />
<br />
local p = {}<br />
<br />
-- Gets a mw.title object, using pcall to avoid generating script errors if we<br />
-- are over the expensive function count limit (among other possible causes).<br />
local function getTitle(...)<br />
local success, titleObj = pcall(mw.title.new, ...)<br />
if success then<br />
return titleObj<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
-- Gets the name of a page that a redirect leads to, or nil if it isn't a<br />
-- redirect.<br />
function p.getTargetFromText(text)<br />
local target = string.match(<br />
text,<br />
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)%]%]"<br />
) or string.match(<br />
text,<br />
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]|]-)|[^%[%]]-%]%]"<br />
)<br />
return target and mw.uri.decode(target, 'PATH')<br />
end<br />
<br />
-- Gets the target of a redirect. If the page specified is not a redirect,<br />
-- returns nil.<br />
function p.getTarget(page, fulltext)<br />
-- Get the title object. Both page names and title objects are allowed<br />
-- as input.<br />
local titleObj<br />
if type(page) == 'string' or type(page) == 'number' then<br />
titleObj = getTitle(page)<br />
elseif type(page) == 'table' and type(page.getContent) == 'function' then<br />
titleObj = page<br />
else<br />
error(string.format(<br />
"bad argument #1 to 'getTarget'"<br />
.. " (string, number, or title object expected, got %s)",<br />
type(page)<br />
), 2)<br />
end<br />
if not titleObj then<br />
return nil<br />
end<br />
local targetTitle = titleObj.redirectTarget<br />
if targetTitle then<br />
if fulltext then<br />
return targetTitle.fullText<br />
else<br />
return targetTitle.prefixedText<br />
end<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
--[[<br />
-- Given a single page name determines what page it redirects to and returns the<br />
-- target page name, or the passed page name when not a redirect. The passed<br />
-- page name can be given as plain text or as a page link.<br />
--<br />
-- Returns page name as plain text, or when the bracket parameter is given, as a<br />
-- page link. Returns an error message when page does not exist or the redirect<br />
-- target cannot be determined for some reason.<br />
--]]<br />
function p.luaMain(rname, bracket, fulltext)<br />
if type(rname) ~= "string" or not rname:find("%S") then<br />
return nil<br />
end<br />
bracket = bracket and "[[%s]]" or "%s"<br />
rname = rname:match("%[%[(.+)%]%]") or rname<br />
local target = p.getTarget(rname, fulltext)<br />
local ret = target or rname<br />
ret = getTitle(ret)<br />
if ret then<br />
if fulltext then<br />
ret = ret.fullText<br />
else<br />
ret = ret.prefixedText<br />
end<br />
return bracket:format(ret)<br />
else<br />
return nil<br />
end<br />
end<br />
<br />
-- Provides access to the luaMain function from wikitext.<br />
function p.main(frame)<br />
local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})<br />
return p.luaMain(args[1], args.bracket, args.fulltext) or ''<br />
end<br />
<br />
-- Returns true if the specified page is a redirect, and false otherwise.<br />
function p.luaIsRedirect(page)<br />
local titleObj = getTitle(page)<br />
if not titleObj then<br />
return false<br />
end<br />
if titleObj.isRedirect then<br />
return true<br />
else<br />
return false<br />
end<br />
end<br />
<br />
-- Provides access to the luaIsRedirect function from wikitext, returning 'yes'<br />
-- if the specified page is a redirect, and the blank string otherwise.<br />
function p.isRedirect(frame)<br />
local args = require('Module:Arguments').getArgs(frame, {frameOnly = true})<br />
if p.luaIsRedirect(args[1]) then<br />
return 'yes'<br />
else<br />
return ''<br />
end<br />
end<br />
<br />
return p</div>tmpl>Johnuniq