PHP 5.3.2 might not be out until February, by which time a number of distros will...
[lhc/web/wiklou.git] / config / Installer.php
index 13ccc25..b0739b1 100644 (file)
@@ -44,6 +44,8 @@ require_once( "$IP/includes/ProfilerStub.php" );
 require_once( "$IP/includes/GlobalFunctions.php" );
 require_once( "$IP/includes/Hooks.php" );
 require_once( "$IP/includes/Exception.php" );
+require_once( "$IP/includes/json/Services_JSON.php" );
+require_once( "$IP/includes/json/FormatJson.php" );
 
 # If we get an exception, the user needs to know
 # all the details
@@ -53,41 +55,60 @@ wfInstallExceptionHandler();
 ## Databases we support:
 
 $ourdb = array();
-$ourdb['mysql']['fullname']      = 'MySQL';
-$ourdb['mysql']['havedriver']    = 0;
-$ourdb['mysql']['compile']       = 'mysql';
-$ourdb['mysql']['bgcolor']       = '#ffe5a7';
-$ourdb['mysql']['rootuser']      = 'root';
-
-$ourdb['postgres']['fullname']   = 'PostgreSQL';
-$ourdb['postgres']['havedriver'] = 0;
-$ourdb['postgres']['compile']    = 'pgsql';
-$ourdb['postgres']['bgcolor']    = '#aaccff';
-$ourdb['postgres']['rootuser']   = 'postgres';
-
-$ourdb['sqlite']['fullname']      = 'SQLite';
-$ourdb['sqlite']['havedriver']    = 0;
-$ourdb['sqlite']['compile']       = 'pdo_sqlite';
-$ourdb['sqlite']['bgcolor']       = '#b1ebb1';
-$ourdb['sqlite']['rootuser']      = '';
-
-$ourdb['mssql']['fullname']      = 'MSSQL';
-$ourdb['mssql']['havedriver']    = 0;
-$ourdb['mssql']['compile']       = 'mssql not ready'; # Change to 'mssql' after includes/DatabaseMssql.php added;
-$ourdb['mssql']['bgcolor']       = '#ffc0cb';
-$ourdb['mssql']['rootuser']      = 'administrator';
-
-$ourdb['ibm_db2']['fullname']   = 'DB2';
-$ourdb['ibm_db2']['havedriver'] = 0;
-$ourdb['ibm_db2']['compile']    = 'ibm_db2';
-$ourdb['ibm_db2']['bgcolor']    = '#ffeba1';
-$ourdb['ibm_db2']['rootuser']   = 'db2admin';
-
-$ourdb['oracle']['fullname']   = 'Oracle';
-$ourdb['oracle']['havedriver'] = 0;
-$ourdb['oracle']['compile']    = 'oci8';
-$ourdb['oracle']['bgcolor']    = '#ffeba1';
-$ourdb['oracle']['rootuser']   = '';
+
+$ourdb['mysql'] = array(
+       'fullname'   => 'MySQL',
+       'havedriver' => 0,
+       'compile'    => 'mysql',
+       'bgcolor'    => '#ffe5a7',
+       'rootuser'   => 'root',
+       'serverless' => false
+);
+
+$ourdb['postgres'] = array(
+       'fullname'   => 'PostgreSQL',
+       'havedriver' => 0,
+       'compile'    => 'pgsql',
+       'bgcolor'    => '#aaccff',
+       'rootuser'   => 'postgres',
+       'serverless' => false
+);
+
+$ourdb['sqlite'] = array(
+       'fullname'   => 'SQLite',
+       'havedriver' => 0,
+       'compile'    => 'pdo_sqlite',
+       'bgcolor'    => '#b1ebb1',
+       'rootuser'   => '',
+       'serverless' =>  true
+);
+
+$ourdb['mssql'] = array(
+       'fullname'   => 'MSSQL',
+       'havedriver' => 0,
+       'compile'    => 'mssql_not_ready', # Change to 'mssql' after includes/DatabaseMssql.php added;
+       'bgcolor'    => '#ffc0cb',
+       'rootuser'   => 'administrator',
+       'serverless' => false
+);
+
+$ourdb['ibm_db2'] = array(
+       'fullname'   => 'DB2',
+       'havedriver' => 0,
+       'compile'    => 'ibm_db2',
+       'bgcolor'    => '#ffeba1',
+       'rootuser'   => 'db2admin',
+       'serverless' => false
+);
+
+$ourdb['oracle'] = array(
+       'fullname'   => 'Oracle',
+       'havedriver' => 0,
+       'compile'    => 'oci8',
+       'bgcolor'    => '#ffeba1',
+       'rootuser'   => 'sys',
+       'serverless' => false
+);
 
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -178,6 +199,7 @@ $ourdb['oracle']['rootuser']   = '';
                        font-size: 110%;
                        color: green;
                }
