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