Add a big shiny obvious error message for safe mode even more obvious than the existi...
[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 print "<li>PHP " . phpversion() . " ok</li>\n";
193
194 if( ini_get( "safe_mode" ) ) {
195 ?>
196 <li class='error'><b>Warning: PHP's
197 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
198 You will likely have problems caused by this. You may need to make the
199 'images' subdirectory writable or specify a TMP environment variable pointing to
200 a writable temporary directory owned by you, since safe mode breaks the system
201 temporary directory.</li>
202 <?php
203 }
204
205 $sapi = php_sapi_name();
206 $conf->prettyURLs = true;
207 print "<li>PHP server API is $sapi; ";
208 switch( $sapi ) {
209 case "apache":
210 case "apache2handler":
211 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
212 break;
213 case "cgi":
214 case "cgi-fcgi":
215 case "apache2filter":
216 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
217 $conf->prettyURLs = false;
218 break;
219 default:
220 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
221 }
222 print "</li>\n";
223
224 $conf->xml = function_exists( "utf8_encode" );
225 if( $conf->xml ) {
226 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
227 } else {
228 print "<li><b>XML / Latin1-UTF-8 conversion is missing! Wiki will probably not work.</b></li>\n";
229 }
230
231 $memlimit = ini_get( "memory_limit" );
232 $conf->raiseMemory = false;
233 if( empty( $memlimit ) ) {
234 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
235 } else {
236 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <b>If this is too low, installation may fail!</b> ";
237 $n = IntVal( $memlimit );
238 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
239 $n = IntVal( $m[1] * (1024*1024) );
240 }
241 if( $n < 20*1024*1024 ) {
242 print "Attempting to raise limit to 20M... ";
243 if( false === ini_set( "memory_limit", "20M" ) ) {
244 print "failed.";
245 } else {
246 $conf->raiseMemory = true;
247 print "ok.";
248 }
249 }
250 print "</li>\n";
251 }
252
253 $conf->zlib = function_exists( "gzencode" );
254 if( $conf->zlib ) {
255 print "<li>Have zlib support; enabling output compression.</li>\n";
256 } else {
257 print "<li>No zlib support.</li>\n";
258 }
259
260 $conf->ImageMagick = false;
261
262 $conf->HaveGD = function_exists( "imagejpeg" );
263 if( $conf->HaveGD ) {
264 print "<li>Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads.</li>\n";
265 } else {
266 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin" );
267 foreach( $imcheck as $dir ) {
268 $im = "$dir/convert";
269 if( file_exists( $im ) ) {
270 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
271 $conf->ImageMagick = $im;
272 break;
273 }
274 }
275 if( !$conf->ImageMagick ) {
276 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
277 }
278 }
279
280 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
281
282 # $conf->IP = "/Users/brion/Sites/inplace";
283 chdir( ".." );
284 $conf->IP = getcwd();
285 chdir( "config" );
286 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
287
288 # $conf->ScriptPath = "/~brion/inplace";
289 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
290 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
291
292 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
293
294 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
295 $conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
296 $conf->DBserver = importPost( "DBserver", "localhost" );
297 $conf->DBname = importPost( "DBname", "wikidb" );
298 $conf->DBuser = importPost( "DBuser", "wikiuser" );
299 $conf->DBpassword = importPost( "DBpassword" );
300 $conf->DBpassword2 = importPost( "DBpassword2" );
301 $conf->RootPW = importPost( "RootPW" );
302 $conf->LanguageCode = importPost( "LanguageCode", "en" );
303 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
304 $conf->SysopPass = importPost( "SysopPass" );
305 $conf->SysopPass2 = importPost( "SysopPass2" );
306
307 /* Check for validity */
308 $errs = array();
309
310 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
311 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
312 }
313 if( $conf->DBpassword == "" ) {
314 $errs["DBpassword"] = "Must not be blank";
315 }
316 if( $conf->DBpassword != $conf->DBpassword2 ) {
317 $errs["DBpassword2"] = "Passwords don't match!";
318 }
319
320 if( $conf->SysopPass == "" ) {
321 $errs["SysopPass"] = "Must not be blank";
322 }
323 if( $conf->SysopPass != $conf->SysopPass2 ) {
324 $errs["SysopPass2"] = "Passwords don't match!";
325 }
326
327 $conf->License = importPost( "License", "none" );
328 if( $conf->License == "gfdl" ) {
329 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
330 $conf->RightsText = "GNU Free Documentation License 1.2";
331 $conf->RightsCode = "gfdl";
332 $conf->RightsIcon = '${wgStylePath}/images/gnu-fdl.png';
333 } elseif( $conf->License == "none" ) {
334 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
335 } else {
336 $conf->RightsUrl = importPost( "RightsUrl", "" );
337 $conf->RightsText = importPost( "RightsText", "" );
338 $conf->RightsCode = importPost( "RightsCode", "" );
339 $conf->RightsIcon = importPost( "RightsIcon", "" );
340 }
341
342 if( $conf->posted && ( 0 == count( $errs ) ) ) {
343 do { /* So we can 'continue' to end prematurely */
344 $conf->Root = ($conf->RootPW != "");
345
346 /* Load up the settings and get installin' */
347 $local = writeLocalSettings( $conf );
348 $wgCommandLineMode = false;
349 chdir( ".." );
350 eval($local);
351 $wgDBadminuser = $wgDBuser;
352 $wgDBadminpassword = $wgDBpassword;
353 $wgCommandLineMode = true;
354 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
355 require_once( "includes/Setup.php" );
356 chdir( "config" );
357
358 require_once( "../maintenance/InitialiseMessages.inc" );
359
360 $wgTitle = Title::newFromText( "Installation script" );
361 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
362 $wgDatabase->mIgnoreErrors = true;
363
364 @$myver = mysql_get_server_info( $wgDatabase->mConn );
365 if( $myver ) {
366 $conf->Root = true;
367 print "<li>Connected as root (automatic)</li>\n";
368 } else {
369 print "<li>MySQL error " . ($err = mysql_errno() ) .
370 ": " . htmlspecialchars( mysql_error() );
371 $ok = false;
372 switch( $err ) {
373 case 1045:
374 if( $conf->Root ) {
375 $errs["RootPW"] = "Check password";
376 } else {
377 print "<li>Trying regular user...\n";
378 /* Try the regular user... */
379 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
380 $wgDatabase->isOpen();
381 $wgDatabase->mIgnoreErrors = true;
382 @$myver = mysql_get_server_info( $wgDatabase->mConn );
383 if( !$myver ) {
384 $errs["DBuser"] = "Check name/pass";
385 $errs["DBpassword"] = "or enter root";
386 $errs["DBpassword2"] = "password below";
387 $errs["RootPW"] = "Got root?";
388 print " need password.</li>\n";
389 } else {
390 $conf->Root = false;
391 $conf->RootPW = "";
392 print " ok.</li>\n";
393 # And keep going...
394 $ok = true;
395 }
396 break;
397 }
398 case 2002:
399 case 2003:
400 $errs["DBserver"] = "Connection failed";
401 break;
402 default:
403 $errs["DBserver"] = "Couldn't connect to database";
404 break;
405 }
406 if( !$ok ) continue;
407 }
408
409 if ( !$wgDatabase->isOpen() ) {
410 $errs["DBserver"] = "Couldn't connect to database";
411 continue;
412 }
413
414 print "<li>Connected to database... $myver";
415 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
416 print "; enabling MySQL 4 enhancements";
417 $conf->DBmysql4 = true;
418 $local = writeLocalSettings( $conf );
419 }
420 print "</li>\n";
421
422 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
423 if( $sel ) {
424 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
425 } else {
426 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
427 if( !$res ) {
428 print "<li>Couldn't create database <tt>" .
429 htmlspecialchars( $wgDBname ) .
430 "</tt>; try with root access or check your username/pass.</li>\n";
431 $errs["RootPW"] = "&lt;- Enter";
432 continue;
433 }
434 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
435 }
436
437 $wgDatabase->selectDB( $wgDBname );
438
439 if( $wgDatabase->tableExists( "cur" ) ) {
440 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n<pre>";
441
442 chdir( ".." );
443 flush();
444 do_ipblocks_update(); flush();
445 do_interwiki_update(); flush();
446 do_index_update(); flush();
447 do_linkscc_update(); flush();
448 do_linkscc_1_3_update(); flush();
449 do_hitcounter_update(); flush();
450 do_recentchanges_update(); flush();
451 convertLinks(); flush();
452 do_user_real_name_update(); flush();
453 do_querycache_update(); flush();
454 do_objectcache_update(); flush();
455 do_categorylinks_update(); flush();
456 do_image_name_unique_update(); flush();
457
458 if ( isTemplateInitialised() ) {
459 print "Template namespace already initialised\n";
460 } else {
461 moveCustomMessages( 1 ); flush();
462 moveCustomMessages( 2 ); flush();
463 moveCustomMessages( 3 ); flush();
464 }
465
466 initialiseMessages(); flush();
467 chdir( "config" );
468
469 print "</pre>\n";
470 print "<li>Finished update checks.</li>\n";
471 } else {
472 # FIXME: Check for errors
473 print "<li>Creating tables...";
474 dbsource( "../maintenance/tables.sql", $wgDatabase );
475 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
476 dbsource( "../maintenance/indexes.sql", $wgDatabase );
477 print " done.</li>\n";
478
479 print "<li>Initializing data...";
480 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
481 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
482 # setting up the db user
483 if( $conf->Root ) {
484 print "<li>Granting user permissions...</li>\n";
485 dbsource( "../maintenance/users.sql", $wgDatabase );
486 }
487
488 if( $conf->SysopName ) {
489 $u = User::newFromName( $conf->getSysopName() );
490 if ( 0 == $u->idForName() ) {
491 $u->addToDatabase();
492 $u->setPassword( $conf->getSysopPass() );
493 $u->addRight( "sysop" );
494 $u->addRight( "bureaucrat" );
495 $u->saveSettings();
496 print "<li>Created sysop account <tt>" .
497 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
498 } else {
499 print "<li>Could not create user - already exists!</li>\n";
500 }
501 } else {
502 print "<li>Skipped sysop account creation, no name given.</li>\n";
503 }
504
505 print "<li>Initialising log pages...";
506 $logs = array(
507 "uploadlogpage" => "uploadlogpagetext",
508 "dellogpage" => "dellogpagetext",
509 "protectlogpage" => "protectlogtext",
510 "blocklogpage" => "blocklogtext"
511 );
512 $metaNamespace = Namespace::getWikipedia();
513 $now = wfTimestampNow();
514 $won = wfInvertTimestamp( $now );
515 foreach( $logs as $page => $text ) {
516 $logTitle = $wgDatabase->strencode( $wgLang->ucfirst( str_replace( " ", "_", wfMsgNoDB( $page ) ) ) );
517 $logText = $wgDatabase->strencode( wfMsgNoDB( $text ) );
518 $wgDatabase->query( "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
519 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) " .
520 "VALUES ($metaNamespace,'$logTitle','$logText','sysop','$now','$won','$now')" );
521 }
522 print "</li>\n";
523
524 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
525 $title = $titleobj->getDBkey();
526 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
527 "VALUES (0,'$title','" .
528 wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) . "','$now','$won','$now')";
529 $wgDatabase->query( $sql, $fname );
530
531 print "<li><pre>";
532 initialiseMessages();
533 print "</pre></li>\n";
534 }
535
536 /* Write out the config file now that all is well */
537 print "<p>Creating LocalSettings.php...</p>\n\n";
538 $localSettings = "<" . "?php$endl$local$endl?" . ">";
539
540 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
541 $xt = "xt"; # Refuse to overwrite an existing file
542 } else {
543 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
544 }
545 $f = fopen( "LocalSettings.php", $xt );
546
547 if( $f == false ) {
548 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" .
549 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
550 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
551 }
552 fwrite( $f, $localSettings );
553 fclose( $f );
554
555 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
556 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
557
558 } while( false );
559 }
560 ?>
561 </ul>
562
563
564 <?php
565
566 if( count( $errs ) ) {
567 /* Display options form */
568
569 if( $conf->posted ) {
570 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
571 }
572 ?>
573
574 <form name="config" method="post">
575
576
577 <h2>Site config</h2>
578
579 <dl class="setup">
580 <dd>
581 <?php
582 aField( $conf, "Sitename", "Site name:" );
583 ?>
584 </dd>
585 <dt>
586 Your site name should be a relatively short word. It'll appear as the namespace
587 name for 'meta' pages as well as throughout the user interface. Good site names
588 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
589 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
590 which may cause problems.
591 </dt>
592
593 <dd>
594 <?php
595 aField( $conf, "EmergencyContact", "Contact e-mail" );
596 ?>
597 </dd>
598 <dt>
599 This will be used as the return address for password reminders and
600 may be displayed in some error conditions so visitors can get in
601 touch with you.
602 </dt>
603
604 <dd>
605 <label class='column' for="LanguageCode">Language</label>
606 <select id="LanguageCode" name="LanguageCode">
607 <?php
608 $list = getLanguageList();
609 foreach( $list as $code => $name ) {
610 $sel = ($code == $conf->LanguageCode) ? "selected" : "";
611 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
612 }
613 ?>
614 </select>
615 </dd>
616 <dt>
617 You may select the language for the user interface of the wiki...
618 Some localizations are less complete than others. This also controls
619 the character encoding; Unicode is more flexible, but Latin-1 may be
620 more compatible with older browsers for some languages. Unicode will
621 be used where not specified otherwise.
622 </dt>
623
624 <dd>
625 <label class='column'>Copyright/license metadata</label>
626 <div>Select one:</div>
627
628 <ul class="plain">
629 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
630 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
631 <li><?php
632 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
633 $partner = "MediaWiki";
634 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
635 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
636 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
637 print "<a href=\"$ccApp\">choose</a>";
638 ?></li>
639 <li><?php aField( $conf, "RightsUrl", $conf->RightsUrl, "hidden" ); ?></li>
640 <li><?php aField( $conf, "RightsText", $conf->RightsText, "hidden" ); ?></li>
641 <li><?php aField( $conf, "RightsCode", $conf->RightsCode, "hidden" ); ?></li>
642 <li><?php aField( $conf, "RightsIcon", $conf->RightsIcon, "hidden" ); ?></li>
643 </ul>
644 </dd>
645 <dt>
646 MediaWiki can include a basic license notice, icon, and machine-reable
647 copyright metadata if your wiki's content is to be licensed under
648 the GNU FDL or a Creative Commons license. If you're not sure, leave
649 it at "none".
650 </dt>
651
652
653 <dd>
654 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
655 </dd>
656 <dd>
657 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
658 </dd>
659 <dd>
660 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
661 </dd>
662 <dt>
663 A sysop user account can lock or delete pages, block problematic IP
664 addresses from editing, and other maintenance tasks. If creating a new
665 wiki database, a sysop account will be created with the given name
666 and password.
667 </dt>
668 </dl>
669
670 <h2>Database config</h2>
671
672 <dl class="setup">
673 <dd><?php
674 aField( $conf, "DBserver", "MySQL server" );
675 ?></dd>
676 <dt>
677 If your database server isn't on your web server, enter the name
678 or IP address here.
679 </dt>
680
681 <dd><?php
682 aField( $conf, "DBname", "Database name" );
683 ?></dd>
684 <dd><?php
685 aField( $conf, "DBuser", "DB username" );
686 ?></dd>
687 <dd><?php
688 aField( $conf, "DBpassword", "DB password", "password" );
689 ?></dd>
690 <dd><?php
691 aField( $conf, "DBpassword2", "again", "password" );
692 ?></dd>
693 <dt>
694 If you only have a single user account and database available,
695 enter those here. If you have database root access (see below)
696 you can specify new accounts/databases to be created.
697 </dt>
698
699
700 <dd>
701 <?php
702 aField( $conf, "RootPW", "DB root password", "password" );
703 ?>
704 </dd>
705 <dt>
706 You will only need this if the database and/or user account
707 above don't already exist.
708 Do <em>not</em> type in your machine's root password! MySQL
709 has its own "root" user with a separate password. (It might
710 even be blank, depending on your configuration.)
711 </dt>
712
713 <dd>
714 <label class='column'>&nbsp;</label>
715 <input type="submit" value="Install!" />
716 </dd>
717 </dl>
718
719
720 </form>
721
722 <?php
723 }
724
725 /* -------------------------------------------------------------------------------------- */
726
727 function writeAdminSettings( $conf ) {
728 return "
729 \$wgDBadminuser = \"{$conf->DBadminuser}\";
730 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
731 ";
732 }
733
734 function writeLocalSettings( $conf ) {
735 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
736 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
737 $conf->PasswordSender = $conf->EmergencyContact;
738 if( preg_match( '/^([a-z]+)-latin1$/', $conf->LanguageCode, $m ) ) {
739 $conf->LanguageCode = $m[1];
740 $conf->Latin1 = true;
741 } else {
742 $conf->Latin1 = false;
743 }
744 $zlib = ($conf->zlib ? "" : "# ");
745 $magic = ($conf->ImageMagick ? "" : "# ");
746 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
747 $pretty = ($conf->prettyURLs ? "" : "# ");
748 $ugly = ($conf->prettyURLs ? "# " : "");
749 $rights = ($conf->RightsUrl) ? "" : "# ";
750
751 $file = @fopen( "/dev/random", "r" );
752 if ( $file ) {
753 $proxyKey = bin2hex( fread( $file, 32 ) );
754 fclose( $file );
755 } else {
756 $proxyKey = "";
757 for ( $i=0; $i<8; $i++ ) {
758 $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
759 }
760 print "<li>Warning: \$wgProxyKey is insecure</li>\n";
761 }
762
763 # Add slashes to strings for double quoting
764 $slconf = array_map( "addslashes", get_object_vars( $conf ) );
765
766
767 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
768 return "
769 # This file was automatically generated by the MediaWiki installer.
770 # If you make manual changes, please keep track in case you need to
771 # recreate them later.
772
773 \$IP = \"{$slconf['IP']}\";
774 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
775 include_once( \"DefaultSettings.php\" );
776
777 # If PHP's memory limit is very low, some operations may fail.
778 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
779
780 if ( \$wgCommandLineMode ) {
781 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
782 die( \"This script must be run from the command line\\n\" );
783 }
784 } elseif ( empty( \$wgConfiguring ) ) {
785 ## Compress output if the browser supports it
786 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) ob_start( 'ob_gzhandler' );
787 }
788
789 \$wgSitename = \"{$slconf['Sitename']}\";
790
791 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
792 \$wgScript = \"\$wgScriptPath/index.php\";
793 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
794
795 ## If using PHP as a CGI module, use the ugly URLs
796 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
797 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
798
799 \$wgStylePath = \"\$wgScriptPath/stylesheets\";
800 \$wgStyleDirectory = \"\$IP/stylesheets\";
801 \$wgLogo = \"\$wgStylePath/images/wiki.png\";
802
803 \$wgUploadPath = \"\$wgScriptPath/images\";
804 \$wgUploadDirectory = \"\$IP/images\";
805
806 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
807 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
808
809 \$wgDBserver = \"{$slconf['DBserver']}\";
810 \$wgDBname = \"{$slconf['DBname']}\";
811 \$wgDBuser = \"{$slconf['DBuser']}\";
812 \$wgDBpassword = \"{$slconf['DBpassword']}\";
813
814 ## To allow SQL queries through the wiki's Special:Askaql page,
815 ## uncomment the next lines. THIS IS VERY INSECURE. If you want
816 ## to allow semipublic read-only SQL access for your sysops,
817 ## you should define a MySQL user with limited privileges.
818 ## See MySQL docs: http://www.mysql.com/doc/en/GRANT.html
819 #
820 # \$wgAllowSysopQueries = true;
821 # \$wgDBsqluser = \"sqluser\";
822 # \$wgDBsqlpassword = \"sqlpass\";
823
824 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
825
826 ## To enable image uploads, make sure the 'images' directory
827 ## is writable, then uncomment this:
828 # \$wgDisableUploads = false;
829 \$wgUseImageResize = {$conf->UseImageResize};
830 {$magic}\$wgUseImageMagick = true;
831 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
832
833 ## If you have the appropriate support software installed
834 ## you can enable inline LaTeX equations:
835 # \$wgUseTeX = true;
836 \$wgMathPath = \"{\$wgUploadPath}/math\";
837 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
838 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
839
840 \$wgLocalInterwiki = \$wgSitename;
841
842 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
843 \$wgUseLatin1 = " . ($conf->Latin1 ? 'true' : 'false') . ";\n
844
845 \$wgProxyKey = \"$proxyKey\";
846
847 ## Default skin: you can change the default skin. Use the internal symbolic
848 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
849 # \$wgDefaultSkin = 'monobook';
850
851 ## For attaching licensing metadata to pages, and displaying an
852 ## appropriate copyright notice / icon. GNU Free Documentation
853 ## License and Creative Commons licenses are supported so far.
854 {$rights}\$wgEnableCreativeCommonsRdf = true;
855 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
856 \$wgRightsUrl = \"{$conf->RightsUrl}\";
857 \$wgRightsText = \"{$conf->RightsText}\";
858 \$wgRightsIcon = \"{$conf->RightsIcon}\";
859 # \$wgRightsCode = \"{$conf->RightsCode}\"; # Not yet used
860 ";
861 }
862
863 function dieout( $text ) {
864 die( $text . "\n\n</body>\n</html>" );
865 }
866
867 function importPost( $name, $default = "" ) {
868 if( isset( $_POST[$name] ) ) {
869 $retval = $_POST[$name];
870 if ( get_magic_quotes_gpc() ) {
871 $retval = stripslashes( $retval );
872 }
873 } else {
874 $retval = $default;
875 }
876 return $retval;
877 }
878
879 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
880 if( $type != "" ) {
881 $xtype = "type=\"$type\"";
882 } else {
883 $xtype = "";
884 }
885
886 if(!(isset($id)) or ($id == "") ) $id = $field;
887 $nolabel = ($type == "radio") || ($type == "hidden");
888 if( $nolabel ) {
889 echo "\t\t<label>";
890 } else {
891 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
892 }
893
894 if( $type == "radio" && $value == $conf->$field ) {
895 $checked = "checked='checked'";
896 } else {
897 $checked = "";
898 }
899 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
900 if( $type == "radio" ) {
901 echo htmlspecialchars( $value );
902 } else {
903 echo htmlspecialchars( $conf->$field );
904 }
905 echo "\" />\n";
906 if( $nolabel ) {
907 echo " $text</label>\n";
908 }
909
910 global $errs;
911 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
912 }
913
914 function getLanguageList() {
915 global $wgLanguageNames;
916 if( !isset( $wgLanguageNames ) ) {
917 $wgLanguageCode = "xxx";
918 function wfLocalUrl( $x ) { return $x; }
919 function wfLocalUrlE( $x ) { return $x; }
920 require_once( "../languages/Names.php" );
921 }
922
923 $codes = array();
924 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
925
926 $d = opendir( "../languages" );
927 while( false !== ($f = readdir( $d ) ) ) {
928 if( preg_match( '/Language([A-Z][a-z]+)\.php$/', $f, $m ) ) {
929 $code = strtolower( $m[1] );
930 if( in_array( $code, $latin1 ) ) {
931 $codes[$code] = "$code - " . $wgLanguageNames[$code] . " - Unicode";
932 $codes[$code.'-latin1'] = "$code - " . $wgLanguageNames[$code] . " - Latin-1";
933 } else {
934 $codes[$code] = "$code - " . $wgLanguageNames[$code];
935 }
936 }
937 }
938 closedir( $d );
939 ksort( $codes );
940 return $codes;
941 }
942
943 ?>
944
945 </body>
946 </html>