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