]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - config/index.php
MediaWiki 1.14.0
[autoinstalls/mediawiki.git] / config / index.php
1 <?php
2
3 # MediaWiki web-based config/installation
4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2006 Rob Church <robchur@gmail.com>
5 # http://www.mediawiki.org/
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21
22 error_reporting( E_ALL );
23 header( "Content-type: text/html; charset=utf-8" );
24 @ini_set( "display_errors", true );
25
26 # In case of errors, let output be clean.
27 $wgRequestTime = microtime( true );
28
29 # Attempt to set up the include path, to fix problems with relative includes
30 $IP = dirname( dirname( __FILE__ ) );
31 define( 'MW_INSTALL_PATH', $IP );
32
33 # Define an entry point and include some files
34 define( "MEDIAWIKI", true );
35 define( "MEDIAWIKI_INSTALL", true );
36
37 // Run version checks before including other files
38 // so people don't see a scary parse error.
39 require_once( "$IP/install-utils.inc" );
40 install_version_checks();
41
42 require_once( "$IP/includes/Defines.php" );
43 require_once( "$IP/includes/DefaultSettings.php" );
44 require_once( "$IP/includes/AutoLoader.php" );
45 require_once( "$IP/includes/MagicWord.php" );
46 require_once( "$IP/includes/Namespace.php" );
47 require_once( "$IP/includes/ProfilerStub.php" );
48 require_once( "$IP/includes/GlobalFunctions.php" );
49 require_once( "$IP/includes/Hooks.php" );
50
51 # If we get an exception, the user needs to know
52 # all the details
53 $wgShowExceptionDetails = true;
54
55 ## Databases we support:
56
57 $ourdb = array();
58 $ourdb['mysql']['fullname']      = 'MySQL';
59 $ourdb['mysql']['havedriver']    = 0;
60 $ourdb['mysql']['compile']       = 'mysql';
61 $ourdb['mysql']['bgcolor']       = '#ffe5a7';
62 $ourdb['mysql']['rootuser']      = 'root';
63
64 $ourdb['postgres']['fullname']   = 'PostgreSQL';
65 $ourdb['postgres']['havedriver'] = 0;
66 $ourdb['postgres']['compile']    = 'pgsql';
67 $ourdb['postgres']['bgcolor']    = '#aaccff';
68 $ourdb['postgres']['rootuser']   = 'postgres';
69
70 /*** SQLITE DISABLED -- USE MEDIAWIKI 1.15 */
71 #$ourdb['sqlite']['fullname']      = 'SQLite';
72 #$ourdb['sqlite']['havedriver']    = 0;
73 #$ourdb['sqlite']['compile']       = 'pdo_sqlite';
74 #$ourdb['sqlite']['bgcolor']       = '#b1ebb1';
75 #$ourdb['sqlite']['rootuser']      = '';
76 /************************************/
77
78 $ourdb['mssql']['fullname']      = 'MSSQL';
79 $ourdb['mssql']['havedriver']    = 0;
80 $ourdb['mssql']['compile']       = 'mssql not ready'; # Change to 'mssql' after includes/DatabaseMssql.php added;
81 $ourdb['mssql']['bgcolor']       = '#ffc0cb';
82 $ourdb['mssql']['rootuser']      = 'administrator';
83
84 ?>
85 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
86 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
87 <head>
88         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
89         <meta name="robots" content="noindex,nofollow"/>
90         <title>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?> Installation</title>
91         <style type="text/css">
92
93                 @import "../skins/monobook/main.css";
94
95                 .env-check {
96                         font-size: 90%;
97                         margin: 1em 0 1em 2.5em;
98                 }
99
100                 .config-section {
101                         margin-top: 2em;
102                 }
103
104                 .config-section label.column {
105                         clear: left;
106                         font-weight: bold;
107                         width: 13em;
108                         float: left;
109                         text-align: right;
110                         padding-right: 1em;
111                         padding-top: .2em;
112                 }
113
114                 .config-input {
115                         clear: left;
116                         zoom: 100%; /* IE hack */
117                 }
118
119                 .config-section .config-desc {
120                         clear: left;
121                         margin: 0 0 2em 18em;
122                         padding-top: 1em;
123                         font-size: 85%;
124                 }
125
126                 .iput-text, .iput-password {
127                         width: 14em;
128                         margin-right: 1em;
129                 }
130
131                 .error {
132                         color: red;
133                         background-color: #fff;
134                         font-weight: bold;
135                         left: 1em;
136                         font-size: 100%;
137                 }
138
139                 .error-top {
140                         color: red;
141                         background-color: #FFF0F0;
142                         border: 2px solid red;
143                         font-size: 130%;
144                         font-weight: bold;
145                         padding: 1em 1.5em;
146                         margin: 2em 0 1em;
147                 }
148
149                 ul.plain {
150                         list-style-type: none;
151                         list-style-image: none;
152                         float: left;
153                         margin: 0;
154                         padding: 0;
155                 }
156
157                 .btn-install {
158                         font-weight: bold;
159                         font-size: 110%;
160                         padding: .2em .3em;
161                 }
162
163                 .license {
164                         font-size: 85%;
165                         padding-top: 3em;
166                 }
167                 
168                 span.success-message {
169                         font-weight: bold;
170                         font-size: 110%;
171                         color: green;
172                 }
173                 .success-box {
174                         font-size: 130%;
175                 }
176
177         </style>
178         <script type="text/javascript">
179         <!--
180         function hideall() {
181                 <?php foreach (array_keys($ourdb) as $db) {
182                 echo "\n                var i = document.getElementById('$db'); if (i) i.style.display='none';";
183                 }
184                 ?>
185
186         }
187         function toggleDBarea(id,defaultroot) {
188                 hideall();
189                 var dbarea = document.getElementById(id);
190                 if (dbarea) dbarea.style.display = (dbarea.style.display == 'none') ? 'block' : 'none';
191                 var db = document.getElementById('RootUser');
192                 if (defaultroot) {
193 <?php foreach (array_keys($ourdb) as $db) {
194                         echo "                  if (id == '$db') { db.value = '".$ourdb[$db]['rootuser']."';}\n";
195 }?>
196                 }
197         }
198         // -->
199         </script>
200 </head>
201
202 <body>
203 <div id="globalWrapper">
204 <div id="column-content">
205 <div id="content">
206 <div id="bodyContent">
207
208 <h1>MediaWiki <?php print htmlspecialchars( $wgVersion ) ?> Installation</h1>
209
210 <?php
211 $mainListOpened = false; # Is the main list (environement checking) opend ? Used by dieout
212
213 /* Check for existing configurations and bug out! */
214
215 if( file_exists( "../LocalSettings.php" ) ) {
216         $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
217         dieout( "<p><strong>Setup has completed, <a href='../$script'>your wiki</a> is configured.</strong></p>
218         <p>Please delete the /config directory for extra security.</p>" );
219 }
220
221 if( file_exists( "./LocalSettings.php" ) ) {
222         writeSuccessMessage();
223         dieout( '' );
224 }
225
226 if( !is_writable( "." ) ) {
227         dieout( "<h2>Can't write config file, aborting</h2>
228
229         <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
230         writable by the web server. Once configuration is done you'll move the created
231         <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
232         then remove the <tt>config</tt> subdirectory entirely.</p>
233
234         <p>To make the directory writable on a Unix/Linux system:</p>
235
236         <pre>
237         cd <i>/path/to/wiki</i>
238         chmod a+w config
239         </pre>
240         
241         <p>Afterwards retry to start the <a href=\"\">setup</a>.</p>" );
242 }
243
244
245 require_once( "$IP/install-utils.inc" );
246 require_once( "$IP/maintenance/updaters.inc" );
247
248 class ConfigData {
249         function getEncoded( $data ) {
250                 # removing latin1 support, no need...
251                 return $data;
252         }
253         function getSitename() { return $this->getEncoded( $this->Sitename ); }
254         function getSysopName() { return $this->getEncoded( $this->SysopName ); }
255         function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
256
257         function setSchema( $schema, $engine ) {
258                 $this->DBschema = $schema;
259                 if ( !preg_match( '/^\w*$/', $engine ) ){
260                         $engine = 'InnoDB';
261                 }
262                 switch ( $this->DBschema ) {
263                         case 'mysql5':
264                                 $this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=utf8";
265                                 $this->DBmysql5 = 'true';
266                                 break;
267                         case 'mysql5-binary':
268                                 $this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=binary";
269                                 $this->DBmysql5 = 'true';
270                                 break;
271                         default:
272                                 $this->DBTableOptions = "TYPE=$engine";
273                                 $this->DBmysql5 = 'false';
274                 }
275                 $this->DBengine = $engine;
276
277                 # Set the global for use during install
278                 global $wgDBTableOptions;
279                 $wgDBTableOptions = $this->DBTableOptions;
280         }
281 }
282
283 ?>
284
285 <ul>
286         <li>
287                 <b>Don't forget security updates!</b> Keep an eye on the
288                 <a href="http://lists.wikimedia.org/mailman/listinfo/mediawiki-announce">low-traffic
289                 release announcements mailing list</a>.
290         </li>
291 </ul>
292
293
294 <h2>Checking environment...</h2>
295 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
296 <ul class="env-check">
297 <?php
298 $mainListOpened = true;
299
300 $endl = "
301 ";
302 define( 'MW_NO_OUTPUT_BUFFER', 1 );
303 $conf = new ConfigData;
304
305 install_version_checks();
306 $self = 'Installer'; # Maintenance script name, to please Setup.php
307
308 print "<li>PHP " . htmlspecialchars( phpversion() ) . " installed</li>\n";
309
310 error_reporting( 0 );
311 $phpdatabases = array();
312 foreach (array_keys($ourdb) as $db) {
313         $compname = $ourdb[$db]['compile'];
314         if( extension_loaded( $compname ) || ( mw_have_dl() && dl( "{$compname}." . PHP_SHLIB_SUFFIX ) ) ) {
315                 array_push($phpdatabases, $db);
316                 $ourdb[$db]['havedriver'] = 1;
317         }
318 }
319 error_reporting( E_ALL );
320
321 if (!$phpdatabases) {
322         print "Could not find a suitable database driver!<ul>";
323         foreach (array_keys($ourdb) AS $db) {
324                 $comp = $ourdb[$db]['compile'];
325                 $full = $ourdb[$db]['fullname'];
326                 print "<li>For <b>$full</b>, compile PHP using <b>--with-$comp</b>, "
327                         ."or install the $comp.so module</li>\n";
328         }
329         echo '</ul>';
330         dieout( '' );
331 }
332
333 print "<li>Found database drivers for:";
334 $DefaultDBtype = '';
335 foreach (array_keys($ourdb) AS $db) {
336         if ($ourdb[$db]['havedriver']) {
337                 if ( $DefaultDBtype == '' ) {
338                         $DefaultDBtype = $db;
339                 }
340                 print "  ".$ourdb[$db]['fullname'];
341         }
342 }
343 print "</li>\n";
344
345 if( wfIniGetBool( "register_globals" ) ) {
346         ?>
347         <li>
348                 <div style="font-size:110%">
349                 <strong class="error">Warning:</strong>
350                 <strong>PHP's <tt><a href="http://php.net/register_globals">register_globals</a></tt> option is enabled. Disable it if you can.</strong>
351                 </div>
352                 MediaWiki will work, but your server is more exposed to PHP-based security vulnerabilities.
353         </li>
354         <?php
355 }
356
357 $fatal = false;
358
359 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
360         $fatal = true;
361         ?><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>
362         This option corrupts data input unpredictably; you cannot install or use
363         MediaWiki unless this option is disabled.</li>
364         <?php
365 }
366
367 if( wfIniGetBool( "magic_quotes_sybase" ) ) {
368         $fatal = true;
369         ?><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>
370         This option corrupts data input unpredictably; you cannot install or use
371         MediaWiki unless this option is disabled.</li>
372         <?php
373 }
374
375 if( wfIniGetBool( "mbstring.func_overload" ) ) {
376         $fatal = true;
377         ?><li class='error'><strong>Fatal: <a href='http://www.php.net/manual/en/ref.mbstring.php#mbstring.overload'>mbstring.func_overload</a> is active!</strong>
378         This option causes errors and may corrupt data unpredictably;
379         you cannot install or use MediaWiki unless this option is disabled.</li>
380         <?php
381 }
382
383 if( wfIniGetBool( "zend.ze1_compatibility_mode" ) ) {
384         $fatal = true;
385         ?><li class="error"><strong>Fatal: <a href="http://www.php.net/manual/en/ini.core.php">zend.ze1_compatibility_mode</a> is active!</strong>
386         This option causes horrible bugs with MediaWiki; you cannot install or use
387         MediaWiki unless this option is disabled.</li>
388         <?php
389 }
390
391
392 if( $fatal ) {
393         dieout( "Cannot install MediaWiki." );
394 }
395
396 if( wfIniGetBool( "safe_mode" ) ) {
397         $conf->safeMode = true;
398         ?>
399         <li><b class='error'>Warning:</b> <strong>PHP's
400         <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active.</strong>
401         You may have problems caused by this, particularly if using image uploads.
402         </li>
403         <?php
404 } else {
405         $conf->safeMode = false;
406 }
407
408 $sapi = htmlspecialchars( php_sapi_name() );
409 print "<li>PHP server API is $sapi; ";
410 $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
411 if( $wgUsePathInfo ) {
412  print "ok, using pretty URLs (<tt>$script/Page_Title</tt>)";
413 } else {
414         print "using ugly URLs (<tt>$script?title=Page_Title</tt>)";
415 }
416 print "</li>\n";
417
418 $conf->xml = function_exists( "utf8_encode" );
419 if( $conf->xml ) {
420         print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
421 } else {
422         dieout( "PHP's XML module is missing; the wiki requires functions in
423                 this module and won't work in this configuration.
424                 If you're running Mandrake, install the php-xml package." );
425 }
426
427 # Check for session support
428 if( !function_exists( 'session_name' ) )
429         dieout( "PHP's session module is missing. MediaWiki requires session support in order to function." );
430
431 # session.save_path doesn't *have* to be set, but if it is, and it's
432 # not valid/writable/etc. then it can cause problems
433 $sessionSavePath = mw_get_session_save_path();
434 $ssp = htmlspecialchars( $sessionSavePath );
435 # Warn the user if it's not set, but let them proceed
436 if( !$sessionSavePath ) {
437         print "<li><strong>Warning:</strong> A value for <tt>session.save_path</tt>
438         has not been set in PHP.ini. If the default value causes problems with
439         saving session data, set it to a valid path which is read/write/execute
440         for the user your web server is running under.</li>";
441 } elseif ( is_dir( $sessionSavePath ) && is_writable( $sessionSavePath ) ) {
442         # All good? Let the user know
443         print "<li>Session save path (<tt>{$ssp}</tt>) appears to be valid.</li>";
444 } else {
445         # Something not right? Warn the user, but let them proceed
446         print "<li><strong>Warning:</strong> Your <tt>session.save_path</tt> value (<tt>{$ssp}</tt>)
447                 appears to be invalid or is not writable. PHP needs to be able to save data to
448                 this location for correct session operation.</li>";
449 }
450
451 # Check for PCRE support
452 if( !function_exists( 'preg_match' ) )
453         dieout( "The PCRE support module appears to be missing. MediaWiki requires the
454         Perl-compatible regular expression functions." );
455
456 $memlimit = ini_get( "memory_limit" );
457 $conf->raiseMemory = false;
458 if( empty( $memlimit ) || $memlimit == -1 ) {
459         print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
460 } else {
461         print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". ";
462         $n = intval( $memlimit );
463         if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
464                 $n = intval( $m[1] * (1024*1024) );
465         }
466         if( $n < 20*1024*1024 ) {
467                 print "Attempting to raise limit to 20M... ";
468                 if( false === ini_set( "memory_limit", "20M" ) ) {
469                         print "failed.<br /><b>" . htmlspecialchars( $memlimit ) . " seems too low, installation may fail!</b>";
470                 } else {
471                         $conf->raiseMemory = true;
472                         print "ok.";
473                 }
474         }
475         print "</li>\n";
476 }
477
478 $conf->turck = function_exists( 'mmcache_get' );
479 if ( $conf->turck ) {
480         print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
481 }
482
483 $conf->xcache = function_exists( 'xcache_get' );
484 if( $conf->xcache )
485         print "<li><a href=\"http://trac.lighttpd.net/xcache/\">XCache</a> installed</li>\n";
486
487 $conf->apc = function_exists('apc_fetch');
488 if ($conf->apc ) {
489         print "<li><a href=\"http://www.php.net/apc\">APC</a> installed</li>\n";
490 }
491
492 $conf->eaccel = function_exists( 'eaccelerator_get' );
493 if ( $conf->eaccel ) {
494         $conf->turck = 'eaccelerator';
495         print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
496 }
497
498 $conf->dba = function_exists( 'dba_open' );
499
500 if( !( $conf->turck || $conf->eaccel || $conf->apc || $conf->xcache ) ) {
501         echo( '<li>Couldn\'t find <a href="http://turck-mmcache.sourceforge.net">Turck MMCache</a>,
502                 <a href="http://eaccelerator.sourceforge.net">eAccelerator</a>,
503                 <a href="http://www.php.net/apc">APC</a> or <a href="http://trac.lighttpd.net/xcache/">XCache</a>;
504                 cannot use these for object caching.</li>' );
505 }
506
507 $conf->diff3 = false;
508 $diff3locations = array_merge(
509         array(
510                 "/usr/bin",
511                 "/usr/local/bin",
512                 "/opt/csw/bin",
513                 "/usr/gnu/bin",
514                 "/usr/sfw/bin" ),
515         explode( PATH_SEPARATOR, getenv( "PATH" ) ) );
516 $diff3names = array( "gdiff3", "diff3", "diff3.exe" );
517
518 $diff3versioninfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
519 foreach ($diff3locations as $loc) {
520         $exe = locate_executable($loc, $diff3names, $diff3versioninfo);
521         if ($exe !== false) {
522                 $conf->diff3 = $exe;
523                 break;
524         }
525 }
526
527 if ($conf->diff3)
528         print "<li>Found GNU diff3: <tt>$conf->diff3</tt>.</li>";
529 else
530         print "<li>GNU diff3 not found.</li>";
531
532 $conf->ImageMagick = false;
533 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
534 foreach( $imcheck as $dir ) {
535         $im = "$dir/convert";
536         if( @file_exists( $im ) ) {
537                 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
538                 $conf->ImageMagick = $im;
539                 break;
540         }
541 }
542
543 $conf->HaveGD = function_exists( "imagejpeg" );
544 if( $conf->HaveGD ) {
545         print "<li>Found GD graphics library built-in";
546         if( !$conf->ImageMagick ) {
547                 print ", image thumbnailing will be enabled if you enable uploads";
548         }
549         print ".</li>\n";
550 } else {
551         if( !$conf->ImageMagick ) {
552                 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
553         }
554 }
555
556 $conf->IP = dirname( dirname( __FILE__ ) );
557 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
558
559
560 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
561 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
562 // to get the path to the current script... hopefully it's reliable. SIGH
563 $path = ($_SERVER["PHP_SELF"] === '')
564         ? $_SERVER["SCRIPT_NAME"]
565         : $_SERVER["PHP_SELF"];
566
567 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $path );
568 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
569
570
571
572 // We may be installing from *.php5 extension file, if so, print message
573 $conf->ScriptExtension = '.php';
574 if (defined('MW_INSTALL_PHP5_EXT')) {
575     $conf->ScriptExtension = '.php5';
576     print "<li>Installing MediaWiki with <tt>php5</tt> file extensions</li>\n";
577 } else {
578     print "<li>Installing MediaWiki with <tt>php</tt> file extensions</li>\n";
579 }
580
581
582 print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\n";
583         $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
584
585         $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
586         $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
587                 ? 'root@localhost'
588                 : $_SERVER["SERVER_ADMIN"];
589         $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
590         $conf->DBtype = importPost( "DBtype", $DefaultDBtype );
591         if ( !isset( $ourdb[$conf->DBtype] ) ) {
592                 $conf->DBtype = $DefaultDBtype;
593         }
594
595         $conf->DBserver = importPost( "DBserver", "localhost" );
596         $conf->DBname = importPost( "DBname", "wikidb" );
597         $conf->DBuser = importPost( "DBuser", "wikiuser" );
598         $conf->DBpassword = importPost( "DBpassword" );
599         $conf->DBpassword2 = importPost( "DBpassword2" );
600         $conf->SysopName = importPost( "SysopName", "WikiSysop" );
601         $conf->SysopPass = importPost( "SysopPass" );
602         $conf->SysopPass2 = importPost( "SysopPass2" );
603         $conf->RootUser = importPost( "RootUser", "root" );
604         $conf->RootPW = importPost( "RootPW", "" );
605         $useRoot = importCheck( 'useroot', false );
606         $conf->LanguageCode = importPost( "LanguageCode", "en" );
607         ## MySQL specific:
608         $conf->DBprefix     = importPost( "DBprefix" );
609         $conf->setSchema( 
610                 importPost( "DBschema", "mysql5-binary" ), 
611                 importPost( "DBengine", "InnoDB" ) );
612
613         ## Postgres specific:
614         $conf->DBport      = importPost( "DBport",      "5432" );
615         $conf->DBmwschema  = importPost( "DBmwschema",  "mediawiki" );
616         $conf->DBts2schema = importPost( "DBts2schema", "public" );
617         
618         ## SQLite specific
619         $conf->SQLiteDataDir = importPost( "SQLiteDataDir", "" );
620         
621         ## MSSQL specific
622         // We need a second field so it doesn't overwrite the MySQL one
623         $conf->DBprefix2 = importPost( "DBprefix2" );
624
625         $conf->ShellLocale = getShellLocale( $conf->LanguageCode );
626
627 /* Check for validity */
628 $errs = array();
629
630 if( preg_match( '/^$|^mediawiki$|#/i', $conf->Sitename ) ) {
631         $errs["Sitename"] = "Must not be blank or \"MediaWiki\" and may not contain \"#\"";
632 }
633 if( $conf->DBuser == "" ) {
634         $errs["DBuser"] = "Must not be blank";
635 }
636 if( ($conf->DBtype == 'mysql') && (strlen($conf->DBuser) > 16) ) {
637         $errs["DBuser"] = "Username too long";
638 }
639 if( $conf->DBpassword == "" && $conf->DBtype != "postgres" ) {
640         $errs["DBpassword"] = "Must not be blank";
641 }
642 if( $conf->DBpassword != $conf->DBpassword2 ) {
643         $errs["DBpassword2"] = "Passwords don't match!";
644 }
645 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
646         $errs["DBprefix"] = "Invalid table prefix";
647 }
648
649 error_reporting( E_ALL );
650
651 /**
652  * Initialise $wgLang and $wgContLang to something so we can
653  * call case-folding methods. Per Brion, this is English for
654  * now, although we could be clever and initialise to the
655  * user-selected language.
656  */
657 $wgContLang = Language::factory( 'en' );
658 $wgLang = $wgContLang;
659
660 /**
661  * We're messing about with users, so we need a stub
662  * authentication plugin...
663  */
664 $wgAuth = new AuthPlugin();
665
666 /**
667  * Validate the initial administrator account; username,
668  * password checks, etc.
669  */
670 if( $conf->SysopName ) {
671         # Check that the user can be created
672         $u = User::newFromName( $conf->SysopName );
673         if( is_a($u, 'User') ) { // please do not use instanceof, it breaks PHP4
674                 # Various password checks
675                 if( $conf->SysopPass != '' ) {
676                         if( $conf->SysopPass == $conf->SysopPass2 ) {
677                                 if( !$u->isValidPassword( $conf->SysopPass ) ) {
678                                         $errs['SysopPass'] = "Bad password";
679                                 }
680                         } else {
681                                 $errs['SysopPass2'] = "Passwords don't match";
682                         }
683                 } else {
684                         $errs['SysopPass'] = "Cannot be blank";
685                 }
686                 unset( $u );
687         } else {
688                 $errs['SysopName'] = "Bad username";
689         }
690 }
691
692 $conf->License = importRequest( "License", "none" );
693 if( $conf->License == "gfdl1_2" ) {
694         $conf->RightsUrl = "http://www.gnu.org/licenses/old-licenses/fdl-1.2.txt";
695         $conf->RightsText = "GNU Free Documentation License 1.2";
696         $conf->RightsCode = "gfdl1_2";
697         $conf->RightsIcon = '${wgScriptPath}/skins/common/images/gnu-fdl.png';
698 } elseif( $conf->License == "gfdl1_3" ) {
699         $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
700         $conf->RightsText = "GNU Free Documentation License 1.3";
701         $conf->RightsCode = "gfdl1_3";
702         $conf->RightsIcon = '${wgScriptPath}/skins/common/images/gnu-fdl.png';
703 } elseif( $conf->License == "none" ) {
704         $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
705 } elseif( $conf->License == "pd" ) {
706         $conf->RightsUrl = "http://creativecommons.org/licenses/publicdomain/";
707         $conf->RightsText = "Public Domain";
708         $conf->RightsCode = "pd";
709         $conf->RightsIcon = '${wgScriptPath}/skins/common/images/public-domain.png';
710 } else {
711         $conf->RightsUrl = importRequest( "RightsUrl", "" );
712         $conf->RightsText = importRequest( "RightsText", "" );
713         $conf->RightsCode = importRequest( "RightsCode", "" );
714         $conf->RightsIcon = importRequest( "RightsIcon", "" );
715 }
716
717 $conf->Shm = importRequest( "Shm", "none" );
718 $conf->MCServers = importRequest( "MCServers" );
719
720 /* Test memcached servers */
721
722 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
723         $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
724         foreach ( $conf->MCServerArray as $server ) {
725                 $error = testMemcachedServer( $server );
726                 if ( $error ) {
727                         $errs["MCServers"] = $error;
728                         break;
729                 }
730         }
731 } else if ( $conf->Shm == 'memcached' ) {
732         $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
733 }
734
735 /* default values for installation */
736 $conf->Email     = importRequest("Email", "email_enabled");
737 $conf->Emailuser = importRequest("Emailuser", "emailuser_enabled");
738 $conf->Enotif    = importRequest("Enotif", "enotif_allpages");
739 $conf->Eauthent  = importRequest("Eauthent", "eauthent_enabled");
740
741 if( $conf->posted && ( 0 == count( $errs ) ) ) {
742         do { /* So we can 'continue' to end prematurely */
743                 $conf->Root = ($conf->RootPW != "");
744
745                 /* Load up the settings and get installin' */
746                 $local = writeLocalSettings( $conf );
747                 echo "<li style=\"list-style: none\">\n";
748                 echo "<p><b>Generating configuration file...</b></p>\n";
749                 echo "</li>\n";         
750
751                 $wgCommandLineMode = false;
752                 chdir( ".." );
753                 $ok = eval( $local );
754                 if( $ok === false ) {
755                         dieout( "<p>Errors in generated configuration; " .
756                                 "most likely due to a bug in the installer... " .
757                                 "Config file was: </p>" .
758                                 "<pre>" .
759                                 htmlspecialchars( $local ) .
760                                 "</pre>" );
761                 }
762                 $conf->DBtypename = '';
763                 foreach (array_keys($ourdb) as $db) {
764                         if ($conf->DBtype === $db)
765                                 $conf->DBtypename = $ourdb[$db]['fullname'];
766                 }
767                 if ( ! strlen($conf->DBtype)) {
768                         $errs["DBpicktype"] = "Please choose a database type";
769                         continue;
770                 }
771
772                 if (! $conf->DBtypename) {
773                         $errs["DBtype"] = "Unknown database type '$conf->DBtype'";
774                         continue;
775                 }
776                 print "<li>Database type: " . htmlspecialchars( $conf->DBtypename ) . "</li>\n";
777                 $dbclass = 'Database'.ucfirst($conf->DBtype);
778                 $wgDBtype = $conf->DBtype;
779                 $wgDBadminuser = "root";
780                 $wgDBadminpassword = $conf->RootPW;
781
782                 ## Mysql specific:
783                 $wgDBprefix = $conf->DBprefix;
784
785                 ## Postgres specific:
786                 $wgDBport      = $conf->DBport;
787                 $wgDBmwschema  = $conf->DBmwschema;
788                 $wgDBts2schema = $conf->DBts2schema;
789
790                 if( $conf->DBprefix2 != '' ) {
791                         // For MSSQL
792                         $wgDBprefix = $conf->DBprefix2;
793                 }
794
795                 $wgCommandLineMode = true;
796                 if (! defined ( 'STDERR' ) )
797                         define( 'STDERR', fopen("php://stderr", "wb"));
798                 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
799                 require_once( "$IP/includes/Setup.php" );
800                 chdir( "config" );
801
802                 $wgTitle = Title::newFromText( "Installation script" );
803                 error_reporting( E_ALL );
804                 print "<li>Loading class: " . htmlspecialchars( $dbclass ) . "</li>\n";
805                 $dbc = new $dbclass;
806
807                 if( $conf->DBtype == 'mysql' ) {
808                         $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
809                         if( $mysqlOldClient ) {
810                                 print "<li><b>PHP is linked with old MySQL client libraries. If you are
811                                         using a MySQL 4.1 server and have problems connecting to the database,
812                                         see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
813                                         >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
814                         }
815                         $ok = true; # Let's be optimistic
816
817                         # Decide if we're going to use the superuser or the regular database user
818                         $conf->Root = $useRoot;
819                         if( $conf->Root ) {
820                                 $db_user = $conf->RootUser;
821                                 $db_pass = $conf->RootPW;
822                         } else {
823                                 $db_user = $wgDBuser;
824                                 $db_pass = $wgDBpassword;
825                         }
826
827                         # Attempt to connect
828                         echo( "<li>Attempting to connect to database server as " . htmlspecialchars( $db_user ) . "..." );
829                         $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
830
831                         # Check the connection and respond to errors
832                         if( $wgDatabase->isOpen() ) {
833                                 # Seems OK
834                                 $ok = true;
835                                 $wgDBadminuser = $db_user;
836                                 $wgDBadminpassword = $db_pass;
837                                 echo( "success.</li>\n" );
838                                 $wgDatabase->ignoreErrors( true );
839                                 $myver = $wgDatabase->getServerVersion();
840                         } else {
841                                 # There were errors, report them and back out
842                                 $ok = false;
843                                 $errno = mysql_errno();
844                                 $errtx = htmlspecialchars( mysql_error() );
845                                 switch( $errno ) {
846                                         case 1045:
847                                         case 2000:
848                                                 echo( "failed due to authentication errors. Check passwords.</li>" );
849                                                 if( $conf->Root ) {
850                                                         # The superuser details are wrong
851                                                         $errs["RootUser"] = "Check username";
852                                                         $errs["RootPW"] = "and password";
853                                                 } else {
854                                                         # The regular user details are wrong
855                                                         $errs["DBuser"] = "Check username";
856                                                         $errs["DBpassword"] = "and password";
857                                                 }
858                                                 break;
859                                         case 2002:
860                                         case 2003:
861                                         default:
862                                                 # General connection problem
863                                                 echo( htmlspecialchars( "failed with error [$errno] $errtx." ) . "</li>\n" );
864                                                 $errs["DBserver"] = "Connection failed";
865                                                 break;
866                                 } # switch
867                         } #conn. att.
868
869                         if( !$ok ) { continue; }
870
871                 } else { # not mysql
872                         error_reporting( E_ALL );
873                         $wgSuperUser = '';
874                         ## Possible connect as a superuser
875                         if( $useRoot && $conf->DBtype != 'sqlite' ) {
876                                 $wgDBsuperuser = $conf->RootUser;
877                                 echo( "<li>Attempting to connect to database \"postgres\" as superuser \"" . 
878                                         htmlspecialchars( $wgDBsuperuser ) . "\"..." );
879                                 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
880                                 if (!$wgDatabase->isOpen()) {
881                                         print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
882                                         $errs["DBserver"] = "Could not connect to database as superuser";
883                                         $errs["RootUser"] = "Check username";
884                                         $errs["RootPW"] = "and password";
885                                         continue;
886                                 }
887                                 $wgDatabase->initial_setup($conf->RootPW, 'postgres');
888                         }
889                         echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) . 
890                                 "\" as \"" . htmlspecialchars( $wgDBuser ) . "\"..." );
891                         $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
892                         if (!$wgDatabase->isOpen()) {
893                                 print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
894                         } else {
895                                 $myver = $wgDatabase->getServerVersion();
896                         }
897                         if (is_callable(array($wgDatabase, 'initial_setup'))) $wgDatabase->initial_setup('', $wgDBname);
898                 } 
899
900                 if ( !$wgDatabase->isOpen() ) {
901                         $errs["DBserver"] = "Couldn't connect to database";
902                         continue;
903                 }
904
905                 print "<li>Connected to " . htmlspecialchars( "{$conf->DBtype} $myver" );
906                 if ($conf->DBtype == 'mysql') {
907                         if( version_compare( $myver, "4.0.14" ) < 0 ) {
908                                 print "</li>\n";
909                                 dieout( "-- mysql 4.0.14 or later required. Aborting." );
910                         }
911                         $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
912                         if( $mysqlNewAuth && $mysqlOldClient ) {
913                                 print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
914                                         to old client libraries; if you have trouble with authentication, see
915                                         <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
916                                         >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
917                         }
918                         if( $wgDBmysql5 ) {
919                                 if( $mysqlNewAuth ) {
920                                         print "; enabling MySQL 4.1/5.0 charset mode";
921                                 } else {
922                                         print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
923                                                 but older version detected; will likely fail.</b>";
924                                 }
925                         }
926                         print "</li>\n";
927
928                         @$sel = $wgDatabase->selectDB( $wgDBname );
929                         if( $sel ) {
930                                 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
931                         } else {
932                                 $err = mysql_errno();
933                                 $databaseSafe = htmlspecialchars( $wgDBname );
934                                 if( $err == 1102 /* Invalid database name */ ) {
935                                         print "<ul><li><strong>{$databaseSafe}</strong> is not a valid database name.</li></ul>";
936                                         continue;
937                                 } elseif( $err != 1049 /* Database doesn't exist */ ) {
938                                         print "<ul><li>Error selecting database <strong>{$databaseSafe}</strong>: {$err} ";
939                                         print htmlspecialchars( mysql_error() ) . "</li></ul>";
940                                         continue;
941                                 }
942                                 print "<li>Attempting to create database...</li>";
943                                 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
944                                 if( !$res ) {
945                                         print "<li>Couldn't create database <tt>" .
946                                                 htmlspecialchars( $wgDBname ) .
947                                                 "</tt>; try with root access or check your username/pass.</li>\n";
948                                         $errs["RootPW"] = "&lt;- Enter";
949                                         continue;
950                                 }
951                                 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
952                         }
953                         $wgDatabase->selectDB( $wgDBname );
954                 }
955                 else if ($conf->DBtype == 'postgres') {
956                         if( version_compare( $myver, "8.0" ) < 0 ) {
957                                 dieout( "<b>Postgres 8.0 or later is required</b>. Aborting." );
958                         }
959                 }
960
961                 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
962                         print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
963
964                         if ( $conf->DBtype == 'mysql') {
965                                 # Determine existing default character set
966                                 if ( $wgDatabase->tableExists( "revision" ) ) {
967                                         $revision = $wgDatabase->escapeLike( $conf->DBprefix . 'revision' );
968                                         $res = $wgDatabase->query( "SHOW TABLE STATUS LIKE '$revision'" );
969                                         $row = $wgDatabase->fetchObject( $res );
970                                         if ( !$row ) {
971                                                 echo "<li>SHOW TABLE STATUS query failed!</li>\n";
972                                                 $existingSchema = false;
973                                                 $existingEngine = false;
974                                         } else {
975                                                 if ( preg_match( '/^latin1/', $row->Collation ) ) {
976                                                         $existingSchema = 'mysql4';
977                                                 } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
978                                                         $existingSchema = 'mysql5';
979                                                 } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
980                                                         $existingSchema = 'mysql5-binary';
981                                                 } else {
982                                                         $existingSchema = false;
983                                                         echo "<li><strong>Warning:</strong> Unrecognised existing collation</li>\n";
984                                                 }
985                                                 if ( isset( $row->Engine ) ) {
986                                                         $existingEngine = $row->Engine;
987                                                 } else {
988                                                         $existingEngine = $row->Type;
989                                                 }
990                                         }
991                                         if ( $existingSchema && $existingSchema != $conf->DBschema ) {
992                                                 $encExisting = htmlspecialchars( $existingSchema );
993                                                 $encRequested = htmlspecialchars( $conf->DBschema );
994                                                 print "<li><strong>Warning:</strong> you requested the $encRequested schema, " .
995                                                         "but the existing database has the $encExisting schema. This upgrade script ". 
996                                                         "can't convert it, so it will remain $encExisting.</li>\n";
997                                                 $conf->setSchema( $existingSchema, $conf->DBengine );
998                                         }
999                                         if ( $existingEngine && $existingEngine != $conf->DBengine ) {
1000                                                 $encExisting = htmlspecialchars( $existingEngine );
1001                                                 $encRequested = htmlspecialchars( $conf->DBengine );
1002                                                 print "<li><strong>Warning:</strong> you requested the $encRequested storage " .
1003                                                         "engine, but the existing database uses the $encExisting engine. This upgrade " .
1004                                                         "script can't convert it, so it will remain $encExisting.</li>\n";
1005                                                 $conf->setSchema( $conf->DBschema, $existingEngine );
1006                                         }
1007                                 }
1008
1009                                 # Create user if required
1010                                 if ( $conf->Root ) {
1011                                         $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
1012                                         if ( $conn->isOpen() ) {
1013                                                 print "<li>DB user account ok</li>\n";
1014                                                 $conn->close();
1015                                         } else {
1016                                                 print "<li>Granting user permissions...";
1017                                                 if( $mysqlOldClient && $mysqlNewAuth ) {
1018                                                         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>";
1019                                                 }
1020                                                 print "</li>\n";
1021                                                 dbsource( "../maintenance/users.sql", $wgDatabase );
1022                                         }
1023                                 }
1024                         }
1025                         print "</ul><pre>\n";
1026                         chdir( ".." );
1027                         flush();
1028                         do_all_updates();
1029                         chdir( "config" );
1030                         print "</pre>\n";
1031                         print "<ul><li>Finished update checks.</li>\n";
1032                 } else {
1033                         # Determine available storage engines if possible
1034                         if ( $conf->DBtype == 'mysql' && version_compare( $myver, "4.1.2", "ge" ) ) {
1035                                 $res = $wgDatabase->query( 'SHOW ENGINES' );
1036                                 $found = false;
1037                                 while ( $row = $wgDatabase->fetchObject( $res ) ) {
1038                                         if ( $row->Engine == $conf->DBengine ) {
1039                                                 $found = true;
1040                                                 break;
1041                                         }
1042                                 }
1043                                 $wgDatabase->freeResult( $res );
1044                                 if ( !$found && $conf->DBengine != 'MyISAM' ) {
1045                                         echo "<li><strong>Warning:</strong> " . htmlspecialchars( $conf->DBengine ) . 
1046                                                 " storage engine not available, " .
1047                                                 "using MyISAM instead</li>\n";
1048                                         $conf->setSchema( $conf->DBschema, 'MyISAM' );
1049                                 }
1050                         }
1051
1052                         # FIXME: Check for errors
1053                         print "<li>Creating tables...";
1054                         if ($conf->DBtype == 'mysql') {
1055                                 dbsource( "../maintenance/tables.sql", $wgDatabase );
1056                                 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
1057                         } elseif (is_callable(array($wgDatabase, 'setup_database'))) {
1058                                 $wgDatabase->setup_database();
1059                         }
1060                         else {
1061                                 $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'";
1062                                 continue;
1063                         }
1064
1065                         print " done.</li>\n";
1066
1067                         print "<li>Initializing statistics...</li>\n";
1068                         $wgDatabase->insert( 'site_stats',
1069                                 array ( 'ss_row_id'        => 1,
1070                                                 'ss_total_views'   => 0,
1071                                                 'ss_total_edits'   => 1, # Main page first edit
1072                                                 'ss_good_articles' => 0, # Main page is not a good article - no internal link
1073                                                 'ss_total_pages'   => 1, # Main page
1074                                                 'ss_users'         => $conf->SysopName ? 1 : 0, # Sysop account, if created
1075                                                 'ss_admins'        => $conf->SysopName ? 1 : 0, # Sysop account, if created
1076                                                 'ss_images'        => 0 ) );
1077
1078                         # Set up the "regular user" account *if we can, and if we need to*
1079                         if( $conf->Root and $conf->DBtype == 'mysql') {
1080                                 # See if we need to
1081                                 $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
1082                                 if( $wgDatabase2->isOpen() ) {
1083                                         # Nope, just close the test connection and continue
1084                                         $wgDatabase2->close();
1085                                         echo( "<li>User " . htmlspecialchars( $wgDBuser ) . " exists. Skipping grants.</li>\n" );
1086                                 } else {
1087                                         # Yes, so run the grants
1088                                         echo( "<li>" . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) );
1089                                         dbsource( "../maintenance/users.sql", $wgDatabase );
1090                                         echo( "success.</li>\n" );
1091                                 }
1092                         }
1093
1094                         if( $conf->SysopName ) {
1095                                 $u = User::newFromName( $conf->getSysopName() );
1096                                 if ( !$u ) {
1097                                         print "<li><strong class=\"error\">Warning:</strong> Skipped sysop account creation - invalid username!</li>\n";
1098                                 }
1099                                 else if ( 0 == $u->idForName() ) {
1100                                         $u->addToDatabase();
1101                                         $u->setPassword( $conf->getSysopPass() );
1102                                         $u->saveSettings();
1103
1104                                         $u->addGroup( "sysop" );
1105                                         $u->addGroup( "bureaucrat" );
1106
1107                                         print "<li>Created sysop account <tt>" .
1108                                                 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
1109                                 } else {
1110                                         print "<li>Could not create user - already exists!</li>\n";
1111                                 }
1112                         } else {
1113                                 print "<li>Skipped sysop account creation, no name given.</li>\n";
1114                         }
1115
1116                         $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
1117                         $article = new Article( $titleobj );
1118                         $newid = $article->insertOn( $wgDatabase );
1119                         $revision = new Revision( array(
1120                                 'page'      => $newid,
1121                                 'text'      => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsgNoTrans( 'mainpagedocfooter' ),
1122                                 'comment'   => '',
1123                                 'user'      => 0,
1124                                 'user_text' => 'MediaWiki default',
1125                                 ) );
1126                         $revid = $revision->insertOn( $wgDatabase );
1127                         $article->updateRevisionOn( $wgDatabase, $revision );
1128                 }
1129
1130                 /* Write out the config file now that all is well */
1131                 print "<li style=\"list-style: none\">\n";
1132                 print "<p>Creating LocalSettings.php...</p>\n\n";
1133                 $localSettings = "<" . "?php$endl$local";
1134                 // Fix up a common line-ending problem (due to CVS on Windows)
1135                 $localSettings = str_replace( "\r\n", "\n", $localSettings );
1136                 $f = fopen( "LocalSettings.php", 'xt' );
1137
1138                 if( $f == false ) {
1139                         print( "</li>\n" );
1140                         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" .
1141                         "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
1142                         "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
1143                 }
1144                 if(fwrite( $f, $localSettings ) ) {
1145                         fclose( $f );
1146                         print "<hr/>\n";
1147                         writeSuccessMessage();
1148                         print "</li>\n";
1149                 } else {
1150                         fclose( $f );
1151                         dieout( "<p class='error'>An error occured while writing the config/LocalSettings.php file. Check user rights and disk space then try again.</p></li>\n" );
1152                 }
1153
1154         } while( false );
1155 }
1156
1157 print "</ul>\n";
1158 $mainListOpened = false;
1159
1160 if( count( $errs ) ) {
1161         /* Display options form */
1162
1163         if( $conf->posted ) {
1164                 echo "<p class='error-top'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
1165         }
1166 ?>
1167
1168 <form action="<?php echo defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php'; ?>" name="config" method="post">
1169
1170 <h2>Site config</h2>
1171
1172 <div class="config-section">
1173         <div class="config-input">
1174                 <?php aField( $conf, "Sitename", "Wiki name:" ); ?>
1175         </div>
1176         <p class="config-desc">
1177                 Preferably a short word without punctuation, i.e. "Wikipedia".<br />
1178                 Will appear as the namespace name for "meta" pages, and throughout the interface.
1179         </p>
1180         <div class="config-input"><?php aField( $conf, "EmergencyContact", "Contact e-mail:" ); ?></div>
1181         <p class="config-desc">
1182                 Displayed to users in some error messages, used as the return address for password reminders, and used as the default sender address of e-mail notifications.
1183         </p>
1184
1185         <div class="config-input">
1186                 <label class='column' for="LanguageCode">Language:</label>
1187                 <select id="LanguageCode" name="LanguageCode"><?php
1188                         $list = getLanguageList();
1189                         foreach( $list as $code => $name ) {
1190                                 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
1191                                 $encCode = htmlspecialchars( $code );
1192                                 $encName = htmlspecialchars( $name );
1193                                 echo "\n\t\t<option value=\"$encCode\" $sel>$encName</option>";
1194                         }
1195                         echo "\n";
1196                 ?>
1197                 </select>
1198         </div>
1199         <p class="config-desc">
1200                 Select the language for your wiki's interface. Some localizations aren't fully complete. Unicode (UTF-8) is used for all localizations.
1201         </p>
1202
1203         <div class="config-input">
1204                 <label class='column'>Copyright/license:</label>
1205
1206                 <ul class="plain">
1207                 <li><?php aField( $conf, "License", "No license metadata", "radio", "none" ); ?></li>
1208                 <li><?php aField( $conf, "License", "Public Domain", "radio", "pd" ); ?></li>
1209                 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl1_2" ); ?></li>
1210                 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.3", "radio", "gfdl1_3" ); ?></li>
1211                 <li><?php
1212                         aField( $conf, "License", "A Creative Commons license - ", "radio", "cc" );
1213                         $partner = "MediaWiki";
1214    $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
1215                         $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/$script?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
1216                         $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
1217                         $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
1218                         print "<a href=\"$ccApp\" target='_blank'>choose</a>";
1219                         if( $conf->License == "cc" ) { ?>
1220                         <ul>
1221                         <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='(Creative Commons icon)' />", "hidden" ); ?></li>
1222                         <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
1223                         <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
1224                         <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
1225                         </ul>
1226                         <?php } ?>
1227                         </li>
1228                 </ul>
1229         </div>
1230         <p class="config-desc">
1231                 A notice, icon, and machine-readable copyright metadata will be displayed for the license you pick.
1232         </p>
1233
1234
1235         <div class="config-input">
1236                 <?php aField( $conf, "SysopName", "Admin username:" ) ?>
1237         </div>
1238         <div class="config-input">
1239                 <?php aField( $conf, "SysopPass", "Password:", "password" ) ?>
1240         </div>
1241         <div class="config-input">
1242                 <?php aField( $conf, "SysopPass2", "Password confirm:", "password" ) ?>
1243         </div>
1244         <p class="config-desc">
1245                 An admin can lock/delete pages, block users from editing, and do other maintenance tasks.<br />
1246                 A new account will be added only when creating a new wiki database.
1247                 <br /><br />
1248                 The password cannot be the same as the username.
1249         </p>
1250
1251         <div class="config-input">
1252                 <label class='column'>Object caching:</label>
1253
1254                 <ul class="plain">
1255                 <li><?php aField( $conf, "Shm", "No caching", "radio", "none" ); ?></li>
1256                 <?php
1257                         if ( $conf->turck ) {
1258                                 echo "<li>";
1259                                 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
1260                                 echo "</li>\n";
1261                         }
1262                         if( $conf->xcache ) {
1263                                 echo "<li>";
1264                                 aField( $conf, 'Shm', 'XCache', 'radio', 'xcache' );
1265                                 echo "</li>\n";
1266                         }
1267                         if ( $conf->apc ) {
1268                                 echo "<li>";
1269                                 aField( $conf, "Shm", "APC", "radio", "apc" );
1270                                 echo "</li>\n";
1271                         }
1272                         if ( $conf->eaccel ) {
1273                                 echo "<li>";
1274                                 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
1275                                 echo "</li>\n";
1276                         }
1277                         if ( $conf->dba ) {
1278                                 echo "<li>";
1279                                 aField( $conf, "Shm", "DBA (not recommended)", "radio", "dba" );
1280                                 echo "</li>";
1281                         }
1282                 ?>
1283                 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
1284                 </ul>
1285                 <div style="clear:left"><?php aField( $conf, "MCServers", "Memcached servers:", "text" ) ?></div>
1286         </div>
1287         <p class="config-desc">
1288                 An object caching system such as memcached will provide a significant performance boost,
1289                 but needs to be installed. Provide the server addresses and ports in a comma-separated list.
1290                 <br /><br />
1291                 MediaWiki can also detect and support eAccelerator, Turck MMCache, APC, and XCache, but
1292                 these should not be used if the wiki will be running on multiple application servers.
1293                 <br/><br/>
1294                 DBA (Berkeley-style DB) is generally slower than using no cache at all, and is only 
1295                 recommended for testing.
1296         </p>
1297 </div>
1298
1299 <h2>E-mail, e-mail notification and authentication setup</h2>
1300
1301 <div class="config-section">
1302         <div class="config-input">
1303                 <label class='column'>E-mail features (global):</label>
1304                 <ul class="plain">
1305                 <li><?php aField( $conf, "Email", "Enabled", "radio", "email_enabled" ); ?></li>
1306                 <li><?php aField( $conf, "Email", "Disabled", "radio", "email_disabled" ); ?></li>
1307                 </ul>
1308         </div>
1309         <p class="config-desc">
1310                 Use this to disable all e-mail functions (password reminders, user-to-user e-mail, and e-mail notifications)
1311                 if sending mail doesn't work on your server.
1312         </p>
1313
1314         <div class="config-input">
1315                 <label class='column'>User-to-user e-mail:</label>
1316                 <ul class="plain">
1317                 <li><?php aField( $conf, "Emailuser", "Enabled", "radio", "emailuser_enabled" ); ?></li>
1318                 <li><?php aField( $conf, "Emailuser", "Disabled", "radio", "emailuser_disabled" ); ?></li>
1319                 </ul>
1320         </div>
1321         <p class="config-desc">
1322                 The user-to-user e-mail feature (Special:Emailuser) lets the wiki act as a relay to allow users to exchange e-mail without publicly advertising their e-mail address.
1323         </p>
1324         <div class="config-input">
1325                 <label class='column'>E-mail notification about changes:</label>
1326                 <ul class="plain">
1327                 <li><?php aField( $conf, "Enotif", "Disabled", "radio", "enotif_disabled" ); ?></li>
1328                 <li><?php aField( $conf, "Enotif", "Enabled for changes to user discussion pages only", "radio", "enotif_usertalk" ); ?></li>
1329                 <li><?php aField( $conf, "Enotif", "Enabled for changes to user discussion pages, and to pages on watchlists (not recommended for large wikis)", "radio", "enotif_allpages" ); ?></li>
1330                 </ul>
1331         </div>
1332         <div class="config-desc">
1333                 <p>
1334                 For this feature to work, an e-mail address must be present for the user account, and the notification
1335                 options in the user's preferences must be enabled. Also note the 
1336                 authentication option below. When testing the feature, keep in mind that your own changes will never trigger notifications to be sent to yourself.</p>
1337
1338                 <p>There are additional options for fine tuning in /includes/DefaultSettings.php; copy these to your LocalSettings.php and edit them there to change them.</p>
1339         </div>
1340
1341         <div class="config-input">
1342                 <label class='column'>E-mail address authentication:</label>
1343                 <ul class="plain">
1344                 <li><?php aField( $conf, "Eauthent", "Disabled", "radio", "eauthent_disabled" ); ?></li>
1345                 <li><?php aField( $conf, "Eauthent", "Enabled", "radio", "eauthent_enabled" ); ?></li>
1346                 </ul>
1347         </div>
1348         <div class="config-desc">
1349                 <p>If this option is enabled, users have to confirm their e-mail address using a magic link sent to them whenever they set or change it, and only authenticated e-mail addresses can receive mails from other users and/or
1350                 change notification mails. Setting this option is <b>recommended</b> for public wikis because of potential abuse of the e-mail features above.</p>
1351         </div>
1352
1353 </div>
1354
1355 <h2>Database config</h2>
1356
1357 <div class="config-section">
1358 <div class="config-input">
1359         <label class='column'>Database type:</label>
1360 <?php 
1361         if (isset($errs['DBpicktype'])) {
1362                 print "\t<span class='error'>" . htmlspecialchars( $errs['DBpicktype'] ) . "</span>\n";
1363         }
1364 ?>
1365         <ul class='plain'><?php 
1366                 database_picker($conf); 
1367         ?></ul>
1368         </div>
1369
1370         <div class="config-input" style="clear:left">
1371         <?php aField( $conf, "DBserver", "Database host:" ); ?>
1372         </div>
1373         <p class="config-desc">
1374                 If your database server isn't on your web server, enter the name or IP address here.
1375         </p>
1376
1377         <div class="config-input"><?php aField( $conf, "DBname", "Database name:" ); ?></div>
1378         <div class="config-input"><?php aField( $conf, "DBuser", "DB username:" ); ?></div>
1379         <div class="config-input"><?php aField( $conf, "DBpassword", "DB password:", "password" ); ?></div>
1380         <div class="config-input"><?php aField( $conf, "DBpassword2", "DB password confirm:", "password" ); ?></div>
1381         <p class="config-desc">
1382                 If you only have a single user account and database available,
1383                 enter those here. If you have database root access (see below)
1384                 you can specify new accounts/databases to be created. This account 
1385                 will not be created if it pre-exists. If this is the case, ensure that it
1386                 has SELECT, INSERT, UPDATE, and DELETE permissions on the MediaWiki database.
1387         </p>
1388
1389         <div class="config-input">
1390                 <label class="column">Superuser account:</label>
1391                 <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?> />
1392                 &nbsp;<label for="useroot">Use superuser account</label>
1393         </div>
1394         <div class="config-input"><?php aField( $conf, "RootUser", "Superuser name:", "text" ); ?></div>
1395         <div class="config-input"><?php aField( $conf, "RootPW", "Superuser password:", "password" ); ?></div>
1396
1397         <p class="config-desc">
1398                 If the database user specified above does not exist, or does not have access to create
1399                 the database (if needed) or tables within it, please check the box and provide details
1400                 of a superuser account, such as <strong>root</strong>, which does.
1401         </p>
1402
1403         <?php database_switcher('mysql'); ?>
1404         <div class="config-input"><?php aField( $conf, "DBprefix", "Database table prefix:" ); ?></div>
1405         <div class="config-desc">
1406                 <p>If you need to share one database between multiple wikis, or
1407                 between MediaWiki and another web application, you may choose to
1408                 add a prefix to all the table names to avoid conflicts.</p>
1409
1410                 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
1411         </div>
1412
1413         <div class="config-input"><label class="column">Storage Engine</label>
1414                 <div>Select one:</div>
1415                 <ul class="plain">
1416                 <li><?php aField( $conf, "DBengine", "InnoDB", "radio", "InnoDB" ); ?></li>
1417                 <li><?php aField( $conf, "DBengine", "MyISAM", "radio", "MyISAM" ); ?></li>
1418                 </ul>
1419         </div>
1420         <p class="config-desc">
1421                 InnoDB is best for public web installations, since it has good concurrency 
1422                 support. MyISAM may be faster in single-user installations. MyISAM databases 
1423                 tend to get corrupted more often than InnoDB databases.
1424         </p>
1425         <div class="config-input"><label class="column">Database character set</label>
1426                 <div>Select one:</div>
1427                 <ul class="plain">
1428                 <li><?php aField( $conf, "DBschema", "MySQL 4.1/5.0 binary", "radio", "mysql5-binary" ); ?></li>
1429                 <li><?php aField( $conf, "DBschema", "MySQL 4.1/5.0 UTF-8", "radio", "mysql5" ); ?></li>
1430                 <li><?php aField( $conf, "DBschema", "MySQL 4.0 backwards-compatible UTF-8", "radio", "mysql4" ); ?></li>
1431                 </ul>
1432         </div>
1433         <p class="config-desc">
1434                 This option is ignored on upgrade, the same character set will be kept. 
1435                 <br/><br/>
1436                 <b>WARNING:</b> If you use <b>backwards-compatible UTF-8</b> on MySQL 4.1+, and subsequently back up the database with <tt>mysqldump</tt>, it may destroy all non-ASCII characters, irreversibly corrupting your backups!.
1437                 <br/><br/>
1438                 In <b>binary mode</b>, MediaWiki stores UTF-8 text to the database in binary fields. This is more efficient than MySQL's UTF-8 mode, and allows you to use the full range of Unicode characters. In <b>UTF-8 mode</b>, MySQL will know what character set your data is in, and can present and convert it appropriately, but it won't let you store characters above the <a target="_blank" href="http://en.wikipedia.org/wiki/Mapping_of_Unicode_character_planes">Basic Multilingual Plane</a>.
1439         </p>
1440         </fieldset>
1441
1442         <?php database_switcher('postgres'); ?>
1443         <div class="config-input"><?php aField( $conf, "DBport", "Database port:" ); ?></div>
1444         <div class="config-input"><?php aField( $conf, "DBmwschema", "Schema for mediawiki:" ); ?></div>
1445         <div class="config-input"><?php aField( $conf, "DBts2schema", "Schema for tsearch2:" ); ?></div>
1446         <div class="config-desc">
1447                 <p>The username specified above (at "DB username") will have its search path set to the above schemas, 
1448                 so it is recommended that you create a new user. The above schemas are generally correct: 
1449         only change them if you are sure you need to.</p>
1450         </div>
1451         </fieldset>
1452
1453         <?php 
1454                 # SQLITE DISABLED -- USE MEDIAWIKI 1.15
1455                 if (false):
1456         ?>
1457         <?php database_switcher('sqlite'); ?>
1458         <div class="config-desc">
1459                 <b>NOTE:</b> SQLite only uses the <i>Database name</i> setting above, the user, password and root settings are ignored.
1460         </div>
1461         <div class="config-input"><?php
1462                 aField( $conf, "SQLiteDataDir", "SQLite data directory:" );
1463         ?></div>
1464         <div class="config-desc">
1465                 <p>SQLite stores table data into files in the filesystem.
1466                 If you do not provide an explicit path, a "data" directory in
1467                 the parent of your document root will be used.</p>
1468                 
1469                 <p>This directory must exist and be writable by the web server.</p>
1470         </div>
1471         </fieldset>
1472
1473         <?php 
1474                 # SQLITE DISABLED -- USE MEDIAWIKI 1.15
1475                 endif
1476         ?>
1477
1478         <?php database_switcher('mssql'); ?>
1479         <div class="config-input"><?php
1480                 aField( $conf, "DBprefix2", "Database table prefix:" );
1481         ?></div>
1482         <div class="config-desc">
1483                 <p>If you need to share one database between multiple wikis, or
1484                 between MediaWiki and another web application, you may choose to
1485                 add a prefix to all the table names to avoid conflicts.</p>
1486
1487                 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
1488         </div>
1489         </fieldset>
1490
1491         <div class="config-input" style="padding:2em 0 3em">
1492                 <label class='column'>&nbsp;</label>
1493                 <input type="submit" value="Install MediaWiki!" class="btn-install" />
1494         </div>
1495 </div>
1496 </form>
1497 <script type="text/javascript">
1498 window.onload = toggleDBarea(<?php echo Xml::encodeJsVar( $conf->DBtype ); ?>,
1499 <?php
1500         ## If they passed in a root user name, don't populate it on page load
1501         echo strlen(importPost('RootUser', '')) ? 0 : 1;
1502 ?>);
1503 </script>
1504 <?php
1505 }
1506
1507 /* -------------------------------------------------------------------------------------- */
1508 function writeSuccessMessage() {
1509  $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
1510         if ( wfIniGetBool( 'safe_mode' ) && !ini_get( 'open_basedir' ) ) {
1511                 echo <<<EOT
1512 <div class="success-box">
1513 <p>Installation successful!</p>
1514 <p>To complete the installation, please do the following:
1515 <ol>
1516         <li>Download config/LocalSettings.php with your FTP client or file manager</li>
1517         <li>Upload it to the parent directory</li>
1518         <li>Delete config/LocalSettings.php</li>
1519         <li>Start using <a href='../$script'>your wiki</a>!
1520 </ol>
1521 <p>If you are in a shared hosting environment, do <strong>not</strong> just move LocalSettings.php
1522 remotely. LocalSettings.php is currently owned by the user your webserver is running under,
1523 which means that anyone on the same server can read your database password! Downloading
1524 it and uploading it again will hopefully change the ownership to a user ID specific to you.</p>
1525 </div>
1526 EOT;
1527         } else {
1528                 echo <<<EOT
1529 <div class="success-box">
1530 <p>
1531 <span class="success-message">Installation successful!</span>
1532 Move the <tt>config/LocalSettings.php</tt> file to the parent directory, then follow
1533 <a href="../$script"> this link</a> to your wiki.</p>
1534 <p>You should change file permissions for <tt>LocalSettings.php</tt> as required to
1535 prevent other users on the server reading passwords and altering configuration data.</p>
1536 </div>
1537 EOT;
1538         }
1539 }
1540
1541
1542 function escapePhpString( $string ) {
1543         if ( is_array( $string ) || is_object( $string ) ) {
1544                 return false;
1545         }
1546         return strtr( $string,
1547                 array(
1548                         "\n" => "\\n",
1549                         "\r" => "\\r",
1550                         "\t" => "\\t",
1551                         "\\" => "\\\\",
1552                         "\$" => "\\\$",
1553                         "\"" => "\\\""
1554                 ));
1555 }
1556
1557 function writeLocalSettings( $conf ) {
1558         $conf->PasswordSender = $conf->EmergencyContact;
1559         $magic = ($conf->ImageMagick ? "" : "# ");
1560         $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
1561         $rights = ($conf->RightsUrl) ? "" : "# ";
1562         $hashedUploads = $conf->safeMode ? '' : '# ';
1563
1564         if ( $conf->ShellLocale ) {
1565                 $locale = '';
1566         } else {
1567                 $locale = '# ';
1568                 $conf->ShellLocale = 'en_US.UTF-8';
1569         }
1570
1571         switch ( $conf->Shm ) {
1572                 case 'memcached':
1573                         $cacheType = 'CACHE_MEMCACHED';
1574                         $mcservers = var_export( $conf->MCServerArray, true );
1575                         break;
1576                 case 'turck':
1577                 case 'xcache':
1578                 case 'apc':
1579                 case 'eaccel':
1580                         $cacheType = 'CACHE_ACCEL';
1581                         $mcservers = 'array()';
1582                         break;
1583                 case 'dba':
1584                         $cacheType = 'CACHE_DBA';
1585                         $mcservers = 'array()';
1586                         break;
1587                 default:
1588                         $cacheType = 'CACHE_NONE';
1589                         $mcservers = 'array()';
1590         }
1591
1592         if ( $conf->Email == 'email_enabled' ) {
1593                 $enableemail = 'true';
1594                 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
1595                 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
1596                 switch ( $conf->Enotif ) {
1597                         case 'enotif_usertalk':
1598                                 $enotifusertalk = 'true';
1599                                 $enotifwatchlist = 'false';
1600                                 break;
1601                         case 'enotif_allpages':
1602                                 $enotifusertalk = 'true';
1603                                 $enotifwatchlist = 'true';
1604                                 break;
1605                         default:
1606                                 $enotifusertalk = 'false';
1607                                 $enotifwatchlist = 'false';
1608                 }
1609         } else {
1610                 $enableuseremail = 'false';
1611                 $enableemail = 'false';
1612                 $eauthent = 'false';
1613                 $enotifusertalk = 'false';
1614                 $enotifwatchlist = 'false';
1615         }
1616
1617         $file = @fopen( "/dev/urandom", "r" );
1618         if ( $file ) {
1619                 $secretKey = bin2hex( fread( $file, 32 ) );
1620                 fclose( $file );
1621         } else {
1622                 $secretKey = "";
1623                 for ( $i=0; $i<8; $i++ ) {
1624                         $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1625                 }
1626                 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1627         }
1628
1629         # Add slashes to strings for double quoting
1630         $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
1631         if( $conf->License == 'gfdl1_2' || $conf->License == 'pd' || $conf->License == 'gfdl1_3' ) {
1632                 # Needs literal string interpolation for the current style path
1633                 $slconf['RightsIcon'] = $conf->RightsIcon;
1634         }
1635
1636         if( $conf->DBtype == 'mysql' ) {
1637                 $dbsettings =
1638 "# MySQL specific settings
1639 \$wgDBprefix         = \"{$slconf['DBprefix']}\";
1640
1641 # MySQL table options to use during installation or update
1642 \$wgDBTableOptions   = \"{$slconf['DBTableOptions']}\";
1643
1644 # Experimental charset support for MySQL 4.1/5.0.
1645 \$wgDBmysql5 = {$conf->DBmysql5};";
1646         } elseif( $conf->DBtype == 'postgres' ) {
1647                 $dbsettings =
1648 "# Postgres specific settings
1649 \$wgDBport           = \"{$slconf['DBport']}\";
1650 \$wgDBmwschema       = \"{$slconf['DBmwschema']}\";
1651 \$wgDBts2schema      = \"{$slconf['DBts2schema']}\";";
1652         } elseif( $conf->DBtype == 'sqlite' ) {
1653                 $dbsettings =
1654 "# SQLite-specific settings
1655 \$wgSQLiteDataDir    = \"{$slconf['SQLiteDataDir']}\";";
1656         } elseif( $conf->DBtype == 'mssql' ) {
1657                 $dbsettings =
1658 "# MSSQL specific settings
1659 \$wgDBprefix         = \"{$slconf['DBprefix2']}\";";
1660         } else {
1661                 // ummm... :D
1662                 $dbsettings = '';
1663         }
1664
1665
1666         $localsettings = "
1667 # This file was automatically generated by the MediaWiki installer.
1668 # If you make manual changes, please keep track in case you need to
1669 # recreate them later.
1670 #
1671 # See includes/DefaultSettings.php for all configurable settings
1672 # and their default values, but don't forget to make changes in _this_
1673 # file, not there.
1674 #
1675 # Further documentation for configuration settings may be found at:
1676 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
1677
1678 # If you customize your file layout, set \$IP to the directory that contains
1679 # the other MediaWiki files. It will be used as a base to locate files.
1680 if( defined( 'MW_INSTALL_PATH' ) ) {
1681         \$IP = MW_INSTALL_PATH;
1682 } else {
1683         \$IP = dirname( __FILE__ );
1684 }
1685
1686 \$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
1687 set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() );
1688
1689 require_once( \"\$IP/includes/DefaultSettings.php\" );
1690
1691 # If PHP's memory limit is very low, some operations may fail.
1692 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
1693
1694 if ( \$wgCommandLineMode ) {
1695         if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1696                 die( \"This script must be run from the command line\\n\" );
1697         }
1698 }
1699 ## Uncomment this to disable output compression
1700 # \$wgDisableOutputCompression = true;
1701
1702 \$wgSitename         = \"{$slconf['Sitename']}\";
1703
1704 ## The URL base path to the directory containing the wiki;
1705 ## defaults for all runtime URL paths are based off of this.
1706 ## For more information on customizing the URLs please see:
1707 ## http://www.mediawiki.org/wiki/Manual:Short_URL
1708 \$wgScriptPath       = \"{$slconf['ScriptPath']}\";
1709 \$wgScriptExtension  = \"{$slconf['ScriptExtension']}\";
1710
1711 ## UPO means: this is also a user preference option
1712
1713 \$wgEnableEmail      = $enableemail;
1714 \$wgEnableUserEmail  = $enableuseremail; # UPO
1715
1716 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1717 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
1718
1719 \$wgEnotifUserTalk = $enotifusertalk; # UPO
1720 \$wgEnotifWatchlist = $enotifwatchlist; # UPO
1721 \$wgEmailAuthentication = $eauthent;
1722
1723 ## Database settings
1724 \$wgDBtype           = \"{$slconf['DBtype']}\";
1725 \$wgDBserver         = \"{$slconf['DBserver']}\";
1726 \$wgDBname           = \"{$slconf['DBname']}\";
1727 \$wgDBuser           = \"{$slconf['DBuser']}\";
1728 \$wgDBpassword       = \"{$slconf['DBpassword']}\";
1729
1730 {$dbsettings}
1731
1732 ## Shared memory settings
1733 \$wgMainCacheType = $cacheType;
1734 \$wgMemCachedServers = $mcservers;
1735
1736 ## To enable image uploads, make sure the 'images' directory
1737 ## is writable, then set this to true:
1738 \$wgEnableUploads       = false;
1739 {$magic}\$wgUseImageMagick = true;
1740 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
1741
1742 ## If you use ImageMagick (or any other shell command) on a
1743 ## Linux server, this will need to be set to the name of an
1744 ## available UTF-8 locale
1745 {$locale}\$wgShellLocale = \"{$slconf['ShellLocale']}\";
1746
1747 ## If you want to use image uploads under safe mode,
1748 ## create the directories images/archive, images/thumb and
1749 ## images/temp, and make them all writable. Then uncomment
1750 ## this, if it's not already uncommented:
1751 {$hashedUploads}\$wgHashedUploadDirectory = false;
1752
1753 ## If you have the appropriate support software installed
1754 ## you can enable inline LaTeX equations:
1755 \$wgUseTeX           = false;
1756
1757 \$wgLocalInterwiki   = strtolower( \$wgSitename );
1758
1759 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
1760
1761 \$wgSecretKey = \"$secretKey\";
1762
1763 ## Default skin: you can change the default skin. Use the internal symbolic
1764 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
1765 \$wgDefaultSkin = 'monobook';
1766
1767 ## For attaching licensing metadata to pages, and displaying an
1768 ## appropriate copyright notice / icon. GNU Free Documentation
1769 ## License and Creative Commons licenses are supported so far.
1770 {$rights}\$wgEnableCreativeCommonsRdf = true;
1771 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
1772 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
1773 \$wgRightsText = \"{$slconf['RightsText']}\";
1774 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
1775 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
1776
1777 \$wgDiff3 = \"{$slconf['diff3']}\";
1778
1779 # When you make changes to this configuration file, this will make
1780 # sure that cached pages are cleared.
1781 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
1782 "; ## End of setting the $localsettings string
1783
1784         // Keep things in Unix line endings internally;
1785         // the system will write out as local text type.
1786         return str_replace( "\r\n", "\n", $localsettings );
1787 }
1788
1789 function dieout( $text ) {
1790         global $mainListOpened;
1791         if( $mainListOpened ) echo( "</ul>" );
1792         if( $text != '' && substr( $text, 0, 2 ) != '<p'  && substr( $text, 0, 2 ) != '<h' ){
1793                 echo "<p>$text</p>\n";
1794         } else {
1795                 echo $text;
1796         }
1797         die( "\n\n</div>\n</div>\n</div>\n</div>\n</body>\n</html>" );
1798 }
1799
1800 function importVar( &$var, $name, $default = "" ) {
1801         if( isset( $var[$name] ) ) {
1802                 $retval = $var[$name];
1803                 if ( get_magic_quotes_gpc() ) {
1804                         $retval = stripslashes( $retval );
1805                 }
1806         } else {
1807                 $retval = $default;
1808         }
1809         return $retval;
1810 }
1811
1812 function importPost( $name, $default = "" ) {
1813         return importVar( $_POST, $name, $default );
1814 }
1815
1816 function importCheck( $name ) {
1817         return isset( $_POST[$name] );
1818 }
1819
1820 function importRequest( $name, $default = "" ) {
1821         return importVar( $_REQUEST, $name, $default );
1822 }
1823
1824 function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick = '' ) {
1825         static $radioCount = 0;
1826         if( $type != "" ) {
1827                 $xtype = "type=\"$type\"";
1828         } else {
1829                 $xtype = "";
1830         }
1831
1832         $id = $field;
1833         $nolabel = ($type == "radio") || ($type == "hidden");
1834
1835         if ($type == 'radio')
1836                 $id .= $radioCount++;
1837
1838         if( !$nolabel ) {
1839                 echo "<label class='column' for=\"$id\">$text</label>";
1840         }
1841
1842         if( $type == "radio" && $value == $conf->$field ) {
1843                 $checked = "checked='checked'";
1844         } else {
1845                 $checked = "";
1846         }
1847         echo "<input $xtype name=\"$field\" id=\"$id\" class=\"iput-$type\" $checked ";
1848         if ($onclick) {
1849                 echo " onclick='toggleDBarea(\"$value\",1)' " ;
1850         }
1851         echo "value=\"";
1852         if( $type == "radio" ) {
1853                 echo htmlspecialchars( $value );
1854         } else {
1855                 echo htmlspecialchars( $conf->$field );
1856         }
1857
1858
1859         echo "\" />";
1860         if( $nolabel ) {
1861                 echo "<label for=\"$id\">$text</label>";
1862         }
1863
1864         global $errs;
1865         if(isset($errs[$field])) {
1866                 echo "<span class='error'>" . htmlspecialchars( $errs[$field] ) . "</span>\n";
1867         }
1868 }
1869
1870 function getLanguageList() {
1871         global $wgLanguageNames, $IP;
1872         if( !isset( $wgLanguageNames ) ) {
1873                 require_once( "$IP/languages/Names.php" );
1874         }
1875
1876         $codes = array();
1877
1878         $d = opendir( "../languages/messages" );
1879         /* In case we are called from the root directory */
1880         if (!$d)
1881                 $d = opendir( "languages/messages");
1882         while( false !== ($f = readdir( $d ) ) ) {
1883                 $m = array();
1884                 if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1885                         $code = str_replace( '_', '-', strtolower( $m[1] ) );
1886                         if( isset( $wgLanguageNames[$code] ) ) {
1887                                 $name = $code . ' - ' . $wgLanguageNames[$code];
1888                         } else {
1889                                 $name = $code;
1890                         }
1891                         $codes[$code] = $name;
1892                 }
1893         }
1894         closedir( $d );
1895         ksort( $codes );
1896         return $codes;
1897 }
1898
1899 #Check for location of an executable
1900 # @param string $loc single location to check
1901 # @param array $names filenames to check for.
1902 # @param mixed $versioninfo array of details to use when checking version, use false for no version checking
1903 function locate_executable($loc, $names, $versioninfo = false) {
1904         if (!is_array($names))
1905                 $names = array($names);
1906
1907         foreach ($names as $name) {
1908                 $command = "$loc".DIRECTORY_SEPARATOR."$name";
1909                 if (@file_exists($command)) {
1910                         if (!$versioninfo)
1911                                 return $command;
1912
1913                         $file = str_replace('$1', $command, $versioninfo[0]);
1914                         if (strstr(`$file`, $versioninfo[1]) !== false)
1915                                 return $command;
1916                 }
1917         }
1918         return false;
1919 }
1920
1921 # Test a memcached server
1922 function testMemcachedServer( $server ) {
1923         $hostport = explode(":", $server);
1924         $errstr = false;
1925         $fp = false;
1926         if ( !function_exists( 'fsockopen' ) ) {
1927                 $errstr = "Can't connect to memcached, fsockopen() not present";
1928         }
1929         if ( !$errstr && count( $hostport ) != 2 ) {
1930                 $errstr = 'Please specify host and port';
1931         }
1932         if ( !$errstr ) {
1933                 list( $host, $port ) = $hostport;
1934                 $errno = 0;
1935                 $fsockerr = '';
1936
1937                 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1938                 if ( $fp === false ) {
1939                         $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1940                 }
1941         }
1942         if ( !$errstr ) {
1943                 $command = "version\r\n";
1944                 $bytes = fwrite( $fp, $command );
1945                 if ( $bytes != strlen( $command ) ) {
1946                         $errstr = "Cannot write to memcached socket on $host:$port";
1947                 }
1948         }
1949         if ( !$errstr ) {
1950                 $expected = "VERSION ";
1951                 $response = fread( $fp, strlen( $expected ) );
1952                 if ( $response != $expected ) {
1953                         $errstr = "Didn't get correct memcached response from $host:$port";
1954                 }
1955         }
1956         if ( $fp ) {
1957                 fclose( $fp );
1958         }
1959         if ( !$errstr ) {
1960                 echo "<li>Connected to memcached on " . htmlspecialchars( "$host:$port" ) ." successfully</li>";
1961         }
1962         return $errstr;
1963 }
1964
1965 function database_picker($conf) {
1966         global $ourdb;
1967         print "\n";
1968         foreach(array_keys($ourdb) as $db) {
1969                 if ($ourdb[$db]['havedriver']) {
1970                         print "\t<li>";
1971                         aField( $conf, "DBtype", $ourdb[$db]['fullname'], 'radio', $db, 'onclick');
1972                         print "</li>\n";
1973                 }
1974         }
1975         print "\n\t";
1976 }
1977
1978 function database_switcher($db) {
1979         global $ourdb;
1980         $color = $ourdb[$db]['bgcolor'];
1981         $full = $ourdb[$db]['fullname'];
1982         print "<fieldset id='$db'><legend>$full specific options</legend>\n";
1983 }
1984
1985 function printListItem( $item ) {
1986         print "<li>$item</li>";
1987 }
1988
1989 # Determine a suitable value for $wgShellLocale
1990 function getShellLocale( $wikiLang ) {
1991         # Give up now if we're in safe mode or open_basedir
1992         # It's theoretically possible but tricky to work with
1993         if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) ) {
1994                 return false;
1995         }
1996
1997         $os = php_uname( 's' );
1998         $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
1999         if ( !in_array( $os, $supported ) ) {
2000                 return false;
2001         }
2002
2003         # Get a list of available locales
2004         $lines = $ret = false;
2005         exec( '/usr/bin/locale -a', $lines, $ret );
2006         if ( $ret ) {
2007                 return false;
2008         }
2009
2010         $lines = array_map( 'trim', $lines );
2011         $candidatesByLocale = array();
2012         $candidatesByLang = array();
2013         foreach ( $lines as $line ) {
2014                 if ( $line === '' ) {
2015                         continue;
2016                 }
2017                 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
2018                         continue;
2019                 }
2020                 list( $all, $lang, $territory, $charset, $modifier ) = $m;
2021                 $candidatesByLocale[$m[0]] = $m;
2022                 $candidatesByLang[$lang][] = $m;
2023         }
2024
2025         # Try the current value of LANG
2026         if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
2027                 return getenv( 'LANG' );
2028         }
2029
2030         # Try the most common ones
2031         $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
2032         foreach ( $commonLocales as $commonLocale ) {
2033                 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
2034                         return $commonLocale;
2035                 }
2036         }
2037
2038         # Is there an available locale in the Wiki's language?
2039         if ( isset( $candidatesByLang[$wikiLang] ) ) {
2040                 $m = reset( $candidatesByLang[$wikiLang] );
2041                 return $m[0];
2042         }
2043
2044         # Are there any at all?
2045         if ( count( $candidatesByLocale ) ) {
2046                 $m = reset( $candidatesByLocale );
2047                 return $m[0];
2048         }
2049
2050         # Give up
2051         return false;
2052 }
2053
2054 ?>
2055
2056         <div class="license">
2057         <hr/>
2058         <p>This program is free software; you can redistribute it and/or modify
2059          it under the terms of the GNU General Public License as published by
2060          the Free Software Foundation; either version 2 of the License, or
2061          (at your option) any later version.</p>
2062
2063          <p>This program is distributed in the hope that it will be useful,
2064          but WITHOUT ANY WARRANTY; without even the implied warranty of
2065          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2066          GNU General Public License for more details.</p>
2067
2068          <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
2069          along with this program; if not, write to the Free Software
2070          Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2071          or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
2072         </div>
2073
2074 </div></div></div>
2075
2076
2077 <div id="column-one">
2078         <div class="portlet" id="p-logo">
2079           <a style="background-image: url(../skins/common/images/mediawiki.png);"
2080             href="http://www.mediawiki.org/"
2081             title="Main Page"></a>
2082         </div>
2083         <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
2084         <div class='portlet'><div class='pBody'>
2085                 <ul>
2086                         <li><strong><a href="http://www.mediawiki.org/">MediaWiki home</a></strong></li>
2087                         <li><a href="../README">Readme</a></li>
2088                         <li><a href="../RELEASE-NOTES">Release notes</a></li>
2089                         <li><a href="../docs/">Documentation</a></li>
2090                         <li><a href="http://www.mediawiki.org/wiki/Help:Contents">User's Guide</a></li>
2091                         <li><a href="http://www.mediawiki.org/wiki/Manual:Contents">Administrator's Guide</a></li>
2092                         <li><a href="http://www.mediawiki.org/wiki/Manual:FAQ">FAQ</a></li>
2093                 </ul>
2094                 <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright © 2001-2008 by Magnus Manske, Brion Vibber,
2095                  Lee Daniel Crocker, Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason, Niklas Laxström,
2096                  Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor, Aaron Schulz and others.</p>
2097         </div></div>
2098 </div>
2099
2100 </div>
2101
2102 </body>
2103 </html>