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