Changes

Jump to: navigation, search

Module:Category handler

1,618 bytes added, 02:39, 25 June 2013
add blacklist check
local basepageSubpage = require('Module:Basepage subpage').main
 
-- Configuration data.
local cfg = {}
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.
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
local pageObject = getPageObject()
if not needsCategory( pageObject ) then return end
if needsBlacklistCheck() then return needsBlacklistCheckfindBlacklistMatch(pageObject ) end
end
Anonymous user

Navigation menu