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