Module:Protection banner: Difference between revisions

sort parameter methods into alphabetical order, and remove the ones that are no longer needed
(start converting the blurb class to the new parameter system)
(sort parameter methods into alphabetical order, and remove the ones that are no longer needed)
Line 230: Line 230:
})
})


parameterFuncs.CURRENTVERSION = self._makeCurrentVersionParameter
parameterFuncs.CURRENTVERSION     = self._makeCurrentVersionParameter
parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter
parameterFuncs.DELETIONDISCUSSION = self._makeDeletionDiscussionParameter
parameterFuncs.DISPUTESECTION = self._makeDisputesParameter
parameterFuncs.DISPUTESECTION     = self._makeDisputeSectionParameter
parameterFuncs.EDITREQUEST = self._makeEditRequestParameter
parameterFuncs.EDITREQUEST       = self._makeEditRequestParameter
parameterFuncs.EXPIRY = self._makeExpiryParameter
parameterFuncs.EXPIRY             = self._makeExpiryParameter
parameterFuncs.EXPLANATIONBLURB = self._makeExplanationBlurbParameter
parameterFuncs.EXPLANATIONBLURB   = self._makeExplanationBlurbParameter
parameterFuncs.INTROBLURB = self._makeIntroBlurbParameter
parameterFuncs.INTROBLURB         = self._makeIntroBlurbParameter
parameterFuncs.PAGETYPE = self._makePagetypeParameter
parameterFuncs.PAGETYPE           = self._makePagetypeParameter
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.TALKPAGE = self._makeTalkPageParameter
parameterFuncs.TALKPAGE           = self._makeTalkPageParameter
parameterFuncs.VANDAL = self._makeVandalTemplateParameter
parameterFuncs.VANDAL             = self._makeVandalTemplateParameter
self._params = params
self._params = params
Line 251: Line 251:
end
end


function Blurb:_makeIntroBlurbParameter()
function Blurb:_makeCurrentVersionParameter()
-- parameter $1
-- A link to the page history or the move log, depending on the kind of
local key
-- protection.
local action = self._protectionStatusObj:getAction()
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local pagename = self._titleObj.prefixedText
if action == 'edit' and level == 'autoconfirmed' then
if action == 'move' then
key = 'reason-text-semi'
-- We need the move log link.
elseif action == 'move' then
return self.makeFullUrl(
key = 'reason-text-move'
'Special:Log',
elseif action == 'create' then
{type = 'move', page = pagename},
key = 'reason-text-create'
self._configObj:getMessage('dispute-move-link-display')
)
else
else
key = 'reason-text-default'
-- We need the history link.
return self.makeFullUrl(
pagename,
{action = 'history'},
self._configObj:getMessage('dispute-edit-link-display')
)
end
end
 
function Blurb:_makeDeletionDiscussionLinkParameter()
local deletionDiscussionPage = self._deletionDiscussionPage
if deletionDiscussionPage then
local display = self._configObj:getMessage('deletion-discussion-link-display')
return string.format('[[%s|%s]]', deletionDiscussionPage, display)
end
end
local msg = self._configObj:getMessage(key)
return self:_substituteParameters(msg)
end
end


function Blurb:_makeDisputeSectionParameter()
function Blurb:_makeDisputeSectionParameter()
-- parameter $3
-- "disputes", with or without a section link
-- "disputes", with or without a section link
local section = self._section
local section = self._section
Line 285: Line 296:
return disputes
return disputes
end
end
end
function Blurb:_makeEditRequestParameter()
local mEditRequest = require('Module:Submit an edit request')
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
-- Get the display message key.
local key
if action == 'edit' and level == 'autoconfirmed' then
key = 'edit-request-semi-display'
else
key = 'edit-request-full-display'
end
local display = self._configObj:getMessage(key)
-- Get the edit request type.
local requestType
if action == 'edit' then
if level == 'autoconfirmed' then
requestType = 'semi'
elseif level == 'templateeditor' then
requestType = 'template'
end
end
requestType = requestType or 'full'
return mEditRequest.exportLinkToLua{type = requestType, display = display}
end
function Blurb:_makeExpiryParameter()
local expiry = self._protectionStatusObj:getExpiry()
if expiry == 'indef' then
return nil
elseif type(expiry) == 'number' then
local formatted = Blurb.formatDate(expiry)
return ' until ' .. formatted
elseif expiry then
-- Expiry is an error string.
return expiry
end
end
function Blurb:_makeExplanationBlurbParameter()
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local key
if action == 'edit' and level == 'autoconfirmed' then
key = 'explanation-text-semi'
elseif action == 'move' then
key = 'explanation-text-move'
elseif action == 'create' then
key = 'explanation-text-create'
else
key = 'explanation-text-default'
end
local msg = self._configObj:getMessage(key)
return self:_substituteParameters(msg)
end
function Blurb:_makeIntroBlurbParameter()
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


function Blurb:_makePagetypeParameter()
function Blurb:_makePagetypeParameter()
-- parameter $4
local pagetypes = self._configObj:getConfigTable('bannerPagetypes')
local pagetypes = self._configObj:getConfigTable('bannerPagetypes')
local namespace = self._titleObj.namespace
local namespace = self._titleObj.namespace
Line 295: Line 380:


