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