Jump to content

Module:Warning: Difference between revisions

From MediaWiki3D
m Changed protection settings for "Module:Warning": High-risk template or module ([Edit=Require template editor access] (indefinite))
 
m 1 revision imported from wikipedia:en:Module:Warning
 
(No difference)

Latest revision as of 17:02, 16 August 2025

Documentation for this module may be created at Module:Warning/doc

local libraryUtil = require('libraryUtil')

local wrapper = "%s" -- wikitext formatting
local msg_loc = "Lua warning in %s at line %d: %s."
local msg = "Lua warning: %s."

return function (message, level)
	libraryUtil.checkType('warn', 2, level, 'number', true)
	level = level or 1
	if level > 0 then
		local _, location = pcall(error, '', level+2)
		if location ~= '' then
			location = mw.text.split(location:sub(1,-3), ':%f[%d]')
			message = msg_loc:format(location[1], location[2], message)
		else
			message = msg:format(message)
		end
	else
		message = msg:format(message)
	end
	mw.addWarning(wrapper:format(message))
end