Module:Protection banner: Difference between revisions
various category updates
(Add render methods to the Padlock and Banner classes, and call them from the exportToLua function. Now we have something to look at, yay!) |
(various category updates) |
||
Line 701: | Line 701: | ||
local Category = class('Category') | local Category = class('Category') | ||
function Category:initialize() | function Category:initialize(configObj, protectionStatusObj, titleObj) | ||
self._configObj = configObj | |||
self._protectionStatusObj = protectionStatusObj | |||
self._titleObj = titleObj | |||
end | end | ||
Line 708: | Line 711: | ||
end | end | ||
function Category: | function Category:render() | ||
if self. | if self._name then | ||
return string.format( | return string.format( | ||
'[[%s:%s]]', | '[[%s:%s]]', | ||
mw.site.namespaces[14].name, | mw.site.namespaces[14].name, | ||
self. | self._name | ||
) | ) | ||
end | end | ||
end | end | ||
Line 726: | Line 727: | ||
local ProtectionCategory = Category:subclass('ProtectionCategory') | local ProtectionCategory = Category:subclass('ProtectionCategory') | ||
function ProtectionCategory: | function ProtectionCategory:initialize(configObj, protectionStatusObj, titleObj) | ||
Category.initialize(self, configObj, protectionStatusObj) | |||
self._titleObj = titleObj | |||
end | |||
function ProtectionCategory:render() | |||
local configObj = self._configObj | |||
local protectionStatusObj = self._protectionStatusObj | |||
local titleObj = self._titleObj | |||
-- Get the namespace category key from the namespace number. | -- Get the namespace category key from the namespace number. | ||
local nskey | local nskey | ||
do | do | ||
local namespace = titleObj.namespace | |||
local categoryNamespaces = configObj:getConfigTable('categoryNamespaces') | local categoryNamespaces = configObj:getConfigTable('categoryNamespaces') | ||
nskey = categoryNamespaces[namespace] | |||
if not nskey and namespace % 2 == 1 then | |||
nskey = 'talk' | |||
end | end | ||
end | end | ||
Line 883: | Line 873: | ||
if cat then | if cat then | ||
Category.setName(self, cat) | Category.setName(self, cat) | ||
return Category.export(self) | |||
else | else | ||
error( | error( | ||
Line 896: | Line 887: | ||
local ExpiryCategory = Category:subclass('ExpiryCategory') | local ExpiryCategory = Category:subclass('ExpiryCategory') | ||
function ExpiryCategory:render() | |||
local configObj = self._configObj | |||
local protectionStatusObj = self._protectionStatusObj | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Line 902: | Line 898: | ||
local ErrorCategory = Category:subclass('ErrorCategory') | local ErrorCategory = Category:subclass('ErrorCategory') | ||
function ErrorCategory:render() | |||
local configObj = self._configObj | |||
local protectionStatusObj = self._protectionStatusObj | |||
local expiry = protectionStatusObj:getExpiry() | |||
local action = protectionStatusObj:getAction() | |||
local level = protectionStatusObj:getLevel() | |||
if type(expiry) == 'number' and expiry < os.time() | |||
or level == '*' | |||
or action == 'move' and level == 'autoconfirmed' | |||
then | |||
Category.setName(self, configObj:getMessage('tracking-category-incorrect')) | |||
return Category.export(self) | |||
end | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |