Added new success message when CLI Installer completes its work succesfuly.
[lhc/web/wiklou.git] / includes / installer / Installer.php
index 168d7ed..2906a83 100644 (file)
@@ -134,6 +134,7 @@ abstract class Installer {
                'envCheckUploadsDirectory',
                'envCheckLibicu',
                'envCheckSuhosinMaxValueLength',
+               'envCheck64Bit',
        ];
 
        /**
@@ -446,6 +447,7 @@ abstract class Installer {
                $this->parserTitle = Title::newFromText( 'Installer' );
                $this->parserOptions = new ParserOptions( $wgUser ); // language will be wrong :(
                $this->parserOptions->setEditSection( false );
+               $this->parserOptions->setWrapOutputClass( false );
                // Don't try to access DB before user language is initialised
                $this->setParserLanguage( Language::factory( 'en' ) );
        }
@@ -544,6 +546,17 @@ abstract class Installer {
                return $this->compiledDBs;
        }
 
+       /**
+        * Get the DatabaseInstaller class name for this type
+        *
+        * @param string $type database type ($wgDBtype)
+        * @return string Class name
+        * @since 1.30
+        */
+       public static function getDBInstallerClass( $type ) {
+               return ucfirst( $type ) . 'Installer';
+       }
+
        /**
         * Get an instance of DatabaseInstaller for the specified DB type.
         *
@@ -559,7 +572,7 @@ abstract class Installer {
                $type = strtolower( $type );
 
                if ( !isset( $this->dbInstallers[$type] ) ) {
-                       $class = ucfirst( $type ) . 'Installer';
+                       $class = self::getDBInstallerClass( $type );
                        $this->dbInstallers[$type] = new $class( $this );
                }
 
@@ -880,10 +893,13 @@ abstract class Installer {
         * @return bool
         */
        protected function envCheckDiff3() {
-               $names = [ "gdiff3", "diff3", "diff3.exe" ];
-               $versionInfo = [ '$1 --version 2>&1', 'GNU diffutils' ];
+               $names = [ "gdiff3", "diff3" ];
+               if ( wfIsWindows() ) {
+                       $names[] = 'diff3.exe';
+               }
+               $versionInfo = [ '--version', 'GNU diffutils' ];
 
-               $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
+               $diff3 = ExecutableFinder::findInDefaultPaths( $names, $versionInfo );
 
                if ( $diff3 ) {
                        $this->setVar( 'wgDiff3', $diff3 );
@@ -900,9 +916,9 @@ abstract class Installer {
         * @return bool
         */
        protected function envCheckGraphics() {
-               $names = [ wfIsWindows() ? 'convert.exe' : 'convert' ];
-               $versionInfo = [ '$1 -version', 'ImageMagick' ];
-               $convert = self::locateExecutableInDefaultPaths( $names, $versionInfo );
+               $names = wfIsWindows() ? 'convert.exe' : 'convert';
+               $versionInfo = [ '-version', 'ImageMagick' ];
+               $convert = ExecutableFinder::findInDefaultPaths( $names, $versionInfo );
 
                $this->setVar( 'wgImageMagickConvertCommand', '' );
                if ( $convert ) {
@@ -926,10 +942,10 @@ abstract class Installer {
         * @return bool
         */
        protected function envCheckGit() {
-               $names = [ wfIsWindows() ? 'git.exe' : 'git' ];
-               $versionInfo = [ '$1 --version', 'git version' ];
+               $names = wfIsWindows() ? 'git.exe' : 'git';
+               $versionInfo = [ '--version', 'git version' ];
 
-               $git = self::locateExecutableInDefaultPaths( $names, $versionInfo );
+               $git = ExecutableFinder::findInDefaultPaths( $names, $versionInfo );
 
                if ( $git ) {
                        $this->setVar( 'wgGitBin', $git );
@@ -1080,6 +1096,20 @@ abstract class Installer {
                return true;
        }
 
+       /**
+        * Checks if we're running on 64 bit or not. 32 bit is becoming increasingly
+        * hard to support, so let's at least warn people.
+        *
+        * @return bool
+        */
+       protected function envCheck64Bit() {
+               if ( PHP_INT_SIZE == 4 ) {
+                       $this->showMessage( 'config-using-32bit' );
+               }
+
+               return true;
+       }
+
        /**
         * Convert a hex string representing a Unicode code point to that code point.
         * @param string $c
@@ -1164,88 +1194,6 @@ abstract class Installer {
                $this->setVar( 'IP', $IP );
        }
 
-       /**
-        * Get an array of likely places we can find executables. Check a bunch
-        * of known Unix-like defaults, as well as the PATH environment variable
-        * (which should maybe make it work for Windows?)
-        *
-        * @return array
-        */
-       protected static function getPossibleBinPaths() {
-               return array_merge(
-                       [ '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
-                               '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ],
-                       explode( PATH_SEPARATOR, getenv( 'PATH' ) )
-               );
-       }
-
-       /**
-        * Search a path for any of the given executable names. Returns the
-        * executable name if found. Also checks the version string returned
-        * by each executable.
-        *
-        * Used only by environment checks.
-        *
-        * @param string $path Path to search
-        * @param array $names Array of executable names
-        * @param array|bool $versionInfo 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 locateExecutable( $path, $names, $versionInfo = false ) {
-               if ( !is_array( $names ) ) {
-                       $names = [ $names ];
-               }
-
-               foreach ( $names as $name ) {
-                       $command = $path . DIRECTORY_SEPARATOR . $name;
-
-                       MediaWiki\suppressWarnings();
-                       $file_exists = is_executable( $command );
-                       MediaWiki\restoreWarnings();
-
-                       if ( $file_exists ) {
-                               if ( !$versionInfo ) {
-                                       return $command;
-                               }
-
-                               $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
-                               if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
-                                       return $command;
-                               }
-                       }
-               }
-
-               return false;
-       }
-
-       /**
-        * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
-        * @see locateExecutable()
-        * @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 ) {
-               foreach ( self::getPossibleBinPaths() as $path ) {
-                       $exe = self::locateExecutable( $path, $names, $versionInfo );
-                       if ( $exe !== false ) {
-                               return $exe;
-                       }
-               }
-
-               return false;
-       }
-
        /**
         * Checks if scripts located in the given directory can be executed via the given URL.
         *
@@ -1339,7 +1287,7 @@ abstract class Installer {
         * Reasonable values for $directory include 'extensions' (the default) and 'skins'.
         *
         * @param string $directory Directory to search in
-        * @return array
+        * @return array [ $extName => [ 'screenshots' => [ '...' ] ]
         */
        public function findExtensions( $directory = 'extensions' ) {
                if ( $this->getVar( 'IP' ) === null ) {
@@ -1352,7 +1300,7 @@ abstract class Installer {
                }
 
                // extensions -> extension.json, skins -> skin.json
-               $jsonFile = substr( $directory, 0, strlen( $directory ) -1 ) . '.json';
+               $jsonFile = substr( $directory, 0, strlen( $directory ) - 1 ) . '.json';
 
                $dh = opendir( $extDir );
                $exts = [];
@@ -1361,11 +1309,19 @@ abstract class Installer {
                                continue;
                        }
                        if ( file_exists( "$extDir/$file/$jsonFile" ) || file_exists( "$extDir/$file/$file.php" ) ) {
-                               $exts[] = $file;
+                               // Extension exists. Now see if there are screenshots
+                               $exts[$file] = [];
+                               if ( is_dir( "$extDir/$file/screenshots" ) ) {
+                                       $paths = glob( "$extDir/$file/screenshots/*.png" );
+                                       foreach ( $paths as $path ) {
+                                               $exts[$file]['screenshots'][] = str_replace( $extDir, "../$directory", $path );
+                                       }
+
+                               }
                        }
                }
                closedir( $dh );
-               natcasesort( $exts );
+               uksort( $exts, 'strnatcasecmp' );
 
                return $exts;
        }
@@ -1529,6 +1485,11 @@ abstract class Installer {
                        }
                }
                if ( $status->isOk() ) {
+                       $this->showMessage(
+                               'config-install-success',
+                               $this->getVar( 'wgServer' ),
+                               $this->getVar( 'wgScriptPath' )
+                       );
                        $this->setVar( '_InstallDone', true );
                }