MWException: restore prior render() logic
authorBryan Davis <bd808@wikimedia.org>
Sun, 2 Oct 2016 00:02:12 +0000 (18:02 -0600)
committerBryan Davis <bd808@wikimedia.org>
Sun, 2 Oct 2016 00:32:12 +0000 (18:32 -0600)
Partially revert 00bee02 by restoring the prior MWException::report()
logic. MWExceptionRenderer does not handle all of the MWException
subclasses that somehow modify the default render() behavior. Notable
among these is Flow\Exception\FlowException and its subclasses which
modify the `$wgOut` global to divert HTML output to alternate locations.

Bug: T147122
Change-Id: Ibe3cadca229ce21ed0a3a2482433e3a22b5f5646

includes/exception/MWException.php

index 5496cb6..e958c94 100644 (file)
@@ -199,7 +199,26 @@ class MWException extends Exception {
         * It will be either HTML or plain text based on isCommandLine().
         */
        public function report() {
-               MWExceptionRenderer::output( $this, MWExceptionRenderer::AS_PRETTY );
+               global $wgMimeType;
+
+               if ( defined( 'MW_API' ) ) {
+                       // Unhandled API exception, we can't be sure that format printer is alive
+                       self::header( 'MediaWiki-API-Error: internal_api_error_' . get_class( $this ) );
+                       wfHttpError( 500, 'Internal Server Error', $this->getText() );
+               } elseif ( self::isCommandLine() ) {
+                       $message = $this->getText();
+                       // T17602: STDERR may not be available
+                       if ( defined( 'STDERR' ) ) {
+                               fwrite( STDERR, $message );
+                       } else {
+                               echo $message;
+                       }
+               } else {
+                       self::statusHeader( 500 );
+                       self::header( "Content-Type: $wgMimeType; charset=utf-8" );
+
+                       $this->reportHTML();
+               }
        }
 
        /**