From c2040515ef936ddc6e5ede0d231a8cf60e10d758 Mon Sep 17 00:00:00 2001 From: Sergio Santoro Date: Mon, 7 Jul 2014 12:48:11 +0200 Subject: [PATCH] Web installer: check for low PHP versions before executing 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 | 10 ++++++++-- includes/installer/Installer.php | 29 +++++++++-------------------- includes/installer/i18n/en.json | 1 - mw-config/index.php | 7 +++++++ 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/includes/PHPVersionError.php b/includes/PHPVersionError.php index 0fb3952bd4..e475f0b862 100644 --- a/includes/PHPVersionError.php +++ b/includes/PHPVersionError.php @@ -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' ); diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 540b647dac..6fbd2f5b2a 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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 ) { diff --git a/includes/installer/i18n/en.json b/includes/installer/i18n/en.json index b19bdc0c6a..bc72ac536b 100644 --- a/includes/installer/i18n/en.json +++ b/includes/installer/i18n/en.json @@ -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": "Warning: 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].", diff --git a/mw-config/index.php b/mw-config/index.php index 56c1308956..9e83c54644 100644 --- a/mw-config/index.php +++ b/mw-config/index.php @@ -20,6 +20,13 @@ * @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 ); -- 2.20.1