Merge "Add columns option to Special:PrefixIndex"
[lhc/web/wiklou.git] / includes / installer / Installer.php
index afd2e3d..48f850f 100644 (file)
@@ -41,12 +41,19 @@ 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
         */
        protected $settings;
 
-
        /**
         * List of detected DBs, access using getCompiledDBs().
         *
@@ -95,6 +102,7 @@ abstract class Installer {
                'mysql',
                'postgres',
                'oracle',
+               'mssql',
                'sqlite',
        );
 
@@ -109,11 +117,9 @@ abstract class Installer {
                'envCheckDB',
                'envCheckRegisterGlobals',
                'envCheckBrokenXML',
-               'envCheckPHP531',
                'envCheckMagicQuotes',
                'envCheckMagicSybase',
                'envCheckMbstring',
-               'envCheckZE1',
                'envCheckSafeMode',
                'envCheckXML',
                'envCheckPCRE',
@@ -131,6 +137,7 @@ abstract class Installer {
                'envCheckLibicu',
                'envCheckSuhosinMaxValueLength',
                'envCheckCtype',
+               'envCheckJSON',
        );
 
        /**
@@ -158,7 +165,6 @@ abstract class Installer {
                'wgImageMagickConvertCommand',
                'wgGitBin',
                'IP',
-               'wgServer',
                'wgScriptPath',
                'wgScriptExtension',
                'wgMetaNamespace',
@@ -303,7 +309,8 @@ abstract class Installer {
        /**
         * URL to mediawiki-announce subscription
         */
