Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / includes / exception / MWExceptionHandler.php
index 9b59191..78a5df9 100644 (file)
@@ -121,7 +121,7 @@ class MWExceptionHandler {
                self::handleException( $e );
 
                // Make sure we don't claim success on exit for CLI scripts (T177414)
-               if ( PHP_SAPI === 'cli' ) {
+               if ( wfIsCLI() ) {
                        register_shutdown_function(
                                function () {
                                        exit( 255 );
@@ -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' ) );
        }
 
        /**
@@ -279,7 +282,7 @@ class MWExceptionHandler {
                // HHVM: Class undefined: foo
                // PHP5: Class 'foo' not found
                if ( preg_match( "/Class (undefined: \w+|'\w+' not found)/", $msg ) ) {
-                       // @codingStandardsIgnoreStart Generic.Files.LineLength.TooLong
+                       // phpcs:disable Generic.Files.LineLength
                        $msg = <<<TXT
 {$msg}
 
@@ -287,7 +290,7 @@ MediaWiki or an installed extension requires this class but it is not embedded d
 
 Please see <a href="https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries">mediawiki.org</a> for help on installing the required components.
 TXT;
-                       // @codingStandardsIgnoreEnd
+                       // phpcs:enable
                }
 
                // We can't just create an exception and log it as it is likely that
@@ -300,7 +303,7 @@ TXT;
                $logger = LoggerFactory::getInstance( 'fatal' );
                $logger->error( $msg, [
                        'fatal_exception' => [
-                               'class' => 'ErrorException',
+                               'class' => ErrorException::class,
                                'message' => "PHP Fatal Error: {$message}",
                                'code' => $level,
                                'file' => $file,
@@ -661,7 +664,7 @@ TXT;
                $catcher = self::CAUGHT_BY_HANDLER;
                // The set_error_handler callback is independent from error_reporting.
                // Filter out unwanted errors manually (e.g. when
-               // MediaWiki\suppressWarnings is active).
+               // Wikimedia\suppressWarnings is active).
                $suppressed = ( error_reporting() & $e->getSeverity() ) === 0;
                if ( !$suppressed ) {
                        $logger = LoggerFactory::getInstance( $channel );