]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/Exception.php
MediaWiki 1.15.0
[autoinstalls/mediawiki.git] / includes / Exception.php
index eb7159861c26222567d84b66fae0e09ad4910dda..5f808b2043c2a02b33d043c329c51fd881f182a9 100644 (file)
@@ -161,23 +161,26 @@ class MWException extends Exception {
                        if( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
                                die( $hookResult );
                        }
-                       echo $this->htmlHeader();
-                       echo $this->getHTML();
-                       echo $this->htmlFooter();
+                       if ( defined( 'MEDIAWIKI_INSTALL' ) || $this->htmlBodyOnly() ) {
+                               echo $this->getHTML();
+                       } else {
+                               echo $this->htmlHeader();
+                               echo $this->getHTML();
+                               echo $this->htmlFooter();
+                       }
                }
        }
 
        /**
         * Output a report about the exception and takes care of formatting.
-        * It will be either HTML or plain text based on $wgCommandLineMode.
+        * It will be either HTML or plain text based on isCommandLine().
         */
        function report() {
-               global $wgCommandLineMode;
                $log = $this->getLogMessage();
                if ( $log ) {
                        wfDebugLog( 'exception', $log );
                }
-               if ( $wgCommandLineMode ) {
+               if ( self::isCommandLine() ) {
                        wfPrintError( $this->getText() );
                } else {
                        $this->reportHTML();
@@ -204,7 +207,7 @@ class MWException extends Exception {
                <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>
                ";
        }
 
@@ -214,6 +217,17 @@ class MWException extends Exception {
        function htmlFooter() {
                echo "</body></html>";
        }
+       
+       /**
+        * headers handled by subclass?
+        */
+       function htmlBodyOnly() {
+               return false;
+       }
+
+       static function isCommandLine() {
+               return !empty( $GLOBALS['wgCommandLineMode'] ) && !defined( 'MEDIAWIKI_INSTALL' );
+       }
 }
 
 /**
@@ -264,41 +278,44 @@ function wfInstallExceptionHandler() {
  * Report an exception to the user
  */
 function wfReportException( Exception $e ) {
-        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 ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {
-                                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 ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {
-                        wfPrintError( $message );
-                } else {
-                        echo nl2br( htmlspecialchars( $message ) ). "\n";
-                }
-        }
+       $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";
+                       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";
+               }
+       }
 }
 
 /**
  * Print a message, if possible to STDERR.
- * Use this in command line mode only (see wgCommandLineMode)
+ * Use this in command line mode only (see isCommandLine)
  */
 function wfPrintError( $message ) {
        #NOTE: STDERR may not be available, especially if php-cgi is used from the command line (bug #15602).