X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/74c929b24b048c9f1e31e17db757ae4195cd7673..dc9cc5d707f5a612938cc9371614cc41c328fda2:/includes/Exception.php diff --git a/includes/Exception.php b/includes/Exception.php index eb715986..5f808b20 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -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

"; } @@ -214,6 +217,17 @@ class MWException extends Exception { function htmlFooter() { echo ""; } + + /** + * 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).