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:
-- other items down accordingly.
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
 
Line 846 ⟶ 863:
function p._main(args, cfg, title)
args = args or {}
cfg = cfg or require('Module:Protection banner/config'CONFIG_MODULE)
 
-- Initialise the protection object and check for errors
Line 869 ⟶ 886:
)
end
-- Initialise the blurb object
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(
-- Initialise the blurb object
(yesno(args.small) and Padlock or Banner)
local blurbObj = Blurb.new(protectionObj, blurbObjargs, cfg)
)
end
-- Render the banner
if protectionObj:isProtected() then
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
local blurbObj = Blurb .new(protectionObj, argsblurbObj, cfg)
)
end
end
 
-- Render the categories
if yesno(args.category) ~= false then
Line 895 ⟶ 916:
 
-- Find default args, if any.
local parentTitleparent = frame:.getParent() and frame:getTitlegetParent()
parentTitlelocal defaultArgs = parentTitleparent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')] or {}
local defaultArgs = cfg.wrappers[parentTitle] or {}
 
-- Find user args, and use the parent frame if we are being called from a
Anonymous user