Add database creation to in-place installer, plus a couple fixlets.
[lhc/web/wiklou.git] / config / index.php
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6 <meta name="robots" content="noindex,nofollow">
7 <title>MediaWiki installation</title>
8 <style type="text/css">
9 #credit {
10 float: right;
11 width: 200px;
12 font-size: 0.7em;
13 background-color: #eee;
14 color: black;
15 border: solid 1px #444;
16 padding: 8px;
17 margin-left: 8px;
18 }
19
20 dl.setup dd {
21 }
22 dl.setup dd label {
23 clear: left;
24 font-weight: bold;
25 width: 10em;
26 float: left;
27 text-align: right;
28 padding-right: 1em;
29 }
30 dl.setup dt {
31 clear: left;
32 font-size: 0.8em;
33 margin-left: 10em;
34 /* margin-right: 200px; */
35 margin-bottom: 2em;
36 }
37 .error {
38 color: red;
39 }
40 </style>
41 </head>
42
43 <body>
44
45 <div id="credit">
46 <center>
47 <a href="http://www.mediawiki.org/"><img
48 src="../images/wiki.png" width="135" height="135" alt="" border="0" /></a>
49 </center>
50
51 <b><a href="http://www.mediawiki.org/">MediaWiki</a></b> is
52 Copyright (C) 2001-2004 by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
53 Tim Starling, Erik M&ouml;ller, and others.</p>
54
55 <ul>
56 <li><a href="../README">Readme</a></li>
57 <li><a href="../RELEASE-NOTES">Release notes</a></li>
58 <li><a href="../docs/">doc/</a></li>
59 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
60 </ul>
61
62 <p>This program is free software; you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation; either version 2 of the License, or
65 (at your option) any later version.</p>
66
67 <p>This progarm is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.</p>
71
72 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
73 along with this program; if not, write to the Free Software
74 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
75 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
76 </div>
77
78 <?php
79 include( "../includes/DefaultSettings.php" );
80 ?>
81
82 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
83
84
85 <?php
86
87 /* Check for existing configurations and bug out! */
88
89 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
90 dieout( "<h2>Wiki is configured.</h2>
91
92 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
93
94 <p>(You should probably remove this directory for added security.)</p>" );
95 }
96
97 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
98 dieout( "<h2>You're configured!</h2>
99
100 <p>Please move <tt>LocalSettings.php</tt> to the parent directory, then
101 <a href='../index.php'>try out your wiki</a>.
102 (You should remove this config directory for added security once you're done.)</p>" );
103 }
104
105
106 include( "../install-utils.inc" );
107 class ConfigData {}
108
109 ?>
110
111
112 <h2>Checking environment...</h2>
113 <ul>
114 <?php
115
116 $conf = new ConfigData;
117
118 install_version_checks();
119 print "<li>PHP " . phpversion() . " ok</li>\n";
120
121 /*
122 $conf->zlib = function_exists( "gzencode" );
123 $z = $conf->zlib ? "Have" : "No";
124 print "<li>$z zlib support</li>\n";
125
126 $conf->gd = function_exists( "imagejpeg" );
127 if( $conf->gd ) {
128 print "<li>Found GD graphics library built-in</li>\n";
129 } else {
130 print "<li>No built-in GD library</li>\n";
131 }
132
133 if( file_exists( "/usr/bin/convert" ) ) {
134 $conf->ImageMagick = "/usr/bin/convert";
135 print "<li>Found ImageMagick: /usr/bin/convert</li>\n";
136 } elseif( file_exists( "/usr/local/bin/convert" ) ) {
137 $conf->ImageMagick = "/usr/local/bin/convert";
138 print "<li>Found ImageMagick: /usr/local/bin/convert</li>\n";
139 } else {
140 $conf->ImageMagick = false;
141 print "<li>No ImageMagick.</li>\n";
142 }
143 */
144
145 # $conf->IP = "/Users/brion/Sites/inplace";
146 chdir( ".." );
147 $conf->IP = getcwd();
148 chdir( "config" );
149 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
150
151 # $conf->ScriptPath = "/~brion/inplace";
152 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
153 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
154
155 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
156
157 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
158 $conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
159 $conf->DBserver = importPost( "DBserver", "localhost" );
160 $conf->DBname = importPost( "DBname", "wikidb" );
161 $conf->DBuser = importPost( "DBuser", "wikiuser" );
162 $conf->DBpassword = importPost( "DBpassword" );
163 $conf->DBpassword2 = importPost( "DBpassword2" );
164 $conf->RootPW = importPost( "RootPW" );
165 $conf->LanguageCode = importPost( "LanguageCode", "en-utf8" );
166
167 /* Check for validity */
168 $errs = array();
169
170 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
171 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
172 }
173 if( $conf->DBpassword == "" ) {
174 $errs["DBpassword"] = "Must not be blank";
175 }
176 if( $conf->DBpassword != $conf->DBpassword2 ) {
177 $errs["DBpassword2"] = "Passwords don't match!";
178 }
179
180 if( $conf->posted && ( 0 == count( $errs ) ) ) {
181 do { /* So we can 'continue' to end prematurely */
182 $conf->Root = ($conf->RootPW != "");
183
184 /* Load up the settings and get installin' */
185 $local = writeLocalSettings( $conf );
186 $wgCommandLineMode = false;
187 eval($local);
188
189 $wgDBadminuser = $wgDBuser;
190 $wgDBadminpassword = $wgDBpassword;
191 $wgCommandLineMode = true;
192 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
193 include_once( "Setup.php" );
194
195 if( $conf->Root ) {
196 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
197 } else {
198 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
199 }
200 $wgDatabase->mIgnoreErrors = true;
201
202 if ( !$wgDatabase->isOpen() ) {
203 $errs["DBserver"] = "Couldn't connect to database";
204 continue;
205 }
206
207 @$myver = mysql_get_server_info( $wgDatabase->mConn );
208 if( !$myver ) {
209 print "<li>MySQL error " . ($err = mysql_errno() ) .
210 ": " . htmlspecialchars( mysql_error() );
211 switch( $err ) {
212 case 1045:
213 if( $conf->Root ) {
214 $errs["RootPW"] = "Check password";
215 } else {
216 $errs["DBuser"] = "Check name/pass";
217 $errs["DBpassword"] = "or enter root";
218 $errs["DBpassword2"] = "password below";
219 $errs["RootPW"] = "Got root?";
220 }
221 break;
222 case 2002:
223 case 2003:
224 $errs["DBserver"] = "Connection failed";
225 break;
226 default:
227 $errs["DBserver"] = "Couldn't connect to database";
228 }
229 continue;
230 }
231 print "<li>Connected to database... $myver";
232 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
233 print "; enabling MySQL 4 enhancements";
234 $conf->DBmysql4 = true;
235 $local = writeLocalSettings( $conf );
236 }
237 print "</li>\n";
238
239 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
240 if( $sel ) {
241 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
242 } else {
243 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
244 if( !$res ) {
245 print "<li>Couldn't create database <tt>" .
246 htmlspecialchars( $wgDBname ) .
247 "</tt>; try with root access or check your username/pass.</li>\n";
248 $errs["RootPW"] = "&lt;- Enter";
249 continue;
250 }
251 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
252 }
253
254 $wgDatabase->selectDB( $wgDBname );
255
256 if( $wgDatabase->tableExists( "cur" ) ) {
257 print "<li>There are already MediaWiki tables in this database. Skipping rest of database setup...</li>\n";
258 } else {
259 # FIXME: Check for errors
260 print "<li>Creating tables...";
261 dbsource( "../maintenance/tables.sql", $wgDatabase );
262 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
263 dbsource( "../maintenance/indexes.sql", $wgDatabase );
264 print " done.</li>\n";
265
266 print "<li>Initializing data...";
267 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
268 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
269
270 # FIXME: Initial sysop account
271 # FIXME: Main page, logs
272 # FIXME: Initialize messages
273 print "<li>(NYI: accounts, pages, messages)</li>\n";
274
275 if( $conf->Root ) {
276 # Grant user permissions
277 dbsource( "../maintenance/users.sql", $wgDatabase );
278 }
279 }
280
281 /* Write out the config file now that all is well */
282 print "<p>Creating LocalSettings.php...</p>\n\n";
283 $f = fopen( "LocalSettings.php", "xt" );
284 if( $f == false ) {
285 dieout( "Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a fiel of that name here." );
286 }
287 fwrite( $f, "<" . "?php\n$local\n?" . ">" );
288 fclose( $f );
289
290 print "<p>Success! Move the LocalSettings.php file into the parent directory, then follow
291 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
292
293 } while( false );
294 }
295 ?>
296 </ul>
297
298
299 <?php
300
301 if( count( $errs ) ) {
302 /* Display options form */
303
304 if( $conf->posted ) {
305 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
306 }
307 ?>
308 <h2>Database config</h2>
309
310 <form name="config" method="post">
311
312 <dl class="setup">
313 <dd><?php
314 aField( $conf, "DBserver", "MySQL server" );
315 ?></dd>
316 <dt>
317 If your database server isn't on your web server, enter the name
318 or IP address here.
319 </dt>
320
321 <dd><?php
322 aField( $conf, "DBname", "Database name" );
323 ?></dd>
324 <dd><?php
325 aField( $conf, "DBuser", "DB username" );
326 ?></dd>
327 <dd><?php
328 aField( $conf, "DBpassword", "DB password", "password" );
329 ?></dd>
330 <dd><?php
331 aField( $conf, "DBpassword2", "again", "password" );
332 ?></dd>
333 <dt>
334 If you only have a single user account and database available,
335 enter those here. If you have database root access (see below)
336 you can specify new accounts/databases to be created.
337 </dt>
338
339
340 <dd>
341 <?php
342 aField( $conf, "RootPW", "DB root password", "password" );
343 ?>
344 </dd>
345 <dt>
346 You will only need this if the database and/or user account
347 above don't already exist.
348 Do <em>not</em> type in your machine's root password! MySQL
349 has its own "root" user with a separate password. (It might
350 even be blank, depending on your configuration.)
351 </dt>
352 </dl>
353
354 <h2>Site config</h2>
355
356 <dl class="setup">
357 <dd>
358 <?php
359 aField( $conf, "Sitename", "Site name:" );
360 ?>
361 </dd>
362 <dt>
363 Your site name should be a relatively short word. It'll appear as the namespace
364 name for 'meta' pages as well as throughout the user interface. Good site names
365 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
366 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
367 which may cause problems.
368 </dt>
369
370 <dd>
371 <?php
372 aField( $conf, "EmergencyContact", "Contact e-mail" );
373 ?>
374 </dd>
375 <dt>
376 If the wiki breaks terribly, it may display this contact address.
377 </dt>
378
379 <dd>
380 <label for="LanguageCode">Language</label>
381 <select id="LanguageCode" name="LanguageCode">
382 <?php
383 $list = getLanguageList();
384 foreach( $list as $code => $name ) {
385 $sel = ($code == $conf->LanguageCode) ? "selected" : "";
386 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
387 }
388 ?>
389 </select>
390 </dd>
391 <dt>
392 You may select the language for the user interface of the wiki...
393 Some localizations are less complete than others. This also controls
394 the character encoding; Unicode is more flexible, but Latin-1 may be
395 more compatible with older browsers for some languages. The default
396 for most languages is Unicode.
397 </dt>
398
399 <dd>
400 <label>&nbsp;</label>
401 <input type="submit" value="Install!" />
402 </dd>
403 </dl>
404
405 </form>
406
407 <?php
408 }
409
410 /* -------------------------------------------------------------------------------------- */
411
412 function writeAdminSettings( $conf ) {
413 return "
414 \$wgDBadminuser = \"{$conf->DBadminuser}\";
415 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
416 ";
417 }
418
419 function writeLocalSettings( $conf ) {
420 $conf->DBmysql4 = $conf->DBmysql4 ? 'true' : 'false';
421 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
422 $conf->DBsqluser = $conf->DBuser;
423 $conf->DBsqlpassword = $conf->DBpassword;
424 $conf->PasswordSender = $conf->EmergencyContact;
425 if( $conf->LanguageCode == "en-utf8" ) {
426 $conf->LanguageCode = "en";
427 $conf->Encoding = "UTF-8";
428 }
429 return "
430 # This file was automatically generated. Don't touch unless you
431 # know what you're doing; see LocalSettings.sample for an edit-
432 # friendly file.
433
434 \$IP = \"{$conf->IP}\";
435 ini_set( \"include_path\", \"\$IP/includes:\$IP/languages:\" . ini_get(\"include_path\") );
436 include_once( \"DefaultSettings.php\" );
437
438 if( \$wgCommandLineMode ) {
439 die( \"Can't use command-line utils with in-place install yet, sorry.\" );
440 }
441
442 \$wgSitename = \"{$conf->Sitename}\";
443
444 \$wgScriptPath = \"{$conf->ScriptPath}\";
445 \$wgScript = \"\$wgScriptPath/index.php\";
446 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
447
448 \$wgArticlePath = \"\$wgScript?title=\$1\";
449 # \$wgArticlePath = \"\$wgScript/\$1\"; # Prettier if you're setup for it
450
451 \$wgStyleSheetPath = \"\$wgScriptPath/stylesheets\";
452 \$wgStyleSheetDirectory = \"\$IP/stylesheets\";
453
454 \$wgUploadPath = \"\$wgScriptPath/images\";
455 \$wgUploadDirectory = \"\$IP/images\";
456 \$wgLogo = \"\$wgUploadPath/wiki.png\";
457
458 \$wgEmergencyContact = \"{$conf->EmergencyContact}\";
459 \$wgPasswordSender = \"{$conf->PasswordSender}\";
460
461 \$wgDBserver = \"{$conf->DBserver}\";
462 \$wgDBname = \"{$conf->DBname}\";
463 \$wgDBuser = \"{$conf->DBuser}\";
464 \$wgDBpassword = \"{$conf->DBpassword}\";
465 \$wgDBsqluser = \"{$conf->DBsqluser}\";
466 \$wgDBsqlpassword = \"{$conf->DBsqlpassword}\";
467
468 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
469
470 \$wgUseImageResize = {$conf->UseImageResize};
471
472 ## If you have the appropriate support software installed
473 ## you can enable inline LaTeX equations:
474 # \$wgUseTeX = true;
475 # \$wgMathPath = \"{$wgUploadPath}/math\";
476 # \$wgMathDirectory = \"{$wgUploadDirectory}/math\";
477 # \$wgTmpDirectory = \"{$wgUploadDirectory}/tmp\";
478
479 \$wgLocalInterwiki = \$wgSitename;
480
481 \$wgLanguageCode = \"{$conf->LanguageCode}\";
482 " . ($conf->Encoding ? "\$wgInputEncoding = \$wgOutputEncoding = \"{$conf->Encoding}\";" : "" ) . "
483
484 ";
485 }
486
487 function dieout( $text ) {
488 die( $text . "\n\n</body>\n</html>" );
489 }
490
491 function importPost( $name, $default = "" ) {
492 if( isset( $_POST[$name] ) ) {
493 return $_POST[$name];
494 } else {
495 return $default;
496 }
497 }
498
499 function aField( &$conf, $field, $text, $type = "" ) {
500 if( $type != "" ) $type = "type=\"$type\"";
501 echo "\t\t<label for=\"$field\">$text</label>\n";
502 echo "\t\t<input $type name=\"$field\" id=\"$field\" value=\"";
503 echo htmlspecialchars( $conf->$field );
504 echo "\" />\n";
505
506 global $errs;
507 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
508 }
509
510 function getLanguageList() {
511 global $wgLanguageNames;
512 if( !isset( $wgLanguageNames ) ) {
513 $wgLanguageCode = "xxx";
514 function wfLocalUrl( $x ) { return $x; }
515 function wfLocalUrlE( $x ) { return $x; }
516 include( "../languages/Language.php" );
517 }
518
519 $codes = array();
520 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
521
522 $d = opendir( "../languages" );
523 while( false !== ($f = readdir( $d ) ) ) {
524 if( preg_match( '/Language([A-Z][a-z]+)\.php$/', $f, $m ) ) {
525 $code = strtolower( $m[1] );
526 $codes[$code] = "$code - " . $wgLanguageNames[$code];
527 if( in_array( $code, $latin1 ) ) {
528 $codes[$code] .= " - Latin-1";
529 }
530 }
531 }
532 $codes["en-utf8"] = "en - English - Unicode";
533 closedir( $d );
534 ksort( $codes );
535 return $codes;
536 }
537
538 ?>
539
540 </body>
541 </html>