Modul:Protection banner: Unterschied zwischen den Versionen

don't use Module:Middleclass
(add category sort keys)
(don't use Module:Middleclass)
Zeile 4: Zeile 4:
-- Initialise necessary modules.
-- Initialise necessary modules.
require('Module:No globals')
require('Module:No globals')
local class = require('Module:Middleclass').class
local newFileLink = require('Module:File link').new
local newFileLink = require('Module:File link').new
local effectiveProtectionLevel = require('Module:Effective protection level')._main
local effectiveProtectionLevel = require('Module:Effective protection level')._main
Zeile 71: Zeile 70:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local Protection = class('Protection')
local Protection = {}
Protection.__index = Protection


Protection.supportedActions = {
Protection.supportedActions = {
Zeile 88: Zeile 88:
}
}


function Protection:initialize(args, cfg, title)
function Protection.new(args, cfg, title)
self._cfg = cfg
local obj = {}
self.title = title or mw.title.getCurrentTitle()
obj._cfg = cfg
obj.title = title or mw.title.getCurrentTitle()


-- Set action
-- Set action
if not args.action then
if not args.action then
self.action = 'edit'
obj.action = 'edit'
elseif self.supportedActions[args.action] then
elseif Protection.supportedActions[args.action] then
self.action = args.action
obj.action = args.action
else
else
error(string.format(
error(string.format(
Zeile 105: Zeile 106:


-- Set level
-- Set level
self.level = effectiveProtectionLevel(self.action, self.title)
obj.level = effectiveProtectionLevel(obj.action, obj.title)
if self.level == 'accountcreator' then
if obj.level == 'accountcreator' then
-- Lump titleblacklisted pages in with template-protected pages,
-- Lump titleblacklisted pages in with template-protected pages,
-- since templateeditors can do both.
-- since templateeditors can do both.
self.level = 'templateeditor'
obj.level = 'templateeditor'
elseif not self.level or (self.action == 'move' and self.level == 'autoconfirmed') then
elseif not obj.level or (obj.action == 'move' and obj.level == 'autoconfirmed') then
-- Users need to be autoconfirmed to move pages anyway, so treat
-- Users need to be autoconfirmed to move pages anyway, so treat
-- semi-move-protected pages as unprotected.
-- semi-move-protected pages as unprotected.
self.level = '*'
obj.level = '*'
end
end


Zeile 119: Zeile 120:
if args.expiry then
if args.expiry then
if cfg.indefStrings[args.expiry] then
if cfg.indefStrings[args.expiry] then
self.expiry = 'indef'
obj.expiry = 'indef'
elseif type(args.expiry) == 'number' then
elseif type(args.expiry) == 'number' then
self.expiry = args.expiry
obj.expiry = args.expiry
else
else
self.expiry = validateDate(args.expiry, 'expiry date')
obj.expiry = validateDate(args.expiry, 'expiry date')
end
end
end
end
Zeile 129: Zeile 130:
-- Set reason
-- Set reason
if args[1] then
if args[1] then
self.reason = mw.ustring.lower(args[1])
obj.reason = mw.ustring.lower(args[1])
if self.reason:find('|') then
if obj.reason:find('|') then
error('reasons cannot contain the pipe character ("|")', 0)
error('reasons cannot contain the pipe character ("|")', 0)
end
end
Zeile 137: Zeile 138:
-- Set protection date
-- Set protection date
if args.date then
if args.date then
self.protectionDate = validateDate(args.date, 'protection date')
obj.protectionDate = validateDate(args.date, 'protection date')
end
end
-- Set banner config
-- Set banner config
do
do
self.bannerConfig = {}
obj.bannerConfig = {}
local configTables = {}
local configTables = {}
if cfg.banners[self.action] then
if cfg.banners[obj.action] then
configTables[#configTables + 1] = cfg.banners[self.action][self.reason]
configTables[#configTables + 1] = cfg.banners[obj.action][obj.reason]
end
end
if cfg.defaultBanners[self.action] then
if cfg.defaultBanners[obj.action] then
configTables[#configTables + 1] = cfg.defaultBanners[self.action][self.level]
configTables[#configTables + 1] = cfg.defaultBanners[obj.action][obj.level]
configTables[#configTables + 1] = cfg.defaultBanners[self.action].default
configTables[#configTables + 1] = cfg.defaultBanners[obj.action].default
end
end
configTables[#configTables + 1] = cfg.masterBanner
configTables[#configTables + 1] = cfg.masterBanner
for i, field in ipairs(self.bannerConfigFields) do
for i, field in ipairs(obj.bannerConfigFields) do
for j, t in ipairs(configTables) do
for j, t in ipairs(configTables) do
if t[field] then
if t[field] then
self.bannerConfig[field] = t[field]
obj.bannerConfig[field] = t[field]
break
break
end
end
Zeile 161: Zeile 162:
end
end
end
end
return setmetatable(obj, Protection)
end
end


Zeile 362: Zeile 364:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local Blurb = class('Blurb')
local Blurb = {}
Blurb.__index = Blurb


Blurb.bannerTextFields = {
Blurb.bannerTextFields = {
Zeile 372: Zeile 375:
}
}


function Blurb:initialize(protectionObj, args, cfg)
function Blurb.new(protectionObj, args, cfg)
self._cfg = cfg
return setmetatable({
self._protectionObj = protectionObj
_cfg = cfg,
self._args = args
_protectionObj = protectionObj,
_args = args
}, Blurb)
end
end


Zeile 679: Zeile 684:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local BannerTemplate = class('BannerTemplate')
local BannerTemplate = {}
BannerTemplate.__index = BannerTemplate


function BannerTemplate:initialize(protectionObj, cfg)
function BannerTemplate.new(protectionObj, cfg)
self._cfg = cfg
local obj = {}
obj._cfg = cfg


-- Set the image filename.
-- Set the image filename.
local imageFilename = protectionObj.bannerConfig.image
local imageFilename = protectionObj.bannerConfig.image
if imageFilename then
if imageFilename then
self._imageFilename = imageFilename
obj._imageFilename = imageFilename
else
else
-- If an image filename isn't specified explicitly in the banner config,
-- If an image filename isn't specified explicitly in the banner config,
Zeile 703: Zeile 710:
-- Fully protected modules and templates get the special red "indef"
-- Fully protected modules and templates get the special red "indef"
-- padlock.
-- padlock.
self._imageFilename = self._cfg.msg['image-filename-indef']
obj._imageFilename = obj._cfg.msg['image-filename-indef']
else
else
-- Deal with regular protection types.
-- Deal with regular protection types.
local images = self._cfg.images
local images = obj._cfg.images
if images[action] then
if images[action] then
if images[action][level] then
if images[action][level] then
self._imageFilename = images[action][level]
obj._imageFilename = images[action][level]
elseif images[action].default then
elseif images[action].default then
self._imageFilename = images[action].default
obj._imageFilename = images[action].default
end
end
end
end
end
end
end
end
return setmetatable(obj, BannerTemplate)
end
end


Zeile 742: Zeile 750:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local Banner = BannerTemplate:subclass('Banner')
local Banner = setmetatable({}, BannerTemplate)
Banner.__index = Banner


function Banner:initialize(protectionObj, blurbObj, cfg)
function Banner.new(protectionObj, blurbObj, cfg)
BannerTemplate.initialize(self, protectionObj, cfg) -- This doesn't need the blurb.
local obj = Banner.new(protectionObj, cfg) -- This doesn't need the blurb.
self:setImageWidth(40)
obj:setImageWidth(40)
self:setImageTooltip(blurbObj:makeBannerText('alt')) -- Large banners use the alt text for the tooltip.
obj:setImageTooltip(blurbObj:makeBannerText('alt')) -- Large banners use the alt text for the tooltip.
self._reasonText = blurbObj:makeBannerText('text')
obj._reasonText = blurbObj:makeBannerText('text')
self._explanationText = blurbObj:makeBannerText('explanation')
obj._explanationText = blurbObj:makeBannerText('explanation')
self._page = protectionObj.title.prefixedText -- Only makes a difference in testing.
obj._page = protectionObj.title.prefixedText -- Only makes a difference in testing.
return setmetatable(obj, Banner)
end
end


Zeile 775: Zeile 785:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local Padlock = BannerTemplate:subclass('Padlock')
local Padlock = setmetatable({}, BannerTemplate)
Padlock.__index = Padlock


function Padlock:initialize(protectionObj, blurbObj, cfg)
function Padlock.new(protectionObj, blurbObj, cfg)
BannerTemplate.initialize(self, protectionObj, cfg) -- This doesn't need the blurb.
local obj = BannerTemplate.new(protectionObj, cfg) -- This doesn't need the blurb.
self:setImageWidth(20)
obj:setImageWidth(20)
self:setImageTooltip(blurbObj:makeBannerText('tooltip'))
obj:setImageTooltip(blurbObj:makeBannerText('tooltip'))
self._imageAlt = blurbObj:makeBannerText('alt')
obj._imageAlt = blurbObj:makeBannerText('alt')
self._imageLink = blurbObj:makeBannerText('link')
obj._imageLink = blurbObj:makeBannerText('link')
self._right = cfg.padlockPositions[protectionObj.action]
obj._right = cfg.padlockPositions[protectionObj.action]
or cfg.padlockPositions.default
or cfg.padlockPositions.default
or '55px'
or '55px'
return setmetatable(obj, Padlock)
end
end


Zeile 821: Zeile 833:
-- Initialise the protection object and check for errors
-- Initialise the protection object and check for errors
local protectionObjCreated, protectionObj = pcall(
local protectionObjCreated, protectionObj = pcall(
Protection.new, Protection, -- equivalent to Protection:new()
Protection.new,
args,
args,
cfg,
cfg,
Zeile 842: Zeile 854:
-- Initialise the blurb object
-- Initialise the blurb object
local blurbObj = Blurb:new(protectionObj, args, cfg)
local blurbObj = Blurb.new(protectionObj, args, cfg)


local ret = {}
local ret = {}
Zeile 850: Zeile 862:
ret[#ret + 1] = tostring(
ret[#ret + 1] = tostring(
(yesno(args.small) and Padlock or Banner)
(yesno(args.small) and Padlock or Banner)
:new(protectionObj, blurbObj, cfg)
.new(protectionObj, blurbObj, cfg)
)
)
end
end
Anonymer Benutzer