r85918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85917‎ | r85918 | r85919 >
Date:20:38, 12 April 2011
Author:happy-melon
Status:resolved (Comments)
Tags:
Comment:
Improvements to handling of 'catastrophic' errors, like unsupported PHP versions, no MySQL functions, no LocalSettings, etc.
* Fix parsing of the three major entry points (index.php, api.php, load.php) back to PHP 4.4.9. We don't care what happens if you actually try to run these files on old versions, but the entry files need to parse correctly.
* consign /includes/templates/PHP4.php and /includes/templates/NoLocalSettings.php to the fiery pit of hell where they belong.
* Prevent loading of any other files for PHP < 5. WebStart.php was rendered unparseable in PHP 4 by the introduction of try/catch blocks in r85327.
* Die outright with a pretty error message on PHP < 5.2.3 as well as PHP 4. All versions of PHP below that throw parse errors of various sorts.
* Reimplement wfDie() to provide an entry-point-dependent die-with-readable-error-message function (for instance, we want a pretty human-readable page in index.php, something wrapped in CSS/JS /*...*/ comment block in load.php, etc).
* Standardise the appearance of the catastrophic errors thrown at the top of the stack with the ones lower down (exception-within-exception, etc). There isn't really a way to do this without duplication, AFAICT.
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/WebStart.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/templates/NoLocalSettings.php (deleted) (history)
  • /trunk/phase3/includes/templates/PHP4.php (deleted) (history)
  • /trunk/phase3/index.php (modified) (history)
  • /trunk/phase3/load.php (modified) (history)
  • /trunk/phase3/php5.php5 (deleted) (history)

Diff [purge]

Index: trunk/phase3/php5.php5
@@ -1,9 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Test for *.php5 capability in webserver
6 - * Used by includes/templates/PHP4.php
7 - */
8 -if ( version_compare( phpversion(), '5.1.0' ) >= 0 ) {
9 - echo 'y'.'e'.'s';
10 -}
Index: trunk/phase3/index.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * This is the main web entry point for MediaWiki.
65 *
@@ -37,6 +36,31 @@
3837 * @file
3938 */
4039
 40+// Bail on old versions of PHP. Pretty much every other file in the codebase
 41+// has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4.
 42+// Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and 5.1, respectively.
 43+if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.0' ) < 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 );
 63+}
 64+
4165 # Initialise common code. This gives us access to GlobalFunctions, the AutoLoader, and
4266 # the globals $wgRequest, $wgOut, $wgUser, $wgLang and $wgContLang, amongst others; it
4367 # does *not* load $wgTitle or $wgArticle
@@ -47,7 +71,8 @@
4872
4973 $maxLag = $wgRequest->getVal( 'maxlag' );
5074 if ( !is_null( $maxLag ) ) {
51 - list( $host, $lag ) = wfGetLB()->getMaxLag();
 75+ $lb = wfGetLB(); // foo()->bar() is not supported in PHP4
 76+ list( $host, $lag ) = $lb->getMaxLag();
5277 if ( $lag > $maxLag ) {
5378 header( 'HTTP/1.1 503 Service Unavailable' );
5479 header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
@@ -123,3 +148,58 @@
124149 wfProfileOut( 'index.php' );
125150
126151 $mediaWiki->restInPeace();
 152+
 153+/**
 154+ * Display something vaguely comprehensible in the event of a totally unrecoverable error.
 155+ * Does not assume access to *anything*; no globals, no autloader, no database, no localisation.
 156+ * Safe for PHP4 (and putting this here means that WebStart.php and GlobalSettings.php
 157+ * no longer need to be).
 158+ *
 159+ * Calling this function kills execution immediately.
 160+ *
 161+ * @param $errorMsg String fully-escaped HTML
 162+ */
 163+function wfDie( $errorMsg ){
 164+ // Use the version set in DefaultSettings if possible, but don't rely on it
 165+ global $wgVersion, $wgLogo;
 166+ $version = isset( $wgVersion ) && $wgVersion
 167+ ? htmlspecialchars( $wgVersion )
 168+ : '';
 169+ $logo = isset( $wgLogo ) && $wgLogo
 170+ ? $wgLogo
 171+ : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png';
 172+
 173+ header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
 174+
 175+ ?>
 176+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 177+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
 178+ <head>
 179+ <title>MediaWiki <?php echo $version; ?></title>
 180+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
 181+ <style type='text/css' media='screen'>
 182+ body {
 183+ color: #000;
 184+ background-color: #fff;
 185+ font-family: sans-serif;
 186+ padding: 2em;
 187+ text-align: center;
 188+ }
 189+ p, img, h1 {
 190+ text-align: left;
 191+ margin: 0.5em 0;
 192+ }
 193+ h1 {
 194+ font-size: 120%;
 195+ }
 196+ </style>
 197+ </head>
 198+ <body>
 199+ <img src="<?php echo $logo; ?>" alt='The MediaWiki logo' />
 200+ <h1>MediaWiki <?php echo $version; ?> internal error</h1>
 201+ <div class='error'> <?php echo $errorMsg; ?> </div>
 202+ </body>
 203+</html>
 204+ <?php
 205+ die( 1 );
 206+}
\ No newline at end of file
Index: trunk/phase3/api.php
@@ -37,7 +37,20 @@
3838 // So extensions (and other code) can check whether they're running in API mode
3939 define( 'MW_API', true );
4040
41 -// Initialise common code
 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 );
 46+}
 47+
 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+
 54+// Initialise common code.
