Merge "Remove a hack, and a hack for the hack, for MediaWiki UI input fields"
[lhc/web/wiklou.git] / includes / exception / MWExceptionHandler.php
index ad462f2..5644231 100644 (file)
@@ -83,8 +83,7 @@ class MWExceptionHandler {
                                }
                        }
                } else {
-                       $message = "Unexpected non-MediaWiki exception encountered, of type \"" .
-                               get_class( $e ) . "\"";
+                       $message = "Exception encountered, of type \"" . get_class( $e ) . "\"";
 
                        if ( $wgShowExceptionDetails ) {
                                $message .= "\n" . MWExceptionHandler::getLogMessage( $e ) . "\nBacktrace:\n" .
@@ -142,7 +141,7 @@ class MWExceptionHandler {
         *
         *   try {
         *       ...
-        *   } catch ( MWException $e ) {
+        *   } catch ( Exception $e ) {
         *       $e->report();
         *   } catch ( Exception $e ) {
         *       echo $e->__toString();
@@ -247,6 +246,7 @@ class MWExceptionHandler {
                        if ( preg_match( "/Class (undefined: \w+|'\w+' not found)/",
                                $lastError['message']
                        ) ) {
+                               // @codingStandardsIgnoreStart Generic.Files.LineLength.TooLong
                                $msg = <<<TXT
 {$msg}
 
@@ -254,6 +254,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
                        }
                        $e = new ErrorException( $msg, 0, $lastError['type'] );
                        self::logError( $e );
@@ -437,6 +438,11 @@ TXT;
                        'message' => $e->getMessage(),
                );
 
+               if ( $e instanceof ErrorException && ( error_reporting() & $e->getSeverity() ) === 0 ) {
+                       // Flag surpressed errors
+                       $exceptionData['suppressed'] = true;
+               }
+
                // Because MediaWiki is first and foremost a web application, we set a
                // 'url' key unconditionally, but set it to null if the exception does
                // not occur in the context of a web request, as a way of making that
@@ -482,18 +488,23 @@ TXT;
         * Log an exception that wasn't thrown but made to wrap an error.
         *
         * @since 1.25
-        * @param Exception $e
+        * @param ErrorException $e
        */
-       protected static function logError( Exception $e ) {
+       protected static function logError( ErrorException $e ) {
                global $wgLogExceptionBacktrace;
 
-               $log = self::getLogMessage( $e );
-               if ( $wgLogExceptionBacktrace ) {
-                       wfDebugLog( 'error', $log . "\n" . $e->getTraceAsString() );
-               } else {
-                       wfDebugLog( 'error', $log );
+               // The set_error_handler callback is independent from error_reporting.
+               // Filter out unwanted errors manually (e.g. when wfSuppressWarnings is active).
+               if ( ( error_reporting() & $e->getSeverity() ) !== 0 ) {
+                       $log = self::getLogMessage( $e );
+                       if ( $wgLogExceptionBacktrace ) {
+                               wfDebugLog( 'error', $log . "\n" . $e->getTraceAsString() );
+                       } else {
+                               wfDebugLog( 'error', $log );
+                       }
                }
 
+               // Include all errors in the json log (surpressed errors will be flagged)
                $json = self::jsonSerializeException( $e, false, FormatJson::ALL_OK );
                if ( $json !== false ) {
                        wfDebugLog( 'error-json', $json, 'private' );