Jump to content

Module:Protection banner and Module:Protection banner/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
use require('strict') instead of require('Module:No globals')
 
m Simplified code to increase readability
 
Line 13: Line 13:


-- Set constants.
-- Set constants.
local CONFIG_MODULE = 'Module:Protection banner/config'
local CONFIG_MODULE = 'Module:Protection banner/config/sandbox' -- SWITCH THIS BACK TO THE MAIN CONFIG PAGE BEFORE GOING LIVE!


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 32: Line 32:
-- Validation function for the expiry and the protection date
-- Validation function for the expiry and the protection date
local function validateDate(dateString, dateType)
local function validateDate(dateString, dateType)
lang = lang or mw.language.getContentLanguage()
if not lang then
lang = mw.language.getContentLanguage()
end
local success, result = pcall(lang.formatDate, lang, 'U', dateString)
local success, result = pcall(lang.formatDate, lang, 'U', dateString)
if success then
if success then
Line 127: Line 125:


-- Set expiry
-- Set expiry
local effectiveExpiry = effectiveProtectionExpiry(obj.action, obj.title)
local effectiveExpiry = args.demoexpiry or effectiveProtectionExpiry(obj.action, obj.title)
if effectiveExpiry == 'infinity' then
if effectiveExpiry == 'infinity' then
obj.expiry = 'indef'
obj.expiry = 'indef'
Line 414: Line 412:
parameterFuncs.PROTECTIONLEVEL = self._makeProtectionLevelParameter
parameterFuncs.PROTECTIONLEVEL = self._makeProtectionLevelParameter
parameterFuncs.PROTECTIONLOG = self._makeProtectionLogParameter
parameterFuncs.PROTECTIONLOG = self._makeProtectionLogParameter
parameterFuncs.PROTECTIONMESSAGE = self._makeProtectionMessageParameter
parameterFuncs.TALKPAGE = self._makeTalkPageParameter
parameterFuncs.TALKPAGE = self._makeTalkPageParameter
parameterFuncs.TOOLTIPBLURB = self._makeTooltipBlurbParameter
parameterFuncs.TOOLTIPBLURB = self._makeTooltipBlurbParameter
Line 623: Line 622:
)
)
end
end
end

function Blurb:_makeProtectionMessageParameter()
local protectionMessages = self._cfg.protectionMessages
local action = self._protectionObj.action
local level = self._protectionObj.level
local msg
if protectionMessages[action][level] then
msg = protectionMessages[action][level]
elseif protectionMessages[action].default then
msg = protectionMessages[action].default
elseif protectionMessages.edit.default then
msg = protectionMessages.edit.default
else
error('no protection level defined for protectionMessages.edit.default', 8)
end
return self:_substituteParameters(msg)
end
end