+
                .success-box {
                        font-size: 130%;
                }
@@ -185,23 +207,25 @@ $ourdb['oracle']['rootuser']   = '';
        </style>
        <script type="text/javascript">
        <!--
+       <?php echo 'var databases = ' . FormatJson::encode( $ourdb ) . ';'; ?>
+       
+       function show(id, showOrHide) {
+               var i = document.getElementById(id);
+               if (i) i.style.display = showOrHide ? 'block' : 'none';
+       }
        function hideall() {
-               <?php foreach (array_keys($ourdb) as $db) {
-               echo "\n                var i = document.getElementById('$db'); if (i) i.style.display='none';";
+               for (db in databases) {
+                       show(db, false);
                }
-               ?>
-
        }
-       function toggleDBarea(id,defaultroot) {
+       function toggleDBarea(id, defaultroot) {
                hideall();
                var dbarea = document.getElementById(id);
                if (dbarea) dbarea.style.display = (dbarea.style.display == 'none') ? 'block' : 'none';
                var db = document.getElementById('RootUser');
-               if (defaultroot) {
-<?php foreach (array_keys($ourdb) as $db) {
-                       echo "                  if (id == '$db') { db.value = '".$ourdb[$db]['rootuser']."';}\n";
-}?>
-               }
+               db.value = databases[id].rootuser;
+               show('db-server-settings1', !databases[id].serverless);
+               show('db-server-settings2', !databases[id].serverless);
        }
        // -->
        </script>
@@ -395,7 +419,6 @@ if( wfIniGetBool( "zend.ze1_compatibility_mode" ) ) {
        <?php
 }
 
-
 if( $fatal ) {
        dieout( "Cannot install MediaWiki." );
 }
@@ -509,24 +532,6 @@ if( !( $conf->turck || $conf->eaccel || $conf->apc || $conf->xcache ) ) {
                cannot use these for object caching.</li>' );
 }
 
-$conf->phpCliPath = false;
-$phpClilocations = array_merge(
-       array(
-               "/usr/bin",
-               "/usr/local/bin",
-               "/opt/csw/bin",
-               "/usr/gnu/bin",
-               "/usr/sfw/bin" ),
-       explode( PATH_SEPARATOR, getenv( "PATH" ) ) );
-$phpClinames = array( "php", "php.exe" );
-foreach ($phpClilocations as $loc) {
-       $exe = locate_executable($loc, $phpClinames);
-       if ($exe !== false) {
-               $conf->phpCliPath= $exe;
-               break;
-       }
-}
-
 $conf->diff3 = false;
 $diff3locations = array_merge(
        array(
@@ -664,17 +669,19 @@ $errs = array();
 if( preg_match( '/^$|^mediawiki$|#/i', $conf->Sitename ) ) {
        $errs["Sitename"] = "Must not be blank or \"MediaWiki\" and may not contain \"#\"";
 }
-if( $conf->DBuser == "" ) {
-       $errs["DBuser"] = "Must not be blank";
-}
-if( ($conf->DBtype == 'mysql') && (strlen($conf->DBuser) > 16) ) {
-       $errs["DBuser"] = "Username too long";
-}
-if( $conf->DBpassword == "" && $conf->DBtype != "postgres" ) {
-       $errs["DBpassword"] = "Must not be blank";
-}
-if( $conf->DBpassword != $conf->DBpassword2 ) {
-       $errs["DBpassword2"] = "Passwords don't match!";
+if( !$ourdb[$conf->DBtype]['serverless'] ) {
+       if( $conf->DBuser == "" ) {
+               $errs["DBuser"] = "Must not be blank";
+       }
+       if( ($conf->DBtype == 'mysql') && (strlen($conf->DBuser) > 16) ) {
+               $errs["DBuser"] = "Username too long";
+       }
+       if( $conf->DBpassword == "" && $conf->DBtype != "postgres" ) {
+               $errs["DBpassword"] = "Must not be blank";
+       }
+       if( $conf->DBpassword != $conf->DBpassword2 ) {
+               $errs["DBpassword2"] = "Passwords don't match!";
+       }
 }
 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
        $errs["DBprefix"] = "Invalid table prefix";
@@ -949,8 +956,8 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        if ("$wgSQLiteDataDir" == '') {
                                $wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data';
                        }
-                       echo "<li>Attempting to connect to SQLite database at \"" . 
-                               htmlspecialchars( $wgSQLiteDataDir ) .  "\"";
+                       echo '<li>Attempting to connect to SQLite database at "' . 
+                               htmlspecialchars( $wgSQLiteDataDir ) . '": ';
                        if ( !is_dir( $wgSQLiteDataDir ) ) {
                                if ( is_writable( dirname( $wgSQLiteDataDir ) ) ) {
                                        $ok = wfMkdirParents( $wgSQLiteDataDir, $wgSQLiteDataDirMode );
@@ -958,25 +965,40 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                        $ok = false;
                                }
                                if ( !$ok ) {
-                                       echo "cannot create data directory</li>";
+                                       echo "cannot create data directory</li>";
                                        $errs['SQLiteDataDir'] = 'Enter a valid data directory';
                                        continue;
                                }
                        }
                        if ( !is_writable( $wgSQLiteDataDir ) ) {
-                               echo "data directory not writable</li>";
+                               echo "data directory not writable</li>";
                                $errs['SQLiteDataDir'] = 'Enter a writable data directory';
                                continue;
                        }
-                       $dataFile = "$wgSQLiteDataDir/$wgDBname.sqlite";
-                       if ( file_exists( $dataFile ) && !is_writable( $dataFile ) ) {
-                               echo ": data file not writable</li>";
-                               $errs['SQLiteDataDir'] = "$wgDBname.sqlite is not writable";
+                       $dataFile = DatabaseSqlite::generateFileName( $wgSQLiteDataDir, $wgDBname );
+                       if ( file_exists( $dataFile ) ) {
+                               if ( !is_writable( $dataFile ) ) {
+                                       echo "data file not writable</li>";
+                                       $errs['SQLiteDataDir'] = basename( $dataFile ) . " is not writable";
+                                       continue;
+                               }
+                       } else {
+                               if ( file_put_contents( $dataFile, '' ) === false ) {
+                                       echo 'could not create database file "' . htmlspecialchars( basename( $dataFile ) ) . "\"</li>\n";
+                                       $errs['SQLiteDataDir'] = "couldn't create " . basename( $dataFile );
+                                       continue;
+                               }
+                       }
+                       try {
+                               $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 );
+                       }
+                       catch( MWException $ex ) {
+                               echo 'error: ' . htmlspecialchars( $ex->getMessage() ) . "</li>\n";
                                continue;
                        }
-                       $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 );
+                       
                        if (!$wgDatabase->isOpen()) {
-                               print "error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
+                               print "error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
                                $errs['SQLiteDataDir'] = 'Could not connect to database';
                                continue;
                        } else {
@@ -986,7 +1008,10 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        echo "ok</li>\n";
                } elseif ( $conf->DBtype == 'oracle' ) {
                        echo "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) ."\"</li>";
+                       $old_error_level = error_reporting();
+                       error_reporting($old_error_level & ~E_WARNING); //disable E_WARNING for test connect (oci returns login denied as warning)
                        $wgDatabase = $dbc->newFromParams('DUMMY', $wgDBuser, $wgDBpassword, $wgDBname, 1);
+                       error_reporting($old_error_level);
                        if (!$wgDatabase->isOpen()) {
                                $ok = true;
                                echo "<li>Connect failed.</li>";
@@ -1227,7 +1252,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        print " done.</li>\n";
                        
                
-                       if ($conf->DBtype == 'ibm_db2') {
+                       if ( $conf->DBtype == 'ibm_db2' ) {
                                // Now that table creation is done, make sure everything is committed
                                // Do this before doing inserts through API
                                if ($wgDatabase->lastError()) {
@@ -1238,6 +1263,10 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                        print "<li>MediaWiki tables successfully created</li>\n";
                                        $wgDatabase->commit();
                                }
+                       } elseif ( $conf->DBtype == 'sqlite' ) {
+                               // Ensure proper searchindex format. We have to do that separately because
+                               // if SQLite is compiled without the FTS3 module, table creation syntax will be invalid.
+                               sqlite_setup_searchindex();
                        }
 
                        print "<li>Initializing statistics...</li>\n";
@@ -1466,7 +1495,7 @@ if( count( $errs ) ) {
                <br /><br />
                MediaWiki can also detect and support eAccelerator, Turck MMCache, APC, and XCache, but
                these should not be used if the wiki will be running on multiple application servers.
-               <br/><br/>
+               <br /><br />
                DBA (Berkeley-style DB) is generally slower than using no cache at all, and is only 
                recommended for testing.
        </p>
@@ -1543,38 +1572,42 @@ if( count( $errs ) ) {
        ?></ul>
        </div>
 
-       <div class="config-input" style="clear:left">
-       <?php aField( $conf, "DBserver", "Database host:" ); ?>
+       <div id="db-server-settings1">
+               <div class="config-input" style="clear:left">
+               <?php aField( $conf, "DBserver", "Database host:" ); ?>
+               </div>
+               <p class="config-desc">
+                       If your database server isn't on your web server, enter the name or IP address here.
+               </p>
        </div>
-       <p class="config-desc">
-               If your database server isn't on your web server, enter the name or IP address here.
-       </p>
-
-       <div class="config-input"><?php aField( $conf, "DBname", "Database name:" ); ?></div>
-       <div class="config-input"><?php aField( $conf, "DBuser", "DB username:" ); ?></div>
-       <div class="config-input"><?php aField( $conf, "DBpassword", "DB password:", "password" ); ?></div>
-       <div class="config-input"><?php aField( $conf, "DBpassword2", "DB password confirm:", "password" ); ?></div>
-       <p class="config-desc">
-               If you only have a single user account and database available,
-               enter those here. If you have database root access (see below)
-               you can specify new accounts/databases to be created. This account 
-               will not be created if it pre-exists. If this is the case, ensure that it
-               has SELECT, INSERT, UPDATE, and DELETE permissions on the MediaWiki database.
-       </p>
 
-       <div class="config-input">
-               <label class="column">Superuser account:</label>
-               <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?> />
-               &nbsp;<label for="useroot">Use superuser account</label>
+               <div class="config-input"><?php aField( $conf, "DBname", "Database name:" ); ?></div>
+       <div id="db-server-settings2">
+               <div class="config-input"><?php aField( $conf, "DBuser", "DB username:" ); ?></div>
+               <div class="config-input"><?php aField( $conf, "DBpassword", "DB password:", "password" ); ?></div>
+               <div class="config-input"><?php aField( $conf, "DBpassword2", "DB password confirm:", "password" ); ?></div>
+               <p class="config-desc">
+                       If you only have a single user account and database available,
+                       enter those here. If you have database root access (see below)
+                       you can specify new accounts/databases to be created. This account 
+                       will not be created if it pre-exists. If this is the case, ensure that it
+                       has SELECT, INSERT, UPDATE, and DELETE permissions on the MediaWiki database.
+               </p>
+
+               <div class="config-input">
+                       <label class="column">Superuser account:</label>
+                       <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?> />
+                       &nbsp;<label for="useroot">Use superuser account</label>
+               </div>
+               <div class="config-input"><?php aField( $conf, "RootUser", "Superuser name:", "text" ); ?></div>
+               <div class="config-input"><?php aField( $conf, "RootPW", "Superuser password:", "password" ); ?></div>
+
+               <p class="config-desc">
+                       If the database user specified above does not exist, or does not have access to create
+                       the database (if needed) or tables within it, please check the box and provide details
+                       of a superuser account, such as <strong>root</strong>, which does.
+               </p>
        </div>
-       <div class="config-input"><?php aField( $conf, "RootUser", "Superuser name:", "text" ); ?></div>
-       <div class="config-input"><?php aField( $conf, "RootPW", "Superuser password:", "password" ); ?></div>
-
-       <p class="config-desc">
-               If the database user specified above does not exist, or does not have access to create
-               the database (if needed) or tables within it, please check the box and provide details
-               of a superuser account, such as <strong>root</strong>, which does.
-       </p>
 
        <?php database_switcher('mysql'); ?>
        <div class="config-input"><?php aField( $conf, "DBprefix", "Database table prefix:" ); ?></div>
@@ -1608,9 +1641,9 @@ if( count( $errs ) ) {
        </div>
        <p class="config-desc">
                This option is ignored on upgrade, the same character set will be kept. 
-               <br/><br/>
+               <br /><br />
                <b>WARNING:</b> If you use <b>backwards-compatible UTF-8</b> on MySQL 4.1+, and subsequently back up the database with <tt>mysqldump</tt>, it may destroy all non-ASCII characters, irreversibly corrupting your backups!.
-               <br/><br/>
+               <br /><br />
                In <b>binary mode</b>, MediaWiki stores UTF-8 text to the database in binary fields. This is more efficient than MySQL's UTF-8 mode, and allows you to use the full range of Unicode characters. In <b>UTF-8 mode</b>, MySQL will know what character set your data is in, and can present and convert it appropriately, but it won't let you store characters above the <a target="_blank" href="http://en.wikipedia.org/wiki/Mapping_of_Unicode_character_planes">Basic Multilingual Plane</a>.
        </p>
        </fieldset>
@@ -1627,9 +1660,6 @@ if( count( $errs ) ) {
        </fieldset>
 
        <?php database_switcher('sqlite'); ?>
-       <div class="config-desc">
-               <b>NOTE:</b> SQLite only uses the <i>Database name</i> setting above, the user, password and root settings are ignored.
-       </div>
        <div class="config-input"><?php
                aField( $conf, "SQLiteDataDir", "SQLite data directory:" );
        ?></div>
@@ -1914,6 +1944,13 @@ if ( \$wgCommandLineMode ) {
 \$wgScriptPath       = \"{$slconf['ScriptPath']}\";
 \$wgScriptExtension  = \"{$slconf['ScriptExtension']}\";
 
+## The relative URL path to the skins directory 
+\$wgStylePath        = \"\$wgScriptPath/skins\";
+
+## The relative URL path to the logo.  Make sure you change this from the default,
+## or else you'll overwrite your logo when you upgrade!
+\$wgLogo             = \"\$wgStylePath/common/images/wiki.png\";
+
 ## UPO means: this is also a user preference option
 
 \$wgEnableEmail      = $enableemail;
@@ -1987,8 +2024,6 @@ if ( \$wgCommandLineMode ) {
 
 \$wgDiff3 = \"{$slconf['diff3']}\";
 
-\$wgPhpCliPath = \"{$slconf['phpCliPath']}\";
-
 # When you make changes to this configuration file, this will make
 # sure that cached pages are cleared.
 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
@@ -2082,31 +2117,13 @@ function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick =
 }
 
 function getLanguageList() {
-       global $wgLanguageNames, $IP;
-       if( !isset( $wgLanguageNames ) ) {
-               require_once( "$IP/languages/Names.php" );
-       }
+       global $wgDummyLanguageCodes;
 
        $codes = array();
-
-       $d = opendir( "../languages/messages" );
-       /* In case we are called from the root directory */
-       if (!$d)
-               $d = opendir( "languages/messages");
-       while( false !== ($f = readdir( $d ) ) ) {
-               $m = array();
-               if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
-                       $code = str_replace( '_', '-', strtolower( $m[1] ) );
-                       if( $code == 'qqq' ) continue;
-                       if( isset( $wgLanguageNames[$code] ) ) {
-                               $name = wfBCP47( $code ) . ' - ' . $wgLanguageNames[$code];
-                       } else {
-                               $name = $code;
-                       }
-                       $codes[$code] = $name;
-               }
+       foreach ( Language::getLanguageNames() as $code => $name ) {
+               if( in_array( $code, $wgDummyLanguageCodes ) ) continue;
+               $codes[$code] = $code . ' - ' . $name;
        }
-       closedir( $d );
        ksort( $codes );
        return $codes;
 }
@@ -2194,7 +2211,7 @@ function database_switcher($db) {
        global $ourdb;
        $color = $ourdb[$db]['bgcolor'];
        $full = $ourdb[$db]['fullname'];
-       print "<fieldset id='$db'><legend>$full specific options</legend>\n";
+       print "<fieldset id='$db' style='clear:both'><legend>$full-specific options</legend>\n";
 }
 
 function printListItem( $item ) {