jenkins-bot has submitted this change and it was merged.
Change subject: Exception: Clean up html document for error pages
......................................................................
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 <style> to have it use a sans-serif font and a bit
padding to offset it from the edge of the window.
* Output stacktrace in <pre> as-is (with linebreaks) instead of
in a <p> with <br/>.
Clean up:
* Removed spurious "<!-- SiteSearch Google -->" comment.
* Change sitesearch radio button to not need the id/for
attributes but simply nest them. Visual rendering and browser
behaviour is identical.
* Renamed $text to $html since that is what it is (follows-up
4ca9805 which reused that variable for html, it used to contain
text).
* Remove odd linebreak from "dberr-problems" message, it was
being output as-is in the html (html escaped, of course) and
line breaks have no meaning inside an <h1> tag. Using a simple
space instead. Visual rendering is identical.
Coding style:
* Using <!DOCTYPE html> instead of <!doctype html> for consistency
with other documents we output.
* Switched a few inline #-style comments to use // instead.
* Switched a few strings from double quotes to single quotes in
areas close to the changed code.
Change-Id: I33232d871200cbd23501c9a6c5f8a178931e135e
---
M includes/Exception.php
M includes/db/DatabaseError.php
M languages/messages/MessagesEn.php
3 files changed, 38 insertions(+), 45 deletions(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Exception.php b/includes/Exception.php
index a91f865..46402f9 100644
--- a/includes/Exception.php
+++ b/includes/Exception.php
@@ -164,7 +164,8 @@
* @return string
*/
function getPageTitle() {
- return $this->msg( 'internalerror', "Internal error" );
+ global $wgSitename;
+ return $this->msg( 'pagetitle', "$1 - $wgSitename", $this->msg(
'internalerror', 'Internal error' ) );
}
/**
@@ -209,13 +210,14 @@
$wgOut->output();
} else {
- header( "Content-Type: text/html; charset=utf-8" );
- echo "<!doctype html>\n" .
+ header( 'Content-Type: text/html; charset=utf-8' );
+ echo "<!DOCTYPE html>\n" .
'<html><head>' .
'<title>' . htmlspecialchars(
$this->getPageTitle() ) . '</title>' .
+ '<style>body { font-family: sans-serif; margin:
0; padding: 0.5em 2em; }</style>' .
"</head><body>\n";
- $hookResult = $this->runHooks( get_class( $this ) .
"Raw" );
+ $hookResult = $this->runHooks( get_class( $this ) .
'Raw' );
if ( $hookResult ) {
echo $hookResult;
} else {
@@ -242,8 +244,8 @@
} 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 da391d7..937bea0 100644
--- a/includes/db/DatabaseError.php
+++ b/includes/db/DatabaseError.php
@@ -66,8 +66,7 @@
$s = $this->getHTMLContent();
if ( $wgShowDBErrorBacktrace ) {
- $s .= '<p>Backtrace:</p><p>' .
- nl2br( htmlspecialchars(
$this->getTraceAsString() ) ) . '</p>';
+ $s .= '<p>Backtrace:</p><pre>' . htmlspecialchars(
$this->getTraceAsString() ) . '</pre>';
}
return $s;
@@ -137,15 +136,8 @@
* @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' );
}
/**
@@ -154,7 +146,7 @@
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 @@
# No database access
MessageCache::singleton()->disable();
- $text =
"<h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
+ $html =
"<h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
if ( $wgShowDBErrorBacktrace ) {
- $text .= '<p>Backtrace:</p><p>' .
- nl2br( htmlspecialchars(
$this->getTraceAsString() ) ) . '</p>';
+ $html .= '<p>Backtrace:</p><pre>' . htmlspecialchars(
$this->getTraceAsString() ) . '</pre>';
}
- $text .= '<hr />';
- $text .= $this->searchForm();
+ $html .= '<hr />';
+ $html .= $this->searchForm();
- return $text;
+ return $html;
}
protected function getTextContent() {
@@ -195,21 +186,21 @@
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( '</html>',
'</body>' ), '', $cache );
- # Add cache notice...
- $cache .= '<div
style="color:red;font-size:150%;font-weight:bold;">' .
+ // Add cache notice...
+ $cache .= '<div style="border:1px solid
#ffd0d0;padding:1em;">' .
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.' ) ) .
'</div>';
- # Output cached page with notices on
bottom and re-close body
+ // Output cached page with notices on
bottom and re-close body
echo "{$cache}<hr
/>{$this->getHTML()}</body></html>";
return;
}
@@ -218,7 +209,7 @@
}
}
- # 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 @@
$trygoogle = <<<EOT
<div style="margin: 1.5em">$usegoogle<br />
-<small>$outofdate</small></div>
-<!-- SiteSearch Google -->
+<small>$outofdate</small>
+</div>
<form method="get" action="//www.google.com/search" id="googlesearch">
<input type="hidden" name="domains" value="$server" />
<input type="hidden" name="num" value="50" />
@@ -249,12 +240,11 @@
<input type="text" name="q" size="31" maxlength="255" value="$search" />
<input type="submit" name="btnG" value="$googlesearch" />
- <div>
- <input type="radio" name="sitesearch" id="gwiki" value="$server"
checked="checked" /><label for="gwiki">$sitename</label>
- <input type="radio" name="sitesearch" id="gWWW" value="" /><label
for="gWWW">WWW</label>
- </div>
+ <p>
+ <label><input type="radio" name="sitesearch" value="$server"
checked="checked" />$sitename</label>
+ <label><input type="radio" name="sitesearch" value=""
/>WWW</label>
+ </p>
</form>
-<!-- SiteSearch Google -->
EOT;
return $trygoogle;
}
@@ -266,15 +256,17 @@
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 6d68d36..fb8457f 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -4956,8 +4956,7 @@
# 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)',
--
To view, visit https://gerrit.wikimedia.org/r/84991
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I33232d871200cbd23501c9a6c5f8a178931e135e
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: PleaseStand <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits