Remove support for magic_quotes_gpc
[lhc/web/wiklou.git] / includes / installer / Installer.php
index 86b975e..0294c42 100644 (file)
@@ -108,6 +108,10 @@ abstract class Installer {
         * These may output warnings using showMessage(), and/or abort the
         * installation process by returning false.
         *
+        * For the WebInstaller these are only called on the Welcome page,
+        * if these methods have side-effects that should affect later page loads
+        * (as well as the generated stylesheet), use envPreps instead.
+        *
         * @var array
         */
        protected $envChecks = array(
@@ -115,7 +119,6 @@ abstract class Installer {
                'envCheckRegisterGlobals',
                'envCheckBrokenXML',
                'envCheckMagicQuotes',
-               'envCheckMagicSybase',
                'envCheckMbstring',
                'envCheckSafeMode',
                'envCheckXML',
@@ -128,15 +131,26 @@ abstract class Installer {
                'envCheckGit',
                'envCheckServer',
                'envCheckPath',
-               'envCheckExtension',
                'envCheckShellLocale',
                'envCheckUploadsDirectory',
                'envCheckLibicu',
                'envCheckSuhosinMaxValueLength',
                'envCheckCtype',
+               'envCheckIconv',
                'envCheckJSON',
        );
 
+       /**
+        * A list of environment preparation methods called by doEnvironmentPreps().
+        *
+        * @var array
+        */
+       protected $envPreps = array(
+               'envPrepExtension',
+               'envPrepServer',
+               'envPrepPath',
+       );
+
        /**
         * MediaWiki configuration globals that will eventually be passed through
         * to LocalSettings.php. The names only are given here, the defaults
@@ -204,6 +218,7 @@ abstract class Installer {
                '_LicenseCode' => 'none',
                '_CCDone' => false,
                '_Extensions' => array(),
+               '_Skins' => array(),
                '_MemCachedServers' => '',
                '_UpgradeKeySupplied' => false,
                '_ExistingDBSettings' => false,
@@ -337,10 +352,17 @@ abstract class Installer {
        abstract public function showError( $msg /*, ... */ );
 
        /**
-        * Show a message to the installing user by using a Status object
+        * Shows messages to the user through a Status object
         * @param Status $status
         */
-       abstract public function showStatusMessage( Status $status );
+       public function showStatusMessage( Status $status ) {
+               $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
+               if ( $errors ) {
+                       foreach ( $errors as $error ) {
+                               call_user_func( 'showMessage', $error );
+                       }
+               }
+       }
 
        /**
         * Constructor, always call this from child classes.
@@ -377,6 +399,8 @@ abstract class Installer {
                        $this->settings[$var] = $GLOBALS[$var];
                }
 
+               $this->doEnvironmentPreps();
+
                $this->compiledDBs = array();
                foreach ( self::getDBTypes() as $type ) {
                        $installer = $this->getDBInstaller( $type );
@@ -417,7 +441,7 @@ abstract class Installer {
        public function doEnvironmentChecks() {
                // Php version has already been checked by entry scripts
                // Show message here for information purposes
-               $this->showMessage( 'config-env-php', phpversion() );
+               $this->showMessage( 'config-env-php', PHP_VERSION );
 
                $good = true;
                // Must go here because an old version of PCRE can prevent other checks from completing
@@ -439,6 +463,12 @@ abstract class Installer {
                return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' );
        }
 
+       public function doEnvironmentPreps() {
+               foreach ( $this->envPreps as $prep ) {
+                       $this->$prep();
+               }
+       }
+
        /**
         * Set a MW configuration variable, or internal installer configuration variable.
         *
@@ -731,31 +761,19 @@ abstract class Installer {
        }
 
        /**
-        * Environment check for magic_quotes_runtime.
+        * Environment check for magic_quotes_(gpc|runtime|sybase).
         * @return bool
         */
        protected function envCheckMagicQuotes() {
-               if ( wfIniGetBool( "magic_quotes_runtime" ) ) {
-                       $this->showError( 'config-magic-quotes-runtime' );
-
-                       return false;
-               }
-
-               return true;
-       }
-
-       /**
-        * Environment check for magic_quotes_sybase.
-        * @return bool
-        */
-       protected function envCheckMagicSybase() {
-               if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
-                       $this->showError( 'config-magic-quotes-sybase' );
-
-                       return false;
+               $status = true;
+               foreach ( array( 'gpc', 'runtime', 'sybase' ) as $magicJunk ) {
+                       if ( wfIniGetBool( "magic_quotes_$magicJunk" ) ) {
+                               $this->showError( "config-magic-quotes-$magicJunk" );
+                               $status = false;
+                       }
                }
 
-               return true;
+               return $status;
        }
 
        /**
@@ -953,55 +971,29 @@ abstract class Installer {
        }
 
        /**
-        * Environment check for the server hostname.
+        * Environment check to inform user which server we've assumed.
+        *
+        * @return bool
         */
        protected function envCheckServer() {
                $server = $this->envGetDefaultServer();
                if ( $server !== null ) {
                        $this->showMessage( 'config-using-server', $server );
-                       $this->setVar( 'wgServer', $server );
                }
-
                return true;
        }
 
        /**
-        * Helper function to be called from envCheckServer()
-        * @return string
-        */
-       abstract protected function envGetDefaultServer();
-
-       /**
-        * Environment check for setting $IP and $wgScriptPath.
+        * Environment check to inform user which paths we've assumed.
+        *
         * @return bool
         */
        protected function envCheckPath() {
-               global $IP;
-               $IP = dirname( dirname( __DIR__ ) );
-               $this->setVar( 'IP', $IP );
-
                $this->showMessage(
                        'config-using-uri',
                        $this->getVar( 'wgServer' ),
                        $this->getVar( 'wgScriptPath' )
                );
-
-               return true;
-       }
-
-       /**
-        * Environment check for setting the preferred PHP file extension.
-        * @return bool
-        */
-       protected function envCheckExtension() {
-               // @todo FIXME: Detect this properly
-               if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
-                       $ext = 'php5';
-               } else {
-                       $ext = 'php';
-               }
-               $this->setVar( 'wgScriptExtension', ".$ext" );
-
                return true;
        }
 
@@ -1203,6 +1195,19 @@ abstract class Installer {
                return true;
        }
 
+       /**
+        * @return bool
+        */
+       protected function envCheckIconv() {
+               if ( !function_exists( 'iconv' ) ) {
+                       $this->showError( 'config-iconv' );
+
+                       return false;
+               }
+
+               return true;
+       }
+
        /**
         * @return bool
         */
@@ -1216,6 +1221,44 @@ abstract class Installer {
                return true;
        }
 
+       /**
+        * Environment prep for the server hostname.
+        */
+       protected function envPrepServer() {
+               $server = $this->envGetDefaultServer();
+               if ( $server !== null ) {
+                       $this->setVar( 'wgServer', $server );
+               }
+       }
+
+       /**
+        * Helper function to be called from envPrepServer()
+        * @return string
+        */
+       abstract protected function envGetDefaultServer();
+
+       /**
+        * Environment prep for setting the preferred PHP file extension.
+        */
+       protected function envPrepExtension() {
+               // @todo FIXME: Detect this properly
+               if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
+                       $ext = '.php5';
+               } else {
+                       $ext = '.php';
+               }
+               $this->setVar( 'wgScriptExtension', $ext );
+       }
+
+       /**
+        * Environment prep for setting $IP and $wgScriptPath.
+        */
+       protected function envPrepPath() {
+               global $IP;
+               $IP = dirname( dirname( __DIR__ ) );
+               $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
@@ -1385,17 +1428,20 @@ abstract class Installer {
        }
 
        /**
-        * Finds extensions that follow the format /extensions/Name/Name.php,
+        * Finds extensions that follow the format /$directory/Name/Name.php,
         * and returns an array containing the value for 'Name' for each found extension.
         *
+        * Reasonable values for $directory include 'extensions' (the default) and 'skins'.
+        *
+        * @param string $directory Directory to search in
         * @return array
         */
-       public function findExtensions() {
+       public function findExtensions( $directory = 'extensions' ) {
                if ( $this->getVar( 'IP' ) === null ) {
                        return array();
                }
 
-               $extDir = $this->getVar( 'IP' ) . '/extensions';
+               $extDir = $this->getVar( 'IP' ) . '/' . $directory;
                if ( !is_readable( $extDir ) || !is_dir( $extDir ) ) {
                        return array();
                }