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