Module:Redirect/sandbox: Difference between revisions

Content deleted Content added
No edit summary
use .redirectTarget()
Tag: Reverted
Line 16:
-- Gets the name of a page that a redirect leads to, or nil if it isn't a
-- redirect.
-- Not necessary anymore; only kept to avoid breakages if it is used elsewhere
function p.getTargetFromText(text)
return string.match(
Line 43 ⟶ 44:
), 2)
end
if not titleObj or not titleObj.isRedirect then
return nil
end
targetTitle = titleObj.redirectTarget()
if targetTitle then
-- Find the target by using string matching on the page content.
if fulltext then
local target = p.getTargetFromText(titleObj:getContent() or "")
return targetTitle.fullText
if target then
local targetTitle = getTitle(target)
if targetTitle then
if fulltext then
return targetTitle.fullText
else
return targetTitle.prefixedText
end
else
return niltargetTitle.prefixedText
end
else
return nil
-- The page is a redirect, but matching failed. This indicates a bug in
-- the redirect matching pattern, so throw an error.
error(string.format(
'could not parse redirect on page "%s"',
fulltext and titleObj.fullText or titleObj.prefixedText
))
end
end