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