Module:Protection banner: Difference between revisions

add some more to the banner.new function
(start converting this to an object-oriented approach - the banner seems naturally suited to object-based code)
(add some more to the banner.new function)
Line 5:
local mArguments = require('Module:Arguments')
local mProtectionLevel = require('Module:Effective protection level')._main
local yesno = require('Module:Yesno')
local mMessageBox -- only needs to be loaded if we are outputting a banner, so lazily initialise
 
Line 235 ⟶ 236:
obj.protectionLevel = protectionLevel or '*'
end
 
-- Fetch the banner data and copy it into the object.
-- This could be problematic if the data table and the banner object have
obj.reason = args.reason
-- any duplicate keys, so check for those.
if obj.reason
do
and cfg.banners[obj.action]
local data
and cfg.banners[obj.action][obj.reason]
obj.reason = if args.reason
then
obj.data = and cfg.banners[obj.action][obj.reason]
elseif cfg.defaultBanners and cfg.defaultBannersbanners[obj.action] then[args.reason]
then
obj.data = cfg.defaultBanners[obj.action]
and data = cfg.banners[obj.action][obj.reason]
elseif cfg.defaultBanners and cfg.defaultBanners.edit then
obj.data =elseif cfg.defaultBanners[obj.editaction] then
obj. data = cfg.defaultBanners[obj.action]
else
error('no banner data found; please define data forelseif cfg.defaultBanners.edit') then
elseif data cfg.defaultBanners and= cfg.defaultBanners.edit then
else
error('no banner data found; please define data for cfg.defaultBanners')
end
local usedFields = {}
for k in pairs(banner) do
usedFields[k] = true
end
for k in pairs(obj) do
usedFields[k] = true
end
for k, v in pairs(data) do
if usedFields[k] then
error('banner.new: duplicate config key "' .. tostring(k) .. '" detected')
else
obj[k] = v
end
end
end
 
return obj
end
Line 323 ⟶ 342:
}
return mMessageBox.main('mbox', mbargs)
end
 
function banner:export()
-- Add the banner/padlock, protection category, and tracking categories.
local ret = ''
ret = ret .. p.self:renderBannerOrPadlock(action, protectionLevel, args)
ret = ret .. p.self:renderProtectionCategory(action, protectionLevel, args)
ret = ret .. p.self:renderTrackingCategories(action, protectionLevel, args)
return ret
end
 
Line 334 ⟶ 362:
local args = mArguments.getArgs(frame)
return p._main(args)
end
 
function p._main(args)
-- Find what action we are supposed to be protecting the page from.
 
-- Add the banner/padlock, protection category, and tracking categories.
local ret = ''
ret = ret .. p.renderBannerOrPadlock(action, protectionLevel, args)
ret = ret .. p.renderProtectionCategory(action, protectionLevel, args)
ret = ret .. p.renderTrackingCategories(action, protectionLevel, args)
return ret
end