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