* Make envCheckPath() specific to each installer, web vs cli
[lhc/web/wiklou.git] / includes / installer / Installer.php
index bb87390..8a142c0 100644 (file)
@@ -99,6 +99,7 @@ abstract class Installer {
                'envCheckCache',
                'envCheckDiff3',
                'envCheckGraphics',
+               'envCheckServer',
                'envCheckPath',
                'envCheckExtension',
                'envCheckShellLocale',
@@ -131,6 +132,7 @@ abstract class Installer {
                'wgDiff3',
                'wgImageMagickConvertCommand',
                'IP',
+               'wgServer',
                'wgScriptPath',
                'wgScriptExtension',
                'wgMetaNamespace',
@@ -161,7 +163,6 @@ abstract class Installer {
                '_UpgradeDone' => false,
                '_InstallDone' => false,
                '_Caches' => array(),
-               '_InstallUser' => 'root',
                '_InstallPassword' => '',
                '_SameAccount' => true,
                '_CreateDBAccount' => false,
@@ -456,7 +457,7 @@ abstract class Installer {
         *
         * @return Array
         */
-       public function getExistingLocalSettings() {
+       public static function getExistingLocalSettings() {
                global $IP;
 
                wfSuppressWarnings();
@@ -651,7 +652,7 @@ abstract class Installer {
         * Environment check for register_globals.
         */
        protected function envCheckRegisterGlobals() {
-               if( wfIniGetBool( "magic_quotes_runtime" ) ) {
+               if( wfIniGetBool( 'register_globals' ) ) {
                        $this->showMessage( 'config-register-globals' );
                }
        }
@@ -790,6 +791,9 @@ abstract class Installer {
                $caches = array();
                foreach ( $this->objectCaches as $name => $function ) {
                        if ( function_exists( $function ) ) {
+                               if ( $name == 'xcache' && !wfIniGetBool( 'xcache.var_size' ) ) {
+                                       continue;
+                               }
                                $caches[$name] = true;
                        }
                }
@@ -838,32 +842,25 @@ abstract class Installer {
                }
        }
 
+       /**
+        * Environment check for the server hostname.
+        */
+       protected function envCheckServer() {
+               $server = WebRequest::detectServer();
+               $this->showMessage( 'config-using-server', $server );
+               $this->setVar( 'wgServer', $server );
+       }
+
        /**
         * Environment check for setting $IP and $wgScriptPath.
         */
        protected function envCheckPath() {
                global $IP;
                $IP = dirname( dirname( dirname( __FILE__ ) ) );
-
                $this->setVar( 'IP', $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
-               // to get the path to the current script... hopefully it's reliable. SIGH
-               if ( !empty( $_SERVER['PHP_SELF'] ) ) {
-                       $path = $_SERVER['PHP_SELF'];
-               } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
-                       $path = $_SERVER['SCRIPT_NAME'];
-               } elseif ( $this->getVar( 'wgScriptPath' ) ) {
-                       // Some kind soul has set it for us already (e.g. debconf)
-                       return true;
-               } else {
-                       $this->showError( 'config-no-uri' );
-                       return false;
-               }
-
-               $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
-               $this->setVar( 'wgScriptPath', $uri );
+               $this->showMessage( 'config-using-uri', $this->getVar( 'wgServer' ), $this->getVar( 'wgScriptPath' ) );
+               return true;
        }
 
        /**
@@ -956,10 +953,10 @@ abstract class Installer {
         * TODO: document
         */
        protected function envCheckUploadsDirectory() {
-               global $IP, $wgServer;
+               global $IP;
 
                $dir = $IP . '/images/';
-               $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
+               $url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/';
                $safe = !$this->dirIsExecutable( $dir, $url );
 
                if ( $safe ) {
@@ -993,12 +990,12 @@ abstract class Installer {
                $c = hexdec($c);
                if ($c <= 0x7F) {
                        return chr($c);
-               } else if ($c <= 0x7FF) {
+               } elseif ($c <= 0x7FF) {
                        return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
-               } else if ($c <= 0xFFFF) {
+               } elseif ($c <= 0xFFFF) {
                        return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
                                . chr(0x80 | $c & 0x3F);
-               } else if ($c <= 0x10FFFF) {
+               } elseif ($c <= 0x10FFFF) {
                        return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
                                . chr(0x80 | $c >> 6 & 0x3F)
                                . chr(0x80 | $c & 0x3F);
@@ -1173,6 +1170,8 @@ abstract class Installer {
 
        /**
         * ParserOptions are constructed before we determined the language, so fix it
+        *
+        * @param $lang Language
         */
        public function setParserLanguage( $lang ) {
                $this->parserOptions->setTargetLanguage( $lang );
@@ -1198,11 +1197,14 @@ abstract class Installer {
                }
 
                $exts = array();
-               $dir = $this->getVar( 'IP' ) . '/extensions';
-               $dh = opendir( $dir );
+               $extDir = $this->getVar( 'IP' ) . '/extensions';
+               $dh = opendir( $extDir );
 
                while ( ( $file = readdir( $dh ) ) !== false ) {
-                       if( file_exists( "$dir/$file/$file.php" ) ) {
+                       if( !is_dir( "$extDir/$file" ) ) {
+                               continue;
+                       }
+                       if( file_exists( "$extDir/$file/$file.php" ) ) {
                                $exts[] = $file;
                        }
                }
@@ -1219,7 +1221,6 @@ abstract class Installer {
                global $IP;
                $exts = $this->getVar( '_Extensions' );
                $IP = $this->getVar( 'IP' );
-               $path = $IP . '/extensions';
 
                /**
                 * We need to include DefaultSettings before including extensions to avoid
@@ -1235,7 +1236,7 @@ abstract class Installer {
                require( "$IP/includes/DefaultSettings.php" );
 
                foreach( $exts as $e ) {
-                       require_once( "$path/$e/$e.php" );
+                       require_once( "$IP/extensions/$e/$e.php" );
                }
 
                $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
@@ -1452,9 +1453,14 @@ abstract class Installer {
                        $params['language'] = $myLang;
                }
 
-               $res = Http::post( $this->mediaWikiAnnounceUrl, array( 'postData' => $params ) );
-               if( !$res ) {
-                       $s->warning( 'config-install-subscribe-fail' );
+               if( MWHttpRequest::canMakeRequests() ) {
+                       $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl,
+                               array( 'method' => 'POST', 'postData' => $params ) )->execute();
+                       if( !$res->isOK() ) {
+                               $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
+                       }
+               } else {
+                       $s->warning( 'config-install-subscribe-notpossible' );
                }
        }
 
@@ -1518,4 +1524,14 @@ abstract class Installer {
        public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
                $this->extraInstallSteps[$findStep][] = $callback;
        }
+
+       /**
+        * Disable the time limit for execution.
+        * Some long-running pages (Install, Upgrade) will want to do this
+        */
+       protected function disableTimeLimit() {
+               wfSuppressWarnings();
+               set_time_limit( 0 );
+               wfRestoreWarnings();
+       }
 }