Modul:Protection banner: Unterschied zwischen den Versionen
allow individual banner config items to fall back to the same value in the defaults table, and add functions for making the blurb values
(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) |
(allow individual banner config items to fall back to the same value in the defaults table, and add functions for making the blurb values) |
||
| Zeile 79: | Zeile 79: | ||
self._cfg = data.cfg | self._cfg = data.cfg | ||
self._msg = data.msg | self._msg = data.msg | ||
self._bannerConfigTables = {} | |||
end | end | ||
| Zeile 85: | Zeile 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 | ||
| Zeile 432: | Zeile 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 | ||