Module:Protection banner: Difference between revisions
Content deleted Content added
sort parameter methods into alphabetical order, and remove the ones that are no longer needed |
add missing parameter methods, add a Blurb:_getExpandedMessage method, and (hopefully) finish updating the various functions to work with the new config structure |
||
Line 214:
-- Private methods --
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj:getMessage(msg)
return self:_substituteParameters(msg)
end
function Blurb:_substituteParameters(msg)
Line 232 ⟶ 237:
parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter
parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter
parameterFuncs.DISPUTEBLURB = self._makeDisputeBlurbParameter
parameterFuncs.DISPUTESECTION = self._makeDisputeSectionParameter
parameterFuncs.EDITREQUEST = self._makeEditRequestParameter
Line 237 ⟶ 243:
parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter
parameterFuncs.INTROBLURB = self._makeIntroBlurbParameter
parameterFuncs.OFFICEBLURB = self._makeOfficeBlurbParameter
parameterFuncs.PAGETYPE = self._makePagetypeParameter
parameterFuncs.PROTECTIONBLURB = self._makeProtectionBlurbParameter
parameterFuncs.PROTECTIONDATE = self._makeProtectionDateParameter
parameterFuncs.PROTECTIONLEVEL = self._makeProtectionLevelParameter
parameterFuncs.PROTECTIONLOG = self._makeProtectionLogParameter
parameterFuncs.RESETBLURB = self._makeResetBlurbParameter
parameterFuncs.TALKPAGE = self._makeTalkPageParameter
parameterFuncs.TOOLTIPBLURB = self._makeTooltipBlurbParameter
parameterFuncs.VANDAL = self._makeVandalTemplateParameter
Line 261 ⟶ 271:
'Special:Log',
{type = 'move', page = pagename},
self
)
else
Line 268 ⟶ 278:
pagename,
{action = 'history'},
self
)
end
Line 276 ⟶ 286:
local deletionDiscussionPage = self._deletionDiscussionPage
if deletionDiscussionPage then
local display = self
return string.format('[[%s|%s]]', deletionDiscussionPage, display)
end
end
function Blurb:_makeDisputeBlurbParameter()
local expiry = self._protectionStatusObj:getExpiry()
if type(expiry) == 'number' then
return self:_getExpandedMessage('dispute-blurb-expiry')
else
return self:_getExpandedMessage('dispute-blurb-noexpiry')
end
end
Line 284 ⟶ 303:
-- "disputes", with or without a section link
local section = self._section
local disputes = self
if section then
return string.format(
Line 310 ⟶ 329:
key = 'edit-request-full-display'
end
local display = self
-- Get the edit request type.
Line 331 ⟶ 350:
return nil
elseif type(expiry) == 'number' then
elseif expiry then
-- Expiry is an error string.
Line 342 ⟶ 360:
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local namespace = self._titleObj.namespace
local isTalk = self._titleObj.isTalkPage
-- @TODO: add semi-protection and pending changes blurbs
local key
if
-- MediaWiki namespace
key = 'explanation-blurb-full-nounprotect'
elseif action == 'edit' and level == 'sysop' and not isTalk then
key = 'explanation-blurb-full-subject'
elseif action == 'move' then
if isTalk then
key = 'explanation-blurb-move-talk'
else
key = 'explanation-blurb-move-subject'
end
elseif action == 'create' then
local xfd = self._deletionDiscussion
if xfd then
key = 'explanation-blurb-create-xfd'
else
key = 'explanation-blurb-create-noxfd'
end
else
key = 'explanation-
end
end
function Blurb:_makeIntroBlurbParameter()
local expiry = self._protectionStatusObj:getExpiry()
if type(expiry) == 'number' then
return self:_getExpandedMessage('intro-blurb-expiry')
else
return self:_getExpandedMessage('intro-blurb-noexpiry')
end
end
function Blurb:_makeOfficeBlurbParameter()
local protectionDate = self._protectionStatusObj:getProtectionDate()
if protectionDate then
return self:_getExpandedMessage('office-blurb-protectiondate')
else
return self:_getExpandedMessage('office-blurb-noprotectiondate')
end
end
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj:getConfigTable('
local namespace = self._titleObj.namespace
return pagetypes[namespace] or pagetypes.default or error('
end
function Blurb:_makeProtectionBlurbParameter()
local protectionBlurbs = self._configObj:getConfigTable('protectionBlurbs')
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local msg
if protectionBlurbs[action][level] then
msg = protectionBlurbs[action][level]
elseif protectionBlurbs[action].default then
msg = protectionBlurbs[action].default
elseif protectionBlurbs.edit.default then
msg = protectionBlurbs.edit.default
else
error('no protection blurb defined for cfg.protectionBlurbs.edit.default')
end
return self:_substituteParameters(msg)
end
Line 389 ⟶ 440:
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj:getConfigTable('protectionLevels')
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local
if protectionLevels[action
msg = protectionLevels[action][level]
elseif protectionLevels[action].default then
msg = protectionLevels[action].default
elseif protectionLevels.edit.default then
msg = protectionLevels.edit.default
else
end
return self
end
Line 418 ⟶ 464:
'Special:Log',
{type = 'stable', page = pagename},
self
)
else
Line 425 ⟶ 471:
'Special:Log',
{type = 'protect', page = pagename},
self
)
end
end
function Blurb:_makeResetBlurbParameter()
local protectionDate = self._protectionStatusObj:getProtectionDate()
if protectionDate then
return self:_getExpandedMessage('reset-blurb-protectiondate')
else
return self:_getExpandedMessage('reset-blurb-noprotectiondate')
end
end
Line 432 ⟶ 487:
function Blurb:_makeTalkPageParameter()
local section = self._section
local display = self
'[[%s:%s#%s|%s]]',
mw.site.namespaces[self._titleObj.namespace].talk.name,
Line 440 ⟶ 495:
display
)
end
function Blurb:_makeTooltipBlurbParameter()
local expiry = self._protectionStatusObj:getExpiry()
if type(expiry) == 'number' then
return self:_getExpandedMessage('tooltip-blurb-expiry')
else
return self:_getExpandedMessage('tooltip-blurb-noexpiry')
end
end
Line 446 ⟶ 510:
local username = self._username
username = username or self._titleObj.baseText
return mVandalM.
end
Line 677 ⟶ 741:
local titleObj = self._titleObj
-- Get the
local expiry = protectionStatusObj:getExpiry()
if type(expiry) == 'number' then
expiry = 'temp'
elseif expiry ~= 'indef' then
expiry = nil
end
-- Get the namespace category key.
local nskey
do
local namespace = titleObj.namespace
local categoryNamespaces = configObj:getConfigTable('
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
Line 687 ⟶ 759:
end
end
-- Get the other inputs.
local reason = protectionStatusObj:getReason()
local action = protectionStatusObj:getAction()
local level = protectionStatusObj:getLevel()
--[[
Line 694 ⟶ 771:
--]]
local properties = {
expiry = {order = 1, val =
namespace = {order = 2, val = nskey},
reason = {order = 3, val =
level = {order = 4, val =
action = {order = 5, val =
}
Line 711 ⟶ 788:
local configOrder = {}
do
local
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
configOrder[t.order] = t
end
if
-- Swap namespace and reason around.
local namespaceTable = table.remove(configOrder, 2)
table.insert(configOrder, 3, namespaceTable)
end
end
Line 787 ⟶ 857:
-- pos field in the property table.
--]]
local cats = configObj:getConfigTable('
local cat
for i = 1, 2^noActive do
|