Module:Category handler: Difference between revisions
Content added Content deleted
(start a replacement for Template:Category handler) |
(add blacklist check) |
||
Line 1: | Line 1: | ||
local basepageSubpage = require('Module:Basepage subpage').main |
|||
-- Configuration data. |
-- Configuration data. |
||
local cfg = {} |
local cfg = {} |
||
Line 12: | Line 10: | ||
cfg.main = 'main' |
cfg.main = 'main' |
||
cfg.other = 'other' |
cfg.other = 'other' |
||
-- The categorisation blacklist. Pages that match Lua patterns in this |
|||
-- list will not be categorised unless the appropriate options are set. |
|||
-- If the namespace name has a space in, it must be written with an |
|||
-- underscore, e.g. "Wikipedia_talk". Other parts of the title can have |
|||
-- either underscores or spaces. |
|||
cfg.blacklist = { |
|||
'^Main Page$', -- don't categorise the main page. |
|||
⚫ | |||
-- Don't categorise the following pages or their subpages. |
|||
'^Wikipedia:Cascade%-protected items$', |
|||
'^Wikipedia:Cascade%-protected items/.*$', |
|||
'^User:UBX$', -- The userbox "template" space. |
|||
'^User:UBX/.*$', |
|||
'^User_talk:UBX$', |
|||
'^User_talk:UBX/.*$', |
|||
-- Don't categorise subpages of these pages, but allow |
|||
-- categorisation of the base page. |
|||
'^Wikipedia:Template messages/.*$', |
|||
'/[aA]rchive' -- Don't categorise archives. |
|||
} |
|||
-- Module start. |
-- Module start. |
||
Line 59: | Line 80: | ||
return true |
return true |
||
end |
end |
||
end |
|||
-- Searches the blacklist to find a match with the page object. The |
|||
-- string searched is the namespace plus the title, including subpages. |
|||
-- Returns true if there is a match, otherwise returns false. |
|||
local function findBlacklistMatch(pageObject) |
|||
if not pageObject then return end |
|||
-- Get the title to check. |
|||
local title = pageObject.nsText -- Get the namespace. |
|||
-- Append a colon if the namespace isn't the blank string. |
|||
if #title > 0 then |
|||
title = title .. ':' .. pageObject.text |
|||
else |
|||
title = pageObject.text |
|||
end |
|||
-- Check the blacklist. |
|||
for i, pattern in ipairs( cfg.blacklist ) do |
|||
if mw.ustring.match( title, pattern ) then |
|||
return true |
|||
end |
|||
end |
|||
return false |
|||
end |
end |
||
Line 64: | Line 109: | ||
local pageObject = getPageObject() |
local pageObject = getPageObject() |
||
if not needsCategory( pageObject ) then return end |
if not needsCategory( pageObject ) then return end |
||
if needsBlacklistCheck() then |
|||
⚫ | |||
return |
return findBlacklistMatch( pageObject ) |
||
end |
|||
end |
end |
||