Module:Redirect hatnote: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content deleted Content added
control for missing pages tables |
|||
Line 8: | Line 8: | ||
local libraryUtil = require('libraryUtil') |
local libraryUtil = require('libraryUtil') |
||
local checkType = libraryUtil.checkType |
local checkType = libraryUtil.checkType |
||
local mRedirect -- lazily initialise [[Module:Redirect]] |
|||
local p = {} |
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) |
function p.redirect(frame) |
||
Line 127: | Line 137: | ||
-- Find whether to add the tracking category. |
-- Find whether to add the tracking category. |
||
-- We add the category if |
-- We only add the category if both of the following are true: |
||
-- a) redirect isn't any of the keywords 'REDIRECT', 'REDIRECT1', |
-- a) redirect isn't any of the keywords 'REDIRECT', 'REDIRECT1', |
||
-- 'REDIRECT2', ..., or 'TERM'. |
-- 'REDIRECT2', ..., or 'TERM'. |
||
-- b) we are in the main namespace. |
-- 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 |
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() |
titleObj = titleObj or mw.title.getCurrentTitle() |
||
if titleObj.namespace == 0 then |
if titleObj.namespace == 0 then |
||
local |
local redirectTitle = getTitle(redirect) |
||
if |
if redirectTitle then |
||
if not redirectTitle.exists then |
|||
category = '[[Category:Missing redirects]]' |
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 |
||
end |
end |