A few more ok -> done
[lhc/web/wiklou.git] / includes / installer / Installer.php
index 58ce470..d8afba1 100644 (file)
@@ -97,13 +97,16 @@ abstract class Installer {
                'envCheckPCRE',
                'envCheckMemory',
                'envCheckCache',
+               'envCheckModSecurity',
                'envCheckDiff3',
                'envCheckGraphics',
+               'envCheckServer',
                'envCheckPath',
                'envCheckExtension',
                'envCheckShellLocale',
                'envCheckUploadsDirectory',
-               'envCheckLibicu'
+               'envCheckLibicu',
+               'envCheckSuhosinMaxValueLength',
        );
 
        /**
@@ -130,6 +133,7 @@ abstract class Installer {
                'wgDiff3',
                'wgImageMagickConvertCommand',
                'IP',
+               'wgServer',
                'wgScriptPath',
                'wgScriptExtension',
                'wgMetaNamespace',
@@ -141,6 +145,7 @@ abstract class Installer {
                'wgUseInstantCommons',
                'wgUpgradeKey',
                'wgDefaultSkin',
+               'wgResourceLoaderMaxQueryLength',
        );
 
        /**
@@ -159,7 +164,6 @@ abstract class Installer {
                '_UpgradeDone' => false,
                '_InstallDone' => false,
                '_Caches' => array(),
-               '_InstallUser' => 'root',
                '_InstallPassword' => '',
                '_SameAccount' => true,
                '_CreateDBAccount' => false,
@@ -236,6 +240,10 @@ abstract class Installer {
         * @var array
         */
        public $licenses = array(
+               'cc-by' => array(
+                       'url' => 'http://creativecommons.org/licenses/by/3.0/',
+                       'icon' => '{$wgStylePath}/common/images/cc-by.png',
+               ),
                'cc-by-sa' => array(
                        'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
                        'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
@@ -249,14 +257,10 @@ abstract class Installer {
                        'icon' => '{$wgStylePath}/common/images/cc-0.png',
                ),
                'pd' => array(
-                       'url' => 'http://creativecommons.org/licenses/publicdomain/',
+                       'url' => '',
                        'icon' => '{$wgStylePath}/common/images/public-domain.png',
                ),
-               'gfdl-old' => array(
-                       'url' => 'http://www.gnu.org/licenses/old-licenses/fdl-1.2.html',
-                       'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
-               ),
-               'gfdl-current' => array(
+               'gfdl' => array(
                        'url' => 'http://www.gnu.org/copyleft/fdl.html',
                        'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
                ),
@@ -329,12 +333,14 @@ abstract class Installer {
                        $this->settings[$var] = $GLOBALS[$var];
                }
 
+               $compiledDBs = array();
                foreach ( self::getDBTypes() as $type ) {
                        $installer = $this->getDBInstaller( $type );
 
                        if ( !$installer->isCompiled() ) {
                                continue;
                        }
+                       $compiledDBs[] = $type;
 
                        $defaults = $installer->getGlobalDefaults();
 
@@ -346,6 +352,7 @@ abstract class Installer {
                                }
                        }
                }
+               $this->setVar( '_CompiledDBs', $compiledDBs );
 
                $this->parserTitle = Title::newFromText( 'Installer' );
                $this->parserOptions = new ParserOptions; // language will  be wrong :(
@@ -454,7 +461,7 @@ abstract class Installer {
         *
         * @return Array
         */
-       public function getExistingLocalSettings() {
+       public static function getExistingLocalSettings() {
                global $IP;
 
                wfSuppressWarnings();
@@ -618,21 +625,15 @@ abstract class Installer {
        protected function envCheckDB() {
                global $wgLang;
 
-               $compiledDBs = array();
                $allNames = array();
 
                foreach ( self::getDBTypes() as $name ) {
-                       if ( $this->getDBInstaller( $name )->isCompiled() ) {
-                               $compiledDBs[] = $name;
-                       }
-                       $allNames[] = wfMsg( 'config-type-' . $name );
+                       $allNames[] = wfMsg( "config-type-$name" );
                }
 
-               $this->setVar( '_CompiledDBs', $compiledDBs );
-
-               if ( !$compiledDBs ) {
+               if ( !$this->getVar( '_CompiledDBs' ) ) {
                        $this->showError( 'config-no-db', $wgLang->commaList( $allNames ) );
-                       // FIXME: this only works for the web installer!
+                       // @todo FIXME: This only works for the web installer!
                        return false;
                }
 
@@ -649,7 +650,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' );
                }
        }
@@ -788,6 +789,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;
                        }
                }
@@ -799,6 +803,15 @@ abstract class Installer {
                $this->setVar( '_Caches', $caches );
        }
 
+       /**
+        * Scare user to death if they have mod_security
+        */
+       protected function envCheckModSecurity() {
+               if ( self::apacheModulePresent( 'mod_security' ) ) {
+                       $this->showMessage( 'config-mod-security' );
+               }
+       }
+
        /**
         * Search for GNU diff3.
         */
@@ -836,39 +849,37 @@ abstract class Installer {
                }
        }
 
+       /**
+        * Environment check for the server hostname.
+        */
+       protected function envCheckServer() {
+               if ( $this->getVar( 'wgServer' ) ) {
+                       // wgServer was pre-defined, perhaps by the cli installer
+                       $server = $this->getVar( 'wgServer' );
+               } else {
+                       $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;
        }
 
        /**
         * Environment check for setting the preferred PHP file extension.
         */
        protected function envCheckExtension() {
-               // FIXME: detect this properly
+               // @todo FIXME: Detect this properly
                if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
                        $ext = 'php5';
                } else {
@@ -954,10 +965,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 ) {
@@ -967,6 +978,24 @@ abstract class Installer {
                }
        }
 
+       /**
+        * Checks if suhosin.get.max_value_length is set, and if so, sets
+        * $wgResourceLoaderMaxQueryLength to that value in the generated
+        * LocalSettings file
+        */
+       protected function envCheckSuhosinMaxValueLength() {
+               $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
+               if ( $maxValueLength > 0 ) {
+                       if( $maxValueLength < 1024 ) {
+                               # Only warn if the value is below the sane 1024
+                               $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
+                       }
+               } else {
+                       $maxValueLength = -1;
+               }
+               $this->setVar( 'wgResourceLoaderMaxQueryLength', $maxValueLength );
+       }
+
        /**
         * Convert a hex string representing a Unicode code point to that code point.
         * @param $c String
@@ -976,12 +1005,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);
@@ -1017,7 +1046,7 @@ abstract class Installer {
                 */
                if( $utf8 ) {
                        $useNormalizer = 'utf8';
-                       $utf8 = utf8_normalize( $not_normal_c, UNORM_NFC );
+                       $utf8 = utf8_normalize( $not_normal_c, UtfNormal::UNORM_NFC );
                        if ( $utf8 !== $normal_c ) $needsUpdate = true;
                }
                if( $intl ) {
@@ -1097,6 +1126,9 @@ abstract class Installer {
        /**
         * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
         * @see locateExecutable()
+        * @param $names
+        * @param $versionInfo bool
+        * @return bool|string
         */
        public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
                foreach( self::getPossibleBinPaths() as $path ) {
@@ -1133,7 +1165,13 @@ abstract class Installer {
                                        break;
                                }
 
-                               $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
+                               try {
+                                       $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
+                               }
+                               catch( MWException $e ) {
+                                       // Http::get throws with allow_url_fopen = false and no curl extension.
+                                       $text = null;
+                               }
                                unlink( $dir . $file );
 
                                if ( $text == 'exec' ) {
@@ -1148,16 +1186,37 @@ abstract class Installer {
                return false;
        }
 
+       /**
+        * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too.
+        *
+        * @param $moduleName String: Name of module to check.
+        * @return bool
+        */
+       public static function apacheModulePresent( $moduleName ) {
+               if ( function_exists( 'apache_get_modules' ) && in_array( $moduleName, apache_get_modules() ) ) {
+                       return true;
+               }
+               // try it the hard way
+               ob_start();
+               phpinfo( INFO_MODULES );
+               $info = ob_get_clean();
+               return strpos( $info, $moduleName ) !== false;
+       }
+
        /**
         * ParserOptions are constructed before we determined the language, so fix it
+        *
+        * @param $lang Language
         */
        public function setParserLanguage( $lang ) {
                $this->parserOptions->setTargetLanguage( $lang );
-               $this->parserOptions->setUserLang( $lang->getCode() );
+               $this->parserOptions->setUserLang( $lang );
        }
 
        /**
         * Overridden by WebInstaller to provide lastPage parameters.
+        * @param $page stirng
+        * @return string
         */
        protected function getDocUrl( $page ) {
                return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
@@ -1175,11 +1234,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;
                        }
                }
@@ -1196,7 +1258,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
@@ -1208,11 +1269,11 @@ abstract class Installer {
                 */
                global $wgAutoloadClasses;
                $wgAutoloadClasses = array();
-               
+
                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'] ) ?
@@ -1429,15 +1490,21 @@ 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' );
                }
        }
 
        /**
         * Insert Main Page with default content.
         *
+        * @param $installer DatabaseInstaller
         * @return Status
         */
        protected function createMainpage( DatabaseInstaller $installer ) {
@@ -1495,4 +1562,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();
+       }
 }