Open main menu

Changes

Module:Protection banner

1,769 bytes added, 05:17, 16 June 2014
move the parameter functions to the top level of the blurb class and add a new one
self._bannerConfig = configObj:getBannerConfig(protectionStatusObj)
self._titleObj = titleObj
end
 
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj:getConfigTable('pagetypeNamespaces')
local namespace = self._titleObj:getNamespace()
return pagetypes[namespace] or pagetypes.default or 'page'
end
parameterFuncs[1] = function ()
-- Intro blurb local key local action = self._protectionStatusObj:getAction() local level = self._protectionStatusObj:getLevel() if action == 'edit' and level == 'autoconfirmed' then key = 'reason-text-semi' elseif action == 'move' then key = 'reason-text-move' elseif action == 'create' then key = 'reason-text-create' else key = 'reason-text-default' end local msg = self._configObj:getMessage(key) return self:_substituteParameters_makeIntroParameter(msg)
end
parameterFuncs[2] = function ()
-- "until" or "or until" depending on the expiry local expiry = return self._protectionStatusObj:getExpiry_makeUntilParameter() if expiry then return 'or until' else return 'until' end
end
parameterFuncs[3] = function ()
-- "disputes", with or without a section linkreturn self:_makeDisputesParameter() end parameterFuncs[4] = function () local section return self:_makePagetypeParameter() end parameterFuncs[5] = function () return self._protectionStatusObj:getSection_makeProtectionDateParameter() end  parameterFuncs[6] = function () local disputes return self:_makeVandalTemplateParameter() end  parameterFuncs[7] = function () return self.configObj:getMessage_makeProtectionLevelParameter('dispute) end  parameterFuncs[8] = function () return self:_makeExpiryParameter() end  parameterFuncs[9] = function () return self:_makeDisputeLinkParameter() -section-A link-display'to the page history or the move log end  parameterFuncs[10] = function () if section thenreturn self:_makeProtectionLogParameter() end  parameterFuncs[11] = function () return string.formatself:_makeTalkLinkParameter() end  ' parameterFuncs[[%s12] = function () return self:%s#%s|%s]]',_makeEditRequestParameter() end  mw.site.namespaces parameterFuncs[self._titleObj.namespace13].talk.name,= function () return self._titleObj.text,:_makeRequestUnprotectionParameter() section, end disputes parameterFuncs[14] = function () elsereturn self:_makeSubjectPageLinksParameter() -- Adds links to edit requests and the talk page if we are on a subject page return disputes end  parameterFuncs[15] = function () endreturn self:_makeDeletionDiscussionParameter()
end
parameterFuncs[16] = function ()
return self:_makeDeletionLogParameter()
end
self._params = params
end
return mw.message.newRawMessage(msg):params(self._params):plain()
end
 
function Blurb:_makeIntroParameter()
-- parameter $1
local key
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
if action == 'edit' and level == 'autoconfirmed' then
key = 'reason-text-semi'
elseif action == 'move' then
key = 'reason-text-move'
elseif action == 'create' then
key = 'reason-text-create'
else
key = 'reason-text-default'
end
local msg = self._configObj:getMessage(key)
return self:_substituteParameters(msg)
end
 
function Blurb:_makeUntilParameter()
-- 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
-- "disputes", with or without a section link
local section = self._protectionStatusObj:getSection()
local disputes = self.configObj:getMessage('dispute-section-link-display')
if section then
return string.format(
'[[%s:%s#%s|%s]]',
mw.site.namespaces[self._titleObj.namespace].talk.name,
self._titleObj.text,
section,
disputes
)
else
return disputes
end
end
 
function Blurb:_makePagetypeParameter()
-- parameter $4
local pagetypes = self._configObj:getConfigTable('pagetypeNamespaces')
local namespace = self._titleObj:getNamespace()
return pagetypes[namespace] or pagetypes.default or 'page'
end
 
function Blurb:_makeProtectionDateParameter()
-- parameter $5
if self._protectionDate then
local lang = mw.language.getContentLanguage()
local success, date = pcall(
lang.formatDate,
lang,
'j F Y',
self._protectionDate
)
if success and date then
return date
end
end
end
Anonymous user