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