From: Greg Sabino Mullane Date: Tue, 27 Jun 2006 14:18:00 +0000 (+0000) Subject: Abstract database installation details as much as possible. X-Git-Tag: 1.31.0-rc.0~56577 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=814127db62c58d61567418ca2503b25dffe5a949;p=lhc%2Fweb%2Fwiklou.git Abstract database installation details as much as possible. Rewrite database detection system. Break configuration into database-specific parts. --- diff --git a/config/index.php b/config/index.php index f2d788e5e7..5deff4df54 100644 --- a/config/index.php +++ b/config/index.php @@ -42,6 +42,19 @@ require_once( "includes/DefaultSettings.php" ); require_once( "includes/MagicWord.php" ); require_once( "includes/Namespace.php" ); +## Databases we support: + +$ourdb = array(); +$ourdb['mysql']['fullname'] = 'MySQL'; +$ourdb['mysql']['havedriver'] = 0; +$ourdb['mysql']['compile'] = 'mysql'; +$ourdb['mysql']['bgcolor'] = '#ffe5a7'; + +$ourdb['postgres']['fullname'] = 'PostgreSQL'; +$ourdb['postgres']['havedriver'] = 0; +$ourdb['postgres']['compile'] = 'pgsql'; +$ourdb['postgres']['bgcolor'] = '#aaccff'; + ?> @@ -126,6 +139,21 @@ require_once( "includes/Namespace.php" ); } + @@ -206,6 +234,43 @@ install_version_checks(); print "
  • PHP " . phpversion() . " installed
  • \n"; +## Temporarily turn off all errors as we try to discover installed databases +$olderrnum = error_reporting(0); + +$phpdatabases = array(); +foreach (array_keys($ourdb) as $db) { + $compname = $ourdb[$db]['compile']; + if (extension_loaded($compname) or dl($compname . '.' . PHP_SHLIB_SUFFIX)) { + array_push($phpdatabases, $db); + $ourdb[$db]['havedriver'] = 1; + } +} + +error_reporting($olderrornum); + +if (!$phpdatabases) { + print "Could not find a suitable database driver!\n"; + exit; +} + +print "
  • Found database drivers for:"; +foreach (array_keys($ourdb) AS $db) { + if ($ourdb[$db]['havedriver']) { + $DefaultDBtype = $db; + print " ".$ourdb[$db]['fullname']; + } +} +print "
  • \n"; +if (count($phpdatabases) != 1) + $DefaultDBtype = ''; + if( ini_get( "register_globals" ) ) { ?>
  • @@ -406,13 +471,18 @@ print "
  • Environment check ? 'root@localhost' : $_SERVER["SERVER_ADMIN"]; $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail ); - $conf->DBtype = importPost( "DBtype", "mysql" ); + $conf->DBtype = importPost( "DBtype", $DefaultDBtype ); +?> + +DBserver = importPost( "DBserver", "localhost" ); $conf->DBname = importPost( "DBname", "wikidb" ); $conf->DBuser = importPost( "DBuser", "wikiuser" ); $conf->DBpassword = importPost( "DBpassword" ); $conf->DBpassword2 = importPost( "DBpassword2" ); $conf->DBprefix = importPost( "DBprefix" ); + $conf->DBschema = importPost( "DBschema", "mediawiki" ); + $conf->DBport = importPost( "DBport", "5432" ); $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false"; $conf->RootUser = importPost( "RootUser", "root" ); $conf->RootPW = importPost( "RootPW", "-" ); @@ -498,11 +568,16 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { $wgCommandLineMode = false; chdir( ".." ); eval($local); - if (!in_array($conf->DBtype, array("mysql", "oracle", "postgres"))) { - $errs["DBtype"] = "Unknown database type."; + $conf->DBtypename = ''; + foreach (array_keys($ourdb) as $db) { + if ($conf->DBtype === $db) + $conf->DBtypename = $ourdb[$db]['fullname']; + } + if (! $conf->DBtypename) { + $errs["DBtype"] = "Unknown database type '$conf->DBtype'"; continue; } - print "
  • Database type: {$conf->DBtype}
  • \n"; + print "
  • Database type: {$conf->DBtypename}
  • \n"; $dbclass = 'Database'.ucfirst($conf->DBtype); $wgDBtype = $conf->DBtype; $wgDBadminuser = "root"; @@ -516,6 +591,8 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { require_once( "maintenance/InitialiseMessages.inc" ); $wgTitle = Title::newFromText( "Installation script" ); +error_reporting( E_ALL ); + print "
  • Loading class: $dbclass"; $dbc = new $dbclass; if( $conf->DBtype == 'mysql' ) { @@ -544,7 +621,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { # Attempt to connect echo( "
  • 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 @@ -687,10 +764,14 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { } else if ($conf->DBtype == 'postgres') { dbsource( "../maintenance/postgres/tables.sql", $wgDatabase ); $wgDatabase->update_interwiki(); - } else { + } else if ($conf->DBtype == 'oracle') { dbsource( "../maintenance/oracle/tables.sql", $wgDatabase ); dbsource( "../maintenance/oracle/interwiki.sql", $wgDatabase ); } + else { + $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'"; + continue; + } print " done.
  • \n"; @@ -809,7 +890,7 @@ if( count( $errs ) ) { ?>

    - Preferably a short word without punctuation, e.g. "Wikipedia".
    + Preferably a short word without punctuation, i.e. "Wikipedia".
    Will appear as the namespace name for "meta" pages, and throughout the interface.

    @@ -978,27 +1059,19 @@ if( count( $errs ) ) {
    -
      -
    • -
    • -
    • -
    +

    - If your database server isn't on your web server, enter the name - or IP address here. MySQL and PostgreSQL only. If using a port for PostgreSQL, enter the number here. + If your database server isn't on your web server, enter the name or IP address here.

    -
    - If using Oracle, set this to your connection identifier. -
    @@ -1018,6 +1091,7 @@ if( count( $errs ) ) { has SELECT, INSERT, UPDATE and DELETE permissions on the MediaWiki database.

    +
    @@ -1042,6 +1116,20 @@ if( count( $errs ) ) { cause things to break. If upgrading an older installation, leave in backwards-compatible mode.

    +
    + + +
    +
    +
    +

    The username specified above will have it's search path set to the above schema, + so it is recommended that you create a new user.

    +
    +
    + + $field ); } + + echo "\" />\n"; if( $nolabel ) { echo " $text\n"; @@ -1474,6 +1572,28 @@ function testMemcachedServer( $server ) { } return $errstr; } + +function database_picker($conf) { + global $ourdb; + print "\n"; + foreach(array_keys($ourdb) as $db) { + if ($ourdb[$db]['havedriver']) { + print "
  • "; + aField( $conf, "DBtype", $ourdb[$db]['fullname'], 'radio', $db, 'onclick'); + print "
  • \n"; + } + } + print "\n"; +} + +function database_switcher($db) { + global $ourdb; + $color = $ourdb[$db]['bgcolor']; + $full = $ourdb[$db]['fullname']; + print "