-       protected $mediaWikiAnnounceUrl = 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
+       protected $mediaWikiAnnounceUrl =
+               'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
 
        /**
         * Supported language codes for Mailman
@@ -339,15 +346,14 @@ abstract class Installer {
         * Constructor, always call this from child classes.
         */
        public function __construct() {
-               global $wgExtensionMessagesFiles, $wgUser;
+               global $wgMessagesDirs, $wgUser;
 
                // Disable the i18n cache and LoadBalancer
                Language::getLocalisationCache()->disableBackend();
                LBFactory::disableBackend();
 
-               // Load the installer's i18n file.
-               $wgExtensionMessagesFiles['MediawikiInstaller'] =
-                       __DIR__ . '/Installer.i18n.php';
+               // Load the installer's i18n.
+               $wgMessagesDirs['MediawikiInstaller'] = __DIR__ . '/i18n';
 
                // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
                $wgUser = User::newFromId( 0 );
@@ -416,6 +422,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();
@@ -490,8 +505,7 @@ abstract class Installer {
        }
 
        /**
-        * Determine if LocalSettings.php exists. If it does, return its variables,
-        * merged with those from AdminSettings.php, as an array.
+        * Determine if LocalSettings.php exists. If it does, return its variables.
         *
         * @return Array
         */
@@ -509,9 +523,7 @@ abstract class Installer {
 
                require "$IP/includes/DefaultSettings.php";
                require "$IP/LocalSettings.php";
-               if ( file_exists( "$IP/AdminSettings.php" ) ) {
-                       require "$IP/AdminSettings.php";
-               }
+
                return get_defined_vars();
        }
 
@@ -629,15 +641,20 @@ abstract class Installer {
                if ( !$status->isOK() ) {
                        return $status;
                }
-               $status->value->insert( 'site_stats', array(
-                       'ss_row_id' => 1,
-                       'ss_total_views' => 0,
-                       'ss_total_edits' => 0,
-                       'ss_good_articles' => 0,
-                       'ss_total_pages' => 0,
-                       'ss_users' => 0,
-                       'ss_images' => 0 ),
-                       __METHOD__, 'IGNORE' );
+               $status->value->insert(
+                       'site_stats',
+                       array(
+                               'ss_row_id' => 1,
+                               'ss_total_views' => 0,
+                               'ss_total_edits' => 0,
+                               'ss_good_articles' => 0,
+                               'ss_total_pages' => 0,
+                               'ss_users' => 0,
+                               'ss_images' => 0
+                       ),
+                       __METHOD__, 'IGNORE'
+               );
+
                return Status::newGood();
        }
 
@@ -669,7 +686,7 @@ abstract class Installer {
 
                $databases = $this->getCompiledDBs();
 
-               $databases = array_flip ( $databases );
+               $databases = array_flip( $databases );
                foreach ( array_keys( $databases ) as $db ) {
                        $installer = $this->getDBInstaller( $db );
                        $status = $installer->checkPrerequisites();
@@ -683,9 +700,11 @@ abstract class Installer {
                $databases = array_flip( $databases );
                if ( !$databases ) {
                        $this->showError( 'config-no-db', $wgLang->commaList( $allNames ) );
+
                        // @todo FIXME: This only works for the web installer!
                        return false;
                }
+
                return true;
        }
 
@@ -706,23 +725,10 @@ abstract class Installer {
                $test = new PhpXmlBugTester();
                if ( !$test->ok ) {
                        $this->showError( 'config-brokenlibxml' );
-                       return false;
-               }
-               return true;
-       }
 
-       /**
-        * Test PHP (probably 5.3.1, but it could regress again) to make sure that
-        * reference parameters to __call() are not converted to null
-        * @return bool
-        */
-       protected function envCheckPHP531() {
-               $test = new PhpRefCallBugTester;
-               $test->execute();
-               if ( !$test->ok ) {
-                       $this->showError( 'config-using531', phpversion() );
                        return false;
                }
+
                return true;
        }
 
@@ -733,8 +739,10 @@ abstract class Installer {
        protected function envCheckMagicQuotes() {
                if ( wfIniGetBool( "magic_quotes_runtime" ) ) {
                        $this->showError( 'config-magic-quotes-runtime' );
+
                        return false;
                }
+
                return true;
        }
 
@@ -745,8 +753,10 @@ abstract class Installer {
        protected function envCheckMagicSybase() {
                if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
                        $this->showError( 'config-magic-quotes-sybase' );
+
                        return false;
                }
+
                return true;
        }
 
@@ -757,20 +767,10 @@ abstract class Installer {
        protected function envCheckMbstring() {
                if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
                        $this->showError( 'config-mbstring' );
-                       return false;
-               }
-               return true;
-       }
 
-       /**
-        * Environment check for zend.ze1_compatibility_mode.
-        * @return bool
-        */
-       protected function envCheckZE1() {
-               if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
-                       $this->showError( 'config-ze1' );
                        return false;
                }
+
                return true;
        }
 
@@ -783,6 +783,7 @@ abstract class Installer {
                        $this->setVar( '_SafeMode', true );
                        $this->showMessage( 'config-safe-mode' );
                }
+
                return true;
        }
 
@@ -793,8 +794,10 @@ abstract class Installer {
        protected function envCheckXML() {
                if ( !function_exists( "utf8_encode" ) ) {
                        $this->showError( 'config-xml-bad' );
+
                        return false;
                }
+
                return true;
        }
 
@@ -807,10 +810,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
@@ -821,8 +820,10 @@ abstract class Installer {
                wfRestoreWarnings();
                if ( $regexd != '--' || $regexprop != '--' ) {
                        $this->showError( 'config-pcre-no-utf8' );
+
                        return false;
                }
+
                return true;
        }
 
@@ -849,6 +850,7 @@ abstract class Installer {
                                $this->setVar( '_RaiseMemory', true );
                        }
                }
+
                return true;
        }
 
@@ -881,6 +883,7 @@ abstract class Installer {
                if ( self::apacheModulePresent( 'mod_security' ) ) {
                        $this->showMessage( 'config-mod-security' );
                }
+
                return true;
        }
 
@@ -900,6 +903,7 @@ abstract class Installer {
                        $this->setVar( 'wgDiff3', false );
                        $this->showMessage( 'config-diff3-bad' );
                }
+
                return true;
        }
 
@@ -916,13 +920,14 @@ abstract class Installer {
                if ( $convert ) {
                        $this->setVar( 'wgImageMagickConvertCommand', $convert );
                        $this->showMessage( 'config-imagemagick', $convert );
+
                        return true;
                } elseif ( function_exists( 'imagejpeg' ) ) {
                        $this->showMessage( 'config-gd' );
-
                } else {
                        $this->showMessage( 'config-no-scaling' );
                }
+
                return true;
        }
 
@@ -945,6 +950,7 @@ abstract class Installer {
                        $this->setVar( 'wgGitBin', false );
                        $this->showMessage( 'config-git-bad' );
                }
+
                return true;
        }
 
