Module:Protection banner: Difference between revisions

m
1 revision imported from wikipedia:Module:Protection_banner
(bring changes from sandbox live)
m (1 revision imported from wikipedia:Module:Protection_banner)
 
(8 intermediate revisions by 7 users not shown)
Line 132:
elseif effectiveExpiry ~= 'unknown' then
obj.expiry = validateDate(effectiveExpiry, 'expiry date')
elseif args.expiry then
if cfg.indefStrings[args.expiry] then
obj.expiry = 'indef'
elseif type(args.expiry) == 'number' then
obj.expiry = args.expiry
else
obj.expiry = validateDate(args.expiry, 'expiry date')
end
end
 
Line 177 ⟶ 169:
end
return setmetatable(obj, Protection)
end
 
function Protection:needsExpiryisUserScript()
-- Whether the page is a user JavaScript or CSS page.
local title = self.title
return not selftitle.expirynamespace == 2 and (
title.contentModel == 'javascript' or title.contentModel == 'css'
)
end
 
Line 182:
return self.level ~= '*'
end
 
function Protection:shouldShowLock()
-- Whether we should output a banner/padlock
return self:isProtected() and not self:isUserScript()
end
 
-- Whether this page needs a protection category.
Protection.shouldHaveProtectionCategory = Protection.shouldShowLock
 
function Protection:isTemporary()
Line 188 ⟶ 196:
 
function Protection:makeProtectionCategory()
if not self:isProtectedshouldHaveProtectionCategory() then
local cfg = self._cfg
local title = self.title
-- Exit if the page is not protected.
if not self:isProtected() then
return ''
end
 
local cfg = self._cfg
local cfgtitle = self._cfgtitle
-- Get the expiry key fragment.
Line 209 ⟶ 216:
namespaceFragment = 'talk'
end
 
-- Define the order that key fragments are tested in. This is done with an
-- array of tables containing the value to be tested, along with its
Line 313 ⟶ 320:
end
return ''
end
 
function Protection:needsExpiry()
local cfg = self._cfg
local actionNeedsCheck = cfg.expiryCheckActions[self.action]
return not self.expiry and (
actionNeedsCheck or (
actionNeedsCheck == nil
and self.reason -- the old {{pp-protected}} didn't check for expiry
and not cfg.reasonsWithoutExpiryCheck[self.reason]
)
)
end
 
function Protection:isIncorrect()
local expiry = self.expiry
return not self:isProtectedshouldHaveProtectionCategory()
or type(expiry) == 'number' and expiry < os.time()
end
Line 344 ⟶ 339:
function Protection:makeCategoryLinks()
local msg = self._cfg.msg
local ret = { self:makeProtectionCategory() }
if self:needsExpiry() then
ret[#ret + 1] = makeCategoryLink(
msg['tracking-category-expiry'],
self.title.text
)
end
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(
Line 663 ⟶ 652:
 
function Blurb:_makeVandalTemplateParameter()
return mw.getCurrentFrame():expandTemplate{
return require('Module:Vandal-m')._main{
title="vandal-m",
args={self._args.user or self._protectionObj.title.baseText}
}
end
Line 864 ⟶ 854:
-- Render the banner
if protectionObj:isProtectedshouldShowLock() then
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)