r87637 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87636‎ | r87637 | r87638 >
Date:15:16, 7 May 2011
Author:happy-melon
Status:reverted (Comments)
Tags:
Comment:
Centralise the minimum-required-php-version in a MW_MIN_PHP_VERSION constant in Defines.php. This requires loading Defines.php before the PHP4 version checks, so include a big note reminding people not to include anything other than vanilla define() statements in there.

I have a sneaking suspicion that including Defines.php in the entry points might not play nicely with HipHop, but I can't test it (wrong OS).
Modified paths:
  • /trunk/phase3/api.php (modified) (history)
  • /trunk/phase3/includes/Defines.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)
  • /trunk/phase3/load.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/install.php (modified) (history)
  • /trunk/phase3/maintenance/update.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/update.php
@@ -25,8 +25,12 @@
2626 * @ingroup Maintenance
2727 */
2828
29 -if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.2.3' ) < 0 ) ) {
30 - echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.2.3 or higher. ABORTING.\n" .
 29+// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION
 30+require_once( dirname( __FILE__ ) . '/includes/Defines.php' );
 31+
 32+if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) ) {
 33+ echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP " .
 34+ MW_MIN_PHP_VERSION . "or higher. ABORTING.\n" .
3135 "Check if you have a newer php executable with a different name, such as php5.\n";
3236 die( 1 );
3337 }
Index: trunk/phase3/maintenance/install.php
@@ -20,9 +20,13 @@
2121 * @see wfWaitForSlaves()
2222 */
2323
24 -if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.2.3' ) < 0 ) ) {
25 - echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.2.3 or higher. ABORTING.\n" .
26 - "Check if you have a newer php executable with a different name, such as php5.\n";
 24+// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION
 25+require_once( dirname( __FILE__ ) . '/includes/Defines.php' );
 26+
 27+if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) ) {
 28+ echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP " .
 29+ MW_MIN_PHP_VERSION . " or higher. ABORTING.\n" .
 30+ "Check if you have a newer php executable with a different name, such as php5.\n";
2731 die( 1 );
2832 }
2933
Index: trunk/phase3/maintenance/Maintenance.php
@@ -20,6 +20,9 @@
2121 * @defgroup Maintenance Maintenance
2222 */
2323
 24+// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION
 25+require_once( dirname( __FILE__ ) . '/includes/Defines.php' );
 26+
2427 // Define this so scripts can easily find doMaintenance.php
2528 define( 'RUN_MAINTENANCE_IF_MAIN', dirname( __FILE__ ) . '/doMaintenance.php' );
2629 define( 'DO_MAINTENANCE', RUN_MAINTENANCE_IF_MAIN ); // original name, harmless
@@ -27,10 +30,10 @@
2831 $maintClass = false;
2932
3033 // 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 " .
 34+if ( version_compare( PHP_VERSION, MW_MIN_PHP_VERSION ) < 0 ) {
 35+ die ( "Sorry! This version of MediaWiki requires PHP " . MW_MIN_PHP_VERSION . "; you are running " .
3336 PHP_VERSION . ".\n\n" .
34 - "If you are sure you already have PHP 5.2.3 or higher installed, it may be\n" .
 37+ "If you are sure you already have PHP " . MW_MIN_PHP_VERSION . " or higher installed, it may be\n" .
3538 "installed in a different path from PHP " . PHP_VERSION . ". Check with your system\n" .
3639 "administrator.\n" );
3740 }
Index: trunk/phase3/includes/Defines.php
@@ -1,6 +1,8 @@
22 <?php
33 /**
4 - * A few constants that might be needed during LocalSettings.php.
 4+ * Global constants declarations. Do *NOT* include *anything* in this file which is
 5+ * not a define() declaration; this file is included in all sorts of scopes and must
 6+ * be parseable by PHP 4 without errors.
57 *
68 * Note: these constants must all be resolvable at compile time by HipHop,
79 * since this file will not be executed during request startup for a compiled
@@ -15,6 +17,14 @@
1618 define( 'MW_VERSION', '1.19alpha' );
1719 define( 'MW_SPECIALPAGE_VERSION', 2 );
1820
 21+/**
 22+ * Minimum version of PHP required to run; entry points will die
 23+ * if they try to run on a version older than this
 24+ */
 25+define( 'MW_MIN_PHP_VERSION', '5.2.3' );
 26+
 27+/**@}*/
 28+
