r91602 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91601‎ | r91602 | r91603 >
Date:21:01, 6 July 2011
Author:demon
Status:ok
Tags:
Comment:
Clean up the mess that is wfDie (resolves r85918). wfDie() doesn't exist anymore, so don't use it.

The only two usages left since r91590 are php version checks for index/load/api.php, and $wgAPIEnabled check in api.php. Consolidate all of the "bailing for invalid version" into PHPVersionError.php. Leaving $wgAPIEnabled as the only user was silly, so just echo and die like wfDie() would've done
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)
  • /trunk/phase3/load.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Maintenance.php
@@ -27,12 +27,9 @@
2828 $maintClass = false;
2929
3030 // Make sure we're on PHP5 or better
31 -if ( version_compare( PHP_VERSION, '5.2.3' ) < 0 ) {
32 - die ( "Sorry! This version of MediaWiki requires PHP 5.2.3; you are running " .
33 - PHP_VERSION . ".\n\n" .
34 - "If you are sure you already have PHP 5.2.3 or higher installed, it may be\n" .
35 - "installed in a different path from PHP " . PHP_VERSION . ". Check with your system\n" .
36 - "administrator.\n" );
 31+if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.2.3' ) < 0 ) {
 32+ require_once( dirname( __FILE__ ) . '/../includes/PHPVersionError.php' );
 33+ wfPHPVersionError( 'cli' );
3734 }
3835
3936 // Wrapper for posix_isatty()
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1244,24 +1244,6 @@
12451245 }
12461246
12471247 /**
1248 - * Print an error message and die, returning nonzero to the shell if any. Plain die()
1249 - * fails to return nonzero to the shell if you pass a string. Entry points may customise
1250 - * this function to return a prettier error message, but implementations must not assume
1251 - * access to any of the usual MediaWiki infrastructure (AutoLoader, localisation, database,
1252 - * etc). This should not be called directly once $wgFullyInitialised is set; instead,
1253 - * throw an exception and let Exception.php handle whether or not it's possible to show
1254 - * a prettier error.
1255 - *
1256 - * @param $msg String
1257 - */
1258 -if( !function_exists( 'wfDie' ) ){
1259 - function wfDie( $msg = '' ) {
1260 - echo $msg;
1261 - die( 1 );
1262 - }
1263 -}
1264 -
1265 -/**
12661248 * Throw a debugging exception. This function previously once exited the process,
12671249 * but now throws an exception instead, with similar results.
12681250 *
Index: trunk/phase3/index.php
@@ -40,25 +40,8 @@
4141 // has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4.
4242 // Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and 5.1, respectively.
4343 if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ) {
44 - $phpversion = htmlspecialchars( phpversion() );
45 - $errorMsg = <<<ENDL
46 - <p>
47 - MediaWiki requires PHP 5.2.3 or higher. You are running PHP $phpversion.
48 - </p>
49 - <p>
50 - Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
51 - PHP versions less than 5.3.0 are no longer supported by the PHP Group and will not receive
52 - security or bugfix updates.
53 - </p>
54 - <p>
55 - If for some reason you are unable to upgrade your PHP version, you will need to
56 - <a href="http://www.mediawiki.org/wiki/Download">download</a> an older version
57 - of MediaWiki from our website. See our
58 - <a href="http://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
59 - for details of which versions are compatible with prior versions of PHP.
60 - </p>
61 -ENDL;
62 - wfDie( $errorMsg );
 44+ require( dirname( __FILE__ ) . '/includes/PHPVersionError.php' );
 45+ wfPHPVersionError( 'index.php' );
6346 }
6447
6548 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
@@ -72,68 +55,3 @@
7356
7457 $mediaWiki = new MediaWiki();
7558 $mediaWiki->run();
76 -
77 -/**
78 - * Display something vaguely comprehensible in the event of a totally unrecoverable error.
79 - * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
80 - * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
81 - * no longer need to be).
82 - *
83 - * Calling this function kills execution immediately.
84 - *
85 - * @param $errorMsg String fully-escaped HTML
86 - */
87 -function wfDie( $errorMsg ){
88 - // Use the version set in DefaultSettings if possible, but don't rely on it
89 - global $wgVersion, $wgLogo;
90 - $version = isset( $wgVersion ) && $wgVersion
91 - ? htmlspecialchars( $wgVersion )
92 - : '';
93 -
94 - $script = $_SERVER['SCRIPT_NAME'];
95 - $path = pathinfo( $script, PATHINFO_DIRNAME ) . '/';
96 - $path = str_replace( '//', '/', $path );
97 -
98 - $logo = isset( $wgLogo ) && $wgLogo
99 - ? $wgLogo
100 - : $path . 'skins/common/images/mediawiki.png';
101 - $encLogo = htmlspecialchars( $logo );
102 -
103 - header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
104 - header( 'Content-type: text/html; charset=UTF-8' );
105 - // Don't cache error pages! They cause no end of trouble...
106 - header( 'Cache-control: none' );
107 - header( 'Pragma: nocache' );
108 -
109 - ?>
110 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
111 -<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
112 - <head>
113 - <title>MediaWiki <?php echo $version; ?></title>
114 - <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
115 - <style type='text/css' media='screen'>
116 - body {
117 - color: #000;
118 - background-color: #fff;
119 - font-family: sans-serif;
120 - padding: 2em;
121 - text-align: center;
122 - }
123 - p, img, h1 {
124 - text-align: left;
125 - margin: 0.5em 0;
126 - }
127 - h1 {
128 - font-size: 120%;
129 - }
130 - </style>
131 - </head>
132 - <body>
133 - <img src="<?php echo $encLogo; ?>" alt='The MediaWiki logo' />
134 - <h1>MediaWiki <?php echo $version; ?> internal error</h1>
135 - <div class='error'> <?php echo $errorMsg; ?> </div>
136 - </body>
137 -</html>
138 - <?php
139 - die( 1 );
140 -}
Index: trunk/phase3/api.php
@@ -37,19 +37,12 @@
3838 // So extensions (and other code) can check whether they're running in API mode
3939 define( 'MW_API', true );
4040
41 -// We want a plain message on catastrophic errors that machines can identify
42 -function wfDie( $msg = '' ) {
43 - header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
44 - echo $msg;
45 - die( 1 );
 41+// Bail if PHP is too low
 42+if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ) {
 43+ require( dirname( __FILE__ ) . '/includes/PHPVersionError.php' );
 44+ wfPHPVersionError( 'api.php' );
4645 }
4746
48 -// Die on unsupported PHP versions
49 -if( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ){
50 - $version = htmlspecialchars( $wgVersion );
51 - wfDie( "MediaWiki $version requires at least PHP version 5.2.3." );
52 -}
53 -
5447 // Initialise common code.
5548 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
5649 require ( 'phase3/includes/WebStart.php' );
@@ -67,9 +60,10 @@
6861
6962 // Verify that the API has not been disabled
7063 if ( !$wgEnableAPI ) {
71 - wfDie( 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php'
72 - . '<pre><b>$wgEnableAPI=true;</b></pre>'
73 - );
 64+ header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
 65+ echo( 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php'
 66+ . '<pre><b>$wgEnableAPI=true;</b></pre>' );
 67+ die(1);
7468 }
7569
7670 // Selectively allow cross-site AJAX
Index: trunk/phase3/load.php
@@ -23,19 +23,12 @@
2424 *
2525 */
2626
27 -// We want error messages to not be interpreted as CSS or JS
28 -function wfDie( $msg = '' ) {
29 - header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
30 - echo "/* $msg */";
31 - die( 1 );
 27+// Bail if PHP is too low
 28+if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ) {
 29+ require( dirname( __FILE__ ) . '/includes/PHPVersionError.php' );
 30+ wfPHPVersionError( 'load.php' );
3231 }
3332
34 -// Die on unsupported PHP versions
35 -if( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ){
36 - $version = htmlspecialchars( $wgVersion );
37 - wfDie( "MediaWiki $version requires at least PHP version 5.2.3." );
38 -}
39 -
4033 if ( isset( $_SERVER['MW_COMPILED'] ) ) {
4134 require ( 'phase3/includes/WebStart.php' );
4235 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r91604Followup r91602, forgot svn adddemon21:05, 6 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
r91590Remove last wfDie()s from maintenancedemon19:57, 6 July 2011

Status & tagging log