Module:Redirect/sandbox: Difference between revisions

Content deleted Content added
m sync
remove the getTitle function, as it is no longer necessary after changes to mw.title inside Scribunto; and use more standard _main and _isRedirect and deprecate luaMain and luaIsRedirect
Line 2:
 
local p = {}
 
-- Gets a mw.title object, using pcall to avoid generating script errors if we
-- are over the expensive function count limit (among other possible causes).
local function getTitle(...)
local success, titleObj = pcall(mw.title.new, ...)
if success then
return titleObj
else
return nil
end
end
 
-- Gets the name of a page that a redirect leads to, or nil if it isn't a
Line 33 ⟶ 22:
local titleObj
if type(page) == 'string' or type(page) == 'number' then
titleObj = getTitlemw.title.new(page)
elseif type(page) == 'table' and type(page.getContent) == 'function' then
titleObj = page
Line 50 ⟶ 39:
local target = p.getTargetFromText(titleObj:getContent() or "")
if target then
local targetTitle = getTitlemw.title.new(target)
if targetTitle then
return targetTitle.prefixedText
Line 75 ⟶ 64:
-- target cannot be determined for some reason.
--]]
function p.luaMain_main(rname, bracket)
if type(rname) ~= "string" or not rname:find("%S") then
return nil
Line 83 ⟶ 72:
local target = p.getTarget(rname)
local ret = target or rname
ret = getTitlemw.title.new(ret)
if ret then
ret = ret.prefixedText
Line 99 ⟶ 88:
 
-- Returns true if the specified page is a redirect, and false otherwise.
function p.luaIsRedirect_isRedirect(page)
local titleObj = getTitlemw.title.new(page)
if not titleObj then
return false
Line 121 ⟶ 110:
end
end
 
-- Aliases for deprecated function names; needed for backwards compatibility
p.luaMain = p._main
p.luaIsRedirect = p._isRedirect
 
return p