Zum Inhalt springen

Modul:Protection banner: Unterschied zwischen den Versionen

move the parameter functions to the top level of the blurb class and add a new one
(simplify the structure a bit and write some more parameter functions)
(move the parameter functions to the top level of the blurb class and add a new one)
Zeile 117: Zeile 117:
self._bannerConfig = configObj:getBannerConfig(protectionStatusObj)
self._bannerConfig = configObj:getBannerConfig(protectionStatusObj)
self._titleObj = titleObj
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
end


Zeile 141: Zeile 135:
parameterFuncs[1] = function ()
parameterFuncs[1] = function ()
-- Intro blurb
return self:_makeIntroParameter()
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
end
parameterFuncs[2] = function ()
parameterFuncs[2] = function ()
-- "until" or "or until" depending on the expiry
return self:_makeUntilParameter()
local expiry = self._protectionStatusObj:getExpiry()
if expiry then
return 'or until'
else
return 'until'
end
end
end
parameterFuncs[3] = function ()
parameterFuncs[3] = function ()
-- "disputes", with or without a section link
return self:_makeDisputesParameter()
local section = self._protectionStatusObj:getSection()
end
local disputes = self.configObj:getMessage('dispute-section-link-display')
if section then
parameterFuncs[4] = function ()
return string.format(
return self:_makePagetypeParameter()
'[[%s:%s#%s|%s]]',
end
mw.site.namespaces[self._titleObj.namespace].talk.name,
self._titleObj.text,
parameterFuncs[5] = function ()
section,
return self:_makeProtectionDateParameter()
disputes
end
)
 
else
parameterFuncs[6] = function ()
return disputes
return self:_makeVandalTemplateParameter()
end
end
 
parameterFuncs[7] = function ()
return self:_makeProtectionLevelParameter()
end
 
parameterFuncs[8] = function ()
return self:_makeExpiryParameter()
end
 
parameterFuncs[9] = function ()
return self:_makeDisputeLinkParameter() -- A link to the page history or the move log
end
 
parameterFuncs[10] = function ()
return self:_makeProtectionLogParameter()
end
 
parameterFuncs[11] = function ()
return self:_makeTalkLinkParameter()
end
 
parameterFuncs[12] = function ()
return self:_makeEditRequestParameter()
end
 
parameterFuncs[13] = function ()
return self:_makeRequestUnprotectionParameter()
end
 
parameterFuncs[14] = function ()
return self:_makeSubjectPageLinksParameter() -- Adds links to edit requests and the talk page if we are on a subject page
end
 
parameterFuncs[15] = function ()
return self:_makeDeletionDiscussionParameter()
end
end


parameterFuncs[16] = function ()
return self:_makeDeletionLogParameter()
end
self._params = params
self._params = params
end
end
return mw.message.newRawMessage(msg):params(self._params):plain()
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
end


Anonymer Benutzer