bring $wgCompressRevisions comment in line with post-1.4 behavior
[lhc/web/wiklou.git] / config / index.php
index 20c1581..3f66337 100644 (file)
@@ -153,6 +153,15 @@ $ourdb['postgres']['rootuser']   = 'postgres';
                        font-size: 85%;
                        padding-top: 3em;
                }
+               
+               span.success-message {
+                       font-weight: bold;
+                       font-size: 110%;
+                       color: green;
+               }
+               .success-box {
+                       font-size: 130%;
+               }
 
        </style>
        <script type="text/javascript">
@@ -192,7 +201,8 @@ $ourdb['postgres']['rootuser']   = 'postgres';
 /* Check for existing configurations and bug out! */
 
 if( file_exists( "../LocalSettings.php" ) ) {
-       dieout( "<p><strong>Setup has completed, <a href='../index.php'>your wiki</a> is configured.</strong></p>
+       $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
+ dieout( "<p><strong>Setup has completed, <a href='../$script'>your wiki</a> is configured.</strong></p>
 
        <p>Please delete the /config directory for extra security.</p></div></div></div></div>" );
 }
@@ -234,21 +244,26 @@ class ConfigData {
        function getSysopName() { return $this->getEncoded( $this->SysopName ); }
        function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
 
-       function setSchema( $schema ) {
+       function setSchema( $schema, $engine ) {
                $this->DBschema = $schema;
+               if ( !preg_match( '/^\w*$/', $engine ) ){
+                       $engine = 'InnoDB';
+               }
                switch ( $this->DBschema ) {
                        case 'mysql5':
-                               $this->DBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=utf8';
+                               $this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=utf8";
                                $this->DBmysql5 = 'true';
                                break;
                        case 'mysql5-binary':
-                               $this->DBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=binary';
+                               $this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=binary";
                                $this->DBmysql5 = 'true';
                                break;
                        default:
-                               $this->DBTableOptions = 'TYPE=InnoDB';
+                               $this->DBTableOptions = "TYPE=$engine";
                                $this->DBmysql5 = 'false';
                }
+               $this->DBengine = $engine;
+
                # Set the global for use during install
                global $wgDBTableOptions;
                $wgDBTableOptions = $this->DBTableOptions;
@@ -303,15 +318,16 @@ if (!$phpdatabases) {
 }
 
 print "<li>Found database drivers for:";
+$DefaultDBtype = '';
 foreach (array_keys($ourdb) AS $db) {
        if ($ourdb[$db]['havedriver']) {
-               $DefaultDBtype = $db;
+               if ( $DefaultDBtype == '' ) {
+                       $DefaultDBtype = $db;
+               }
                print "  ".$ourdb[$db]['fullname'];
        }
 }
 print "</li>\n";
-if (count($phpdatabases) != 1)
-       $DefaultDBtype = '';
 
 if( ini_get( "register_globals" ) ) {
        ?>
@@ -378,10 +394,11 @@ if( ini_get( "safe_mode" ) ) {
 
 $sapi = php_sapi_name();
 print "<li>PHP server API is $sapi; ";
+$script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
 if( $wgUsePathInfo ) {
      print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
print "ok, using pretty URLs (<tt>$script/Page_Title</tt>)";
 } else {
-       print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
+       print "using ugly URLs (<tt>$script?title=Page_Title</tt>)";
 }
 print "</li>\n";
 
@@ -534,6 +551,18 @@ $path = ($_SERVER["PHP_SELF"] === '')
 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $path );
 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
 
+
+
+// We may be installing from *.php5 extension file, if so, print message
+$conf->ScriptExtension = '.php';
+if (defined('MW_INSTALL_PHP5_EXT')) {
+    $conf->ScriptExtension = '.php5';
+    print "<li>Installing MediaWiki with <tt>php5</tt> file extensions</li>\n";
+} else {
+    print "<li>Installing MediaWiki with <tt>php</tt> file extensions</li>\n";
+}
+
+
 print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\n";
        $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
 
@@ -561,7 +590,9 @@ print "<li style='font-weight:bold;color:green;font-size:110%'>Environment check
 
        ## MySQL specific:
        $conf->DBprefix     = importPost( "DBprefix" );
-       $conf->setSchema( importPost( "DBschema", "mysql4" ) );
+       $conf->setSchema( 
+               importPost( "DBschema", "mysql4" ), 
+               importPost( "DBengine", "InnoDB" ) );
 
        ## Postgres specific:
        $conf->DBport      = importPost( "DBport",      "5432" );
@@ -614,7 +645,7 @@ $wgAuth = new AuthPlugin();
 if( $conf->SysopName ) {
        # Check that the user can be created
        $u = User::newFromName( $conf->SysopName );
-       if( $u instanceof User ) {
+       if( is_a($u, 'User') ) { // please do not use instanceof, it breaks PHP4
                # Various password checks
                if( $conf->SysopPass != '' ) {
                        if( $conf->SysopPass == $conf->SysopPass2 ) {
@@ -885,7 +916,6 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
 
                        if ( $conf->DBtype == 'mysql') {
-
                                # Determine existing default character set
                                if ( $wgDatabase->tableExists( "revision" ) ) {
                                        $revision = $wgDatabase->escapeLike( $conf->DBprefix . 'revision' );
@@ -894,21 +924,35 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                        if ( !$row ) {
                                                echo "<li>SHOW TABLE STATUS query failed!</li>\n";
                                                $existingSchema = false;
-                                       } elseif ( preg_match( '/^latin1/', $row->Collation ) ) {
-                                               $existingSchema = 'mysql4';
-                                       } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
-                                               $existingSchema = 'mysql5';
-                                       } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
-                                               $existingSchema = 'mysql5-binary';
+                                               $existingEngine = false;
                                        } else {
-                                               $existingSchema = false;
-                                               echo "<li><strong>Warning:</strong> Unrecognised existing collation</li>\n";
+                                               if ( preg_match( '/^latin1/', $row->Collation ) ) {
+                                                       $existingSchema = 'mysql4';
+                                               } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
+                                                       $existingSchema = 'mysql5';
+                                               } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
+                                                       $existingSchema = 'mysql5-binary';
+                                               } else {
+                                                       $existingSchema = false;
+                                                       echo "<li><strong>Warning:</strong> Unrecognised existing collation</li>\n";
+                                               }
+                                               if ( isset( $row->Engine ) ) {
+                                                       $existingEngine = $row->Engine;
+                                               } else {
+                                                       $existingEngine = $row->Type;
+                                               }
                                        }
                                        if ( $existingSchema && $existingSchema != $conf->DBschema ) {
                                                print "<li><strong>Warning:</strong> you requested the {$conf->DBschema} schema, " .
                                                        "but the existing database has the $existingSchema schema. This upgrade script ". 
                                                        "can't convert it, so it will remain $existingSchema.</li>\n";
-                                               $conf->setSchema( $existingSchema );
+                                               $conf->setSchema( $existingSchema, $conf->DBengine );
+                                       }
+                                       if ( $existingEngine && $existingEngine != $conf->DBengine ) {
+                                               print "<li><strong>Warning:</strong> you requested the {$conf->DBengine} storage " .
+                                                       "engine, but the existing database uses the $existingEngine engine. This upgrade " .
+                                                       "script can't convert it, so it will remain $existingEngine.</li>\n";
+                                               $conf->setSchema( $conf->DBschema, $existingEngine );
                                        }
                                }
 
@@ -936,6 +980,24 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        print "</pre>\n";
                        print "<ul><li>Finished update checks.</li>\n";
                } else {
+                       # Determine available storage engines if possible
+                       if ( $conf->DBtype == 'mysql' && version_compare( $myver, "4.1.2", "ge" ) ) {
+                               $res = $wgDatabase->query( 'SHOW ENGINES' );
+                               $found = false;
+                               while ( $row = $wgDatabase->fetchObject( $res ) ) {
+                                       if ( $row->Engine == $conf->DBengine ) {
+                                               $found = true;
+                                               break;
+                                       }
+                               }
+                               $wgDatabase->freeResult( $res );
+                               if ( !$found && $conf->DBengine != 'MyISAM' ) {
+                                       echo "<li><strong>Warning:</strong> {$conf->DBengine} storage engine not available, " .
+                                               "using MyISAM instead</li>\n";
+                                       $conf->setSchema( $conf->DBschema, 'MyISAM' );
+                               }
+                       }
+
                        # FIXME: Check for errors
                        print "<li>Creating tables...";
                        if ($conf->DBtype == 'mysql') {
@@ -1025,13 +1087,13 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                }
                if(fwrite( $f, $localSettings ) ) {
                        fclose( $f );
+                       print "</li></ul><hr/>\n";
                        writeSuccessMessage();
                } else {
                        fclose( $f );
                        die("<p class='error'>An error occured while writing the config/LocalSettings.php file. Check user rights and disk space then try again.</p>\n");
-
+                       print "</li></ul>\n";
                }
-               print "</li>\n";
 
        } while( false );
 }
@@ -1049,7 +1111,7 @@ if( count( $errs ) ) {
        }
 ?>
 
-<form action="index.php" name="config" method="post">
+<form action="<?php echo defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php'; ?>" name="config" method="post">
 
 
 <h2>Site config</h2>
@@ -1100,7 +1162,8 @@ if( count( $errs ) ) {
                <li><?php
                        aField( $conf, "License", "A Creative Commons license - ", "radio", "cc" );
                        $partner = "MediaWiki";
-                       $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
+   $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
+                       $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/$script?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
                        $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
                        $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
                        print "<a href=\"$ccApp\" target='_blank'>choose</a>";
@@ -1303,7 +1366,19 @@ if( count( $errs ) ) {
                <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
        </div>
 
-       <div class="config-input"><label class="column">Database charset</label>
+       <div class="config-input"><label class="column">Storage Engine</label>
+               <div>Select one:</div>
+               <ul class="plain">
+               <li><?php aField( $conf, "DBengine", "InnoDB", "radio", "InnoDB" ); ?></li>
+               <li><?php aField( $conf, "DBengine", "MyISAM", "radio", "MyISAM" ); ?></li>
+               </ul>
+       </div>
+       <p class="config-desc">
+               InnoDB is best for public web installations, since it has good concurrency 
+               support. MyISAM may be faster in single-user installations. MyISAM databases 
+               tend to get corrupted more often than InnoDB databases.
+       </p>
+       <div class="config-input"><label class="column">Database character set</label>
                <div>Select one:</div>
                <ul class="plain">
                <li><?php aField( $conf, "DBschema", "Backwards-compatible UTF-8", "radio", "mysql4" ); ?></li>
@@ -1334,7 +1409,7 @@ if( count( $errs ) ) {
                so it is recommended that you create a new user. The above schemas are generally correct: 
         only change them if you are sure you need to.</p>
        </div>
-       </div>
+       </fieldset>
 
        <div class="config-input" style="padding:2em 0 3em">
                <label class='column'>&nbsp;</label>
@@ -1358,24 +1433,35 @@ window.onload = toggleDBarea('<?php echo $conf->DBtype; ?>',
 
 /* -------------------------------------------------------------------------------------- */
 function writeSuccessMessage() {
+ $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
        if ( ini_get( 'safe_mode' ) && !ini_get( 'open_basedir' ) ) {
                echo <<<EOT
+<div class="success-box">
 <p>Installation successful!</p>
 <p>To complete the installation, please do the following:
 <ol>
        <li>Download config/LocalSettings.php with your FTP client or file manager</li>
        <li>Upload it to the parent directory</li>
        <li>Delete config/LocalSettings.php</li>
-       <li>Start using <a href='../index.php'>your wiki</a>!
+       <li>Start using <a href='../$script'>your wiki</a>!
 </ol>
 <p>If you are in a shared hosting environment, do <strong>not</strong> just move LocalSettings.php
 remotely. LocalSettings.php is currently owned by the user your webserver is running under,
 which means that anyone on the same server can read your database password! Downloading
 it and uploading it again will hopefully change the ownership to a user ID specific to you.</p>
+</div>
 EOT;
        } else {
-               echo "<p><span style='font-weight:bold;color:green;font-size:110%'>Installation successful!</span> Move the <tt>config/LocalSettings.php</tt> file into the parent directory, then follow
-                       <strong><a href='../index.php'>this link</a></strong> to your wiki.</p>\n";
+               echo <<<EOT
+<div class="success-box">
+<p>
+<span class="success-message">Installation successful!</span>
+Move the <tt>config/LocalSettings.php</tt> file to the parent directory, then follow
+<a href="../$script"> this link</a> to your wiki.</p>
+<p>You should change file permissions for <tt>LocalSettings.php</tt> as required to
+prevent other users on the server reading passwords and altering configuration data.</p>
+</div>
+EOT;
        }
 }
 
@@ -1498,6 +1584,7 @@ if ( \$wgCommandLineMode ) {
 ## The URL base path to the directory containing the wiki;
 ## defaults for all runtime URL paths are based off of this.
 \$wgScriptPath       = \"{$slconf['ScriptPath']}\";
+\$wgScriptExtension  = \"{$slconf['ScriptExtension']}\";
 
 ## For more information on customizing the URLs please see:
 ## http://www.mediawiki.org/wiki/Manual:Short_URL
@@ -1779,8 +1866,7 @@ function database_switcher($db) {
        global $ourdb;
        $color = $ourdb[$db]['bgcolor'];
        $full = $ourdb[$db]['fullname'];
-       print "<div id='$db' style='display:none; background: $color'>\n";
-       print "<h3>$full specific options:</h3>\n";
+       print "<fieldset id='$db'><legend>$full specific options</legend>\n";
 }
 
 function printListItem( $item ) {