r87630 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87629‎ | r87630 | r87631 >
Date:14:01, 7 May 2011
Author:happy-melon
Status:ok
Tags:
Comment:
Follow-up r85918:
* Clean up the ugly adding-then-removing-then-readding HTML <head> and <body> tags in DBConnectionError, deprecates MWException::htmlBodyOnly()
* Also deprecates MWException::htmlHeader(), removes code duplication since MWException::reportHTML() can safely call wfDie() and get an output format appropriate for the entry point
* Copy a couple of HTML headers (Cache-control, Pragma and Content-type) to the wfDie() implementation.
Modified paths:
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Exception.php
@@ -188,12 +188,11 @@
189189 die( $hookResult );
190190 }
191191
192 - if ( defined( 'MEDIAWIKI_INSTALL' ) || $this->htmlBodyOnly() ) {
193 - echo $this->getHTML();
 192+ $html = $this->getHTML();
 193+ if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
 194+ echo $html;
194195 } else {
195 - echo $this->htmlHeader();
196 - echo $this->getHTML();
197 - echo $this->htmlFooter();
 196+ wfDie( $html );
198197 }
199198 }
200199 }
@@ -219,6 +218,7 @@
220219 /**
221220 * Send headers and output the beginning of the html page if not using
222221 * $wgOut to output the exception.
 222+ * @deprecated since 1.18 call wfDie() if you need to die immediately
223223 */
224224 function htmlHeader() {
225225 global $wgLogo, $wgLang;
@@ -273,18 +273,12 @@
274274
275275 /**
276276 * print the end of the html page if not using $wgOut.
 277+ * @deprecated since 1.18
277278 */
278279 function htmlFooter() {
279280 return Html::closeElement( 'body' ) . Html::closeElement( 'html' );
280281 }
281282
282 - /**
283 - * headers handled by subclass?
284 - */
285 - function htmlBodyOnly() {
286 - return false;
287 - }
288 -
289283 static function isCommandLine() {
290284 return !empty( $GLOBALS['wgCommandLineMode'] ) && !defined( 'MEDIAWIKI_INSTALL' );
291285 }
Index: trunk/phase3/includes/db/Database.php
@@ -2970,6 +2970,13 @@
29712971
29722972 $extra = $this->searchForm();
29732973
 2974+ return "$text<hr />$extra";
 2975+ }
 2976+
 2977+ public function reportHTML(){
 2978+ global $wgUseFileCache;
 2979+
 2980+ # Check whether we can serve a file-cached copy of the page with the error underneath
29742981 if ( $wgUseFileCache ) {
29752982 try {
29762983 $cache = $this->fileCachedPage();
@@ -2984,15 +2991,16 @@
29852992 '</div>';
29862993
29872994 # Output cached page with notices on bottom and re-close body
2988 - return "{$cache}<hr />$text<hr />$extra</body></html>";
 2995+ echo "{$cache}<hr />{$this->getHTML()}</body></html>";
 2996+ return;
29892997 }
29902998 } catch ( MWException $e ) {
29912999 // Do nothing, just use the default page
29923000 }
29933001 }
29943002
2995 - # Headers needed here - output is just the error message
2996 - return $this->htmlHeader() . "$text<hr />$extra" . $this->htmlFooter();
 3003+ # We can't, cough and die in the usual fashion
 3004+ return parent::reportHTML();
29973005 }
29983006
29993007 function searchForm() {
@@ -3049,10 +3057,6 @@
30503058 return '';
30513059 }
30523060 }
3053 -
3054 - function htmlBodyOnly() {
3055 - return true;
3056 - }
30573061 }
30583062
30593063 /**
Index: trunk/phase3/index.php
@@ -170,6 +170,10 @@
171171 : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png';
172172
173173 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
 174+ header( 'Content-type: text/html; charset=UTF-8' );
 175+ // Don't cache error pages! They cause no end of trouble...
 176+ header( 'Cache-control: none' );
 177+ header( 'Pragma: nocache' );
174178
175179 ?>
176180 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Follow-up revisions

RevisionCommit summaryAuthorDate
r88352Follow up r87630. The file cache is now checked at reportHTML() which overrid...platonides21:21, 17 May 2011
r92328REL1_18 MFT r79056, r80612, r81499, r87627, r87628, r87630, r87998, r88134, r...reedy22:46, 15 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85918Improvements to handling of 'catastrophic' errors, like unsupported PHP versi...happy-melon20:38, 12 April 2011

Status & tagging log