Module:Category handler: Difference between revisions

Content added Content deleted
(add support for "categories=no" and "category2=¬")
(better fallback behaviour if we are over the expensive function count)
Line 103: Line 103:
----------------------------------------------------------------------
----------------------------------------------------------------------


-- Get dependent modules and declare the table of functions that we will
-- Get [[Module:Namespace detect]] and declare the table of functions
-- return.
-- that we will return.
local NamespaceDetect = require('Module:Namespace detect')
local NamespaceDetect = require('Module:Namespace detect')
local p = {}
local p = {}
Line 116: Line 116:
-- Find whether we need to return a category or not.
-- Find whether we need to return a category or not.
local function needsCategory( pageObject, args )
local function needsCategory( pageObject, args )
-- Don't categorise if the relevant options are set.
-- If there is no pageObject available, then that either means that we are over
-- the expensive function limit or that the title specified was invalid. Invalid
-- titles will probably only be a problem during testing, so choose the best
-- default for being over the expensive function limit, i.e. categorise the page.
if not pageObject then
return true
end
-- Only categorise if the relevant options are set.
if args[cfg.nocat] == cfg.nocatTrue
if args[cfg.nocat] == cfg.nocatTrue
or args[cfg.categories] == cfg.categoriesNo
or args[cfg.categories] == cfg.categoriesNo
Line 129: Line 122:
and args[cfg.category2] ~= cfg.category2Yes
and args[cfg.category2] ~= cfg.category2Yes
and args[cfg.category2] ~= cfg.category2Negative )
and args[cfg.category2] ~= cfg.category2Negative )
then
or ( args[cfg.subpage] == cfg.subpageNo and pageObject.isSubpage )
return false
or ( args[cfg.subpage] == cfg.subpageOnly and not pageObject.isSubpage ) then
end
-- If there is no pageObject available, then that either means that we are over
-- the expensive function limit or that the title specified was invalid. Invalid
-- titles will probably only be a problem during testing, so we choose the best
-- fallback for being over the expensive function limit. The fallback behaviour
-- of the old template was to assume the page was not a subpage, so we will do
-- the same here.
if args[cfg.subpage] == cfg.subpageNo and pageObject and pageObject.isSubpage then
return false
end
if args[cfg.subpage] == cfg.subpageOnly
and (not pageObject or (pageObject and not pageObject.isSubpage) ) then
return false
return false
else
return true
end
end
return true
end
end