r15090 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15089‎ | r15090 | r15091 >
Date:14:18, 27 June 2006
Author:greg
Status:old
Tags:
Comment:
Abstract database installation details as much as possible.
Rewrite database detection system.
Break configuration into database-specific parts.
Modified paths:
  • /trunk/phase3/config/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/config/index.php
@@ -42,6 +42,19 @@
4343 require_once( "includes/MagicWord.php" );
4444 require_once( "includes/Namespace.php" );
4545
 46+## Databases we support:
 47+
 48+$ourdb = array();
 49+$ourdb['mysql']['fullname'] = 'MySQL';
 50+$ourdb['mysql']['havedriver'] = 0;
 51+$ourdb['mysql']['compile'] = 'mysql';
 52+$ourdb['mysql']['bgcolor'] = '#ffe5a7';
 53+
 54+$ourdb['postgres']['fullname'] = 'PostgreSQL';
 55+$ourdb['postgres']['havedriver'] = 0;
 56+$ourdb['postgres']['compile'] = 'pgsql';
 57+$ourdb['postgres']['bgcolor'] = '#aaccff';
 58+
4659 ?>
4760 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4861 <html>
@@ -126,6 +139,21 @@
127140 }
128141
129142 </style>
 143+ <script type="text/javascript">
 144+ <!--
 145+ function hideall() {
 146+ <?php foreach (array_keys($ourdb) as $db) {
 147+ echo "document.getElementById('$db').style.display='none';\n";
 148+ }
 149+ ?>
 150+ }
 151+ function togglearea(id) {
 152+ hideall();
 153+ var dbarea = document.getElementById(id).style;
 154+ dbarea.display = dbarea.display = 'none' ? 'block' : 'none';
 155+ }
 156+ // -->
 157+ </script>
130158 </head>
131159
132160 <body>
@@ -206,6 +234,43 @@
207235
208236 print "<li>PHP " . phpversion() . " installed</li>\n";
209237
 238+## Temporarily turn off all errors as we try to discover installed databases
 239+$olderrnum = error_reporting(0);
 240+
 241+$phpdatabases = array();
 242+foreach (array_keys($ourdb) as $db) {
 243+ $compname = $ourdb[$db]['compile'];
 244+ if (extension_loaded($compname) or dl($compname . '.' . PHP_SHLIB_SUFFIX)) {
 245+ array_push($phpdatabases, $db);
 246+ $ourdb[$db]['havedriver'] = 1;
 247+ }
 248+}
 249+
 250+error_reporting($olderrornum);
 251+
 252+if (!$phpdatabases) {
 253+ print "Could not find a suitable database driver!<ul>";
 254+ foreach (array_keys($ourdb) AS $db) {
 255+ $comp = $ourdb[$db]['compile'];
 256+ $full = $ourdb[$db]['fullname'];
 257+ print "<li>For <b>$full</b>, compile PHP using <b>--with-$comp</b>, "
 258+ ."or install the $comp.so module</li>\n";
 259+ }
 260+ print "</ul></ul></body></html>\n";
 261+ exit;
 262+}
 263+
 264+print "<li>Found database drivers for:";
 265+foreach (array_keys($ourdb) AS $db) {
 266+ if ($ourdb[$db]['havedriver']) {
 267+ $DefaultDBtype = $db;
 268+ print " ".$ourdb[$db]['fullname'];
 269+ }
 270+}
 271+print "</li>\n";
 272+if (count($phpdatabases) != 1)
 273+ $DefaultDBtype = '';
 274+
