From 7055add7990fd1fd23d4a58572582cf97839614d Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Sat, 7 May 2011 15:16:01 +0000 Subject: [PATCH] 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). --- api.php | 10 +++++++--- includes/Defines.php | 12 +++++++++++- includes/installer/Installer.php | 7 ++++--- index.php | 15 ++++++++------- load.php | 10 +++++++--- maintenance/Maintenance.php | 9 ++++++--- maintenance/install.php | 10 +++++++--- maintenance/update.php | 8 ++++++-- 8 files changed, 56 insertions(+), 25 deletions(-) diff --git a/api.php b/api.php index f55f85361a..1d12e03f09 100644 --- a/api.php +++ b/api.php @@ -37,6 +37,9 @@ // So extensions (and other code) can check whether they're running in API mode define( 'MW_API', true ); +// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION +require_once( dirname( __FILE__ ) . '/includes/Defines.php' ); + // We want a plain message on catastrophic errors that machines can identify function wfDie( $msg = '' ) { header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 ); @@ -45,9 +48,10 @@ function wfDie( $msg = '' ) { } // Die on unsupported PHP versions -if( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ){ - $version = htmlspecialchars( $wgVersion ); - wfDie( "MediaWiki $version requires at least PHP version 5.2.3." ); +if( !function_exists( 'version_compare' ) || version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ){ + $version = htmlspecialchars( MW_VERSION ); + $phpversion = htmlspecialchars( MW_MIN_PHP_VERSION ); + wfDie( "MediaWiki $version requires at least PHP version $phpversion." ); } // Initialise common code. diff --git a/includes/Defines.php b/includes/Defines.php index c226e5569a..3ca7dcb366 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -1,6 +1,8 @@ =' ) ) { + if( version_compare( $phpVersion, MW_MIN_PHP_VERSION, '>=' ) ) { $this->showMessage( 'config-env-php', $phpVersion ); $good = true; } else { - $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION ); + $this->showMessage( 'config-env-php-toolow', $phpVersion, MW_MIN_PHP_VERSION ); $good = false; } diff --git a/index.php b/index.php index ff50131e3d..d203f755a6 100644 --- a/index.php +++ b/index.php @@ -36,14 +36,18 @@ * @file */ +// Load global constants, including MW_VERSION and MW_MIN_PHP_VERSION +require_once( dirname( __FILE__ ) . '/includes/Defines.php' ); + // Bail on old versions of PHP. Pretty much every other file in the codebase // has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in PHP 4. // Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and 5.1, respectively. -if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ) { +if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) { $phpversion = htmlspecialchars( phpversion() ); + $reqVersion = htmlspecialchars( MW_MIN_PHP_VERSION ); $errorMsg = << - MediaWiki requires PHP 5.2.3 or higher. You are running PHP $phpversion. + MediaWiki requires PHP $reqVersion or higher. You are running PHP $phpversion.

Please consider upgrading your copy of PHP. @@ -160,11 +164,8 @@ $mediaWiki->restInPeace(); * @param $errorMsg String fully-escaped HTML */ function wfDie( $errorMsg ){ - // Use the version set in DefaultSettings if possible, but don't rely on it - global $wgVersion, $wgLogo; - $version = isset( $wgVersion ) && $wgVersion - ? htmlspecialchars( $wgVersion ) - : ''; + global $wgLogo; + $version = htmlspecialchars( MW_VERSION ); $logo = isset( $wgLogo ) && $wgLogo ? $wgLogo : 'http://upload.wikimedia.org/wikipedia/commons/1/1c/MediaWiki_logo.png'; diff --git a/load.php b/load.php index 7fff7c4991..ff6d9d7fef 100644 --- a/load.php +++ b/load.php @@ -30,10 +30,14 @@ function wfDie( $msg = '' ) { die( 1 ); } +// Load global constants, including MW_VERSION and MW_MIN_PHP_VERSION +require_once( dirname( __FILE__ ) . '/includes/Defines.php' ); + // Die on unsupported PHP versions -if( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ){ - $version = htmlspecialchars( $wgVersion ); - wfDie( "MediaWiki $version requires at least PHP version 5.2.3." ); +if( !function_exists( 'version_compare' ) || version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ){ + $version = htmlspecialchars( MW_VERSION ); + $phpversion = htmlspecialchars( MW_MIN_PHP_VERSION ); + wfDie( "MediaWiki $version requires at least PHP version $phpversion." ); } require ( dirname( __FILE__ ) . '/includes/WebStart.php' ); diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 9d4da81873..3e3def8f29 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -20,6 +20,9 @@ * @defgroup Maintenance Maintenance */ +// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION +require_once( dirname( __FILE__ ) . '/includes/Defines.php' ); + // Define this so scripts can easily find doMaintenance.php define( 'RUN_MAINTENANCE_IF_MAIN', dirname( __FILE__ ) . '/doMaintenance.php' ); define( 'DO_MAINTENANCE', RUN_MAINTENANCE_IF_MAIN ); // original name, harmless @@ -27,10 +30,10 @@ define( 'DO_MAINTENANCE', RUN_MAINTENANCE_IF_MAIN ); // original name, harmless $maintClass = false; // Make sure we're on PHP5 or better -if ( version_compare( PHP_VERSION, '5.2.3' ) < 0 ) { - die ( "Sorry! This version of MediaWiki requires PHP 5.2.3; you are running " . +if ( version_compare( PHP_VERSION, MW_MIN_PHP_VERSION ) < 0 ) { + die ( "Sorry! This version of MediaWiki requires PHP " . MW_MIN_PHP_VERSION . "; you are running " . PHP_VERSION . ".\n\n" . - "If you are sure you already have PHP 5.2.3 or higher installed, it may be\n" . + "If you are sure you already have PHP " . MW_MIN_PHP_VERSION . " or higher installed, it may be\n" . "installed in a different path from PHP " . PHP_VERSION . ". Check with your system\n" . "administrator.\n" ); } diff --git a/maintenance/install.php b/maintenance/install.php index 57e669d178..6f279f0da3 100644 --- a/maintenance/install.php +++ b/maintenance/install.php @@ -20,9 +20,13 @@ * @see wfWaitForSlaves() */ -if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.2.3' ) < 0 ) ) { - echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.2.3 or higher. ABORTING.\n" . - "Check if you have a newer php executable with a different name, such as php5.\n"; +// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION +require_once( dirname( __FILE__ ) . '/includes/Defines.php' ); + +if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) ) { + echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP " . + MW_MIN_PHP_VERSION . " or higher. ABORTING.\n" . + "Check if you have a newer php executable with a different name, such as php5.\n"; die( 1 ); } diff --git a/maintenance/update.php b/maintenance/update.php index ede6ebe4aa..ab695c1849 100644 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -25,8 +25,12 @@ * @ingroup Maintenance */ -if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.2.3' ) < 0 ) ) { - echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.2.3 or higher. ABORTING.\n" . +// Include global constants, including MW_VERSION and MW_MIN_PHP_VERSION +require_once( dirname( __FILE__ ) . '/includes/Defines.php' ); + +if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), MW_MIN_PHP_VERSION ) < 0 ) ) { + echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP " . + MW_MIN_PHP_VERSION . "or higher. ABORTING.\n" . "Check if you have a newer php executable with a different name, such as php5.\n"; die( 1 ); } -- 2.20.1