Use ob_implicit_flush() rather than ob_end_flush() in install-utils.
[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 error_reporting( E_ALL );
22 header( "Content-type: text/html; charset=utf-8" );
23 @ini_set( "display_errors", true );
24
25 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
26 "http://www.w3.org/TR/html4/loose.dtd">
27 <html>
28 <head>
29 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
30 <meta name="robots" content="noindex,nofollow">
31 <title>MediaWiki installation</title>
32 <style type="text/css">
33 #credit {
34 float: right;
35 width: 200px;
36 font-size: 0.7em;
37 background-color: #eee;
38 color: black;
39 border: solid 1px #444;
40 padding: 8px;
41 margin-left: 8px;
42 }
43
44 dl.setup dd {
45 margin-left: 0;
46 }
47 dl.setup dd label.column {
48 clear: left;
49 font-weight: bold;
50 width: 12em;
51 float: left;
52 text-align: right;
53 padding-right: 1em;
54 }
55 dl.setup dt {
56 clear: left;
57 font-size: 0.8em;
58 margin-left: 10em;
59 /* margin-right: 200px; */
60 margin-bottom: 2em;
61 }
62 .error {
63 color: red;
64 }
65 ul.plain {
66 list-style: none;
67 clear: both;
68 margin-left: 12em;
69 }
70 </style>
71 </head>
72
73 <body>
74
75 <div id="credit">
76 <center>
77 <a href="http://www.mediawiki.org/"><img
78 src="../stylesheets/images/wiki.png" width="135" height="135" alt="" border="0" /></a>
79 </center>
80
81 <b><a href="http://www.mediawiki.org/">MediaWiki</a></b> is
82 Copyright (C) 2001-2004 by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
83 Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
84
85 <ul>
86 <li><a href="../README">Readme</a></li>
87 <li><a href="../RELEASE-NOTES">Release notes</a></li>
88 <li><a href="../docs/">doc/</a></li>
89 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
90 </ul>
91
92 <p>This program is free software; you can redistribute it and/or modify
93 it under the terms of the GNU General Public License as published by
94 the Free Software Foundation; either version 2 of the License, or
95 (at your option) any later version.</p>
96
97 <p>This program is distributed in the hope that it will be useful,
98 but WITHOUT ANY WARRANTY; without even the implied warranty of
99 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100 GNU General Public License for more details.</p>
101
102 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
103 along with this program; if not, write to the Free Software
104 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
105 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
106 </div>
107
108 <?php
109
110 $IP = ".."; # Just to suppress notices, not for anything useful
111 define( "MEDIAWIKI", true );
112 define( "MEDIAWIKI_INSTALL", true );
113 require_once( "../includes/Defines.php" );
114 require_once( "../includes/DefaultSettings.php" );
115 require_once( "../includes/MagicWord.php" );
116 require_once( "../includes/Namespace.php" );
117 ?>
118
119 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
120
121
122 <?php
123
124 /* Check for existing configurations and bug out! */
125
126 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
127 dieout( "<h2>Wiki is configured.</h2>
128
129 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
130
131 <p>(You should probably remove this directory for added security.)</p>" );
132 }
133
134 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
135 dieout( "<h2>You're configured!</h2>
136
137 <p>Please move <tt>LocalSettings.php</tt> to the parent directory, then
138 <a href='../index.php'>try out your wiki</a>.
139 (You should remove this config directory for added security once you're done.)</p>" );
140 }
141
142 if( !is_writable( "." ) ) {
143 dieout( "<h2>Can't write config file, aborting</h2>
144
145 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
146 writable by the web server. Once configuration is done you'll move the created
147 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
148 then remove the <tt>config</tt> subdirectory entirely.</p>
149
150 <p>To make the directory writable on a Unix/Linux system:</p>
151
152 <pre>
153 cd <i>/path/to/wiki</i>
154 chmod a+w config
155 </pre>" );
156 }
157
158
159 require_once( "../install-utils.inc" );
160 require_once( "../maintenance/updaters.inc" );
161 require_once( "../maintenance/convertLinks.inc" );
162 require_once( "../maintenance/archives/moveCustomMessages.inc" );
163
164 class ConfigData {
165 function getEncoded( $data ) {
166 # Hackish
167 global $wgUseLatin1;
168 if( $wgUseLatin1 ) {
169 return utf8_decode( $data ); /* to latin1 wikis */
170 } else {
171 return $data;
172 }
173 }
174 function getSitename() { return $this->getEncoded( $this->Sitename ); }
175 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
176 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
177 }
178
179 ?>
180
181 <p><i>Please include all of the lines below when reporting installation problems.</i></p>
182
183 <h2>Checking environment...</h2>
184 <ul>
185 <?php
186 $endl = "
187 ";
188 $wgConfiguring = true;
189 $conf = new ConfigData;
190
191 install_version_checks();
192
193 print "<li>PHP " . phpversion() . ": ";
194 if( version_compare( phpversion(), "5.0", "lt" ) ) {
195 print "ok";
196 } else {
197 print " <b>the MonoBook skin will be disabled due to an incompatibility
198 between the PHPTAL template library and PHP 5</b>. The wiki should
199 function normally, but with the older look and feel.";
200 }
201 print "</li>\n";
202
203 if( ini_get( "register_globals" ) ) {
204 ?>
205 <li><b class='error'>Warning:</b> <b>PHP's
206 <tt><a href="http://php.net/register_globals">register_globals</a></tt>
207 option is enabled.</b> MediaWiki will work correctly, but this setting
208 increases your exposure to potential security vulnerabilities in PHP-based
209 software running on your server. <b>You should disable it if you are able.</b></li>
210 <?php
211 }
212
213 if( ini_get( "safe_mode" ) ) {
214 ?>
215 <li class='error'><b>Warning: PHP's
216 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
217 You will likely have problems caused by this. You may need to make the
218 'images' subdirectory writable or specify a TMP environment variable pointing to
219 a writable temporary directory owned by you, since safe mode breaks the system
220 temporary directory.</li>
221 <?php
222 }
223
224 $sapi = php_sapi_name();
225 $conf->prettyURLs = true;
226 print "<li>PHP server API is $sapi; ";
227 switch( $sapi ) {
228 case "apache":
229 case "apache2handler":
230 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
231 break;
232 case "cgi":
233 case "cgi-fcgi":
234 case "apache2filter":
235 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
236 $conf->prettyURLs = false;
237 break;
238 default:
239 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
240 }
241 print "</li>\n";
242
243 $conf->xml = function_exists( "utf8_encode" );
244 if( $conf->xml ) {
245 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
246 } else {
247 dieout( "PHP's XML module is missing; the wiki requires functions in
248 this module and won't work in this configuration.
249 If you're running Mandrake, install the php-xml package." );
250 }
251
252 $memlimit = ini_get( "memory_limit" );
253 $conf->raiseMemory = false;
254 if( empty( $memlimit ) ) {
255 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
256 } else {
257 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <b>If this is too low, installation may fail!</b> ";
258 $n = IntVal( $memlimit );
259 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
260 $n = IntVal( $m[1] * (1024*1024) );
261 }
262 if( $n < 20*1024*1024 ) {
263 print "Attempting to raise limit to 20M... ";
264 if( false === ini_set( "memory_limit", "20M" ) ) {
265 print "failed.";
266 } else {
267 $conf->raiseMemory = true;
268 print "ok.";
269 }
270 }
271 print "</li>\n";
272 }
273
274 $conf->zlib = function_exists( "gzencode" );
275 if( $conf->zlib ) {
276 print "<li>Have zlib support; enabling output compression.</li>\n";
277 } else {
278 print "<li>No zlib support.</li>\n";
279 }
280
281 $conf->ImageMagick = false;
282
283 $conf->HaveGD = function_exists( "imagejpeg" );
284 if( $conf->HaveGD ) {
285 print "<li>Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads.</li>\n";
286 } else {
287 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin" );
288 foreach( $imcheck as $dir ) {
289 $im = "$dir/convert";
290 if( file_exists( $im ) ) {
291 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
292 $conf->ImageMagick = $im;
293 break;
294 }
295 }
296 if( !$conf->ImageMagick ) {
297 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
298 }
299 }
300
301 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
302
303 # $conf->IP = "/Users/brion/Sites/inplace";
304 chdir( ".." );
305 $conf->IP = getcwd();
306 chdir( "config" );
307 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
308
309 # $conf->ScriptPath = "/~brion/inplace";
310 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
311 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
312
313 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
314
315 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
316 $conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
317 $conf->DBserver = importPost( "DBserver", "localhost" );
318 $conf->DBname = importPost( "DBname", "wikidb" );
319 $conf->DBuser = importPost( "DBuser", "wikiuser" );
320 $conf->DBpassword = importPost( "DBpassword" );
321 $conf->DBpassword2 = importPost( "DBpassword2" );
322 $conf->RootPW = importPost( "RootPW" );
323 $conf->LanguageCode = importPost( "LanguageCode", "en" );
324 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
325 $conf->SysopPass = importPost( "SysopPass" );
326 $conf->SysopPass2 = importPost( "SysopPass2" );
327
328 /* Check for validity */
329 $errs = array();
330
331 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
332 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
333 }
334 if( $conf->DBuser == "" ) {
335 $errs["DBuser"] = "Must not be blank";
336 }
337 if( $conf->DBpassword == "" ) {
338 $errs["DBpassword"] = "Must not be blank";
339 }
340 if( $conf->DBpassword != $conf->DBpassword2 ) {
341 $errs["DBpassword2"] = "Passwords don't match!";
342 }
343
344 if( $conf->SysopPass == "" ) {
345 $errs["SysopPass"] = "Must not be blank";
346 }
347 if( $conf->SysopPass != $conf->SysopPass2 ) {
348 $errs["SysopPass2"] = "Passwords don't match!";
349 }
350
351 $conf->License = importRequest( "License", "none" );
352 if( $conf->License == "gfdl" ) {
353 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
354 $conf->RightsText = "GNU Free Documentation License 1.2";
355 $conf->RightsCode = "gfdl";
356 $conf->RightsIcon = '${wgStylePath}/images/gnu-fdl.png';
357 } elseif( $conf->License == "none" ) {
358 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
359 } else {
360 $conf->RightsUrl = importRequest( "RightsUrl", "" );
361 $conf->RightsText = importRequest( "RightsText", "" );
362 $conf->RightsCode = importRequest( "RightsCode", "" );
363 $conf->RightsIcon = importRequest( "RightsIcon", "" );
364 }
365
366 if( $conf->posted && ( 0 == count( $errs ) ) ) {
367 do { /* So we can 'continue' to end prematurely */
368 $conf->Root = ($conf->RootPW != "");
369
370 /* Load up the settings and get installin' */
371 $local = writeLocalSettings( $conf );
372 $wgCommandLineMode = false;
373 chdir( ".." );
374 eval($local);
375 $wgDBadminuser = $wgDBuser;
376 $wgDBadminpassword = $wgDBpassword;
377 $wgCommandLineMode = true;
378 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
379 require_once( "includes/Setup.php" );
380 chdir( "config" );
381
382 require_once( "../maintenance/InitialiseMessages.inc" );
383
384 $wgTitle = Title::newFromText( "Installation script" );
385 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
386 $wgDatabase->mIgnoreErrors = true;
387
388 @$myver = mysql_get_server_info( $wgDatabase->mConn );
389 if( $myver ) {
390 $conf->Root = true;
391 print "<li>Connected as root (automatic)</li>\n";
392 } else {
393 print "<li>MySQL error " . ($err = mysql_errno() ) .
394 ": " . htmlspecialchars( mysql_error() );
395 $ok = false;
396 switch( $err ) {
397 case 1045:
398 if( $conf->Root ) {
399 $errs["RootPW"] = "Check password";
400 } else {
401 print "<li>Trying regular user...\n";
402 /* Try the regular user... */
403 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
404 $wgDatabase->isOpen();
405 $wgDatabase->mIgnoreErrors = true;
406 @$myver = mysql_get_server_info( $wgDatabase->mConn );
407 if( !$myver ) {
408 $errs["DBuser"] = "Check name/pass";
409 $errs["DBpassword"] = "or enter root";
410 $errs["DBpassword2"] = "password below";
411 $errs["RootPW"] = "Got root?";
412 print " need password.</li>\n";
413 } else {
414 $conf->Root = false;
415 $conf->RootPW = "";
416 print " ok.</li>\n";
417 # And keep going...
418 $ok = true;
419 }
420 break;
421 }
422 case 2002:
423 case 2003:
424 $errs["DBserver"] = "Connection failed";
425 break;
426 default:
427 $errs["DBserver"] = "Couldn't connect to database";
428 break;
429 }
430 if( !$ok ) continue;
431 }
432
433 if ( !$wgDatabase->isOpen() ) {
434 $errs["DBserver"] = "Couldn't connect to database";
435 continue;
436 }
437
438 print "<li>Connected to database... $myver";
439 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
440 print "; enabling MySQL 4 enhancements";
441 $conf->DBmysql4 = true;
442 $local = writeLocalSettings( $conf );
443 }
444 print "</li>\n";
445
446 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
447 if( $sel ) {
448 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
449 } else {
450 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
451 if( !$res ) {
452 print "<li>Couldn't create database <tt>" .
453 htmlspecialchars( $wgDBname ) .
454 "</tt>; try with root access or check your username/pass.</li>\n";
455 $errs["RootPW"] = "&lt;- Enter";
456 continue;
457 }
458 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
459 }
460
461 $wgDatabase->selectDB( $wgDBname );
462
463 if( $wgDatabase->tableExists( "cur" ) ) {
464 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n<pre>";
465
466 chdir( ".." );
467 flush();
468 do_ipblocks_update(); flush();
469 do_interwiki_update(); flush();
470 do_index_update(); flush();
471 do_linkscc_update(); flush();
472 do_linkscc_1_3_update(); flush();
473 do_hitcounter_update(); flush();
474 do_recentchanges_update(); flush();
475 convertLinks(); flush();
476 do_user_real_name_update(); flush();
477 do_querycache_update(); flush();
478 do_objectcache_update(); flush();
479 do_categorylinks_update(); flush();
480 do_image_name_unique_update(); flush();
481
482 if ( isTemplateInitialised() ) {
483 print "Template namespace already initialised\n";
484 } else {
485 moveCustomMessages( 1 ); flush();
486 moveCustomMessages( 2 ); flush();
487 moveCustomMessages( 3 ); flush();
488 }
489
490 initialiseMessages(); flush();
491 chdir( "config" );
492
493 print "</pre>\n";
494 print "<li>Finished update checks.</li>\n";
495 } else {
496 # FIXME: Check for errors
497 print "<li>Creating tables...";
498 dbsource( "../maintenance/tables.sql", $wgDatabase );
499 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
500 dbsource( "../maintenance/indexes.sql", $wgDatabase );
501 print " done.</li>\n";
502
503 print "<li>Initializing data...";
504 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
505 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
506 # setting up the db user
507 if( $conf->Root ) {
508 print "<li>Granting user permissions...</li>\n";
509 dbsource( "../maintenance/users.sql", $wgDatabase );
510 }
511
512 if( $conf->SysopName ) {
513 $u = User::newFromName( $conf->getSysopName() );
514 if ( 0 == $u->idForName() ) {
515 $u->addToDatabase();
516 $u->setPassword( $conf->getSysopPass() );
517 $u->addRight( "sysop" );
518 $u->addRight( "bureaucrat" );
519 $u->saveSettings();
520 print "<li>Created sysop account <tt>" .
521 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
522 } else {
523 print "<li>Could not create user - already exists!</li>\n";
524 }
525 } else {
526 print "<li>Skipped sysop account creation, no name given.</li>\n";
527 }
528
529 print "<li>Initialising log pages...";
530 $logs = array(
531 "uploadlogpage" => "uploadlogpagetext",
532 "dellogpage" => "dellogpagetext",
533 "protectlogpage" => "protectlogtext",
534 "blocklogpage" => "blocklogtext"
535 );
536 $metaNamespace = Namespace::getWikipedia();
537 $now = wfTimestampNow();
538 $won = wfInvertTimestamp( $now );
539 foreach( $logs as $page => $text ) {
540 $logTitle = $wgDatabase->strencode( $wgLang->ucfirst( str_replace( " ", "_", wfMsgNoDB( $page ) ) ) );
541 $logText = $wgDatabase->strencode( wfMsgNoDB( $text ) );
542 $wgDatabase->query( "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
543 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) " .
544 "VALUES ($metaNamespace,'$logTitle','$logText','sysop','$now','$won','$now')" );
545 }
546 print "</li>\n";
547
548 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
549 $title = $titleobj->getDBkey();
550 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
551 "VALUES (0,'$title','" .
552 wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) . "','$now','$won','$now')";
553 $wgDatabase->query( $sql, $fname );
554
555 print "<li><pre>";
556 initialiseMessages();
557 print "</pre></li>\n";
558 }
559
560 /* Write out the config file now that all is well */
561 print "<p>Creating LocalSettings.php...</p>\n\n";
562 $localSettings = "<" . "?php$endl$local$endl?" . ">";
563
564 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
565 $xt = "xt"; # Refuse to overwrite an existing file
566 } else {
567 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
568 }
569 $f = fopen( "LocalSettings.php", $xt );
570
571 if( $f == false ) {
572 dieout( "<p>Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a file of that name here...</p>\n" .
573 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
574 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
575 }
576 fwrite( $f, $localSettings );
577 fclose( $f );
578
579 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
580 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
581
582 } while( false );
583 }
584 ?>
585 </ul>
586
587
588 <?php
589
590 if( count( $errs ) ) {
591 /* Display options form */
592
593 if( $conf->posted ) {
594 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
595 }
596 ?>
597
598 <form name="config" method="post">
599
600
601 <h2>Site config</h2>
602
603 <dl class="setup">
604 <dd>
605 <?php
606 aField( $conf, "Sitename", "Site name:" );
607 ?>
608 </dd>
609 <dt>
610 Your site name should be a relatively short word. It'll appear as the namespace
611 name for 'meta' pages as well as throughout the user interface. Good site names
612 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
613 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
614 which may cause problems.
615 </dt>
616
617 <dd>
618 <?php
619 aField( $conf, "EmergencyContact", "Contact e-mail" );
620 ?>
621 </dd>
622 <dt>
623 This will be used as the return address for password reminders and
624 may be displayed in some error conditions so visitors can get in
625 touch with you.
626 </dt>
627
628 <dd>
629 <label class='column' for="LanguageCode">Language</label>
630 <select id="LanguageCode" name="LanguageCode">
631 <?php
632 $list = getLanguageList();
633 foreach( $list as $code => $name ) {
634 $sel = ($code == $conf->LanguageCode) ? "selected" : "";
635 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
636 }
637 ?>
638 </select>
639 </dd>
640 <dt>
641 You may select the language for the user interface of the wiki...
642 Some localizations are less complete than others. This also controls
643 the character encoding; Unicode is more flexible, but Latin-1 may be
644 more compatible with older browsers for some languages. Unicode will
645 be used where not specified otherwise.
646 </dt>
647
648 <dd>
649 <label class='column'>Copyright/license metadata</label>
650 <div>Select one:</div>
651
652 <ul class="plain">
653 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
654 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
655 <li><?php
656 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
657 $partner = "MediaWiki";
658 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
659 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
660 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
661 print "<a href=\"$ccApp\">choose</a>";
662 ?> (link will wipe out any other data in this form!)
663 <?php if( $conf->License == "cc" ) { ?>
664 <ul>
665 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
666 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
667 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
668 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
669 </ul>
670 <?php } ?>
671 </li>
672 </ul>
673 </dd>
674 <dt>
675 MediaWiki can include a basic license notice, icon, and machine-reable
676 copyright metadata if your wiki's content is to be licensed under
677 the GNU FDL or a Creative Commons license. If you're not sure, leave
678 it at "none".
679 </dt>
680
681
682 <dd>
683 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
684 </dd>
685 <dd>
686 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
687 </dd>
688 <dd>
689 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
690 </dd>
691 <dt>
692 A sysop user account can lock or delete pages, block problematic IP
693 addresses from editing, and other maintenance tasks. If creating a new
694 wiki database, a sysop account will be created with the given name
695 and password.
696 </dt>
697 </dl>
698
699 <h2>Database config</h2>
700
701 <dl class="setup">
702 <dd><?php
703 aField( $conf, "DBserver", "MySQL server" );
704 ?></dd>
705 <dt>
706 If your database server isn't on your web server, enter the name
707 or IP address here.
708 </dt>
709
710 <dd><?php
711 aField( $conf, "DBname", "Database name" );
712 ?></dd>
713 <dd><?php
714 aField( $conf, "DBuser", "DB username" );
715 ?></dd>
716 <dd><?php
717 aField( $conf, "DBpassword", "DB password", "password" );
718 ?></dd>
719 <dd><?php
720 aField( $conf, "DBpassword2", "again", "password" );
721 ?></dd>
722 <dt>
723 If you only have a single user account and database available,
724 enter those here. If you have database root access (see below)
725 you can specify new accounts/databases to be created.
726 </dt>
727
728
729 <dd>
730 <?php
731 aField( $conf, "RootPW", "DB root password", "password" );
732 ?>
733 </dd>
734 <dt>
735 You will only need this if the database and/or user account
736 above don't already exist.
737 Do <em>not</em> type in your machine's root password! MySQL
738 has its own "root" user with a separate password. (It might
739 even be blank, depending on your configuration.)
740 </dt>
741
742 <dd>
743 <label class='column'>&nbsp;</label>
744 <input type="submit" value="Install!" />
745 </dd>
746 </dl>
747
748
749 </form>
750
751 <?php
752 }
753
754 /* -------------------------------------------------------------------------------------- */
755
756 function writeAdminSettings( $conf ) {
757 return "
758 \$wgDBadminuser = \"{$conf->DBadminuser}\";
759 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
760 ";
761 }
762
763 function escapePhpString( $string ) {
764 return strtr( $string,
765 array(
766 "\n" => "\\n",
767 "\r" => "\\r",
768 "\t" => "\\t",
769 "\\" => "\\\\",
770 "\$" => "\\\$",
771 "\"" => "\\\""
772 ));
773 }
774
775 function writeLocalSettings( $conf ) {
776 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
777 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
778 $conf->PasswordSender = $conf->EmergencyContact;
779 if( preg_match( '/^([a-z]+)-latin1$/', $conf->LanguageCode, $m ) ) {
780 $conf->LanguageCode = $m[1];
781 $conf->Latin1 = true;
782 } else {
783 $conf->Latin1 = false;
784 }
785 $zlib = ($conf->zlib ? "" : "# ");
786 $magic = ($conf->ImageMagick ? "" : "# ");
787 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
788 $pretty = ($conf->prettyURLs ? "" : "# ");
789 $ugly = ($conf->prettyURLs ? "# " : "");
790 $rights = ($conf->RightsUrl) ? "" : "# ";
791
792 $file = @fopen( "/dev/random", "r" );
793 if ( $file ) {
794 $proxyKey = bin2hex( fread( $file, 32 ) );
795 fclose( $file );
796 } else {
797 $proxyKey = "";
798 for ( $i=0; $i<8; $i++ ) {
799 $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
800 }
801 print "<li>Warning: \$wgProxyKey is insecure</li>\n";
802 }
803
804 # Add slashes to strings for double quoting
805 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
806 if( $conf->License == 'gfdl' ) {
807 # Needs literal string interpolation for the current style path
808 $slconf['RightsIcon'] = $conf->RightsIcon;
809 }
810
811 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
812 return "
813 # This file was automatically generated by the MediaWiki installer.
814 # If you make manual changes, please keep track in case you need to
815 # recreate them later.
816
817 \$IP = \"{$slconf['IP']}\";
818 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
819 include_once( \"DefaultSettings.php\" );
820
821 # If PHP's memory limit is very low, some operations may fail.
822 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
823
824 if ( \$wgCommandLineMode ) {
825 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
826 die( \"This script must be run from the command line\\n\" );
827 }
828 } elseif ( empty( \$wgConfiguring ) ) {
829 ## Compress output if the browser supports it
830 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
831 }
832
833 \$wgSitename = \"{$slconf['Sitename']}\";
834
835 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
836 \$wgScript = \"\$wgScriptPath/index.php\";
837 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
838
839 ## If using PHP as a CGI module, use the ugly URLs
840 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
841 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
842
843 \$wgStylePath = \"\$wgScriptPath/stylesheets\";
844 \$wgStyleDirectory = \"\$IP/stylesheets\";
845 \$wgLogo = \"\$wgStylePath/images/wiki.png\";
846
847 \$wgUploadPath = \"\$wgScriptPath/images\";
848 \$wgUploadDirectory = \"\$IP/images\";
849
850 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
851 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
852
853 \$wgDBserver = \"{$slconf['DBserver']}\";
854 \$wgDBname = \"{$slconf['DBname']}\";
855 \$wgDBuser = \"{$slconf['DBuser']}\";
856 \$wgDBpassword = \"{$slconf['DBpassword']}\";
857
858 ## To allow SQL queries through the wiki's Special:Askaql page,
859 ## uncomment the next lines. THIS IS VERY INSECURE. If you want
860 ## to allow semipublic read-only SQL access for your sysops,
861 ## you should define a MySQL user with limited privileges.
862 ## See MySQL docs: http://www.mysql.com/doc/en/GRANT.html
863 #
864 # \$wgAllowSysopQueries = true;
865 # \$wgDBsqluser = \"sqluser\";
866 # \$wgDBsqlpassword = \"sqlpass\";
867
868 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
869
870 ## To enable image uploads, make sure the 'images' directory
871 ## is writable, then uncomment this:
872 # \$wgDisableUploads = false;
873 \$wgUseImageResize = {$conf->UseImageResize};
874 {$magic}\$wgUseImageMagick = true;
875 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
876
877 ## If you have the appropriate support software installed
878 ## you can enable inline LaTeX equations:
879 # \$wgUseTeX = true;
880 \$wgMathPath = \"{\$wgUploadPath}/math\";
881 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
882 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
883
884 \$wgLocalInterwiki = \$wgSitename;
885
886 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
887 \$wgUseLatin1 = " . ($conf->Latin1 ? 'true' : 'false') . ";\n
888
889 \$wgProxyKey = \"$proxyKey\";
890
891 ## Default skin: you can change the default skin. Use the internal symbolic
892 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
893 # \$wgDefaultSkin = 'monobook';
894
895 ## For attaching licensing metadata to pages, and displaying an
896 ## appropriate copyright notice / icon. GNU Free Documentation
897 ## License and Creative Commons licenses are supported so far.
898 {$rights}\$wgEnableCreativeCommonsRdf = true;
899 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
900 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
901 \$wgRightsText = \"{$slconf['RightsText']}\";
902 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
903 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
904 ";
905 }
906
907 function dieout( $text ) {
908 die( $text . "\n\n</body>\n</html>" );
909 }
910
911 function importVar( &$var, $name, $default = "" ) {
912 if( isset( $var[$name] ) ) {
913 $retval = $var[$name];
914 if ( get_magic_quotes_gpc() ) {
915 $retval = stripslashes( $retval );
916 }
917 } else {
918 $retval = $default;
919 }
920 return $retval;
921 }
922
923 function importPost( $name, $default = "" ) {
924 return importVar( $_POST, $name, $default );
925 }
926
927 function importRequest( $name, $default = "" ) {
928 return importVar( $_REQUEST, $name, $default );
929 }
930
931 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
932 if( $type != "" ) {
933 $xtype = "type=\"$type\"";
934 } else {
935 $xtype = "";
936 }
937
938 if(!(isset($id)) or ($id == "") ) $id = $field;
939 $nolabel = ($type == "radio") || ($type == "hidden");
940 if( $nolabel ) {
941 echo "\t\t<label>";
942 } else {
943 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
944 }
945
946 if( $type == "radio" && $value == $conf->$field ) {
947 $checked = "checked='checked'";
948 } else {
949 $checked = "";
950 }
951 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
952 if( $type == "radio" ) {
953 echo htmlspecialchars( $value );
954 } else {
955 echo htmlspecialchars( $conf->$field );
956 }
957 echo "\" />\n";
958 if( $nolabel ) {
959 echo " $text</label>\n";
960 }
961
962 global $errs;
963 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
964 }
965
966 function getLanguageList() {
967 global $wgLanguageNames;
968 if( !isset( $wgLanguageNames ) ) {
969 $wgLanguageCode = "xxx";
970 function wfLocalUrl( $x ) { return $x; }
971 function wfLocalUrlE( $x ) { return $x; }
972 require_once( "../languages/Names.php" );
973 }
974
975 $codes = array();
976 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
977
978 $d = opendir( "../languages" );
979 while( false !== ($f = readdir( $d ) ) ) {
980 if( preg_match( '/Language([A-Z][a-z]+)\.php$/', $f, $m ) ) {
981 $code = strtolower( $m[1] );
982 if( in_array( $code, $latin1 ) ) {
983 $codes[$code] = "$code - " . $wgLanguageNames[$code] . " - Unicode";
984 $codes[$code.'-latin1'] = "$code - " . $wgLanguageNames[$code] . " - Latin-1";
985 } else {
986 $codes[$code] = "$code - " . $wgLanguageNames[$code];
987 }
988 }
989 }
990 closedir( $d );
991 ksort( $codes );
992 return $codes;
993 }
994
995 ?>
996
997 </body>
998 </html>