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