Module:Utils: Difference between revisions
From Halopedia, the Halo wiki
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
local category = args[3] or 'Pages containing template errors' | local category = args[3] or 'Pages containing template errors' | ||
local template = args[4] or nil | local template = args[4] or nil | ||
-- Style data | |||
etype = string.upper( etype ) | |||
-- Add a warning to the edit preview | -- Add a warning to the edit preview | ||
if template == nil then | if template == nil then | ||
mw.addWarning( etype .. ' | mw.addWarning( "'''" .. etype .. " ERROR:''' " .. message ) | ||
else | else | ||
mw.addWarning( etype .. ' | mw.addWarning( "'''" .. etype .. " ERROR:''' " .. message .. ' (Template name: "' .. template .. ')' ) | ||
end | end | ||
-- Create and return the text to display on the page itself | -- Create and return the text to display on the page itself | ||
return [[<span class="template-error" style="color: red;">''' | return [[<span class="template-error" style="color: red;">''']] | ||
.. etype | .. etype | ||
.. [[ | .. [[ ERROR:''' ]] | ||
.. message | .. message | ||
.. '</span> [[Category:' | .. '</span> [[Category:' |
Revision as of 15:03, September 28, 2020
Documentation for this module may be created at ModuleDoc:Utils
local utils = {}
function utils.error( ... )
-- Collect necessary information to display error
local args = select( 1, ... )[ 'args' ]
local message = args[1] or 'There was an error with a template. Are the parameters all correct?'
local etype = args[2] or 'Template'
local category = args[3] or 'Pages containing template errors'
local template = args[4] or nil
-- Style data
etype = string.upper( etype )
-- Add a warning to the edit preview
if template == nil then
mw.addWarning( "'''" .. etype .. " ERROR:''' " .. message )
else
mw.addWarning( "'''" .. etype .. " ERROR:''' " .. message .. ' (Template name: "' .. template .. ')' )
end
-- Create and return the text to display on the page itself
return [[<span class="template-error" style="color: red;">''']]
.. etype
.. [[ ERROR:''' ]]
.. message
.. '</span> [[Category:'
.. category
.. ']]'
end
return utils