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