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