// @codingStandardsIgnoreFile Generic.Files.LineLength
// @codingStandardsIgnoreFile MediaWiki.Usage.DirUsage.FunctionFound
/**
- * Check PHP Version, as well as for composer dependencies in entry points,
- * and display something vaguely comprehensible in the event of a totally
- * unrecoverable error.
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
*
* @file
*/
+
+/**
+ * Check PHP Version, as well as for composer dependencies in entry points,
+ * and display something vaguely comprehensible in the event of a totally
+ * unrecoverable error.
+ * @class
+ */
class PHPVersionCheck {
/* @var string The number of the MediaWiki version used */
var $mwVersion = '1.30';
- /* @var string The minimum php version for MediaWiki to run */
- var $minimumVersionPHP = '5.5.9';
var $functionsExtensionsMapping = array(
'mb_substr' => 'mbstring',
'utf8_encode' => 'xml',
/**
* Returns the version of the installed php implementation.
*
- * @return string
+ * @param string $impl By default, the function returns the info of the currently installed PHP
+ * implementation. Using this parameter the caller can decide, what version info will be
+ * returned. Valid values: HHVM, PHP
+ * @return array An array of information about the php implementation, containing:
+ * - 'version': The version of the php implementation (specific to the implementation, not
+ * the version of the implemented php version)
+ * - 'implementation': The name of the implementation used
+ * - 'vendor': The development group, vendor or developer of the implementation.
+ * - 'upstreamSupported': The minimum version of the implementation supported by the named vendor.
+ * - 'minSupported': The minimum version supported by MediWiki
+ * - 'upgradeURL': The URL to the website of the implementation that contains
+ * upgrade/installation instructions.
*/
- function getPHPImplVersion() {
- return PHP_VERSION;
+ function getPHPInfo( $impl = false ) {
+ if (
+ ( defined( 'HHVM_VERSION' ) && $impl !== 'PHP' ) ||
+ $impl === 'HHVM'
+ ) {
+ return array(
+ 'implementation' => 'HHVM',
+ 'version' => defined( 'HHVM_VERSION' ) ? HHVM_VERSION : 'undefined',
+ 'vendor' => 'Facebook',
+ 'upstreamSupported' => '3.6.5',
+ 'minSupported' => '3.6.5',
+ 'upgradeURL' => 'https://docs.hhvm.com/hhvm/installation/introduction',
+ );
+ }
+ return array(
+ 'implementation' => 'PHP',
+ 'version' => PHP_VERSION,
+ 'vendor' => 'the PHP Group',
+ 'upstreamSupported' => '5.5.0',
+ 'minSupported' => '5.5.9',
+ 'upgradeURL' => 'http://www.php.net/downloads.php',
+ );
}
/**
* @return $this
*/
function checkRequiredPHPVersion() {
+ $phpInfo = $this->getPHPInfo();
+ $minimumVersion = $phpInfo['minSupported'];
+ $otherInfo = $this->getPHPInfo( $phpInfo['implementation'] === 'HHVM' ? 'PHP' : 'HHVM' );
if (
!function_exists( 'version_compare' )
- || version_compare( $this->getPHPImplVersion(), $this->minimumVersionPHP ) < 0
+ || version_compare( $phpInfo['version'], $minimumVersion ) < 0
) {
- $shortText = "MediaWiki $this->mwVersion requires at least PHP version"
- . " $this->minimumVersionPHP, you are using PHP {$this->getPHPImplVersion()}.";
+ $shortText = "MediaWiki $this->mwVersion requires at least {$phpInfo['implementation']}"
+ . " version $minimumVersion or {$otherInfo['implementation']} version "
+ . "{$otherInfo['minSupported']}, you are using {$phpInfo['implementation']} "
+ . "{$phpInfo['version']}.";
- $longText = "Error: You might be using on older PHP version. \n"
- . "MediaWiki $this->mwVersion needs PHP $this->minimumVersionPHP or higher.\n\n"
- . "Check if you have a newer php executable with a different name, "
- . "such as php5.\n\n";
+ $longText = "Error: You might be using an older {$phpInfo['implementation']} version. \n"
+ . "MediaWiki $this->mwVersion needs {$phpInfo['implementation']}"
+ . " $minimumVersion or higher or {$otherInfo['implementation']} version "
+ . "{$otherInfo['minSupported']}.\n\nCheck if you have a"
+ . " newer php executable with a different name, such as php5.\n\n";
$longHtml = <<<HTML
- Please consider <a href="http://www.php.net/downloads.php">upgrading your copy of PHP</a>.
- PHP versions less than 5.5.0 are no longer supported by the PHP Group and will not receive
+ Please consider <a href="{$phpInfo['upgradeURL']}">upgrading your copy of
+ {$phpInfo['implementation']}</a>.
+ {$phpInfo['implementation']} versions less than {$phpInfo['upstreamSupported']} are no
+ longer supported by {$phpInfo['vendor']} and will not receive
security or bugfix updates.
</p>
<p>
- If for some reason you are unable to upgrade your PHP version, you will need to
- <a href="https://www.mediawiki.org/wiki/Download">download</a> an older version
- of MediaWiki from our website. See our
- <a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
- for details of which versions are compatible with prior versions of PHP.
+ If for some reason you are unable to upgrade your {$phpInfo['implementation']} version,
+ you will need to <a href="https://www.mediawiki.org/wiki/Download">download</a> an
+ older version of MediaWiki from our website.
+ See our<a href="https://www.mediawiki.org/wiki/Compatibility#PHP">compatibility page</a>
+ for details of which versions are compatible with prior versions of {$phpInfo['implementation']}.
HTML;
- $this->triggerError( 'Supported PHP versions', $shortText, $longText, $longHtml );
+ $this->triggerError(
+ "Supported {$phpInfo['implementation']} versions",
+ $shortText,
+ $longText,
+ $longHtml
+ );
}
}