Module:Protection banner: Difference between revisions
m
11 revisions imported: import clickable buttons 2
(use actual Lua errors, and a small fix to parameter handling) |
m (11 revisions imported: import clickable buttons 2) |
||
(28 intermediate revisions by 12 users not shown) | |||
Line 4:
-- Initialise necessary modules.
require('Module:No globals')
local
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionExpiry = require('Module:Effective protection expiry')._main
local yesno = require('Module:Yesno')
Line 19 ⟶ 20:
local function makeCategoryLink(cat, sort)
if cat then
return string.format(
'[[%s:%s|%s]]',
mw.site.namespaces[14].name,
cat,
sort
)
end
end
Line 40 ⟶ 32:
-- Validation function for the expiry and the protection date
local function validateDate(dateString, dateType)
if not lang then
lang = mw.language.getContentLanguage()
end
local success, result = pcall(lang.formatDate, lang, 'U', dateString)
if success then
Line 49 ⟶ 43:
end
error(string.format(
'invalid %s:
dateType,
tostring(dateString)
Line 63 ⟶ 57:
end
-- Given a directed graph formatted as node -> table of direct successors,
-- get a table of all nodes reachable from a given node (though always
-- including the given node).
local function getReachableNodes(graph, start)
local toWalk, retval = {[start] = true}, {}
while true do
-- Can't use pairs() since we're adding and removing things as we're iterating
local k = next(toWalk) -- This always gets the "first" key
if k == nil then
return retval
end
toWalk[k] = nil
retval[k] = true
for _,v in ipairs(
if not retval[v] then
toWalk[v] = true
Line 83 ⟶ 76:
end
end
end
Line 96 ⟶ 88:
edit = true,
move = true,
autoreview = true,
upload = true
}
Line 120 ⟶ 113:
else
error(string.format(
'invalid action:
tostring(args.action)
), 3)
Line 126 ⟶ 119:
-- Set level
obj.level = args.demolevel or effectiveProtectionLevel(obj.action, obj.title)
if not obj.level or (obj.action == 'move' and obj.level == '
-- Users need to be autoconfirmed to move pages anyway, so treat
-- semi-move-protected pages as unprotected.
Line 138 ⟶ 127:
-- Set expiry
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
end
Line 211 ⟶ 197:
-- Get the namespace key fragment.
local namespaceFragment = cfg.categoryNamespaceKeys[title.namespace]
if not namespaceFragment and title.namespace % 2 == 1 then
namespaceFragment =
end
Line 241 ⟶ 224:
-- instead.
--]]
--[[
Line 327 ⟶ 305:
end
return ''
end
Line 359 ⟶ 325:
local msg = self._cfg.msg
local ret = { self:makeProtectionCategory() }
if self:isIncorrect() then
ret[#ret + 1] = makeCategoryLink(
Line 492 ⟶ 452:
if level == 'autoconfirmed' then
requestType = 'semi'
elseif level == 'extendedconfirmed' then
requestType = 'extended'
elseif level == 'templateeditor' then
requestType = 'template'
Line 758 ⟶ 720:
end
return setmetatable(obj, BannerTemplate)
end
Line 772 ⟶ 726:
or self._cfg.msg['image-filename-default']
or 'Transparent.gif'
return
file = filename,
caption = self.imageCaption
}
end
Line 789 ⟶ 744:
function Banner.new(protectionObj, blurbObj, cfg)
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
obj
obj
obj._reasonText = blurbObj:makeBannerText('text')
obj._explanationText = blurbObj:makeBannerText('explanation')
Line 824 ⟶ 779:
function Padlock.new(protectionObj, blurbObj, cfg)
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
obj
obj
obj._imageAlt = blurbObj:makeBannerText('alt')
obj._imageLink = blurbObj:makeBannerText('link')
obj.
or cfg.
or '
return setmetatable(obj, Padlock)
end
function Padlock:__tostring()
local
-- The nowiki tag helps prevent whitespace at the top of articles.
return frame:extensionTag{name = 'nowiki'} .. frame:extensionTag{
name = 'indicator',
}
end
Line 869 ⟶ 824:
local ret = {}
-- If a page's edit protection is equally or more restrictive than its
-- protection from some other action, then don't bother displaying anything
-- for the other action (except categories).
if protectionObj.action == 'edit' or
args.demolevel or
not getReachableNodes(
cfg.hierarchy,
protectionObj.level
)[effectiveProtectionLevel('edit', protectionObj.title)]
then
-- Initialise the blurb object
local blurbObj = Blurb.new(protectionObj, args, cfg)
|