Anonymous user
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 p = {}
Line 112 ⟶ 111:
end
function p._redirect(redirect, data, options,
-- Validate the input. Don't bother checking
-- targetTitle, as they are only used in testing.
checkType('_redirect', 1, redirect, 'string')
checkType('_redirect', 2, data, 'table', true)
Line 120 ⟶ 119:
data = data or {}
options = options or {}
-- Generate the text.
Line 132:
text = table.concat(text, ' ')
-- Generate the
-- 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▼
local category
if not redirect:find('^REDIRECT%d*$') and redirect ~= 'TERM'
▲ titleObj = titleObj or mw.title.getCurrentTitle()
then
▲ if titleObj.namespace == 0 then
▲ category = '[[Category:Missing redirects]]'
if targetTitle and targetTitle ~= currentTitle then
▲ category = '[[Category:Invalid redirects]]'
category = 'Invalid redirects'
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
return mHatnote._hatnote(text, mhOptions) .. category
|