@@ -953,8 +959,11 @@ abstract class Installer {
         */
        protected function envCheckServer() {
                $server = $this->envGetDefaultServer();
-               $this->showMessage( 'config-using-server', $server );
-               $this->setVar( 'wgServer', $server );
+               if ( $server !== null ) {
+                       $this->showMessage( 'config-using-server', $server );
+                       $this->setVar( 'wgServer', $server );
+               }
+
                return true;
        }
 
@@ -973,7 +982,12 @@ abstract class Installer {
                $IP = dirname( dirname( __DIR__ ) );
                $this->setVar( 'IP', $IP );
 
-               $this->showMessage( 'config-using-uri', $this->getVar( 'wgServer' ), $this->getVar( 'wgScriptPath' ) );
+               $this->showMessage(
+                       'config-using-uri',
+                       $this->getVar( 'wgServer' ),
+                       $this->getVar( 'wgScriptPath' )
+               );
+
                return true;
        }
 
@@ -989,6 +1003,7 @@ abstract class Installer {
                        $ext = 'php';
                }
                $this->setVar( 'wgScriptExtension', ".$ext" );
+
                return true;
        }
 
@@ -1034,6 +1049,7 @@ abstract class Installer {
                # Try the current value of LANG.
                if ( isset( $candidatesByLocale[getenv( 'LANG' )] ) ) {
                        $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
+
                        return true;
                }
 
@@ -1042,6 +1058,7 @@ abstract class Installer {
                foreach ( $commonLocales as $commonLocale ) {
                        if ( isset( $candidatesByLocale[$commonLocale] ) ) {
                                $this->setVar( 'wgShellLocale', $commonLocale );
+
                                return true;
                        }
                }
@@ -1052,6 +1069,7 @@ abstract class Installer {
                if ( isset( $candidatesByLang[$wikiLang] ) ) {
                        $m = reset( $candidatesByLang[$wikiLang] );
                        $this->setVar( 'wgShellLocale', $m[0] );
+
                        return true;
                }
 
@@ -1059,6 +1077,7 @@ abstract class Installer {
                if ( count( $candidatesByLocale ) ) {
                        $m = reset( $candidatesByLocale );
                        $this->setVar( 'wgShellLocale', $m[0] );
+
                        return true;
                }
 
@@ -1080,6 +1099,7 @@ abstract class Installer {
                if ( !$safe ) {
                        $this->showMessage( 'config-uploads-not-safe', $dir );
                }
+
                return true;
        }
 
@@ -1094,6 +1114,7 @@ abstract class Installer {
                        // Only warn if the value is below the sane 1024
                        $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
                }
+
                return true;
        }
 
@@ -1110,11 +1131,11 @@ abstract class Installer {
                        return chr( 0xC0 | $c >> 6 ) . chr( 0x80 | $c & 0x3F );
                } elseif ( $c <= 0xFFFF ) {
                        return chr( 0xE0 | $c >> 12 ) . chr( 0x80 | $c >> 6 & 0x3F )
-                               . chr( 0x80 | $c & 0x3F );
+                       . chr( 0x80 | $c & 0x3F );
                } elseif ( $c <= 0x10FFFF ) {
                        return chr( 0xF0 | $c >> 18 ) . chr( 0x80 | $c >> 12 & 0x3F )
-                               . chr( 0x80 | $c >> 6 & 0x3F )
-                               . chr( 0x80 | $c & 0x3F );
+                       . chr( 0x80 | $c >> 6 & 0x3F )
+                       . chr( 0x80 | $c & 0x3F );
                } else {
                        return false;
                }
@@ -1159,7 +1180,8 @@ abstract class Installer {
                        }
                }
 
-               // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
+               // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8',
+               // 'config-unicode-using-intl'
                if ( $useNormalizer === 'php' ) {
                        $this->showMessage( 'config-unicode-pure-php-warning' );
                } else {
@@ -1176,8 +1198,23 @@ abstract class Installer {
        protected function envCheckCtype() {
                if ( !function_exists( 'ctype_digit' ) ) {
                        $this->showError( 'config-ctype' );
+
+                       return false;
+               }
+
+               return true;
+       }
+
+       /**
+        * @return bool
+        */
+       protected function envCheckJSON() {
+               if ( !function_exists( 'json_decode' ) ) {
+                       $this->showError( 'config-json' );
+
                        return false;
                }
+
                return true;
        }
 
@@ -1206,8 +1243,8 @@ abstract class Installer {
         * @param string $path path to search
         * @param array $names of executable names
         * @param $versionInfo Boolean false or array with two members:
-        *               0 => Command to run for version check, with $1 for the full executable name
-        *               1 => String to compare the output with
+        *         0 => Command to run for version check, with $1 for the full executable name
+        *         1 => String to compare the output with
         *
         * If $versionInfo is not false, only executables with a version
         * matching $versionInfo[1] will be returned.
@@ -1236,14 +1273,20 @@ abstract class Installer {
                                }
                        }
                }
+
                return false;
        }
 
        /**
         * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
         * @see locateExecutable()
-        * @param $names
-        * @param $versionInfo bool
+        * @param array $names Array of possible names.
+        * @param array|bool $versionInfo Default: false or array with two members:
+        *         0 => Command to run for version check, with $1 for the full executable name
+        *         1 => String to compare the output with
+        *
+        * If $versionInfo is not false, only executables with a version
+        * matching $versionInfo[1] will be returned.
         * @return bool|string
         */
        public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
@@ -1253,6 +1296,7 @@ abstract class Installer {
                                return $exe;
                        }
                }
+
                return false;
        }
 
