9e7e188b2789673bb0b8e8fd17f6deea0b243680
[lhc/web/wiklou.git] / config / Installer.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 if( !defined( 'MEDIAWIKI_INSTALL' ) ) {
23 die( 'Not an entry point.' );
24 }
25
26 error_reporting( E_ALL | E_STRICT );
27 header( "Content-type: text/html; charset=utf-8" );
28 @ini_set( "display_errors", true );
29
30 # In case of errors, let output be clean.
31 $wgRequestTime = microtime( true );
32
33 // Run version checks before including other files
34 // so people don't see a scary parse error.
35 require_once( "$IP/maintenance/install-utils.inc" );
36 install_version_checks();
37
38 require_once( "$IP/includes/Defines.php" );
39 require_once( "$IP/includes/DefaultSettings.php" );
40 require_once( "$IP/includes/AutoLoader.php" );
41 require_once( "$IP/includes/MagicWord.php" );
42 require_once( "$IP/includes/Namespace.php" );
43 require_once( "$IP/includes/ProfilerStub.php" );
44 require_once( "$IP/includes/GlobalFunctions.php" );
45 require_once( "$IP/includes/Hooks.php" );
46 require_once( "$IP/includes/Exception.php" );
47 require_once( "$IP/includes/json/Services_JSON.php" );
48 require_once( "$IP/includes/json/FormatJson.php" );
49
50 # If we get an exception, the user needs to know
51 # all the details
52 $wgShowExceptionDetails = true;
53 $wgShowSQLErrors = true;
54 wfInstallExceptionHandler();
55 ## Databases we support:
56
57 $ourdb = array();
58
59 $ourdb['mysql'] = array(
60 'fullname' => 'MySQL',
61 'havedriver' => 0,
62 'compile' => 'mysql',
63 'bgcolor' => '#ffe5a7',
64 'rootuser' => 'root',
65 'serverless' => false
66 );
67
68 $ourdb['postgres'] = array(
69 'fullname' => 'PostgreSQL',
70 'havedriver' => 0,
71 'compile' => 'pgsql',
72 'bgcolor' => '#aaccff',
73 'rootuser' => 'postgres',
74 'serverless' => false
75 );
76
77 $ourdb['sqlite'] = array(
78 'fullname' => 'SQLite',
79 'havedriver' => 0,
80 'compile' => 'pdo_sqlite',
81 'bgcolor' => '#b1ebb1',
82 'rootuser' => '',
83 'serverless' => true
84 );
85
86 $ourdb['mssql'] = array(
87 'fullname' => 'MSSQL',
88 'havedriver' => 0,
89 'compile' => 'mssql_not_ready', # Change to 'mssql' after includes/DatabaseMssql.php added;
90 'bgcolor' => '#ffc0cb',
91 'rootuser' => 'administrator',
92 'serverless' => false
93 );
94
95 $ourdb['ibm_db2'] = array(
96 'fullname' => 'DB2',
97 'havedriver' => 0,
98 'compile' => 'ibm_db2',
99 'bgcolor' => '#ffeba1',
100 'rootuser' => 'db2admin',
101 'serverless' => false
102 );
103
104 $ourdb['oracle'] = array(
105 'fullname' => 'Oracle',
106 'havedriver' => 0,
107 'compile' => 'oci8',
108 'bgcolor' => '#ffeba1',
109 'rootuser' => 'sys',
110 'serverless' => false
111 );
112
113 ?>
114 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
115 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
116 <head>
117 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
118 <meta name="robots" content="noindex,nofollow"/>
119 <title>MediaWiki <?php echo htmlspecialchars( $wgVersion ); ?> Installation</title>
120 <style type="text/css">
121
122 @import "../skins/monobook/main.css";
123
124 .env-check {
125 font-size: 90%;
126 margin: 1em 0 1em 2.5em;
127 }
128
129 .config-section {
130 margin-top: 2em;
131 }
132
133 .config-section label.column {
134 clear: left;
135 font-weight: bold;
136 width: 13em;
137 float: left;
138 text-align: right;
139 padding-right: 1em;
140 padding-top: .2em;
141 }
142
143 .config-input {
144 clear: left;
145 zoom: 100%; /* IE hack */
146 }
147
148 .config-section .config-desc {
149 clear: left;
150 margin: 0 0 2em 18em;
151 padding-top: 1em;
152 font-size: 85%;
153 }
154
155 .iput-text, .iput-password {
156 width: 14em;
157 margin-right: 1em;
158 }
159
160 .error {
161 color: red;
162 background-color: #fff;
163 font-weight: bold;
164 left: 1em;
165 font-size: 100%;
166 }
167
168 .error-top {
169 color: red;
170 background-color: #FFF0F0;
171 border: 2px solid red;
172 font-size: 130%;
173 font-weight: bold;
174 padding: 1em 1.5em;
175 margin: 2em 0 1em;
176 }
177
178 ul.plain {
179 list-style-type: none;
180 list-style-image: none;
181 float: left;
182 margin: 0;
183 padding: 0;
184 }
185
186 .btn-install {
187 font-weight: bold;
188 font-size: 110%;
189 padding: .2em .3em;
190 }
191
192 .license {
193 font-size: 85%;
194 padding-top: 3em;
195 }
196
197 span.success-message {
198 font-weight: bold;
199 font-size: 110%;
200 color: green;
201 }
202
203 .success-box {
204 font-size: 130%;
205 }
206
207 </style>
208 <script type="text/javascript">
209 <!--
210 <?php echo 'var databases = ' . FormatJson::encode( $ourdb ) . ';'; ?>
211
212 function show(id, showOrHide) {
213 var i = document.getElementById(id);
214 if (i) i.style.display = showOrHide ? 'block' : 'none';
215 }
216 function hideall() {
217 for (db in databases) {
218 show(db, false);
219 }
220 }
221 function toggleDBarea(id, defaultroot) {
222 hideall();
223 var dbarea = document.getElementById(id);
224 if (dbarea) dbarea.style.display = (dbarea.style.display == 'none') ? 'block' : 'none';
225 var db = document.getElementById('RootUser');
226 db.value = databases[id].rootuser;
227 show('db-server-settings1', !databases[id].serverless);
228 show('db-server-settings2', !databases[id].serverless);
229 }
230 // -->
231 </script>
232 </head>
233
234 <body>
235 <div id="globalWrapper">
236 <div id="column-content">
237 <div id="content">
238 <div id="bodyContent">
239
240 <h1>MediaWiki <?php print htmlspecialchars( $wgVersion ) ?> Installation</h1>
241
242 <?php
243 $mainListOpened = false; # Is the main list (environement checking) opend ? Used by dieout
244
245 /* Check for existing configurations and bug out! */
246
247 if( file_exists( "../LocalSettings.php" ) ) {
248 $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
249 dieout( "<p><strong>Setup has completed, <a href='../$script'>your wiki</a> is configured.</strong></p>
250 <p>Please delete the /config directory for extra security.</p>" );
251 }
252
253 if( file_exists( "./LocalSettings.php" ) ) {
254 writeSuccessMessage();
255 dieout( '' );
256 }
257
258 if( !is_writable( "." ) ) {
259 dieout( "<h2>Can't write config file, aborting</h2>
260
261 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
262 writable by the web server. Once configuration is done you'll move the created
263 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
264 then remove the <tt>config</tt> subdirectory entirely.</p>
265
266 <p>To make the directory writable on a Unix/Linux system:</p>
267
268 <pre>
269 cd <i>" . htmlspecialchars( dirname( dirname( __FILE__ ) ) ) . "</i>
270 chmod a+w config
271 </pre>
272
273 <p>Afterwards retry to start the <a href=\"\">setup</a>.</p>" );
274 }
275
276
277 require_once( "$IP/maintenance/updaters.inc" );
278
279 class ConfigData {
280 function getEncoded( $data ) {
281 # removing latin1 support, no need...
282 return $data;
283 }
284 function getSitename() { return $this->getEncoded( $this->Sitename ); }
285 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
286 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
287
288 function setSchema( $schema, $engine ) {
289 $this->DBschema = $schema;
290 if ( !preg_match( '/^\w*$/', $engine ) ){
291 $engine = 'InnoDB';
292 }
293 switch ( $this->DBschema ) {
294 case 'mysql5':
295 $this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=utf8";
296 $this->DBmysql5 = 'true';
297 break;
298 case 'mysql5-binary':
299 $this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=binary";
300 $this->DBmysql5 = 'true';
301 break;
302 default:
303 $this->DBTableOptions = "TYPE=$engine";
304 $this->DBmysql5 = 'false';
305 }
306 $this->DBengine = $engine;
307
308 # Set the global for use during install
309 global $wgDBTableOptions;
310 $wgDBTableOptions = $this->DBTableOptions;
311 }
312 }
313
314 ?>
315
316 <ul>
317 <li>
318 <b>Don't forget security updates!</b> Keep an eye on the
319 <a href="http://lists.wikimedia.org/mailman/listinfo/mediawiki-announce">low-traffic
320 release announcements mailing list</a>.
321 </li>
322 </ul>
323
324
325 <h2>Checking environment...</h2>
326 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
327 <ul class="env-check">
328 <?php
329 $mainListOpened = true;
330
331 $endl = "
332 ";
333 define( 'MW_NO_OUTPUT_BUFFER', 1 );
334 $conf = new ConfigData;
335
336 install_version_checks();
337 $self = 'Installer'; # Maintenance script name, to please Setup.php
338
339 print "<li>PHP " . htmlspecialchars( phpversion() ) . " installed</li>\n";
340
341 error_reporting( 0 );
342 $phpdatabases = array();
343 foreach (array_keys($ourdb) as $db) {
344 $compname = $ourdb[$db]['compile'];
345 if( extension_loaded( $compname ) || ( mw_have_dl() && dl( "{$compname}." . PHP_SHLIB_SUFFIX ) ) ) {
346 array_push($phpdatabases, $db);
347 $ourdb[$db]['havedriver'] = 1;
348 }
349 }
350 error_reporting( E_ALL | E_STRICT );
351
352 if (!$phpdatabases) {
353 print "Could not find a suitable database driver!<ul>";
354 foreach (array_keys($ourdb) AS $db) {
355 $comp = $ourdb[$db]['compile'];
356 $full = $ourdb[$db]['fullname'];
357 print "<li>For <b>$full</b>, compile PHP using <b>--with-$comp</b>, "
358 ."or install the $comp.so module</li>\n";
359 }
360 echo '</ul>';
361 dieout( '' );
362 }
363
364 print "<li>Found database drivers for:";
365 $DefaultDBtype = '';
366 foreach (array_keys($ourdb) AS $db) {
367 if ($ourdb[$db]['havedriver']) {
368 if ( $DefaultDBtype == '' ) {
369 $DefaultDBtype = $db;
370 }
371 print " ".$ourdb[$db]['fullname'];
372 }
373 }
374 print "</li>\n";
375
376 if( wfIniGetBool( "register_globals" ) ) {
377 ?>
378 <li>
379 <div style="font-size:110%">
380 <strong class="error">Warning:</strong>
381 <strong>PHP's <tt><a href="http://php.net/register_globals">register_globals</a></tt> option is enabled. Disable it if you can.</strong>
382 </div>
383 MediaWiki will work, but your server is more exposed to PHP-based security vulnerabilities.
384 </li>
385 <?php
386 }
387
388 $fatal = false;
389
390 if( wfIniGetBool( "magic_quotes_runtime" ) ) {
391 $fatal = true;
392 ?><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>
393 This option corrupts data input unpredictably; you cannot install or use
394 MediaWiki unless this option is disabled.</li>
395 <?php
396 }
397
398 if( wfIniGetBool( "magic_quotes_sybase" ) ) {
399 $fatal = true;
400 ?><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>
401 This option corrupts data input unpredictably; you cannot install or use
402 MediaWiki unless this option is disabled.</li>
403 <?php
404 }
405
406 if( wfIniGetBool( "mbstring.func_overload" ) ) {
407 $fatal = true;
408 ?><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>
409 This option causes errors and may corrupt data unpredictably;
410 you cannot install or use MediaWiki unless this option is disabled.</li>
411 <?php
412 }
413
414 if( wfIniGetBool( "zend.ze1_compatibility_mode" ) ) {
415 $fatal = true;
416 ?><li class="error"><strong>Fatal: <a href="http://www.php.net/manual/en/ini.core.php">zend.ze1_compatibility_mode</a> is active!</strong>
417 This option causes horrible bugs with MediaWiki; you cannot install or use
418 MediaWiki unless this option is disabled.</li>
419 <?php
420 }
421
422
423 if( $fatal ) {
424 dieout( "Cannot install MediaWiki." );
425 }
426
427 if( wfIniGetBool( "safe_mode" ) ) {
428 $conf->safeMode = true;
429 ?>
430 <li><b class='error'>Warning:</b> <strong>PHP's
431 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active.</strong>
432 You may have problems caused by this, particularly if using image uploads.
433 </li>
434 <?php
435 } else {
436 $conf->safeMode = false;
437 }
438
439 $sapi = htmlspecialchars( php_sapi_name() );
440 print "<li>PHP server API is $sapi; ";
441 $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
442 if( $wgUsePathInfo ) {
443 print "ok, using pretty URLs (<tt>$script/Page_Title</tt>)";
444 } else {
445 print "using ugly URLs (<tt>$script?title=Page_Title</tt>)";
446 }
447 print "</li>\n";
448
449 $conf->xml = function_exists( "utf8_encode" );
450 if( $conf->xml ) {
451 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
452 } else {
453 dieout( "PHP's XML module is missing; the wiki requires functions in
454 this module and won't work in this configuration.
455 If you're running Mandrake, install the php-xml package." );
456 }
457
458 # Check for session support
459 if( !function_exists( 'session_name' ) )
460 dieout( "PHP's session module is missing. MediaWiki requires session support in order to function." );
461
462 # session.save_path doesn't *have* to be set, but if it is, and it's
463 # not valid/writable/etc. then it can cause problems
464 $sessionSavePath = mw_get_session_save_path();
465 $ssp = htmlspecialchars( $sessionSavePath );
466 # Warn the user if it's not set, but let them proceed
467 if( !$sessionSavePath ) {
468 print "<li><strong>Warning:</strong> A value for <tt>session.save_path</tt>
469 has not been set in PHP.ini. If the default value causes problems with
470 saving session data, set it to a valid path which is read/write/execute
471 for the user your web server is running under.</li>";
472 } elseif ( is_dir( $sessionSavePath ) && is_writable( $sessionSavePath ) ) {
473 # All good? Let the user know
474 print "<li>Session save path (<tt>{$ssp}</tt>) appears to be valid.</li>";
475 } else {
476 # Something not right? Warn the user, but let them proceed
477 print "<li><strong>Warning:</strong> Your <tt>session.save_path</tt> value (<tt>{$ssp}</tt>)
478 appears to be invalid or is not writable. PHP needs to be able to save data to
479 this location for correct session operation.</li>";
480 }
481
482 # Check for PCRE support
483 if( !function_exists( 'preg_match' ) )
484 dieout( "The PCRE support module appears to be missing. MediaWiki requires the
485 Perl-compatible regular expression functions." );
486
487 # The installer can take a while, and we really don't want it to time out
488 wfSuppressWarnings();
489 set_time_limit( 0 );
490 wfRestoreWarnings();
491
492 $memlimit = ini_get( "memory_limit" );
493 if( $memlimit == -1 ) {
494 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
495 } else {
496 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ). " bytes. ";
497 $newlimit = wfMemoryLimit();
498 $memlimit = wfShorthandToInteger( $memlimit );
499 if( $newlimit < $memlimit ) {
500 print "<b>Failed raising limit, installation may fail.</b>";
501 } elseif ( $newlimit > $memlimit ) {
502 print "Raised <tt>memory_limit</tt> to " . htmlspecialchars( $newlimit ) . " bytes. ";
503 }
504 print "</li>\n";
505 }
506
507 $conf->turck = function_exists( 'mmcache_get' );
508 if ( $conf->turck ) {
509 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
510 }
511
512 $conf->xcache = function_exists( 'xcache_get' );
513 if( $conf->xcache )
514 print "<li><a href=\"http://trac.lighttpd.net/xcache/\">XCache</a> installed</li>\n";
515
516 $conf->apc = function_exists('apc_fetch');
517 if ($conf->apc ) {
518 print "<li><a href=\"http://www.php.net/apc\">APC</a> installed</li>\n";
519 }
520
521 $conf->eaccel = function_exists( 'eaccelerator_get' );
522 if ( $conf->eaccel ) {
523 $conf->turck = 'eaccelerator';
524 print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
525 }
526
527 $conf->dba = function_exists( 'dba_open' );
528
529 if( !( $conf->turck || $conf->eaccel || $conf->apc || $conf->xcache ) ) {
530 echo( '<li>Couldn\'t find <a href="http://turck-mmcache.sourceforge.net">Turck MMCache</a>,
531 <a href="http://eaccelerator.sourceforge.net">eAccelerator</a>,
532 <a href="http://www.php.net/apc">APC</a> or <a href="http://trac.lighttpd.net/xcache/">XCache</a>;
533 cannot use these for object caching.</li>' );
534 }
535
536 $conf->phpCliPath = false;
537 $phpClilocations = array_merge(
538 array(
539 "/usr/bin",
540 "/usr/local/bin",
541 "/opt/csw/bin",
542 "/usr/gnu/bin",
543 "/usr/sfw/bin" ),
544 explode( PATH_SEPARATOR, getenv( "PATH" ) ) );
545 $phpClinames = array( "php", "php.exe" );
546 foreach ($phpClilocations as $loc) {
547 $exe = locate_executable($loc, $phpClinames);
548 if ($exe !== false) {
549 $conf->phpCliPath= $exe;
550 break;
551 }
552 }
553
554 $conf->diff3 = false;
555 $diff3locations = array_merge(
556 array(
557 "/usr/bin",
558 "/usr/local/bin",
559 "/opt/csw/bin",
560 "/usr/gnu/bin",
561 "/usr/sfw/bin" ),
562 explode( PATH_SEPARATOR, getenv( "PATH" ) ) );
563 $diff3names = array( "gdiff3", "diff3", "diff3.exe" );
564
565 $diff3versioninfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
566 foreach ($diff3locations as $loc) {
567 $exe = locate_executable($loc, $diff3names, $diff3versioninfo);
568 if ($exe !== false) {
569 $conf->diff3 = $exe;
570 break;
571 }
572 }
573
574 if ($conf->diff3)
575 print "<li>Found GNU diff3: <tt>$conf->diff3</tt>.</li>";
576 else
577 print "<li>GNU diff3 not found.</li>";
578
579 $conf->ImageMagick = false;
580 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
581 foreach( $imcheck as $dir ) {
582 $im = "$dir/convert";
583 if( @file_exists( $im ) ) {
584 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
585 $conf->ImageMagick = $im;
586 break;
587 }
588 }
589
590 $conf->HaveGD = function_exists( "imagejpeg" );
591 if( $conf->HaveGD ) {
592 print "<li>Found GD graphics library built-in";
593 if( !$conf->ImageMagick ) {
594 print ", image thumbnailing will be enabled if you enable uploads";
595 }
596 print ".</li>\n";
597 } else {
598 if( !$conf->ImageMagick ) {
599 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
600 }
601 }
602
603 $conf->IP = dirname( dirname( __FILE__ ) );
604 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
605
606
607 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
608 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
609 // to get the path to the current script... hopefully it's reliable. SIGH
610 $path = ($_SERVER["PHP_SELF"] === '')
611 ? $_SERVER["SCRIPT_NAME"]
612 : $_SERVER["PHP_SELF"];
613
614 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $path );
615 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
616
617
618
619 // We may be installing from *.php5 extension file, if so, print message
620 $conf->ScriptExtension = '.php';
621 if (defined('MW_INSTALL_PHP5_EXT')) {
622 $conf->ScriptExtension = '.php5';
623 print "<li>Installing MediaWiki with <tt>php5</tt> file extensions</li>\n";
624 } else {
625 print "<li>Installing MediaWiki with <tt>php</tt> file extensions</li>\n";
626 }
627
628
629 print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\n";
630 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
631
632 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
633 $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
634 ? 'root@localhost'
635 : $_SERVER["SERVER_ADMIN"];
636 $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
637 $conf->DBtype = importPost( "DBtype", $DefaultDBtype );
638 if ( !isset( $ourdb[$conf->DBtype] ) ) {
639 $conf->DBtype = $DefaultDBtype;
640 }
641
642 $conf->DBserver = importPost( "DBserver", "localhost" );
643 $conf->DBname = importPost( "DBname", "wikidb" );
644 $conf->DBuser = importPost( "DBuser", "wikiuser" );
645 $conf->DBpassword = importPost( "DBpassword" );
646 $conf->DBpassword2 = importPost( "DBpassword2" );
647 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
648 $conf->SysopPass = importPost( "SysopPass" );
649 $conf->SysopPass2 = importPost( "SysopPass2" );
650 $conf->RootUser = importPost( "RootUser", "root" );
651 $conf->RootPW = importPost( "RootPW", "" );
652 $useRoot = importCheck( 'useroot', false );
653 $conf->LanguageCode = importPost( "LanguageCode", "en" );
654 ## MySQL specific:
655 $conf->DBprefix = importPost( "DBprefix" );
656 $conf->setSchema(
657 importPost( "DBschema", "mysql5-binary" ),
658 importPost( "DBengine", "InnoDB" ) );
659
660 ## Postgres specific:
661 $conf->DBport = importPost( "DBport", "5432" );
662 $conf->DBts2schema = importPost( "DBts2schema", "public" );
663 $conf->DBpgschema = importPost( "DBpgschema", "mediawiki" );
664
665 ## SQLite specific
666 $conf->SQLiteDataDir = importPost( "SQLiteDataDir", "" );
667
668 ## MSSQL specific
669 // We need a second field so it doesn't overwrite the MySQL one
670 $conf->DBprefix2 = importPost( "DBprefix2" );
671
672 ## DB2 specific:
673 // New variable in order to have a different default port number
674 $conf->DBport_db2 = importPost( "DBport_db2", "50000" );
675 $conf->DBcataloged = importPost( "DBcataloged", "cataloged" );
676 $conf->DBdb2schema = importPost( "DBdb2schema", "mediawiki" );
677
678 // Oracle specific
679 $conf->DBprefix_ora = importPost( "DBprefix_ora" );
680 $conf->DBdefTS_ora = importPost( "DBdefTS_ora", "USERS" );
681 $conf->DBtempTS_ora = importPost( "DBtempTS_ora", "TEMP" );
682
683 $conf->ShellLocale = getShellLocale( $conf->LanguageCode );
684
685 /* Check for validity */
686 $errs = array();
687
688 if( preg_match( '/^$|^mediawiki$|#/i', $conf->Sitename ) ) {
689 $errs["Sitename"] = "Must not be blank or \"MediaWiki\" and may not contain \"#\"";
690 }
691 if( !$ourdb[$conf->DBtype]['serverless'] ) {
692 if( $conf->DBuser == "" ) {
693 $errs["DBuser"] = "Must not be blank";
694 }
695 if( ($conf->DBtype == 'mysql') && (strlen($conf->DBuser) > 16) ) {
696 $errs["DBuser"] = "Username too long";
697 }
698 if( $conf->DBpassword == "" && $conf->DBtype != "postgres" ) {
699 $errs["DBpassword"] = "Must not be blank";
700 }
701 if( $conf->DBpassword != $conf->DBpassword2 ) {
702 $errs["DBpassword2"] = "Passwords don't match!";
703 }
704 }
705 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
706 $errs["DBprefix"] = "Invalid table prefix";
707 } else {
708 untaint( $conf->DBprefix, TC_MYSQL );
709 }
710 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix_ora ) ) {
711 $errs["DBprefix_ora"] = "Invalid table prefix";
712 }
713
714 error_reporting( E_ALL | E_STRICT );
715
716 /**
717 * Initialise $wgLang and $wgContLang to something so we can
718 * call case-folding methods. Per Brion, this is English for
719 * now, although we could be clever and initialise to the
720 * user-selected language.
721 */
722 $wgContLang = Language::factory( 'en' );
723 $wgLang = $wgContLang;
724
725 /**
726 * We're messing about with users, so we need a stub
727 * authentication plugin...
728 */
729 $wgAuth = new AuthPlugin();
730
731 /**
732 * Validate the initial administrator account; username,
733 * password checks, etc.
734 */
735 if( $conf->SysopName ) {
736 # Check that the user can be created
737 $u = User::newFromName( $conf->SysopName );
738 if( $u instanceof User ) {
739 # Various password checks
740 if( $conf->SysopPass != '' ) {
741 if( $conf->SysopPass == $conf->SysopPass2 ) {
742 if( !$u->isValidPassword( $conf->SysopPass ) ) {
743 $errs['SysopPass'] = "Bad password";
744 }
745 } else {
746 $errs['SysopPass2'] = "Passwords don't match";
747 }
748 } else {
749 $errs['SysopPass'] = "Cannot be blank";
750 }
751 unset( $u );
752 } else {
753 $errs['SysopName'] = "Bad username";
754 }
755 }
756
757 $conf->License = importRequest( "License", "none" );
758 if( $conf->License == "gfdl1_2" ) {
759 $conf->RightsUrl = "http://www.gnu.org/licenses/old-licenses/fdl-1.2.txt";
760 $conf->RightsText = "GNU Free Documentation License 1.2";
761 $conf->RightsCode = "gfdl1_2";
762 $conf->RightsIcon = '${wgScriptPath}/skins/common/images/gnu-fdl.png';
763 } elseif( $conf->License == "gfdl1_3" ) {
764 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
765 $conf->RightsText = "GNU Free Documentation License 1.3";
766 $conf->RightsCode = "gfdl1_3";
767 $conf->RightsIcon = '${wgScriptPath}/skins/common/images/gnu-fdl.png';
768 } elseif( $conf->License == "none" ) {
769 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
770 } elseif( $conf->License == "pd" ) {
771 $conf->RightsUrl = "http://creativecommons.org/licenses/publicdomain/";
772 $conf->RightsText = "Public Domain";
773 $conf->RightsCode = "pd";
774 $conf->RightsIcon = '${wgScriptPath}/skins/common/images/public-domain.png';
775 } else {
776 $conf->RightsUrl = importRequest( "RightsUrl", "" );
777 $conf->RightsText = importRequest( "RightsText", "" );
778 $conf->RightsCode = importRequest( "RightsCode", "" );
779 $conf->RightsIcon = importRequest( "RightsIcon", "" );
780 }
781
782 $conf->Shm = importRequest( "Shm", "none" );
783 $conf->MCServers = importRequest( "MCServers" );
784
785 /* Test memcached servers */
786
787 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
788 $conf->MCServerArray = wfArrayMap( 'trim', explode( ',', $conf->MCServers ) );
789 foreach ( $conf->MCServerArray as $server ) {
790 $error = testMemcachedServer( $server );
791 if ( $error ) {
792 $errs["MCServers"] = $error;
793 break;
794 }
795 }
796 } else if ( $conf->Shm == 'memcached' ) {
797 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
798 }
799
800 /* default values for installation */
801 $conf->Email = importRequest("Email", "email_enabled");
802 $conf->Emailuser = importRequest("Emailuser", "emailuser_enabled");
803 $conf->Enotif = importRequest("Enotif", "enotif_allpages");
804 $conf->Eauthent = importRequest("Eauthent", "eauthent_enabled");
805
806 if( $conf->posted && ( 0 == count( $errs ) ) ) {
807 do { /* So we can 'continue' to end prematurely */
808 $conf->Root = ($conf->RootPW != "");
809
810 /* Load up the settings and get installin' */
811 $local = writeLocalSettings( $conf );
812 echo "<li style=\"list-style: none\">\n";
813 echo "<p><b>Generating configuration file...</b></p>\n";
814 echo "</li>\n";
815
816 $wgCommandLineMode = false;
817 chdir( ".." );
818 $ok = eval( $local );
819 if( $ok === false ) {
820 dieout( "<p>Errors in generated configuration; " .
821 "most likely due to a bug in the installer... " .
822 "Config file was: </p>" .
823 "<pre>" .
824 htmlspecialchars( $local ) .
825 "</pre>" );
826 }
827 $conf->DBtypename = '';
828 foreach (array_keys($ourdb) as $db) {
829 if ($conf->DBtype === $db)
830 $conf->DBtypename = $ourdb[$db]['fullname'];
831 }
832 if ( ! strlen($conf->DBtype)) {
833 $errs["DBpicktype"] = "Please choose a database type";
834 continue;
835 }
836
837 if (! $conf->DBtypename) {
838 $errs["DBtype"] = "Unknown database type '$conf->DBtype'";
839 continue;
840 }
841 print "<li>Database type: " . htmlspecialchars( $conf->DBtypename ) . "</li>\n";
842 $dbclass = 'Database'.ucfirst($conf->DBtype);
843 $wgDBtype = $conf->DBtype;
844 $wgDBadminuser = "root";
845 $wgDBadminpassword = $conf->RootPW;
846
847 ## Mysql specific:
848 $wgDBprefix = $conf->DBprefix;
849
850 ## Postgres specific:
851 $wgDBport = $conf->DBport;
852 $wgDBts2schema = $conf->DBts2schema;
853
854 if( $wgDBtype == 'postgres' ) {
855 $wgDBmwschema = $conf->DBpgschema;
856 } elseif ( $wgDBtype == 'ibm_db2' ) {
857 $wgDBmwschema = $conf->DBdb2schema;
858 }
859
860 if( $conf->DBprefix2 != '' ) {
861 // For MSSQL
862 $wgDBprefix = $conf->DBprefix2;
863 } elseif( $conf->DBprefix_ora != '' ) {
864 // For Oracle
865 $wgDBprefix = $conf->DBprefix_ora;
866 }
867
868 ## DB2 specific:
869 $wgDBcataloged = $conf->DBcataloged;
870
871 $wgCommandLineMode = true;
872 if (! defined ( 'STDERR' ) )
873 define( 'STDERR', fopen("php://stderr", "wb"));
874 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
875 require_once( "$IP/includes/Setup.php" );
876 Language::getLocalisationCache()->disableBackend();
877
878 chdir( "config" );
879
880 $wgTitle = Title::newFromText( "Installation script" );
881 error_reporting( E_ALL | E_STRICT );
882 print "<li>Loading class: " . htmlspecialchars( $dbclass ) . "</li>\n";
883 if ( $conf->DBtype != 'sqlite' ) {
884 $dbc = new $dbclass;
885 }
886
887 if( $conf->DBtype == 'mysql' ) {
888 $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
889 if( $mysqlOldClient ) {
890 print "<li><b>PHP is linked with old MySQL client libraries. If you are
891 using a MySQL 4.1 server and have problems connecting to the database,
892 see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
893 >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
894 }
895 $ok = true; # Let's be optimistic
896
897 # Decide if we're going to use the superuser or the regular database user
898 $conf->Root = $useRoot;
899 if( $conf->Root ) {
900 $db_user = $conf->RootUser;
901 $db_pass = $conf->RootPW;
902 } else {
903 $db_user = $wgDBuser;
904 $db_pass = $wgDBpassword;
905 }
906
907 # Attempt to connect
908 echo( "<li>Attempting to connect to database server as " . htmlspecialchars( $db_user ) . "..." );
909 $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
910
911 # Check the connection and respond to errors
912 if( $wgDatabase->isOpen() ) {
913 # Seems OK
914 $ok = true;
915 $wgDBadminuser = $db_user;
916 $wgDBadminpassword = $db_pass;
917 echo( "success.</li>\n" );
918 $wgDatabase->ignoreErrors( true );
919 $myver = $wgDatabase->getServerVersion();
920 } else {
921 # There were errors, report them and back out
922 $ok = false;
923 $errno = mysql_errno();
924 $errtx = htmlspecialchars( mysql_error() );
925 switch( $errno ) {
926 case 1045:
927 case 2000:
928 echo( "failed due to authentication errors. Check passwords.</li>" );
929 if( $conf->Root ) {
930 # The superuser details are wrong
931 $errs["RootUser"] = "Check username";
932 $errs["RootPW"] = "and password";
933 } else {
934 # The regular user details are wrong
935 $errs["DBuser"] = "Check username";
936 $errs["DBpassword"] = "and password";
937 }
938 break;
939 case 2002:
940 case 2003:
941 default:
942 # General connection problem
943 echo( htmlspecialchars( "failed with error [$errno] $errtx." ) . "</li>\n" );
944 $errs["DBserver"] = "Connection failed";
945 break;
946 } # switch
947 } #conn. att.
948
949 if( !$ok ) { continue; }
950 }
951 else if( $conf->DBtype == 'ibm_db2' ) {
952 if( $useRoot ) {
953 $db_user = $conf->RootUser;
954 $db_pass = $conf->RootPW;
955 } else {
956 $db_user = $wgDBuser;
957 $db_pass = $wgDBpassword;
958 }
959
960 echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) .
961 "\" as \"" . htmlspecialchars( $db_user ) . "\"..." );
962 $wgDatabase = $dbc->newFromParams($wgDBserver, $db_user, $db_pass, $wgDBname, 1);
963 // enable extra debug messages
964 $dbc->setMode(DatabaseIbm_db2::INSTALL_MODE);
965 $wgDatabase->setMode(DatabaseIbm_db2::INSTALL_MODE);
966
967 if (!$wgDatabase->isOpen()) {
968 print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
969 } else {
970 $myver = $wgDatabase->getServerVersion();
971 }
972 if (is_callable(array($wgDatabase, 'initial_setup'))) $wgDatabase->initial_setup('', $wgDBname);
973
974 } elseif ( $conf->DBtype == 'sqlite' ) {
975 if ("$wgSQLiteDataDir" == '') {
976 $wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data';
977 }
978 echo '<li>Attempting to connect to SQLite database at "' .
979 htmlspecialchars( $wgSQLiteDataDir ) . '": ';
980 if ( !is_dir( $wgSQLiteDataDir ) ) {
981 if ( is_writable( dirname( $wgSQLiteDataDir ) ) ) {
982 $ok = wfMkdirParents( $wgSQLiteDataDir, $wgSQLiteDataDirMode );
983 } else {
984 $ok = false;
985 }
986 if ( !$ok ) {
987 echo "cannot create data directory</li>";
988 $errs['SQLiteDataDir'] = 'Enter a valid data directory';
989 continue;
990 }
991 }
992 if ( !is_writable( $wgSQLiteDataDir ) ) {
993 echo "data directory not writable</li>";
994 $errs['SQLiteDataDir'] = 'Enter a writable data directory';
995 continue;
996 }
997 $dataFile = DatabaseSqlite::generateFileName( $wgSQLiteDataDir, $wgDBname );
998 if ( file_exists( $dataFile ) ) {
999 if ( !is_writable( $dataFile ) ) {
1000 echo "data file not writable</li>";
1001 $errs['SQLiteDataDir'] = basename( $dataFile ) . " is not writable";
1002 continue;
1003 }
1004 } else {
1005 if ( file_put_contents( $dataFile, '' ) === false ) {
1006 echo 'could not create database file "' . htmlspecialchars( basename( $dataFile ) ) . "\"</li>\n";
1007 $errs['SQLiteDataDir'] = "couldn't create " . basename( $dataFile );
1008 continue;
1009 }
1010 }
1011 try {
1012 $wgDatabase = new DatabaseSqlite( false, false, false, $wgDBname, 1 );
1013 }
1014 catch( MWException $ex ) {
1015 echo 'error: ' . htmlspecialchars( $ex->getMessage() ) . "</li>\n";
1016 continue;
1017 }
1018
1019 if (!$wgDatabase->isOpen()) {
1020 print "error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
1021 $errs['SQLiteDataDir'] = 'Could not connect to database';
1022 continue;
1023 } else {
1024 $myver = $wgDatabase->getServerVersion();
1025 }
1026 if (is_callable(array($wgDatabase, 'initial_setup'))) $wgDatabase->initial_setup('', $wgDBname);
1027 echo "ok</li>\n";
1028 } elseif ( $conf->DBtype == 'oracle' ) {
1029 echo "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) ."\"</li>";
1030 $old_error_level = error_reporting();
1031 error_reporting($old_error_level & ~E_WARNING); //disable E_WARNING for test connect (oci returns login denied as warning)
1032 $wgDatabase = $dbc->newFromParams('DUMMY', $wgDBuser, $wgDBpassword, $wgDBname, 1);
1033 error_reporting($old_error_level);
1034 if (!$wgDatabase->isOpen()) {
1035 $ok = true;
1036 echo "<li>Connect failed.</li>";
1037 if ($useRoot) {
1038 if (ini_get('oci8.privileged_connect') === false) {
1039 echo "<li>Privileged connect disabled, please set oci8.privileged_connect or run maintenance/ora/user.sql script manually prior to continuing.</li>";
1040 $ok = false;
1041 } else {
1042 $wgDBadminuser = $conf->RootUser;
1043 $wgDBadminpassword = $conf->RootPW;
1044 echo "<li>Attempting to create DB user.</li>";
1045 $wgDatabase = $dbc->newFromParams('DUMMY', $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1, 64);
1046 if ($wgDatabase->isOpen()) {
1047 $wgDBOracleDefTS = $conf->DBdefTS_ora;
1048 $wgDBOracleTempTS = $conf->DBtempTS_ora;
1049 $wgDatabase->sourceFile( "../maintenance/ora/user.sql" );
1050 } else {
1051 echo "<li>Invalid database superuser, please supply a valid superuser account.</li>";
1052 echo "<li>ERR: ".print_r(oci_error(), true)."</li>";
1053 $ok = false;
1054 }
1055 }
1056 } else {
1057 echo "<li>Database superuser missing, please supply a valid superuser account.</li>";
1058 $ok = false;
1059 }
1060 if (!$ok) {
1061 $errs["RootUser"] = "Check username";
1062 $errs["RootPW"] = "and password";
1063 } else {
1064 echo "<li>Attempting to connect to database with new user \"" . htmlspecialchars( $wgDBname ) ."\"</li>";
1065 $wgDatabase = $dbc->newFromParams('DUMMY', $wgDBuser, $wgDBpassword, $wgDBname, 1);
1066 }
1067 }
1068 if ($ok) {
1069 $myver = $wgDatabase->getServerVersion();
1070 }
1071 } else { # not mysql
1072 error_reporting( E_ALL | E_STRICT );
1073 $wgSuperUser = '';
1074 ## Possible connect as a superuser
1075 // Changed !mysql to postgres check since it seems to only apply to postgres
1076 if( $useRoot && $conf->DBtype == 'postgres' ) {
1077 $wgDBsuperuser = $conf->RootUser;
1078 echo( "<li>Attempting to connect to database \"postgres\" as superuser \"" .
1079 htmlspecialchars( $wgDBsuperuser ) . "\"..." );
1080 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
1081 if (!$wgDatabase->isOpen()) {
1082 print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
1083 $errs["DBserver"] = "Could not connect to database as superuser";
1084 $errs["RootUser"] = "Check username";
1085 $errs["RootPW"] = "and password";
1086 continue;
1087 }
1088 $wgDatabase->initial_setup($conf->RootPW, 'postgres');
1089 }
1090 echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) .
1091 "\" as \"" . htmlspecialchars( $wgDBuser ) . "\"..." );
1092 $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1);
1093 if (!$wgDatabase->isOpen()) {
1094 print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
1095 $errs["DBserver"] = "Could not connect to database as user";
1096 $errs["DBuser"] = "Check username";
1097 $errs["DBpassword"] = "and password";
1098 continue;
1099 } else {
1100 $myver = $wgDatabase->getServerVersion();
1101 }
1102 if (is_callable(array($wgDatabase, 'initial_setup'))) $wgDatabase->initial_setup('', $wgDBname);
1103 }
1104
1105 if ( !$wgDatabase->isOpen() ) {
1106 $errs["DBserver"] = "Couldn't connect to database";
1107 continue;
1108 }
1109
1110 print "<li>Connected to " . htmlspecialchars( "{$conf->DBtype} $myver" );
1111 if ($conf->DBtype == 'mysql') {
1112 if( version_compare( $myver, "4.0.14" ) < 0 ) {
1113 print "</li>\n";
1114 dieout( "-- mysql 4.0.14 or later required. Aborting." );
1115 }
1116 $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
1117 if( $mysqlNewAuth && $mysqlOldClient ) {
1118 print "; <b class='error'>You are using MySQL 4.1 server, but PHP is linked
1119 to old client libraries; if you have trouble with authentication, see
1120 <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
1121 >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
1122 }
1123 if( $wgDBmysql5 ) {
1124 if( $mysqlNewAuth ) {
1125 print "; enabling MySQL 4.1/5.0 charset mode";
1126 } else {
1127 print "; <b class='error'>MySQL 4.1/5.0 charset mode enabled,
1128 but older version detected; will likely fail.</b>";
1129 }
1130 }
1131 print "</li>\n";
1132
1133 @$sel = $wgDatabase->selectDB( $wgDBname );
1134 if( $sel ) {
1135 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
1136 } else {
1137 $err = mysql_errno();
1138 $databaseSafe = htmlspecialchars( $wgDBname );
1139 if( $err == 1102 /* Invalid database name */ ) {
1140 print "<ul><li><strong>{$databaseSafe}</strong> is not a valid database name.</li></ul>";
1141 continue;
1142 } elseif( $err != 1049 /* Database doesn't exist */ ) {
1143 print "<ul><li>Error selecting database <strong>{$databaseSafe}</strong>: {$err} ";
1144 print htmlspecialchars( mysql_error() ) . "</li></ul>";
1145 continue;
1146 }
1147 print "<li>Attempting to create database...</li>";
1148 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
1149 if( !$res ) {
1150 print "<li>Couldn't create database <tt>" .
1151 htmlspecialchars( $wgDBname ) .
1152 "</tt>; try with root access or check your username/pass.</li>\n";
1153 $errs["RootPW"] = "<- Enter";
1154 continue;
1155 }
1156 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
1157 }
1158 $wgDatabase->selectDB( $wgDBname );
1159 }
1160 else if ($conf->DBtype == 'postgres') {
1161 if( version_compare( $myver, "8.0" ) < 0 ) {
1162 dieout( "<b>Postgres 8.0 or later is required</b>. Aborting." );
1163 }
1164 }
1165
1166 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
1167 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
1168
1169 if ( $conf->DBtype == 'mysql') {
1170 # Determine existing default character set
1171 if ( $wgDatabase->tableExists( "revision" ) ) {
1172 $revision = $wgDatabase->escapeLike( $conf->DBprefix . 'revision' );
1173 $res = $wgDatabase->query( "SHOW TABLE STATUS LIKE '$revision'" );
1174 $row = $wgDatabase->fetchObject( $res );
1175 if ( !$row ) {
1176 echo "<li>SHOW TABLE STATUS query failed!</li>\n";
1177 $existingSchema = false;
1178 $existingEngine = false;
1179 } else {
1180 if ( preg_match( '/^latin1/', $row->Collation ) ) {
1181 $existingSchema = 'mysql4';
1182 } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
1183 $existingSchema = 'mysql5';
1184 } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
1185 $existingSchema = 'mysql5-binary';
1186 } else {
1187 $existingSchema = false;
1188 echo "<li><strong>Warning:</strong> Unrecognised existing collation</li>\n";
1189 }
1190 if ( isset( $row->Engine ) ) {
1191 $existingEngine = $row->Engine;
1192 } else {
1193 $existingEngine = $row->Type;
1194 }
1195 }
1196 if ( $existingSchema && $existingSchema != $conf->DBschema ) {
1197 $encExisting = htmlspecialchars( $existingSchema );
1198 $encRequested = htmlspecialchars( $conf->DBschema );
1199 print "<li><strong>Warning:</strong> you requested the $encRequested schema, " .
1200 "but the existing database has the $encExisting schema. This upgrade script ".
1201 "can't convert it, so it will remain $encExisting.</li>\n";
1202 $conf->setSchema( $existingSchema, $conf->DBengine );
1203 }
1204 if ( $existingEngine && $existingEngine != $conf->DBengine ) {
1205 $encExisting = htmlspecialchars( $existingEngine );
1206 $encRequested = htmlspecialchars( $conf->DBengine );
1207 print "<li><strong>Warning:</strong> you requested the $encRequested storage " .
1208 "engine, but the existing database uses the $encExisting engine. This upgrade " .
1209 "script can't convert it, so it will remain $encExisting.</li>\n";
1210 $conf->setSchema( $conf->DBschema, $existingEngine );
1211 }
1212 }
1213
1214 # Create user if required
1215 if ( $conf->Root ) {
1216 $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
1217 if ( $conn->isOpen() ) {
1218 print "<li>DB user account ok</li>\n";
1219 $conn->close();
1220 } else {
1221 print "<li>Granting user permissions...";
1222 if( $mysqlOldClient && $mysqlNewAuth ) {
1223 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>";
1224 }
1225 print "</li>\n";
1226 $wgDatabase->sourceFile( "../maintenance/users.sql" );
1227 }
1228 }
1229 }
1230 print "</ul><pre>\n";
1231 chdir( ".." );
1232 flush();
1233 do_all_updates();
1234 chdir( "config" );
1235 print "</pre>\n";
1236 print "<ul><li>Finished update checks.</li>\n";
1237 // if tables don't yet exist
1238 } else {
1239 # Determine available storage engines if possible
1240 if ( $conf->DBtype == 'mysql' && version_compare( $myver, "4.1.2", "ge" ) ) {
1241 $res = $wgDatabase->query( 'SHOW ENGINES' );
1242 $found = false;
1243 while ( $row = $wgDatabase->fetchObject( $res ) ) {
1244 if ( $row->Engine == $conf->DBengine && ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) ) {
1245 $found = true;
1246 break;
1247 }
1248 }
1249 $wgDatabase->freeResult( $res );
1250 if ( !$found && $conf->DBengine != 'MyISAM' ) {
1251 echo "<li><strong>Warning:</strong> " . htmlspecialchars( $conf->DBengine ) .
1252 " storage engine not available, " .
1253 "using MyISAM instead</li>\n";
1254 $conf->setSchema( $conf->DBschema, 'MyISAM' );
1255 }
1256 }
1257
1258 # FIXME: Check for errors
1259 print "<li>Creating tables...";
1260 if ($conf->DBtype == 'mysql') {
1261 $wgDatabase->sourceFile( "../maintenance/tables.sql" );
1262 $wgDatabase->sourceFile( "../maintenance/interwiki.sql" );
1263 } elseif (is_callable(array($wgDatabase, 'setup_database'))) {
1264 $wgDatabase->setup_database();
1265 }
1266 else {
1267 $errs["DBtype"] = "Do not know how to handle database type '$conf->DBtype'";
1268 continue;
1269 }
1270
1271 print " done.</li>\n";
1272
1273
1274 if ( $conf->DBtype == 'ibm_db2' ) {
1275 // Now that table creation is done, make sure everything is committed
1276 // Do this before doing inserts through API
1277 if ($wgDatabase->lastError()) {
1278 print "<li>Errors encountered during table creation -- rolled back</li>\n";
1279 $wgDatabase->rollback();
1280 }
1281 else {
1282 print "<li>MediaWiki tables successfully created</li>\n";
1283 $wgDatabase->commit();
1284 }
1285 } elseif ( $conf->DBtype == 'sqlite' ) {
1286 // Ensure proper searchindex format. We have to do that separately because
1287 // if SQLite is compiled without the FTS3 module, table creation syntax will be invalid.
1288 sqlite_setup_searchindex();
1289 }
1290
1291 print "<li>Initializing statistics...</li>\n";
1292 $wgDatabase->insert( 'site_stats',
1293 array ( 'ss_row_id' => 1,
1294 'ss_total_views' => 0,
1295 'ss_total_edits' => 1, # Main page first edit
1296 'ss_good_articles' => 0, # Main page is not a good article - no internal link
1297 'ss_total_pages' => 1, # Main page
1298 'ss_users' => $conf->SysopName ? 1 : 0, # Sysop account, if created
1299 'ss_admins' => $conf->SysopName ? 1 : 0, # Sysop account, if created
1300 'ss_images' => 0 ) );
1301
1302 # Set up the "regular user" account *if we can, and if we need to*
1303 if( $conf->Root and $conf->DBtype == 'mysql') {
1304 # See if we need to
1305 $wgDatabase2 = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
1306 if( $wgDatabase2->isOpen() ) {
1307 # Nope, just close the test connection and continue
1308 $wgDatabase2->close();
1309 echo( "<li>User " . htmlspecialchars( $wgDBuser ) . " exists. Skipping grants.</li>\n" );
1310 } else {
1311 # Yes, so run the grants
1312 echo( "<li>" . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) );
1313 $wgDatabase->sourceFile( "../maintenance/users.sql" );
1314 echo( "success.</li>\n" );
1315 }
1316 }
1317
1318 if( $conf->SysopName ) {
1319 $u = User::newFromName( $conf->getSysopName() );
1320 if ( !$u ) {
1321 print "<li><strong class=\"error\">Warning:</strong> Skipped sysop account creation - invalid username!</li>\n";
1322 }
1323 else if ( 0 == $u->idForName() ) {
1324 $u->addToDatabase();
1325 $u->setPassword( $conf->getSysopPass() );
1326 $u->saveSettings();
1327
1328 $u->addGroup( "sysop" );
1329 $u->addGroup( "bureaucrat" );
1330
1331 print "<li>Created sysop account <tt>" .
1332 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
1333 } else {
1334 print "<li>Could not create user - already exists!</li>\n";
1335 }
1336 } else {
1337 print "<li>Skipped sysop account creation, no name given.</li>\n";
1338 }
1339
1340 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
1341 $article = new Article( $titleobj );
1342 $newid = $article->insertOn( $wgDatabase );
1343 $revision = new Revision( array(
1344 'page' => $newid,
1345 'text' => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsgNoTrans( 'mainpagedocfooter' ),
1346 'comment' => '',
1347 'user' => 0,
1348 'user_text' => 'MediaWiki default',
1349 ) );
1350 $revid = $revision->insertOn( $wgDatabase );
1351 $article->updateRevisionOn( $wgDatabase, $revision );
1352 }
1353
1354 /* Write out the config file now that all is well */
1355 print "<li style=\"list-style: none\">\n";
1356 print "<p>Creating LocalSettings.php...</p>\n\n";
1357 $localSettings = "<" . "?php$endl$local";
1358 // Fix up a common line-ending problem (due to CVS on Windows)
1359 $localSettings = str_replace( "\r\n", "\n", $localSettings );
1360 $f = fopen( "LocalSettings.php", 'xt' );
1361
1362 if( $f == false ) {
1363 print( "</li>\n" );
1364 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" .
1365 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
1366 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
1367 }
1368 if(fwrite( $f, $localSettings ) ) {
1369 fclose( $f );
1370 print "<hr/>\n";
1371 writeSuccessMessage();
1372 print "</li>\n";
1373 } else {
1374 fclose( $f );
1375 dieout( "<p class='error'>An error occured while writing the config/LocalSettings.php file. Check user rights and disk space then try again.</p></li>\n" );
1376 }
1377
1378 } while( false );
1379 }
1380
1381 print "</ul>\n";
1382 $mainListOpened = false;
1383
1384 if( count( $errs ) ) {
1385 /* Display options form */
1386
1387 if( $conf->posted ) {
1388 echo "<p class='error-top'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
1389 }
1390 ?>
1391
1392 <form action="<?php echo defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php'; ?>" name="config" method="post">
1393
1394 <h2>Site config</h2>
1395
1396 <div class="config-section">
1397 <div class="config-input">
1398 <?php aField( $conf, "Sitename", "Wiki name:" ); ?>
1399 </div>
1400 <p class="config-desc">
1401 Preferably a short word without punctuation, i.e. "Wikipedia".<br />
1402 Will appear as the namespace name for "meta" pages, and throughout the interface.
1403 </p>
1404 <div class="config-input"><?php aField( $conf, "EmergencyContact", "Contact e-mail:" ); ?></div>
1405 <p class="config-desc">
1406 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.
1407 </p>
1408
1409 <div class="config-input">
1410 <label class='column' for="LanguageCode">Language:</label>
1411 <select id="LanguageCode" name="LanguageCode"><?php
1412 $list = getLanguageList();
1413 foreach( $list as $code => $name ) {
1414 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
1415 $encCode = htmlspecialchars( $code );
1416 $encName = htmlspecialchars( $name );
1417 echo "\n\t\t<option value=\"$encCode\" $sel>$encName</option>";
1418 }
1419 echo "\n";
1420 ?>
1421 </select>
1422 </div>
1423 <p class="config-desc">
1424 Select the language for your wiki's interface. Some localizations aren't fully complete. Unicode (UTF-8) is used for all localizations.
1425 </p>
1426
1427 <div class="config-input">
1428 <label class='column'>Copyright/license:</label>
1429
1430 <ul class="plain">
1431 <li><?php aField( $conf, "License", "No license metadata", "radio", "none" ); ?></li>
1432 <li><?php aField( $conf, "License", "Public Domain", "radio", "pd" ); ?></li>
1433 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2", "radio", "gfdl1_2" ); ?></li>
1434 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.3", "radio", "gfdl1_3" ); ?></li>
1435 <li><?php
1436 aField( $conf, "License", "A Creative Commons license - ", "radio", "cc" );
1437 $partner = "MediaWiki";
1438 $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
1439 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/$script?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
1440 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
1441 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
1442 print "<a href=\"$ccApp\" target='_blank'>choose</a>";
1443 if( $conf->License == "cc" ) { ?>
1444 <ul>
1445 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='(Creative Commons icon)' />", "hidden" ); ?></li>
1446 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
1447 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
1448 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
1449 </ul>
1450 <?php } ?>
1451 </li>
1452 </ul>
1453 </div>
1454 <p class="config-desc">
1455 A notice, icon, and machine-readable copyright metadata will be displayed for the license you pick.
1456 </p>
1457
1458
1459 <div class="config-input">
1460 <?php aField( $conf, "SysopName", "Admin username:" ) ?>
1461 </div>
1462 <div class="config-input">
1463 <?php aField( $conf, "SysopPass", "Password:", "password" ) ?>
1464 </div>
1465 <div class="config-input">
1466 <?php aField( $conf, "SysopPass2", "Password confirm:", "password" ) ?>
1467 </div>
1468 <p class="config-desc">
1469 An admin can lock/delete pages, block users from editing, and do other maintenance tasks.<br />
1470 A new account will be added only when creating a new wiki database.
1471 <br /><br />
1472 The password cannot be the same as the username.
1473 </p>
1474
1475 <div class="config-input">
1476 <label class='column'>Object caching:</label>
1477
1478 <ul class="plain">
1479 <li><?php aField( $conf, "Shm", "No caching", "radio", "none" ); ?></li>
1480 <?php
1481 if ( $conf->turck ) {
1482 echo "<li>";
1483 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
1484 echo "</li>\n";
1485 }
1486 if( $conf->xcache ) {
1487 echo "<li>";
1488 aField( $conf, 'Shm', 'XCache', 'radio', 'xcache' );
1489 echo "</li>\n";
1490 }
1491 if ( $conf->apc ) {
1492 echo "<li>";
1493 aField( $conf, "Shm", "APC", "radio", "apc" );
1494 echo "</li>\n";
1495 }
1496 if ( $conf->eaccel ) {
1497 echo "<li>";
1498 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
1499 echo "</li>\n";
1500 }
1501 if ( $conf->dba ) {
1502 echo "<li>";
1503 aField( $conf, "Shm", "DBA (not recommended)", "radio", "dba" );
1504 echo "</li>";
1505 }
1506 ?>
1507 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
1508 </ul>
1509 <div style="clear:left"><?php aField( $conf, "MCServers", "Memcached servers:", "text" ) ?></div>
1510 </div>
1511 <p class="config-desc">
1512 An object caching system such as memcached will provide a significant performance boost,
1513 but needs to be installed. Provide the server addresses and ports in a comma-separated list.
1514 <br /><br />
1515 MediaWiki can also detect and support eAccelerator, Turck MMCache, APC, and XCache, but
1516 these should not be used if the wiki will be running on multiple application servers.
1517 <br/><br/>
1518 DBA (Berkeley-style DB) is generally slower than using no cache at all, and is only
1519 recommended for testing.
1520 </p>
1521 </div>
1522
1523 <h2>E-mail, e-mail notification and authentication setup</h2>
1524
1525 <div class="config-section">
1526 <div class="config-input">
1527 <label class='column'>E-mail features (global):</label>
1528 <ul class="plain">
1529 <li><?php aField( $conf, "Email", "Enabled", "radio", "email_enabled" ); ?></li>
1530 <li><?php aField( $conf, "Email", "Disabled", "radio", "email_disabled" ); ?></li>
1531 </ul>
1532 </div>
1533 <p class="config-desc">
1534 Use this to disable all e-mail functions (password reminders, user-to-user e-mail, and e-mail notifications)
1535 if sending mail doesn't work on your server.
1536 </p>
1537
1538 <div class="config-input">
1539 <label class='column'>User-to-user e-mail:</label>
1540 <ul class="plain">
1541 <li><?php aField( $conf, "Emailuser", "Enabled", "radio", "emailuser_enabled" ); ?></li>
1542 <li><?php aField( $conf, "Emailuser", "Disabled", "radio", "emailuser_disabled" ); ?></li>
1543 </ul>
1544 </div>
1545 <p class="config-desc">
1546 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.
1547 </p>
1548 <div class="config-input">
1549 <label class='column'>E-mail notification about changes:</label>
1550 <ul class="plain">
1551 <li><?php aField( $conf, "Enotif", "Disabled", "radio", "enotif_disabled" ); ?></li>
1552 <li><?php aField( $conf, "Enotif", "Enabled for changes to user discussion pages only", "radio", "enotif_usertalk" ); ?></li>
1553 <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>
1554 </ul>
1555 </div>
1556 <div class="config-desc">
1557 <p>
1558 For this feature to work, an e-mail address must be present for the user account, and the notification
1559 options in the user's preferences must be enabled. Also note the
1560 authentication option below. When testing the feature, keep in mind that your own changes will never trigger notifications to be sent to yourself.</p>
1561
1562 <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>
1563 </div>
1564
1565 <div class="config-input">
1566 <label class='column'>E-mail address authentication:</label>
1567 <ul class="plain">
1568 <li><?php aField( $conf, "Eauthent", "Disabled", "radio", "eauthent_disabled" ); ?></li>
1569 <li><?php aField( $conf, "Eauthent", "Enabled", "radio", "eauthent_enabled" ); ?></li>
1570 </ul>
1571 </div>
1572 <div class="config-desc">
1573 <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
1574 change notification mails. Setting this option is <b>recommended</b> for public wikis because of potential abuse of the e-mail features above.</p>
1575 </div>
1576
1577 </div>
1578
1579 <h2>Database config</h2>
1580
1581 <div class="config-section">
1582 <div class="config-input">
1583 <label class='column'>Database type:</label>
1584 <?php
1585 if (isset($errs['DBpicktype'])) {
1586 print "\t<span class='error'>" . htmlspecialchars( $errs['DBpicktype'] ) . "</span>\n";
1587 }
1588 ?>
1589 <ul class='plain'><?php
1590 database_picker($conf);
1591 ?></ul>
1592 </div>
1593
1594 <div id="db-server-settings1">
1595 <div class="config-input" style="clear:left">
1596 <?php aField( $conf, "DBserver", "Database host:" ); ?>
1597 </div>
1598 <p class="config-desc">
1599 If your database server isn't on your web server, enter the name or IP address here.
1600 </p>
1601 </div>
1602
1603 <div class="config-input"><?php aField( $conf, "DBname", "Database name:" ); ?></div>
1604 <div id="db-server-settings2">
1605 <div class="config-input"><?php aField( $conf, "DBuser", "DB username:" ); ?></div>
1606 <div class="config-input"><?php aField( $conf, "DBpassword", "DB password:", "password" ); ?></div>
1607 <div class="config-input"><?php aField( $conf, "DBpassword2", "DB password confirm:", "password" ); ?></div>
1608 <p class="config-desc">
1609 If you only have a single user account and database available,
1610 enter those here. If you have database root access (see below)
1611 you can specify new accounts/databases to be created. This account
1612 will not be created if it pre-exists. If this is the case, ensure that it
1613 has SELECT, INSERT, UPDATE, and DELETE permissions on the MediaWiki database.
1614 </p>
1615
1616 <div class="config-input">
1617 <label class="column">Superuser account:</label>
1618 <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?> />
1619 &nbsp;<label for="useroot">Use superuser account</label>
1620 </div>
1621 <div class="config-input"><?php aField( $conf, "RootUser", "Superuser name:", "text" ); ?></div>
1622 <div class="config-input"><?php aField( $conf, "RootPW", "Superuser password:", "password" ); ?></div>
1623
1624 <p class="config-desc">
1625 If the database user specified above does not exist, or does not have access to create
1626 the database (if needed) or tables within it, please check the box and provide details
1627 of a superuser account, such as <strong>root</strong>, which does.
1628 </p>
1629 </div>
1630
1631 <?php database_switcher('mysql'); ?>
1632 <div class="config-input"><?php aField( $conf, "DBprefix", "Database table prefix:" ); ?></div>
1633 <div class="config-desc">
1634 <p>If you need to share one database between multiple wikis, or
1635 between MediaWiki and another web application, you may choose to
1636 add a prefix to all the table names to avoid conflicts.</p>
1637
1638 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
1639 </div>
1640
1641 <div class="config-input"><label class="column">Storage Engine</label>
1642 <div>Select one:</div>
1643 <ul class="plain">
1644 <li><?php aField( $conf, "DBengine", "InnoDB", "radio", "InnoDB" ); ?></li>
1645 <li><?php aField( $conf, "DBengine", "MyISAM", "radio", "MyISAM" ); ?></li>
1646 </ul>
1647 </div>
1648 <p class="config-desc">
1649 InnoDB is best for public web installations, since it has good concurrency
1650 support. MyISAM may be faster in single-user installations. MyISAM databases
1651 tend to get corrupted more often than InnoDB databases.
1652 </p>
1653 <div class="config-input"><label class="column">Database character set</label>
1654 <div>Select one:</div>
1655 <ul class="plain">
1656 <li><?php aField( $conf, "DBschema", "MySQL 4.1/5.0 binary", "radio", "mysql5-binary" ); ?></li>
1657 <li><?php aField( $conf, "DBschema", "MySQL 4.1/5.0 UTF-8", "radio", "mysql5" ); ?></li>
1658 <li><?php aField( $conf, "DBschema", "MySQL 4.0 backwards-compatible UTF-8", "radio", "mysql4" ); ?></li>
1659 </ul>
1660 </div>
1661 <p class="config-desc">
1662 This option is ignored on upgrade, the same character set will be kept.
1663 <br/><br/>
1664 <b>WARNING:</b> If you use <b>backwards-compatible UTF-8</b> on MySQL 4.1+, and subsequently back up the database with <tt>mysqldump</tt>, it may destroy all non-ASCII characters, irreversibly corrupting your backups!.
1665 <br/><br/>
1666 In <b>binary mode</b>, MediaWiki stores UTF-8 text to the database in binary fields. This is more efficient than MySQL's UTF-8 mode, and allows you to use the full range of Unicode characters. In <b>UTF-8 mode</b>, MySQL will know what character set your data is in, and can present and convert it appropriately, but it won't let you store characters above the <a target="_blank" href="http://en.wikipedia.org/wiki/Mapping_of_Unicode_character_planes">Basic Multilingual Plane</a>.
1667 </p>
1668 </fieldset>
1669
1670 <?php database_switcher('postgres'); ?>
1671 <div class="config-input"><?php aField( $conf, "DBport", "Database port:" ); ?></div>
1672 <div class="config-input"><?php aField( $conf, "DBpgschema", "Schema for mediawiki:" ); ?></div>
1673 <div class="config-input"><?php aField( $conf, "DBts2schema", "Schema for tsearch2:" ); ?></div>
1674 <div class="config-desc">
1675 <p>The username specified above (at "DB username") will have its search path set to the above schemas,
1676 so it is recommended that you create a new user. The above schemas are generally correct:
1677 only change them if you are sure you need to.</p>
1678 </div>
1679 </fieldset>
1680
1681 <?php database_switcher('sqlite'); ?>
1682 <div class="config-input"><?php
1683 aField( $conf, "SQLiteDataDir", "SQLite data directory:" );
1684 ?></div>
1685 <div class="config-desc">
1686 <p>SQLite stores table data into files in the filesystem.
1687 If you do not provide an explicit path, a "data" directory in
1688 the parent of your document root will be used.</p>
1689
1690 <p>This directory must exist and be writable by the web server.</p>
1691 </div>
1692 </fieldset>
1693
1694 <?php database_switcher('mssql'); ?>
1695 <div class="config-input"><?php
1696 aField( $conf, "DBprefix2", "Database table prefix:" );
1697 ?></div>
1698 <div class="config-desc">
1699 <p>If you need to share one database between multiple wikis, or
1700 between MediaWiki and another web application, you may choose to
1701 add a prefix to all the table names to avoid conflicts.</p>
1702
1703 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
1704 </div>
1705 </fieldset>
1706
1707 <?php database_switcher('ibm_db2'); ?>
1708 <div class="config-input"><?php
1709 aField( $conf, "DBport_db2", "Database port:" );
1710 ?></div>
1711 <div class="config-input"><?php
1712 aField( $conf, "DBdb2schema", "Schema for mediawiki:" );
1713 ?></div>
1714 <div>Select one:</div>
1715 <ul class="plain">
1716 <li><?php aField( $conf, "DBcataloged", "Cataloged (DB2 installed locally)", "radio", "cataloged" ); ?></li>
1717 <li><?php aField( $conf, "DBcataloged", "Uncataloged (remote DB2 through ODBC)", "radio", "uncataloged" ); ?></li>
1718 </ul>
1719 <div class="config-desc">
1720 <p>If you need to share one database between multiple wikis, or
1721 between MediaWiki and another web application, you may specify
1722 a different schema to avoid conflicts.</p>
1723 </div>
1724 </fieldset>
1725
1726 <?php database_switcher('oracle'); ?>
1727 <div class="config-input"><?php aField( $conf, "DBprefix_ora", "Database table prefix:" ); ?></div>
1728 <div class="config-desc">
1729 <p>If you need to share one database between multiple wikis, or
1730 between MediaWiki and another web application, you may choose to
1731 add a prefix to all the table names to avoid conflicts.</p>
1732
1733 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
1734 </div>
1735 <div class="config-input"><?php aField( $conf, "DBdefTS_ora", "Default tablespace:" ); ?></div>
1736 <div class="config-input"><?php aField( $conf, "DBtempTS_ora", "Temporary tablespace:" ); ?></div>
1737 </fieldset>
1738
1739 <div class="config-input" style="padding:2em 0 3em">
1740 <label class='column'>&nbsp;</label>
1741 <input type="submit" value="Install MediaWiki!" class="btn-install" />
1742 </div>
1743 </div>
1744 </form>
1745 <script type="text/javascript">
1746 window.onload = toggleDBarea( <?php echo Xml::encodeJsVar( $conf->DBtype ); ?>,
1747 <?php
1748 ## If they passed in a root user name, don't populate it on page load
1749 echo strlen(importPost('RootUser', '')) ? 0 : 1;
1750 ?>);
1751 </script>
1752 <?php
1753 }
1754
1755 /* -------------------------------------------------------------------------------------- */
1756 function writeSuccessMessage() {
1757 $script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
1758 if ( wfIniGetBool( 'safe_mode' ) && !ini_get( 'open_basedir' ) ) {
1759 echo <<<EOT
1760 <div class="success-box">
1761 <p>Installation successful!</p>
1762 <p>To complete the installation, please do the following:
1763 <ol>
1764 <li>Download config/LocalSettings.php with your FTP client or file manager</li>
1765 <li>Upload it to the parent directory</li>
1766 <li>Delete config/LocalSettings.php</li>
1767 <li>Start using <a href='../$script'>your wiki</a>!
1768 </ol>
1769 <p>If you are in a shared hosting environment, do <strong>not</strong> just move LocalSettings.php
1770 remotely. LocalSettings.php is currently owned by the user your webserver is running under,
1771 which means that anyone on the same server can read your database password! Downloading
1772 it and uploading it again will hopefully change the ownership to a user ID specific to you.</p>
1773 </div>
1774 EOT;
1775 } else {
1776 echo <<<EOT
1777 <div class="success-box">
1778 <p>
1779 <span class="success-message">Installation successful!</span>
1780 Move the <tt>config/LocalSettings.php</tt> file to the parent directory, then follow
1781 <a href="../$script"> this link</a> to your wiki.</p>
1782 <p>You should change file permissions for <tt>LocalSettings.php</tt> as required to
1783 prevent other users on the server reading passwords and altering configuration data.</p>
1784 </div>
1785 EOT;
1786 }
1787 }
1788
1789
1790 function escapePhpString( $string ) {
1791 if ( is_array( $string ) || is_object( $string ) ) {
1792 return false;
1793 }
1794 return strtr( $string,
1795 array(
1796 "\n" => "\\n",
1797 "\r" => "\\r",
1798 "\t" => "\\t",
1799 "\\" => "\\\\",
1800 "\$" => "\\\$",
1801 "\"" => "\\\""
1802 ));
1803 }
1804
1805 function writeLocalSettings( $conf ) {
1806 $conf->PasswordSender = $conf->EmergencyContact;
1807 $magic = ($conf->ImageMagick ? "" : "# ");
1808 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
1809 $rights = ($conf->RightsUrl) ? "" : "# ";
1810 $hashedUploads = $conf->safeMode ? '' : '# ';
1811
1812 if ( $conf->ShellLocale ) {
1813 $locale = '';
1814 } else {
1815 $locale = '# ';
1816 $conf->ShellLocale = 'en_US.UTF-8';
1817 }
1818
1819 switch ( $conf->Shm ) {
1820 case 'memcached':
1821 $cacheType = 'CACHE_MEMCACHED';
1822 $mcservers = var_export( $conf->MCServerArray, true );
1823 break;
1824 case 'turck':
1825 case 'xcache':
1826 case 'apc':
1827 case 'eaccel':
1828 $cacheType = 'CACHE_ACCEL';
1829 $mcservers = 'array()';
1830 break;
1831 case 'dba':
1832 $cacheType = 'CACHE_DBA';
1833 $mcservers = 'array()';
1834 break;
1835 default:
1836 $cacheType = 'CACHE_NONE';
1837 $mcservers = 'array()';
1838 }
1839
1840 if ( $conf->Email == 'email_enabled' ) {
1841 $enableemail = 'true';
1842 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
1843 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
1844 switch ( $conf->Enotif ) {
1845 case 'enotif_usertalk':
1846 $enotifusertalk = 'true';
1847 $enotifwatchlist = 'false';
1848 break;
1849 case 'enotif_allpages':
1850 $enotifusertalk = 'true';
1851 $enotifwatchlist = 'true';
1852 break;
1853 default:
1854 $enotifusertalk = 'false';
1855 $enotifwatchlist = 'false';
1856 }
1857 } else {
1858 $enableuseremail = 'false';
1859 $enableemail = 'false';
1860 $eauthent = 'false';
1861 $enotifusertalk = 'false';
1862 $enotifwatchlist = 'false';
1863 }
1864
1865 $file = @fopen( "/dev/urandom", "r" );
1866 if ( $file ) {
1867 $secretKey = bin2hex( fread( $file, 32 ) );
1868 fclose( $file );
1869 } else {
1870 $secretKey = "";
1871 for ( $i=0; $i<8; $i++ ) {
1872 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1873 }
1874 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1875 }
1876
1877 # Add slashes to strings for double quoting
1878 $slconf = wfArrayMap( "escapePhpString", get_object_vars( $conf ) );
1879 if( $conf->License == 'gfdl1_2' || $conf->License == 'pd' || $conf->License == 'gfdl1_3' ) {
1880 # Needs literal string interpolation for the current style path
1881 $slconf['RightsIcon'] = $conf->RightsIcon;
1882 }
1883
1884 if( $conf->DBtype == 'mysql' ) {
1885 $dbsettings =
1886 "# MySQL specific settings
1887 \$wgDBprefix = \"{$slconf['DBprefix']}\";
1888
1889 # MySQL table options to use during installation or update
1890 \$wgDBTableOptions = \"{$slconf['DBTableOptions']}\";
1891
1892 # Experimental charset support for MySQL 4.1/5.0.
1893 \$wgDBmysql5 = {$conf->DBmysql5};";
1894 } elseif( $conf->DBtype == 'postgres' ) {
1895 $dbsettings =
1896 "# Postgres specific settings
1897 \$wgDBport = \"{$slconf['DBport']}\";
1898 \$wgDBmwschema = \"{$slconf['DBpgschema']}\";
1899 \$wgDBts2schema = \"{$slconf['DBts2schema']}\";";
1900 } elseif( $conf->DBtype == 'sqlite' ) {
1901 $dbsettings =
1902 "# SQLite-specific settings
1903 \$wgSQLiteDataDir = \"{$slconf['SQLiteDataDir']}\";";
1904 } elseif( $conf->DBtype == 'mssql' ) {
1905 $dbsettings =
1906 "# MSSQL specific settings
1907 \$wgDBprefix = \"{$slconf['DBprefix2']}\";";
1908 } elseif( $conf->DBtype == 'ibm_db2' ) {
1909 $dbsettings =
1910 "# DB2 specific settings
1911 \$wgDBport_db2 = \"{$slconf['DBport_db2']}\";
1912 \$wgDBmwschema = \"{$slconf['DBdb2schema']}\";
1913 \$wgDBcataloged = \"{$slconf['DBcataloged']}\";";
1914 } elseif( $conf->DBtype == 'oracle' ) {
1915 $dbsettings =
1916 "# Oracle specific settings
1917 \$wgDBprefix = \"{$slconf['DBprefix']}\";";
1918 } else {
1919 // ummm... :D
1920 $dbsettings = '';
1921 }
1922
1923
1924 $localsettings = "
1925 # This file was automatically generated by the MediaWiki installer.
1926 # If you make manual changes, please keep track in case you need to
1927 # recreate them later.
1928 #
1929 # See includes/DefaultSettings.php for all configurable settings
1930 # and their default values, but don't forget to make changes in _this_
1931 # file, not there.
1932 #
1933 # Further documentation for configuration settings may be found at:
1934 # http://www.mediawiki.org/wiki/Manual:Configuration_settings
1935
1936 # If you customize your file layout, set \$IP to the directory that contains
1937 # the other MediaWiki files. It will be used as a base to locate files.
1938 if( defined( 'MW_INSTALL_PATH' ) ) {
1939 \$IP = MW_INSTALL_PATH;
1940 } else {
1941 \$IP = dirname( __FILE__ );
1942 }
1943
1944 \$path = array( \$IP, \"\$IP/includes\", \"\$IP/languages\" );
1945 set_include_path( implode( PATH_SEPARATOR, \$path ) . PATH_SEPARATOR . get_include_path() );
1946
1947 require_once( \"\$IP/includes/DefaultSettings.php\" );
1948
1949 if ( \$wgCommandLineMode ) {
1950 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1951 die( \"This script must be run from the command line\\n\" );
1952 }
1953 }
1954 ## Uncomment this to disable output compression
1955 # \$wgDisableOutputCompression = true;
1956
1957 \$wgSitename = \"{$slconf['Sitename']}\";
1958
1959 ## The URL base path to the directory containing the wiki;
1960 ## defaults for all runtime URL paths are based off of this.
1961 ## For more information on customizing the URLs please see:
1962 ## http://www.mediawiki.org/wiki/Manual:Short_URL
1963 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
1964 \$wgScriptExtension = \"{$slconf['ScriptExtension']}\";
1965
1966 ## The relative URL path to the skins directory
1967 \$wgStylePath = \"\$wgScriptPath/skins\";
1968
1969 ## The relative URL path to the logo. Make sure you change this from the default,
1970 ## or else you'll overwrite your logo when you upgrade!
1971 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
1972
1973 ## UPO means: this is also a user preference option
1974
1975 \$wgEnableEmail = $enableemail;
1976 \$wgEnableUserEmail = $enableuseremail; # UPO
1977
1978 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1979 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
1980
1981 \$wgEnotifUserTalk = $enotifusertalk; # UPO
1982 \$wgEnotifWatchlist = $enotifwatchlist; # UPO
1983 \$wgEmailAuthentication = $eauthent;
1984
1985 ## Database settings
1986 \$wgDBtype = \"{$slconf['DBtype']}\";
1987 \$wgDBserver = \"{$slconf['DBserver']}\";
1988 \$wgDBname = \"{$slconf['DBname']}\";
1989 \$wgDBuser = \"{$slconf['DBuser']}\";
1990 \$wgDBpassword = \"{$slconf['DBpassword']}\";
1991
1992 {$dbsettings}
1993
1994 ## Shared memory settings
1995 \$wgMainCacheType = $cacheType;
1996 \$wgMemCachedServers = $mcservers;
1997
1998 ## To enable image uploads, make sure the 'images' directory
1999 ## is writable, then set this to true:
2000 \$wgEnableUploads = false;
2001 {$magic}\$wgUseImageMagick = true;
2002 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
2003
2004 ## If you use ImageMagick (or any other shell command) on a
2005 ## Linux server, this will need to be set to the name of an
2006 ## available UTF-8 locale
2007 {$locale}\$wgShellLocale = \"{$slconf['ShellLocale']}\";
2008
2009 ## If you want to use image uploads under safe mode,
2010 ## create the directories images/archive, images/thumb and
2011 ## images/temp, and make them all writable. Then uncomment
2012 ## this, if it's not already uncommented:
2013 {$hashedUploads}\$wgHashedUploadDirectory = false;
2014
2015 ## If you have the appropriate support software installed
2016 ## you can enable inline LaTeX equations:
2017 \$wgUseTeX = false;
2018
2019 ## Set \$wgCacheDirectory to a writable directory on the web server
2020 ## to make your wiki go slightly faster. The directory should not
2021 ## be publically accessible from the web.
2022 #\$wgCacheDirectory = \"\$IP/cache\";
2023
2024 \$wgLocalInterwiki = strtolower( \$wgSitename );
2025
2026 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
2027
2028 \$wgSecretKey = \"$secretKey\";
2029
2030 ## Default skin: you can change the default skin. Use the internal symbolic
2031 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
2032 \$wgDefaultSkin = 'monobook';
2033
2034 ## For attaching licensing metadata to pages, and displaying an
2035 ## appropriate copyright notice / icon. GNU Free Documentation
2036 ## License and Creative Commons licenses are supported so far.
2037 {$rights}\$wgEnableCreativeCommonsRdf = true;
2038 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
2039 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
2040 \$wgRightsText = \"{$slconf['RightsText']}\";
2041 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
2042 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
2043
2044 \$wgDiff3 = \"{$slconf['diff3']}\";
2045
2046 \$wgPhpCliPath = \"{$slconf['phpCliPath']}\";
2047
2048 # When you make changes to this configuration file, this will make
2049 # sure that cached pages are cleared.
2050 \$wgCacheEpoch = max( \$wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
2051 "; ## End of setting the $localsettings string
2052
2053 // Keep things in Unix line endings internally;
2054 // the system will write out as local text type.
2055 return str_replace( "\r\n", "\n", $localsettings );
2056 }
2057
2058 function dieout( $text ) {
2059 global $mainListOpened;
2060 if( $mainListOpened ) echo( "</ul>" );
2061 if( $text != '' && substr( $text, 0, 2 ) != '<p' && substr( $text, 0, 2 ) != '<h' ){
2062 echo "<p>$text</p>\n";
2063 } else {
2064 echo $text;
2065 }
2066 die( "\n\n</div>\n</div>\n</div>\n</div>\n</body>\n</html>" );
2067 }
2068
2069 function importVar( &$var, $name, $default = "" ) {
2070 if( isset( $var[$name] ) ) {
2071 $retval = $var[$name];
2072 if ( get_magic_quotes_gpc() ) {
2073 $retval = stripslashes( $retval );
2074 }
2075 } else {
2076 $retval = $default;
2077 }
2078 taint( $retval );
2079 return $retval;
2080 }
2081
2082 function importPost( $name, $default = "" ) {
2083 return importVar( $_POST, $name, $default );
2084 }
2085
2086 function importCheck( $name ) {
2087 return isset( $_POST[$name] );
2088 }
2089
2090 function importRequest( $name, $default = "" ) {
2091 return importVar( $_REQUEST, $name, $default );
2092 }
2093
2094 function aField( &$conf, $field, $text, $type = "text", $value = "", $onclick = '' ) {
2095 static $radioCount = 0;
2096 if( $type != "" ) {
2097 $xtype = "type=\"$type\"";
2098 } else {
2099 $xtype = "";
2100 }
2101
2102 $id = $field;
2103 $nolabel = ($type == "radio") || ($type == "hidden");
2104
2105 if ($type == 'radio')
2106 $id .= $radioCount++;
2107
2108 if( !$nolabel ) {
2109 echo "<label class='column' for=\"$id\">$text</label>";
2110 }
2111
2112 if( $type == "radio" && $value == $conf->$field ) {
2113 $checked = "checked='checked'";
2114 } else {
2115 $checked = "";
2116 }
2117 echo "<input $xtype name=\"$field\" id=\"$id\" class=\"iput-$type\" $checked ";
2118 if ($onclick) {
2119 echo " onclick='toggleDBarea(\"$value\",1)' " ;
2120 }
2121 echo "value=\"";
2122 if( $type == "radio" ) {
2123 echo htmlspecialchars( $value );
2124 } else {
2125 echo htmlspecialchars( $conf->$field );
2126 }
2127
2128
2129 echo "\" />";
2130 if( $nolabel ) {
2131 echo "<label for=\"$id\">$text</label>";
2132 }
2133
2134 global $errs;
2135 if(isset($errs[$field])) {
2136 echo "<span class='error'>" . htmlspecialchars( $errs[$field] ) . "</span>\n";
2137 }
2138 }
2139
2140 function getLanguageList() {
2141 global $wgLanguageNames, $IP;
2142 if( !isset( $wgLanguageNames ) ) {
2143 require_once( "$IP/languages/Names.php" );
2144 }
2145
2146 $codes = array();
2147
2148 $d = opendir( "../languages/messages" );
2149 /* In case we are called from the root directory */
2150 if (!$d)
2151 $d = opendir( "languages/messages");
2152 while( false !== ($f = readdir( $d ) ) ) {
2153 $m = array();
2154 if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
2155 $code = str_replace( '_', '-', strtolower( $m[1] ) );
2156 if( $code == 'qqq' ) continue;
2157 if( isset( $wgLanguageNames[$code] ) ) {
2158 $name = wfBCP47( $code ) . ' - ' . $wgLanguageNames[$code];
2159 } else {
2160 $name = $code;
2161 }
2162 $codes[$code] = $name;
2163 }
2164 }
2165 closedir( $d );
2166 ksort( $codes );
2167 return $codes;
2168 }
2169
2170 #Check for location of an executable
2171 # @param string $loc single location to check
2172 # @param array $names filenames to check for.
2173 # @param mixed $versioninfo array of details to use when checking version, use false for no version checking
2174 function locate_executable($loc, $names, $versioninfo = false) {
2175 if (!is_array($names))
2176 $names = array($names);
2177
2178 foreach ($names as $name) {
2179 $command = "$loc".DIRECTORY_SEPARATOR."$name";
2180 if (@file_exists($command)) {
2181 if (!$versioninfo)
2182 return $command;
2183
2184 $file = str_replace('$1', $command, $versioninfo[0]);
2185 if (strstr(`$file`, $versioninfo[1]) !== false)
2186 return $command;
2187 }
2188 }
2189 return false;
2190 }
2191
2192 # Test a memcached server
2193 function testMemcachedServer( $server ) {
2194 $hostport = explode(":", $server);
2195 $errstr = false;
2196 $fp = false;
2197 if ( !function_exists( 'fsockopen' ) ) {
2198 $errstr = "Can't connect to memcached, fsockopen() not present";
2199 }
2200 if ( !$errstr && count( $hostport ) != 2 ) {
2201 $errstr = 'Please specify host and port';
2202 }
2203 if ( !$errstr ) {
2204 list( $host, $port ) = $hostport;
2205 $errno = 0;
2206 $fsockerr = '';
2207
2208 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
2209 if ( $fp === false ) {
2210 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
2211 }
2212 }
2213 if ( !$errstr ) {
2214 $command = "version\r\n";
2215 $bytes = fwrite( $fp, $command );
2216 if ( $bytes != strlen( $command ) ) {
2217 $errstr = "Cannot write to memcached socket on $host:$port";
2218 }
2219 }
2220 if ( !$errstr ) {
2221 $expected = "VERSION ";
2222 $response = fread( $fp, strlen( $expected ) );
2223 if ( $response != $expected ) {
2224 $errstr = "Didn't get correct memcached response from $host:$port";
2225 }
2226 }
2227 if ( $fp ) {
2228 fclose( $fp );
2229 }
2230 if ( !$errstr ) {
2231 echo "<li>Connected to memcached on " . htmlspecialchars( "$host:$port" ) ." successfully</li>";
2232 }
2233 return $errstr;
2234 }
2235
2236 function database_picker($conf) {
2237 global $ourdb;
2238 print "\n";
2239 foreach(array_keys($ourdb) as $db) {
2240 if ($ourdb[$db]['havedriver']) {
2241 print "\t<li>";
2242 aField( $conf, "DBtype", $ourdb[$db]['fullname'], 'radio', $db, 'onclick');
2243 print "</li>\n";
2244 }
2245 }
2246 print "\n\t";
2247 }
2248
2249 function database_switcher($db) {
2250 global $ourdb;
2251 $color = $ourdb[$db]['bgcolor'];
2252 $full = $ourdb[$db]['fullname'];
2253 print "<fieldset id='$db' style='clear:both'><legend>$full-specific options</legend>\n";
2254 }
2255
2256 function printListItem( $item ) {
2257 print "<li>$item</li>";
2258 }
2259
2260 # Determine a suitable value for $wgShellLocale
2261 function getShellLocale( $wikiLang ) {
2262 # Give up now if we're in safe mode or open_basedir
2263 # It's theoretically possible but tricky to work with
2264 if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) || !function_exists('exec') ) {
2265 return false;
2266 }
2267
2268 $os = php_uname( 's' );
2269 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
2270 if ( !in_array( $os, $supported ) ) {
2271 return false;
2272 }
2273
2274 # Get a list of available locales
2275 $lines = $ret = false;
2276 exec( '/usr/bin/locale -a', $lines, $ret );
2277 if ( $ret ) {
2278 return false;
2279 }
2280
2281 $lines = wfArrayMap( 'trim', $lines );
2282 $candidatesByLocale = array();
2283 $candidatesByLang = array();
2284 foreach ( $lines as $line ) {
2285 if ( $line === '' ) {
2286 continue;
2287 }
2288 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
2289 continue;
2290 }
2291 list( $all, $lang, $territory, $charset, $modifier ) = $m;
2292 $candidatesByLocale[$m[0]] = $m;
2293 $candidatesByLang[$lang][] = $m;
2294 }
2295
2296 # Try the current value of LANG
2297 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
2298 return getenv( 'LANG' );
2299 }
2300
2301 # Try the most common ones
2302 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
2303 foreach ( $commonLocales as $commonLocale ) {
2304 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
2305 return $commonLocale;
2306 }
2307 }
2308
2309 # Is there an available locale in the Wiki's language?
2310 if ( isset( $candidatesByLang[$wikiLang] ) ) {
2311 $m = reset( $candidatesByLang[$wikiLang] );
2312 return $m[0];
2313 }
2314
2315 # Are there any at all?
2316 if ( count( $candidatesByLocale ) ) {
2317 $m = reset( $candidatesByLocale );
2318 return $m[0];
2319 }
2320
2321 # Give up
2322 return false;
2323 }
2324
2325 function wfArrayMap( $function, $input ) {
2326 $ret = array_map( $function, $input );
2327 foreach ( $ret as $key => $value ) {
2328 $taint = istainted( $input[$key] );
2329 if ( $taint ) {
2330 taint( $ret[$key], $taint );
2331 }
2332 }
2333 return $ret;
2334 }
2335
2336 ?>
2337
2338 <div class="license">
2339 <hr/>
2340 <p>This program is free software; you can redistribute it and/or modify
2341 it under the terms of the GNU General Public License as published by
2342 the Free Software Foundation; either version 2 of the License, or
2343 (at your option) any later version.</p>
2344
2345 <p>This program is distributed in the hope that it will be useful,
2346 but WITHOUT ANY WARRANTY; without even the implied warranty of
2347 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2348 GNU General Public License for more details.</p>
2349
2350 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
2351 along with this program; if not, write to the Free Software
2352 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2353 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
2354 </div>
2355
2356 </div></div></div>
2357
2358
2359 <div id="column-one">
2360 <div class="portlet" id="p-logo">
2361 <a style="background-image: url(../skins/common/images/mediawiki.png);"
2362 href="../"
2363 title="Main Page"></a>
2364 </div>
2365 <script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
2366 <div class='portlet'><div class='pBody'>
2367 <ul>
2368 <li><a href="../README">Readme</a></li>
2369 <li><a href="../RELEASE-NOTES">Release notes</a></li>
2370 <li><a href="../docs/">Documentation</a></li>
2371 <li><a href="http://www.mediawiki.org/wiki/Help:Contents">User's Guide</a></li>
2372 <li><a href="http://www.mediawiki.org/wiki/Manual:Contents">Administrator's Guide</a></li>
2373 <li><a href="http://www.mediawiki.org/wiki/Manual:FAQ">FAQ</a></li>
2374 </ul>
2375 <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright © 2001-2009 by Magnus Manske, Brion Vibber,
2376 Lee Daniel Crocker, Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason, Niklas Laxström,
2377 Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor, Aaron Schulz and others.</p>
2378 </div></div>
2379 </div>
2380
2381 </div>
2382
2383 </body>
2384 </html>