From: Gergő Tisza Date: Tue, 21 Feb 2017 00:47:07 +0000 (-0800) Subject: Make it possible to not propagate errors to PHP X-Git-Tag: 1.31.0-rc.0~656^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22calendrier%22%2C%22type=semaine%22%29%20.%20%22?a=commitdiff_plain;h=87a8c1de7318f4bd83b7b51f20bab5a81994d8b3;p=lhc%2Fweb%2Fwiklou.git Make it possible to not propagate errors to PHP Add a $wgPropagateErrors configuration variable which can be used to prevent passing handled errors to PHP (and thus logging them twice). Bug: T45086 Change-Id: I64ab09762a04de2007b7d7864e3c504a1d6f8aee --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bdbeb70d6e..a6a36865bb 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6275,6 +6275,12 @@ $wgShowDBErrorBacktrace = false; */ $wgLogExceptionBacktrace = true; +/** + * If true, the MediaWiki error handler passes errors/warnings to the default error handler + * after logging them. The setting is ignored when the track_errors php.ini flag is true. + */ +$wgPropagateErrors = true; + /** * Expose backend server host names through the API and various HTML comments */ diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index 205ec77773..b125f58c48 100644 --- a/includes/exception/MWExceptionHandler.php +++ b/includes/exception/MWExceptionHandler.php @@ -170,6 +170,8 @@ class MWExceptionHandler { public static function handleError( $level, $message, $file = null, $line = null ) { + global $wgPropagateErrors; + if ( in_array( $level, self::$fatalErrorTypes ) ) { return call_user_func_array( 'MWExceptionHandler::handleFatalError', func_get_args() @@ -213,9 +215,10 @@ class MWExceptionHandler { $e = new ErrorException( "PHP $levelName: $message", 0, $level, $file, $line ); self::logError( $e, 'error', $severity ); - // This handler is for logging only. Return false will instruct PHP - // to continue regular handling. - return false; + // If $wgPropagateErrors is true return false so PHP shows/logs the error normally. + // Ignore $wgPropagateErrors if the error should break execution, or track_errors is set + // (which means someone is counting on regular PHP error handling behavior). + return !( $wgPropagateErrors || $level == E_RECOVERABLE_ERROR || ini_get( 'track_errors' ) ); } /**