Editing Module:Protection banner
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 46: | Line 46: | ||
dateType, | dateType, | ||
tostring(dateString) | tostring(dateString) | ||
), | ), 0) | ||
end | end | ||
Line 115: | Line 115: | ||
'invalid action: %s', | 'invalid action: %s', | ||
tostring(args.action) | tostring(args.action) | ||
), | ), 0) | ||
end | end | ||
Line 138: | Line 138: | ||
obj.reason = mw.ustring.lower(args[1]) | obj.reason = mw.ustring.lower(args[1]) | ||
if obj.reason:find('|') then | if obj.reason:find('|') then | ||
error('reasons cannot contain the pipe character ("|")', | error('reasons cannot contain the pipe character ("|")', 0) | ||
end | end | ||
end | end | ||
Line 520: | Line 520: | ||
level, | level, | ||
talkKey | talkKey | ||
) | )) | ||
end | end | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
Line 560: | Line 560: | ||
return pagetypes[self._protectionObj.title.namespace] | return pagetypes[self._protectionObj.title.namespace] | ||
or pagetypes.default | or pagetypes.default | ||
or error('no default pagetype defined' | or error('no default pagetype defined') | ||
end | end | ||
Line 575: | Line 575: | ||
msg = protectionBlurbs.edit.default | msg = protectionBlurbs.edit.default | ||
else | else | ||
error('no protection blurb defined for protectionBlurbs.edit.default' | error('no protection blurb defined for protectionBlurbs.edit.default') | ||
end | end | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
Line 601: | Line 601: | ||
msg = protectionLevels.edit.default | msg = protectionLevels.edit.default | ||
else | else | ||
error('no protection level defined for protectionLevels.edit.default' | error('no protection level defined for protectionLevels.edit.default') | ||
end | end | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
Line 681: | Line 681: | ||
tostring(key), | tostring(key), | ||
type(msg) | type(msg) | ||
) | )) | ||
end | end | ||
return self:_substituteParameters(msg) | return self:_substituteParameters(msg) | ||
Line 771: | Line 771: | ||
-- Renders the banner. | -- Renders the banner. | ||
makeMessageBox = makeMessageBox or require('Module:Message box').main | makeMessageBox = makeMessageBox or require('Module:Message box').main | ||
local reasonText = self._reasonText or error('no reason text set' | local reasonText = self._reasonText or error('no reason text set') | ||
local explanationText = self._explanationText | local explanationText = self._explanationText | ||
local mbargs = { | local mbargs = { | ||
Line 836: | Line 836: | ||
cfg = cfg or require(CONFIG_MODULE) | cfg = cfg or require(CONFIG_MODULE) | ||
local protectionObj = Protection.new( | -- Initialise the protection object and check for errors | ||
local protectionObjCreated, protectionObj = pcall( | |||
Protection.new, | |||
args, | |||
cfg, | |||
title | |||
) | |||
if not protectionObjCreated then | |||
local errorBlurb = cfg.msg['error-message-blurb'] or 'Error: $1.' | |||
local errorText = mw.message.newRawMessage(errorBlurb) | |||
:params(protectionObj) -- protectionObj is the error message | |||
:plain() | |||
return string.format( | |||
'<strong class="error">%s</strong>%s', | |||
errorText, | |||
makeCategoryLink( | |||
cfg.msg['tracking-category-incorrect'], | |||
title and title.text or mw.title.getCurrentTitle().text | |||
) | |||
) | |||
end | |||
local ret = {} | local ret = {} | ||
Line 875: | Line 895: | ||
-- Find default args, if any. | -- Find default args, if any. | ||
local parent = frame.getParent and frame:getParent() | local parent = frame.getParent and frame:getParent() | ||
local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')] | local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')] or {} | ||
-- Find user args, and use the parent frame if we are being called from a | -- Find user args, and use the parent frame if we are being called from a | ||
Line 887: | Line 907: | ||
-- Build the args table. User-specified args overwrite default args. | -- Build the args table. User-specified args overwrite default args. | ||
local args = {} | local args = {} | ||
for k, v in pairs(defaultArgs | for k, v in pairs(defaultArgs) do | ||
args[k] = v | args[k] = v | ||
end | end |