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