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