Module:Error: Difference between revisions
Jump to navigation
Jump to search
PhantomCaleb (talk | contribs) (Created page with "local p = {} p.Templates = { Error = { purpose = "This template indicates that another template is being used incorrectly." } } return p") |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local utilsError = require("Module:UtilsError") | |||
local p = {} | local p = {} | ||
local DEFAULT_ERROR_MESSAGE = "Error" | |||
local CATEGORY_ERRORS = "Category:Pages with template errors" | |||
function p.Error(frame) | |||
local args = frame:getParent().args | |||
return p.printError(args[1], args[2]) | |||
end | |||
function p.printError(message, category) | |||
local errorMessage = message or DEFAULT_ERROR_MESSAGE | |||
local errorCategory = category or CATEGORY_ERRORS | |||
utilsError.warn(errorMessage) | |||
local err = mw.html.create("strong") | |||
:addClass("error") | |||
:wikitext(errorMessage) | |||
return string.format("[[:%s|%s]][[%s]]", errorMessage, tostring(err), errorCategory) | |||
end | |||
p.Templates = { | p.Templates = { | ||
Error = { | Error = { | ||
purpose = "This template indicates that | purpose = "This template indicates that a template is being used incorrectly. See also [[Template:Warn]].", | ||
} | params = { | ||
[1] = { | |||
name = "message", | |||
type = "wikitext", | |||
desc = "The error message to display. The message will be displayed both in the article itself and as a [[Template:Warn|warning]] in page edit previews.", | |||
default = DEFAULT_ERROR_MESSAGE, | |||
}, | |||
[2] = { | |||
name = "category", | |||
type = "string", | |||
desc = "The name of a category to include with the error so that a list of errors can be tracked. This category should be [[:Category:Hidden categories|hidden]].", | |||
default = CATEGORY_ERRORS | |||
}, | |||
}, | |||
examples = { | |||
{"This is an error"}, | |||
{"Invalid weapon type", "{{Invalid Arguments}}"}, | |||
{}, | |||
} | |||
}, | |||
} | } | ||
return p | return p |
Revision as of 13:22, 15 September 2022
This module provides functions which templates can invoke when they receive invalid input.
local utilsError = require("Module:UtilsError")
local p = {}
local DEFAULT_ERROR_MESSAGE = "Error"
local CATEGORY_ERRORS = "Category:Pages with template errors"
function p.Error(frame)
local args = frame:getParent().args
return p.printError(args[1], args[2])
end
function p.printError(message, category)
local errorMessage = message or DEFAULT_ERROR_MESSAGE
local errorCategory = category or CATEGORY_ERRORS
utilsError.warn(errorMessage)
local err = mw.html.create("strong")
:addClass("error")
:wikitext(errorMessage)
return string.format("[[:%s|%s]][[%s]]", errorMessage, tostring(err), errorCategory)
end
p.Templates = {
Error = {
purpose = "This template indicates that a template is being used incorrectly. See also [[Template:Warn]].",
params = {
[1] = {
name = "message",
type = "wikitext",
desc = "The error message to display. The message will be displayed both in the article itself and as a [[Template:Warn|warning]] in page edit previews.",
default = DEFAULT_ERROR_MESSAGE,
},
[2] = {
name = "category",
type = "string",
desc = "The name of a category to include with the error so that a list of errors can be tracked. This category should be [[:Category:Hidden categories|hidden]].",
default = CATEGORY_ERRORS
},
},
examples = {
{"This is an error"},
{"Invalid weapon type", "{{Invalid Arguments}}"},
{},
}
},
}
return p