* @since 1.19
* @param $msg string
* @param $callerOffset int
+ * @param $level int A PHP error level. See sendWarning()
+ * @param $log string: 'production' will always trigger a php error, 'auto'
+ * will trigger an error if $wgDevelopmentWarnings is true, and 'debug'
+ * will only write to the debug log(s).
+ *
* @return mixed
*/
- public static function warning( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
+ public static function warning( $msg, $callerOffset = 1, $level = E_USER_NOTICE, $log = 'auto' ) {
+ global $wgDevelopmentWarnings;
+
+ if ( $log === 'auto' && !$wgDevelopmentWarnings ) {
+ $log = 'debug';
+ }
+
+ if ( $log === 'debug' ) {
+ $level = false;
+ }
+
$callerDescription = self::getCallerDescription( $callerOffset );
self::sendWarning( $msg, $callerDescription, $level );
* - MediaWiki's debug log, if $wgDevelopmentWarnings is set to false.
*
* @since 1.19
- * @param $function string: Function that is deprecated.
- * @param $version string|bool: Version in which the function was deprecated.
- * @param $component string|bool: Component to which the function belongs.
+ * @param string $function Function that is deprecated.
+ * @param string|bool $version Version in which the function was deprecated.
+ * @param string|bool $component Component to which the function belongs.
* If false, it is assumbed the function is in MediaWiki core.
* @param $callerOffset integer: How far up the callstack is the original
* caller. 2 = function that called the function that called
}
if ( $sendToLog ) {
- self::sendWarning( $msg, $callerDescription, E_USER_DEPRECATED );
+ global $wgDevelopmentWarnings; // we could have a more specific $wgDeprecationWarnings setting.
+ self::sendWarning( $msg, $callerDescription, $wgDevelopmentWarnings ? E_USER_DEPRECATED : false );
}
if ( self::$enabled ) {
}
/**
- * Send a warning either to the debug log or by triggering an user PHP
- * error depending on $wgDevelopmentWarnings.
+ * Send a warning to the debug log and optionally also trigger a PHP
+ * error, depending on the $level argument.
*
* @param $msg string Message to send
* @param $caller array caller description get from getCallerDescription()
- * @param $level error level to use if $wgDevelopmentWarnings is true
+ * @param $level int|bool error level to use; set to false to not trigger an error
*/
private static function sendWarning( $msg, $caller, $level ) {
- global $wgDevelopmentWarnings;
-
$msg .= ' [Called from ' . $caller['func'] . ' in ' . $caller['file'] . ']';
- if ( $wgDevelopmentWarnings ) {
+ if ( $level !== false ) {
trigger_error( $msg, $level );
- } else {
- wfDebug( "$msg\n" );
}
+
+ wfDebug( "$msg\n" );
}
/**