Module:Redirect hatnote: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
detect more types of invalid and missing redirects
m (Protected Module:Redirect hatnote: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
(detect more types of invalid and missing redirects)
Line 8:
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local mRedirect -- lazily initialise [[Module:Redirect]]
 
local p = {}
Line 112 ⟶ 111:
end
 
function p._redirect(redirect, data, options, titleObjcurrentTitle, redirectTitle, targetTitle)
-- Validate the input. Don't bother checking titleObjcurrentTitle, asredirectTitle it is only usedor
-- targetTitle, as they are only used in testing.
-- for testing purposes.
checkType('_redirect', 1, redirect, 'string')
checkType('_redirect', 2, data, 'table', true)
Line 120 ⟶ 119:
data = data or {}
options = options or {}
titleObj currentTitle = titleObjcurrentTitle or mw.title.getCurrentTitle()
 
-- Generate the text.
Line 132:
text = table.concat(text, ' ')
-- Generate the optionstracking to pass to [[Module:Hatnote]]category.
-- We don't need a tracking category if the template invocation has been
local mhOptions = {}
-- copied directly from the docs, or if we aren't in mainspace.
mhOptions.selfref = options.selfref
 
-- Find whether to add the tracking category.
-- We only add the category if both of the following are true:
-- a) redirect isn't any of the keywords 'REDIRECT', 'REDIRECT1',
-- 'REDIRECT2', ..., or 'TERM'.
-- b) we are in the main namespace.
-- If these are both true, then we check for existence of the redirect. If
-- it doesn't exist, then we add the missing redirect category. If it does
-- exist, but the redirect target is not the current page, we add the
-- invalid redirect category.
local category
if not redirect:find('^REDIRECT%d*$') and redirect ~= 'TERM' then--
ifand titleObjcurrentTitle.namespace == 0 then
titleObj = titleObj or mw.title.getCurrentTitle()
then
if titleObj.namespace == 0 then
local redirectTitle = redirectTitle or getTitle(redirect)
if not redirectTitle or not redirectTitle.exists then
category = '[[Category:Missing redirects]]'
ifelseif not redirectTitle.existsisRedirect then
category = '[[Category:Missing redirects]]'
category = '[[Category:Invalid redirects]]'
else
mRedirect = require('Module:Redirect')
local targetmRedirect = mRedirect.getTargetrequire(redirectTitle'Module:Redirect')
local targetTitletarget = target and getTitlemRedirect.getTarget(targetredirectTitle)
iftargetTitle = targetTitle andor nottarget mw.title.equals(targetTitle,and titleObjgetTitle(target) then
if targetTitle and targetTitle ~= currentTitle then
category = '[[Category:Invalid redirects]]'
category = 'Invalid redirects'
end
end
end
end
end
category = category and string.format('[[Category:%s]]', category) or ''
 
-- Generate the options to pass to [[Module:Hatnote]].
local mhOptions = {}
if currentTitle.namespace == 0
and redirectTitle and redirectTitle.namespace ~= 0
then
-- We are on a mainspace page, and the hatnote starts with something
-- like "Wikipedia:Foo redirects here", so automatically label it as a
-- self-reference.
mhOptions.selfref = true
else
mhOptions.selfref = options.selfref
end
 
return mHatnote._hatnote(text, mhOptions) .. category
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu