Module:Redirect hatnote: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
(control for missing pages tables)
Line 8:
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local mRedirect -- lazily initialise [[Module:Redirect]]
 
local p = {}
 
local function getTitle(...)
local success, titleObj = pcall(mw.title.new, ...)
if success then
return titleObj
else
return nil
end
end
 
function p.redirect(frame)
Line 127 ⟶ 137:
 
-- Find whether to add the tracking category.
-- We only add the category if allboth 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
-- c) the redirect title does not exist.
-- 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
titleObj = titleObj or mw.title.getCurrentTitle()
if titleObj.namespace == 0 then
local success, redirectTitle = pcallgetTitle(mw.title.new, redirect)
if success and not redirectTitle.exists then
if not redirectTitle.exists then
category = '[[Category:Missing redirects]]'
else
mRedirect = require('Module:Redirect')
local target = mRedirect.main(redirect)
local targetTitle = getTitle(target)
if not mw.title.equals(targetTitle, titleObj) then
category = '[[Category:Invalid redirects]]'
end
end
end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu