Set $wgRequestTime so db errors end cleanly; mark Oracle support as experimental.
[lhc/web/wiklou.git] / config / index.php
index 043c8d1..7051b01 100644 (file)
@@ -1,6 +1,7 @@
 <?php
+
 # MediaWiki web-based config/installation
-# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
+# Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2006 Rob Church <robchur@gmail.com>
 # http://www.mediawiki.org/
 #
 # This program is free software; you can redistribute it and/or modify
@@ -22,15 +23,34 @@ error_reporting( E_ALL );
 header( "Content-type: text/html; charset=utf-8" );
 @ini_set( "display_errors", true );
 
-?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-        "http://www.w3.org/TR/html4/loose.dtd">
+# In case of errors, let output be clean.
+$wgRequestTime = microtime();
+
+# Attempt to set up the include path, to fix problems with relative includes
+$IP = dirname( dirname( __FILE__ ) );
+define( 'MW_INSTALL_PATH', $IP );
+$sep = PATH_SEPARATOR;
+if( !ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages" ) ) {
+       set_include_path( ".$sep$IP$sep$IP/includes$sep$IP/languages" );
+}
+
+# Define an entry point and include some files
+define( "MEDIAWIKI", true );
+define( "MEDIAWIKI_INSTALL", true );
+require_once( "includes/Defines.php" );
+require_once( "includes/DefaultSettings.php" );
+require_once( "includes/MagicWord.php" );
+require_once( "includes/Namespace.php" );
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
-       <title>MediaWiki installation</title>
+       <title>MediaWiki <?php echo( $wgVersion ); ?> Installation</title>
        <style type="text/css">
 
-               @import "../skins/monobook/main.css"; 
+               @import "../skins/monobook/main.css";
 
                .env-check {
                        font-size: 90%;
@@ -114,30 +134,7 @@ header( "Content-type: text/html; charset=utf-8" );
 <div id="content">
 <div id="bodyContent">
 
-
-<?php
-
-# Relative includes seem to break if a parent directory is not readable;
-# this is common for public_html subdirs under user home directories.
-#
-# As a dirty hack, we'll try to set up the include path first.
-#
-$IP = dirname( dirname( __FILE__ ) );
-$sep = PATH_SEPARATOR;
-if( !ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages" ) ) {
-       set_include_path( ".$sep$IP$sep$IP/includes$sep$IP/languages" );
-}
-
-
-define( "MEDIAWIKI", true );
-define( "MEDIAWIKI_INSTALL", true );
-require_once( "includes/Defines.php" );
-require_once( "includes/DefaultSettings.php" );
-require_once( "includes/MagicWord.php" );
-require_once( "includes/Namespace.php" );
-?>
-
-<h1>MediaWiki <?php print $wgVersion ?> installation</h1>
+<h1>MediaWiki <?php print $wgVersion ?> Installation</h1>
 
 <?php
 
@@ -239,7 +236,7 @@ if( ini_get( "mbstring.func_overload" ) ) {
 }
 
 if( $fatal ) {
-       dieout( "</ul><p>Cannot install Mediawiki.</p>" );
+       dieout( "</ul><p>Cannot install MediaWiki.</p>" );
 }
 
 if( ini_get( "safe_mode" ) ) {
@@ -254,7 +251,6 @@ if( ini_get( "safe_mode" ) ) {
        $conf->safeMode = false;
 }
 
-
 $sapi = php_sapi_name();
 $conf->prettyURLs = true;
 print "<li>PHP server API is $sapi; ";
@@ -371,11 +367,9 @@ if( $conf->HaveGD ) {
 
 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
 
-# $conf->IP = "/Users/brion/Sites/inplace";
 $conf->IP = dirname( dirname( __FILE__ ) );
 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
 
-# $conf->ScriptPath = "/~brion/inplace";
 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAME
 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
 
@@ -395,7 +389,8 @@ print "<li style='font-weight:bold;color:green;font-size:110%'>Environment check
        $conf->DBpassword2 = importPost( "DBpassword2" );
        $conf->DBprefix = importPost( "DBprefix" );
        $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false";
-       $conf->RootPW = importPost( "RootPW" );
+       $conf->RootUser = importPost( "RootUser", "root" );
+       $conf->RootPW = importPost( "RootPW", "-" );
        $conf->LanguageCode = importPost( "LanguageCode", "en" );
        $conf->SysopName = importPost( "SysopName", "WikiSysop" );
        $conf->SysopPass = importPost( "SysopPass" );
@@ -472,6 +467,9 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
 
                /* Load up the settings and get installin' */
                $local = writeLocalSettings( $conf );
+               echo "<p><b>Generating configuration file...</b></p>\n";
+               echo "<pre>" . htmlspecialchars( $local ) . "</pre>\n";
+               
                $wgCommandLineMode = false;
                chdir( ".." );
                eval($local);
@@ -502,60 +500,67 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
                }
                $dbc = new $dbclass;
-               if ($conf->DBtype == 'mysql') {
-                       print "<li>Trying to connect to database server on $wgDBserver as root...\n";
-                       $wgDatabase = $dbc->newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
-
-                       if( $wgDatabase->isOpen() ) {
-                               $myver = get_db_version();
-                               $wgDatabase->ignoreErrors(true);
+               
+               if( $conf->DBtype == 'mysql' ) {
+                       $ok = true; # Let's be optimistic
+                       
+                       # Decide if we're going to use the superuser or the regular database user
+                       if( $conf->RootPW == '-' ) {
+                               # Regular user
+                               $conf->Root = false;
+                               $db_user = $wgDBuser;
+                               $db_pass = $wgDBpassword;
+                       } else {
+                               # Superuser
                                $conf->Root = true;
-                               print "<ul><li>Connected as root (automatic)</li></ul></li>\n";
+                               $db_user = $conf->RootUser;
+                               $db_pass = $conf->RootPW;
+                       }
+                       
+                       # Attempt to connect
+                       echo( "<li>Attempting to connect to database server as $db_user..." );
+                       $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
+                       
+                       # Check the connection and respond to errors
+                       if( $wgDatabase->isOpen() ) {
+                               # Seems OK
+                               $ok = true;
+                               $wgDBadminuser = $db_user;
+                               $wgDBadminpassword = $db_pass;
+                               echo( "success.</li>\n" );
+                               $wgDatabase->ignoreErrors( true );
+                               $myver = mysql_get_server_info( $wgDatabase->mConn );
                        } else {
-                               print "<ul><li>MySQL error " . ($err = mysql_errno() ) .
-                                       ": " . htmlspecialchars( mysql_error() ) . "</li></ul></li>";
+                               # There were errors, report them and back out
                                $ok = false;
-                               switch( $err ) {
-                               case 1045:
-                               case 2000:
-                                       if( $conf->Root ) {
-                                               $errs["RootPW"] = "Check password";
-                                       } else {
-                                               print "<li>Trying regular user...\n";
-                                               /* Try the regular user... */
-                                               $wgDBadminuser = $wgDBuser;
-                                               $wgDBadminpassword = $wgDBpassword;
-                                               /* Wait one second for connection rate limiting, present on some systems */
-                                               sleep(1);
-                                               $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
-                                               if( !$wgDatabase->isOpen() ) {
-                                                       print "<ul><li>MySQL error " . ($err = mysql_errno() ) .
-                                                               ": " . htmlspecialchars( mysql_error() ) . "</li></ul></li>";
-                                                       $errs["DBuser"] = "Check name/pass";
-                                                       $errs["DBpassword"] = "or enter root";
-                                                       $errs["DBpassword2"] = "password below";
-                                                       $errs["RootPW"] = "Got root?";
+                               $errno = mysql_errno();
+                               $errtx = htmlspecialchars( mysql_error() );
+                               switch( $errno ) {
+                                       case 1045:
+                                       case 2000:
+                                               echo( "failed due to authentication errors. Check passwords.</li>" );
+                                               if( $conf->Root ) {
+                                                       # The superuser details are wrong
+                                                       $errs["RootUser"] = "Check username";
+                                                       $errs["RootPW"] = "and password";
                                                } else {
-                                                       $myver = mysql_get_server_info( $wgDatabase->mConn );
-                                                       $wgDatabase->ignoreErrors(true);
-                                                       $conf->Root = false;
-                                                       $conf->RootPW = "";
-                                                       print " ok.</li>\n";
-                                                       # And keep going...
-                                                       $ok = true;
+                                                       # The regular user details are wrong
+                                                       $errs["DBuser"] = "Check username";
+                                                       $errs["DBpassword"] = "and password";
                                                }
                                                break;
-                                       }
-                               case 2002:
-                               case 2003:
-                                       $errs["DBserver"] = "Connection failed";
-                                       break;
-                               default:
-                                       $errs["DBserver"] = "Couldn't connect to database";
-                                       break;
-                               }
-                               if( !$ok ) continue;
-                       }
+                                       case 2002:
+                                       case 2003:
+                                       default:
+                                               # General connection problem
+                                               echo( "failed with error [$errno] $errtx.</li>\n" );
+                                               $errs["DBserver"] = "Connection failed";
+                                               break;
+                               } # switch
+                       } #conn. att.
+               
+                       if( !$ok ) { continue; }
+
                } else /* not mysql */ {
                        print "<li>Connecting to SQL server...";
                        $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
@@ -617,7 +622,6 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        $wgDatabase->selectDB( $wgDBname );
                }
 
-
                if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
                        print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
 
@@ -669,12 +673,23 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                       'ss_total_views'   => 0,
                                       'ss_total_edits'   => 0,
                                       'ss_good_articles' => 0 ) );
-                       # setting up the db user
+                                          
+                       # Set up the "regular user" account *if we can, and if we need to*
                        if( $conf->Root ) {
-                               print "<li>Granting user permissions...</li>\n";
-                               dbsource( "../maintenance/users.sql", $wgDatabase );
+                               # See if we need to
+                               $wgDatabase2 = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, '', 1 );
+                               if( $wgDatabase2->isOpen() ) {
+                                       # Nope, just close the test connection and continue
+                                       $wgDatabase2->close();
+                                       echo( "<li>User $wgDBuser exists. Skipping grants.</li>" );
+                               } else {
+                                       # Yes, so run the grants
+                                       echo( "<li>Granting user permissions to $wgDBuser on $wgDBname..." );
+                                       dbsource( "../maintenance/users.sql", $wgDatabase );
+                                       echo( "success.</li>" );
+                               }
                        }
-
+                                          
                        if( $conf->SysopName ) {
                                $u = User::newFromName( $conf->getSysopName() );
                                if ( 0 == $u->idForName() ) {
@@ -944,7 +959,7 @@ if( count( $errs ) ) {
                <label class='column'>Database type:</label>
                <ul class='plain'>
                        <li><?php aField( $conf, "DBtype", "MySQL", "radio", "mysql"); ?></li>
-                       <li><?php aField( $conf, "DBtype", "Oracle", "radio", "oracle" ); ?></li>
+                       <li><?php aField( $conf, "DBtype", "Oracle (experimental)", "radio", "oracle" ); ?></li>
                </ul>
        </div>
 
@@ -976,6 +991,10 @@ if( count( $errs ) ) {
                enter those here. If you have database root access (see below)
                you can specify new accounts/databases to be created.
        </p>
+       <p>
+               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"><?php
                aField( $conf, "DBprefix", "Database table prefix:" );
@@ -987,7 +1006,7 @@ 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>Select one:</div>
                <ul class="plain">
@@ -1004,15 +1023,19 @@ if( count( $errs ) ) {
 
        <div class="config-input">
                <?php
-               aField( $conf, "RootPW", "DB root password:", "password" );
+               aField( $conf, "RootUser", "Superuser account:", "superuser" );
                ?>
        </div>
+       <div class="config-input">
+               <?php
+               aField( $conf, "RootPW", "Superuser password:", "password" );
+               ?>
+       </div>
+       
        <p class="config-desc">
-               You will only need this if the database and/or user account
-               above don't already exist.
-               Do <em>not</em> type in your machine's root password! MySQL
-               has its own "root" user with a separate password. (It might
-               even be blank, depending on your configuration.)
+               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 provide details of a superuser account,
+               such as <strong>root</strong>, which does. Leave the password set to <strong>-</strong> if this is not needed.
        </p>
 
        <div class="config-input" style="padding:2em 0 3em">
@@ -1143,10 +1166,17 @@ function writeLocalSettings( $conf ) {
 # and their default values, but don't forget to make changes in _this_
 # file, not there.
 
-\$IP = \"{$slconf['IP']}\";
-if( !ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" ) ) {
-       set_include_path( \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
+# If you customize your file layout, set \$IP to the directory that contains
+# the other MediaWiki files. It will be used as a base to locate files.
+if( defined( 'MW_INSTALL_PATH' ) ) {
+       \$IP = MW_INSTALL_PATH;
+} else {
+       \$IP = dirname( __FILE__ );
 }
+
+\$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
+set_include_path( implode( PATH_SEPARATOR, \$path ) );
+
 require_once( \"includes/DefaultSettings.php\" );
 
 # If PHP's memory limit is very low, some operations may fail.
@@ -1167,7 +1197,9 @@ if ( \$wgCommandLineMode ) {
 \$wgScript           = \"\$wgScriptPath/index.php\";
 \$wgRedirectScript   = \"\$wgScriptPath/redirect.php\";
 
-## If using PHP as a CGI module, use the ugly URLs
+## For more information on customizing the URLs please see:
+## http://meta.wikimedia.org/wiki/Eliminating_index.php_from_the_url
+## If using PHP as a CGI module, the ?title= style usually must be used.
 {$pretty}\$wgArticlePath      = \"\$wgScript/\$1\";
 {$ugly}\$wgArticlePath      = \"\$wgScript?title=\$1\";
 
@@ -1208,8 +1240,8 @@ if ( \$wgCommandLineMode ) {
 \$wgMemCachedServers = $mcservers;
 
 ## To enable image uploads, make sure the 'images' directory
-## is writable, then uncomment this:
-# \$wgEnableUploads            = true;
+## is writable, then set this to true:
+\$wgEnableUploads              = false;
 \$wgUseImageResize             = {$conf->UseImageResize};
 {$magic}\$wgUseImageMagick = true;
 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
@@ -1222,7 +1254,7 @@ if ( \$wgCommandLineMode ) {
 
 ## If you have the appropriate support software installed
 ## you can enable inline LaTeX equations:
-# \$wgUseTeX                   = true;
+\$wgUseTeX              = false;
 \$wgMathPath         = \"{\$wgUploadPath}/math\";
 \$wgMathDirectory    = \"{\$wgUploadDirectory}/math\";
 \$wgTmpDirectory     = \"{\$wgUploadDirectory}/tmp\";
@@ -1235,7 +1267,7 @@ if ( \$wgCommandLineMode ) {
 
 ## Default skin: you can change the default skin. Use the internal symbolic
 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
-\$wgDefaultSkin = 'monobook';
+\$wgDefaultSkin = 'monobook';
 
 ## For attaching licensing metadata to pages, and displaying an
 ## appropriate copyright notice / icon. GNU Free Documentation
@@ -1248,6 +1280,11 @@ if ( \$wgCommandLineMode ) {
 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
 
 \$wgDiff3 = \"{$slconf['diff3']}\";
+
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+\$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
+\$wgCacheEpoch = max( \$wgCacheEpoch, \$configdate );
 ";
        // Keep things in Unix line endings internally;
        // the system will write out as local text type.
@@ -1281,7 +1318,7 @@ function importRequest( $name, $default = "" ) {
 $radioCount = 0;
 
 function aField( &$conf, $field, $text, $type = "text", $value = "" ) {
-       global $radioCount; 
+       global $radioCount;
        if( $type != "" ) {
                $xtype = "type=\"$type\"";
        } else {
@@ -1290,10 +1327,10 @@ function aField( &$conf, $field, $text, $type = "text", $value = "" ) {
 
        if(!(isset($id)) or ($id == "") ) $id = $field;
        $nolabel = ($type == "radio") || ($type == "hidden");
-       
+
        if ($type == 'radio')
                $id .= $radioCount++;
-       
+
        if( $nolabel ) {
                echo "\t\t<label>";
        } else {
@@ -1462,7 +1499,7 @@ function testMemcachedServer( $server ) {
                        <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
                        <li><a href="http://meta.wikimedia.org/wiki/MediaWiki_FAQ">FAQ</a></li>
                </ul>
-               <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright &copy; 2001-2005 by Magnus Manske, Brion Vibber, Lee Daniel Crocker, Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
+               <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright &copy; 2001-2006 by Magnus Manske, Brion Vibber, Lee Daniel Crocker, Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
        </div></div>
 </div>