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