Module:Redirect: Difference between revisions

add p.getTargetFromText
m (Changed protection level of Module:Redirect: High-risk Lua module: allow template editors ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
(add p.getTargetFromText)
Line 12:
return nil
end
end
 
-- Gets the name of a page that a redirect leads to, or nil if it isn't a
-- redirect.
function p.getTargetFromText(text)
return string.match(
text,
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]]-)%]%]"
)
end
 
Line 36 ⟶ 45:
-- Find the target by using string matching on the page content.
local target = stringp.matchgetTargetFromText(titleObj:getContent() or "")
titleObj:getContent() or "",
"^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]]-)%]%]"
)
if target then
local targetTitle = getTitle(target)
Anonymous user