Module:Protection banner: Difference between revisions
Jump to navigation
Jump to search
allow individual banner config items to fall back to the same value in the defaults table, and add functions for making the blurb values
>Mr. Stradivarius (use gsub instead of the mw.message library for substituting parameters, as mw.message:params doesn't work with metatables; also, a few bug fixes) |
>Mr. Stradivarius (allow individual banner config items to fall back to the same value in the defaults table, and add functions for making the blurb values) |
||
Line 79: | Line 79: | ||
self._cfg = data.cfg | self._cfg = data.cfg | ||
self._msg = data.msg | self._msg = data.msg | ||
self._bannerConfigTables = {} | |||
end | end | ||
Line 85: | Line 86: | ||
local action = protectionStatusObj:getAction() | local action = protectionStatusObj:getAction() | ||
local reason = protectionStatusObj:getReason() | local reason = protectionStatusObj:getReason() | ||
if | |||
return | if self._bannerConfigTables[protectionStatusObj] then | ||
return self._bannerConfigTables[protectionStatusObj] | |||
else | else | ||
local ret = {} | |||
local fields = { | |||
'text', | |||
'explanation', | |||
'tooltip', | |||
'alt', | |||
'image', | |||
'categoryOrder', | |||
'categoryReason' | |||
} | |||
local configTables = {} | |||
configTables[#configTables + 1] = cfg.banners[action][reason] | |||
configTables[#configTables + 1] = cfg.defaultBanners[action] | |||
for i, field in ipairs(fields) do | |||
for j, t in ipairs(configTables) do | |||
if t[field] then | |||
ret[field] = t[field] | |||
break | |||
end | |||
end | |||
end | |||
self._bannerConfigTables[protectionStatusObj] = ret | |||
return ret | |||
end | end | ||
end | end | ||
Line 432: | Line 456: | ||
function Blurb:makeReasonText() | function Blurb:makeReasonText() | ||
local msg = self._bannerConfig.text | local msg = self._bannerConfig.text | ||
return self:_substituteParameters(msg) | |||
end | |||
function Blurb:makeExplanationText() | |||
local msg = self._bannerConfig.explanation | |||
return self:_substituteParameters(msg) | |||
end | |||
function Blurb:makeTooltipText() | |||
local msg = self._bannerConfig.tooltip | |||
return self:_substituteParameters(msg) | |||
end | |||
function Blurb:makeAltText() | |||
local msg = self._bannerConfig.alt | |||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
end | end |