Zum Inhalt springen

Modul:Protection banner: Unterschied zwischen den Versionen

use actual Lua errors, and a small fix to parameter handling
(only show banners for actions other than edit if they're more restricted than edit)
(use actual Lua errors, and a small fix to parameter handling)
Zeile 52: Zeile 52:
dateType,
dateType,
tostring(dateString)
tostring(dateString)
), 0)
), 4)
end
end


Zeile 122: Zeile 122:
'invalid action ("%s")',
'invalid action ("%s")',
tostring(args.action)
tostring(args.action)
), 0)
), 3)
end
end


Zeile 152: Zeile 152:
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 ("|")', 0)
error('reasons cannot contain the pipe character ("|")', 3)
end
end
end
end
Zeile 543: Zeile 543:
level,
level,
talkKey
talkKey
))
), 8)
end
end
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
Zeile 583: Zeile 583:
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', 8)
end
end


Zeile 598: Zeile 598:
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', 8)
end
end
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
Zeile 624: Zeile 624:
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', 8)
end
end
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
Zeile 703: Zeile 703:
tostring(key),
tostring(key),
type(msg)
type(msg)
))
), 4)
end
end
return self:_substituteParameters(msg)
return self:_substituteParameters(msg)
Zeile 800: Zeile 800:
-- 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', 2)
local explanationText = self._explanationText
local explanationText = self._explanationText
local mbargs = {
local mbargs = {
Zeile 865: Zeile 865:
cfg = cfg or require(CONFIG_MODULE)
cfg = cfg or require(CONFIG_MODULE)


-- Initialise the protection object and check for errors
local protectionObj = Protection.new(args, cfg, title)
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 = {}
Zeile 917: Zeile 897:
-- 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$', '')] or {}
local defaultArgs = parent and cfg.wrappers[parent:getTitle():gsub('/sandbox$', '')]


-- 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
Zeile 929: Zeile 909:
-- 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) do
for k, v in pairs(defaultArgs or {}) do
args[k] = v
args[k] = v
end
end
Anonymer Benutzer