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