Create sysop account on new wiki creation.
[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
241 if( $conf->Root ) {
242 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
243 } else {
244 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
245 }
246 $wgDatabase->mIgnoreErrors = true;
247
248 if ( !$wgDatabase->isOpen() ) {
249 $errs["DBserver"] = "Couldn't connect to database";
250 continue;
251 }
252
253 @$myver = mysql_get_server_info( $wgDatabase->mConn );
254 if( !$myver ) {
255 print "<li>MySQL error " . ($err = mysql_errno() ) .
256 ": " . htmlspecialchars( mysql_error() );
257 switch( $err ) {
258 case 1045:
259 if( $conf->Root ) {
260 $errs["RootPW"] = "Check password";
261 } else {
262 $errs["DBuser"] = "Check name/pass";
263 $errs["DBpassword"] = "or enter root";
264 $errs["DBpassword2"] = "password below";
265 $errs["RootPW"] = "Got root?";
266 }
267 break;
268 case 2002:
269 case 2003:
270 $errs["DBserver"] = "Connection failed";
271 break;
272 default:
273 $errs["DBserver"] = "Couldn't connect to database";
274 }
275 continue;
276 }
277 print "<li>Connected to database... $myver";
278 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
279 print "; enabling MySQL 4 enhancements";
280 $conf->DBmysql4 = true;
281 $local = writeLocalSettings( $conf );
282 }
283 print "</li>\n";
284
285 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
286 if( $sel ) {
287 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
288 } else {
289 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
290 if( !$res ) {
291 print "<li>Couldn't create database <tt>" .
292 htmlspecialchars( $wgDBname ) .
293 "</tt>; try with root access or check your username/pass.</li>\n";
294 $errs["RootPW"] = "&lt;- Enter";
295 continue;
296 }
297 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
298 }
299
300 $wgDatabase->selectDB( $wgDBname );
301
302 if( $wgDatabase->tableExists( "cur" ) ) {
303 print "<li>There are already MediaWiki tables in this database. Skipping rest of database setup...</li>\n";
304 } else {
305 # FIXME: Check for errors
306 print "<li>Creating tables...";
307 dbsource( "../maintenance/tables.sql", $wgDatabase );
308 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
309 dbsource( "../maintenance/indexes.sql", $wgDatabase );
310 print " done.</li>\n";
311
312 print "<li>Initializing data...";
313 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
314 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
315
316 if( $conf->SysopName ) {
317 $u = User::newFromName( $conf->getSysopName() );
318 if ( 0 == $u->idForName() ) {
319 $u->addToDatabase();
320 $u->setPassword( $conf->getSysopPass() );
321 $u->addRight( "sysop" );
322 $u->addRight( "developer" ); /* ?? */
323 $u->saveSettings();
324 print "<li>Created sysop account <tt>" .
325 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
326 } else {
327 print "<li>Could not create user - already exists!</li>\n";
328 }
329 } else {
330 print "<li>Skipped sysop account creation, no name given.</li>\n";
331 }
332
333 # FIXME: Main page, logs
334 # FIXME: Initialize messages
335 print "<li>(NYI: accounts, pages, messages)</li>\n";
336
337 if( $conf->Root ) {
338 # Grant user permissions
339 dbsource( "../maintenance/users.sql", $wgDatabase );
340 }
341 }
342
343 /* Write out the config file now that all is well */
344 print "<p>Creating LocalSettings.php...</p>\n\n";
345 $f = fopen( "LocalSettings.php", "xt" );
346 if( $f == false ) {
347 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." );
348 }
349 fwrite( $f, "<" . "?php\n$local\n?" . ">" );
350 fclose( $f );
351
352 print "<p>Success! Move the LocalSettings.php file into the parent directory, then follow
353 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
354
355 } while( false );
356 }
357 ?>
358 </ul>
359
360
361 <?php
362
363 if( count( $errs ) ) {
364 /* Display options form */
365
366 if( $conf->posted ) {
367 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
368 }
369 ?>
370
371 <form name="config" method="post">
372
373
374 <h2>Site config</h2>
375
376 <dl class="setup">
377 <dd>
378 <?php
379 aField( $conf, "Sitename", "Site name:" );
380 ?>
381 </dd>
382 <dt>
383 Your site name should be a relatively short word. It'll appear as the namespace
384 name for 'meta' pages as well as throughout the user interface. Good site names
385 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
386 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
387 which may cause problems.
388 </dt>
389
390 <dd>
391 <?php
392 aField( $conf, "EmergencyContact", "Contact e-mail" );
393 ?>
394 </dd>
395 <dt>
396 This will be used as the return address for password reminders and
397 may be displayed in some error conditions so visitors can get in
398 touch with you.
399 </dt>
400
401 <dd>
402 <label for="LanguageCode">Language</label>
403 <select id="LanguageCode" name="LanguageCode">
404 <?php
405 $list = getLanguageList();
406 foreach( $list as $code => $name ) {
407 $sel = ($code == $conf->LanguageCode) ? "selected" : "";
408 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
409 }
410 ?>
411 </select>
412 </dd>
413 <dt>
414 You may select the language for the user interface of the wiki...
415 Some localizations are less complete than others. This also controls
416 the character encoding; Unicode is more flexible, but Latin-1 may be
417 more compatible with older browsers for some languages. Unicode will
418 be used where not specified otherwise.
419 </dt>
420
421 <dd>
422 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
423 </dd>
424 <dd>
425 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
426 </dd>
427 <dd>
428 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
429 </dd>
430 <dt>
431 A sysop user account can lock or delete pages, block problematic IP
432 addresses from editing, and other maintenance tasks. If creating a new
433 wiki database, a sysop account will be created with the given name
434 and password.
435 </dt>
436 </dl>
437
438 <h2>Database config</h2>
439
440 <dl class="setup">
441 <dd><?php
442 aField( $conf, "DBserver", "MySQL server" );
443 ?></dd>
444 <dt>
445 If your database server isn't on your web server, enter the name
446 or IP address here.
447 </dt>
448
449 <dd><?php
450 aField( $conf, "DBname", "Database name" );
451 ?></dd>
452 <dd><?php
453 aField( $conf, "DBuser", "DB username" );
454 ?></dd>
455 <dd><?php
456 aField( $conf, "DBpassword", "DB password", "password" );
457 ?></dd>
458 <dd><?php
459 aField( $conf, "DBpassword2", "again", "password" );
460 ?></dd>
461 <dt>
462 If you only have a single user account and database available,
463 enter those here. If you have database root access (see below)
464 you can specify new accounts/databases to be created.
465 </dt>
466
467
468 <dd>
469 <?php
470 aField( $conf, "RootPW", "DB root password", "password" );
471 ?>
472 </dd>
473 <dt>
474 You will only need this if the database and/or user account
475 above don't already exist.
476 Do <em>not</em> type in your machine's root password! MySQL
477 has its own "root" user with a separate password. (It might
478 even be blank, depending on your configuration.)
479 </dt>
480
481 <dd>
482 <label>&nbsp;</label>
483 <input type="submit" value="Install!" />
484 </dd>
485 </dl>
486
487
488 </form>
489
490 <?php
491 }
492
493 /* -------------------------------------------------------------------------------------- */
494
495 function writeAdminSettings( $conf ) {
496 return "
497 \$wgDBadminuser = \"{$conf->DBadminuser}\";
498 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
499 ";
500 }
501
502 function writeLocalSettings( $conf ) {
503 $conf->DBmysql4 = $conf->DBmysql4 ? 'true' : 'false';
504 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
505 $conf->DBsqluser = $conf->DBuser;
506 $conf->DBsqlpassword = $conf->DBpassword;
507 $conf->PasswordSender = $conf->EmergencyContact;
508 if( $conf->LanguageCode == "en-utf8" ) {
509 $conf->LanguageCode = "en";
510 $conf->Encoding = "UTF-8";
511 }
512 return "
513 # This file was automatically generated. Don't touch unless you
514 # know what you're doing; see LocalSettings.sample for an edit-
515 # friendly file.
516
517 \$IP = \"{$conf->IP}\";
518 ini_set( \"include_path\", \"\$IP/includes:\$IP/languages:\" . ini_get(\"include_path\") );
519 include_once( \"DefaultSettings.php\" );
520
521 if( \$wgCommandLineMode ) {
522 die( \"Can't use command-line utils with in-place install yet, sorry.\" );
523 }
524
525 \$wgSitename = \"{$conf->Sitename}\";
526
527 \$wgScriptPath = \"{$conf->ScriptPath}\";
528 \$wgScript = \"\$wgScriptPath/index.php\";
529 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
530
531 \$wgArticlePath = \"\$wgScript?title=\$1\";
532 # \$wgArticlePath = \"\$wgScript/\$1\"; # Prettier if you're setup for it
533
534 \$wgStyleSheetPath = \"\$wgScriptPath/stylesheets\";
535 \$wgStyleSheetDirectory = \"\$IP/stylesheets\";
536
537 \$wgUploadPath = \"\$wgScriptPath/images\";
538 \$wgUploadDirectory = \"\$IP/images\";
539 \$wgLogo = \"\$wgUploadPath/wiki.png\";
540
541 \$wgEmergencyContact = \"{$conf->EmergencyContact}\";
542 \$wgPasswordSender = \"{$conf->PasswordSender}\";
543
544 \$wgDBserver = \"{$conf->DBserver}\";
545 \$wgDBname = \"{$conf->DBname}\";
546 \$wgDBuser = \"{$conf->DBuser}\";
547 \$wgDBpassword = \"{$conf->DBpassword}\";
548 \$wgDBsqluser = \"{$conf->DBsqluser}\";
549 \$wgDBsqlpassword = \"{$conf->DBsqlpassword}\";
550
551 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
552
553 \$wgUseImageResize = {$conf->UseImageResize};
554
555 ## If you have the appropriate support software installed
556 ## you can enable inline LaTeX equations:
557 # \$wgUseTeX = true;
558 # \$wgMathPath = \"{$wgUploadPath}/math\";
559 # \$wgMathDirectory = \"{$wgUploadDirectory}/math\";
560 # \$wgTmpDirectory = \"{$wgUploadDirectory}/tmp\";
561
562 \$wgLocalInterwiki = \$wgSitename;
563
564 \$wgLanguageCode = \"{$conf->LanguageCode}\";
565 " . ($conf->Encoding ? "\$wgInputEncoding = \$wgOutputEncoding = \"{$conf->Encoding}\";" : "" ) . "
566
567 ";
568 }
569
570 function dieout( $text ) {
571 die( $text . "\n\n</body>\n</html>" );
572 }
573
574 function importPost( $name, $default = "" ) {
575 if( isset( $_POST[$name] ) ) {
576 return $_POST[$name];
577 } else {
578 return $default;
579 }
580 }
581
582 function aField( &$conf, $field, $text, $type = "" ) {
583 if( $type != "" ) $type = "type=\"$type\"";
584 echo "\t\t<label for=\"$field\">$text</label>\n";
585 echo "\t\t<input $type name=\"$field\" id=\"$field\" value=\"";
586 echo htmlspecialchars( $conf->$field );
587 echo "\" />\n";
588
589 global $errs;
590 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
591 }
592
593 function getLanguageList() {
594 global $wgLanguageNames;
595 if( !isset( $wgLanguageNames ) ) {
596 $wgLanguageCode = "xxx";
597 function wfLocalUrl( $x ) { return $x; }
598 function wfLocalUrlE( $x ) { return $x; }
599 include( "../languages/Language.php" );
600 }
601
602 $codes = array();
603 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
604
605 $d = opendir( "../languages" );
606 while( false !== ($f = readdir( $d ) ) ) {
607 if( preg_match( '/Language([A-Z][a-z]+)\.php$/', $f, $m ) ) {
608 $code = strtolower( $m[1] );
609 $codes[$code] = "$code - " . $wgLanguageNames[$code];
610 if( in_array( $code, $latin1 ) ) {
611 $codes[$code] .= " - Latin-1";
612 }
613 }
614 }
615 $codes["en-utf8"] = "en - English - Unicode";
616 closedir( $d );
617 ksort( $codes );
618 return $codes;
619 }
620
621 ?>
622
623 </body>
624 </html>