* @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'] );
}
*/
function useMessageCache() {
global $wgLang;
+ foreach ( $this->getTrace() as $frame ) {
+ if ( isset( $frame['class'] ) && $frame['class'] === 'LocalisationCache' ) {
+ return false;
+ }
+ }
return is_object( $wgLang );
}
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();
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>
";
}
* 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() {
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";
- if ( $GLOBALS['wgShowExceptionDetails'] )
- $message .= "Original exception: " . $e->__toString();
- $message .= "\n\nException caught inside exception handler";
- if ( $GLOBALS['wgShowExceptionDetails'] )
- $message .= ": " . $e2->__toString();
- $message .= "\n";
+ 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";
- }
}
- } 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";
- }
- }
+ }
}
/**
# Try to produce meaningful output anyway. Using echo may corrupt output to STDOUT though.
if ( defined( 'STDERR' ) ) {
fwrite( STDERR, $message );
- }
- else {
+ } else {
echo( $message );
}
}