Index: trunk/phase3/config/index.php |
— | — | @@ -42,6 +42,19 @@ |
43 | 43 | require_once( "includes/MagicWord.php" ); |
44 | 44 | require_once( "includes/Namespace.php" ); |
45 | 45 | |
| 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 | + |
46 | 59 | ?> |
47 | 60 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
48 | 61 | <html> |
— | — | @@ -126,6 +139,21 @@ |
127 | 140 | } |
128 | 141 | |
129 | 142 | </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> |
130 | 158 | </head> |
131 | 159 | |
132 | 160 | <body> |
— | — | @@ -206,6 +234,43 @@ |
207 | 235 | |
208 | 236 | print "<li>PHP " . phpversion() . " installed</li>\n"; |
209 | 237 | |
| 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 | + |
210 | 275 | if( ini_get( "register_globals" ) ) { |
211 | 276 | ?> |
212 | 277 | <li> |
— | — | @@ -406,13 +471,18 @@ |
407 | 472 | ? 'root@localhost' |
408 | 473 | : $_SERVER["SERVER_ADMIN"]; |
409 | 474 | $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail ); |
410 | | - $conf->DBtype = importPost( "DBtype", "mysql" ); |
| 475 | + $conf->DBtype = importPost( "DBtype", $DefaultDBtype ); |
| 476 | +?> |
| 477 | + |
| 478 | +<?php |
411 | 479 | $conf->DBserver = importPost( "DBserver", "localhost" ); |
412 | 480 | $conf->DBname = importPost( "DBname", "wikidb" ); |
413 | 481 | $conf->DBuser = importPost( "DBuser", "wikiuser" ); |
414 | 482 | $conf->DBpassword = importPost( "DBpassword" ); |
415 | 483 | $conf->DBpassword2 = importPost( "DBpassword2" ); |
416 | 484 | $conf->DBprefix = importPost( "DBprefix" ); |
| 485 | + $conf->DBschema = importPost( "DBschema", "mediawiki" ); |
| 486 | + $conf->DBport = importPost( "DBport", "5432" ); |
417 | 487 | $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false"; |
418 | 488 | $conf->RootUser = importPost( "RootUser", "root" ); |
419 | 489 | $conf->RootPW = importPost( "RootPW", "-" ); |
— | — | @@ -498,11 +568,16 @@ |
499 | 569 | $wgCommandLineMode = false; |
500 | 570 | chdir( ".." ); |
501 | 571 | 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'"; |
504 | 579 | continue; |
505 | 580 | } |
506 | | - print "<li>Database type: {$conf->DBtype}</li>\n"; |
| 581 | + print "<li>Database type: {$conf->DBtypename}</li>\n"; |
507 | 582 | $dbclass = 'Database'.ucfirst($conf->DBtype); |
508 | 583 | $wgDBtype = $conf->DBtype; |
509 | 584 | $wgDBadminuser = "root"; |
— | — | @@ -516,6 +591,8 @@ |
517 | 592 | require_once( "maintenance/InitialiseMessages.inc" ); |
518 | 593 | |
519 | 594 | $wgTitle = Title::newFromText( "Installation script" ); |
| 595 | +error_reporting( E_ALL ); |
| 596 | + print "<li>Loading class: $dbclass"; |
520 | 597 | $dbc = new $dbclass; |
521 | 598 | |
522 | 599 | if( $conf->DBtype == 'mysql' ) { |
— | — | @@ -544,7 +621,7 @@ |
545 | 622 | # Attempt to connect |
546 | 623 | echo( "<li>Attempting to connect to database server as $db_user..." ); |
547 | 624 | $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 ); |
548 | | - |
| 625 | + |
549 | 626 | # Check the connection and respond to errors |
550 | 627 | if( $wgDatabase->isOpen() ) { |
551 | 628 | # Seems OK |
— | — | @@ -687,10 +764,14 @@ |
688 | 765 | } else if ($conf->DBtype == 'postgres') { |
689 | 766 | dbsource( "../maintenance/postgres/tables.sql", $wgDatabase ); |
690 | 767 | $wgDatabase->update_interwiki(); |
691 | | - } else { |
| 768 | + } else if ($conf->DBtype == 'oracle') { |
692 | 769 | dbsource( "../maintenance/oracle/tables.sql", $wgDatabase ); |
693 | 770 | dbsource( "../maintenance/oracle/interwiki.sql", $wgDatabase ); |
694 | 771 | } |
| 772 | + else { |
| 773 | + $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'"; |
| 774 | + continue; |
| 775 | + } |
695 | 776 | |
696 | 777 | print " done.</li>\n"; |
697 | 778 | |
— | — | @@ -809,7 +890,7 @@ |
810 | 891 | ?> |
811 | 892 | </div> |
812 | 893 | <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> |
814 | 895 | Will appear as the namespace name for "meta" pages, and throughout the interface. |
815 | 896 | </p> |
816 | 897 | |
— | — | @@ -978,27 +1059,19 @@ |
979 | 1060 | <div class="config-section"> |
980 | 1061 | <div class="config-input"> |
981 | 1062 | <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> |
987 | 1064 | </div> |
988 | 1065 | |
989 | 1066 | <div class="config-input" style="clear:left"><?php |
990 | | - aField( $conf, "DBserver", "SQL server host:" ); |
| 1067 | + aField( $conf, "DBserver", "Database host:" ); |
991 | 1068 | ?></div> |
992 | 1069 | <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. |
995 | 1071 | </p> |
996 | 1072 | |
997 | 1073 | <div class="config-input"><?php |
998 | 1074 | aField( $conf, "DBname", "Database name:" ); |
999 | 1075 | ?></div> |
1000 | | - <div class="config-desc"> |
1001 | | - If using Oracle, set this to your connection identifier. |
1002 | | - </div> |
1003 | 1076 | <div class="config-input"><?php |
1004 | 1077 | aField( $conf, "DBuser", "DB username:" ); |
1005 | 1078 | ?></div> |
— | — | @@ -1018,6 +1091,7 @@ |
1019 | 1092 | has SELECT, INSERT, UPDATE and DELETE permissions on the MediaWiki database. |
1020 | 1093 | </p> |
1021 | 1094 | |
| 1095 | + <?php database_switcher('mysql'); ?> |
1022 | 1096 | <div class="config-input"><?php |
1023 | 1097 | aField( $conf, "DBprefix", "Database table prefix:" ); |
1024 | 1098 | ?></div> |
— | — | @@ -1042,7 +1116,21 @@ |
1043 | 1117 | cause things to break. <b>If upgrading an older installation, leave |
1044 | 1118 | in backwards-compatible mode.</b> |
1045 | 1119 | </p> |
| 1120 | + </div> |
1046 | 1121 | |
| 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 | + |
1047 | 1135 | <div class="config-input"> |
1048 | 1136 | <?php |
1049 | 1137 | aField( $conf, "RootUser", "Superuser account:", "superuser" ); |
— | — | @@ -1067,6 +1155,10 @@ |
1068 | 1156 | |
1069 | 1157 | </div> |
1070 | 1158 | |
| 1159 | +<script type="text/javascript"> |
| 1160 | +window.onload = togglearea('<?php echo $conf->DBtype; ?>'); |
| 1161 | +</script> |
| 1162 | + |
1071 | 1163 | </form> |
1072 | 1164 | |
1073 | 1165 | <?php |
— | — | @@ -1339,7 +1431,7 @@ |
1340 | 1432 | |
1341 | 1433 | $radioCount = 0; |
1342 | 1434 | |
1343 | | -function aField( &$conf, $field, $text, $type = "text", $value = "" ) { |
| 1435 | +function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick = '' ) { |
1344 | 1436 | global $radioCount; |
1345 | 1437 | if( $type != "" ) { |
1346 | 1438 | $xtype = "type=\"$type\""; |
— | — | @@ -1364,12 +1456,18 @@ |
1365 | 1457 | } else { |
1366 | 1458 | $checked = ""; |
1367 | 1459 | } |
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=\""; |
1369 | 1465 | if( $type == "radio" ) { |
1370 | 1466 | echo htmlspecialchars( $value ); |
1371 | 1467 | } else { |
1372 | 1468 | echo htmlspecialchars( $conf->$field ); |
1373 | 1469 | } |
| 1470 | + |
| 1471 | + |
1374 | 1472 | echo "\" />\n"; |
1375 | 1473 | if( $nolabel ) { |
1376 | 1474 | echo " $text</label>\n"; |
— | — | @@ -1474,6 +1572,28 @@ |
1475 | 1573 | } |
1476 | 1574 | return $errstr; |
1477 | 1575 | } |
| 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 | + |
1478 | 1598 | ?> |
1479 | 1599 | |
1480 | 1600 | <div class="license"> |