Centralise the minimum-required-php-version in a MW_MIN_PHP_VERSION constant in Defin...
authorHappy-melon <happy-melon@users.mediawiki.org>
Sat, 7 May 2011 15:16:01 +0000 (15:16 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Sat, 7 May 2011 15:16:01 +0000 (15:16 +0000)
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
includes/Defines.php
includes/installer/Installer.php
index.php
load.php
maintenance/Maintenance.php
maintenance/install.php
maintenance/update.php

diff --git a/api.php b/api.php
index f55f853..1d12e03 100644 (file)
--- 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.
index c226e55..3ca7dcb 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * A few constants that might be needed during LocalSettings.php.
+ * Global constants declarations.  Do *NOT* include *anything* in this file which is
+ * not a define() declaration; this file is included in all sorts of scopes and must
+ * be parseable by PHP 4 without errors.
  *
  * Note: these constants must all be resolvable at compile time by HipHop, 
  * since this file will not be executed during request startup for a compiled
 define( 'MW_VERSION', '1.19alpha' );
 define( 'MW_SPECIALPAGE_VERSION', 2 );
 
+/**
+ * Minimum version of PHP required to run; entry points will die
+ * if they try to run on a version older than this
+ */
+define( 'MW_MIN_PHP_VERSION', '5.2.3' );
+
+/**@}*/
+
 /**@{
  * Database related constants
  */
index f8de893..8ece8b9 100644 (file)
@@ -24,7 +24,8 @@
 abstract class Installer {
 
        // This is the absolute minimum PHP version we can support
-       const MINIMUM_PHP_VERSION = '5.2.3';
+       // @deprecated since 1.18
+       const MINIMUM_PHP_VERSION = MW_MIN_PHP_VERSION;
 
        /**
         * @var array
@@ -378,11 +379,11 @@ abstract class Installer {
         */
        public function doEnvironmentChecks() {
                $phpVersion = phpversion();
-               if( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
+               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;
                }
 
index ff50131..d203f75 100644 (file)
--- a/index.php
+++ b/index.php
  * @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 = <<<ENDL
                <p>
-                       MediaWiki requires PHP 5.2.3 or higher. You are running PHP $phpversion.
+                       MediaWiki requires PHP $reqVersion or higher. You are running PHP $phpversion.
                </p>
                <p>
                        Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
@@ -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';
index 7fff7c4..ff6d9d7 100644 (file)
--- 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' );
index 9d4da81..3e3def8 100644 (file)
@@ -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" );
 }
index 57e669d..6f279f0 100644 (file)
  * @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 );
 }
 
index ede6ebe..ab695c1 100644 (file)
  * @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 );
 }