Module:Protection banner: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(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: | Line 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 |
||
Line 235: | Line 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 |
|||
⚫ | |||
-- any duplicate keys, so check for those. |
|||
if obj.reason |
|||
do |
|||
⚫ | |||
local data |
|||
and cfg.banners[obj.action][obj.reason] |
|||
⚫ | |||
⚫ | |||
and cfg.banners[obj.action] |
|||
and cfg.banners[obj.action][args.reason] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
elseif cfg.defaultBanners[obj.action] then |
|||
⚫ | |||
⚫ | |||
elseif cfg.defaultBanners.edit then |
|||
⚫ | |||
⚫ | |||
error('no banner data found; please define data for cfg.defaultBanners') |
|||
⚫ | |||
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 |
||
Line 323: | Line 342: | ||
} |
} |
||
return mMessageBox.main('mbox', mbargs) |
return mMessageBox.main('mbox', mbargs) |
||
end |
|||
function banner:export() |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
Line 334: | Line 362: | ||
local args = mArguments.getArgs(frame) |
local args = mArguments.getArgs(frame) |
||
return p._main(args) |
return p._main(args) |
||
⚫ | |||
function p._main(args) |
|||
-- Find what action we are supposed to be protecting the page from. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||