Module:Protection banner: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(make Blurb be responsible for setting its own fields)
(put Protection in charge of generating its own category links)
Line 301: Line 301:
end
end


function Protection:makeExpiryCategory()
function Protection:needsExpiry()
local cfg = self._cfg
local cfg = self._cfg
if not self.expiry
return not self.expiry
and cfg.expiryCheckActions[self.action]
and cfg.expiryCheckActions[self.action]
and self.reason -- the old {{pp-protected}} didn't check for expiry
and self.reason -- the old {{pp-protected}} didn't check for expiry
and not cfg.reasonsWithoutExpiryCheck[self.reason]
and not cfg.reasonsWithoutExpiryCheck[self.reason]
then
return makeCategoryLink(self._cfg.msg['tracking-category-expiry'])
end
end
end


function Protection:makeErrorCategory()
function Protection:isIncorrect()
local expiry = self.expiry
local expiry = self.expiry
if not self:isProtected()
return not self:isProtected()
or type(expiry) == 'number' and expiry < os.time()
or type(expiry) == 'number' and expiry < os.time()
then
return makeCategoryLink(self._cfg.msg['tracking-category-incorrect'])
end
end
end


function Protection:makeTemplateCategory()
function Protection:isTemplateProtectedNonTemplate()
local action, namespace = self.action, self.title.namespace
local action, namespace = self.action, self.title.namespace
if self.level == 'templateeditor'
return self.level == 'templateeditor'
and (
and (
(action ~= 'edit' and action ~= 'move')
(action ~= 'edit' and action ~= 'move')
or (namespace ~= 10 and namespace ~= 828)
or (namespace ~= 10 and namespace ~= 828)
)
)
end
then

return makeCategoryLink(self._cfg.msg['tracking-category-template'])
function Protection:makeCategoryLinks()
local msg = self._cfg.msg
local ret = { self:makeProtectionCategory() }
if self:needsExpiry() then
ret[#ret + 1] = makeCategoryLink(msg['tracking-category-expiry'])
end
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(msg['tracking-category-incorrect'])
end
if self:isTemplateProtectedNonTemplate() then
ret[#ret + 1] = makeCategoryLink(msg['tracking-category-template'])
end
end
return table.concat(ret)
end
end


Line 916: Line 922:
-- Render the categories
-- Render the categories
if yesno(args.category) ~= false then
if yesno(args.category) ~= false then
ret[#ret + 1] = protectionObj:makeProtectionCategory()
ret[#ret + 1] = protectionObj:makeCategoryLinks()
ret[#ret + 1] = protectionObj:makeExpiryCategory()
ret[#ret + 1] = protectionObj:makeErrorCategory()
ret[#ret + 1] = protectionObj:makeTemplateCategory()
end
end