Module:Redirect: Difference between revisions

    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 = string.match(
    local target = p.getTargetFromText(titleObj:getContent() or "")
    titleObj:getContent() or "",
    "^%s*#[Rr][Ee][Dd][Ii][Rr][Ee][Cc][Tt]%s*:?%s*%[%[([^%[%]]-)%]%]"
    )
    if target then
    if target then
    local targetTitle = getTitle(target)
    local targetTitle = getTitle(target)