4255 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
4356
4457 wfProfileIn( 'api.php' );
@@ -61,9 +74,9 @@
6275
6376 // Verify that the API has not been disabled
6477 if ( !$wgEnableAPI ) {
65 - echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
66 - echo '<pre><b>$wgEnableAPI=true;</b></pre>';
67 - die( 1 );
 78+ wfDie( 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php'
 79+ . '<pre><b>$wgEnableAPI=true;</b></pre>'
 80+ );
6881 }
6982
7083 // Selectively allow cross-site AJAX
@@ -131,7 +144,8 @@
132145 $_SERVER['HTTP_USER_AGENT']
133146 );
134147 $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';
135 - if ( $processor->getModule()->mustBePosted() ) {
 148+ $module = $processor->getModule();
 149+ if ( $module->mustBePosted() ) {
136150 $items[] = "action=" . $wgRequest->getVal( 'action' );
137151 } else {
138152 $items[] = wfArrayToCGI( $wgRequest->getValues() );
@@ -140,6 +154,8 @@
141155 wfDebug( "Logged API request to $wgAPIRequestLog\n" );
142156 }
143157
144 -// Shut down the database
145 -wfGetLBFactory()->shutdown();
 158+// Shut down the database. foo()->bar() syntax is not supported in PHP4: we won't ever actually
 159+// get here to worry about whether this should be = or =&, but the file has to parse properly.
 160+$lb = wfGetLBFactory();
 161+$lb->shutdown();
146162
Index: trunk/phase3/load.php
@@ -23,6 +23,19 @@
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 );
 32+}
 33+
 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+
2740 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
2841 wfProfileIn( 'load.php' );
2942
@@ -48,5 +61,7 @@
4962 wfProfileOut( 'load.php' );
5063 wfLogProfilingData();
5164
52 -// Shut down the database
53 -wfGetLBFactory()->shutdown();
 65+// Shut down the database. foo()->bar() syntax is not supported in PHP4, and this file
 66+// needs to *parse* in PHP4, although we'll never get down here to worry about = vs =&
 67+$lb = wfGetLBFactory();
 68+$lb->shutdown();
