Anonymous user
Module:Protection banner: Difference between revisions
get rid of the config class while still allowing replacing it for testing
Enwikipedia>Jackmcbarn (don't keep the whole export table around when we only need one thing from it) |
Enwikipedia>Jackmcbarn (get rid of the config class while still allowing replacing it for testing) |
||
Line 10:
-- Lazily initialise modules and objects we don't always need.
local mArguments, mMessageBox, lang, config
--------------------------------------------------------------------------------
Line 137 ⟶ 68:
-- Set expiry
if args.expiry then
local indefStrings = configObj
if indefStrings[args.expiry] then
self._expiry = 'indef'
Line 157 ⟶ 88:
-- Set protection date
self._protectionDate = validateDate(args.date, 'protection date')
-- Set banner config
do
self.bannerConfig = {}
local cfg = configObj.cfg
local fields = {
'text',
'explanation',
'tooltip',
'alt',
'link',
'image'
}
local configTables = {}
if cfg.banners[self._action] then
configTables[#configTables + 1] = cfg.banners[self._action][self._reason]
end
if cfg.defaultBanners[self._action] then
configTables[#configTables + 1] = cfg.defaultBanners[self._action][self._level]
configTables[#configTables + 1] = cfg.defaultBanners[self._action].default
end
configTables[#configTables + 1] = cfg.masterBanner
for i, field in ipairs(fields) do
for j, t in ipairs(configTables) do
if t[field] then
self.bannerConfig[field] = t[field]
break
end
end
end
end
end
Line 192 ⟶ 154:
self._configObj = configObj
self._protectionObj = protectionObj
self._bannerConfig =
self._titleObj = titleObj
end
Line 221 ⟶ 183:
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj
return self:_substituteParameters(msg)
end
Line 396 ⟶ 358:
function Blurb:_makeImageLinkParameter()
local imageLinks = self._configObj
local action = self._protectionObj:getAction()
local level = self._protectionObj:getLevel()
Line 429 ⟶ 391:
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj
local namespace = self._titleObj.namespace
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined')
Line 435 ⟶ 397:
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj
local action = self._protectionObj:getAction()
local level = self._protectionObj:getLevel()
Line 461 ⟶ 423:
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj
local action = self._protectionObj:getAction()
local level = self._protectionObj:getLevel()
Line 604 ⟶ 566:
-- Fully protected modules and templates get the special red "indef"
-- padlock.
self._imageFilename = self._configObj
return nil
end
-- Deal with regular protection types.
local images = self._configObj
if images[action] then
if images[action][level] then
Line 633 ⟶ 595:
function BannerTemplate:renderImage()
local filename = self._imageFilename
or self._configObj
or 'Transparent.gif'
return newFileLink(filename)
Line 778 ⟶ 740:
do
local namespace = titleObj.namespace
local categoryNamespaces = configObj
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
Line 813 ⟶ 775:
local configOrder = {}
do
local reasonsWithNamespacePriority = configObj
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
Line 882 ⟶ 844:
-- pos field in the property table.
--]]
local cats = configObj
local cat
for i = 1, 2^noActive do
Line 922 ⟶ 884:
local protectionObj = self._protectionObj
local reasonsWithoutExpiryCheck = configObj
local expiryCheckActions = configObj
local expiry = protectionObj:getExpiry()
local action = protectionObj:getAction()
Line 933 ⟶ 895:
and not reasonsWithoutExpiryCheck[reason]
then
self:setName(configObj
end
return Category.render(self)
Line 955 ⟶ 917:
or type(expiry) == 'number' and expiry < os.time()
then
self:setName(configObj
end
return Category.render(self)
Line 986 ⟶ 948:
)
then
self:setName(configObj
end
return Category.render(self)
Line 1,007 ⟶ 969:
-- Get data objects
if not config then
config = mw.loadData('Module:Protection banner/config')
end
local configObj = config
local protectionObj = Protection:new(args, configObj, titleObj)
Line 1,030 ⟶ 995:
-- Set the image fields
local bannerConfig =
bannerObj:setImageFilename(bannerConfig.image, protectionObj, titleObj)
if isPadlock then
Line 1,070 ⟶ 1,035:
return {
Protection = Protection,
Blurb = Blurb,
BannerTemplate = BannerTemplate,
|