From: Kevin Israel Date: Mon, 16 Dec 2013 16:02:51 +0000 (-0500) Subject: Check for very old PCRE versions in installer and updater X-Git-Tag: 1.31.0-rc.0~17205 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_modifier.php?a=commitdiff_plain;h=b215d91224f711e263126ae3b8546e022f33ef00;p=lhc%2Fweb%2Fwiklou.git Check for very old PCRE versions in installer and updater RE_IPV6_ADD uses (?(-n)) ("relative reference condition"), and CSSMin uses \K ("reset start of match"), which only work in PCRE 7.2 and later -- newer versions than the PCRE 6.6 included with Red Hat Enterprise Linux 5 and its derivatives (e.g. CentOS 5). Because the WMF developers, in general, do not seem to support maintaining compatibility with such old software versions, I have opted to add a check to the MediaWiki installer for these versions of PCRE. Affected users are directed to a MediaWiki.org page advising the use of a different PHP package that uses the bundled PCRE version instead of the older system version. For now, the minimum PCRE version is set to 7.2, the oldest version not known to break MediaWiki core. Once PHP 5.3 support is dropped, we may be able to require PCRE 8.12 (bundled with PHP 5.4.0) or later. The existing check for mere existence of the PCRE functions is removed; since PHP 5.3, it is impossible to compile PHP without PCRE support. Bug: 58213 Change-Id: Icf3732b6f84eeb25990178ae8fe3bd0fe4cc833f --- diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index 3ba91d4cb9..cbd9af255a 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -124,8 +124,9 @@ It may cause problems, particularly if using file uploads and math 'config-xml-bad' => "PHP's XML module is missing. MediaWiki requires functions in this module and will not work in this configuration. If you're running Mandrake, install the php-xml package.", - 'config-pcre' => 'The PCRE support module appears to be missing. -MediaWiki requires the Perl-compatible regular expression functions to work.', + 'config-pcre-old' => "'''Fatal:''' PCRE $1 or later is required. +Your PHP binary is linked with PCRE $2. +[https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE More information].", 'config-pcre-no-utf8' => "'''Fatal:''' PHP's PCRE module seems to be compiled without PCRE_UTF8 support. MediaWiki requires UTF-8 support to function correctly.", 'config-memory-raised' => "PHP's memory_limit is $1, raised to $2.", @@ -651,6 +652,10 @@ Parameters: 'config-mbstring' => '{{Related|Config-fatal}}', 'config-ze1' => '{{Related|Config-fatal}}', 'config-pcre' => 'PCRE is an initialism for "Perl-compatible regular expression". Perl is programming language whose [[:w:regular expression|regular expression]] syntax is popular and used in other languages using a library called PCRE.', + 'config-pcre-old' => 'Parameters: +* $1 - minimum PCRE version number +* $2 - the installed version of [[wikipedia:PCRE|PCRE]] +{{Related|Config-fatal}}', 'config-pcre-no-utf8' => "PCRE is a name of a programmers' library for supporting regular expressions. It can probably be translated without change. {{Related|Config-fatal}}", 'config-memory-raised' => 'Parameters: diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 765838bd1f..9fbf0881f6 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -41,6 +41,14 @@ 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. + * + * Defining this is necessary because PHP may be linked with a system version + * of PCRE, which may be older than that bundled with the minimum PHP version. + */ + const MINIMUM_PCRE_VERSION = '7.2'; + /** * @var array */ @@ -416,6 +424,15 @@ abstract class Installer { $good = false; } + // 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 ) { foreach ( $this->envChecks as $check ) { $status = $this->$check(); @@ -826,11 +843,6 @@ abstract class Installer { * @return bool */ protected function envCheckPCRE() { - if ( !function_exists( 'preg_match' ) ) { - $this->showError( 'config-pcre' ); - - return false; - } wfSuppressWarnings(); $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' ); // Need to check for \p support too, as PCRE can be compiled diff --git a/maintenance/update.php b/maintenance/update.php index beed72089d..ea3133ca72 100644 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -57,6 +57,20 @@ class UpdateMediaWiki extends Maintenance { } function compatChecks() { + // Avoid syntax error in PHP4 + $minimumPcreVersion = constant( 'Installer::MINIMUM_PCRE_VERSION' ); + + list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 ); + if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) { + $this->error( + "PCRE $minimumPcreVersion or later is required.\n" . + "Your PHP binary is linked with PCRE $pcreVersion.\n\n" . + "More information:\n" . + "https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE\n\n" . + "ABORTING.\n", + true ); + } + $test = new PhpXmlBugTester(); if ( !$test->ok ) { $this->error(