Modul:Redirect hatnote: Unterschied zwischen den Versionen

allow passing a custom title object to the p._redirect function
(create a formatUseTable to reduce code redundancy)
(allow passing a custom title object to the p._redirect function)
Zeile 102: Zeile 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)
Zeile 131: Zeile 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
local currentTitle = mw.title.getCurrentTitle()
titleObj = titleObj or mw.title.getCurrentTitle()
if currentTitle.namespace == 0 then
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
Anonymer Benutzer