Module:Protection banner: Difference between revisions
start converting the blurb class to the new parameter system
m (check the right action variable) |
(start converting the blurb class to the new parameter system) |
||
Line 39: | Line 39: | ||
'tooltip', | 'tooltip', | ||
'alt', | 'alt', | ||
'image | 'image' | ||
} | } | ||
local configTables = {} | local configTables = {} | ||
Line 51: | Line 49: | ||
configTables[#configTables + 1] = cfg.defaultBanners[action].default | configTables[#configTables + 1] = cfg.defaultBanners[action].default | ||
end | end | ||
configTables[#configTables + 1] = cfg.masterBanner | |||
for i, field in ipairs(fields) do | for i, field in ipairs(fields) do | ||
for j, t in ipairs(configTables) do | for j, t in ipairs(configTables) do | ||
Line 67: | Line 66: | ||
local blacklist = { | local blacklist = { | ||
banners = true, | banners = true, | ||
defaultBanners = true | defaultBanners = true, | ||
masterBanner = true | |||
} | } | ||
if not blacklist[key] then | if not blacklist[key] then | ||
Line 190: | Line 190: | ||
self._titleObj = titleObj | self._titleObj = titleObj | ||
end | end | ||
-- Static methods -- | |||
function Blurb.makeFullUrl(page, query, display) | function Blurb.makeFullUrl(page, query, display) | ||
Line 198: | Line 200: | ||
function Blurb.formatDate(num) | function Blurb.formatDate(num) | ||
-- Formats a Unix timestamp into dd | -- Formats a Unix timestamp into dd Month, YYYY format. | ||
lang = lang or mw.language.getContentLanguage() | lang = lang or mw.language.getContentLanguage() | ||
local success, date = pcall( | local success, date = pcall( | ||
Line 211: | Line 213: | ||
end | end | ||
-- Private methods -- | |||
function Blurb:_substituteParameters(msg) | function Blurb:_substituteParameters(msg) | ||
Line 237: | Line 229: | ||
end | end | ||
}) | }) | ||
parameterFuncs | parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter | ||
parameterFuncs | parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter | ||
parameterFuncs | parameterFuncs.DISPUTESECTION = self._makeDisputesParameter | ||
parameterFuncs | parameterFuncs.EDITREQUEST = self._makeEditRequestParameter | ||
parameterFuncs | parameterFuncs.EXPIRY = self._makeExpiryParameter | ||
parameterFuncs | parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter | ||
parameterFuncs | parameterFuncs.INTROBLURB = self._makeIntroBlurbParameter | ||
parameterFuncs | parameterFuncs.PAGETYPE = self._makePagetypeParameter | ||
parameterFuncs | parameterFuncs.PROTECTIONDATE = self._makeProtectionDateParameter | ||
parameterFuncs.PROTECTIONLEVEL = self._makeProtectionLevelParameter | |||
parameterFuncs | parameterFuncs.PROTECTIONLOG = self._makeProtectionLogParameter | ||
parameterFuncs.TALKPAGE = self._makeTalkPageParameter | |||
parameterFuncs | parameterFuncs.VANDAL = self._makeVandalTemplateParameter | ||
parameterFuncs | |||
parameterFuncs | |||
self._params = params | self._params = params | ||
end | end | ||
msg = msg:gsub('${(%u+)}', self._params) | |||
msg = msg:gsub('$( | |||
return msg | return msg | ||
end | end | ||
function Blurb: | function Blurb:_makeIntroBlurbParameter() | ||
-- parameter $1 | -- parameter $1 | ||
local key | local key | ||
Line 287: | Line 269: | ||
end | end | ||
function Blurb: | function Blurb:_makeDisputeSectionParameter() | ||
-- parameter $3 | -- parameter $3 | ||
-- "disputes", with or without a section link | -- "disputes", with or without a section link | ||
Line 379: | Line 350: | ||
end | end | ||
function Blurb: | function Blurb:_makeCurrentVersionParameter() | ||
-- parameter $9 | -- parameter $9 | ||
-- A link to the page history or the move log, depending on the kind of | -- A link to the page history or the move log, depending on the kind of | ||
Line 423: | Line 394: | ||
end | end | ||
function Blurb: | function Blurb:_makeTalkPageParameter() | ||
-- parameter $11 | -- parameter $11 | ||
local section = self._section | local section = self._section | ||
Line 513: | Line 484: | ||
end | end | ||
function Blurb: | function Blurb:_makeExplanationBlurbParameter() | ||
-- parameter $18 | -- parameter $18 | ||
local action = self._protectionStatusObj:getAction() | local action = self._protectionStatusObj:getAction() | ||
Line 529: | Line 500: | ||
local msg = self._configObj:getMessage(key) | local msg = self._configObj:getMessage(key) | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
end | |||
-- Public methods -- | |||
function Blurb:setDeletionDiscussionPage(page) | |||
self._deletionDiscussionPage = page | |||
end | |||
function Blurb:setUsername(username) | |||
self._username = username | |||
end | |||
function Blurb:setSection(section) | |||
self._section = section | |||
end | end | ||