From 2bcffe8be4202ea2cb2d264669e307daaa94ddcb Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 19 Sep 2013 18:22:51 +0200 Subject: [PATCH] Exception: Clean up html document for error pages Interface: * Restore sitename as part of error page document title (follows-up 4ca9805). Moved to general Exception class as it is useful in general, this effectively changes the title from "This wiki has a problem" to "Internal error - Wikipedia". * Added basic ' . "\n"; - $hookResult = $this->runHooks( get_class( $this ) . "Raw" ); + $hookResult = $this->runHooks( get_class( $this ) . 'Raw' ); if ( $hookResult ) { echo $hookResult; } else { @@ -242,8 +244,8 @@ class MWException extends Exception { } elseif ( self::isCommandLine() ) { MWExceptionHandler::printError( $this->getText() ); } else { - header( "HTTP/1.1 500 MediaWiki exception" ); - header( "Status: 500 MediaWiki exception", true ); + header( 'HTTP/1.1 500 MediaWiki exception' ); + header( 'Status: 500 MediaWiki exception', true ); header( "Content-Type: $wgMimeType; charset=utf-8", true ); $this->reportHTML(); diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index da391d7aac..937bea0fed 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -66,8 +66,7 @@ class DBError extends MWException { $s = $this->getHTMLContent(); if ( $wgShowDBErrorBacktrace ) { - $s .= '

Backtrace:

' . - nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . '

'; + $s .= '

Backtrace:

' . htmlspecialchars( $this->getTraceAsString() ) . '
'; } return $s; @@ -137,24 +136,17 @@ class DBConnectionError extends DBError { * @return bool */ function getLogMessage() { - # Don't send to the exception log + // Don't send to the exception log return false; } - /** - * @return string - */ - function getPageTitle() { - return $this->msg( 'dberr-header', 'This wiki has a problem' ); - } - /** * @return string */ function getHTML() { global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors; - $sorry = htmlspecialchars( $this->msg( 'dberr-problems', "Sorry!\nThis site is experiencing technical difficulties." ) ); + $sorry = htmlspecialchars( $this->msg( 'dberr-problems', 'Sorry! This site is experiencing technical difficulties.' ) ); $again = htmlspecialchars( $this->msg( 'dberr-again', 'Try waiting a few minutes and reloading.' ) ); if ( $wgShowHostnames || $wgShowSQLErrors ) { @@ -169,17 +161,16 @@ class DBConnectionError extends DBError { # No database access MessageCache::singleton()->disable(); - $text = "

$sorry

$again

$info

"; + $html = "

$sorry

$again

$info

"; if ( $wgShowDBErrorBacktrace ) { - $text .= '

Backtrace:

' . - nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . '

'; + $html .= '

Backtrace:

' . htmlspecialchars( $this->getTraceAsString() ) . '
'; } - $text .= '
'; - $text .= $this->searchForm(); + $html .= '
'; + $html .= $this->searchForm(); - return $text; + return $html; } protected function getTextContent() { @@ -195,21 +186,21 @@ class DBConnectionError extends DBError { public function reportHTML() { global $wgUseFileCache; - # Check whether we can serve a file-cached copy of the page with the error underneath + // Check whether we can serve a file-cached copy of the page with the error underneath if ( $wgUseFileCache ) { try { $cache = $this->fileCachedPage(); - # Cached version on file system? + // Cached version on file system? if ( $cache !== null ) { - # Hack: extend the body for error messages + // Hack: extend the body for error messages $cache = str_replace( array( '', '' ), '', $cache ); - # Add cache notice... - $cache .= '
' . + // Add cache notice... + $cache .= '
' . htmlspecialchars( $this->msg( 'dberr-cachederror', - 'This is a cached copy of the requested page, and may not be up to date. ' ) ) . + 'This is a cached copy of the requested page, and may not be up to date.' ) ) . '
'; - # Output cached page with notices on bottom and re-close body + // Output cached page with notices on bottom and re-close body echo "{$cache}
{$this->getHTML()}"; return; } @@ -218,7 +209,7 @@ class DBConnectionError extends DBError { } } - # We can't, cough and die in the usual fashion + // We can't, cough and die in the usual fashion parent::reportHTML(); } @@ -239,8 +230,8 @@ class DBConnectionError extends DBError { $trygoogle = <<$usegoogle
-$outofdate
- +$outofdate +
@@ -249,12 +240,11 @@ class DBConnectionError extends DBError { -
- - -
+

+ + +

- EOT; return $trygoogle; } @@ -266,15 +256,17 @@ EOT; global $wgTitle, $wgOut, $wgRequest; if ( $wgOut->isDisabled() ) { - return ''; // Done already? + // Done already? + return ''; } - if ( $wgTitle ) { // use $wgTitle if we managed to set it + if ( $wgTitle ) { + // use $wgTitle if we managed to set it $t = $wgTitle->getPrefixedDBkey(); } else { - # Fallback to the raw title URL param. We can't use the Title - # class is it may hit the interwiki table and give a DB error. - # We may get a cache miss due to not sanitizing the title though. + // Fallback to the raw title URL param. We can't use the Title + // class is it may hit the interwiki table and give a DB error. + // We may get a cache miss due to not sanitizing the title though. $t = str_replace( ' ', '_', $wgRequest->getVal( 'title' ) ); if ( $t == '' ) { // fallback to main page $t = Title::newFromText( diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 6d68d36aa5..fb8457f63a 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -4956,8 +4956,7 @@ You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU Gen # Database error messages 'dberr-header' => 'This wiki has a problem', -'dberr-problems' => 'Sorry! -This site is experiencing technical difficulties.', +'dberr-problems' => 'Sorry! This site is experiencing technical difficulties.', 'dberr-again' => 'Try waiting a few minutes and reloading.', 'dberr-info' => '(Cannot contact the database server: $1)', 'dberr-info-hidden' => '(Cannot contact the database server)', -- 2.20.1