Module:Protection banner: Difference between revisions
only show banners for actions other than edit if they're more restricted than edit
(allow user-specified args to overwrite default args; updated from sandbox) |
(only show banners for actions other than edit if they're more restricted than edit) |
||
Line 67: | Line 67: | ||
-- other items down accordingly. | -- other items down accordingly. | ||
return table.insert(t, table.remove(t, pos)) | return table.insert(t, table.remove(t, pos)) | ||
end | |||
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 | |||
end | |||
return retval | |||
end | end | ||
Line 846: | Line 863: | ||
function p._main(args, cfg, title) | function p._main(args, cfg, title) | ||
args = args or {} | args = args or {} | ||
cfg = cfg or require( | cfg = cfg or require(CONFIG_MODULE) | ||
-- Initialise the protection object and check for errors | -- Initialise the protection object and check for errors | ||
Line 869: | Line 886: | ||
) | ) | ||
end | end | ||
local ret = {} | local ret = {} | ||
-- Render the banner | -- 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 not walkHierarchy(cfg.hierarchy, protectionObj.level)[effectiveProtectionLevel('edit', protectionObj.title)] then | |||
-- Initialise the blurb object | |||
local blurbObj = Blurb.new(protectionObj, args, cfg) | |||
-- Render the banner | |||
if protectionObj:isProtected() then | |||
ret[#ret + 1] = tostring( | |||
(yesno(args.small) and Padlock or Banner) | |||
.new(protectionObj, blurbObj, cfg) | |||
) | |||
end | |||
end | end | ||
-- Render the categories | -- Render the categories | ||
if yesno(args.category) ~= false then | if yesno(args.category) ~= false then | ||
Line 895: | Line 916: | ||
-- Find default args, if any. | -- Find default args, if any. | ||
local | local parent = frame.getParent and frame:getParent() | ||
local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')] or {} | |||
-- Find user args, and use the parent frame if we are being called from a | -- Find user args, and use the parent frame if we are being called from a |