Followup r76220: locateExecutableInDefaultPaths() was made static, so use static...
[lhc/web/wiklou.git] / includes / installer / Installer.php
index 266a631..c1cc4f5 100644 (file)
@@ -82,9 +82,10 @@ abstract class Installer {
         * @var array
         */
        protected $envChecks = array(
-               'envLatestVersion',
                'envCheckDB',
                'envCheckRegisterGlobals',
+               'envCheckBrokenXML',
+               'envCheckPHP531',
                'envCheckMagicQuotes',
                'envCheckMagicSybase',
                'envCheckMbstring',
@@ -141,8 +142,6 @@ abstract class Installer {
         * @return boolean
         */
        public function doEnvironmentChecks() {
-               $this->showMessage( 'config-env-php', phpversion() );
-
                $good = true;
 
                foreach ( $this->envChecks as $check ) {
@@ -214,33 +213,29 @@ abstract class Installer {
        }
 
        /**
-        * Determine if LocalSettings exists. If it does, return an appropriate
-        * status for whether we should can upgrade or not.
+        * Determine if LocalSettings.php exists. If it does, return its variables, 
+        * merged with those from AdminSettings.php, as an array.
         *
-        * @return Status
+        * @return Array
         */
-       public function getLocalSettingsStatus() {
+       public function getExistingLocalSettings() {
                global $IP;
 
-               $status = Status::newGood();
-
                wfSuppressWarnings();
-               $ls = file_exists( "$IP/LocalSettings.php" );
+               $_lsExists = file_exists( "$IP/LocalSettings.php" );
                wfRestoreWarnings();
 
-               if( $ls ) {
-                       $wgCacheEpoch = $wgCommandLineMode = false;
-                       require_once( "$IP/LocalSettings.php" );
-                       $vars = get_defined_vars();
-                       if( isset( $vars['wgUpgradeKey'] ) && $vars['wgUpgradeKey'] ) {
-                               $status->warning( 'config-localsettings-upgrade' );
-                               $this->setVar( '_UpgradeKey', $vars['wgUpgradeKey' ] );
-                       } else {
-                               $status->fatal( 'config-localsettings-noupgrade' );
-                       }
+               if( !$_lsExists ) {
+                       return false;
                }
+               unset($_lsExists);
 
-               return $status;
+               require( "$IP/includes/DefaultSettings.php" );
+               require( "$IP/LocalSettings.php" );
+               if ( file_exists( "$IP/AdminSettings.php" ) ) {
+                       require( "$IP/AdminSettings.php" );
+               }
+               return get_defined_vars();
        }
 
        /**
@@ -304,7 +299,7 @@ abstract class Installer {
         * external links work just fine.
         *
         * But in case a translator decides to throw in a #ifexist or internal link or
-        * whatever, this function is guarded to catch attempted DB access and to present
+        * whatever, this function is guarded to catch the attempted DB access and to present
         * some fallback text.
         *
         * @param $text String
@@ -328,24 +323,19 @@ abstract class Installer {
                return $html;
        }
 
-       /**
-        * TODO: document
-        *
-        * @param $installer DatabaseInstaller
-        *
-        * @return Status
-        */
-       public function installDatabase( DatabaseInstaller &$installer ) {
-               if( !$installer ) {
-                       $type = $this->getVar( 'wgDBtype' );
-                       $status = Status::newFatal( "config-no-db", $type );
-               } else {
-                       $status = $installer->setupDatabase();
-               }
+       public function getParserOptions() {
+               return $this->parserOptions;
+       }
 
-               return $status;
+       public function disableLinkPopups() {
+               $this->parserOptions->setExternalLinkTarget( false );
        }
 
+       public function restoreLinkPopups() {
+               global $wgExternalLinkTarget;
+               $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
+       }       
+
        /**
         * TODO: document
         *
@@ -363,17 +353,6 @@ abstract class Installer {
                return $status;
        }
 
-       /**
-        * TODO: document
-        *
-        * @param $installer DatabaseInstaller
-        *
-        * @return Status
-        */
-       public function installInterwiki( DatabaseInstaller &$installer ) {
-               return $installer->populateInterwikiTable();
-       }
-
        /**
         * Exports all wg* variables stored by the installer into global scope.
         */
@@ -385,39 +364,10 @@ abstract class Installer {
                }
        }
 
-       /**
-        * Check if we're installing the latest version.
-        */
-       public function envLatestVersion() {
-               global $wgVersion;
-
-               $repository = wfGetRepository();
-               $currentVersion = $repository->getLatestCoreVersion();
-
-               $this->setVar( '_ExternalHTTP', true );
-
-               if ( $currentVersion === false ) {
-                       # For when the request is successful but there's e.g. some silly man in
-                       # the middle firewall blocking us, e.g. one of those annoying airport ones
-                       $this->showMessage( 'config-env-latest-can-not-check', $repository->getLocation() );
-                       return;
-               }
-
-               if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
-                       $this->showMessage( 'config-env-latest-old' );
-                       // FIXME: this only works for the web installer!
-                       $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
-               } elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
-                       $this->showMessage( 'config-env-latest-new' );
-               } else {
-                       $this->showMessage( 'config-env-latest-ok' );
-               }
-       }
-
        /**
         * Environment check for DB types.
         */
-       public function envCheckDB() {
+       protected function envCheckDB() {
                global $wgLang;
 
                $compiledDBs = array();
@@ -445,32 +395,53 @@ abstract class Installer {
                        return false;
                }
 
-               $this->showMessage( 'config-have-db', $wgLang->listToText( $goodNames ), count( $goodNames ) );
-
                // Check for FTS3 full-text search module
                $sqlite = $this->getDBInstaller( 'sqlite' );
                if ( $sqlite->isCompiled() ) {
                        $db = new DatabaseSqliteStandalone( ':memory:' );
-                       $this->showMessage( $db->getFulltextSearchModule() == 'FTS3'
-                               ? 'config-have-fts3'
-                               : 'config-no-fts3'
-                       );
+                       if( $db->getFulltextSearchModule() != 'FTS3' ) {
+                               $this->showMessage( 'config-no-fts3' );
+                       }
                }
        }
 
        /**
         * Environment check for register_globals.
         */
-       public function envCheckRegisterGlobals() {
+       protected function envCheckRegisterGlobals() {
                if( wfIniGetBool( "magic_quotes_runtime" ) ) {
                        $this->showMessage( 'config-register-globals' );
                }
        }
 
+       /**
+        * Some versions of libxml+PHP break < and > encoding horribly
+        */
+       protected function envCheckBrokenXML() {
+               $test = new PhpXmlBugTester();
+               if ( !$test->ok ) {
+                       $this->showMessage( 'config-brokenlibxml' );
+                       return false;
+               }
+       }
+
+       /**
+        * Test PHP (probably 5.3.1, but it could regress again) to make sure that
+        * reference parameters to __call() are not converted to null
+        */
+       protected function envCheckPHP531() {
+               $test = new PhpRefCallBugTester;
+               $test->execute();
+               if ( !$test->ok ) {
+                       $this->showMessage( 'config-using531' );
+                       return false;
+               }
+       }
+
        /**
         * Environment check for magic_quotes_runtime.
         */
-       public function envCheckMagicQuotes() {
+       protected function envCheckMagicQuotes() {
                if( wfIniGetBool( "magic_quotes_runtime" ) ) {
                        $this->showMessage( 'config-magic-quotes-runtime' );
                        return false;
@@ -480,7 +451,7 @@ abstract class Installer {
        /**
         * Environment check for magic_quotes_sybase.
         */
-       public function envCheckMagicSybase() {
+       protected function envCheckMagicSybase() {
                if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
                        $this->showMessage( 'config-magic-quotes-sybase' );
                        return false;
@@ -490,7 +461,7 @@ abstract class Installer {
        /**
         * Environment check for mbstring.func_overload.
         */
-       public function envCheckMbstring() {
+       protected function envCheckMbstring() {
                if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
                        $this->showMessage( 'config-mbstring' );
                        return false;
@@ -500,7 +471,7 @@ abstract class Installer {
        /**
         * Environment check for zend.ze1_compatibility_mode.
         */
-       public function envCheckZE1() {
+       protected function envCheckZE1() {
                if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
                        $this->showMessage( 'config-ze1' );
                        return false;
@@ -510,7 +481,7 @@ abstract class Installer {
        /**
         * Environment check for safe_mode.
         */
-       public function envCheckSafeMode() {
+       protected function envCheckSafeMode() {
                if ( wfIniGetBool( 'safe_mode' ) ) {
                        $this->setVar( '_SafeMode', true );
                        $this->showMessage( 'config-safe-mode' );
@@ -520,32 +491,37 @@ abstract class Installer {
        /**
         * Environment check for the XML module.
         */
-       public function envCheckXML() {
+       protected function envCheckXML() {
                if ( !function_exists( "utf8_encode" ) ) {
                        $this->showMessage( 'config-xml-bad' );
                        return false;
                }
-               $this->showMessage( 'config-xml-good' );
        }
 
        /**
         * Environment check for the PCRE module.
         */
-       public function envCheckPCRE() {
+       protected function envCheckPCRE() {
                if ( !function_exists( 'preg_match' ) ) {
                        $this->showMessage( 'config-pcre' );
                        return false;
                }
+               wfSuppressWarnings();
+               $regexd = preg_replace( '/[\x{0400}-\x{04FF}]/u', '', '-АБВГД-' );
+               wfRestoreWarnings();
+               if ( $regexd != '--' ) {
+                       $this->showMessage( 'config-pcre-no-utf8' );
+                       return false;
+               }
        }
 
        /**
         * Environment check for available memory.
         */
-       public function envCheckMemory() {
+       protected function envCheckMemory() {
                $limit = ini_get( 'memory_limit' );
 
                if ( !$limit || $limit == -1 ) {
-                       $this->showMessage( 'config-memory-none' );
                        return true;
                }
 
@@ -565,20 +541,18 @@ abstract class Installer {
                                $this->setVar( '_RaiseMemory', true );
                        }
                } else {
-                       $this->showMessage( 'config-memory-ok', $limit );
+                       return true;
                }
        }
 
        /**
         * Environment check for compiled object cache types.
         */
-       public function envCheckCache() {
+       protected function envCheckCache() {
                $caches = array();
-
                foreach ( $this->objectCaches as $name => $function ) {
                        if ( function_exists( $function ) ) {
                                $caches[$name] = true;
-                               $this->showMessage( 'config-' . $name );
                        }
                }
 
@@ -592,14 +566,13 @@ abstract class Installer {
        /**
         * Search for GNU diff3.
         */
-       public function envCheckDiff3() {
+       protected function envCheckDiff3() {
                $names = array( "gdiff3", "diff3", "diff3.exe" );
-               $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
+               $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
 
-               $diff3 = $this->locateExecutableInDefaultPaths( $names, $versionInfo );
+               $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
 
                if ( $diff3 ) {
-                       $this->showMessage( 'config-diff3-good', $diff3 );
                        $this->setVar( 'wgDiff3', $diff3 );
                } else {
                        $this->setVar( 'wgDiff3', false );
@@ -610,9 +583,9 @@ abstract class Installer {
        /**
         * Environment check for ImageMagick and GD.
         */
-       public function envCheckGraphics() {
+       protected function envCheckGraphics() {
                $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
-               $convert = $this->locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
+               $convert = self::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
 
                if ( $convert ) {
                        $this->setVar( 'wgImageMagickConvertCommand', $convert );
@@ -629,12 +602,11 @@ abstract class Installer {
        /**
         * Environment check for setting $IP and $wgScriptPath.
         */
-       public function envCheckPath() {
+       protected function envCheckPath() {
                global $IP;
                $IP = dirname( dirname( dirname( __FILE__ ) ) );
 
                $this->setVar( 'IP', $IP );
-               $this->showMessage( 'config-dir', $IP );
 
                // PHP_SELF isn't available sometimes, such as when PHP is CGI but
                // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
@@ -653,28 +625,25 @@ abstract class Installer {
 
                $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
                $this->setVar( 'wgScriptPath', $uri );
-               $this->showMessage( 'config-uri', $uri );
        }
 
        /**
         * Environment check for setting the preferred PHP file extension.
         */
-       public function envCheckExtension() {
+       protected function envCheckExtension() {
                // FIXME: detect this properly
                if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
                        $ext = 'php5';
                } else {
                        $ext = 'php';
                }
-
                $this->setVar( 'wgScriptExtension', ".$ext" );
-               $this->showMessage( 'config-file-extension', $ext );
        }
 
        /**
         * TODO: document
         */
-       public function envCheckShellLocale() {
+       protected function envCheckShellLocale() {
                $os = php_uname( 's' );
                $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
 
@@ -712,7 +681,6 @@ abstract class Installer {
                # Try the current value of LANG.
                if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
                        $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
-                       $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
                        return true;
                }
 
@@ -721,7 +689,6 @@ abstract class Installer {
                foreach ( $commonLocales as $commonLocale ) {
                        if ( isset( $candidatesByLocale[$commonLocale] ) ) {
                                $this->setVar( 'wgShellLocale', $commonLocale );
-                               $this->showMessage( 'config-shell-locale', $commonLocale );
                                return true;
                        }
                }
@@ -732,7 +699,6 @@ abstract class Installer {
                if ( isset( $candidatesByLang[$wikiLang] ) ) {
                        $m = reset( $candidatesByLang[$wikiLang] );
                        $this->setVar( 'wgShellLocale', $m[0] );
-                       $this->showMessage( 'config-shell-locale', $m[0] );
                        return true;
                }
 
@@ -740,7 +706,6 @@ abstract class Installer {
                if ( count( $candidatesByLocale ) ) {
                        $m = reset( $candidatesByLocale );
                        $this->setVar( 'wgShellLocale', $m[0] );
-                       $this->showMessage( 'config-shell-locale', $m[0] );
                        return true;
                }
 
@@ -751,7 +716,7 @@ abstract class Installer {
        /**
         * TODO: document
         */
-       public function envCheckUploadsDirectory() {
+       protected function envCheckUploadsDirectory() {
                global $IP, $wgServer;
 
                $dir = $IP . '/images/';
@@ -759,7 +724,7 @@ abstract class Installer {
                $safe = !$this->dirIsExecutable( $dir, $url );
 
                if ( $safe ) {
-                       $this->showMessage( 'config-uploads-safe' );
+                       return true;
                } else {
                        $this->showMessage( 'config-uploads-not-safe', $dir );
                }
@@ -792,7 +757,7 @@ abstract class Installer {
        /**
         * Check the libicu version
         */
-       public function envCheckLibicu() {
+       protected function envCheckLibicu() {
                $utf8 = function_exists( 'utf8_normalize' );
                $intl = function_exists( 'normalizer_normalize' );
 
@@ -825,11 +790,13 @@ abstract class Installer {
                }
 
                // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
-               $this->showMessage( 'config-unicode-using-' . $useNormalizer );
                if( $useNormalizer === 'php' ) {
                        $this->showMessage( 'config-unicode-pure-php-warning' );
-               } elseif( $needsUpdate ) {
-                       $this->showMessage( 'config-unicode-update-warning' );
+               } else {
+                       $this->showMessage( 'config-unicode-using-' . $useNormalizer );
+                       if( $needsUpdate ) {
+                               $this->showMessage( 'config-unicode-update-warning' );
+                       }
                }
        }
 
@@ -840,7 +807,7 @@ abstract class Installer {
         *
         * @return Array
         */
-       protected function getPossibleBinPaths() {
+       protected static function getPossibleBinPaths() {
                return array_merge(
                        array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
                                '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
@@ -858,13 +825,13 @@ abstract class Installer {
         * @param $path String: path to search
         * @param $names Array of executable names
         * @param $versionInfo Boolean false or array with two members:
-        *               0 => Command to run for version check, with $1 for the path
+        *               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.
         */
-       protected function locateExecutable( $path, $names, $versionInfo = false ) {
+       public static function locateExecutable( $path, $names, $versionInfo = false ) {
                if ( !is_array( $names ) ) {
                        $names = array( $names );
                }
@@ -881,11 +848,8 @@ abstract class Installer {
                                        return $command;
                                }
 
-                               if ( wfIsWindows() ) {
-                                       $command = "\"$command\"";
-                               }
-                               $file = str_replace( '$1', $command, $versionInfo[0] );
-                               if ( strstr( wfShellExec( $file ), $versionInfo[1]) !== false ) {
+                               $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
+                               if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
                                        return $command;
                                }
                        }
@@ -897,9 +861,9 @@ abstract class Installer {
         * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
         * @see locateExecutable()
         */
-       protected function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
-               foreach( $this->getPossibleBinPaths() as $path ) {
-                       $exe = $this->locateExecutable( $path, $names, $versionInfo );
+       public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
+               foreach( self::getPossibleBinPaths() as $path ) {
+                       $exe = self::locateExecutable( $path, $names, $versionInfo );
                        if( $exe !== false ) {
                                return $exe;
                        }