Capitalization fix in memcached setting
[mediawiki.git] / config / index.php
blob96e7a23a1b7482859658bf028738187587d7b413
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/"><img
78 src="../skins/common/images/wiki.png" width="135" height="135" alt="" border="0" /></a>
79 </center>
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>
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>
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>
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>
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>
108 <?php
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" );
119 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
122 <?php
124 /* Check for existing configurations and bug out! */
126 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
127 dieout( "<h2>Wiki is configured.</h2>
129 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
131 <p>(You should probably remove this directory for added security.)</p>" );
134 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
135 dieout( "<h2>You're configured!</h2>
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>" );
142 if( !is_writable( "." ) ) {
143 dieout( "<h2>Can't write config file, aborting</h2>
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>
150 <p>To make the directory writable on a Unix/Linux system:</p>
152 <pre>
153 cd <i>/path/to/wiki</i>
154 chmod a+w config
155 </pre>" );
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" );
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;
174 function getSitename() { return $this->getEncoded( $this->Sitename ); }
175 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
176 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
181 <p><i>Please include all of the lines below when reporting installation problems.</i></p>
183 <h2>Checking environment...</h2>
184 <ul>
185 <?php
186 $endl = "
188 $wgConfiguring = true;
189 $conf = new ConfigData;
191 install_version_checks();
193 print "<li>PHP " . phpversion() . ": ok</li>\n";
195 if( ini_get( "register_globals" ) ) {
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
205 if( ini_get( "safe_mode" ) ) {
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
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>";
233 print "</li>\n";
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." );
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) );
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.";
263 print "</li>\n";
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";
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";
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;
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";
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";
305 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
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";
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";
315 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
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->RootPW = importPost( "RootPW" );
325 $conf->LanguageCode = importPost( "LanguageCode", "en" );
326 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
327 $conf->SysopPass = importPost( "SysopPass" );
328 $conf->SysopPass2 = importPost( "SysopPass2" );
330 /* Check for validity */
331 $errs = array();
333 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
334 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
336 if( $conf->DBuser == "" ) {
337 $errs["DBuser"] = "Must not be blank";
339 if( $conf->DBpassword == "" ) {
340 $errs["DBpassword"] = "Must not be blank";
342 if( $conf->DBpassword != $conf->DBpassword2 ) {
343 $errs["DBpassword2"] = "Passwords don't match!";
346 if( $conf->SysopPass == "" ) {
347 $errs["SysopPass"] = "Must not be blank";
349 if( $conf->SysopPass != $conf->SysopPass2 ) {
350 $errs["SysopPass2"] = "Passwords don't match!";
353 $conf->License = importRequest( "License", "none" );
354 if( $conf->License == "gfdl" ) {
355 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
356 $conf->RightsText = "GNU Free Documentation License 1.2";
357 $conf->RightsCode = "gfdl";
358 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
359 } elseif( $conf->License == "none" ) {
360 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
361 } else {
362 $conf->RightsUrl = importRequest( "RightsUrl", "" );
363 $conf->RightsText = importRequest( "RightsText", "" );
364 $conf->RightsCode = importRequest( "RightsCode", "" );
365 $conf->RightsIcon = importRequest( "RightsIcon", "" );
368 $conf->Shm = importRequest( "Shm", "none" );
369 $conf->MCServers = importRequest( "MCServers" );
371 /* Test memcached servers */
373 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
374 $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
375 foreach ( $conf->MCServerArray as $server ) {
376 $error = testMemcachedServer( $server );
377 if ( $error ) {
378 $errs["MCServers"] = $error;
379 break;
382 } else if ( $conf->Shm == 'memcached' ) {
383 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
386 if( $conf->posted && ( 0 == count( $errs ) ) ) {
387 do { /* So we can 'continue' to end prematurely */
388 $conf->Root = ($conf->RootPW != "");
390 /* Load up the settings and get installin' */
391 $local = writeLocalSettings( $conf );
392 $wgCommandLineMode = false;
393 chdir( ".." );
394 eval($local);
395 $wgDBadminuser = "root";
396 $wgDBadminpassword = $conf->RootPW;
397 $wgCommandLineMode = true;
398 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
399 require_once( "includes/Setup.php" );
400 chdir( "config" );
402 require_once( "../maintenance/InitialiseMessages.inc" );
404 $wgTitle = Title::newFromText( "Installation script" );
405 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
406 $wgDatabase->mIgnoreErrors = true;
408 @$myver = mysql_get_server_info( $wgDatabase->mConn );
409 if( $myver ) {
410 $conf->Root = true;
411 print "<li>Connected as root (automatic)</li>\n";
412 } else {
413 print "<li>MySQL error " . ($err = mysql_errno() ) .
414 ": " . htmlspecialchars( mysql_error() );
415 $ok = false;
416 switch( $err ) {
417 case 1045:
418 case 2000:
419 if( $conf->Root ) {
420 $errs["RootPW"] = "Check password";
421 } else {
422 print "<li>Trying regular user...\n";
423 /* Try the regular user... */
424 $wgDBadminuser = $wgDBuser;
425 $wgDBadminpassword = $wgDBpassword;
426 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
427 $wgDatabase->isOpen();
428 $wgDatabase->mIgnoreErrors = true;
429 @$myver = mysql_get_server_info( $wgDatabase->mConn );
430 if( !$myver ) {
431 $errs["DBuser"] = "Check name/pass";
432 $errs["DBpassword"] = "or enter root";
433 $errs["DBpassword2"] = "password below";
434 $errs["RootPW"] = "Got root?";
435 print " need password.</li>\n";
436 } else {
437 $conf->Root = false;
438 $conf->RootPW = "";
439 print " ok.</li>\n";
440 # And keep going...
441 $ok = true;
443 break;
445 case 2002:
446 case 2003:
447 $errs["DBserver"] = "Connection failed";
448 break;
449 default:
450 $errs["DBserver"] = "Couldn't connect to database";
451 break;
453 if( !$ok ) continue;
456 if ( !$wgDatabase->isOpen() ) {
457 $errs["DBserver"] = "Couldn't connect to database";
458 continue;
461 print "<li>Connected to database... $myver";
462 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
463 print "; enabling MySQL 4 enhancements";
464 $conf->DBmysql4 = true;
465 $local = writeLocalSettings( $conf );
467 print "</li>\n";
469 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
470 if( $sel ) {
471 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
472 } else {
473 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
474 if( !$res ) {
475 print "<li>Couldn't create database <tt>" .
476 htmlspecialchars( $wgDBname ) .
477 "</tt>; try with root access or check your username/pass.</li>\n";
478 $errs["RootPW"] = "&lt;- Enter";
479 continue;
481 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
484 $wgDatabase->selectDB( $wgDBname );
486 if( $wgDatabase->tableExists( "cur" ) ) {
487 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
489 # Create user if required
490 if ( $conf->Root ) {
491 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
492 if ( $conn->isOpen() ) {
493 print "<li>DB user account ok</li>\n";
494 $conn->close();
495 } else {
496 print "<li>Granting user permissions...</li>\n";
497 dbsource( "../maintenance/users.sql", $wgDatabase );
500 print "<pre>\n";
501 chdir( ".." );
502 flush();
503 do_all_updates();
504 chdir( "config" );
506 print "</pre>\n";
507 print "<li>Finished update checks.</li>\n";
508 } else {
509 # FIXME: Check for errors
510 print "<li>Creating tables...";
511 dbsource( "../maintenance/tables.sql", $wgDatabase );
512 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
513 dbsource( "../maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase );
514 print " done.</li>\n";
516 print "<li>Initializing data...";
517 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
518 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
519 # setting up the db user
520 if( $conf->Root ) {
521 print "<li>Granting user permissions...</li>\n";
522 dbsource( "../maintenance/users.sql", $wgDatabase );
525 if( $conf->SysopName ) {
526 $u = User::newFromName( $conf->getSysopName() );
527 if ( 0 == $u->idForName() ) {
528 $u->addToDatabase();
529 $u->setPassword( $conf->getSysopPass() );
530 $u->addRight( "sysop" );
531 $u->addRight( "bureaucrat" );
532 $u->saveSettings();
533 print "<li>Created sysop account <tt>" .
534 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
535 } else {
536 print "<li>Could not create user - already exists!</li>\n";
538 } else {
539 print "<li>Skipped sysop account creation, no name given.</li>\n";
542 print "<li>Initialising log pages...";
543 $logs = array(
544 "uploadlogpage" => "uploadlogpagetext",
545 "dellogpage" => "dellogpagetext",
546 "protectlogpage" => "protectlogtext",
547 "blocklogpage" => "blocklogtext"
549 $metaNamespace = Namespace::getWikipedia();
550 $now = wfTimestampNow();
551 $won = wfInvertTimestamp( $now );
552 foreach( $logs as $page => $text ) {
553 $logTitle = $wgDatabase->strencode( $wgLang->ucfirst( str_replace( " ", "_", wfMsgNoDB( $page ) ) ) );
554 $logText = $wgDatabase->strencode( wfMsgNoDB( $text ) );
555 $wgDatabase->query( "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
556 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) " .
557 "VALUES ($metaNamespace,'$logTitle','$logText','sysop','$now','$won','$now')" );
559 print "</li>\n";
561 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
562 $title = $titleobj->getDBkey();
563 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched,cur_user,cur_user_text) " .
564 "VALUES (0,'$title','" .
565 wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) .
566 "','$now','$won','$now',0,'MediaWiki default')";
567 $wgDatabase->query( $sql, $fname );
569 print "<li><pre>";
570 initialiseMessages();
571 print "</pre></li>\n";
574 /* Write out the config file now that all is well */
575 print "<p>Creating LocalSettings.php...</p>\n\n";
576 $localSettings = "<" . "?php$endl$local$endl?" . ">";
578 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
579 $xt = "xt"; # Refuse to overwrite an existing file
580 } else {
581 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
583 $f = fopen( "LocalSettings.php", $xt );
585 if( $f == false ) {
586 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" .
587 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
588 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
590 if(fwrite( $f, $localSettings ) ) {
591 fclose( $f );
593 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
594 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
595 } else {
596 fclose( $f );
597 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");
601 } while( false );
604 </ul>
607 <?php
609 if( count( $errs ) ) {
610 /* Display options form */
612 if( $conf->posted ) {
613 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
617 <form name="config" method="post">
620 <h2>Site config</h2>
622 <dl class="setup">
623 <dd>
624 <?php
625 aField( $conf, "Sitename", "Site name:" );
627 </dd>
628 <dt>
629 Your site name should be a relatively short word. It'll appear as the namespace
630 name for 'meta' pages as well as throughout the user interface. Good site names
631 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
632 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
633 which may cause problems.
634 </dt>
636 <dd>
637 <?php
638 aField( $conf, "EmergencyContact", "Contact e-mail" );
640 </dd>
641 <dt>
642 This will be used as the return address for password reminders and
643 may be displayed in some error conditions so visitors can get in
644 touch with you.
645 </dt>
647 <dd>
648 <label class='column' for="LanguageCode">Language</label>
649 <select id="LanguageCode" name="LanguageCode">
650 <?php
651 $list = getLanguageList();
652 foreach( $list as $code => $name ) {
653 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
654 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
657 </select>
658 </dd>
659 <dt>
660 You may select the language for the user interface of the wiki...
661 Some localizations are less complete than others. This also controls
662 the character encoding; Unicode is more flexible, but Latin-1 may be
663 more compatible with older browsers for some languages. Unicode will
664 be used where not specified otherwise.
665 </dt>
667 <dd>
668 <label class='column'>Copyright/license metadata</label>
669 <div>Select one:</div>
671 <ul class="plain">
672 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
673 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
674 <li><?php
675 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
676 $partner = "MediaWiki";
677 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
678 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
679 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
680 print "<a href=\"$ccApp\">choose</a>";
681 ?> (link will wipe out any other data in this form!)
682 <?php if( $conf->License == "cc" ) { ?>
683 <ul>
684 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
685 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
686 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
687 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
688 </ul>
689 <?php } ?>
690 </li>
691 </ul>
692 </dd>
693 <dt>
694 MediaWiki can include a basic license notice, icon, and machine-readable
695 copyright metadata if your wiki's content is to be licensed under
696 the GNU FDL or a Creative Commons license. If you're not sure, leave
697 it at "none".
698 </dt>
701 <dd>
702 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
703 </dd>
704 <dd>
705 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
706 </dd>
707 <dd>
708 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
709 </dd>
710 <dt>
711 A sysop user account can lock or delete pages, block problematic IP
712 addresses from editing, and other maintenance tasks. If creating a new
713 wiki database, a sysop account will be created with the given name
714 and password.
715 </dt>
717 <dd>
718 <label class='column'>Shared memory caching</label>
719 <div>Select one:</div>
721 <ul class="plain">
722 <li><?php aField( $conf, "Shm", "no caching", "radio", "none" ); ?></li>
723 <?php
724 if ( $conf->turck ) {
725 echo "<li>";
726 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
727 echo "</li>";
730 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
731 <li><?php aField( $conf, "MCServers", "Memcached servers", "" ) ?></li>
732 </ul>
733 </dd>
734 <dt>
735 Using a shared memory system such as Turck MMCache or Memcached will speed
736 up MediaWiki significantly. Memcached is the best solution but needs to be
737 installed. Specify the server addresses and ports in a comma-separted list. Only
738 use Turck shared memory if the wiki will be running on a single Apache server.
739 </dl>
741 <h2>Database config</h2>
743 <dl class="setup">
744 <dd><?php
745 aField( $conf, "DBserver", "MySQL server" );
746 ?></dd>
747 <dt>
748 If your database server isn't on your web server, enter the name
749 or IP address here.
750 </dt>
752 <dd><?php
753 aField( $conf, "DBname", "Database name" );
754 ?></dd>
755 <dd><?php
756 aField( $conf, "DBuser", "DB username" );
757 ?></dd>
758 <dd><?php
759 aField( $conf, "DBpassword", "DB password", "password" );
760 ?></dd>
761 <dd><?php
762 aField( $conf, "DBpassword2", "again", "password" );
763 ?></dd>
764 <dt>
765 If you only have a single user account and database available,
766 enter those here. If you have database root access (see below)
767 you can specify new accounts/databases to be created.
768 </dt>
771 <dd>
772 <?php
773 aField( $conf, "RootPW", "DB root password", "password" );
775 </dd>
776 <dt>
777 You will only need this if the database and/or user account
778 above don't already exist.
779 Do <em>not</em> type in your machine's root password! MySQL
780 has its own "root" user with a separate password. (It might
781 even be blank, depending on your configuration.)
782 </dt>
784 <dd>
785 <label class='column'>&nbsp;</label>
786 <input type="submit" value="Install!" />
787 </dd>
788 </dl>
791 </form>
793 <?php
796 /* -------------------------------------------------------------------------------------- */
798 function writeAdminSettings( $conf ) {
799 return "
800 \$wgDBadminuser = \"{$conf->DBadminuser}\";
801 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
805 function escapePhpString( $string ) {
806 return strtr( $string,
807 array(
808 "\n" => "\\n",
809 "\r" => "\\r",
810 "\t" => "\\t",
811 "\\" => "\\\\",
812 "\$" => "\\\$",
813 "\"" => "\\\""
817 function writeLocalSettings( $conf ) {
818 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
819 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
820 $conf->PasswordSender = $conf->EmergencyContact;
821 if( preg_match( '/^([a-z]+)-latin1$/', $conf->LanguageCode, $m ) ) {
822 $conf->LanguageCode = $m[1];
823 $conf->Latin1 = true;
824 } else {
825 $conf->Latin1 = false;
827 $zlib = ($conf->zlib ? "" : "# ");
828 $magic = ($conf->ImageMagick ? "" : "# ");
829 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
830 $pretty = ($conf->prettyURLs ? "" : "# ");
831 $ugly = ($conf->prettyURLs ? "# " : "");
832 $rights = ($conf->RightsUrl) ? "" : "# ";
834 switch ( $conf->Shm ) {
835 case 'memcached':
836 $memcached = 'true';
837 $turck = '#';
838 $mcservers = var_export( $conf->MCServerArray, true );
839 break;
840 case 'turck':
841 $memcached = 'false';
842 $mcservers = 'array()';
843 $turck = '';
844 break;
845 default:
846 $memcached = 'false';
847 $mcservers = 'array()';
848 $turck = '#';
852 $file = @fopen( "/dev/urandom", "r" );
853 if ( $file ) {
854 $proxyKey = bin2hex( fread( $file, 32 ) );
855 fclose( $file );
856 } else {
857 $proxyKey = "";
858 for ( $i=0; $i<8; $i++ ) {
859 $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
861 print "<li>Warning: \$wgProxyKey is insecure</li>\n";
864 # Add slashes to strings for double quoting
865 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
866 if( $conf->License == 'gfdl' ) {
867 # Needs literal string interpolation for the current style path
868 $slconf['RightsIcon'] = $conf->RightsIcon;
871 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
872 return "
873 # This file was automatically generated by the MediaWiki installer.
874 # If you make manual changes, please keep track in case you need to
875 # recreate them later.
877 \$IP = \"{$slconf['IP']}\";
878 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
879 require_once( \"includes/DefaultSettings.php\" );
881 # If PHP's memory limit is very low, some operations may fail.
882 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
884 if ( \$wgCommandLineMode ) {
885 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
886 die( \"This script must be run from the command line\\n\" );
888 } elseif ( empty( \$wgConfiguring ) ) {
889 ## Compress output if the browser supports it
890 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
893 \$wgSitename = \"{$slconf['Sitename']}\";
895 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
896 \$wgScript = \"\$wgScriptPath/index.php\";
897 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
899 ## If using PHP as a CGI module, use the ugly URLs
900 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
901 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
903 \$wgStylePath = \"\$wgScriptPath/skins\";
904 \$wgStyleDirectory = \"\$IP/skins\";
905 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
907 \$wgUploadPath = \"\$wgScriptPath/images\";
908 \$wgUploadDirectory = \"\$IP/images\";
910 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
911 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
913 \$wgDBserver = \"{$slconf['DBserver']}\";
914 \$wgDBname = \"{$slconf['DBname']}\";
915 \$wgDBuser = \"{$slconf['DBuser']}\";
916 \$wgDBpassword = \"{$slconf['DBpassword']}\";
918 ## To allow SQL queries through the wiki's Special:Askaql page,
919 ## uncomment the next lines. THIS IS VERY INSECURE. If you want
920 ## to allow semipublic read-only SQL access for your sysops,
921 ## you should define a MySQL user with limited privileges.
922 ## See MySQL docs: http://www.mysql.com/doc/en/GRANT.html
924 # \$wgAllowSysopQueries = true;
925 # \$wgDBsqluser = \"sqluser\";
926 # \$wgDBsqlpassword = \"sqlpass\";
928 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
930 ## Shared memory settings
931 \$wgUseMemCached = $memcached;
932 \$wgMemCachedServers = $mcservers;
933 {$turck}\$wgUseTurckShm = function_exists( 'mmcache_get' ) && php_sapi_name() == 'apache';
935 ## To enable image uploads, make sure the 'images' directory
936 ## is writable, then uncomment this:
937 # \$wgDisableUploads = false;
938 \$wgUseImageResize = {$conf->UseImageResize};
939 {$magic}\$wgUseImageMagick = true;
940 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
942 ## If you have the appropriate support software installed
943 ## you can enable inline LaTeX equations:
944 # \$wgUseTeX = true;
945 \$wgMathPath = \"{\$wgUploadPath}/math\";
946 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
947 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
949 \$wgLocalInterwiki = \$wgSitename;
951 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
952 \$wgUseLatin1 = " . ($conf->Latin1 ? 'true' : 'false') . ";\n
954 \$wgProxyKey = \"$proxyKey\";
956 ## Default skin: you can change the default skin. Use the internal symbolic
957 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
958 # \$wgDefaultSkin = 'monobook';
960 ## For attaching licensing metadata to pages, and displaying an
961 ## appropriate copyright notice / icon. GNU Free Documentation
962 ## License and Creative Commons licenses are supported so far.
963 {$rights}\$wgEnableCreativeCommonsRdf = true;
964 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
965 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
966 \$wgRightsText = \"{$slconf['RightsText']}\";
967 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
968 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
972 function dieout( $text ) {
973 die( $text . "\n\n</body>\n</html>" );
976 function importVar( &$var, $name, $default = "" ) {
977 if( isset( $var[$name] ) ) {
978 $retval = $var[$name];
979 if ( get_magic_quotes_gpc() ) {
980 $retval = stripslashes( $retval );
982 } else {
983 $retval = $default;
985 return $retval;
988 function importPost( $name, $default = "" ) {
989 return importVar( $_POST, $name, $default );
992 function importRequest( $name, $default = "" ) {
993 return importVar( $_REQUEST, $name, $default );
996 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
997 if( $type != "" ) {
998 $xtype = "type=\"$type\"";
999 } else {
1000 $xtype = "";
1003 if(!(isset($id)) or ($id == "") ) $id = $field;
1004 $nolabel = ($type == "radio") || ($type == "hidden");
1005 if( $nolabel ) {
1006 echo "\t\t<label>";
1007 } else {
1008 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1011 if( $type == "radio" && $value == $conf->$field ) {
1012 $checked = "checked='checked'";
1013 } else {
1014 $checked = "";
1016 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
1017 if( $type == "radio" ) {
1018 echo htmlspecialchars( $value );
1019 } else {
1020 echo htmlspecialchars( $conf->$field );
1022 echo "\" />\n";
1023 if( $nolabel ) {
1024 echo " $text</label>\n";
1027 global $errs;
1028 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1031 function getLanguageList() {
1032 global $wgLanguageNames;
1033 if( !isset( $wgLanguageNames ) ) {
1034 $wgContLanguageCode = "xxx";
1035 function wfLocalUrl( $x ) { return $x; }
1036 function wfLocalUrlE( $x ) { return $x; }
1037 require_once( "../languages/Names.php" );
1040 $codes = array();
1041 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
1043 $d = opendir( "../languages" );
1044 while( false !== ($f = readdir( $d ) ) ) {
1045 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1046 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1047 if( in_array( $code, $latin1 ) ) {
1048 $codes[$code] = "$code - " . $wgLanguageNames[$code] . " - Unicode";
1049 $codes[$code.'-latin1'] = "$code - " . $wgLanguageNames[$code] . " - Latin-1";
1050 } else {
1051 $codes[$code] = "$code - " . $wgLanguageNames[$code];
1055 closedir( $d );
1056 ksort( $codes );
1057 return $codes;
1060 # Test a memcached server
1061 function testMemcachedServer( $server ) {
1062 $hostport = explode(":", $server);
1063 $errstr = false;
1064 $fp = false;
1065 if ( !function_exists( 'fsockopen' ) ) {
1066 $errstr = "Can't connect to memcached, fsockopen() not present";
1068 if ( !$errstr && count( $hostport ) != 2 ) {
1069 $errstr = 'Please specify host and port';
1070 var_dump( $hostport );
1072 if ( !$errstr ) {
1073 list( $host, $port ) = $hostport;
1074 $errno = 0;
1075 $fsockerr = '';
1077 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1078 if ( $fp === false ) {
1079 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1082 if ( !$errstr ) {
1083 $command = "version\r\n";
1084 $bytes = fwrite( $fp, $command );
1085 if ( $bytes != strlen( $command ) ) {
1086 $errstr = "Cannot write to memcached socket on $host:$port";
1089 if ( !$errstr ) {
1090 $expected = "VERSION ";
1091 $response = fread( $fp, strlen( $expected ) );
1092 if ( $response != $expected ) {
1093 $errstr = "Didn't get correct memcached response from $host:$port";
1096 if ( $fp ) {
1097 fclose( $fp );
1099 if ( !$errstr ) {
1100 echo "<li>Connected to memcached on $host:$port successfully";
1102 return $errstr;
1106 </body>
1107 </html>