Web installer: check for low PHP versions before executing
authorSergio Santoro <santoro.srg@gmail.com>
Mon, 7 Jul 2014 10:48:11 +0000 (12:48 +0200)
committerSergio Santoro <santoro.srg@gmail.com>
Tue, 8 Jul 2014 08:19:02 +0000 (10:19 +0200)
Web installer was not checking for unsupported PHP versions.
In those cases the script should terminate or the
installation will break (e.g. syntax errors for PHP4).

Installer::doEnvironmentChecks() no longer checks for PHP
version since it has already been done by the entry scripts
(both in cli and web modes)

Installer::MINIMUM_PHP_VERSION has been removed since it is
no longer used.

Message config-env-php-toolow is no longer used and it has
been removed

Change-Id: I9227868bd2bd4e13bad6b95ad581be3ada71c94e

includes/PHPVersionError.php
includes/installer/Installer.php
includes/installer/i18n/en.json
mw-config/index.php

index 0fb3952..e475f0b 100644 (file)
@@ -32,6 +32,7 @@
  *   - index.php
  *   - load.php
  *   - api.php
+ *   - mw-config/index.php
  *   - cli
  *
  * @note Since we can't rely on anything, the minimum PHP versions and MW current
@@ -50,10 +51,15 @@ function wfPHPVersionError( $type ) {
                $finalOutput = "You are using PHP version $phpVersion "
                        . "but MediaWiki $mwVersion needs PHP $minimumVersionPHP or higher. ABORTING.\n"
                        . "Check if you have a newer php executable with a different name, such as php5.\n";
-       } elseif ( $type == 'index.php' ) {
+       } elseif ( $type == 'index.php' || $type == 'mw-config/index.php' ) {
                $pathinfo = pathinfo( $_SERVER['SCRIPT_NAME'] );
+               if ( $type == 'mw-config/index.php' ) {
+                       $dirname = dirname( $pathinfo['dirname'] );
+               } else {
+                       $dirname = $pathinfo['dirname'];
+               }
                $encLogo = htmlspecialchars(
-                       str_replace( '//', '/', $pathinfo['dirname'] . '/' ) .
+                       str_replace( '//', '/', $dirname . '/' ) .
                        'skins/common/images/mediawiki.png'
                );
 
index 540b647..6fbd2f5 100644 (file)
@@ -38,9 +38,6 @@
  */
 abstract class Installer {
 
-       // This is the absolute minimum PHP version we can support
-       const MINIMUM_PHP_VERSION = '5.3.2';
-
        /**
         * The oldest version of PCRE we can support.
         *
@@ -429,25 +426,17 @@ abstract class Installer {
         * @return Status
         */
        public function doEnvironmentChecks() {
-               $phpVersion = phpversion();
-               if ( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
-                       $this->showMessage( 'config-env-php', $phpVersion );
-                       $good = true;
-               } else {
-                       $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION );
-                       $good = false;
-               }
+               // Php version has already been checked by entry scripts
+               // Show message here for information purposes
+               $this->showMessage( 'config-env-php', phpversion() );
 
+               $good = true;
                // Must go here because an old version of PCRE can prevent other checks from completing
-               if ( $good ) {
-                       list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
-                       if ( version_compare( $pcreVersion, self::MINIMUM_PCRE_VERSION, '<' ) ) {
-                               $this->showError( 'config-pcre-old', self::MINIMUM_PCRE_VERSION, $pcreVersion );
-                               $good = false;
-                       }
-               }
-
-               if ( $good ) {
+               list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 );
+               if ( version_compare( $pcreVersion, self::MINIMUM_PCRE_VERSION, '<' ) ) {
+                       $this->showError( 'config-pcre-old', self::MINIMUM_PCRE_VERSION, $pcreVersion );
+                       $good = false;
+               } else {
                        foreach ( $this->envChecks as $check ) {
                                $status = $this->$check();
                                if ( $status === false ) {
index b19bdc0..bc72ac5 100644 (file)
@@ -44,7 +44,6 @@
        "config-env-good": "The environment has been checked.\nYou can install MediaWiki.",
        "config-env-bad": "The environment has been checked.\nYou cannot install MediaWiki.",
        "config-env-php": "PHP $1 is installed.",
-       "config-env-php-toolow": "PHP $1 is installed.\nHowever, MediaWiki requires PHP $2 or higher.",
        "config-unicode-using-utf8": "Using Brion Vibber's utf8_normalize.so for Unicode normalization.",
        "config-unicode-using-intl": "Using the [http://pecl.php.net/intl intl PECL extension] for Unicode normalization.",
        "config-unicode-pure-php-warning": "<strong>Warning:</strong> The [http://pecl.php.net/intl intl PECL extension] is not available to handle Unicode normalization, falling back to slow pure-PHP implementation.\nIf you run a high-traffic site, you should read a little on [//www.mediawiki.org/wiki/Special:MyLanguage/Unicode_normalization_considerations Unicode normalization].",
index 56c1308..9e83c54 100644 (file)
  * @file
  */
 
+// Bail if PHP is too low
+if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.3.2' ) < 0 ) {
+       // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+
+       require dirname( dirname( __FILE__ ) ) . '/includes/PHPVersionError.php';
+       wfPHPVersionError( 'mw-config/index.php' );
+}
+
 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
 define( 'MEDIAWIKI_INSTALL', true );