Jump to content

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:export()
function Category:render()
if self._categoryName then
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._categoryName
self._name
)
)
else
return ''
end
end
end
end
Line 726: Line 727:
local ProtectionCategory = Category:subclass('ProtectionCategory')
local ProtectionCategory = Category:subclass('ProtectionCategory')


function ProtectionCategory:setName(
function ProtectionCategory:initialize(configObj, protectionStatusObj, titleObj)
name,
Category.initialize(self, configObj, protectionStatusObj)
configObj,
self._titleObj = titleObj
protectionStatusObj,
end
namespace
 
)
function ProtectionCategory:render()
--[[
local configObj = self._configObj
-- Sets the protection category. If a category name is not provided, this
local protectionStatusObj = self._protectionStatusObj
-- method gets a category name from the module config, given a combination
local titleObj = self._titleObj
-- 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
Category.setName(self, name)
end
-- 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
nskey = categoryNamespaces[namespace]
nskey = nil
if not nskey and namespace % 2 == 1 then
else
nskey = 'talk'
nskey = categoryNamespaces[ns]
if not nskey and ns % 2 == 1 then
nskey = 'talk'
end
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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Cookies help us deliver our services. By using our services, you agree to our use of cookies.