Module:Category handler: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add blacklist check
(start a replacement for Template:Category handler)
 
(add blacklist check)
Line 1:
local basepageSubpage = require('Module:Basepage subpage').main
 
-- Configuration data.
local cfg = {}
Line 12 ⟶ 10:
cfg.main = 'main'
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.
Line 59 ⟶ 80:
return true
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
 
Line 64 ⟶ 109:
local pageObject = getPageObject()
if not needsCategory( pageObject ) then return end
if needsBlacklistCheck() then
return needsBlacklistCheckfindBlacklistMatch( pageObject )
end
end
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu