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