1929 /**@{
2030 * Database related constants
2131 */
Index: trunk/phase3/includes/installer/Installer.php
@@ -24,7 +24,8 @@
2525 abstract class Installer {
2626
2727 // This is the absolute minimum PHP version we can support
28 - const MINIMUM_PHP_VERSION = '5.2.3';
 28+ // @deprecated since 1.18
 29+ const MINIMUM_PHP_VERSION = MW_MIN_PHP_VERSION;
2930
3031 /**
3132 * @var array
@@ -378,11 +379,11 @@
379380 */
380381 public function doEnvironmentChecks() {
381382 $phpVersion = phpversion();
382 - if( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
 383+ if( version_compare( $phpVersion, MW_MIN_PHP_VERSION, '>=' ) ) {
383384 $this->showMessage( 'config-env-php', $phpVersion );
384385 $good = true;
385386 } else {
386 - $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION );
 387+ $this->showMessage( 'config-env-php-toolow', $phpVersion, MW_MIN_PHP_VERSION );
387388 $good = false;
388389 }
389390
Index: trunk/phase3/index.php
@@ -36,14 +36,18 @@
3737 * @file
3838 */
3939
 40+// Load global constants, including MW_VERSION and MW_MIN_PHP_VERSION
 41+require_once( dirname( __FILE__ ) . '/includes/Defines.php' );
 42+
4043 // Bail on old versions of PHP. Pretty much every other file in the codebase
4144 // has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4.
4245 // 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.3' ) < 0 ) {
 46+if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) {
4447 $phpversion = htmlspecialchars( phpversion() );
 48+ $reqVersion = htmlspecialchars( MW_MIN_PHP_VERSION );
4549 $errorMsg = <<<ENDL
4650 <p>
47 - MediaWiki requires PHP 5.2.3 or higher. You are running PHP $phpversion.
 51+ MediaWiki requires PHP $reqVersion or higher. You are running PHP $phpversion.
4852 </p>
4953 <p>
5054 Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
@@ -160,11 +164,8 @@
161165 * @param $errorMsg String fully-escaped HTML
162166 */
163167 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 - : '';
 168+ global $wgLogo;
 169+ $version = htmlspecialchars( MW_VERSION );
169170 $logo = isset( $wgLogo ) && $wgLogo
170171 ? $wgLogo
171172 : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png';
Index: trunk/phase3/api.php
@@ -37,6 +37,9 @@
3838 // So extensions (and other code) can check whether they're running in API mode
3939 define( 'MW_API', true );
4040
 41+// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION
 42+require_once( dirname( __FILE__ ) . '/includes/Defines.php' );
 43+
4144 // We want a plain message on catastrophic errors that machines can identify
4245 function wfDie( $msg = '' ) {
4346 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
@@ -45,9 +48,10 @@
4649 }
4750
4851 // 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+if( !function_exists( 'version_compare' ) || version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ){
 53+ $version = htmlspecialchars( MW_VERSION );
 54+ $phpversion = htmlspecialchars( MW_MIN_PHP_VERSION );
 55+ wfDie( "MediaWiki $version requires at least PHP version $phpversion." );
5256 }
5357
5458 // Initialise common code.
Index: trunk/phase3/load.php
@@ -30,10 +30,14 @@
3131 die( 1 );
3232 }
3333
 34+// Load global constants, including MW_VERSION and MW_MIN_PHP_VERSION
 35+require_once( dirname( __FILE__ ) . '/includes/Defines.php' );
 36+
3437 // 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+if( !function_exists( 'version_compare' ) || version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ){
 39+ $version = htmlspecialchars( MW_VERSION );
 40+ $phpversion = htmlspecialchars( MW_MIN_PHP_VERSION );
 41+ wfDie( "MediaWiki $version requires at least PHP version $phpversion." );
3842 }
3943
4044 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r87643Follow-up r87637: the terrors of copy-and-paste.happy-melon15:37, 7 May 2011
r88176Revert r87635, r87637, r87639, r87643 (MW_MIN_PHP_VERSION etc.): breaks HipHo...tstarling13:21, 15 May 2011
r91192Move $wgFeedClasses to DefaultSettings where they belong. This has been bothe...demon18:16, 30 June 2011

Comments

#Comment by Siebrand (talk | contribs)   15:30, 7 May 2011

PHP Warning: require_once(/www/w/maintenance/includes/Defines.php): failed to open stream: No such file or directory in /www/w/maintenance/Maintenance.php on line 24

PHP Fatal error: require_once(): Failed opening required '/www/w/maintenance/includes/Defines.php' (include_path='.:/usr/share/php:/usr/share/pear') in /www/w/maintenance/Maintenance.php on line 24

Status & tagging log