Editing Module:Category handler
From MINR.ORG WIKI
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 15: | Line 15: | ||
-- Load required modules | -- Load required modules | ||
+ | local class = require('Module:Middleclass').class | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
Line 46: | Line 47: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
− | local CategoryHandler = | + | local CategoryHandler = class('CategoryHandler') |
− | |||
− | function CategoryHandler | + | function CategoryHandler:initialize(data, args) |
− | + | self._data = data | |
+ | self._args = args | ||
-- Set the title object | -- Set the title object | ||
do | do | ||
− | local pagename = | + | local pagename = self:parameter('demopage') |
− | local | + | local success, titleObj = pcall(mw.title.new, pagename) |
− | |||
− | |||
− | |||
if success and titleObj then | if success and titleObj then | ||
− | + | self.title = titleObj | |
− | |||
− | |||
− | |||
else | else | ||
− | + | self.title = mw.title.getCurrentTitle() | |
− | + | self._usesCurrentTitle = true | |
end | end | ||
end | end | ||
Line 72: | Line 67: | ||
-- Set suppression parameter values | -- Set suppression parameter values | ||
for _, key in ipairs{'nocat', 'categories'} do | for _, key in ipairs{'nocat', 'categories'} do | ||
− | local value = | + | local value = self:parameter(key) |
value = trimWhitespace(value, true) | value = trimWhitespace(value, true) | ||
− | + | self['_' .. key] = yesno(value) | |
end | end | ||
do | do | ||
− | local subpage = | + | local subpage = self:parameter('subpage') |
− | local category2 = | + | local category2 = self:parameter('category2') |
if type(subpage) == 'string' then | if type(subpage) == 'string' then | ||
subpage = mw.ustring.lower(subpage) | subpage = mw.ustring.lower(subpage) | ||
Line 85: | Line 80: | ||
subpage = mw.ustring.lower(category2) | subpage = mw.ustring.lower(category2) | ||
end | end | ||
− | + | self._subpage = trimWhitespace(subpage, true) | |
− | + | self._category2 = trimWhitespace(category2) -- don't remove blank values | |
end | end | ||
− | |||
end | end | ||
Line 245: | Line 239: | ||
function p._main(args, data) | function p._main(args, data) | ||
data = data or mw.loadData('Module:Category handler/data') | data = data or mw.loadData('Module:Category handler/data') | ||
− | local handler = CategoryHandler | + | local handler = CategoryHandler:new(data, args) |
if handler:isSuppressed() then | if handler:isSuppressed() then | ||
return nil | return nil |