* (bug 1938) Fix normalization of character references in link text and
[mediawiki.git] / config / index.php
blob1c3e0017fb1a97c875a2dab068e861e2678752d7
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/mediawiki.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 # Relative includes seem to break if a parent directory is not readable;
112 # this is common for public_html subdirs under user home directories.
114 # As a dirty hack, we'll try to set up the include path first.
116 $IP = dirname( dirname( __FILE__ ) );
117 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
118 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages" );
120 define( "MEDIAWIKI", true );
121 define( "MEDIAWIKI_INSTALL", true );
122 require_once( "includes/Defines.php" );
123 require_once( "includes/DefaultSettings.php" );
124 require_once( "includes/MagicWord.php" );
125 require_once( "includes/Namespace.php" );
128 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
131 <?php
133 /* Check for existing configurations and bug out! */
135 if( file_exists( "../LocalSettings.php" ) ) {
136 dieout( "<h2>Wiki is configured.</h2>
138 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
140 <p>(You should probably remove this directory for added security.)</p>" );
143 if( file_exists( "./LocalSettings.php" ) ) {
144 writeSuccessMessage();
146 dieout( '' );
149 if( !is_writable( "." ) ) {
150 dieout( "<h2>Can't write config file, aborting</h2>
152 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
153 writable by the web server. Once configuration is done you'll move the created
154 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
155 then remove the <tt>config</tt> subdirectory entirely.</p>
157 <p>To make the directory writable on a Unix/Linux system:</p>
159 <blockquote>
160 <tt>cd /path/to/wiki</tt><br>
161 <tt>chmod a+w config</tt>
162 </blockquote>" );
166 require_once( "install-utils.inc" );
167 require_once( "maintenance/updaters.inc" );
168 require_once( "maintenance/convertLinks.inc" );
169 require_once( "maintenance/archives/moveCustomMessages.inc" );
171 class ConfigData {
172 function getEncoded( $data ) {
173 # removing latin1 support, no need...
174 return $data;
176 function getSitename() { return $this->getEncoded( $this->Sitename ); }
177 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
178 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
183 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
185 <h2>Checking environment...</h2>
186 <ul>
187 <?php
188 $endl = "
190 $wgNoOutputBuffer = true;
191 $conf = new ConfigData;
193 install_version_checks();
195 print "<li>PHP " . phpversion() . ": ok</li>\n";
197 if( ini_get( "register_globals" ) ) {
199 <li><b class='error'>Warning:</b> <strong>PHP's
200 <tt><a href="http://php.net/register_globals">register_globals</a></tt>
201 option is enabled.</strong> MediaWiki will work correctly, but this setting
202 increases your exposure to potential security vulnerabilities in PHP-based
203 software running on your server. <strong>You should disable it if you are able.</strong></li>
204 <?php
207 $fatal = false;
209 if( ini_get( "magic_quotes_runtime" ) ) {
210 $fatal = true;
211 ?><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>
212 This option corrupts data input unpredictably; you cannot install or use
213 MediaWiki unless this option is disabled.
214 <?php
217 if( ini_get( "magic_quotes_sybase" ) ) {
218 $fatal = true;
219 ?><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>
220 This option corrupts data input unpredictably; you cannot install or use
221 MediaWiki unless this option is disabled.
222 <?php
225 if( $fatal ) {
226 dieout( "</ul><p>Cannot install wiki.</p>" );
229 if( ini_get( "safe_mode" ) ) {
230 $conf->safeMode = true;
232 <li><b class='error'>Warning:</b> <strong>PHP's
233 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active.</strong>
234 You may have problems caused by this, particularly if using image uploads.
235 </li>
236 <?php
237 } else {
238 $conf->safeMode = false;
242 $sapi = php_sapi_name();
243 $conf->prettyURLs = true;
244 print "<li>PHP server API is $sapi; ";
245 switch( $sapi ) {
246 case "apache":
247 case "apache2handler":
248 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
249 break;
250 case "cgi":
251 case "cgi-fcgi":
252 case "apache2filter":
253 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
254 $conf->prettyURLs = false;
255 break;
256 default:
257 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
259 print "</li>\n";
261 $conf->xml = function_exists( "utf8_encode" );
262 if( $conf->xml ) {
263 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
264 } else {
265 dieout( "PHP's XML module is missing; the wiki requires functions in
266 this module and won't work in this configuration.
267 If you're running Mandrake, install the php-xml package." );
270 $memlimit = ini_get( "memory_limit" );
271 $conf->raiseMemory = false;
272 if( empty( $memlimit ) ) {
273 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
274 } else {
275 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <strong>If this is too low, installation may fail!</strong> ";
276 $n = IntVal( $memlimit );
277 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
278 $n = IntVal( $m[1] * (1024*1024) );
280 if( $n < 20*1024*1024 ) {
281 print "Attempting to raise limit to 20M... ";
282 if( false === ini_set( "memory_limit", "20M" ) ) {
283 print "failed.";
284 } else {
285 $conf->raiseMemory = true;
286 print "ok.";
289 print "</li>\n";
292 $conf->zlib = function_exists( "gzencode" );
293 if( $conf->zlib ) {
294 print "<li>Have zlib support; enabling output compression.</li>\n";
295 } else {
296 print "<li>No zlib support.</li>\n";
299 $conf->turck = function_exists( 'mmcache_get' );
300 if ( $conf->turck ) {
301 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
303 $conf->eaccel = function_exists( 'eaccelerator_get' );
304 if ( $conf->eaccel ) {
305 $conf->turck = 'eaccelerator';
306 print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
308 if (!$conf->turck && !$conf->eaccel) {
309 print "<li>Neither <a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> nor <a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> are installed, " .
310 "can't use object caching functions</li>\n";
313 $conf->ImageMagick = false;
314 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
315 foreach( $imcheck as $dir ) {
316 $im = "$dir/convert";
317 if( file_exists( $im ) ) {
318 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
319 $conf->ImageMagick = $im;
320 break;
324 $conf->HaveGD = function_exists( "imagejpeg" );
325 if( $conf->HaveGD ) {
326 print "<li>Found GD graphics library built-in";
327 if( !$conf->ImageMagick ) {
328 print ", image thumbnailing will be enabled if you enable uploads";
330 print ".</li>\n";
331 } else {
332 if( !$conf->ImageMagick ) {
333 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
337 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
339 # $conf->IP = "/Users/brion/Sites/inplace";
340 $conf->IP = dirname( dirname( __FILE__ ) );
341 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
343 # $conf->ScriptPath = "/~brion/inplace";
344 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAME
345 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
347 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
349 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
350 $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
351 ? 'root@localhost'
352 : $_SERVER["SERVER_ADMIN"];
353 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
354 $conf->DBserver = importPost( "DBserver", "localhost" );
355 $conf->DBname = importPost( "DBname", "wikidb" );
356 $conf->DBuser = importPost( "DBuser", "wikiuser" );
357 $conf->DBpassword = importPost( "DBpassword" );
358 $conf->DBpassword2 = importPost( "DBpassword2" );
359 $conf->DBprefix = importPost( "DBprefix" );
360 $conf->RootPW = importPost( "RootPW" );
361 $conf->LanguageCode = importPost( "LanguageCode", "en" );
362 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
363 $conf->SysopPass = importPost( "SysopPass" );
364 $conf->SysopPass2 = importPost( "SysopPass2" );
366 /* Check for validity */
367 $errs = array();
369 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
370 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
372 if( $conf->DBuser == "" ) {
373 $errs["DBuser"] = "Must not be blank";
375 if( $conf->DBpassword == "" ) {
376 $errs["DBpassword"] = "Must not be blank";
378 if( $conf->DBpassword != $conf->DBpassword2 ) {
379 $errs["DBpassword2"] = "Passwords don't match!";
381 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
382 $errs["DBprefix"] = "Invalid table prefix";
385 if( $conf->SysopPass == "" ) {
386 $errs["SysopPass"] = "Must not be blank";
388 if( $conf->SysopPass != $conf->SysopPass2 ) {
389 $errs["SysopPass2"] = "Passwords don't match!";
392 $conf->License = importRequest( "License", "none" );
393 if( $conf->License == "gfdl" ) {
394 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
395 $conf->RightsText = "GNU Free Documentation License 1.2";
396 $conf->RightsCode = "gfdl";
397 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
398 } elseif( $conf->License == "none" ) {
399 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
400 } else {
401 $conf->RightsUrl = importRequest( "RightsUrl", "" );
402 $conf->RightsText = importRequest( "RightsText", "" );
403 $conf->RightsCode = importRequest( "RightsCode", "" );
404 $conf->RightsIcon = importRequest( "RightsIcon", "" );
407 $conf->Shm = importRequest( "Shm", "none" );
408 $conf->MCServers = importRequest( "MCServers" );
410 /* Test memcached servers */
412 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
413 $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
414 foreach ( $conf->MCServerArray as $server ) {
415 $error = testMemcachedServer( $server );
416 if ( $error ) {
417 $errs["MCServers"] = $error;
418 break;
421 } else if ( $conf->Shm == 'memcached' ) {
422 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
425 /* default values for installation */
426 $conf->Email =importRequest("Email", "email_enabled");
427 $conf->Emailuser=importRequest("Emailuser", "emailuser_enabled");
428 $conf->Enotif =importRequest("Enotif", "enotif_allpages");
429 $conf->Eauthent =importRequest("Eauthent", "eauthent_enabled");
431 if( $conf->posted && ( 0 == count( $errs ) ) ) {
432 do { /* So we can 'continue' to end prematurely */
433 $conf->Root = ($conf->RootPW != "");
435 /* Load up the settings and get installin' */
436 $local = writeLocalSettings( $conf );
437 $wgCommandLineMode = false;
438 chdir( ".." );
439 eval($local);
440 $wgDBadminuser = "root";
441 $wgDBadminpassword = $conf->RootPW;
442 $wgDBprefix = $conf->DBprefix;
443 $wgCommandLineMode = true;
444 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
445 require_once( "includes/Setup.php" );
446 chdir( "config" );
448 require_once( "maintenance/InitialiseMessages.inc" );
450 $wgTitle = Title::newFromText( "Installation script" );
451 print "<li>Trying to connect to MySQL on $wgDBserver as root...\n";
452 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
454 if( $wgDatabase->isOpen() ) {
455 $myver = mysql_get_server_info( $wgDatabase->mConn );
456 $wgDatabase->ignoreErrors(true);
457 $conf->Root = true;
458 print "<ul><li>Connected as root (automatic)</li></ul></li>\n";
459 } else {
460 print "<ul><li>MySQL error " . ($err = mysql_errno() ) .
461 ": " . htmlspecialchars( mysql_error() ) . "</li></ul></li>";
462 $ok = false;
463 switch( $err ) {
464 case 1045:
465 case 2000:
466 if( $conf->Root ) {
467 $errs["RootPW"] = "Check password";
468 } else {
469 print "<li>Trying regular user...\n";
470 /* Try the regular user... */
471 $wgDBadminuser = $wgDBuser;
472 $wgDBadminpassword = $wgDBpassword;
473 /* Wait one second for connection rate limiting, present on some systems */
474 sleep(1);
475 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
476 if( !$wgDatabase->isOpen() ) {
477 print "<ul><li>MySQL error " . ($err = mysql_errno() ) .
478 ": " . htmlspecialchars( mysql_error() ) . "</li></ul></li>";
479 $errs["DBuser"] = "Check name/pass";
480 $errs["DBpassword"] = "or enter root";
481 $errs["DBpassword2"] = "password below";
482 $errs["RootPW"] = "Got root?";
483 } else {
484 $myver = mysql_get_server_info( $wgDatabase->mConn );
485 $wgDatabase->ignoreErrors(true);
486 $conf->Root = false;
487 $conf->RootPW = "";
488 print " ok.</li>\n";
489 # And keep going...
490 $ok = true;
492 break;
494 case 2002:
495 case 2003:
496 $errs["DBserver"] = "Connection failed";
497 break;
498 default:
499 $errs["DBserver"] = "Couldn't connect to database";
500 break;
502 if( !$ok ) continue;
505 if ( !$wgDatabase->isOpen() ) {
506 $errs["DBserver"] = "Couldn't connect to database";
507 continue;
510 print "<li>Connected to $myver";
511 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
512 print "; enabling MySQL 4 enhancements";
513 $conf->DBmysql4 = true;
514 $local = writeLocalSettings( $conf );
516 print "</li>\n";
518 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
519 if( $sel ) {
520 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
521 } else {
522 $err = mysql_errno();
523 if ( $err != 1049 ) {
524 print "<ul><li>Error selecting database $wgDBname: $err " . htmlspecialchars( mysql_error() ) .
525 "</li></ul>";
526 continue;
528 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
529 if( !$res ) {
530 print "<li>Couldn't create database <tt>" .
531 htmlspecialchars( $wgDBname ) .
532 "</tt>; try with root access or check your username/pass.</li>\n";
533 $errs["RootPW"] = "&lt;- Enter";
534 continue;
536 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
539 $wgDatabase->selectDB( $wgDBname );
541 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
542 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
544 # Create user if required
545 if ( $conf->Root ) {
546 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
547 if ( $conn->isOpen() ) {
548 print "<li>DB user account ok</li>\n";
549 $conn->close();
550 } else {
551 print "<li>Granting user permissions...</li>\n";
552 dbsource( "../maintenance/users.sql", $wgDatabase );
555 print "<pre>\n";
556 chdir( ".." );
557 flush();
558 do_all_updates();
559 chdir( "config" );
561 print "</pre>\n";
562 print "<li>Finished update checks.</li>\n";
563 } else {
564 # FIXME: Check for errors
565 print "<li>Creating tables...";
566 dbsource( "../maintenance/tables.sql", $wgDatabase );
567 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
568 dbsource( "../maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase );
569 print " done.</li>\n";
571 print "<li>Initializing data...";
572 $wgDatabase->insert( 'site_stats',
573 array( 'ss_row_id' => 1,
574 'ss_total_views' => 0,
575 'ss_total_edits' => 0,
576 'ss_good_articles' => 0 ) );
577 # setting up the db user
578 if( $conf->Root ) {
579 print "<li>Granting user permissions...</li>\n";
580 dbsource( "../maintenance/users.sql", $wgDatabase );
583 if( $conf->SysopName ) {
584 $u = User::newFromName( $conf->getSysopName() );
585 if ( 0 == $u->idForName() ) {
586 $u->addToDatabase();
587 $u->setPassword( $conf->getSysopPass() );
588 $u->addRight( "sysop" );
589 $u->addRight( "bureaucrat" );
590 $u->saveSettings();
592 # Set up the new user in the sysop group
593 # This is a bit of an ugly hack
594 global $wgSysopGroupId, $wgBureaucratGroupId;
595 $groups = $u->getGroups();
596 $groups[] = $wgSysopGroupId;
597 $groups[] = $wgBureaucratGroupId;
598 $u->setGroups( $groups );
599 $u->saveSettings();
601 print "<li>Created sysop account <tt>" .
602 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
603 } else {
604 print "<li>Could not create user - already exists!</li>\n";
606 } else {
607 print "<li>Skipped sysop account creation, no name given.</li>\n";
610 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
611 $article = new Article( $titleobj );
612 $newid = $article->insertOn( $wgDatabase );
613 $revision = new Revision( array(
614 'page' => $newid,
615 'text' => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsg( 'mainpagedocfooter' ),
616 'comment' => '',
617 'user' => 0,
618 'user_text' => 'MediaWiki default',
619 ) );
620 $revid = $revision->insertOn( $wgDatabase );
621 $article->updateRevisionOn( $wgDatabase, $revision );
623 print "<li><pre>";
624 initialiseMessages();
625 print "</pre></li>\n";
628 /* Write out the config file now that all is well */
629 print "<p>Creating LocalSettings.php...</p>\n\n";
630 $localSettings = "<" . "?php$endl$local$endl?" . ">";
631 // Fix up a common line-ending problem (due to CVS on Windows)
632 $localSettings = str_replace( "\r\n", "\n", $localSettings );
634 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
635 $xt = "xt"; # Refuse to overwrite an existing file
636 } else {
637 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
639 $f = fopen( "LocalSettings.php", $xt );
641 if( $f == false ) {
642 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" .
643 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
644 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
646 if(fwrite( $f, $localSettings ) ) {
647 fclose( $f );
648 writeSuccessMessage();
649 } else {
650 fclose( $f );
651 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");
655 } while( false );
658 </ul>
661 <?php
663 if( count( $errs ) ) {
664 /* Display options form */
666 if( $conf->posted ) {
667 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
671 <form name="config" method="post">
674 <h2>Site config</h2>
676 <dl class="setup">
677 <dd>
678 <?php
679 aField( $conf, "Sitename", "Site name:" );
681 </dd>
682 <dt>
683 Your site name should be a relatively short word. It'll appear as the namespace
684 name for 'meta' pages as well as throughout the user interface. Good site names
685 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
686 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
687 which may cause problems.
688 </dt>
690 <dd>
691 <?php
692 aField( $conf, "EmergencyContact", "Contact e-mail" );
694 </dd>
695 <dt>
696 This will be used as the return address for password reminders and
697 may be displayed in some error conditions so visitors can get in
698 touch with you. It is also be used as the default sender address of e-mail
699 notifications (enotifs).
700 </dt>
702 <dd>
703 <label class='column' for="LanguageCode">Language</label>
704 <select id="LanguageCode" name="LanguageCode">
706 <?php
707 $list = getLanguageList();
708 foreach( $list as $code => $name ) {
709 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
710 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
713 </select>
714 </dd>
715 <dt>
716 You may select the language for the user interface of the wiki...
717 Some localizations are less complete than others. Unicode (UTF-8 encoding)
718 is used for all localizations.
719 </dt>
721 <dd>
722 <label class='column'>Copyright/license metadata</label>
723 <div>Select one:</div>
725 <ul class="plain">
726 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
727 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
728 <li><?php
729 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
730 $partner = "MediaWiki";
731 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
732 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
733 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
734 print "<a href=\"$ccApp\">choose</a>";
735 ?> (link will wipe out any other data in this form!)
736 <?php if( $conf->License == "cc" ) { ?>
737 <ul>
738 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
739 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
740 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
741 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
742 </ul>
743 <?php } ?>
744 </li>
745 </ul>
746 </dd>
747 <dt>
748 MediaWiki can include a basic license notice, icon, and machine-readable
749 copyright metadata if your wiki's content is to be licensed under
750 the GNU FDL or a Creative Commons license. If you're not sure, leave
751 it at "none".
752 </dt>
755 <dd>
756 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
757 </dd>
758 <dd>
759 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
760 </dd>
761 <dd>
762 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
763 </dd>
764 <dt>
765 A sysop user account can lock or delete pages, block problematic IP
766 addresses from editing, and other maintenance tasks. If creating a new
767 wiki database, a sysop account will be created with the given name
768 and password.
769 </dt>
771 <dd>
772 <label class='column'>Shared memory caching</label>
773 <div>Select one:</div>
775 <ul class="plain">
776 <li><?php aField( $conf, "Shm", "no caching", "radio", "none" ); ?></li>
777 <?php
778 if ( $conf->turck ) {
779 echo "<li>";
780 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
781 echo "</li>";
784 <?php
785 if ( $conf->eaccel ) {
786 echo "<li>";
787 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
788 echo "</li>";
791 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
792 <li><?php aField( $conf, "MCServers", "Memcached servers", "" ) ?></li>
793 </ul>
794 </dd>
795 <dt>
796 Using a shared memory system such as Turck MMCache, eAccelerator, or Memcached will speed
797 up MediaWiki significantly. Memcached is the best solution but needs to be
798 installed. Specify the server addresses and ports in a comma-separted list. Only
799 use Turck shared memory if the wiki will be running on a single Apache server.
800 </dl>
802 <h2>E-mail, e-mail notification and authentification setup</h2>
804 <dl class="setup">
805 <dd>
806 <label class='column'>E-mail (general)</label>
807 <div>Select one:</div>
809 <ul class="plain">
810 <li><?php aField( $conf, "Email", "enabled", "radio", "email_enabled" ); ?></li>
811 <li><?php aField( $conf, "Email", "disabled", "radio", "email_disabled" ); ?></li>
812 </ul>
813 </dd>
814 <dt>
815 Use this to disable all e-mail functions (send a password reminder, user-to-user e-mail and e-mail notification),
816 if sending e-mails on your server doesn't work.
817 </dt>
818 <dd>
819 <label class='column'>User-to-user e-mail</label>
820 <div>Select one:</div>
822 <ul class="plain">
823 <li><?php aField( $conf, "Emailuser", "enabled", "radio", "emailuser_enabled" ); ?></li>
824 <li><?php aField( $conf, "Emailuser", "disabled", "radio", "emailuser_disabled" ); ?></li>
825 </ul>
826 </dd>
827 <dt>
828 Use this to disable only the user-to-user e-mail function (EmailUser).
829 </dt>
830 <dd>
831 <label class='column'>E-mail notification</label>
832 <div>Select one:</div>
834 <ul class="plain">
835 <li><?php aField( $conf, "Enotif", "disabled", "radio", "enotif_disabled" ); ?></li>
836 <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>
837 <li><?php aField( $conf, "Enotif", "enabled for changes of user_talk pages only (suited for small and large wikis)", "radio", "enotif_usertalk" ); ?></li>
838 </ul>
839 </dd>
840 <dt>
841 <p><?php
842 $ccEnotif = htmlspecialchars( 'http://meta.wikipedia.org/Enotif' );
843 print "<a href=\"$ccEnotif\">E-mail notification</a>";
845 sends a notification e-mail to a user, when the user_talk page is changed
846 and/or when watch-listed pages are changed, depending on the above settings.
847 When testing this feature, be reminded, that obviously an e-mail address must be present in your preferences
848 and that your own changes never trigger notifications to be sent to yourself.</p>
850 <p>Users get corresponding options to select or deselect in their users' preferences.
851 The user options are not shown on the preference page, if e-mail notification is disabled.</p>
853 <p>There are additional options for fine tuning in /includes/DefaultSettings.php .</p>
854 </dt>
856 <dd>
857 <label class='column'>E-mail address authentication</label>
858 <div>Select one:</div>
860 <ul class="plain">
861 <li><?php aField( $conf, "Eauthent", "disabled", "radio", "eauthent_disabled" ); ?></li>
862 <li><?php aField( $conf, "Eauthent", "enabled", "radio", "eauthent_enabled" ); ?></li>
863 </ul>
864 </dd>
865 <dt>
866 <p><?php
867 $ccEauthent = htmlspecialchars( 'http://meta.wikipedia.org/Eauthent' );
868 print "<a href=\"$ccEnotif\">E-mail address authentication</a>";
870 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
871 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
872 is only authenticated at the moment when the user logs in with the one-time temporary password.<p>
874 <p>The e-mail address stays authenticated as long as the user does not change it; the time of authentication is indicated
875 on the user preference page.</p>
877 <p>If the option is enabled, only authenticated e-mail addresses can receive EmailUser mails and/or
878 e-mail notification mails.</p>
879 </dt>
881 </dl>
883 <h2>Database config</h2>
885 <dl class="setup">
886 <dd><?php
887 aField( $conf, "DBserver", "MySQL server" );
888 ?></dd>
889 <dt>
890 If your database server isn't on your web server, enter the name
891 or IP address here.
892 </dt>
894 <dd><?php
895 aField( $conf, "DBname", "Database name" );
896 ?></dd>
897 <dd><?php
898 aField( $conf, "DBuser", "DB username" );
899 ?></dd>
900 <dd><?php
901 aField( $conf, "DBpassword", "DB password", "password" );
902 ?></dd>
903 <dd><?php
904 aField( $conf, "DBpassword2", "again", "password" );
905 ?></dd>
906 <dt>
907 If you only have a single user account and database available,
908 enter those here. If you have database root access (see below)
909 you can specify new accounts/databases to be created.
910 </dt>
912 <dd><?php
913 aField( $conf, "DBprefix", "Database table prefix" );
914 ?></dd>
915 <dt>
916 <p>If you need to share one database between multiple wikis, or
917 MediaWiki and another web application, you may choose to
918 add a prefix to all the table names to avoid conflicts.</p>
920 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
921 </dt>
923 <dd>
924 <?php
925 aField( $conf, "RootPW", "DB root password", "password" );
927 </dd>
928 <dt>
929 You will only need this if the database and/or user account
930 above don't already exist.
931 Do <em>not</em> type in your machine's root password! MySQL
932 has its own "root" user with a separate password. (It might
933 even be blank, depending on your configuration.)
934 </dt>
936 <dd>
937 <label class='column'>&nbsp;</label>
938 <input type="submit" value="Install!" />
939 </dd>
940 </dl>
943 </form>
945 <?php
948 /* -------------------------------------------------------------------------------------- */
949 function writeSuccessMessage() {
950 global $conf;
951 if ( ini_get( 'safe_mode' ) && !ini_get( 'open_basedir' ) ) {
952 echo <<<EOT
953 <p>Installation successful!</p>
954 <p>To complete the installation, please do the following:
955 <ol>
956 <li>Download config/LocalSettings.php with your FTP client or file manager</li>
957 <li>Upload it to the parent directory</li>
958 <li>Delete config/LocalSettings.php</li>
959 <li>Start using <a href='../index.php'>your wiki</a>!
960 </ol>
961 <p>If you are in a shared hosting environment, do <strong>not</strong> just move LocalSettings.php
962 remotely. LocalSettings.php is currently owned by the user your webserver is running under,
963 which means that anyone on the same server can read your database password! Downloading
964 it and uploading it again will hopefully change the ownership to a user ID specific to you.</p>
965 EOT;
966 } else {
967 echo "<p>Installation successful! Move the config/LocalSettings.php file into the parent directory, then follow
968 <a href='../index.php'>this link</a> to your wiki.</p>\n";
973 function escapePhpString( $string ) {
974 return strtr( $string,
975 array(
976 "\n" => "\\n",
977 "\r" => "\\r",
978 "\t" => "\\t",
979 "\\" => "\\\\",
980 "\$" => "\\\$",
981 "\"" => "\\\""
985 function writeLocalSettings( $conf ) {
986 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
987 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
988 $conf->PasswordSender = $conf->EmergencyContact;
989 $zlib = ($conf->zlib ? "" : "# ");
990 $magic = ($conf->ImageMagick ? "" : "# ");
991 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
992 $pretty = ($conf->prettyURLs ? "" : "# ");
993 $ugly = ($conf->prettyURLs ? "# " : "");
994 $rights = ($conf->RightsUrl) ? "" : "# ";
995 $hashedUploads = $conf->safeMode ? '' : '# ';
997 switch ( $conf->Shm ) {
998 case 'memcached':
999 $cacheType = 'CACHE_MEMCACHED';
1000 $mcservers = var_export( $conf->MCServerArray, true );
1001 break;
1002 case 'turck':
1003 case 'eaccel':
1004 $cacheType = 'CACHE_ACCEL';
1005 $mcservers = 'array()';
1006 break;
1007 default:
1008 $cacheType = 'CACHE_NONE';
1009 $mcservers = 'array()';
1012 if ( $conf->Email == 'email_enabled' ) {
1013 $enableemail = 'true';
1014 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
1015 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
1016 switch ( $conf->Enotif ) {
1017 case 'enotif_usertalk':
1018 $enotifusertalk = 'true';
1019 $enotifwatchlist = 'false';
1020 break;
1021 case 'enotif_allpages':
1022 $enotifusertalk = 'true';
1023 $enotifwatchlist = 'true';
1024 break;
1025 default:
1026 $enotifusertalk = 'false';
1027 $enotifwatchlist = 'false';
1029 } else {
1030 $enableuseremail = 'false';
1031 $enableemail = 'false';
1032 $eauthent = 'false';
1033 $enotifusertalk = 'false';
1034 $enotifwatchlist = 'false';
1037 $file = @fopen( "/dev/urandom", "r" );
1038 if ( $file ) {
1039 $secretKey = bin2hex( fread( $file, 32 ) );
1040 fclose( $file );
1041 } else {
1042 $secretKey = "";
1043 for ( $i=0; $i<8; $i++ ) {
1044 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1046 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1049 # Add slashes to strings for double quoting
1050 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
1051 if( $conf->License == 'gfdl' ) {
1052 # Needs literal string interpolation for the current style path
1053 $slconf['RightsIcon'] = $conf->RightsIcon;
1056 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
1057 return "
1058 # This file was automatically generated by the MediaWiki installer.
1059 # If you make manual changes, please keep track in case you need to
1060 # recreate them later.
1062 \$IP = \"{$slconf['IP']}\";
1063 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
1064 require_once( \"includes/DefaultSettings.php\" );
1066 # If PHP's memory limit is very low, some operations may fail.
1067 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
1069 if ( \$wgCommandLineMode ) {
1070 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1071 die( \"This script must be run from the command line\\n\" );
1073 } elseif ( empty( \$wgNoOutputBuffer ) ) {
1074 ## Compress output if the browser supports it
1075 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
1078 \$wgSitename = \"{$slconf['Sitename']}\";
1080 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
1081 \$wgScript = \"\$wgScriptPath/index.php\";
1082 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
1084 ## If using PHP as a CGI module, use the ugly URLs
1085 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
1086 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
1088 \$wgStylePath = \"\$wgScriptPath/skins\";
1089 \$wgStyleDirectory = \"\$IP/skins\";
1090 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
1092 \$wgUploadPath = \"\$wgScriptPath/images\";
1093 \$wgUploadDirectory = \"\$IP/images\";
1095 \$wgEnableEmail = $enableemail;
1096 \$wgEnableUserEmail = $enableuseremail;
1098 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1099 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
1101 ## For a detailed description of the following switches see
1102 ## http://meta.wikimedia.org/Enotif and http://meta.wikimedia.org/Eauthent
1103 ## There are many more options for fine tuning available see
1104 ## /includes/DefaultSettings.php
1105 ## UPO means: this is also a user preference option
1106 \$wgEmailNotificationForUserTalkPages = $enotifusertalk; # UPO
1107 \$wgEmailNotificationForWatchlistPages = $enotifwatchlist; # UPO
1108 \$wgEmailAuthentication = $eauthent;
1110 \$wgDBserver = \"{$slconf['DBserver']}\";
1111 \$wgDBname = \"{$slconf['DBname']}\";
1112 \$wgDBuser = \"{$slconf['DBuser']}\";
1113 \$wgDBpassword = \"{$slconf['DBpassword']}\";
1114 \$wgDBprefix = \"{$slconf['DBprefix']}\";
1116 # If you're on MySQL 3.x, this next line must be FALSE:
1117 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
1119 ## Shared memory settings
1120 \$wgMainCacheType = $cacheType;
1121 \$wgMemCachedServers = $mcservers;
1123 ## To enable image uploads, make sure the 'images' directory
1124 ## is writable, then uncomment this:
1125 # \$wgEnableUploads = true;
1126 \$wgUseImageResize = {$conf->UseImageResize};
1127 {$magic}\$wgUseImageMagick = true;
1128 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
1130 ## If you want to use image uploads under safe mode,
1131 ## create the directories images/archive, images/thumb and
1132 ## images/temp, and make them all writable. Then uncomment
1133 ## this, if it's not already uncommented:
1134 {$hashedUploads}\$wgHashedUploadDirectory = false;
1136 ## If you have the appropriate support software installed
1137 ## you can enable inline LaTeX equations:
1138 # \$wgUseTeX = true;
1139 \$wgMathPath = \"{\$wgUploadPath}/math\";
1140 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
1141 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
1143 \$wgLocalInterwiki = \$wgSitename;
1145 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
1147 \$wgProxyKey = \"$secretKey\";
1149 ## Default skin: you can change the default skin. Use the internal symbolic
1150 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
1151 # \$wgDefaultSkin = 'monobook';
1153 ## For attaching licensing metadata to pages, and displaying an
1154 ## appropriate copyright notice / icon. GNU Free Documentation
1155 ## License and Creative Commons licenses are supported so far.
1156 {$rights}\$wgEnableCreativeCommonsRdf = true;
1157 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
1158 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
1159 \$wgRightsText = \"{$slconf['RightsText']}\";
1160 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
1161 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
1165 function dieout( $text ) {
1166 die( $text . "\n\n</body>\n</html>" );
1169 function importVar( &$var, $name, $default = "" ) {
1170 if( isset( $var[$name] ) ) {
1171 $retval = $var[$name];
1172 if ( get_magic_quotes_gpc() ) {
1173 $retval = stripslashes( $retval );
1175 } else {
1176 $retval = $default;
1178 return $retval;
1181 function importPost( $name, $default = "" ) {
1182 return importVar( $_POST, $name, $default );
1185 function importRequest( $name, $default = "" ) {
1186 return importVar( $_REQUEST, $name, $default );
1189 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
1190 if( $type != "" ) {
1191 $xtype = "type=\"$type\"";
1192 } else {
1193 $xtype = "";
1196 if(!(isset($id)) or ($id == "") ) $id = $field;
1197 $nolabel = ($type == "radio") || ($type == "hidden");
1198 if( $nolabel ) {
1199 echo "\t\t<label>";
1200 } else {
1201 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1204 if( $type == "radio" && $value == $conf->$field ) {
1205 $checked = "checked='checked'";
1206 } else {
1207 $checked = "";
1209 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
1210 if( $type == "radio" ) {
1211 echo htmlspecialchars( $value );
1212 } else {
1213 echo htmlspecialchars( $conf->$field );
1215 echo "\" />\n";
1216 if( $nolabel ) {
1217 echo " $text</label>\n";
1220 global $errs;
1221 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1224 function getLanguageList() {
1225 global $wgLanguageNames;
1226 if( !isset( $wgLanguageNames ) ) {
1227 $wgContLanguageCode = "xxx";
1228 function wfLocalUrl( $x ) { return $x; }
1229 function wfLocalUrlE( $x ) { return $x; }
1230 require_once( "languages/Names.php" );
1233 $codes = array();
1235 $d = opendir( "../languages" );
1236 while( false !== ($f = readdir( $d ) ) ) {
1237 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1238 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1239 if( isset( $wgLanguageNames[$code] ) ) {
1240 $name = $code . ' - ' . $wgLanguageNames[$code];
1241 } else {
1242 $name = $code;
1244 $codes[$code] = $name;
1247 closedir( $d );
1248 ksort( $codes );
1249 return $codes;
1252 # Test a memcached server
1253 function testMemcachedServer( $server ) {
1254 $hostport = explode(":", $server);
1255 $errstr = false;
1256 $fp = false;
1257 if ( !function_exists( 'fsockopen' ) ) {
1258 $errstr = "Can't connect to memcached, fsockopen() not present";
1260 if ( !$errstr && count( $hostport ) != 2 ) {
1261 $errstr = 'Please specify host and port';
1262 var_dump( $hostport );
1264 if ( !$errstr ) {
1265 list( $host, $port ) = $hostport;
1266 $errno = 0;
1267 $fsockerr = '';
1269 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1270 if ( $fp === false ) {
1271 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1274 if ( !$errstr ) {
1275 $command = "version\r\n";
1276 $bytes = fwrite( $fp, $command );
1277 if ( $bytes != strlen( $command ) ) {
1278 $errstr = "Cannot write to memcached socket on $host:$port";
1281 if ( !$errstr ) {
1282 $expected = "VERSION ";
1283 $response = fread( $fp, strlen( $expected ) );
1284 if ( $response != $expected ) {
1285 $errstr = "Didn't get correct memcached response from $host:$port";
1288 if ( $fp ) {
1289 fclose( $fp );
1291 if ( !$errstr ) {
1292 echo "<li>Connected to memcached on $host:$port successfully";
1294 return $errstr;
1298 </body>
1299 </html>