Anonymous user
Module:Protection banner: Difference between revisions
use actual Lua errors, and a small fix to parameter handling
m (1 revision: import Template:Shortcut) |
(use actual Lua errors, and a small fix to parameter handling) |
||
Line 52:
dateType,
tostring(dateString)
),
end
Line 67:
-- other items down accordingly.
return table.insert(t, table.remove(t, pos))
local function walkHierarchy(hierarchy, 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)
if k == nil then break end
toWalk[k] = nil
retval[k] = true
for _,v in ipairs(hierarchy[k]) do
if not retval[v] then
toWalk[v] = true
end
end
return retval
end
Line 105 ⟶ 122:
'invalid action ("%s")',
tostring(args.action)
),
end
Line 135 ⟶ 152:
obj.reason = mw.ustring.lower(args[1])
if obj.reason:find('|') then
error('reasons cannot contain the pipe character ("|")',
end
end
Line 526 ⟶ 543:
level,
talkKey
), 8)
end
return self:_substituteParameters(msg)
Line 566 ⟶ 583:
return pagetypes[self._protectionObj.title.namespace]
or pagetypes.default
or error('no default pagetype defined', 8)
end
Line 581 ⟶ 598:
msg = protectionBlurbs.edit.default
else
error('no protection blurb defined for protectionBlurbs.edit.default', 8)
end
return self:_substituteParameters(msg)
Line 607 ⟶ 624:
msg = protectionLevels.edit.default
else
error('no protection level defined for protectionLevels.edit.default', 8)
end
return self:_substituteParameters(msg)
Line 686 ⟶ 703:
tostring(key),
type(msg)
), 4)
end
return self:_substituteParameters(msg)
Line 783 ⟶ 800:
-- Renders the banner.
makeMessageBox = makeMessageBox or require('Module:Message box').main
local reasonText = self._reasonText or error('no reason text set', 2)
local explanationText = self._explanationText
local mbargs = {
Line 846 ⟶ 863:
function p._main(args, cfg, title)
args = args or {}
cfg = cfg or require(
local protectionObj = Protection.new(args, cfg, title)
-- Initialise the protection object and check for errors▼
)▼
▲ )
)▼
▲ end
local blurbObj = Blurb.new(protectionObj, args, cfg)▼
local ret = {}
-- If a page's edit protection is equally or more restrictive than its protection from some other action,
-- Render the banner▼
-- then don't bother displaying anything for the other action (except categories).
if protectionObj:isProtected() then▼
if protectionObj.action == 'edit' or not walkHierarchy(cfg.hierarchy, protectionObj.level)[effectiveProtectionLevel('edit', protectionObj.title)] then
ret[#ret + 1] = tostring(▼
(yesno(args.small) and Padlock or Banner)▼
▲ ret[#ret + 1] = tostring(
▲ (yesno(args.small) and Padlock or Banner)
▲ )
end
end
-- Render the categories
if yesno(args.category) ~= false then
Line 895 ⟶ 896:
-- Find default args, if any.
local
-- Find user args, and use the parent frame if we are being called from a
Line 909:
-- Build the args table. User-specified args overwrite default args.
local args = {}
for k, v in pairs(defaultArgs or {}) do
args[k] = v
end
|