Don't need existence check for the article, it's implied
[mediawiki.git] / config / index.php
blobbb59029b8c38d7c3400cfb99e910bb3df880bc4f
1 <?php
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
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.
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.
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
21 error_reporting( E_ALL );
22 header( "Content-type: text/html; charset=utf-8" );
23 @ini_set( "display_errors", true );
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;
44 dl.setup dd {
45 margin-left: 0;
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;
55 dl.setup dt {
56 clear: left;
57 font-size: 0.8em;
58 margin-left: 10em;
59 /* margin-right: 200px; */
60 margin-bottom: 2em;
62 .error {
63 color: red;
65 ul.plain {
66 list-style: none;
67 clear: both;
68 margin-left: 12em;
70 </style>
71 </head>
73 <body>
75 <div id="credit">
76 <center>
77 <a href="http://www.mediawiki.org/">
78 <img src="../skins/common/images/wiki.png" width="135" height="135" alt="" border="0" />
79 </a>
80 </center>
82 <strong><a href="http://www.mediawiki.org/">MediaWiki</a></strong> is
83 Copyright (C) 2001-<?=date('Y')?> by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
84 Tim Starling, Erik M&ouml;ller, Gabriel Wicke, Thomas Gries and others.</p>
86 <ul>
87 <li><a href="../README">Readme</a></li>
88 <li><a href="../RELEASE-NOTES">Release notes</a></li>
89 <li><a href="../docs/">doc/</a></li>
90 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
91 </ul>
93 <p>This program is free software; you can redistribute it and/or modify
94 it under the terms of the GNU General Public License as published by
95 the Free Software Foundation; either version 2 of the License, or
96 (at your option) any later version.</p>
98 <p>This program is distributed in the hope that it will be useful,
99 but WITHOUT ANY WARRANTY; without even the implied warranty of
100 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 GNU General Public License for more details.</p>
103 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
104 along with this program; if not, write to the Free Software
105 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
106 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
107 </div>
109 <?php
111 $IP = ".."; # Just to suppress notices, not for anything useful
112 define( "MEDIAWIKI", true );
113 define( "MEDIAWIKI_INSTALL", true );
114 require_once( "../includes/Defines.php" );
115 require_once( "../includes/DefaultSettings.php" );
116 require_once( "../includes/MagicWord.php" );
117 require_once( "../includes/Namespace.php" );
120 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
123 <?php
125 /* Check for existing configurations and bug out! */
127 if( file_exists( "../LocalSettings.php" ) ) {
128 dieout( "<h2>Wiki is configured.</h2>
130 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
132 <p>(You should probably remove this directory for added security.)</p>" );
135 if( file_exists( "./LocalSettings.php" ) ) {
136 dieout( "<h2>You're configured!</h2>
138 <p>Please move <tt>LocalSettings.php</tt> to the parent directory, then
139 <a href='../index.php'>try out your wiki</a>.
140 (You should remove this config directory for added security once you're done.)</p>" );
143 if( !is_writable( "." ) ) {
144 dieout( "<h2>Can't write config file, aborting</h2>
146 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
147 writable by the web server. Once configuration is done you'll move the created
148 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
149 then remove the <tt>config</tt> subdirectory entirely.</p>
151 <p>To make the directory writable on a Unix/Linux system:</p>
153 <blockquote>
154 <tt>cd /path/to/wiki</tt><br>
155 <tt>chmod a+w config</tt>
156 </blockquote>" );
160 require_once( "../install-utils.inc" );
161 require_once( "../maintenance/updaters.inc" );
162 require_once( "../maintenance/convertLinks.inc" );
163 require_once( "../maintenance/archives/moveCustomMessages.inc" );
165 class ConfigData {
166 function getEncoded( $data ) {
167 # removing latin1 support, no need...
168 return $data;
170 function getSitename() { return $this->getEncoded( $this->Sitename ); }
171 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
172 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
177 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
179 <h2>Checking environment...</h2>
180 <ul>
181 <?php
182 $endl = "
184 $wgConfiguring = true;
185 $conf = new ConfigData;
187 install_version_checks();
189 print "<li>PHP " . phpversion() . ": ok</li>\n";
191 if( ini_get( "register_globals" ) ) {
193 <li><b class='error'>Warning:</strong> <strong>PHP's
194 <tt><a href="http://php.net/register_globals">register_globals</a></tt>
195 option is enabled.</strong> MediaWiki will work correctly, but this setting
196 increases your exposure to potential security vulnerabilities in PHP-based
197 software running on your server. <strong>You should disable it if you are able.</strong></li>
198 <?php
201 if( ini_get( "safe_mode" ) ) {
203 <li class='error'><strong>Warning: PHP's
204 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</strong>
205 You may have problems caused by this, particularly if using image uploads.
206 </li>
207 <?php
210 $fatal = false;
212 if( ini_get( "magic_quotes_runtime" ) ) {
213 $fatal = true;
214 ?><li class='error'><strong>Fatal: <a href='http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-runtime'>magic_quotes_runtime</a> is active!</strong>
215 This option corrupts data input unpredictably; you cannot install or use
216 MediaWiki unless this option is disabled.
217 <?php
220 if( ini_get( "magic_quotes_sybase" ) ) {
221 $fatal = true;
222 ?><li class='error'><strong>Fatal: <a href='http://www.php.net/manual/en/ref.sybase.php#ini.magic-quotes-sybase'>magic_quotes_sybase</a> is active!</strong>
223 This option corrupts data input unpredictably; you cannot install or use
224 MediaWiki unless this option is disabled.
225 <?php
228 if( $fatal ) {
229 dieout( "</ul><p>Cannot install wiki.</p>" );
232 $sapi = php_sapi_name();
233 $conf->prettyURLs = true;
234 print "<li>PHP server API is $sapi; ";
235 switch( $sapi ) {
236 case "apache":
237 case "apache2handler":
238 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
239 break;
240 case "cgi":
241 case "cgi-fcgi":
242 case "apache2filter":
243 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
244 $conf->prettyURLs = false;
245 break;
246 default:
247 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
249 print "</li>\n";
251 $conf->xml = function_exists( "utf8_encode" );
252 if( $conf->xml ) {
253 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
254 } else {
255 dieout( "PHP's XML module is missing; the wiki requires functions in
256 this module and won't work in this configuration.
257 If you're running Mandrake, install the php-xml package." );
260 $memlimit = ini_get( "memory_limit" );
261 $conf->raiseMemory = false;
262 if( empty( $memlimit ) ) {
263 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
264 } else {
265 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <strong>If this is too low, installation may fail!</strong> ";
266 $n = IntVal( $memlimit );
267 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
268 $n = IntVal( $m[1] * (1024*1024) );
270 if( $n < 20*1024*1024 ) {
271 print "Attempting to raise limit to 20M... ";
272 if( false === ini_set( "memory_limit", "20M" ) ) {
273 print "failed.";
274 } else {
275 $conf->raiseMemory = true;
276 print "ok.";
279 print "</li>\n";
282 $conf->zlib = function_exists( "gzencode" );
283 if( $conf->zlib ) {
284 print "<li>Have zlib support; enabling output compression.</li>\n";
285 } else {
286 print "<li>No zlib support.</li>\n";
289 $conf->turck = function_exists( 'mmcache_get' );
290 if ( $conf->turck ) {
291 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
293 $conf->eaccel = function_exists( 'eaccelerator_get' );
294 if ( $conf->eaccel ) {
295 $conf->turck = 'eaccelerator';
296 print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
298 if (!$conf->turck && !$conf->eaccel) {
299 print "<li>Neither <a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> nor <a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> are installed, " .
300 "can't use object caching functions</li>\n";
303 $conf->ImageMagick = false;
304 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
305 foreach( $imcheck as $dir ) {
306 $im = "$dir/convert";
307 if( file_exists( $im ) ) {
308 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
309 $conf->ImageMagick = $im;
310 break;
314 $conf->HaveGD = function_exists( "imagejpeg" );
315 if( $conf->HaveGD ) {
316 print "<li>Found GD graphics library built-in";
317 if( !$conf->ImageMagick ) {
318 print ", image thumbnailing will be enabled if you enable uploads";
320 print ".</li>\n";
321 } else {
322 if( !$conf->ImageMagick ) {
323 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
327 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
329 # $conf->IP = "/Users/brion/Sites/inplace";
330 $conf->IP = dirname( dirname( __FILE__ ) );
331 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
333 # $conf->ScriptPath = "/~brion/inplace";
334 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAME
335 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
337 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
339 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
340 $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
341 ? 'root@localhost'
342 : $_SERVER["SERVER_ADMIN"];
343 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
344 $conf->DBserver = importPost( "DBserver", "localhost" );
345 $conf->DBname = importPost( "DBname", "wikidb" );
346 $conf->DBuser = importPost( "DBuser", "wikiuser" );
347 $conf->DBpassword = importPost( "DBpassword" );
348 $conf->DBpassword2 = importPost( "DBpassword2" );
349 $conf->DBprefix = importPost( "DBprefix" );
350 $conf->RootPW = importPost( "RootPW" );
351 $conf->LanguageCode = importPost( "LanguageCode", "en" );
352 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
353 $conf->SysopPass = importPost( "SysopPass" );
354 $conf->SysopPass2 = importPost( "SysopPass2" );
356 /* Check for validity */
357 $errs = array();
359 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
360 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
362 if( $conf->DBuser == "" ) {
363 $errs["DBuser"] = "Must not be blank";
365 if( $conf->DBpassword == "" ) {
366 $errs["DBpassword"] = "Must not be blank";
368 if( $conf->DBpassword != $conf->DBpassword2 ) {
369 $errs["DBpassword2"] = "Passwords don't match!";
371 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
372 $errs["DBprefix"] = "Invalid table prefix";
375 if( $conf->SysopPass == "" ) {
376 $errs["SysopPass"] = "Must not be blank";
378 if( $conf->SysopPass != $conf->SysopPass2 ) {
379 $errs["SysopPass2"] = "Passwords don't match!";
382 $conf->License = importRequest( "License", "none" );
383 if( $conf->License == "gfdl" ) {
384 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
385 $conf->RightsText = "GNU Free Documentation License 1.2";
386 $conf->RightsCode = "gfdl";
387 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
388 } elseif( $conf->License == "none" ) {
389 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
390 } else {
391 $conf->RightsUrl = importRequest( "RightsUrl", "" );
392 $conf->RightsText = importRequest( "RightsText", "" );
393 $conf->RightsCode = importRequest( "RightsCode", "" );
394 $conf->RightsIcon = importRequest( "RightsIcon", "" );
397 $conf->Shm = importRequest( "Shm", "none" );
398 $conf->MCServers = importRequest( "MCServers" );
400 /* Test memcached servers */
402 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
403 $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
404 foreach ( $conf->MCServerArray as $server ) {
405 $error = testMemcachedServer( $server );
406 if ( $error ) {
407 $errs["MCServers"] = $error;
408 break;
411 } else if ( $conf->Shm == 'memcached' ) {
412 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
415 /* default values for installation */
416 $conf->Email =importRequest("Email", "email_enabled");
417 $conf->Emailuser=importRequest("Emailuser", "emailuser_enabled");
418 $conf->Enotif =importRequest("Enotif", "enotif_allpages");
419 $conf->Eauthent =importRequest("Eauthent", "eauthent_enabled");
421 if( $conf->posted && ( 0 == count( $errs ) ) ) {
422 do { /* So we can 'continue' to end prematurely */
423 $conf->Root = ($conf->RootPW != "");
425 /* Load up the settings and get installin' */
426 $local = writeLocalSettings( $conf );
427 $wgCommandLineMode = false;
428 chdir( ".." );
429 eval($local);
430 $wgDBadminuser = "root";
431 $wgDBadminpassword = $conf->RootPW;
432 $wgDBprefix = $conf->DBprefix;
433 $wgCommandLineMode = true;
434 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
435 require_once( "includes/Setup.php" );
436 chdir( "config" );
438 require_once( "../maintenance/InitialiseMessages.inc" );
440 $wgTitle = Title::newFromText( "Installation script" );
441 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
442 $wgDatabase->ignoreErrors(true);
444 @$myver = mysql_get_server_info( $wgDatabase->mConn );
445 if( $myver ) {
446 $conf->Root = true;
447 print "<li>Connected as root (automatic)</li>\n";
448 } else {
449 print "<li>MySQL error " . ($err = mysql_errno() ) .
450 ": " . htmlspecialchars( mysql_error() );
451 $ok = false;
452 switch( $err ) {
453 case 1045:
454 case 2000:
455 if( $conf->Root ) {
456 $errs["RootPW"] = "Check password";
457 } else {
458 print "<li>Trying regular user...\n";
459 /* Try the regular user... */
460 $wgDBadminuser = $wgDBuser;
461 $wgDBadminpassword = $wgDBpassword;
462 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
463 $wgDatabase->isOpen();
464 $wgDatabase->ignoreErrors(true);
465 @$myver = mysql_get_server_info( $wgDatabase->mConn );
466 if( !$myver ) {
467 $errs["DBuser"] = "Check name/pass";
468 $errs["DBpassword"] = "or enter root";
469 $errs["DBpassword2"] = "password below";
470 $errs["RootPW"] = "Got root?";
471 print " need password.</li>\n";
472 } else {
473 $conf->Root = false;
474 $conf->RootPW = "";
475 print " ok.</li>\n";
476 # And keep going...
477 $ok = true;
479 break;
481 case 2002:
482 case 2003:
483 $errs["DBserver"] = "Connection failed";
484 break;
485 default:
486 $errs["DBserver"] = "Couldn't connect to database";
487 break;
489 if( !$ok ) continue;
492 if ( !$wgDatabase->isOpen() ) {
493 $errs["DBserver"] = "Couldn't connect to database";
494 continue;
497 print "<li>Connected to database... $myver";
498 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
499 print "; enabling MySQL 4 enhancements";
500 $conf->DBmysql4 = true;
501 $local = writeLocalSettings( $conf );
503 print "</li>\n";
505 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
506 if( $sel ) {
507 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
508 } else {
509 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
510 if( !$res ) {
511 print "<li>Couldn't create database <tt>" .
512 htmlspecialchars( $wgDBname ) .
513 "</tt>; try with root access or check your username/pass.</li>\n";
514 $errs["RootPW"] = "&lt;- Enter";
515 continue;
517 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
520 $wgDatabase->selectDB( $wgDBname );
522 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
523 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
525 # Create user if required
526 if ( $conf->Root ) {
527 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
528 if ( $conn->isOpen() ) {
529 print "<li>DB user account ok</li>\n";
530 $conn->close();
531 } else {
532 print "<li>Granting user permissions...</li>\n";
533 dbsource( "../maintenance/users.sql", $wgDatabase );
536 print "<pre>\n";
537 chdir( ".." );
538 flush();
539 do_all_updates();
540 chdir( "config" );
542 print "</pre>\n";
543 print "<li>Finished update checks.</li>\n";
544 } else {
545 # FIXME: Check for errors
546 print "<li>Creating tables...";
547 dbsource( "../maintenance/tables.sql", $wgDatabase );
548 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
549 dbsource( "../maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase );
550 print " done.</li>\n";
552 print "<li>Initializing data...";
553 $wgDatabase->insert( 'site_stats',
554 array( 'ss_row_id' => 1,
555 'ss_total_views' => 0,
556 'ss_total_edits' => 0,
557 'ss_good_articles' => 0 ) );
558 # setting up the db user
559 if( $conf->Root ) {
560 print "<li>Granting user permissions...</li>\n";
561 dbsource( "../maintenance/users.sql", $wgDatabase );
564 if( $conf->SysopName ) {
565 $u = User::newFromName( $conf->getSysopName() );
566 if ( 0 == $u->idForName() ) {
567 $u->addToDatabase();
568 $u->setPassword( $conf->getSysopPass() );
569 $u->addRight( "sysop" );
570 $u->addRight( "bureaucrat" );
571 $u->saveSettings();
573 # Set up the new user in the sysop group
574 # This is a bit of an ugly hack
575 global $wgSysopGroupId, $wgBureaucratGroupId;
576 $groups = $u->getGroups();
577 $groups[] = $wgSysopGroupId;
578 $groups[] = $wgBureaucratGroupId;
579 $u->setGroups( $groups );
580 $u->saveSettings();
582 print "<li>Created sysop account <tt>" .
583 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
584 } else {
585 print "<li>Could not create user - already exists!</li>\n";
587 } else {
588 print "<li>Skipped sysop account creation, no name given.</li>\n";
591 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
592 $article = new Article( $titleobj );
593 $newid = $article->insertOn( $wgDatabase );
594 $revision = new Revision( array(
595 'page' => $newid,
596 'text' => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsg( 'mainpagedocfooter' ),
597 'comment' => '',
598 'user' => 0,
599 'user_text' => 'MediaWiki default',
600 ) );
601 $revid = $revision->insertOn( $wgDatabase );
602 $article->updateRevisionOn( $wgDatabase, $revision );
604 print "<li><pre>";
605 initialiseMessages();
606 print "</pre></li>\n";
609 /* Write out the config file now that all is well */
610 print "<p>Creating LocalSettings.php...</p>\n\n";
611 $localSettings = "<" . "?php$endl$local$endl?" . ">";
613 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
614 $xt = "xt"; # Refuse to overwrite an existing file
615 } else {
616 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
618 $f = fopen( "LocalSettings.php", $xt );
620 if( $f == false ) {
621 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" .
622 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
623 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
625 if(fwrite( $f, $localSettings ) ) {
626 fclose( $f );
628 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
629 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
630 } else {
631 fclose( $f );
632 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");
636 } while( false );
639 </ul>
642 <?php
644 if( count( $errs ) ) {
645 /* Display options form */
647 if( $conf->posted ) {
648 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
652 <form name="config" method="post">
655 <h2>Site config</h2>
657 <dl class="setup">
658 <dd>
659 <?php
660 aField( $conf, "Sitename", "Site name:" );
662 </dd>
663 <dt>
664 Your site name should be a relatively short word. It'll appear as the namespace
665 name for 'meta' pages as well as throughout the user interface. Good site names
666 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
667 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
668 which may cause problems.
669 </dt>
671 <dd>
672 <?php
673 aField( $conf, "EmergencyContact", "Contact e-mail" );
675 </dd>
676 <dt>
677 This will be used as the return address for password reminders and
678 may be displayed in some error conditions so visitors can get in
679 touch with you. It is also be used as the default sender address of e-mail
680 notifications (enotifs).
681 </dt>
683 <dd>
684 <label class='column' for="LanguageCode">Language</label>
685 <select id="LanguageCode" name="LanguageCode">
687 <?php
688 $list = getLanguageList();
689 foreach( $list as $code => $name ) {
690 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
691 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
694 </select>
695 </dd>
696 <dt>
697 You may select the language for the user interface of the wiki...
698 Some localizations are less complete than others. Unicode (UTF-8 encoding)
699 is used for all localizations.
700 </dt>
702 <dd>
703 <label class='column'>Copyright/license metadata</label>
704 <div>Select one:</div>
706 <ul class="plain">
707 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
708 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
709 <li><?php
710 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
711 $partner = "MediaWiki";
712 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
713 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
714 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
715 print "<a href=\"$ccApp\">choose</a>";
716 ?> (link will wipe out any other data in this form!)
717 <?php if( $conf->License == "cc" ) { ?>
718 <ul>
719 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
720 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
721 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
722 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
723 </ul>
724 <?php } ?>
725 </li>
726 </ul>
727 </dd>
728 <dt>
729 MediaWiki can include a basic license notice, icon, and machine-readable
730 copyright metadata if your wiki's content is to be licensed under
731 the GNU FDL or a Creative Commons license. If you're not sure, leave
732 it at "none".
733 </dt>
736 <dd>
737 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
738 </dd>
739 <dd>
740 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
741 </dd>
742 <dd>
743 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
744 </dd>
745 <dt>
746 A sysop user account can lock or delete pages, block problematic IP
747 addresses from editing, and other maintenance tasks. If creating a new
748 wiki database, a sysop account will be created with the given name
749 and password.
750 </dt>
752 <dd>
753 <label class='column'>Shared memory caching</label>
754 <div>Select one:</div>
756 <ul class="plain">
757 <li><?php aField( $conf, "Shm", "no caching", "radio", "none" ); ?></li>
758 <?php
759 if ( $conf->turck ) {
760 echo "<li>";
761 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
762 echo "</li>";
765 <?php
766 if ( $conf->eaccel ) {
767 echo "<li>";
768 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
769 echo "</li>";
772 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
773 <li><?php aField( $conf, "MCServers", "Memcached servers", "" ) ?></li>
774 </ul>
775 </dd>
776 <dt>
777 Using a shared memory system such as Turck MMCache, eAccelerator, or Memcached will speed
778 up MediaWiki significantly. Memcached is the best solution but needs to be
779 installed. Specify the server addresses and ports in a comma-separted list. Only
780 use Turck shared memory if the wiki will be running on a single Apache server.
781 </dl>
783 <h2>E-mail, e-mail notification and authentification setup</h2>
785 <dl class="setup">
786 <dd>
787 <label class='column'>E-mail (general)</label>
788 <div>Select one:</div>
790 <ul class="plain">
791 <li><?php aField( $conf, "Email", "enabled", "radio", "email_enabled" ); ?></li>
792 <li><?php aField( $conf, "Email", "disabled", "radio", "email_disabled" ); ?></li>
793 </ul>
794 </dd>
795 <dt>
796 Use this to disable all e-mail functions (send a password reminder, user-to-user e-mail and e-mail notification),
797 if sending e-mails on your server doesn't work.
798 </dt>
799 <dd>
800 <label class='column'>User-to-user e-mail</label>
801 <div>Select one:</div>
803 <ul class="plain">
804 <li><?php aField( $conf, "Emailuser", "enabled", "radio", "emailuser_enabled" ); ?></li>
805 <li><?php aField( $conf, "Emailuser", "disabled", "radio", "emailuser_disabled" ); ?></li>
806 </ul>
807 </dd>
808 <dt>
809 Use this to disable only the user-to-user e-mail function (EmailUser).
810 </dt>
811 <dd>
812 <label class='column'>E-mail notification</label>
813 <div>Select one:</div>
815 <ul class="plain">
816 <li><?php aField( $conf, "Enotif", "disabled", "radio", "enotif_disabled" ); ?></li>
817 <li><?php aField( $conf, "Enotif", "enabled for changes of watch-listed and user_talk pages (recommended for small wikis; perhaps not suited for large wikis)", "radio", "enotif_allpages" ); ?></li>
818 <li><?php aField( $conf, "Enotif", "enabled for changes of user_talk pages only (suited for small and large wikis)", "radio", "enotif_usertalk" ); ?></li>
819 </ul>
820 </dd>
821 <dt>
822 <p><?php
823 $ccEnotif = htmlspecialchars( 'http://meta.wikipedia.org/Enotif' );
824 print "<a href=\"$ccEnotif\">E-mail notification</a>";
826 sends a notification e-mail to a user, when the user_talk page is changed
827 and/or when watch-listed pages are changed, depending on the above settings.
828 When testing this feature, be reminded, that obviously an e-mail address must be present in your preferences
829 and that your own changes never trigger notifications to be sent to yourself.</p>
831 <p>Users get corresponding options to select or deselect in their users' preferences.
832 The user options are not shown on the preference page, if e-mail notification is disabled.</p>
834 <p>There are additional options for fine tuning in /includes/DefaultSettings.php .</p>
835 </dt>
837 <dd>
838 <label class='column'>E-mail address authentication</label>
839 <div>Select one:</div>
841 <ul class="plain">
842 <li><?php aField( $conf, "Eauthent", "disabled", "radio", "eauthent_disabled" ); ?></li>
843 <li><?php aField( $conf, "Eauthent", "enabled", "radio", "eauthent_enabled" ); ?></li>
844 </ul>
845 </dd>
846 <dt>
847 <p><?php
848 $ccEauthent = htmlspecialchars( 'http://meta.wikipedia.org/Eauthent' );
849 print "<a href=\"$ccEnotif\">E-mail address authentication</a>";
851 uses a scheme to authenticate e-mail addresses of the users. The user who initially enters or who changes his/her stored e-mail address
852 gets a one-time temporary password mailed to that address. The user can use the original password as long as wanted, however, the stored e-mail address
853 is only authenticated at the moment when the user logs in with the one-time temporary password.<p>
855 <p>The e-mail address stays authenticated as long as the user does not change it; the time of authentication is indicated
856 on the user preference page.</p>
858 <p>If the option is enabled, only authenticated e-mail addresses can receive EmailUser mails and/or
859 e-mail notification mails.</p>
860 </dt>
862 </dl>
864 <h2>Database config</h2>
866 <dl class="setup">
867 <dd><?php
868 aField( $conf, "DBserver", "MySQL server" );
869 ?></dd>
870 <dt>
871 If your database server isn't on your web server, enter the name
872 or IP address here.
873 </dt>
875 <dd><?php
876 aField( $conf, "DBname", "Database name" );
877 ?></dd>
878 <dd><?php
879 aField( $conf, "DBuser", "DB username" );
880 ?></dd>
881 <dd><?php
882 aField( $conf, "DBpassword", "DB password", "password" );
883 ?></dd>
884 <dd><?php
885 aField( $conf, "DBpassword2", "again", "password" );
886 ?></dd>
887 <dt>
888 If you only have a single user account and database available,
889 enter those here. If you have database root access (see below)
890 you can specify new accounts/databases to be created.
891 </dt>
893 <dd><?php
894 aField( $conf, "DBprefix", "Database table prefix" );
895 ?></dd>
896 <dt>
897 <p>If you need to share one database between multiple wikis, or
898 MediaWiki and another web application, you may choose to
899 add a prefix to all the table names to avoid conflicts.</p>
901 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
902 </dt>
904 <dd>
905 <?php
906 aField( $conf, "RootPW", "DB root password", "password" );
908 </dd>
909 <dt>
910 You will only need this if the database and/or user account
911 above don't already exist.
912 Do <em>not</em> type in your machine's root password! MySQL
913 has its own "root" user with a separate password. (It might
914 even be blank, depending on your configuration.)
915 </dt>
917 <dd>
918 <label class='column'>&nbsp;</label>
919 <input type="submit" value="Install!" />
920 </dd>
921 </dl>
924 </form>
926 <?php
929 /* -------------------------------------------------------------------------------------- */
931 function escapePhpString( $string ) {
932 return strtr( $string,
933 array(
934 "\n" => "\\n",
935 "\r" => "\\r",
936 "\t" => "\\t",
937 "\\" => "\\\\",
938 "\$" => "\\\$",
939 "\"" => "\\\""
943 function writeLocalSettings( $conf ) {
944 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
945 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
946 $conf->PasswordSender = $conf->EmergencyContact;
947 $zlib = ($conf->zlib ? "" : "# ");
948 $magic = ($conf->ImageMagick ? "" : "# ");
949 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
950 $pretty = ($conf->prettyURLs ? "" : "# ");
951 $ugly = ($conf->prettyURLs ? "# " : "");
952 $rights = ($conf->RightsUrl) ? "" : "# ";
954 switch ( $conf->Shm ) {
955 case 'memcached':
956 $memcached = 'true';
957 $turck = '#';
958 $mcservers = var_export( $conf->MCServerArray, true );
959 break;
960 case 'turck':
961 case 'eaccel':
962 $memcached = 'false';
963 $mcservers = 'array()';
964 $turck = '';
965 break;
966 default:
967 $memcached = 'false';
968 $mcservers = 'array()';
969 $turck = '#';
972 if ( $conf->Email == 'email_enabled' ) {
973 $enableemail = 'true';
974 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
975 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
976 switch ( $conf->Enotif ) {
977 case 'enotif_usertalk':
978 $enotifusertalk = 'true';
979 $enotifwatchlist = 'false';
980 break;
981 case 'enotif_allpages':
982 $enotifusertalk = 'true';
983 $enotifwatchlist = 'true';
984 break;
985 default:
986 $enotifusertalk = 'false';
987 $enotifwatchlist = 'false';
989 } else {
990 $enableuseremail = 'false';
991 $enableemail = 'false';
992 $eauthent = 'false';
993 $enotifusertalk = 'false';
994 $enotifwatchlist = 'false';
997 $file = @fopen( "/dev/urandom", "r" );
998 if ( $file ) {
999 $secretKey = bin2hex( fread( $file, 32 ) );
1000 fclose( $file );
1001 } else {
1002 $secretKey = "";
1003 for ( $i=0; $i<8; $i++ ) {
1004 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1006 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1009 # Add slashes to strings for double quoting
1010 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
1011 if( $conf->License == 'gfdl' ) {
1012 # Needs literal string interpolation for the current style path
1013 $slconf['RightsIcon'] = $conf->RightsIcon;
1016 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
1017 return "
1018 # This file was automatically generated by the MediaWiki installer.
1019 # If you make manual changes, please keep track in case you need to
1020 # recreate them later.
1022 \$IP = \"{$slconf['IP']}\";
1023 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
1024 require_once( \"includes/DefaultSettings.php\" );
1026 # If PHP's memory limit is very low, some operations may fail.
1027 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
1029 if ( \$wgCommandLineMode ) {
1030 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1031 die( \"This script must be run from the command line\\n\" );
1033 } elseif ( empty( \$wgConfiguring ) ) {
1034 ## Compress output if the browser supports it
1035 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
1038 \$wgSitename = \"{$slconf['Sitename']}\";
1040 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
1041 \$wgScript = \"\$wgScriptPath/index.php\";
1042 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
1044 ## If using PHP as a CGI module, use the ugly URLs
1045 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
1046 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
1048 \$wgStylePath = \"\$wgScriptPath/skins\";
1049 \$wgStyleDirectory = \"\$IP/skins\";
1050 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
1052 \$wgUploadPath = \"\$wgScriptPath/images\";
1053 \$wgUploadDirectory = \"\$IP/images\";
1055 \$wgEnableEmail = $enableemail;
1056 \$wgEnableUserEmail = $enableuseremail;
1058 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1059 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
1061 ## For a detailed description of the following switches see
1062 ## http://meta.wikimedia.org/Enotif and http://meta.wikimedia.org/Eauthent
1063 ## There are many more options for fine tuning available see
1064 ## /includes/DefaultSettings.php
1065 ## UPO means: this is also a user preference option
1066 \$wgEmailNotificationForUserTalkPages = $enotifusertalk; # UPO
1067 \$wgEmailNotificationForWatchlistPages = $enotifwatchlist; # UPO
1068 \$wgEmailAuthentication = $eauthent;
1070 \$wgDBserver = \"{$slconf['DBserver']}\";
1071 \$wgDBname = \"{$slconf['DBname']}\";
1072 \$wgDBuser = \"{$slconf['DBuser']}\";
1073 \$wgDBpassword = \"{$slconf['DBpassword']}\";
1074 \$wgDBprefix = \"{$slconf['DBprefix']}\";
1076 # If you're on MySQL 3.x, this next line must be FALSE:
1077 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
1079 ## Shared memory settings
1080 \$wgUseMemCached = $memcached;
1081 \$wgMemCachedServers = $mcservers;
1082 {$turck}\$wgUseTurckShm = function_exists( 'mmcache_get' ) && ( php_sapi_name() == 'apache' || php_sapi_name() == 'apache2handler' );
1083 {$turck}\$wgUseEAccelShm = function_exists( 'eaccelerator_get' ) && ( php_sapi_name() == 'apache' || php_sapi_name() == 'apache2handler' );
1085 ## To enable image uploads, make sure the 'images' directory
1086 ## is writable, then uncomment this:
1087 # \$wgEnableUploads = true;
1088 \$wgUseImageResize = {$conf->UseImageResize};
1089 {$magic}\$wgUseImageMagick = true;
1090 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
1092 ## If you have the appropriate support software installed
1093 ## you can enable inline LaTeX equations:
1094 # \$wgUseTeX = true;
1095 \$wgMathPath = \"{\$wgUploadPath}/math\";
1096 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
1097 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
1099 \$wgLocalInterwiki = \$wgSitename;
1101 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
1103 \$wgProxyKey = \"$secretKey\";
1105 ## Default skin: you can change the default skin. Use the internal symbolic
1106 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
1107 # \$wgDefaultSkin = 'monobook';
1109 ## For attaching licensing metadata to pages, and displaying an
1110 ## appropriate copyright notice / icon. GNU Free Documentation
1111 ## License and Creative Commons licenses are supported so far.
1112 {$rights}\$wgEnableCreativeCommonsRdf = true;
1113 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
1114 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
1115 \$wgRightsText = \"{$slconf['RightsText']}\";
1116 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
1117 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
1121 function dieout( $text ) {
1122 die( $text . "\n\n</body>\n</html>" );
1125 function importVar( &$var, $name, $default = "" ) {
1126 if( isset( $var[$name] ) ) {
1127 $retval = $var[$name];
1128 if ( get_magic_quotes_gpc() ) {
1129 $retval = stripslashes( $retval );
1131 } else {
1132 $retval = $default;
1134 return $retval;
1137 function importPost( $name, $default = "" ) {
1138 return importVar( $_POST, $name, $default );
1141 function importRequest( $name, $default = "" ) {
1142 return importVar( $_REQUEST, $name, $default );
1145 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
1146 if( $type != "" ) {
1147 $xtype = "type=\"$type\"";
1148 } else {
1149 $xtype = "";
1152 if(!(isset($id)) or ($id == "") ) $id = $field;
1153 $nolabel = ($type == "radio") || ($type == "hidden");
1154 if( $nolabel ) {
1155 echo "\t\t<label>";
1156 } else {
1157 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1160 if( $type == "radio" && $value == $conf->$field ) {
1161 $checked = "checked='checked'";
1162 } else {
1163 $checked = "";
1165 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
1166 if( $type == "radio" ) {
1167 echo htmlspecialchars( $value );
1168 } else {
1169 echo htmlspecialchars( $conf->$field );
1171 echo "\" />\n";
1172 if( $nolabel ) {
1173 echo " $text</label>\n";
1176 global $errs;
1177 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1180 function getLanguageList() {
1181 global $wgLanguageNames;
1182 if( !isset( $wgLanguageNames ) ) {
1183 $wgContLanguageCode = "xxx";
1184 function wfLocalUrl( $x ) { return $x; }
1185 function wfLocalUrlE( $x ) { return $x; }
1186 require_once( "../languages/Names.php" );
1189 $codes = array();
1191 $d = opendir( "../languages" );
1192 while( false !== ($f = readdir( $d ) ) ) {
1193 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1194 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1195 if( isset( $wgLanguageNames[$code] ) ) {
1196 $name = $code . ' - ' . $wgLanguageNames[$code];
1197 } else {
1198 $name = $code;
1200 $codes[$code] = $name;
1203 closedir( $d );
1204 ksort( $codes );
1205 return $codes;
1208 # Test a memcached server
1209 function testMemcachedServer( $server ) {
1210 $hostport = explode(":", $server);
1211 $errstr = false;
1212 $fp = false;
1213 if ( !function_exists( 'fsockopen' ) ) {
1214 $errstr = "Can't connect to memcached, fsockopen() not present";
1216 if ( !$errstr && count( $hostport ) != 2 ) {
1217 $errstr = 'Please specify host and port';
1218 var_dump( $hostport );
1220 if ( !$errstr ) {
1221 list( $host, $port ) = $hostport;
1222 $errno = 0;
1223 $fsockerr = '';
1225 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1226 if ( $fp === false ) {
1227 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1230 if ( !$errstr ) {
1231 $command = "version\r\n";
1232 $bytes = fwrite( $fp, $command );
1233 if ( $bytes != strlen( $command ) ) {
1234 $errstr = "Cannot write to memcached socket on $host:$port";
1237 if ( !$errstr ) {
1238 $expected = "VERSION ";
1239 $response = fread( $fp, strlen( $expected ) );
1240 if ( $response != $expected ) {
1241 $errstr = "Didn't get correct memcached response from $host:$port";
1244 if ( $fp ) {
1245 fclose( $fp );
1247 if ( !$errstr ) {
1248 echo "<li>Connected to memcached on $host:$port successfully";
1250 return $errstr;
1254 </body>
1255 </html>