Module:Protection banner: Difference between revisions
Content added Content deleted
Enwikipedia>Mr. Stradivarius (simplify the structure a bit and write some more parameter functions) |
Enwikipedia>Mr. Stradivarius (move the parameter functions to the top level of the blurb class and add a new one) |
||
Line 117: | Line 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 |
||
Line 141: | Line 135: | ||
parameterFuncs[1] = function () |
parameterFuncs[1] = function () |
||
return self:_makeIntroParameter() |
|||
-- 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(msg) |
|||
end |
end |
||
parameterFuncs[2] = function () |
parameterFuncs[2] = function () |
||
return self:_makeUntilParameter() |
|||
-- "until" or "or until" depending on the expiry |
|||
local expiry = self._protectionStatusObj:getExpiry() |
|||
if expiry then |
|||
return 'or until' |
|||
else |
|||
return 'until' |
|||
end |
|||
end |
end |
||
parameterFuncs[3] = function () |
parameterFuncs[3] = function () |
||
return self:_makeDisputesParameter() |
|||
-- "disputes", with or without a section link |
|||
end |
|||
local section = self._protectionStatusObj:getSection() |
|||
local disputes = self.configObj:getMessage('dispute-section-link-display') |
|||
parameterFuncs[4] = function () |
|||
if section then |
|||
return self:_makePagetypeParameter() |
|||
end |
|||
'[[%s:%s#%s|%s]]', |
|||
mw.site.namespaces[self._titleObj.namespace].talk.name, |
|||
parameterFuncs[5] = function () |
|||
self._titleObj.text, |
|||
return self:_makeProtectionDateParameter() |
|||
section, |
|||
disputes |
|||
) |
|||
else |
|||
return disputes |
|||
end |
|||
end |
end |
||
parameterFuncs[6] = function () |
|||
return self:_makeVandalTemplateParameter() |
|||
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 |
|||
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 |
||