Module:Protection banner: Difference between revisions
Content added Content deleted
Enwikipedia>Mr. Stradivarius (Add render methods to the Padlock and Banner classes, and call them from the exportToLua function. Now we have something to look at, yay!) |
Enwikipedia>Mr. Stradivarius (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 |
||
) |
) |
||
else |
|||
return '' |
|||
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) |
|||
name, |
|||
self._titleObj = titleObj |
|||
configObj, |
|||
⚫ | |||
⚫ | |||
namespace |
|||
function ProtectionCategory:render() |
|||
⚫ | |||
local configObj = self._configObj |
|||
--[[ |
|||
local protectionStatusObj = self._protectionStatusObj |
|||
-- Sets the protection category. If a category name is not provided, this |
|||
local titleObj = self._titleObj |
|||
-- method gets a category name from the module config, given a combination |
|||
-- of the protection type, the protection level, the namespace number, the |
|||
-- reason for protection, and the expiry date. |
|||
--]] |
|||
-- If a name was provided, use that. |
|||
if name then |
|||
⚫ | |||
⚫ | |||
-- 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') |
||
⚫ | |||
if not namespace or type(namespace) ~= 'number' then |
|||
if not nskey and namespace % 2 == 1 then |
|||
⚫ | |||
else |
|||
⚫ | |||
if not nskey and ns % 2 == 1 then |
|||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
Line 883: | Line 873: | ||
if cat then |
if cat then |
||
Category.setName(self, cat) |
Category.setName(self, cat) |
||
⚫ | |||
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 |
|||
⚫ | |||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
||
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() |
|||
⚫ | |||
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 |
|||
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |