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'
'categoryOrder',
'categoryReason'
}
}
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 M, YYYY format.
-- 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


function Blurb:setDeletionDiscussionPage(page)
-- Private methods --
self._deletionDiscussionPage = page
end
 
function Blurb:setUsername(username)
self._username = username
end
 
function Blurb:setSection(section)
self._section = section
end


function Blurb:_substituteParameters(msg)
function Blurb:_substituteParameters(msg)
Line 237: Line 229:
end
end
})
})
 
parameterFuncs[1] = self._makeIntroParameter
parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter
parameterFuncs[2] = self._makeUntilParameter
parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter
parameterFuncs[3] = self._makeDisputesParameter
parameterFuncs.DISPUTESECTION = self._makeDisputesParameter
parameterFuncs[4] = self._makePagetypeParameter
parameterFuncs.EDITREQUEST = self._makeEditRequestParameter
parameterFuncs[5] = self._makeProtectionDateParameter
parameterFuncs.EXPIRY = self._makeExpiryParameter
parameterFuncs[6] = self._makeVandalTemplateParameter
parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter
parameterFuncs[7] = self._makeProtectionLevelParameter
parameterFuncs.INTROBLURB = self._makeIntroBlurbParameter
parameterFuncs[8] = self._makeExpiryParameter
parameterFuncs.PAGETYPE = self._makePagetypeParameter
parameterFuncs[9] = self._makeDisputeLinkParameter -- A link to the page history or the move log
parameterFuncs.PROTECTIONDATE = self._makeProtectionDateParameter
parameterFuncs[10] = self._makeProtectionLogParameter
parameterFuncs.PROTECTIONLEVEL = self._makeProtectionLevelParameter
parameterFuncs[11] = self._makeTalkLinkParameter
parameterFuncs.PROTECTIONLOG = self._makeProtectionLogParameter
parameterFuncs[12] = self._makeEditRequestParameter
parameterFuncs.TALKPAGE = self._makeTalkPageParameter
parameterFuncs[13] = self._makeRequestUnprotectionParameter
parameterFuncs.VANDAL = self._makeVandalTemplateParameter
parameterFuncs[14] = self._makeSubjectPageLinksParameter -- Adds links to edit requests and the talk page if we are on a subject page
parameterFuncs[15] = self._makeDeletionBlurbParameter
parameterFuncs[16] = self._makeDeletionDiscussionLinkParameter
parameterFuncs[17] = self._makeDeletionLogParameter
parameterFuncs[18] = self._makeExplanationTextParameter
self._params = params
self._params = params
end
end
 
local function getParameter(match)
msg = msg:gsub('${(%u+)}', self._params)
match = tonumber(match)
return self._params[match]
end
 
msg = msg:gsub('$([1-9][0-9]*)', getParameter)
return msg
return msg
end
end


function Blurb:_makeIntroParameter()
function Blurb:_makeIntroBlurbParameter()
-- parameter $1
-- parameter $1
local key
local key
Line 287: Line 269:
end
end


function Blurb:_makeUntilParameter()
function Blurb:_makeDisputeSectionParameter()
-- parameter $2
-- "until" or "or until" depending on the expiry
local expiry = self._protectionStatusObj:getExpiry()
if expiry then
return 'or until'
else
return 'until'
end
end
 
function Blurb:_makeDisputesParameter()
-- 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:_makeDisputeLinkParameter()
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:_makeTalkLinkParameter()
function Blurb:_makeTalkPageParameter()
-- parameter $11
-- parameter $11
local section = self._section
local section = self._section
Line 513: Line 484:
end
end


function Blurb:_makeExplanationTextParameter()
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