210275 if( ini_get( "register_globals" ) ) {
211276 ?>
212277 <li>
@@ -406,13 +471,18 @@
407472 ? 'root@localhost'
408473 : $_SERVER["SERVER_ADMIN"];
409474 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
410 - $conf->DBtype = importPost( "DBtype", "mysql" );
 475+ $conf->DBtype = importPost( "DBtype", $DefaultDBtype );
 476+?>
 477+
 478+<?php
411479 $conf->DBserver = importPost( "DBserver", "localhost" );
412480 $conf->DBname = importPost( "DBname", "wikidb" );
413481 $conf->DBuser = importPost( "DBuser", "wikiuser" );
414482 $conf->DBpassword = importPost( "DBpassword" );
415483 $conf->DBpassword2 = importPost( "DBpassword2" );
416484 $conf->DBprefix = importPost( "DBprefix" );
 485+ $conf->DBschema = importPost( "DBschema", "mediawiki" );
 486+ $conf->DBport = importPost( "DBport", "5432" );
417487 $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false";
418488 $conf->RootUser = importPost( "RootUser", "root" );
419489 $conf->RootPW = importPost( "RootPW", "-" );
@@ -498,11 +568,16 @@
499569 $wgCommandLineMode = false;
500570 chdir( ".." );
501571 eval($local);
502 - if (!in_array($conf->DBtype, array("mysql", "oracle", "postgres"))) {
503 - $errs["DBtype"] = "Unknown database type.";
 572+ $conf->DBtypename = '';
 573+ foreach (array_keys($ourdb) as $db) {
 574+ if ($conf->DBtype === $db)
 575+ $conf->DBtypename = $ourdb[$db]['fullname'];
 576+ }
 577+ if (! $conf->DBtypename) {
 578+ $errs["DBtype"] = "Unknown database type '$conf->DBtype'";
504579 continue;
505580 }
506 - print "<li>Database type: {$conf->DBtype}</li>\n";
 581+ print "<li>Database type: {$conf->DBtypename}</li>\n";
507582 $dbclass = 'Database'.ucfirst($conf->DBtype);
508583 $wgDBtype = $conf->DBtype;
509584 $wgDBadminuser = "root";
@@ -516,6 +591,8 @@
517592 require_once( "maintenance/InitialiseMessages.inc" );
518593
519594 $wgTitle = Title::newFromText( "Installation script" );
 595+error_reporting( E_ALL );
 596+ print "<li>Loading class: $dbclass";
520597 $dbc = new $dbclass;
521598
522599 if( $conf->DBtype == 'mysql' ) {
@@ -544,7 +621,7 @@
545622 # Attempt to connect
546623 echo( "<li>Attempting to connect to database server as $db_user..." );
547624 $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
548 -
 625+
549626 # Check the connection and respond to errors
550627 if( $wgDatabase->isOpen() ) {
551628 # Seems OK
@@ -687,10 +764,14 @@
688765 } else if ($conf->DBtype == 'postgres') {
689766 dbsource( "../maintenance/postgres/tables.sql", $wgDatabase );
690767 $wgDatabase->update_interwiki();
691 - } else {
 768+ } else if ($conf->DBtype == 'oracle') {
692769 dbsource( "../maintenance/oracle/tables.sql", $wgDatabase );
693770 dbsource( "../maintenance/oracle/interwiki.sql", $wgDatabase );
694771 }
 772+ else {
 773+ $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'";
 774+ continue;
 775+ }
695776
696777 print " done.</li>\n";
697778
@@ -809,7 +890,7 @@
810891 ?>
811892 </div>
812893 <p class="config-desc">
813 - Preferably a short word without punctuation, e.g. "Wikipedia".<br>
 894+ Preferably a short word without punctuation, i.e. "Wikipedia".<br>
814895 Will appear as the namespace name for "meta" pages, and throughout the interface.
815896 </p>
816897
@@ -978,27 +1059,19 @@
9791060 <div class="config-section">
9801061 <div class="config-input">
9811062 <label class='column'>Database type:</label>
982 - <ul class='plain'>
983 - <li><?php aField( $conf, "DBtype", "MySQL", "radio", "mysql"); ?></li>
984 - <li><?php aField( $conf, "DBtype", "Oracle (experimental)", "radio", "oracle" ); ?></li>
985 - <li><?php aField( $conf, "DBtype", "PostgreSQL", "radio", "postgres" ); ?></li>
986 - </ul>
 1063+ <ul class='plain'><?php database_picker($conf) ?></ul>
9871064 </div>
9881065
9891066 <div class="config-input" style="clear:left"><?php
990 - aField( $conf, "DBserver", "SQL server host:" );
 1067+ aField( $conf, "DBserver", "Database host:" );
9911068 ?></div>
9921069 <p class="config-desc">
993 - If your database server isn't on your web server, enter the name
994 - or IP address here. MySQL and PostgreSQL only. If using a port for PostgreSQL, enter the number here.
 1070+ If your database server isn't on your web server, enter the name or IP address here.
9951071 </p>
9961072
9971073 <div class="config-input"><?php
9981074 aField( $conf, "DBname", "Database name:" );
9991075 ?></div>
1000 - <div class="config-desc">
1001 - If using Oracle, set this to your connection identifier.
1002 - </div>
10031076 <div class="config-input"><?php
10041077 aField( $conf, "DBuser", "DB username:" );
10051078 ?></div>
@@ -1018,6 +1091,7 @@
10191092 has SELECT, INSERT, UPDATE and DELETE permissions on the MediaWiki database.
10201093 </p>
10211094
 1095+ <?php database_switcher('mysql'); ?>
10221096 <div class="config-input"><?php
10231097 aField( $conf, "DBprefix", "Database table prefix:" );
10241098 ?></div>
@@ -1042,7 +1116,21 @@
10431117 cause things to break. <b>If upgrading an older installation, leave
10441118 in backwards-compatible mode.</b>
10451119 </p>
 1120+ </div>
10461121
 1122+ <?php database_switcher('postgres'); ?>
 1123+ <div class="config-input"><?php
 1124+ aField( $conf, "DBport", "Database port:" );
 1125+ ?></div>
 1126+ <div class="config-input"><?php
 1127+ aField( $conf, "DBschema", "Database schema:" );
 1128+ ?></div>
 1129+ <div class="config-desc">
 1130+ <p>The username specified above will have it's search path set to the above schema,
 1131+ so it is recommended that you create a new user.</p>
 1132+ </div>
 1133+ </div>
 1134+
10471135 <div class="config-input">
10481136 <?php
10491137 aField( $conf, "RootUser", "Superuser account:", "superuser" );
@@ -1067,6 +1155,10 @@
10681156
10691157 </div>
10701158
 1159+<script type="text/javascript">
 1160+window.onload = togglearea('<?php echo $conf->DBtype; ?>');
 1161+</script>
 1162+
10711163 </form>
10721164
10731165 <?php
@@ -1339,7 +1431,7 @@
13401432
13411433 $radioCount = 0;
13421434
1343 -function aField( &$conf, $field, $text, $type = "text", $value = "" ) {
 1435+function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick = '' ) {
13441436 global $radioCount;
13451437 if( $type != "" ) {
13461438 $xtype = "type=\"$type\"";
@@ -1364,12 +1456,18 @@
13651457 } else {
13661458 $checked = "";
13671459 }
1368 - echo "\t\t<input $xtype name=\"$field\" id=\"$id\" class=\"iput-$type\" $checked value=\"";
 1460+ echo "\t\t<input $xtype name=\"$field\" id=\"$id\" class=\"iput-$type\" $checked ";
 1461+ if ($onclick) {
 1462+ echo " onclick='togglearea(\"$value\")' " ;
 1463+ }
 1464+ echo "value=\"";
13691465 if( $type == "radio" ) {
13701466 echo htmlspecialchars( $value );
13711467 } else {
13721468 echo htmlspecialchars( $conf->$field );
13731469 }
 1470+
 1471+
13741472 echo "\" />\n";
13751473 if( $nolabel ) {
13761474 echo " $text</label>\n";
@@ -1474,6 +1572,28 @@
14751573 }
14761574 return $errstr;
14771575 }
 1576+
 1577+function database_picker($conf) {
 1578+ global $ourdb;
 1579+ print "\n";
 1580+ foreach(array_keys($ourdb) as $db) {
 1581+ if ($ourdb[$db]['havedriver']) {
 1582+ print "<li>";
 1583+ aField( $conf, "DBtype", $ourdb[$db]['fullname'], 'radio', $db, 'onclick');
 1584+ print "</li>\n";
 1585+ }
 1586+ }
 1587+ print "\n";
 1588+}
 1589+
 1590+function database_switcher($db) {
 1591+ global $ourdb;
 1592+ $color = $ourdb[$db]['bgcolor'];
 1593+ $full = $ourdb[$db]['fullname'];
 1594+ print "<div id='$db' style='display:none; background: $color'>\n";
 1595+ print "<h3>$full specific options:</h3>\n";
 1596+}
 1597+
14781598 ?>
14791599
14801600 <div class="license">