Revert the attempt to autodetect CGI configs with working PATHINFO, since it turns...
[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 $sep = PATH_SEPARATOR;
33 if( !ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages" ) ) {
34 set_include_path( ".$sep$IP$sep$IP/includes$sep$IP/languages" );
35 }
36
37 # Define an entry point and include some files
38 define( "MEDIAWIKI", true );
39 define( "MEDIAWIKI_INSTALL", true );
40
41 // Run version checks before including other files
42 // so people don't see a scary parse error.
43 require_once( "install-utils.inc" );
44 install_version_checks();
45
46 require_once( "includes/Defines.php" );
47 require_once( "includes/DefaultSettings.php" );
48 require_once( "includes/MagicWord.php" );
49 require_once( "includes/Namespace.php" );
50 require_once( "includes/ProfilerStub.php" );
51
52 ## Databases we support:
53
54 $ourdb = array();
55 $ourdb['mysql']['fullname'] = 'MySQL';
56 $ourdb['mysql']['havedriver'] = 0;
57 $ourdb['mysql']['compile'] = 'mysql';
58 $ourdb['mysql']['bgcolor'] = '#ffe5a7';
59 $ourdb['mysql']['rootuser'] = 'root';
60
61 $ourdb['postgres']['fullname'] = 'PostgreSQL';
62 $ourdb['postgres']['havedriver'] = 0;
63 $ourdb['postgres']['compile'] = 'pgsql';
64 $ourdb['postgres']['bgcolor'] = '#aaccff';
65 $ourdb['postgres']['rootuser'] = 'postgres';
66
67 ?>
68 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
69 <html>
70 <head>
71 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
72 <title>MediaWiki <?php echo( $wgVersion ); ?> Installation</title>
73 <style type="text/css">
74
75 @import "../skins/monobook/main.css";
76
77 .env-check {
78 font-size: 90%;
79 margin: 1em 0 1em 2.5em;
80 }
81
82 .config-section {
83 margin-top: 2em;
84 }
85
86 .config-section label.column {
87 clear: left;
88 font-weight: bold;
89 width: 13em;
90 float: left;
91 text-align: right;
92 padding-right: 1em;
93 padding-top: .2em;
94 }
95
96 .config-input {
97 clear: left;
98 zoom: 100%; /* IE hack */
99 }
100
101 .config-section .config-desc {
102 clear: left;
103 margin: 0 0 2em 18em;
104 padding-top: 1em;
105 font-size: 85%;
106 }
107
108 .iput-text, .iput-password {
109 width: 14em;
110 margin-right: 1em;
111 }
112
113 .error {
114 color: red;
115 background-color: #fff;
116 font-weight: bold;
117 left: 1em;
118 font-size: 100%;
119 }
120
121 .error-top {
122 color: red;
123 background-color: #FFF0F0;
124 border: 2px solid red;
125 font-size: 130%;
126 font-weight: bold;
127 padding: 1em 1.5em;
128 margin: 2em 0 1em;
129 }
130
131 ul.plain {
132 list-style-type: none;
133 list-style-image: none;
134 float: left;
135 margin: 0;
136 padding: 0;
137 }
138
139 .btn-install {
140 font-weight: bold;
141 font-size: 110%;
142 padding: .2em .3em;
143 }
144
145 .license {
146 font-size: 85%;
147 padding-top: 3em;
148 }
149
150 </style>
151 <script type="text/javascript">
152 <!--
153 function hideall() {
154 <?php foreach (array_keys($ourdb) as $db) {
155 echo "\n document.getElementById('$db').style.display='none';";
156 }
157 ?>
158
159 }
160 function toggleDBarea(id,defaultroot) {
161 hideall();
162 var dbarea = document.getElementById(id).style;
163 dbarea.display = (dbarea.display == 'none') ? 'block' : 'none';
164 var db = document.getElementById('RootUser');
165 if (defaultroot) {
166 <?php foreach (array_keys($ourdb) as $db) {
167 echo " if (id == '$db') { db.value = '".$ourdb[$db]['rootuser']."';}\n";
168 }?>
169 }
170 }
171 // -->
172 </script>
173 </head>
174
175 <body>
176 <div id="globalWrapper">
177 <div id="column-content">
178 <div id="content">
179 <div id="bodyContent">
180
181 <h1>MediaWiki <?php print $wgVersion ?> Installation</h1>
182
183 <?php
184
185 /* Check for existing configurations and bug out! */
186
187 if( file_exists( "../LocalSettings.php" ) ) {
188 dieout( "<p><strong>Setup has completed, <a href='../index.php'>your wiki</a> is configured.</strong></p>
189
190 <p>Please delete the /config directory for extra security.</p></div></div></div></div>" );
191 }
192
193 if( file_exists( "./LocalSettings.php" ) ) {
194 writeSuccessMessage();
195
196 dieout( '' );
197 }
198
199 if( !is_writable( "." ) ) {
200 dieout( "<h2>Can't write config file, aborting</h2>
201
202 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
203 writable by the web server. Once configuration is done you'll move the created
204 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
205 then remove the <tt>config</tt> subdirectory entirely.</p>
206
207 <p>To make the directory writable on a Unix/Linux system:</p>
208
209 <pre>
210 cd <i>/path/to/wiki</i>
211 chmod a+w config
212 </pre>
213
214 <p>Afterwards retry to start the <a href=\"\">setup</a>.</p>" );
215 }
216
217
218 require_once( "install-utils.inc" );
219 require_once( "maintenance/updaters.inc" );
220
221 class ConfigData {
222 function getEncoded( $data ) {
223 # removing latin1 support, no need...
224 return $data;
225 }
226 function getSitename() { return $this->getEncoded( $this->Sitename ); }
227 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
228 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
229 }
230
231 ?>
232
233 <ul>
234 <li>
235 <b>Don't forget security updates!</b> Keep an eye on the
236 <a href="http://mail.wikimedia.org/mailman/listinfo/mediawiki-announce">low-traffic
237 release announcements mailing list</a>.
238 </li>
239 </ul>
240
241
242 <h2>Checking environment...</h2>
243 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
244 <ul class="env-check">
245 <?php
246 $endl = "
247 ";
248 $wgNoOutputBuffer = true;
249 $conf = new ConfigData;
250
251 install_version_checks();
252
253 print "<li>PHP " . phpversion() . " installed</li>\n";
254
255 ## Temporarily turn off all errors as we try to discover installed databases
256 $olderrnum = error_reporting(0);
257
258 $phpdatabases = array();
259 foreach (array_keys($ourdb) as $db) {
260 $compname = $ourdb[$db]['compile'];
261 if (extension_loaded($compname) or dl($compname . '.' . PHP_SHLIB_SUFFIX)) {
262 array_push($phpdatabases, $db);
263 $ourdb[$db]['havedriver'] = 1;
264 }
265 }
266
267 error_reporting($olderrornum);
268
269 if (!$phpdatabases) {
270 print "Could not find a suitable database driver!<ul>";
271 foreach (array_keys($ourdb) AS $db) {
272 $comp = $ourdb[$db]['compile'];
273 $full = $ourdb[$db]['fullname'];
274 print "<li>For <b>$full</b>, compile PHP using <b>--with-$comp</b>, "
275 ."or install the $comp.so module</li>\n";
276 }
277 dieout( "</ul></ul>" );
278 }
279
280 print "<li>Found database drivers for:";
281 foreach (array_keys($ourdb) AS $db) {
282 if ($ourdb[$db]['havedriver']) {
283 $DefaultDBtype = $db;
284 print " ".$ourdb[$db]['fullname'];
285 }
286 }
287 print "</li>\n";
288 if (count($phpdatabases) != 1)
289 $DefaultDBtype = '';
290
291 if( ini_get( "register_globals" ) ) {
292 ?>
293 <li>
294 <div style="font-size:110%">
295 <strong class="error">Warning:</strong>
296 <strong>PHP's <tt><a href="http://php.net/register_globals">register_globals</a></tt> option is enabled. Disable it if you can.</strong>
297 </div>
298 MediaWiki will work, but your server is more exposed to PHP-based security vulnerabilities.
299 </li>
300 <?php
301 }
302
303 $fatal = false;
304
305 if( ini_get( "magic_quotes_runtime" ) ) {
306 $fatal = true;
307 ?><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>
308 This option corrupts data input unpredictably; you cannot install or use
309 MediaWiki unless this option is disabled.
310 <?php
311 }
312
313 if( ini_get( "magic_quotes_sybase" ) ) {
314 $fatal = true;
315 ?><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>
316 This option corrupts data input unpredictably; you cannot install or use
317 MediaWiki unless this option is disabled.
318 <?php
319 }
320
321 if( ini_get( "mbstring.func_overload" ) ) {
322 $fatal = true;
323 ?><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>
324 This option causes errors and may corrupt data unpredictably;
325 you cannot install or use MediaWiki unless this option is disabled.
326 <?php
327 }
328
329 if( $fatal ) {
330 dieout( "</ul><p>Cannot install MediaWiki.</p>" );
331 }
332
333 if( ini_get( "safe_mode" ) ) {
334 $conf->safeMode = true;
335 ?>
336 <li><b class='error'>Warning:</b> <strong>PHP's
337 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active.</strong>
338 You may have problems caused by this, particularly if using image uploads.
339 </li>
340 <?php
341 } else {
342 $conf->safeMode = false;
343 }
344
345 $sapi = php_sapi_name();
346 $conf->prettyURLs = true;
347 print "<li>PHP server API is $sapi; ";
348 switch( $sapi ) {
349 case "apache":
350 case "apache2handler":
351 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
352 break;
353 case "cgi":
354 case "cgi-fcgi":
355 // For some reason cgi.fix_pathinfo isn't retrievable via ini_get()
356 // but even if it is, it's not necessarily safe.
357 // @fixme add optional runtime testing...?
358 $conf->prettyURLs = false;
359 break;
360 case "apache2filter":
361 case "isapi":
362 // Pretty sure these two break from past tests
363 $conf->prettyURLs = false;
364 break;
365 default:
366 print "unknown, assuming PATH_INFO broken for safety; ";
367 $conf->prettyURLs = false;
368 }
369 if( $conf->prettyURLs ) {
370 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
371 } else {
372 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
373 }
374 print "</li>\n";
375
376 $conf->xml = function_exists( "utf8_encode" );
377 if( $conf->xml ) {
378 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
379 } else {
380 dieout( "PHP's XML module is missing; the wiki requires functions in
381 this module and won't work in this configuration.
382 If you're running Mandrake, install the php-xml package." );
383 }
384
385 # Crude check for session support
386 if( !function_exists( 'session_name' ) )
387 dieout( "PHP's session module is missing. MediaWiki requires session support in order to function." );
388
389 # Likewise for PCRE
390 if( !function_exists( 'preg_match' ) )
391 dieout( "The PCRE regular expression functions are missing. MediaWiki requires these in order to function." );
392
393 $memlimit = ini_get( "memory_limit" );
394 $conf->raiseMemory = false;
395 if( empty( $memlimit ) || $memlimit == -1 ) {
396 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
397 } else {
398 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <strong>If this is too low, installation may fail!</strong> ";
399 $n = intval( $memlimit );
400 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
401 $n = intval( $m[1] * (1024*1024) );
402 }
403 if( $n < 20*1024*1024 ) {
404 print "Attempting to raise limit to 20M... ";
405 if( false === ini_set( "memory_limit", "20M" ) ) {
406 print "failed.";
407 } else {
408 $conf->raiseMemory = true;
409 print "ok.";
410 }
411 }
412 print "</li>\n";
413 }
414
415 $conf->zlib = function_exists( "gzencode" );
416 if( $conf->zlib ) {
417 print "<li>Have zlib support; enabling output compression.</li>\n";
418 } else {
419 print "<li>No zlib support.</li>\n";
420 }
421
422 $conf->turck = function_exists( 'mmcache_get' );
423 if ( $conf->turck ) {
424 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
425 }
426
427 $conf->apc = function_exists('apc_fetch');
428 if ($conf->apc ) {
429 print "<li><a href=\"http://www.php.net/apc\">APC</a> installed</li>";
430 }
431
432 $conf->eaccel = function_exists( 'eaccelerator_get' );
433 if ( $conf->eaccel ) {
434 $conf->turck = 'eaccelerator';
435 print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
436 }
437
438 if( !$conf->turck && !$conf->eaccel && !$conf->apc ) {
439 echo( '<li>Couldn\'t find <a href="http://turck-mmcache.sourceforge.net">Turck MMCache</a>,
440 <a href="http://eaccelerator.sourceforge.net">eAccelerator</a> or
441 <a href="http://www.php.net/apc">APC</a>. Object caching functions cannot be used.</li>' );
442 }
443
444 $conf->diff3 = false;
445 $diff3locations = array_merge(
446 array(
447 "/usr/bin",
448 "/usr/local/bin",
449 "/opt/csw/bin",
450 "/usr/gnu/bin",
451 "/usr/sfw/bin" ),
452 explode( $sep, getenv( "PATH" ) ) );
453 $diff3names = array( "gdiff3", "diff3", "diff3.exe" );
454
455 $diff3versioninfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
456 foreach ($diff3locations as $loc) {
457 $exe = locate_executable($loc, $diff3names, $diff3versioninfo);
458 if ($exe !== false) {
459 $conf->diff3 = $exe;
460 break;
461 }
462 }
463
464 if ($conf->diff3)
465 print "<li>Found GNU diff3: <tt>$conf->diff3</tt>.</li>";
466 else
467 print "<li>GNU diff3 not found.</li>";
468
469 $conf->ImageMagick = false;
470 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
471 foreach( $imcheck as $dir ) {
472 $im = "$dir/convert";
473 if( file_exists( $im ) ) {
474 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
475 $conf->ImageMagick = $im;
476 break;
477 }
478 }
479
480 $conf->HaveGD = function_exists( "imagejpeg" );
481 if( $conf->HaveGD ) {
482 print "<li>Found GD graphics library built-in";
483 if( !$conf->ImageMagick ) {
484 print ", image thumbnailing will be enabled if you enable uploads";
485 }
486 print ".</li>\n";
487 } else {
488 if( !$conf->ImageMagick ) {
489 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
490 }
491 }
492
493 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
494
495 $conf->IP = dirname( dirname( __FILE__ ) );
496 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
497
498
499 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
500 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
501 // to get the path to the current script... hopefully it's reliable. SIGH
502 $path = ($_SERVER["PHP_SELF"] === '')
503 ? $_SERVER["SCRIPT_NAME"]
504 : $_SERVER["PHP_SELF"];
505 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $path );
506 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
507
508 print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\n";
509 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
510
511 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
512 $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
513 ? 'root@localhost'
514 : $_SERVER["SERVER_ADMIN"];
515 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
516 $conf->DBtype = importPost( "DBtype", $DefaultDBtype );
517 ?>
518
519 <?php
520 $conf->DBserver = importPost( "DBserver", "localhost" );
521 $conf->DBname = importPost( "DBname", "wikidb" );
522 $conf->DBuser = importPost( "DBuser", "wikiuser" );
523 $conf->DBpassword = importPost( "DBpassword" );
524 $conf->DBpassword2 = importPost( "DBpassword2" );
525 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
526 $conf->SysopPass = importPost( "SysopPass" );
527 $conf->SysopPass2 = importPost( "SysopPass2" );
528 $conf->RootUser = importPost( "RootUser", "root" );
529 $conf->RootPW = importPost( "RootPW", "" );
530 $useRoot = importCheck( 'useroot', false );
531
532 ## MySQL specific:
533 $conf->DBprefix = importPost( "DBprefix" );
534 $conf->DBschema = importPost( "DBschema", "mysql4" );
535 $conf->DBmysql5 = ($conf->DBschema == "mysql5" ||
536 $conf->DBschema == "mysql5-binary")
537 ? "true" : "false";
538 $conf->LanguageCode = importPost( "LanguageCode", "en" );
539
540 ## Postgres specific:
541 $conf->DBport = importPost( "DBport", "5432" );
542 $conf->DBmwschema = importPost( "DBmwschema", "mediawiki" );
543 $conf->DBts2schema = importPost( "DBts2schema", "public" );
544
545 /* Check for validity */
546 $errs = array();
547
548 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
549 $errs["Sitename"] = "Must not be blank or \"MediaWiki\"";
550 }
551 if( $conf->DBuser == "" ) {
552 $errs["DBuser"] = "Must not be blank";
553 }
554 if( $conf->DBpassword == "" ) {
555 $errs["DBpassword"] = "Must not be blank";
556 }
557 if( $conf->DBpassword != $conf->DBpassword2 ) {
558 $errs["DBpassword2"] = "Passwords don't match!";
559 }
560 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
561 $errs["DBprefix"] = "Invalid table prefix";
562 }
563
564 if( $conf->SysopPass == "" ) {
565 $errs["SysopPass"] = "Must not be blank";
566 }
567 if( $conf->SysopPass != $conf->SysopPass2 ) {
568 $errs["SysopPass2"] = "Passwords don't match!";
569 }
570
571 $conf->License = importRequest( "License", "none" );
572 if( $conf->License == "gfdl" ) {
573 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
574 $conf->RightsText = "GNU Free Documentation License 1.2";
575 $conf->RightsCode = "gfdl";
576 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
577 } elseif( $conf->License == "none" ) {
578 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
579 } else {
580 $conf->RightsUrl = importRequest( "RightsUrl", "" );
581 $conf->RightsText = importRequest( "RightsText", "" );
582 $conf->RightsCode = importRequest( "RightsCode", "" );
583 $conf->RightsIcon = importRequest( "RightsIcon", "" );
584 }
585
586 $conf->Shm = importRequest( "Shm", "none" );
587 $conf->MCServers = importRequest( "MCServers" );
588
589 /* Test memcached servers */
590
591 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
592 $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
593 foreach ( $conf->MCServerArray as $server ) {
594 $error = testMemcachedServer( $server );
595 if ( $error ) {
596 $errs["MCServers"] = $error;
597 break;
598 }
599 }
600 } else if ( $conf->Shm == 'memcached' ) {
601 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
602 }
603
604 /* default values for installation */
605 $conf->Email = importRequest("Email", "email_enabled");
606 $conf->Emailuser = importRequest("Emailuser", "emailuser_enabled");
607 $conf->Enotif = importRequest("Enotif", "enotif_allpages");
608 $conf->Eauthent = importRequest("Eauthent", "eauthent_enabled");
609
610 if( $conf->posted && ( 0 == count( $errs ) ) ) {
611 do { /* So we can 'continue' to end prematurely */
612 $conf->Root = ($conf->RootPW != "");
613
614 /* Load up the settings and get installin' */
615 $local = writeLocalSettings( $conf );
616 echo "<li style=\"list-style: none\">\n";
617 echo "<p><b>Generating configuration file...</b></p>\n";
618 echo "</li>\n";
619
620 $wgCommandLineMode = false;
621 chdir( ".." );
622 $ok = eval( $local );
623 if( $ok === false ) {
624 dieout( "Errors in generated configuration; " .
625 "most likely due to a bug in the installer... " .
626 "Config file was: " .
627 "<pre>" .
628 htmlspecialchars( $local ) .
629 "</pre>" .
630 "</ul>" );
631 }
632 $conf->DBtypename = '';
633 foreach (array_keys($ourdb) as $db) {
634 if ($conf->DBtype === $db)
635 $conf->DBtypename = $ourdb[$db]['fullname'];
636 }
637 if ( ! strlen($conf->DBtype)) {
638 $errs["DBpicktype"] = "Please choose a database type";
639 continue;
640 }
641
642 if (! $conf->DBtypename) {
643 $errs["DBtype"] = "Unknown database type '$conf->DBtype'";
644 continue;
645 }
646 print "<li>Database type: {$conf->DBtypename}</li>\n";
647 $dbclass = 'Database'.ucfirst($conf->DBtype);
648 $wgDBtype = $conf->DBtype;
649 $wgDBadminuser = "root";
650 $wgDBadminpassword = $conf->RootPW;
651
652 ## Mysql specific:
653 $wgDBprefix = $conf->DBprefix;
654
655 ## Postgres specific:
656 $wgDBport = $conf->DBport;
657 $wgDBmwschema = $conf->DBmwschema;
658 $wgDBts2schema = $conf->DBts2schema;
659
660 $wgCommandLineMode = true;
661 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
662 require_once( "includes/Setup.php" );
663 chdir( "config" );
664
665 require_once( "maintenance/InitialiseMessages.inc" );
666
667 $wgTitle = Title::newFromText( "Installation script" );
668 error_reporting( E_ALL );
669 print "<li>Loading class: $dbclass";
670 $dbc = new $dbclass;
671
672 if( $conf->DBtype == 'mysql' ) {
673 $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
674 if( $mysqlOldClient ) {
675 print "<li><b>PHP is linked with old MySQL client libraries. If you are
676 using a MySQL 4.1 server and have problems connecting to the database,
677 see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
678 >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
679 }
680 $ok = true; # Let's be optimistic
681
682 # Decide if we're going to use the superuser or the regular database user
683 $conf->Root = $useRoot;
684 if( $conf->Root ) {
685 $db_user = $conf->RootUser;
686 $db_pass = $conf->RootPW;
687 } else {
688 $db_user = $wgDBuser;
689 $db_pass = $wgDBpassword;
690 }
691
692 # Attempt to connect
693 echo( "<li>Attempting to connect to database server as $db_user..." );
694 $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
695
696 # Check the connection and respond to errors
697 if( $wgDatabase->isOpen() ) {
698 # Seems OK
699 $ok = true;
700 $wgDBadminuser = $db_user;
701 $wgDBadminpassword = $db_pass;
702 echo( "success.</li>\n" );
703 $wgDatabase->ignoreErrors( true );
704 $myver = $wgDatabase->getServerVersion();
705 } else {
706 # There were errors, report them and back out
707 $ok = false;
708 $errno = mysql_errno();
709 $errtx = htmlspecialchars( mysql_error() );
710 switch( $errno ) {
711 case 1045:
712 case 2000:
713 echo( "failed due to authentication errors. Check passwords.</li>" );
714 if( $conf->Root ) {
715 # The superuser details are wrong
716 $errs["RootUser"] = "Check username";
717 $errs["RootPW"] = "and password";
718 } else {
719 # The regular user details are wrong
720 $errs["DBuser"] = "Check username";
721 $errs["DBpassword"] = "and password";
722 }
723 break;
724 case 2002:
725 case 2003:
726 default:
727 # General connection problem
728 echo( "failed with error [$errno] $errtx.</li>\n" );
729 $errs["DBserver"] = "Connection failed";
730 break;
731 } # switch
732 } #conn. att.
733
734 if( !$ok ) { continue; }
735
736 } else /* not mysql */ {
737 error_reporting( E_ALL );
738 $wgSuperUser = '';
739 ## Possible connect as a superuser
740 if( $conf->Root ) {
741 $wgDBsuperuser = $conf->RootUser;
742 echo( "<li>Attempting to connect to database \"postgres\" as superuser \"$wgDBsuperuser\"..." );
743 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
744 if (!$wgDatabase->isOpen()) {
745 print " error: " . $wgDatabase->lastError() . "</li>\n";
746 $errs["DBserver"] = "Could not connect to database as superuser";
747 $errs["RootUser"] = "Check username";
748 $errs["RootPW"] = "and password";
749 continue;
750 }
751 }
752 echo( "<li>Attempting to connect to database \"$wgDBname\" as \"$wgDBuser\"..." );
753 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
754 if (!$wgDatabase->isOpen()) {
755 print " error: " . $wgDatabase->lastError() . "</li>\n";
756 } else {
757 $myver = $wgDatabase->getServerVersion();
758 }
759 }
760
761 if ( !$wgDatabase->isOpen() ) {
762 $errs["DBserver"] = "Couldn't connect to database";
763 continue;
764 }
765
766 print "<li>Connected to $myver";
767 if ($conf->DBtype == 'mysql') {
768 if( version_compare( $myver, "4.0.14" ) < 0 ) {
769 dieout( " -- mysql 4.0.14 or later required. Aborting." );
770 }
771 $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
772 if( $mysqlNewAuth && $mysqlOldClient ) {
773 print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
774 to old client libraries; if you have trouble with authentication, see
775 <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
776 >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
777 }
778 if( $wgDBmysql5 ) {
779 if( $mysqlNewAuth ) {
780 print "; enabling MySQL 4.1/5.0 charset mode";
781 } else {
782 print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
783 but older version detected; will likely fail.</b>";
784 }
785 }
786 print "</li>\n";
787
788 @$sel = $wgDatabase->selectDB( $wgDBname );
789 if( $sel ) {
790 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
791 } else {
792 $err = mysql_errno();
793 $databaseSafe = htmlspecialchars( $wgDBname );
794 if( $err == 1102 /* Invalid database name */ ) {
795 print "<ul><li><strong>{$databaseSafe}</strong> is not a valid database name.</li></ul>";
796 continue;
797 } elseif( $err != 1049 /* Database doesn't exist */ ) {
798 print "<ul><li>Error selecting database <strong>{$databaseSafe}</strong>: {$err} ";
799 print htmlspecialchars( mysql_error() ) . "</li></ul>";
800 continue;
801 }
802 print "<li>Attempting to create database...</li>";
803 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
804 if( !$res ) {
805 print "<li>Couldn't create database <tt>" .
806 htmlspecialchars( $wgDBname ) .
807 "</tt>; try with root access or check your username/pass.</li>\n";
808 $errs["RootPW"] = "&lt;- Enter";
809 continue;
810 }
811 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
812 }
813 $wgDatabase->selectDB( $wgDBname );
814 }
815 else if ($conf->DBtype == 'postgres') {
816 if( version_compare( $myver, "PostgreSQL 8.0" ) < 0 ) {
817 dieout( " <b>Postgres 8.0 or later is required</b>. Aborting.</li></ul>" );
818 }
819 }
820
821 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
822 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
823
824 # Create user if required (todo: other databases)
825 if ( $conf->Root && $conf->DBtype == 'mysql') {
826 $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
827 if ( $conn->isOpen() ) {
828 print "<li>DB user account ok</li>\n";
829 $conn->close();
830 } else {
831 print "<li>Granting user permissions...";
832 if( $mysqlOldClient && $mysqlNewAuth ) {
833 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>";
834 }
835 print "</li>\n";
836 dbsource( "../maintenance/users.sql", $wgDatabase );
837 }
838 }
839 print "<pre>\n";
840 chdir( ".." );
841 flush();
842 do_all_updates();
843 chdir( "config" );
844 print "</pre>\n";
845 print "<li>Finished update checks.</li>\n";
846 } else {
847 # FIXME: Check for errors
848 print "<li>Creating tables...";
849 if ($conf->DBtype == 'mysql') {
850 switch( $conf->DBschema ) {
851 case "mysql4":
852 print " using MySQL 4 table defs...";
853 dbsource( "../maintenance/tables.sql", $wgDatabase );
854 break;
855 case "mysql5":
856 print " using MySQL 5 UTF-8 table defs...";
857 dbsource( "../maintenance/mysql5/tables.sql", $wgDatabase );
858 break;
859 case "mysql5-binary":
860 print " using MySQL 5 binary table defs...";
861 dbsource( "../maintenance/mysql5/tables-binary.sql", $wgDatabase );
862 break;
863 default:
864 dieout( " <b>invalid schema selection!</b></li>" );
865 }
866 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
867 } else if ($conf->DBtype == 'postgres') {
868 $wgDatabase->setup_database();
869 }
870 else {
871 $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'";
872 continue;
873 }
874
875 print " done.</li>\n";
876
877 print "<li>Initializing data...</li>\n";
878 $wgDatabase->insert( 'site_stats',
879 array ( 'ss_row_id' => 1,
880 'ss_total_views' => 0,
881 'ss_total_edits' => 0,
882 'ss_good_articles' => 0 ) );
883
884 # Set up the "regular user" account *if we can, and if we need to*
885 if( $conf->Root and $conf->DBtype == 'mysql') {
886 # See if we need to
887 $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
888 if( $wgDatabase2->isOpen() ) {
889 # Nope, just close the test connection and continue
890 $wgDatabase2->close();
891 echo( "<li>User $wgDBuser exists. Skipping grants.</li>\n" );
892 } else {
893 # Yes, so run the grants
894 echo( "<li>Granting user permissions to $wgDBuser on $wgDBname..." );
895 dbsource( "../maintenance/users.sql", $wgDatabase );
896 echo( "success.</li>\n" );
897 }
898 }
899
900 if( $conf->SysopName ) {
901 $u = User::newFromName( $conf->getSysopName() );
902 if ( !$u ) {
903 print "<li><strong class=\"error\">Warning:</strong> Skipped sysop account creation - invalid username!</li>\n";
904 }
905 else if ( 0 == $u->idForName() ) {
906 $u->addToDatabase();
907 $u->setPassword( $conf->getSysopPass() );
908 $u->saveSettings();
909
910 $u->addGroup( "sysop" );
911 $u->addGroup( "bureaucrat" );
912
913 print "<li>Created sysop account <tt>" .
914 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
915 } else {
916 print "<li>Could not create user - already exists!</li>\n";
917 }
918 } else {
919 print "<li>Skipped sysop account creation, no name given.</li>\n";
920 }
921
922 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
923 $article = new Article( $titleobj );
924 $newid = $article->insertOn( $wgDatabase );
925 $revision = new Revision( array(
926 'page' => $newid,
927 'text' => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsg( 'mainpagedocfooter' ),
928 'comment' => '',
929 'user' => 0,
930 'user_text' => 'MediaWiki default',
931 ) );
932 $revid = $revision->insertOn( $wgDatabase );
933 $article->updateRevisionOn( $wgDatabase, $revision );
934
935 initialiseMessages( false, false, 'printListItem' );
936 }
937
938 /* Write out the config file now that all is well */
939 print "<li style=\"list-style: none\">\n";
940 print "<p>Creating LocalSettings.php...</p>\n\n";
941 $localSettings = "<" . "?php$endl$local$endl?" . ">\r\n";
942 // Fix up a common line-ending problem (due to CVS on Windows)
943 $localSettings = str_replace( "\r\n", "\n", $localSettings );
944 $f = fopen( "LocalSettings.php", 'xt' );
945
946 if( $f == false ) {
947 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" .
948 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
949 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
950 }
951 if(fwrite( $f, $localSettings ) ) {
952 fclose( $f );
953 writeSuccessMessage();
954 } else {
955 fclose( $f );
956 die("<p class='error'>An error occured while writing the config/LocalSettings.php file. Check user rights and disk space then try again.</p>\n");
957
958 }
959 print "</li>\n";
960
961 } while( false );
962 }
963 ?>
964 </ul>
965
966
967 <?php
968
969 if( count( $errs ) ) {
970 /* Display options form */
971
972 if( $conf->posted ) {
973 echo "<p class='error-top'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
974 }
975 ?>
976
977 <form action="index.php" name="config" method="post">
978
979
980 <h2>Site config</h2>
981
982 <div class="config-section">
983 <div class="config-input">
984 <?php
985 aField( $conf, "Sitename", "Wiki name:" );
986 ?>
987 </div>
988 <p class="config-desc">
989 Preferably a short word without punctuation, i.e. "Wikipedia".<br />
990 Will appear as the namespace name for "meta" pages, and throughout the interface.
991 </p>
992
993 <div class="config-input">
994 <?php
995 aField( $conf, "EmergencyContact", "Contact e-mail:" );
996 ?>
997 </div>
998 <p class="config-desc">
999 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.
1000 </p>
1001
1002 <div class="config-input">
1003 <label class='column' for="LanguageCode">Language:</label>
1004 <select id="LanguageCode" name="LanguageCode">
1005
1006 <?php
1007 $list = getLanguageList();
1008 foreach( $list as $code => $name ) {
1009 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
1010 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
1011 }
1012 ?>
1013 </select>
1014 </div>
1015 <p class="config-desc">
1016 Select the language for your wiki's interface. Some localizations aren't fully complete. Unicode (UTF-8) is used for all localizations.
1017 </p>
1018
1019 <div class="config-input">
1020 <label class='column'>Copyright/license:</label>
1021
1022 <ul class="plain">
1023 <li><?php aField( $conf, "License", "No license metadata", "radio", "none" ); ?></li>
1024 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
1025 <li><?php
1026 aField( $conf, "License", "A Creative Commons license - ", "radio", "cc" );
1027 $partner = "MediaWiki";
1028 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
1029 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
1030 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
1031 print "<a href=\"$ccApp\" target='_blank'>choose</a>";
1032 ?>
1033 <?php if( $conf->License == "cc" ) { ?>
1034 <ul>
1035 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='(Creative Commons icon)' />", "hidden" ); ?></li>
1036 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
1037 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
1038 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
1039 </ul>
1040 <?php } ?>
1041 </li>
1042 </ul>
1043 </div>
1044 <p class="config-desc">
1045 A notice, icon, and machine-readable copyright metadata will be displayed for the license you pick.
1046 </p>
1047
1048
1049 <div class="config-input">
1050 <?php aField( $conf, "SysopName", "Admin username:" ) ?>
1051 </div>
1052 <div class="config-input">
1053 <?php aField( $conf, "SysopPass", "Password:", "password" ) ?>
1054 </div>
1055 <div class="config-input">
1056 <?php aField( $conf, "SysopPass2", "Password confirm:", "password" ) ?>
1057 </div>
1058 <p class="config-desc">
1059 An admin can lock/delete pages, block users from editing, and do other maintenance tasks.<br />
1060 A new account will be added only when creating a new wiki database.
1061 </p>
1062
1063 <div class="config-input">
1064 <label class='column'>Shared memory caching:</label>
1065
1066 <ul class="plain">
1067 <li><?php aField( $conf, "Shm", "No caching", "radio", "none" ); ?></li>
1068 <?php
1069 if ( $conf->turck ) {
1070 echo "<li>";
1071 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
1072 echo "</li>";
1073 }
1074 if ( $conf->apc ) {
1075 echo "<li>";
1076 aField( $conf, "Shm", "APC", "radio", "apc" );
1077 echo "</li>";
1078 }
1079 if ( $conf->eaccel ) {
1080 echo "<li>";
1081 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
1082 echo "</li>";
1083 }
1084 ?>
1085 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
1086 </ul>
1087 <div style="clear:left"><?php aField( $conf, "MCServers", "Memcached servers:", "text" ) ?></div>
1088 </div>
1089 <p class="config-desc">
1090 Using a shared memory system such as Turck MMCache, APC, eAccelerator, or Memcached
1091 will speed up MediaWiki significantly. Memcached is the best solution but needs to be
1092 installed. Specify the server addresses and ports in a comma-separted list. Only
1093 use Turck shared memory if the wiki will be running on a single Apache server.
1094 </p>
1095 </div>
1096
1097 <h2>E-mail, e-mail notification and authentication setup</h2>
1098
1099 <div class="config-section">
1100 <div class="config-input">
1101 <label class='column'>E-mail features (global):</label>
1102 <ul class="plain">
1103 <li><?php aField( $conf, "Email", "Enabled", "radio", "email_enabled" ); ?></li>
1104 <li><?php aField( $conf, "Email", "Disabled", "radio", "email_disabled" ); ?></li>
1105 </ul>
1106 </div>
1107 <p class="config-desc">
1108 Use this to disable all e-mail functions (password reminders, user-to-user e-mail and e-mail notifications)
1109 if sending mail doesn't work on your server.
1110 </p>
1111
1112 <div class="config-input">
1113 <label class='column'>User-to-user e-mail:</label>
1114 <ul class="plain">
1115 <li><?php aField( $conf, "Emailuser", "Enabled", "radio", "emailuser_enabled" ); ?></li>
1116 <li><?php aField( $conf, "Emailuser", "Disabled", "radio", "emailuser_disabled" ); ?></li>
1117 </ul>
1118 </div>
1119 <p class="config-desc">
1120 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.
1121 </p>
1122 <div class="config-input">
1123 <label class='column'>E-mail notification about changes:</label>
1124 <ul class="plain">
1125 <li><?php aField( $conf, "Enotif", "Disabled", "radio", "enotif_disabled" ); ?></li>
1126 <li><?php aField( $conf, "Enotif", "Enabled for changes to user discussion pages only", "radio", "enotif_usertalk" ); ?></li>
1127 <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>
1128 </ul>
1129 </div>
1130 <div class="config-desc">
1131 <p>
1132 For this feature to work, an e-mail address must be present for the user account, and the notification
1133 options in the user's preferences must be enabled. Also note the
1134 authentication option below. When testing the feature, keep in mind that your own changes will never trigger notifications to be sent to yourself.</p>
1135
1136 <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>
1137 </div>
1138
1139 <div class="config-input">
1140 <label class='column'>E-mail address authentication:</label>
1141 <ul class="plain">
1142 <li><?php aField( $conf, "Eauthent", "Disabled", "radio", "eauthent_disabled" ); ?></li>
1143 <li><?php aField( $conf, "Eauthent", "Enabled", "radio", "eauthent_enabled" ); ?></li>
1144 </ul>
1145 </div>
1146 <div class="config-desc">
1147 <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
1148 change notification mails. Setting this option is <B>recommended</B> for public wikis because of potential abuse of the e-mail features above.</p>
1149 </div>
1150
1151 </div>
1152
1153 <h2>Database config</h2>
1154
1155 <div class="config-section">
1156 <div class="config-input">
1157 <label class='column'>Database type:</label>
1158 <?php if (isset($errs['DBpicktype'])) print "<span class='error'>$errs[DBpicktype]</span>\n"; ?>
1159 <ul class='plain'><?php database_picker($conf) ?></ul>
1160 </div>
1161
1162 <div class="config-input" style="clear:left"><?php
1163 aField( $conf, "DBserver", "Database host:" );
1164 ?></div>
1165 <p class="config-desc">
1166 If your database server isn't on your web server, enter the name or IP address here.
1167 </p>
1168
1169 <div class="config-input"><?php
1170 aField( $conf, "DBname", "Database name:" );
1171 ?></div>
1172 <div class="config-input"><?php
1173 aField( $conf, "DBuser", "DB username:" );
1174 ?></div>
1175 <div class="config-input"><?php
1176 aField( $conf, "DBpassword", "DB password:", "password" );
1177 ?></div>
1178 <div class="config-input"><?php
1179 aField( $conf, "DBpassword2", "DB password confirm:", "password" );
1180 ?></div>
1181 <p class="config-desc">
1182 If you only have a single user account and database available,
1183 enter those here. If you have database root access (see below)
1184 you can specify new accounts/databases to be created. This account
1185 will not be created if it pre-exists. If this is the case, ensure that it
1186 has SELECT, INSERT, UPDATE and DELETE permissions on the MediaWiki database.
1187 </p>
1188
1189 <div class="config-input">
1190 <label class="column">Superuser account:</label>
1191 <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?>/>
1192 &nbsp;<label for="useroot">Use superuser account</label>
1193 </div>
1194 <div class="config-input">
1195 <?php
1196 aField( $conf, "RootUser", "Superuser name:", "superuser" );
1197 ?>
1198 </div>
1199 <div class="config-input">
1200 <?php
1201 aField( $conf, "RootPW", "Superuser password:", "password" );
1202 ?>
1203 </div>
1204
1205 <p class="config-desc">
1206 If the database user specified above does not exist, or does not have access to create
1207 the database (if needed) or tables within it, please check the box and provide details
1208 of a superuser account, such as <strong>root</strong>, which does.
1209 </p>
1210
1211 <?php database_switcher('mysql'); ?>
1212 <div class="config-input"><?php
1213 aField( $conf, "DBprefix", "Database table prefix:" );
1214 ?></div>
1215 <div class="config-desc">
1216 <p>If you need to share one database between multiple wikis, or
1217 MediaWiki and another web application, you may choose to
1218 add a prefix to all the table names to avoid conflicts.</p>
1219
1220 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
1221 </div>
1222
1223 <div class="config-input"><label class="column">Database charset</label>
1224 <div>Select one:</div>
1225 <ul class="plain">
1226 <li><?php aField( $conf, "DBschema", "Backwards-compatible UTF-8", "radio", "mysql4" ); ?></li>
1227 <li><?php aField( $conf, "DBschema", "Experimental MySQL 4.1/5.0 UTF-8", "radio", "mysql5" ); ?></li>
1228 <li><?php aField( $conf, "DBschema", "Experimental MySQL 4.1/5.0 binary", "radio", "mysql5-binary" ); ?></li>
1229 </ul>
1230 </div>
1231 <p class="config-desc">
1232 <b>EXPERIMENTAL:</b> You can enable explicit Unicode charset support
1233 for MySQL 4.1 and 5.0 servers. This is not well tested and may
1234 cause things to break. <b>If upgrading an older installation, leave
1235 in backwards-compatible mode.</b>
1236 </p>
1237 </div>
1238
1239 <?php database_switcher('postgres'); ?>
1240 <div class="config-input"><?php
1241 aField( $conf, "DBport", "Database port:" );
1242 ?></div>
1243 <div class="config-input"><?php
1244 aField( $conf, "DBmwschema", "Schema for mediawiki:" );
1245 ?></div>
1246 <div class="config-input"><?php
1247 aField( $conf, "DBts2schema", "Schema for tsearch2:" );
1248 ?></div>
1249 <div class="config-desc">
1250 <p>The username specified above will have it's search path set to the above schemas,
1251 so it is recommended that you create a new user.</p>
1252 </div>
1253 </div>
1254
1255 <div class="config-input" style="padding:2em 0 3em">
1256 <label class='column'>&nbsp;</label>
1257 <input type="submit" value="Install MediaWiki!" class="btn-install" />
1258 </div>
1259
1260 </div>
1261
1262 <script type="text/javascript">
1263 window.onload = toggleDBarea('<?php echo $conf->DBtype; ?>',
1264 <?php
1265 ## If they passed in a root user name, don't populate it on page load
1266 echo strlen(importPost('RootUser', '')) ? 0 : 1;
1267 ?>);
1268 </script>
1269
1270 </form>
1271
1272 <?php
1273 }
1274
1275 /* -------------------------------------------------------------------------------------- */
1276 function writeSuccessMessage() {
1277 if ( ini_get( 'safe_mode' ) && !ini_get( 'open_basedir' ) ) {
1278 echo <<<EOT
1279 <p>Installation successful!</p>
1280 <p>To complete the installation, please do the following:
1281 <ol>
1282 <li>Download config/LocalSettings.php with your FTP client or file manager</li>
1283 <li>Upload it to the parent directory</li>
1284 <li>Delete config/LocalSettings.php</li>
1285 <li>Start using <a href='../index.php'>your wiki</a>!
1286 </ol>
1287 <p>If you are in a shared hosting environment, do <strong>not</strong> just move LocalSettings.php
1288 remotely. LocalSettings.php is currently owned by the user your webserver is running under,
1289 which means that anyone on the same server can read your database password! Downloading
1290 it and uploading it again will hopefully change the ownership to a user ID specific to you.</p>
1291 EOT;
1292 } else {
1293 echo "<p><span style='font-weight:bold;color:green;font-size:110%'>Installation successful!</span> Move the <tt>config/LocalSettings.php</tt> file into the parent directory, then follow
1294 <strong><a href='../index.php'>this link</a></strong> to your wiki.</p>\n";
1295 }
1296 }
1297
1298
1299 function escapePhpString( $string ) {
1300 return strtr( $string,
1301 array(
1302 "\n" => "\\n",
1303 "\r" => "\\r",
1304 "\t" => "\\t",
1305 "\\" => "\\\\",
1306 "\$" => "\\\$",
1307 "\"" => "\\\""
1308 ));
1309 }
1310
1311 function writeLocalSettings( $conf ) {
1312 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
1313 $conf->PasswordSender = $conf->EmergencyContact;
1314 $zlib = ($conf->zlib ? "" : "# ");
1315 $magic = ($conf->ImageMagick ? "" : "# ");
1316 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
1317 $pretty = ($conf->prettyURLs ? "" : "# ");
1318 $ugly = ($conf->prettyURLs ? "# " : "");
1319 $rights = ($conf->RightsUrl) ? "" : "# ";
1320 $hashedUploads = $conf->safeMode ? '' : '# ';
1321
1322 switch ( $conf->Shm ) {
1323 case 'memcached':
1324 $cacheType = 'CACHE_MEMCACHED';
1325 $mcservers = var_export( $conf->MCServerArray, true );
1326 break;
1327 case 'turck':
1328 case 'apc':
1329 case 'eaccel':
1330 $cacheType = 'CACHE_ACCEL';
1331 $mcservers = 'array()';
1332 break;
1333 default:
1334 $cacheType = 'CACHE_NONE';
1335 $mcservers = 'array()';
1336 }
1337
1338 if ( $conf->Email == 'email_enabled' ) {
1339 $enableemail = 'true';
1340 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
1341 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
1342 switch ( $conf->Enotif ) {
1343 case 'enotif_usertalk':
1344 $enotifusertalk = 'true';
1345 $enotifwatchlist = 'false';
1346 break;
1347 case 'enotif_allpages':
1348 $enotifusertalk = 'true';
1349 $enotifwatchlist = 'true';
1350 break;
1351 default:
1352 $enotifusertalk = 'false';
1353 $enotifwatchlist = 'false';
1354 }
1355 } else {
1356 $enableuseremail = 'false';
1357 $enableemail = 'false';
1358 $eauthent = 'false';
1359 $enotifusertalk = 'false';
1360 $enotifwatchlist = 'false';
1361 }
1362
1363 $file = @fopen( "/dev/urandom", "r" );
1364 if ( $file ) {
1365 $secretKey = bin2hex( fread( $file, 32 ) );
1366 fclose( $file );
1367 } else {
1368 $secretKey = "";
1369 for ( $i=0; $i<8; $i++ ) {
1370 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1371 }
1372 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1373 }
1374
1375 # Add slashes to strings for double quoting
1376 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
1377 if( $conf->License == 'gfdl' ) {
1378 # Needs literal string interpolation for the current style path
1379 $slconf['RightsIcon'] = $conf->RightsIcon;
1380 }
1381
1382 $localsettings = "
1383 # This file was automatically generated by the MediaWiki installer.
1384 # If you make manual changes, please keep track in case you need to
1385 # recreate them later.
1386 #
1387 # See includes/DefaultSettings.php for all configurable settings
1388 # and their default values, but don't forget to make changes in _this_
1389 # file, not there.
1390
1391 # If you customize your file layout, set \$IP to the directory that contains
1392 # the other MediaWiki files. It will be used as a base to locate files.
1393 if( defined( 'MW_INSTALL_PATH' ) ) {
1394 \$IP = MW_INSTALL_PATH;
1395 } else {
1396 \$IP = dirname( __FILE__ );
1397 }
1398
1399 \$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
1400 set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() );
1401
1402 require_once( \"includes/DefaultSettings.php\" );
1403
1404 # If PHP's memory limit is very low, some operations may fail.
1405 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
1406
1407 if ( \$wgCommandLineMode ) {
1408 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1409 die( \"This script must be run from the command line\\n\" );
1410 }
1411 } elseif ( empty( \$wgNoOutputBuffer ) ) {
1412 ## Compress output if the browser supports it
1413 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
1414 }
1415
1416 \$wgSitename = \"{$slconf['Sitename']}\";
1417
1418 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
1419 \$wgScript = \"\$wgScriptPath/index.php\";
1420 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
1421
1422 ## For more information on customizing the URLs please see:
1423 ## http://meta.wikimedia.org/wiki/Eliminating_index.php_from_the_url
1424
1425 ## 'Pretty' URLs using PATH_INFO work on most configurations with
1426 ## PHP configured as an Apache module.
1427 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
1428
1429 ## If using PHP as a CGI module, the ?title= style might have to be used
1430 ## depending on the configuration. If it fails, try enabling the option
1431 ## cgi.fix_pathinfo in php.ini, then switch to pretty URLs.
1432 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
1433
1434 \$wgStylePath = \"\$wgScriptPath/skins\";
1435 \$wgStyleDirectory = \"\$IP/skins\";
1436 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
1437
1438 \$wgUploadPath = \"\$wgScriptPath/images\";
1439 \$wgUploadDirectory = \"\$IP/images\";
1440
1441 \$wgEnableEmail = $enableemail;
1442 \$wgEnableUserEmail = $enableuseremail;
1443
1444 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1445 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
1446
1447 ## For a detailed description of the following switches see
1448 ## http://meta.wikimedia.org/Enotif and http://meta.wikimedia.org/Eauthent
1449 ## There are many more options for fine tuning available see
1450 ## /includes/DefaultSettings.php
1451 ## UPO means: this is also a user preference option
1452 \$wgEnotifUserTalk = $enotifusertalk; # UPO
1453 \$wgEnotifWatchlist = $enotifwatchlist; # UPO
1454 \$wgEmailAuthentication = $eauthent;
1455
1456 \$wgDBtype = \"{$slconf['DBtype']}\";
1457 \$wgDBserver = \"{$slconf['DBserver']}\";
1458 \$wgDBname = \"{$slconf['DBname']}\";
1459 \$wgDBuser = \"{$slconf['DBuser']}\";
1460 \$wgDBpassword = \"{$slconf['DBpassword']}\";
1461 \$wgDBport = \"{$slconf['DBport']}\";
1462 \$wgDBprefix = \"{$slconf['DBprefix']}\";
1463
1464 # Schemas for Postgres
1465 \$wgDBmwschema = \"{$slconf['DBmwschema']}\";
1466 \$wgDBts2schema = \"{$slconf['DBts2schema']}\";
1467
1468 # Experimental charset support for MySQL 4.1/5.0.
1469 \$wgDBmysql5 = {$conf->DBmysql5};
1470
1471 ## Shared memory settings
1472 \$wgMainCacheType = $cacheType;
1473 \$wgMemCachedServers = $mcservers;
1474
1475 ## To enable image uploads, make sure the 'images' directory
1476 ## is writable, then set this to true:
1477 \$wgEnableUploads = false;
1478 \$wgUseImageResize = {$conf->UseImageResize};
1479 {$magic}\$wgUseImageMagick = true;
1480 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
1481
1482 ## If you want to use image uploads under safe mode,
1483 ## create the directories images/archive, images/thumb and
1484 ## images/temp, and make them all writable. Then uncomment
1485 ## this, if it's not already uncommented:
1486 {$hashedUploads}\$wgHashedUploadDirectory = false;
1487
1488 ## If you have the appropriate support software installed
1489 ## you can enable inline LaTeX equations:
1490 \$wgUseTeX = false;
1491 \$wgMathPath = \"{\$wgUploadPath}/math\";
1492 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
1493 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
1494
1495 \$wgLocalInterwiki = \$wgSitename;
1496
1497 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
1498
1499 \$wgProxyKey = \"$secretKey\";
1500
1501 ## Default skin: you can change the default skin. Use the internal symbolic
1502 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
1503 \$wgDefaultSkin = 'monobook';
1504
1505 ## For attaching licensing metadata to pages, and displaying an
1506 ## appropriate copyright notice / icon. GNU Free Documentation
1507 ## License and Creative Commons licenses are supported so far.
1508 {$rights}\$wgEnableCreativeCommonsRdf = true;
1509 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
1510 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
1511 \$wgRightsText = \"{$slconf['RightsText']}\";
1512 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
1513 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
1514
1515 \$wgDiff3 = \"{$slconf['diff3']}\";
1516
1517 # When you make changes to this configuration file, this will make
1518 # sure that cached pages are cleared.
1519 \$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
1520 \$wgCacheEpoch = max( \$wgCacheEpoch, \$configdate );
1521 "; ## End of setting the $localsettings string
1522
1523 // Keep things in Unix line endings internally;
1524 // the system will write out as local text type.
1525 return str_replace( "\r\n", "\n", $localsettings );
1526 }
1527
1528 function dieout( $text ) {
1529 die( $text . "\n\n</body>\n</html>" );
1530 }
1531
1532 function importVar( &$var, $name, $default = "" ) {
1533 if( isset( $var[$name] ) ) {
1534 $retval = $var[$name];
1535 if ( get_magic_quotes_gpc() ) {
1536 $retval = stripslashes( $retval );
1537 }
1538 } else {
1539 $retval = $default;
1540 }
1541 return $retval;
1542 }
1543
1544 function importPost( $name, $default = "" ) {
1545 return importVar( $_POST, $name, $default );
1546 }
1547
1548 function importCheck( $name ) {
1549 return isset( $_POST[$name] );
1550 }
1551
1552 function importRequest( $name, $default = "" ) {
1553 return importVar( $_REQUEST, $name, $default );
1554 }
1555
1556 $radioCount = 0;
1557
1558 function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick = '' ) {
1559 global $radioCount;
1560 if( $type != "" ) {
1561 $xtype = "type=\"$type\"";
1562 } else {
1563 $xtype = "";
1564 }
1565
1566 $id = $field;
1567 $nolabel = ($type == "radio") || ($type == "hidden");
1568
1569 if ($type == 'radio')
1570 $id .= $radioCount++;
1571
1572 if( $nolabel ) {
1573 echo "\t\t<label>";
1574 } else {
1575 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1576 }
1577
1578 if( $type == "radio" && $value == $conf->$field ) {
1579 $checked = "checked='checked'";
1580 } else {
1581 $checked = "";
1582 }
1583 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" class=\"iput-$type\" $checked ";
1584 if ($onclick) {
1585 echo " onclick='toggleDBarea(\"$value\",1)' " ;
1586 }
1587 echo "value=\"";
1588 if( $type == "radio" ) {
1589 echo htmlspecialchars( $value );
1590 } else {
1591 echo htmlspecialchars( $conf->$field );
1592 }
1593
1594
1595 echo "\" />\n";
1596 if( $nolabel ) {
1597 echo " $text</label>\n";
1598 }
1599
1600 global $errs;
1601 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1602 }
1603
1604 function getLanguageList() {
1605 global $wgLanguageNames;
1606 if( !isset( $wgLanguageNames ) ) {
1607 require_once( "languages/Names.php" );
1608 }
1609
1610 $codes = array();
1611
1612 $d = opendir( "../languages/messages" );
1613 /* In case we are called from the root directory */
1614 if (!$d)
1615 $d = opendir( "languages/messages");
1616 while( false !== ($f = readdir( $d ) ) ) {
1617 $m = array();
1618 if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1619 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1620 if( isset( $wgLanguageNames[$code] ) ) {
1621 $name = $code . ' - ' . $wgLanguageNames[$code];
1622 } else {
1623 $name = $code;
1624 }
1625 $codes[$code] = $name;
1626 }
1627 }
1628 closedir( $d );
1629 ksort( $codes );
1630 return $codes;
1631 }
1632
1633 #Check for location of an executable
1634 # @param string $loc single location to check
1635 # @param array $names filenames to check for.
1636 # @param mixed $versioninfo array of details to use when checking version, use false for no version checking
1637 function locate_executable($loc, $names, $versioninfo = false) {
1638 if (!is_array($names))
1639 $names = array($names);
1640
1641 foreach ($names as $name) {
1642 $command = "$loc".DIRECTORY_SEPARATOR."$name";
1643 if (file_exists($command)) {
1644 if (!$versioninfo)
1645 return $command;
1646
1647 $file = str_replace('$1', $command, $versioninfo[0]);
1648 if (strstr(`$file`, $versioninfo[1]) !== false)
1649 return $command;
1650 }
1651 }
1652 return false;
1653 }
1654
1655 # Test a memcached server
1656 function testMemcachedServer( $server ) {
1657 $hostport = explode(":", $server);
1658 $errstr = false;
1659 $fp = false;
1660 if ( !function_exists( 'fsockopen' ) ) {
1661 $errstr = "Can't connect to memcached, fsockopen() not present";
1662 }
1663 if ( !$errstr && count( $hostport ) != 2 ) {
1664 $errstr = 'Please specify host and port';
1665 var_dump( $hostport );
1666 }
1667 if ( !$errstr ) {
1668 list( $host, $port ) = $hostport;
1669 $errno = 0;
1670 $fsockerr = '';
1671
1672 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1673 if ( $fp === false ) {
1674 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1675 }
1676 }
1677 if ( !$errstr ) {
1678 $command = "version\r\n";
1679 $bytes = fwrite( $fp, $command );
1680 if ( $bytes != strlen( $command ) ) {
1681 $errstr = "Cannot write to memcached socket on $host:$port";
1682 }
1683 }
1684 if ( !$errstr ) {
1685 $expected = "VERSION ";
1686 $response = fread( $fp, strlen( $expected ) );
1687 if ( $response != $expected ) {
1688 $errstr = "Didn't get correct memcached response from $host:$port";
1689 }
1690 }
1691 if ( $fp ) {
1692 fclose( $fp );
1693 }
1694 if ( !$errstr ) {
1695 echo "<li>Connected to memcached on $host:$port successfully";
1696 }
1697 return $errstr;
1698 }
1699
1700 function database_picker($conf) {
1701 global $ourdb;
1702 print "\n";
1703 foreach(array_keys($ourdb) as $db) {
1704 if ($ourdb[$db]['havedriver']) {
1705 print "<li>";
1706 aField( $conf, "DBtype", $ourdb[$db]['fullname'], 'radio', $db, 'onclick');
1707 print "</li>\n";
1708 }
1709 }
1710 print "\n";
1711 }
1712
1713 function database_switcher($db) {
1714 global $ourdb;
1715 $color = $ourdb[$db]['bgcolor'];
1716 $full = $ourdb[$db]['fullname'];
1717 print "<div id='$db' style='display:none; background: $color'>\n";
1718 print "<h3>$full specific options:</h3>\n";
1719 }
1720
1721 function printListItem( $item ) {
1722 print "<li>$item</li>";
1723 }
1724
1725 ?>
1726
1727 <div class="license">
1728 <hr>
1729 <p>This program is free software; you can redistribute it and/or modify
1730 it under the terms of the GNU General Public License as published by
1731 the Free Software Foundation; either version 2 of the License, or
1732 (at your option) any later version.</p>
1733
1734 <p>This program is distributed in the hope that it will be useful,
1735 but WITHOUT ANY WARRANTY; without even the implied warranty of
1736 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1737 GNU General Public License for more details.</p>
1738
1739 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
1740 along with this program; if not, write to the Free Software
1741 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1742 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
1743 </div>
1744
1745 </div></div></div>
1746
1747
1748 <div id="column-one">
1749 <div class="portlet" id="p-logo">
1750 <a style="background-image: url(../skins/common/images/mediawiki.png);"
1751 href="http://www.mediawiki.org/"
1752 title="Main Page"></a>
1753 </div>
1754 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
1755 <div class='portlet'><div class='pBody'>
1756 <ul>
1757 <li><strong><a href="http://www.mediawiki.org/">MediaWiki home</a></strong></li>
1758 <li><a href="../README">Readme</a></li>
1759 <li><a href="../RELEASE-NOTES">Release notes</a></li>
1760 <li><a href="../docs/">Documentation</a></li>
1761 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
1762 <li><a href="http://meta.wikimedia.org/wiki/MediaWiki_FAQ">FAQ</a></li>
1763 </ul>
1764 <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright &copy; 2001-2007 by Magnus Manske, Brion Vibber, Lee Daniel Crocker, Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
1765 </div></div>
1766 </div>
1767
1768 </div>
1769
1770 </body>
1771 </html>