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