Modul:Protection banner: Unterschied zwischen den Versionen
produce wikitext errors rather than script errors for errors caused by invalid user input
(use mw.ustring.lower to convert the reason to lower case, for the benefit of other-language wikis) |
(produce wikitext errors rather than script errors for errors caused by invalid user input) |
||
Zeile 15: | Zeile 15: | ||
-- Helper functions | -- Helper functions | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function makeWikitextError(msg) | |||
-- @TODO: localise this. | |||
local boilerplate = 'Error: $1 ([[Module:Protection banner#Errors|help]])' | |||
local errorText = mw.message.newRawMessage(boilerplate):params(msg):plain() | |||
return string.format( | |||
'<strong class="error">%s</strong>', | |||
errorText | |||
) | |||
end | |||
local function makeCategoryLink(cat) | local function makeCategoryLink(cat) | ||
Zeile 42: | Zeile 52: | ||
dateType, | dateType, | ||
tostring(dateString) | tostring(dateString) | ||
)) | ), 0) | ||
end | end | ||
Zeile 84: | Zeile 94: | ||
self.action = args.action | self.action = args.action | ||
else | else | ||
error(' | error(string.format( | ||
'invalid action ("%s")', | |||
tostring(args.action) | |||
), 0) | |||
end | end | ||
Zeile 800: | Zeile 813: | ||
end | end | ||
-- Initialise protection and | -- Initialise the protection object and check for errors | ||
local protectionObj = Protection:new(args, cfg, title) | local protectionObjCreated, protectionObj = pcall( | ||
Protection.new, Protection, -- equivalent to Protection:new() | |||
args, | |||
cfg, | |||
title | |||
) | |||
if not protectionObjCreated then | |||
-- protectionObj is the error message. | |||
return makeWikitextError(protectionObj) | |||
end | |||
-- Initialise the blurb object | |||
local blurbObj = Blurb:new(protectionObj, args, cfg) | local blurbObj = Blurb:new(protectionObj, args, cfg) | ||