Module:Utils

local utils = {}

function utils.defaultIfEmpty( val, default ) if val == nil or val == '' or val == {} then return default else return val end end

function utils.error( ... ) -- Collect necessary information to display error local args = select( 1, ... )[ 'args' ] local message = defaultIfEmpty( args[1], 'There was an error with a template. Are the parameters all correct?' ) local etype = defaultIfEmpty( args[2], 'Template' ) local category = defaultIfEmpty( args[3], 'Pages containing template errors' ) local template = defaultIfEmpty( args[4], 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 		.. etype		..  ERROR: 		.. message		.. ' [[Category:'		.. category		.. ']]' end

return utils