Zum Inhalt springen

Modul:Protection banner: Unterschied zwischen den Versionen

add missing parameter methods, add a Blurb:_getExpandedMessage method, and (hopefully) finish updating the various functions to work with the new config structure
(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)
Zeile 214: Zeile 214:


-- Private methods --
-- Private methods --
function Blurb:_getExpandedMessage(msg)
local msg = self._configObj:getMessage(msg)
return self:_substituteParameters(msg)
end


function Blurb:_substituteParameters(msg)
function Blurb:_substituteParameters(msg)
Zeile 232: Zeile 237:
parameterFuncs.CURRENTVERSION    = self._makeCurrentVersionParameter
parameterFuncs.CURRENTVERSION    = self._makeCurrentVersionParameter
parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter
parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter
parameterFuncs.DISPUTEBLURB      = self._makeDisputeBlurbParameter
parameterFuncs.DISPUTESECTION    = self._makeDisputeSectionParameter
parameterFuncs.DISPUTESECTION    = self._makeDisputeSectionParameter
parameterFuncs.EDITREQUEST        = self._makeEditRequestParameter
parameterFuncs.EDITREQUEST        = self._makeEditRequestParameter
Zeile 237: Zeile 243:
parameterFuncs.EXPLANATIONBLURB  = self._makeExplanationBlurbParameter
parameterFuncs.EXPLANATIONBLURB  = self._makeExplanationBlurbParameter
parameterFuncs.INTROBLURB        = self._makeIntroBlurbParameter
parameterFuncs.INTROBLURB        = self._makeIntroBlurbParameter
parameterFuncs.OFFICEBLURB        = self._makeOfficeBlurbParameter
parameterFuncs.PAGETYPE          = self._makePagetypeParameter
parameterFuncs.PAGETYPE          = self._makePagetypeParameter
parameterFuncs.PROTECTIONBLURB    = self._makeProtectionBlurbParameter
parameterFuncs.PROTECTIONDATE    = self._makeProtectionDateParameter
parameterFuncs.PROTECTIONDATE    = self._makeProtectionDateParameter
parameterFuncs.PROTECTIONLEVEL    = self._makeProtectionLevelParameter
parameterFuncs.PROTECTIONLEVEL    = self._makeProtectionLevelParameter
parameterFuncs.PROTECTIONLOG      = self._makeProtectionLogParameter
parameterFuncs.PROTECTIONLOG      = self._makeProtectionLogParameter
parameterFuncs.RESETBLURB        = self._makeResetBlurbParameter
parameterFuncs.TALKPAGE          = self._makeTalkPageParameter
parameterFuncs.TALKPAGE          = self._makeTalkPageParameter
parameterFuncs.TOOLTIPBLURB      = self._makeTooltipBlurbParameter
parameterFuncs.VANDAL            = self._makeVandalTemplateParameter
parameterFuncs.VANDAL            = self._makeVandalTemplateParameter
Zeile 261: Zeile 271:
'Special:Log',
'Special:Log',
{type = 'move', page = pagename},
{type = 'move', page = pagename},
self._configObj:getMessage('dispute-move-link-display')
self:_getExpandedMessage('current-version-move-display')
)
)
else
else
Zeile 268: Zeile 278:
pagename,
pagename,
{action = 'history'},
{action = 'history'},
self._configObj:getMessage('dispute-edit-link-display')
self:_getExpandedMessage('current-version-edit-display')
)
)
end
end
Zeile 276: Zeile 286:
local deletionDiscussionPage = self._deletionDiscussionPage
local deletionDiscussionPage = self._deletionDiscussionPage
if deletionDiscussionPage then
if deletionDiscussionPage then
local display = self._configObj:getMessage('deletion-discussion-link-display')
local display = self:_getExpandedMessage('deletion-discussion-link-display')
return string.format('[[%s|%s]]', deletionDiscussionPage, display)
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
end
end
Zeile 284: Zeile 303:
-- "disputes", with or without a section link
-- "disputes", with or without a section link
local section = self._section
local section = self._section
local disputes = self.configObj:getMessage('dispute-section-link-display')
local disputes = self:_getExpandedMessage('dispute-section-link-display')
if section then
if section then
return string.format(
return string.format(
Zeile 310: Zeile 329:
key = 'edit-request-full-display'
key = 'edit-request-full-display'
end
end
local display = self._configObj:getMessage(key)
local display = self:_getExpandedMessage(key)
-- Get the edit request type.
-- Get the edit request type.
Zeile 331: Zeile 350:
return nil
return nil
elseif type(expiry) == 'number' then
elseif type(expiry) == 'number' then
local formatted = Blurb.formatDate(expiry)
return Blurb.formatDate(expiry)
return ' until ' .. formatted
elseif expiry then
elseif expiry then
-- Expiry is an error string.
-- Expiry is an error string.
Zeile 342: Zeile 360:
local action = self._protectionStatusObj:getAction()
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
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
local key
if action == 'edit' and level == 'autoconfirmed' then
if namespace == 8 then
key = 'explanation-text-semi'
-- 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
elseif action == 'move' then
key = 'explanation-text-move'
if isTalk then
key = 'explanation-blurb-move-talk'
else
key = 'explanation-blurb-move-subject'
end
elseif action == 'create' then
elseif action == 'create' then
key = 'explanation-text-create'
local xfd = self._deletionDiscussion
if xfd then
key = 'explanation-blurb-create-xfd'
else
key = 'explanation-blurb-create-noxfd'
end
else
else
key = 'explanation-text-default'
key = 'explanation-blurb-default'
end
end
local msg = self._configObj:getMessage(key)
return self:_getExpandedMessage(key)
return self:_substituteParameters(msg)
end
end


function Blurb:_makeIntroBlurbParameter()
function Blurb:_makeIntroBlurbParameter()
local key
local expiry = self._protectionStatusObj:getExpiry()
local action = self._protectionStatusObj:getAction()
if type(expiry) == 'number' then
local level = self._protectionStatusObj:getLevel()
return self:_getExpandedMessage('intro-blurb-expiry')
if action == 'edit' and level == 'autoconfirmed' then
else
key = 'reason-text-semi'
return self:_getExpandedMessage('intro-blurb-noexpiry')
elseif action == 'move' then
end
key = 'reason-text-move'
end
elseif action == 'create' then
 
key = 'reason-text-create'
function Blurb:_makeOfficeBlurbParameter()
local protectionDate = self._protectionStatusObj:getProtectionDate()
if protectionDate then
return self:_getExpandedMessage('office-blurb-protectiondate')
else
else
key = 'reason-text-default'
return self:_getExpandedMessage('office-blurb-noprotectiondate')
end
end
local msg = self._configObj:getMessage(key)
return self:_substituteParameters(msg)
end
end


function Blurb:_makePagetypeParameter()
function Blurb:_makePagetypeParameter()
local pagetypes = self._configObj:getConfigTable('bannerPagetypes')
local pagetypes = self._configObj:getConfigTable('pagetypes')
local namespace = self._titleObj.namespace
local namespace = self._titleObj.namespace
return pagetypes[namespace] or pagetypes.default or 'page'
return pagetypes[namespace] or pagetypes.default or error('no default pagetype defined')
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
end


Zeile 389: Zeile 440:


function Blurb:_makeProtectionLevelParameter()
function Blurb:_makeProtectionLevelParameter()
local protectionLevels = self._configObj:getConfigTable('protectionLevels')
local action = self._protectionStatusObj:getAction()
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local level = self._protectionStatusObj:getLevel()
local key
local msg
if action == 'edit' then
if protectionLevels[action][level] then
if level == 'sysop' then
msg = protectionLevels[action][level]
key = 'protection-level-full'
elseif protectionLevels[action].default then
elseif level == 'templateeditor' then
msg = protectionLevels[action].default
key = 'protection-level-template'
elseif protectionLevels.edit.default then
elseif level == 'autoconfirmed' then
msg = protectionLevels.edit.default
key = 'protection-level-semi'
end
elseif action == 'move' then
key = 'protection-level-move'
elseif action == 'create' then
key = 'protection-level-create'
else
else
key = 'protection-level-default'
error('no protection level defined for cfg.protectionLevels.edit.default')
end
end
return self._configObj:getMessage(key)
return self:_substituteParameters(msg)
end
end


Zeile 418: Zeile 464:
'Special:Log',
'Special:Log',
{type = 'stable', page = pagename},
{type = 'stable', page = pagename},
self._configObj:getMessage('more-details-pc-log-display')
self:_getExpandedMessage('pc-log-display')
)
)
else
else
Zeile 425: Zeile 471:
'Special:Log',
'Special:Log',
{type = 'protect', page = pagename},
{type = 'protect', page = pagename},
self._configObj:getMessage('more-details-protection-log-display')
self:_getExpandedMessage('protection-log-display')
)
)
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
end
end
Zeile 432: Zeile 487:
function Blurb:_makeTalkPageParameter()
function Blurb:_makeTalkPageParameter()
local section = self._section
local section = self._section
local display = self._configObj:getMessage('talk-page-link-display')
local display = self:_getExpandedMessage('talk-page-link-display')
return string.format(
return string.format(
'[[%s:%s#%s|%s]]',
'[[%s:%s#%s|%s]]',
mw.site.namespaces[self._titleObj.namespace].talk.name,
mw.site.namespaces[self._titleObj.namespace].talk.name,
Zeile 440: Zeile 495:
display
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
end


Zeile 446: Zeile 510:
local username = self._username
local username = self._username
username = username or self._titleObj.baseText
username = username or self._titleObj.baseText
return mVandalM.luaMain{username}
return mVandalM._main{username}
end
end


Zeile 677: Zeile 741:
local titleObj = self._titleObj
local titleObj = self._titleObj
-- Get the namespace category key from the namespace number.
-- Get the expiry.
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
local nskey
do
do
local namespace = titleObj.namespace
local namespace = titleObj.namespace
local categoryNamespaces = configObj:getConfigTable('categoryNamespaces')
local categoryNamespaces = configObj:getConfigTable('categoryNamespaceKeys')
nskey = categoryNamespaces[namespace]
nskey = categoryNamespaces[namespace]
if not nskey and namespace % 2 == 1 then
if not nskey and namespace % 2 == 1 then
Zeile 687: Zeile 759:
end
end
end
end
-- Get the other inputs.
local reason = protectionStatusObj:getReason()
local action = protectionStatusObj:getAction()
local level = protectionStatusObj:getLevel()
   
   
--[[
--[[
Zeile 694: Zeile 771:
--]]
--]]
local properties = {
local properties = {
expiry    = {order = 1, val = protectionStatusObj:getExpiry()},
expiry    = {order = 1, val = expiry},
namespace = {order = 2, val = nskey},
namespace = {order = 2, val = nskey},
reason    = {order = 3, val = protectionStatusObj:getReason()},
reason    = {order = 3, val = reason},
level    = {order = 4, val = protectionStatusObj:getLevel()},
level    = {order = 4, val = level},
action    = {order = 5, val = protectionStatusObj:getAction()}
action    = {order = 5, val = action}
}
}
   
   
Zeile 711: Zeile 788:
local configOrder = {}
local configOrder = {}
do
do
local bannerConfig = configObj:getBannerConfig(protectionStatusObj)
local reasonsWithNamespacePriority = configObj:getConfigTable('reasonsWithNamespacePriority')
local categoryOrder = bannerConfig.categoryOrder
local namespaceFirst = reason and reasonsWithNamespacePriority[reason] or false
for propertiesKey, t in pairs(properties) do
for propertiesKey, t in pairs(properties) do
configOrder[t.order] = t
configOrder[t.order] = t
end
end
if categoryOrder then
if namespaceFirst then
local property = properties[categoryOrder]
-- Swap namespace and reason around.
if not property then
local namespaceTable = table.remove(configOrder, 2)
local msg = '"'
table.insert(configOrder, 3, namespaceTable)
.. categoryOrder
.. '" is not a valid value of cfg.reasons.'
.. reason
.. '.categoryOrder'
error(msg)
end
table.insert(configOrder, table.remove(configOrder, property.order))
end
end
end
end
Zeile 787: Zeile 857:
-- pos field in the property table.
-- pos field in the property table.
--]]
--]]
local cats = configObj:getConfigTable('categories')
local cats = configObj:getConfigTable('protectionCategories')
local cat
local cat
for i = 1, 2^noActive do
for i = 1, 2^noActive do
Anonymer Benutzer