Changes

Jump to: navigation, search

Module:Category handler

2 bytes added, 09:57, 13 July 2014
apply changes from sandbox as requested by User:Jackmcbarn which removes middleclass dependency
-- Load required modules
local class = require('Module:Middleclass').class
local yesno = require('Module:Yesno')
--------------------------------------------------------------------------------
local CategoryHandler = class('{}CategoryHandler.__index = CategoryHandler')
function CategoryHandler:initialize.new(data, args) self.local obj = setmetatable({ _data = data self., _args = args}, CategoryHandler)
-- Set the title object
do
local pagename = selfobj:parameter('demopage')
local success, titleObj = pcall(mw.title.new, pagename)
if success and titleObj then
selfobj.title = titleObj
else
selfobj.title = mw.title.getCurrentTitle() selfobj._usesCurrentTitle = true
end
end
-- Set suppression parameter values
for _, key in ipairs{'nocat', 'categories'} do
local value = selfobj:parameter(key)
value = trimWhitespace(value, true)
selfobj['_' .. key] = yesno(value)
end
do
local subpage = selfobj:parameter('subpage') local category2 = selfobj:parameter('category2')
if type(subpage) == 'string' then
subpage = mw.ustring.lower(subpage)
subpage = mw.ustring.lower(category2)
end
selfobj._subpage = trimWhitespace(subpage, true) selfobj._category2 = trimWhitespace(category2) -- don't remove blank values
end
return obj
end
function p._main(args, data)
data = data or mw.loadData('Module:Category handler/data')
local handler = CategoryHandler:.new(data, args)
if handler:isSuppressed() then
return nil
Anonymous user

Navigation menu