@@ -1286,8 +1330,7 @@ abstract class Installer {
 
                                try {
                                        $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
-                               }
-                               catch ( MWException $e ) {
+                               } catch ( MWException $e ) {
                                        // Http::get throws with allow_url_fopen = false and no curl extension.
                                        $text = null;
                                }
@@ -1295,6 +1338,7 @@ abstract class Installer {
 
                                if ( $text == 'exec' ) {
                                        wfRestoreWarnings();
+
                                        return $ext;
                                }
                        }
@@ -1319,6 +1363,7 @@ abstract class Installer {
                ob_start();
                phpinfo( INFO_MODULES );
                $info = ob_get_clean();
+
                return strpos( $info, $moduleName ) !== false;
        }
 
@@ -1424,13 +1469,13 @@ abstract class Installer {
         */
        protected function getInstallSteps( DatabaseInstaller $installer ) {
                $coreInstallSteps = array(
-                       array( 'name' => 'database',   'callback' => array( $installer, 'setupDatabase' ) ),
-                       array( 'name' => 'tables',     'callback' => array( $installer, 'createTables' ) ),
-                       array( 'name' => 'interwiki',  'callback' => array( $installer, 'populateInterwikiTable' ) ),
-                       array( 'name' => 'stats',      'callback' => array( $this, 'populateSiteStats' ) ),
-                       array( 'name' => 'keys',       'callback' => array( $this, 'generateKeys' ) ),
-                       array( 'name' => 'sysop',      'callback' => array( $this, 'createSysop' ) ),
-                       array( 'name' => 'mainpage',   'callback' => array( $this, 'createMainpage' ) ),
+                       array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
+                       array( 'name' => 'tables', 'callback' => array( $installer, 'createTables' ) ),
+                       array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
+                       array( 'name' => 'stats', 'callback' => array( $this, 'populateSiteStats' ) ),
+                       array( 'name' => 'keys', 'callback' => array( $this, 'generateKeys' ) ),
+                       array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
+                       array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
                );
 
                // Build the array of install steps starting from the core install list,
@@ -1463,6 +1508,7 @@ abstract class Installer {
                                'callback' => array( $installer, 'createExtensionTables' )
                        );
                }
+
                return $this->installSteps;
        }
 
@@ -1499,6 +1545,7 @@ abstract class Installer {
                if ( $status->isOk() ) {
                        $this->setVar( '_InstallDone', true );
                }
+
                return $installResults;
        }
 
@@ -1512,6 +1559,7 @@ abstract class Installer {
                if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
                        $keys['wgUpgradeKey'] = 16;
                }
+
                return $this->doGenerateKeys( $keys );
        }
 
@@ -1633,10 +1681,11 @@ abstract class Installer {
                        );
 
                        $page->doEditContent( $content,
-                                       '',
-                                       EDIT_NEW,
-                                       false,
-                                       User::newFromName( 'MediaWiki default' ) );
+                               '',
+                               EDIT_NEW,
+                               false,
+                               User::newFromName( 'MediaWiki default' )
+                       );
                } catch ( MWException $e ) {
                        //using raw, because $wgShowExceptionDetails can not be set yet
                        $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
@@ -1672,6 +1721,11 @@ abstract class Installer {
 
                // Some of the environment checks make shell requests, remove limits
                $GLOBALS['wgMaxShellMemory'] = 0;
+
+               // Don't bother embedding images into generated CSS, which is not cached
+               $GLOBALS['wgResourceLoaderLESSFunctions']['embeddable'] = function ( $frame, $less ) {
+                       return $less->toBool( false );
+               };
        }
 
        /**