Index: trunk/phase3/includes/templates/NoLocalSettings.php
@@ -1,64 +0,0 @@
2 -<?php
3 -/**
4 - * Template used when there is no LocalSettings.php file
5 - *
6 - * @file
7 - * @ingroup Templates
8 - */
9 -
10 -if ( !isset( $wgVersion ) ) {
11 - $wgVersion = 'VERSION';
12 -}
13 -$script = $_SERVER['SCRIPT_NAME'];
14 -$path = pathinfo( $script, PATHINFO_DIRNAME ) . '/';
15 -$path = str_replace( '//', '/', $path );
16 -$ext = pathinfo( $script, PATHINFO_EXTENSION );
17 -
18 -# Check to see if the installer is running
19 -if ( !function_exists( 'session_name' ) ) {
20 - $installerStarted = false;
21 -} else {
22 - session_name( 'mw_installer_session' );
23 - $oldReporting = error_reporting( E_ALL & ~E_NOTICE );
24 - $success = session_start();
25 - error_reporting( $oldReporting );
26 - $installerStarted = ( $success && isset( $_SESSION['installData'] ) );
27 -}
28 -?>
29 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
30 -<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
31 - <head>
32 - <title>MediaWiki <?php echo htmlspecialchars( $wgVersion ) ?></title>
33 - <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
34 - <style type='text/css' media='screen'>
35 - html, body {
36 - color: #000;
37 - background-color: #fff;
38 - font-family: sans-serif;
39 - text-align: center;
40 - }
41 -
42 - h1 {
43 - font-size: 150%;
44 - }
45 - </style>
46 - </head>
47 - <body>
48 - <img src="<?php echo htmlspecialchars( $path ) ?>skins/common/images/mediawiki.png" alt='The MediaWiki logo' />
49 -
50 - <h1>MediaWiki <?php echo htmlspecialchars( $wgVersion ) ?></h1>
51 - <div class='error'>
52 - <p>LocalSettings.php not found.</p>
53 - <p>
54 - <?php
55 - if ( $installerStarted ) {
56 - echo( "Please <a href=\"" . htmlspecialchars( $path ) . "mw-config/index." . htmlspecialchars( $ext ) . "\"> complete the installation</a> and download LocalSettings.php." );
57 - } else {
58 - echo( "Please <a href=\"" . htmlspecialchars( $path ) . "mw-config/index." . htmlspecialchars( $ext ) . "\"> set up the wiki</a> first." );
59 - }
60 - ?>
61 - </p>
62 -
63 - </div>
64 - </body>
65 -</html>
Index: trunk/phase3/includes/templates/PHP4.php
@@ -1,102 +0,0 @@
2 -<?php
3 -/**
4 - * Template used when the installer detects that this is PHP 4
5 - *
6 - * @file
7 - * @ingroup Templates
8 - */
9 -
10 -if( !defined( 'MW_PHP4' ) ) {
11 - die( "Not an entry point.");
12 -}
13 -
14 -if( isset( $_SERVER['SCRIPT_NAME'] ) ) {
15 - // Probably IIS; doesn't set REQUEST_URI
16 - $scriptUrl = $_SERVER['SCRIPT_NAME'];
17 -} elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
18 - // We're trying SCRIPT_NAME first because it won't include PATH_INFO... hopefully
19 - $scriptUrl = $_SERVER['REQUEST_URI'];
20 -} else {
21 - $scriptUrl = '';
22 -}
23 -if ( preg_match( '!^(.*)/(mw-)?config/[^/]*.php$!', $scriptUrl, $m ) ) {
24 - $baseUrl = $m[1];
25 -} elseif ( preg_match( '!^(.*)/[^/]*.php$!', $scriptUrl, $m ) ) {
26 - $baseUrl = $m[1];
27 -} else {
28 - $baseUrl = dirname( $scriptUrl );
29 -}
30 -
31 -?>
32 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
33 -<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
34 - <head>
35 - <title>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?></title>
36 - <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
37 - <style type='text/css' media='screen'>
38 - html, body {
39 - color: #000;
40 - background-color: #fff;
41 - font-family: sans-serif;
42 - text-align: center;
43 - }
44 -
45 - p {
46 - text-align: left;
47 - margin-left: 2em;
48 - margin-right: 2em;
49 - }
50 -
51 - h1 {
52 - font-size: 150%;
53 - }
54 - </style>
55 - </head>
56 - <body>
57 - <img src="<?php echo htmlspecialchars( $baseUrl ) ?>/skins/common/images/mediawiki.png" alt='The MediaWiki logo' />
58 -
59 - <h1>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?></h1>
60 - <div class='error'>
61 -<p>
62 - MediaWiki requires PHP 5.2.3 or higher. You are running PHP
63 - <?php echo htmlspecialchars( phpversion() ); ?>.
64 -</p>
65 -<?php
66 -flush();
67 -/**
68 - * Test the *.php5 extension
69 - */
70 -$downloadOther = true;
71 -if ( $baseUrl ) {
72 - $testUrl = "$wgServer$baseUrl/php5.php5";
73 - if( function_exists( 'file_get_contents' ) ) {
74 - $errorLevel = error_reporting();
75 - error_reporting( $errorLevel & !E_WARNING );
76 -
77 - ini_set( 'allow_url_fopen', '1' );
78 - $s = file_get_contents( $testUrl );
79 -
80 - error_reporting( $errorLevel );
81 - }
82 -
83 - if ( strpos( $s, 'yes' ) !== false ) {
84 - $encUrl = htmlspecialchars( str_replace( '.php', '.php5', $scriptUrl ) );
85 - echo "<p>You may be able to use MediaWiki using a <a href=\"$encUrl\">.php5</a> file extension.</p>";
86 - $downloadOther = false;
87 - }
88 -}
89 -if ( $downloadOther ) {
90 -?>
91 -<p>Please consider
92 -<a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
93 -PHP 4 is at the end of its lifecycle and will not receive further security updates.</p>
94 -<p>If for some reason you really really need to run MediaWiki on PHP 4, you will need to
95 -<a href="http://www.mediawiki.org/wiki/Download">download version 1.6.x</a>
96 -from our website. </p>
97 -<?php
98 -}
99 -?>
100 -
101 - </div>
102 - </body>
103 -</html>
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -851,13 +851,20 @@
852852 }
853853
854854 /**
855 - * Print a simple message and die, returning nonzero to the shell if any.
856 - * Plain die() fails to return nonzero to the shell if you pass a string.
 855+ * Print an error message and die, returning nonzero to the shell if any. Plain die()
 856+ * fails to return nonzero to the shell if you pass a string. Entry points may customise
 857+ * this function to return a prettier error message, but implementations must not assume
 858+ * access to any of the usual MediaWiki infrastructure (AutoLoader, localisation, database,
 859+ * etc). This should not be called directly once $wgFullyInitialised is set; instead,
 860+ * throw an exception and let Exception.php handle whether or not it's possible to show
 861+ * a prettier error.
857862 * @param $msg String
858863 */
859 -function wfDie( $msg = '' ) {
860 - echo $msg;
861 - die( 1 );
 864+if( !function_exists( 'wfDie' ) ){
 865+ function wfDie( $msg = '' ) {
 866+ echo $msg;
 867+ die( 1 );
 868+ }
862869 }
863870
864871 /**
Index: trunk/phase3/includes/Exception.php
@@ -236,32 +236,44 @@
237237 header( 'Pragma: nocache' );
238238 }
239239
240 - $title = Html::element( 'title', null, $this->getPageTitle() );
 240+ $head = Html::element( 'title', null, $this->getPageTitle() ) . "\n";
 241+ $head .= Html::inlineStyle( <<<ENDL
 242+ body {
 243+ color: #000;
 244+ background-color: #fff;
 245+ font-family: sans-serif;
 246+ padding: 2em;
 247+ text-align: center;
 248+ }
 249+ p, img, h1 {
 250+ text-align: left;
 251+ margin: 0.5em 0;
 252+ }
 253+ h1 {
 254+ font-size: 120%;
 255+ }
 256+ENDL
 257+ );
241258
242 - $left = 'left';
243 - $right = 'right';
244259 $dir = 'ltr';
245260 $code = 'en';
246261
247262 if ( $wgLang instanceof Language ) {
248 - $left = $wgLang->alignStart();
249 - $right = $wgLang->alignEnd();
250263 $dir = $wgLang->getDir();
251264 $code = $wgLang->getCode();
252265 }
253266
254267 $header = Html::element( 'img', array(
255268 'src' => $wgLogo,
256 - 'style' => "float: $left; margin-$right: 1em;",
257269 'alt' => '' ), $this->getPageTitle() );
258270
259271 $attribs = array( 'dir' => $dir, 'lang' => $code );
260272
261273 return
262274 Html::htmlHeader( $attribs ) .
263 - Html::rawElement( 'head', null, $title ) . "\n".
 275+ Html::rawElement( 'head', null, $head ) . "\n".
264276 Html::openElement( 'body' ) . "\n" .
265 - Html::rawElement( 'h1', null, $header ) . "\n";
 277+ $header . "\n";
266278 }
267279
268280 /**
@@ -338,6 +350,7 @@
339351
340352 if ( $e instanceof MWException ) {
341353 try {
 354+ // Try and show the exception prettily, with the normal skin infrastructure
342355 $e->report();
343356 } catch ( Exception $e2 ) {
344357 // Exception occurred from within exception handler
@@ -359,7 +372,7 @@
360373 if ( $cmdLine ) {
361374 wfPrintError( $message );
362375 } else {
363 - echo nl2br( htmlspecialchars( $message ) ) . "\n";
 376+ wfDie( htmlspecialchars( $message ) ) . "\n";
364377 }
365378 }
366379 } else {
@@ -373,7 +386,7 @@
374387 if ( $cmdLine ) {
375388 wfPrintError( $message );
376389 } else {
377 - echo nl2br( htmlspecialchars( $message ) ) . "\n";
 390+ wfDie( htmlspecialchars( $message ) ) . "\n";
378391 }
379392 }
380393 }
Index: trunk/phase3/includes/db/Database.php
@@ -2955,7 +2955,7 @@
29562956
29572957 $this->error = Html::element( 'span', array( 'dir' => 'ltr' ), $this->error );
29582958
2959 - $noconnect = "<p><strong>$sorry</strong><br />$again</p><p><small>$info</small></p>";
 2959+ $noconnect = "<h1>$sorry</h1><p>$again</p><p><small>$info</small></p>";
29602960 $text = str_replace( '$1', $this->error, $noconnect );
29612961
29622962 if ( $wgShowDBErrorBacktrace ) {
Index: trunk/phase3/includes/WebStart.php
@@ -100,16 +100,6 @@
101101 # Load up some global defines.
102102 require_once( "$IP/includes/Defines.php" );
103103
104 - # Check for PHP 5
105 - if ( !function_exists( 'version_compare' )
106 - || version_compare( phpversion(), '5.0.0' ) < 0
107 - ) {
108 - define( 'MW_PHP4', '1' );
109 - require( "$IP/includes/DefaultSettings.php" );
110 - require( "$IP/includes/templates/PHP4.php" );
111 - exit;
112 - }
113 -
114104 # Start the autoloader, so that extensions can derive classes from core files
115105 require_once( "$IP/includes/AutoLoader.php" );
116106 }
@@ -126,13 +116,31 @@
127117 if ( !defined( 'MW_CONFIG_FILE' ) ) {
128118 define('MW_CONFIG_FILE', MWInit::interpretedPath( 'LocalSettings.php' ) );
129119 }
130 -
 120+
131121 # LocalSettings.php is the per site customization file. If it does not exist
132122 # the wiki installer needs to be launched or the generated file uploaded to
133123 # the root wiki directory
134124 if( !file_exists( MW_CONFIG_FILE ) ) {
135 - require_once( "$IP/includes/templates/NoLocalSettings.php" );
136 - die();
 125+ $script = $_SERVER['SCRIPT_NAME'];
 126+ $path = htmlspecialchars( str_replace( '//', '/', pathinfo( $script, PATHINFO_DIRNAME ) ) );
 127+ $ext = htmlspecialchars( pathinfo( $script, PATHINFO_EXTENSION ) );
 128+
 129+ # Check to see if the installer is running
 130+ if ( !function_exists( 'session_name' ) ) {
 131+ $installerStarted = false;
 132+ } else {
 133+ session_name( 'mw_installer_session' );
 134+ $oldReporting = error_reporting( E_ALL & ~E_NOTICE );
 135+ $success = session_start();
 136+ error_reporting( $oldReporting );
 137+ $installerStarted = ( $success && isset( $_SESSION['installData'] ) );
 138+ }
 139+
 140+ $please = $installerStarted
 141+ ? "Please <a href=\"$path/mw-config/index.$ext\"> complete the installation</a> and download LocalSettings.php."
 142+ : "Please <a href=\"$path/mw-config/index.$ext\"> set up the wiki</a> first.";
 143+
 144+ wfDie( "<p>LocalSettings.php not found.</p><p>$please</p>" );
137145 }
138146
139147 # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)

Follow-up revisions

RevisionCommit summaryAuthorDate
r87628(bug 28834) Restore nl2br() wrappers removed in r85918.happy-melon13:24, 7 May 2011
r87630Follow-up r85918:...happy-melon14:01, 7 May 2011
r89624* Restored the page shown when LocalSettings.php is missing to how it was bef...tstarling05:11, 7 June 2011
r90338As discussed in r85918 CR. Move everything from wfIndexMain() at index.php to...platonides14:50, 18 June 2011
r91602Clean up the mess that is wfDie (resolves r85918). wfDie() doesn't exist anym...demon21:01, 6 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85327The beginnings of HipHop compiled mode support. It works now for parser cache...tstarling12:59, 4 April 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   18:01, 5 May 2011

Appears to have caused bug 28834 with the change to Exception.php's wfReportException() removing an nl2br() call and thus removing line breaks from the exception stack trace.

#Comment by Happy-melon (talk | contribs)   15:26, 7 May 2011

Fixed in r87628.

#Comment by Tim Starling (talk | contribs)   04:57, 7 June 2011

Appears to break HipHop support. Please do not define multiple functions with the same name, even if they are in different files. There are lots of other ways to do this.

#Comment by 😂 (talk | contribs)   05:01, 7 June 2011

I had already noticed this, I just hadn't worked on a fix for it yet. To be honest, I don't really like this approach at all. wfDie() means very different things, depending on the context.

  • Dying in maintenance scripts - New maintenance scripts can just use error() with the second parameter. Older ones should be updated to subclass Maintenance anyway.
  • Catastrophic errors like PHP version too low, API disabled, or missing LocalSettings.
  • Some old junk in Exception.php

Since wfDie() isn't used outside of core anywhere, I'd suggest we just remove it entirely or at least severely limit the use-cases.

#Comment by Tim Starling (talk | contribs)   05:53, 7 June 2011

In most places where you might want to use this new variant of wfDie(), you can throw an exception instead. Exceptions already have the infrastructure for formatting error messages in various ways depending on the entry point. If there's some problem with that infrastructure, then it should be fixed rather than duplicated.

The old uses of wfDie() are just a shortcut for "echo $msg;die(-1);", they reflect Brion's disgust at PHP when he found out that die($msg) doesn't do that. See r12660. I removed most instances from the core in r14631 in favour of exceptions.

#Comment by Happy-melon (talk | contribs)   09:09, 7 June 2011

Certainly pretty much all errors should be triggered by raising an exception. The use of wfDie() is to define what the exception should do with it. Before, IIRC, exceptions triggered in load.php outputted HTML into what should be a CSS/JS environment, for instance, because Exception.php didn't know what context it was echoing into (still doesn't, for that matter). The uses of wfDie() in Exception.php are not old junk, they're brand new in this revision.

How does wfDie() have "different meanings depending on the context"? wfDie() means "I can't handle this any more, get me out of here"; in a fashion which is entry-point-dependent, doesn't require access to the autoloader, and preferably which works on as many environments as possible, such as PHP4.

#Comment by Tim Starling (talk | contribs)   13:25, 7 June 2011

I suggest restoring wfDie() back to how it was before, and thinking of a new name for what you want to do.

#Comment by Happy-melon (talk | contribs)   09:25, 7 June 2011

It would be helpful if this, like the other issues affecting HipHop support, could be documented at HipHop or somesuch. What is the way to achieve this? Would a structure like

// load.php
define( 'MW_ENTRY_POINT', 'LOAD' );

...

if( MW_ENTRY_POINT == 'LOAD' ) {
    function wfDie( $msg ){ ... }
}

Work?

#Comment by Tim Starling (talk | contribs)   13:22, 7 June 2011

I thought I documented it already, at HipHop#Declarations. Let me know if there's something unclear about that page.

No, it won't work. One thing that would work would be to have a set of exception formatting classes in an autoloaded class file, then set the class name to use via a constant, global variable or static member accessor function like Exception::setFormattingClass(). That won't work for PHP 4, but I'm pretty sure I broke PHP 4 parsing in r88959. So maybe some more robust solution is needed for PHP 4, like say moving the bulk of the code out of the entry points and restoring PHP4.php.

PHP4.php was better than what you have here anyway, since it was able to detect the situation where a .php5 extension will work. Or at least it did until the entry points were broken again.

#Comment by 😂 (talk | contribs)   15:25, 7 June 2011

The other option is forgetting about PHP4.

#Comment by Tim Starling (talk | contribs)   22:56, 7 June 2011

Well yeah, specifically, documenting the fact that parse errors mean you have to upgrade to PHP 5 and leaving it at that. The reason I did some work on PHP 4 error messages in r41713 is because we were having support requests from people who didn't know what the parse errors meant.

#Comment by Platonides (talk | contribs)   23:02, 7 June 2011

> I'm pretty sure I broke PHP 4 parsing in r88959.

You did r1=88958&r2=88959. PHP 4 doesn't like try/catch.

#Comment by Brion VIBBER (talk | contribs)   23:04, 7 June 2011

I'd say let's either drop the PHP 4 checks entirely, or move the actual code out of the entry points and require() through to the 'real' code, so we don't all keep accidentally checking things in that break the PHP 4 parser. :)

#Comment by Platonides (talk | contribs)   23:08, 7 June 2011

I had already looked at wfIndexMain(), I think it should be pieced and moved into MediaWiki class. Also, it is broken for $wgArticle currently.

#Comment by Tim Starling (talk | contribs)   23:13, 7 June 2011

Sounds good. Can you also rename the MediaWiki class to MainEntry or something while you're at it? It's always been a helper for index.php, and has very little to do with the rest of MediaWiki.

#Comment by Happy-melon (talk | contribs)   23:42, 7 June 2011

That's exactly what I did! But as Tim's pointed out elsewhere, most uses of require() breaks HipHop unless it's run through MWInit::compiledPath(), and you can't get that without loading WebStart, which is not PHP4-compatible... :( So you can't really move very much of what's in index.php deeper into the callstack, because you still have to leave enough infrastructure to be able to correctly find the deeper file.

#Comment by Brion VIBBER (talk | contribs)   23:47, 7 June 2011

Poop. My vote then goes towards just killing all the PHP 4 stuff and documenting 'if you get parse errors, it's cause you're running year-2000 tech still, upgrade silly' :D

Status & tagging log