Modul:Protection banner: Unterschied zwischen den Versionen

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)
Zeile 5: Zeile 5:
local mArguments = require('Module:Arguments')
local mArguments = require('Module:Arguments')
local mProtectionLevel = require('Module:Effective protection level')._main
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
local mMessageBox -- only needs to be loaded if we are outputting a banner, so lazily initialise


Zeile 235: Zeile 236:
obj.protectionLevel = protectionLevel or '*'
obj.protectionLevel = protectionLevel or '*'
end
end
 
-- Fetch the banner data.
-- Fetch the banner data and copy it into the object.
obj.reason = args.reason
-- This could be problematic if the data table and the banner object have
if obj.reason  
-- any duplicate keys, so check for those.
and cfg.banners[obj.action]
do
and cfg.banners[obj.action][obj.reason]
local data
then
if args.reason  
obj.data = cfg.banners[obj.action][obj.reason]
and cfg.banners[obj.action]
elseif cfg.defaultBanners and cfg.defaultBanners[obj.action] then
and cfg.banners[obj.action][args.reason]
obj.data = cfg.defaultBanners[obj.action]
then
elseif cfg.defaultBanners and cfg.defaultBanners.edit then
data = cfg.banners[obj.action][obj.reason]
obj.data = cfg.defaultBanners.edit
elseif cfg.defaultBanners[obj.action] then
else
data = cfg.defaultBanners[obj.action]
error('no banner data found; please define data for cfg.defaultBanners.edit')
elseif cfg.defaultBanners.edit then
data = cfg.defaultBanners.edit
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
end
 
return obj
return obj
end
end
Zeile 323: Zeile 342:
}
}
return mMessageBox.main('mbox', mbargs)
return mMessageBox.main('mbox', mbargs)
end
function banner:export()
-- Add the banner/padlock, protection category, and tracking categories.
local ret = ''
ret = ret .. self:renderBannerOrPadlock()
ret = ret .. self:renderProtectionCategory()
ret = ret .. self:renderTrackingCategories()
return ret
end
end


Zeile 334: Zeile 362:
local args = mArguments.getArgs(frame)
local args = mArguments.getArgs(frame)
return p._main(args)
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
end


Anonymer Benutzer