Check for very old PCRE versions in installer and updater
authorKevin Israel <pleasestand@live.com>
Mon, 16 Dec 2013 16:02:51 +0000 (11:02 -0500)
committerKevin Israel <pleasestand@live.com>
Tue, 21 Jan 2014 22:28:35 +0000 (17:28 -0500)
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

includes/installer/Installer.i18n.php
includes/installer/Installer.php
maintenance/update.php

index 3ba91d4..cbd9af2 100644 (file)
@@ -124,8 +124,9 @@ It may cause problems, particularly if using file uploads and <code>math</code>
        '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 <code>memory_limit</code> 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:
index 765838b..9fbf088 100644 (file)
@@ -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
index beed720..ea3133c 100644 (file)
@@ -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(