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