Follow up r64936. Even better, provide the bug number and imagemagick doc page.
[lhc/web/wiklou.git] / includes / Exception.php
index b71a07b..ddcd739 100644 (file)
@@ -8,13 +8,13 @@
  * @ingroup Exception
  */
 class MWException extends Exception {
-
        /**
         * Should the exception use $wgOut to output the error ?
         * @return bool
         */
        function useOutputPage() {
-               return !empty( $GLOBALS['wgFullyInitialised'] ) &&
+               return $this->useMessageCache() &&
+                       !empty( $GLOBALS['wgFullyInitialised'] ) &&
                        ( !empty( $GLOBALS['wgArticle'] ) || ( !empty( $GLOBALS['wgOut'] ) && !$GLOBALS['wgOut']->isArticle() ) ) &&
                        !empty( $GLOBALS['wgTitle'] );
        }
@@ -25,15 +25,20 @@ class MWException extends Exception {
         */
        function useMessageCache() {
                global $wgLang;
+               foreach ( $this->getTrace() as $frame ) {
+                       if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) {
+                               return false;
+                       }
+               }
                return is_object( $wgLang );
        }
 
        /**
         * Run hook to allow extensions to modify the text of the exception
         *
-        * @param String $name class name of the exception
-        * @param Array $args arguments to pass to the callback functions
-        * @return mixed string to output or null if any hook has been called
+        * @param $name String: class name of the exception
+        * @param $args Array: arguments to pass to the callback functions
+        * @return Mixed: string to output or null if any hook has been called
         */
        function runHooks( $name, $args = array() ) {
                global $wgExceptionHooks;
@@ -58,9 +63,9 @@ class MWException extends Exception {
        /**
         * Get a message from i18n
         *
-        * @param String $key message name
-        * @param String $fallback default message if the message cache can't be
-        *                         called by the exception
+        * @param $key String: message name
+        * @param $fallback String: default message if the message cache can't be
+        *                  called by the exception
         * The function also has other parameters that are arguments for the message
         * @return String message with arguments replaced
         */
@@ -122,7 +127,7 @@ class MWException extends Exception {
         * Return the requested URL and point to file and line number from which the
         * exception occured
         *
-        * @return string
+        * @return String
         */
        function getLogMessage() {
                global $wgRequest;
@@ -161,7 +166,7 @@ class MWException extends Exception {
                        if( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
                                die( $hookResult );
                        }
-                       if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
+                       if ( defined( 'MEDIAWIKI_INSTALL' ) || $this->htmlBodyOnly() ) {
                                echo $this->getHTML();
                        } else {
                                echo $this->htmlHeader();
@@ -202,12 +207,12 @@ class MWException extends Exception {
                        header( 'Pragma: nocache' );
                }
                $title = $this->getPageTitle();
-               echo "<html>
+               return "<html>
                <head>
                <title>$title</title>
                </head>
                <body>
-               <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>
+               <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''/>$title</h1>
                ";
        }
 
@@ -215,7 +220,14 @@ class MWException extends Exception {
         * print the end of the html page if not using $wgOut.
         */
        function htmlFooter() {
-               echo "</body></html>";
+               return "</body></html>";
+       }
+       
+       /**
+        * headers handled by subclass?
+        */
+       function htmlBodyOnly() {
+               return false;
        }
 
        static function isCommandLine() {
@@ -272,36 +284,38 @@ function wfInstallExceptionHandler() {
  */
 function wfReportException( Exception $e ) {
        $cmdLine = MWException::isCommandLine();
-        if ( $e instanceof MWException ) {
-                try {
-                        $e->report();
-                } catch ( Exception $e2 ) {
-                        // Exception occurred from within exception handler
-                        // Show a simpler error message for the original exception,
-                        // don't try to invoke report()
-                        $message = "MediaWiki internal error.\n\n" .
-                        "Original exception: " . $e->__toString() .
-                        "\n\nException caught inside exception handler: " .
-                        $e2->__toString() . "\n";
-
-                        if ( $cmdLine ) {
-                                wfPrintError( $message );
-                        } else {
-                                echo nl2br( htmlspecialchars( $message ) ). "\n";
-                        }
-                }
-        } else {
-                $message = "Unexpected non-MediaWiki exception encountered, of type \"" . get_class( $e ) . "\"\n" .
-                        $e->__toString() . "\n";
-                if ( $GLOBALS['wgShowExceptionDetails'] ) {
-                        $message .= "\n" . $e->getTraceAsString() ."\n";
-                }
-                if ( $cmdLine ) {
-                        wfPrintError( $message );
-                } else {
-                        echo nl2br( htmlspecialchars( $message ) ). "\n";
-                }
-        }
+       if ( $e instanceof MWException ) {
+               try {
+                       $e->report();
+               } catch ( Exception $e2 ) {
+                       // Exception occurred from within exception handler
+                       // Show a simpler error message for the original exception,
+                       // don't try to invoke report()
+                       $message = "MediaWiki internal error.\n\n";
+                       if ( $GLOBALS['wgShowExceptionDetails'] )
+                               $message .= "Original exception: " . $e->__toString();
+                       $message .= "\n\nException caught inside exception handler";
+                       if ( $GLOBALS['wgShowExceptionDetails'] )
+                               $message .= ": " . $e2->__toString();
+                       $message .= "\n";
+                       if ( $cmdLine ) {
+                               wfPrintError( $message );
+                       } else {
+                               echo nl2br( htmlspecialchars( $message ) ). "\n";
+                       }
+               }
+       } else {
+               $message = "Unexpected non-MediaWiki exception encountered, of type \"" . get_class( $e ) . "\"\n" .
+                       $e->__toString() . "\n";
+               if ( $GLOBALS['wgShowExceptionDetails'] ) {
+                       $message .= "\n" . $e->getTraceAsString() ."\n";
+               }
+               if ( $cmdLine ) {
+                       wfPrintError( $message );
+               } else {
+                       echo nl2br( htmlspecialchars( $message ) ). "\n";
+               }
+       }
 }
 
 /**
@@ -313,8 +327,7 @@ function wfPrintError( $message ) {
        #      Try to produce meaningful output anyway. Using echo may corrupt output to STDOUT though.
        if ( defined( 'STDERR' ) ) {
                fwrite( STDERR, $message );
-       }
-       else {
+       } else {
                echo( $message );
        }
 }