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. | ||
-- This could be problematic if the data table and the banner object have | |||
if | -- any duplicate keys, so check for those. | ||
do | |||
local data | |||
if args.reason | |||
and cfg.banners[obj.action] | |||
and cfg.banners[obj.action][args.reason] | |||
then | |||
data = cfg.banners[obj.action][obj.reason] | |||
elseif cfg.defaultBanners[obj.action] then | |||
data = cfg.defaultBanners[obj.action] | |||
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 | end | ||