Merge "Use test user helper methods in UserGroupMembershipTest/UserTest"
[lhc/web/wiklou.git] / includes / exception / MWExceptionRenderer.php
index a9bd4da..bd43934 100644 (file)
@@ -47,10 +47,10 @@ class MWExceptionRenderer {
                } elseif ( self::isCommandLine() ) {
                        self::printError( self::getText( $e ) );
                } elseif ( $mode === self::AS_PRETTY ) {
+                       self::statusHeader( 500 );
                        if ( $e instanceof DBConnectionError ) {
                                self::reportOutageHTML( $e );
                        } else {
-                               self::statusHeader( 500 );
                                self::header( "Content-Type: $wgMimeType; charset=utf-8" );
                                self::reportHTML( $e );
                        }
@@ -84,51 +84,6 @@ class MWExceptionRenderer {
                }
        }
 
-       /**
-        * Run hook to allow extensions to modify the text of the exception
-        *
-        * Called by MWException for b/c
-        *
-        * @param Exception|Throwable $e
-        * @param string $name Class name of the exception
-        * @param array $args Arguments to pass to the callback functions
-        * @return string|null String to output or null if any hook has been called
-        */
-       public static function runHooks( $e, $name, $args = [] ) {
-               global $wgExceptionHooks;
-
-               if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) {
-                       return null; // Just silently ignore
-               }
-
-               if ( !array_key_exists( $name, $wgExceptionHooks ) ||
-                       !is_array( $wgExceptionHooks[$name] )
-               ) {
-                       return null;
-               }
-
-               $hooks = $wgExceptionHooks[$name];
-               $callargs = array_merge( [ $e ], $args );
-
-               foreach ( $hooks as $hook ) {
-                       if (
-                               is_string( $hook ) ||
-                               ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) )
-                       ) {
-                               // 'function' or [ 'class', 'hook' ]
-                               $result = call_user_func_array( $hook, $callargs );
-                       } else {
-                               $result = null;
-                       }
-
-                       if ( is_string( $result ) ) {
-                               return $result;
-                       }
-               }
-
-               return null;
-       }
-
        /**
         * @param Exception|Throwable $e
         * @return bool Should the exception use $wgOut to output the error?
@@ -167,16 +122,11 @@ class MWExceptionRenderer {
                                $wgOut->prepareErrorPage( self::msg( 'internalerror', 'Internal error' ) );
                        }
 
-                       $hookResult = self::runHooks( $e, get_class( $e ) );
-                       if ( $hookResult ) {
-                               $wgOut->addHTML( $hookResult );
-                       } else {
-                               // Show any custom GUI message before the details
-                               if ( $e instanceof MessageSpecifier ) {
-                                       $wgOut->addHTML( Message::newFromSpecifier( $e )->escaped() );
-                               }
-                               $wgOut->addHTML( self::getHTML( $e ) );
+                       // Show any custom GUI message before the details
+                       if ( $e instanceof MessageSpecifier ) {
+                               $wgOut->addHTML( Message::newFromSpecifier( $e )->escaped() );
                        }
+                       $wgOut->addHTML( self::getHTML( $e ) );
 
                        $wgOut->output();
                } else {
@@ -191,12 +141,7 @@ class MWExceptionRenderer {
                                '<style>body { font-family: sans-serif; margin: 0; padding: 0.5em 2em; }</style>' .
                                "</head><body>\n";
 
-                       $hookResult = self::runHooks( $e, get_class( $e ) . 'Raw' );
-                       if ( $hookResult ) {
-                               echo $hookResult;
-                       } else {
-                               echo self::getHTML( $e );
-                       }
+                       echo self::getHTML( $e );
 
                        echo "</body></html>\n";
                }
@@ -293,7 +238,7 @@ class MWExceptionRenderer {
                        $vars[] = '$wgShowDBErrorBacktrace = true;';
                }
                $vars = implode( ' and ', $vars );
-               return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information";
+               return "Set $vars at the bottom of LocalSettings.php to show detailed debugging information\n";
        }
 
        /**