function Blurb:_makeProtectionDateParameter()
function Blurb:_makeProtectionDateParameter()
-- parameter $5
local protectionDate = self._protectionStatusObj:getProtectionDate()
local protectionDate = self._protectionStatusObj:getProtectionDate()
if type(protectionDate) == 'number' then
if type(protectionDate) == 'number' then
Line 302: Line 386:
return protectionDate
return protectionDate
end
end
end
function Blurb:_makeVandalTemplateParameter()
-- parameter $6
local mVandalM = require('Module:Vandal-m')
local username = self._username
username = username or self._titleObj.baseText
return mVandalM.luaMain{username}
end
end


function Blurb:_makeProtectionLevelParameter()
function Blurb:_makeProtectionLevelParameter()
-- parameter $7
local action = self._protectionStatusObj:getAction()
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local level = self._protectionStatusObj:getLevel()
Line 333: Line 408:
end
end
return self._configObj:getMessage(key)
return self._configObj:getMessage(key)
end
function Blurb:_makeExpiryParameter()
-- parameter $8
-- @TODO: Check to see if the expiry is valid.
local expiry = self._protectionStatusObj:getExpiry()
if expiry == 'indef' then
return nil
elseif type(expiry) == 'number' then
local formatted = Blurb.formatDate(expiry)
return ' until ' .. formatted
elseif expiry then
-- Expiry is an error string.
return expiry
end
end
function Blurb:_makeCurrentVersionParameter()
-- parameter $9
-- A link to the page history or the move log, depending on the kind of
-- protection.
local action = self._protectionStatusObj:getAction()
local pagename = self._titleObj.prefixedText
if action == 'move' then
-- We need the move log link.
return self.makeFullUrl(
'Special:Log',
{type = 'move', page = pagename},
self._configObj:getMessage('dispute-move-link-display')
)
else
-- We need the history link.
return self.makeFullUrl(
pagename,
{action = 'history'},
self._configObj:getMessage('dispute-edit-link-display')
)
end
end
end


function Blurb:_makeProtectionLogParameter()
function Blurb:_makeProtectionLogParameter()
-- parameter $10
local action = self._protectionStatusObj:getAction()
local action = self._protectionStatusObj:getAction()
local pagename = self._titleObj.prefixedText
local pagename = self._titleObj.prefixedText
Line 395: Line 431:


function Blurb:_makeTalkPageParameter()
function Blurb:_makeTalkPageParameter()
-- parameter $11
local section = self._section
local section = self._section
local display = self._configObj:getMessage('talk-page-link-display')
local display = self._configObj:getMessage('talk-page-link-display')
Line 407: Line 442:
end
end


function Blurb:_makeEditRequestParameter()
function Blurb:_makeVandalTemplateParameter()
-- parameter $12
local mVandalM = require('Module:Vandal-m')
local mEditRequest = require('Module:Submit an edit request')
local username = self._username
local action = self._protectionStatusObj:getAction()
username = username or self._titleObj.baseText
local level = self._protectionStatusObj:getLevel()
return mVandalM.luaMain{username}
-- Get the display message key.
local key
if action == 'edit' and level == 'autoconfirmed' then
key = 'edit-request-semi-display'
else
key = 'edit-request-full-display'
end
local display = self._configObj:getMessage(key)
-- Get the edit request type.
local requestType
if action == 'edit' then
if level == 'autoconfirmed' then
requestType = 'semi'
elseif level == 'templateeditor' then
requestType = 'template'
end
end
requestType = requestType or 'full'
return mEditRequest.exportLinkToLua{type = requestType, display = display}
end
 
function Blurb:_makeRequestUnprotectionParameter()
-- parameter $13
if self._titleObj.namespace ~= 8 then
-- MediaWiki pages can't be unprotected.
return self._configObj:getMessage('request-unprotection-blurb')
end
end
 
function Blurb:_makeSubjectPageLinksParameter()
-- parameter $14
-- Don't display these links if we are on a talk page.
if not self._titleObj.isTalkPage then
local msg = self._configObj:getMessage('semi-subject-page-links')
return self:_substituteParameters(msg)
end
end
 
function Blurb:_makeDeletionBlurbParameter()
-- parameter $15
local deletionDiscussionPage = self._deletionDiscussionPage
local key
if deletionDiscussionPage then
key = 'deletion-discussion-blurb-xfd'
else
key = 'deletion-discussion-blurb-noxfd'
end
local msg = self._configObj:getMessage(msg)
return self._substituteParameters(msg)
end
 
function Blurb:_makeDeletionDiscussionLinkParameter()
-- parameter $16
local deletionDiscussionPage = self._deletionDiscussionPage
if deletionDiscussionPage then
local display = self._configObj:getMessage('deletion-discussion-link-display')
return string.format('[[%s|%s]]', deletionDiscussionPage, display)
end
end
 
function Blurb:_makeDeletionLogParameter()
-- parameter $17
return Blurb.makeFullUrl(
'Special:Log',
{type = 'delete', page = self._titleObj.prefixedText},
self._configObj:getMessage('deletion-log-link-display')
)
end
 
function Blurb:_makeExplanationBlurbParameter()
-- parameter $18
local action = self._protectionStatusObj:getAction()
local level = self._protectionStatusObj:getLevel()
local key
if action == 'edit' and level == 'autoconfirmed' then
key = 'explanation-text-semi'
elseif action == 'move' then
key = 'explanation-text-move'
elseif action == 'create' then
key = 'explanation-text-create'
else
key = 'explanation-text-default'
end
local msg = self._configObj:getMessage(key)
return self:_substituteParameters(msg)
end
end