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