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