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