Module:Redirect hatnote: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content deleted Content added
create a formatUseTable to reduce code redundancy |
allow passing a custom title object to the p._redirect function |
||
Line 102: | Line 102: | ||
end |
end |
||
function p._redirect(redirect, data, options) |
function p._redirect(redirect, data, options, titleObj) |
||
-- Validate the input. Don't bother checking titleObj as it is only used |
|||
-- for testing purposes. |
|||
checkType('_redirect', 1, redirect, 'string') |
checkType('_redirect', 1, redirect, 'string') |
||
checkType('_redirect', 2, data, 'table', true) |
checkType('_redirect', 2, data, 'table', true) |
||
Line 131: | Line 133: | ||
local category |
local category |
||
if not redirect:find('^REDIRECT%d*$') and redirect ~= 'TERM' then |
if not redirect:find('^REDIRECT%d*$') and redirect ~= 'TERM' then |
||
titleObj = titleObj or mw.title.getCurrentTitle() |
|||
if |
if titleObj.namespace == 0 then |
||
local success, redirectTitle = pcall(mw.title.new, redirect) |
local success, redirectTitle = pcall(mw.title.new, redirect) |
||
if success and not redirectTitle.exists then |
if success and not redirectTitle.exists then |