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