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: | Line 12: | ||
return nil | return nil | ||
end | 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 | end | ||
Line 36: | Line 45: | ||
-- Find the target by using string matching on the page content. | -- Find the target by using string matching on the page content. | ||
local target = | local target = p.getTargetFromText(titleObj:getContent() or "") | ||
if target then | if target then | ||
local targetTitle = getTitle(target) | local targetTitle = getTitle(target) |