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