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