]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - config/index.php
MediaWiki 1.5.8 (initial commit)
[autoinstallsdev/mediawiki.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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
27         "http://www.w3.org/TR/html4/loose.dtd">
28 <html>
29 <head>
30         <meta http-equiv="Content-type" content="text/html; charset=utf-8">
31         <meta name="robots" content="noindex,nofollow">
32         <title>MediaWiki 1.5 Installation</title>
33         <style type="text/css">
34         #credit {
35                 float: right;
36                 width: 200px;
37                 font-size: 0.7em;
38                 background-color: #eee;
39                 color: black;
40                 border: solid 1px #444;
41                 padding: 8px;
42                 margin-left: 8px;
43         }
44
45         dl.setup dd {
46                 margin-left: 0;
47         }
48         dl.setup dd label.column {
49                 clear: left;
50                 font-weight: bold;
51                 width: 12em;
52                 float: left;
53                 text-align: right;
54                 padding-right: 1em;
55         }
56         dl.setup dt {
57                 clear: left;
58                 font-size: 0.8em;
59                 margin-left: 10em;
60                 /* margin-right: 200px; */
61                 margin-bottom: 2em;
62         }
63         .error {
64                 color: red;
65         }
66         ul.plain {
67                 list-style: none;
68                 clear: both;
69                 margin-left: 12em;
70         }
71         </style>
72 </head>
73
74 <body>
75
76 <div id="credit">
77  <center>
78   <a href="http://www.mediawiki.org/">
79    <img src="../skins/common/images/mediawiki.png" width="135" height="135" alt="" border="0" />
80   </a>
81  </center>
82
83  <p><strong><a href="http://www.mediawiki.org/">MediaWiki</a></strong> is
84  Copyright (C) 2001-2006 by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
85  Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
86
87  <ul>
88   <li><a href="../README">Readme</a></li>
89   <li><a href="../RELEASE-NOTES">Release notes</a></li>
90   <li><a href="../docs/">doc/</a></li>
91   <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
92  </ul>
93
94  <p>This program is free software; you can redistribute it and/or modify
95  it under the terms of the GNU General Public License as published by
96  the Free Software Foundation; either version 2 of the License, or
97  (at your option) any later version.</p>
98
99  <p>This program is distributed in the hope that it will be useful,
100  but WITHOUT ANY WARRANTY; without even the implied warranty of
101  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
102  GNU General Public License for more details.</p>
103
104  <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
105  along with this program; if not, write to the Free Software
106  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
107  or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
108 </div>
109
110 <?php
111
112 # Relative includes seem to break if a parent directory is not readable;
113 # this is common for public_html subdirs under user home directories.
114 #
115 # As a dirty hack, we'll try to set up the include path first.
116 #
117 $IP = dirname( dirname( __FILE__ ) );
118 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
119 ini_set( "include_path", ".$sep$IP$sep$IP/includes$sep$IP/languages" );
120
121 define( "MEDIAWIKI", true );
122 define( "MEDIAWIKI_INSTALL", true );
123 require_once( "includes/Defines.php" );
124 require_once( "includes/DefaultSettings.php" );
125 require_once( "includes/MagicWord.php" );
126 require_once( "includes/Namespace.php" );
127 ?>
128
129 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
130
131
132 <?php
133
134 /* Check for existing configurations and bug out! */
135
136 if( file_exists( "../LocalSettings.php" ) ) {
137         dieout( "<h2>Wiki is configured.</h2>
138
139         <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
140
141         <p>(You should probably remove this directory for added security.)</p>" );
142 }
143
144 if( file_exists( "./LocalSettings.php" ) ) {
145         writeSuccessMessage();
146
147         dieout( '' );
148 }
149
150 if( !is_writable( "." ) ) {
151         dieout( "<h2>Can't write config file, aborting</h2>
152
153         <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
154         writable by the web server. Once configuration is done you'll move the created
155         <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
156         then remove the <tt>config</tt> subdirectory entirely.</p>
157
158         <p>To make the directory writable on a Unix/Linux system:</p>
159
160         <pre>
161         cd <i>/path/to/wiki</i>
162         chmod a+w config
163         </pre>" );
164 }
165
166
167 require_once( "install-utils.inc" );
168 require_once( "maintenance/updaters.inc" );
169
170 class ConfigData {
171         function getEncoded( $data ) {
172                 # removing latin1 support, no need...
173                 return $data;
174         }
175         function getSitename() { return $this->getEncoded( $this->Sitename ); }
176         function getSysopName() { return $this->getEncoded( $this->SysopName ); }
177         function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
178 }
179
180 ?>
181
182 <p><em>Please include all of the lines below when reporting installation problems.</em></p>
183
184 <h2>Checking environment...</h2>
185 <ul>
186 <?php
187 $endl = "
188 ";
189 $wgNoOutputBuffer = true;
190 $conf = new ConfigData;
191
192 install_version_checks();
193
194 print "<li>PHP " . phpversion() . ": ok</li>\n";
195
196 if( ini_get( "register_globals" ) ) {
197         ?>
198         <li><b class='error'>Warning:</b> <strong>PHP's
199         <tt><a href="http://php.net/register_globals">register_globals</a></tt>
200         option is enabled.</strong> MediaWiki will work correctly, but this setting
201         increases your exposure to potential security vulnerabilities in PHP-based
202         software running on your server. <strong>You should disable it if you are able.</strong></li>
203         <?php
204 }
205
206 $fatal = false;
207
208 if( ini_get( "magic_quotes_runtime" ) ) {
209         $fatal = true;
210         ?><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>
211         This option corrupts data input unpredictably; you cannot install or use
212         MediaWiki unless this option is disabled.
213         <?php
214 }
215
216 if( ini_get( "magic_quotes_sybase" ) ) {
217         $fatal = true;
218         ?><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>
219         This option corrupts data input unpredictably; you cannot install or use
220         MediaWiki unless this option is disabled.
221         <?php
222 }
223
224 if( ini_get( "mbstring.func_overload" ) ) {
225         $fatal = true;
226         ?><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>
227         This option causes errors and may corrupt data unpredictably;
228         you cannot install or use MediaWiki unless this option is disabled.
229         <?php
230 }
231
232 if( $fatal ) {
233         dieout( "</ul><p>Cannot install wiki.</p>" );
234 }
235
236 if( ini_get( "safe_mode" ) ) {
237         $conf->safeMode = true;
238         ?>
239         <li><b class='error'>Warning:</b> <strong>PHP's
240         <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active.</strong>
241         You may have problems caused by this, particularly if using image uploads.
242         </li>
243         <?php
244 } else {
245         $conf->safeMode = false;
246 }
247
248 $sapi = php_sapi_name();
249 $conf->prettyURLs = true;
250 print "<li>PHP server API is $sapi; ";
251 switch( $sapi ) {
252 case "apache":
253 case "apache2handler":
254         print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
255         break;
256 default:
257         print "unknown; ";
258 case "cgi":
259 case "cgi-fcgi":
260 case "apache2filter":
261 case "isapi":
262         print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
263         $conf->prettyURLs = false;
264         break;
265 }
266 print "</li>\n";
267
268 $conf->xml = function_exists( "utf8_encode" );
269 if( $conf->xml ) {
270         print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
271 } else {
272         dieout( "PHP's XML module is missing; the wiki requires functions in
273                 this module and won't work in this configuration.
274                 If you're running Mandrake, install the php-xml package." );
275 }
276
277 $memlimit = ini_get( "memory_limit" );
278 $conf->raiseMemory = false;
279 if( empty( $memlimit ) || $memlimit == -1 ) {
280         print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
281 } else {
282         print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <strong>If this is too low, installation may fail!</strong> ";
283         $n = IntVal( $memlimit );
284         if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
285                 $n = IntVal( $m[1] * (1024*1024) );
286         }
287         if( $n < 20*1024*1024 ) {
288                 print "Attempting to raise limit to 20M... ";
289                 if( false === ini_set( "memory_limit", "20M" ) ) {
290                         print "failed.";
291                 } else {
292                         $conf->raiseMemory = true;
293                         print "ok.";
294                 }
295         }
296         print "</li>\n";
297 }
298
299 $conf->zlib = function_exists( "gzencode" );
300 if( $conf->zlib ) {
301         print "<li>Have zlib support; enabling output compression.</li>\n";
302 } else {
303         print "<li>No zlib support.</li>\n";
304 }
305
306 $conf->turck = function_exists( 'mmcache_get' );
307 if ( $conf->turck ) {
308         print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
309 }
310 $conf->eaccel = function_exists( 'eaccelerator_get' );
311 if ( $conf->eaccel ) {
312     $conf->turck = 'eaccelerator';
313     print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
314 }
315 if (!$conf->turck && !$conf->eaccel) {
316         print "<li>Neither <a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> nor <a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> are installed, " .
317           "can't use object caching functions</li>\n";
318 }
319
320 $conf->diff3 = false;
321 $diff3locations = array("/usr/bin", "/opt/csw/bin", "/usr/gnu/bin", "/usr/sfw/bin") + explode(":", getenv("PATH"));
322 $diff3names = array("gdiff3", "diff3");
323
324 $diff3versioninfo = array('$1 --version 2>&1', 'diff3 (GNU diffutils)');
325 foreach ($diff3locations as $loc) {
326         $exe = locate_executable($loc, $diff3names, $diff3versioninfo);
327         if ($exe !== false) {
328                 $conf->diff3 = $exe;
329                 break;
330         }
331 }
332
333 if ($conf->diff3)
334         print "<li>Found GNU diff3: <tt>$conf->diff3</tt>.</li>";
335 else
336         print "<li>GNU diff3 not found.</li>";
337
338 $conf->ImageMagick = false;
339 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
340 foreach( $imcheck as $dir ) {
341         $im = "$dir/convert";
342         if( file_exists( $im ) ) {
343                 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
344                 $conf->ImageMagick = $im;
345                 break;
346         }
347 }
348
349 $conf->HaveGD = function_exists( "imagejpeg" );
350 if( $conf->HaveGD ) {
351         print "<li>Found GD graphics library built-in";
352         if( !$conf->ImageMagick ) {
353                 print ", image thumbnailing will be enabled if you enable uploads";
354         }
355         print ".</li>\n";
356 } else {
357         if( !$conf->ImageMagick ) {
358                 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
359         }
360 }
361
362 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
363
364 # $conf->IP = "/Users/brion/Sites/inplace";
365 $conf->IP = dirname( dirname( __FILE__ ) );
366 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
367
368 # $conf->ScriptPath = "/~brion/inplace";
369 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["PHP_SELF"] ); # was SCRIPT_NAME
370 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
371
372         $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
373
374         $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
375         $defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
376                 ? 'root@localhost'
377                 : $_SERVER["SERVER_ADMIN"];
378         $conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
379         $conf->DBserver = importPost( "DBserver", "localhost" );
380         $conf->DBname = importPost( "DBname", "wikidb" );
381         $conf->DBuser = importPost( "DBuser", "wikiuser" );
382         $conf->DBpassword = importPost( "DBpassword" );
383         $conf->DBpassword2 = importPost( "DBpassword2" );
384         $conf->DBprefix = importPost( "DBprefix" );
385         $conf->DBmysql5 = (importPost( "DBmysql5" ) == "true") ? "true" : "false";
386         $conf->RootUser = importPost( "RootUser", "root" );
387         $conf->RootPW = importPost( "RootPW", "-" );
388         $conf->LanguageCode = importPost( "LanguageCode", "en" );
389         $conf->SysopName = importPost( "SysopName", "WikiSysop" );
390         $conf->SysopPass = importPost( "SysopPass" );
391         $conf->SysopPass2 = importPost( "SysopPass2" );
392
393 /* Check for validity */
394 $errs = array();
395
396 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
397         $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
398 }
399 if( $conf->DBuser == "" ) {
400         $errs["DBuser"] = "Must not be blank";
401 }
402 if( $conf->DBpassword == "" ) {
403         $errs["DBpassword"] = "Must not be blank";
404 }
405 if( $conf->DBpassword != $conf->DBpassword2 ) {
406         $errs["DBpassword2"] = "Passwords don't match!";
407 }
408 if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
409         $errs["DBprefix"] = "Invalid table prefix";
410 }
411
412 if( $conf->SysopPass == "" ) {
413         $errs["SysopPass"] = "Must not be blank";
414 }
415 if( $conf->SysopPass != $conf->SysopPass2 ) {
416         $errs["SysopPass2"] = "Passwords don't match!";
417 }
418
419 $conf->License = importRequest( "License", "none" );
420 if( $conf->License == "gfdl" ) {
421         $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
422         $conf->RightsText = "GNU Free Documentation License 1.2";
423         $conf->RightsCode = "gfdl";
424         $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
425 } elseif( $conf->License == "none" ) {
426         $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
427 } else {
428         $conf->RightsUrl = importRequest( "RightsUrl", "" );
429         $conf->RightsText = importRequest( "RightsText", "" );
430         $conf->RightsCode = importRequest( "RightsCode", "" );
431         $conf->RightsIcon = importRequest( "RightsIcon", "" );
432 }
433
434 $conf->Shm = importRequest( "Shm", "none" );
435 $conf->MCServers = importRequest( "MCServers" );
436
437 /* Test memcached servers */
438
439 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
440         $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
441         foreach ( $conf->MCServerArray as $server ) {
442                 $error = testMemcachedServer( $server );
443                 if ( $error ) {
444                         $errs["MCServers"] = $error;
445                         break;
446                 }
447         }
448 } else if ( $conf->Shm == 'memcached' ) {
449         $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
450 }
451
452 /* default values for installation */
453 $conf->Email    =importRequest("Email", "email_enabled");
454 $conf->Emailuser=importRequest("Emailuser", "emailuser_enabled");
455 $conf->Enotif   =importRequest("Enotif", "enotif_allpages");
456 $conf->Eauthent =importRequest("Eauthent", "eauthent_enabled");
457
458 if( $conf->posted && ( 0 == count( $errs ) ) ) {
459         do { /* So we can 'continue' to end prematurely */
460                 $conf->Root = ($conf->RootPW != "");
461
462                 /* Load up the settings and get installin' */
463                 $local = writeLocalSettings( $conf );
464                 $wgCommandLineMode = false;
465                 chdir( ".." );
466                 eval($local);
467                 $wgDBadminuser = "root";
468                 $wgDBadminpassword = $conf->RootPW;
469                 $wgDBprefix = $conf->DBprefix;
470                 $wgCommandLineMode = true;
471                 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
472                 require_once( "includes/Setup.php" );
473                 chdir( "config" );
474
475                 require_once( "maintenance/InitialiseMessages.inc" );
476
477                 $wgTitle = Title::newFromText( "Installation script" );
478                 $mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
479                 if( $mysqlOldClient ) {
480                         print "<li><b>PHP is linked with old MySQL client libraries. If you are
481                                 using a MySQL 4.1 server and have problems connecting to the database,
482                                 see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'
483                                 >http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b></li>\n";
484                 }
485                 
486                 # Determine how we're going to connect to the database
487                 if( $conf->RootPW == '-' ) {
488                         # Regular user
489                         $conf->Root = false;
490                         $db_user = $wgDBuser;
491                         $db_pass = $wgDBpassword;
492                 } else {
493                         # Superuser
494                         $conf->Root = true;
495                         $db_user = $conf->RootUser;
496                         $db_pass = $conf->RootPW;
497                 }
498                 
499                 # Now attempt the connection
500                 echo( "<li>Connecting to $wgDBname on $wgDBserver as $db_user..." );
501                 $wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, "", 1 );
502                 if( $wgDatabase->isOpen() ) {
503                         # We're in; set up a few variables
504                         $ok = true;
505                         echo( "success.</li>\n" );
506                         $wgDatabase->ignoreErrors( true );
507                         $myver = mysql_get_server_info( $wgDatabase->mConn );
508                         $wgDBadminuser = $db_user;
509                         $wgDBadminpassword = $db_pass;
510                 } else {
511                         # There was an error; if we recognise it, give some useful feedback
512                         $ok = false;
513                         $errno = mysql_errno();
514                         $errtx = htmlspecialchars( mysql_error() );
515                         echo( "failed with error $errno: $errtx.</li>\n" );
516                         switch( $errno ) {
517                                 case 1045:
518                                 case 2000:
519                                         # Authentication
520                                         if( $conf->Root ) {
521                                                 # The superuser details are wrong
522                                                 $errs["RootUser"] = "Check username";
523                                                 $errs["RootPW"] = "and password";
524                                         } else {
525                                                 # The regular user details are wrong
526                                                 $errs["DBuser"] = "Check username";
527                                                 $errs["DBpassword"] = "and password";
528                                         }
529                                         break;
530                                 default:
531                                         # Something else
532                                         $errs["DBserver"] = "Couldn't connect to database";
533                                         break;
534                         } # switch
535                 } # conn att
536
537                 if( !$ok ) continue;
538
539                 # Print out the mySQL version and enable mySQL 4 enhancements as needed
540                 echo( "<li>Connected to $myver" );
541                 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
542                         echo( "; using enhancements for mySQL 4.</li>" );
543                         $conf->DBmysql4 = true;
544                         $local = writeLocalSettings( $conf );
545                 }
546                 
547                 # Check for possible authentication problems re. password encryption in newer mySQL versions
548                 $mysqlNewAuth = version_compare( $myver, "4.1.0", "ge" );
549                 if( $mysqlNewAuth && $mysqlOldClient ) {
550                         echo( "<li><span class=\"error\"><strong>You are using mySQL 4.1, however, PHP is linked to older client libraries. If you encounter authentication problems, 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 pertinent solutions.</strong></span></li>\n" );
551                 }
552                 
553                 # Check versions with regards to character sets, cough up an error if there are inconsistencies
554                 if( $wgDBmysql5 ) {
555                         if( $mysqlNewAuth ) {
556                                 echo( "<li>Enabling mySQL 4.1/5.0 character set mode.</li>\n" );
557                         } else {
558                                 echo( "<li><span class=\"error\"><strong>mySQL 4.1/5.0 character set mode has been enabled, however, an older version of mySQL has been detected. This will likely cause the installation to fail.</li>\n" );
559                         }
560                 }
561
562                 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
563                 if( $sel ) {
564                         print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
565                 } else {
566                         $err = mysql_errno();
567                         if ( $err != 1049 ) {
568                                 print "<ul><li>Error selecting database $wgDBname: $err " . htmlspecialchars( mysql_error() ) .
569                                         "</li></ul>";
570                                 continue;
571                         }
572                         $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
573                         if( !$res ) {
574                                 print "<li>Couldn't create database <tt>" .
575                                         htmlspecialchars( $wgDBname ) .
576                                         "</tt>; try with root access or check your username/pass.</li>\n";
577                                 $errs["RootPW"] = "&lt;- Enter";
578                                 continue;
579                         }
580                         print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
581                 }
582
583                 $wgDatabase->selectDB( $wgDBname );
584
585                 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
586                         print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
587
588                         # Create user if required
589                         if ( $conf->Root ) {
590                                 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
591                                 if ( $conn->isOpen() ) {
592                                         print "<li>DB user account ok</li>\n";
593                                         $conn->close();
594                                 } else {
595                                         print "<li>Granting user permissions...";
596                                         if( $mysqlOldClient && $mysqlNewAuth ) {
597                                                 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>";
598                                         }
599                                         print "</li>\n";
600                                         dbsource( "../maintenance/users.sql", $wgDatabase );
601                                 }
602                         }
603                         print "<pre>\n";
604                         chdir( ".." );
605                         flush();
606                         do_all_updates();
607                         chdir( "config" );
608
609                         print "</pre>\n";
610                         print "<li>Finished update checks.</li>\n";
611                 } else {
612                         # FIXME: Check for errors
613                         print "<li>Creating tables...";
614                         if( $wgDBmysql5 ) {
615                                 print " using MySQL 5 table defs...";
616                                 dbsource( "../maintenance/mysql5/tables.sql", $wgDatabase );
617                         } else {
618                                 print " using MySQL 3/4 table defs...";
619                                 dbsource( "../maintenance/tables.sql", $wgDatabase );
620                         }
621                         dbsource( "../maintenance/interwiki.sql", $wgDatabase );
622                         print " done.</li>\n";
623
624                         print "<li>Initializing data...";
625                         $wgDatabase->insert( 'site_stats',
626                                 array( 'ss_row_id'        => 1,
627                                        'ss_total_views'   => 0,
628                                        'ss_total_edits'   => 0,
629                                        'ss_good_articles' => 0 ) );
630
631
632                         # Set up the DB user if we (i) can and (ii) need to
633                         if( $conf->Root ) {
634                                 $db = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
635                                 if( $db->isOpen() ) {
636                                         $db->close();
637                                 } else {
638                                         print "<li>Granting user permissions...</li>\n";
639                                         dbsource( "../maintenance/users.sql", $wgDatabase );
640                                         $db->close();
641                                 }
642                         }
643
644                         if( $conf->SysopName ) {
645                                 $u = User::newFromName( $conf->getSysopName() );
646                                 if ( 0 == $u->idForName() ) {
647                                         $u->addToDatabase();
648                                         $u->setPassword( $conf->getSysopPass() );
649                                         $u->saveSettings();
650
651                                         $u->addGroup( "sysop" );
652                                         $u->addGroup( "bureaucrat" );
653
654                                         print "<li>Created sysop account <tt>" .
655                                                 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
656                                 } else {
657                                         print "<li>Could not create user - already exists!</li>\n";
658                                 }
659                         } else {
660                                 print "<li>Skipped sysop account creation, no name given.</li>\n";
661                         }
662
663                         $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
664                         $article = new Article( $titleobj );
665                         $newid = $article->insertOn( $wgDatabase );
666                         $revision = new Revision( array(
667                                 'page'      => $newid,
668                                 'text'      => wfMsg( 'mainpagetext' ) . "\n\n" . wfMsg( 'mainpagedocfooter' ),
669                                 'comment'   => '',
670                                 'user'      => 0,
671                                 'user_text' => 'MediaWiki default',
672                                 ) );
673                         $revid = $revision->insertOn( $wgDatabase );
674                         $article->updateRevisionOn( $wgDatabase, $revision );
675
676                         print "<li><pre>";
677                         initialiseMessages();
678                         print "</pre></li>\n";
679                 }
680
681                 /* Write out the config file now that all is well */
682                 print "<p>Creating LocalSettings.php...</p>\n\n";
683                 $localSettings =  "<" . "?php$endl$local$endl?" . ">";
684                 // Fix up a common line-ending problem (due to CVS on Windows)
685                 $localSettings = str_replace( "\r\n", "\n", $localSettings );
686
687                 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
688                         $xt = "xt"; # Refuse to overwrite an existing file
689                 } else {
690                         $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
691                 }
692                 $f = fopen( "LocalSettings.php", $xt );
693
694                 if( $f == false ) {
695                         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" .
696                         "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
697                         "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
698                 }
699                 if(fwrite( $f, $localSettings ) ) {
700                         fclose( $f );
701                         writeSuccessMessage();
702                 } else {
703                         fclose( $f );
704                         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");
705
706                 }
707
708         } while( false );
709 }
710 ?>
711 </ul>
712
713
714 <?php
715
716 if( count( $errs ) ) {
717         /* Display options form */
718
719         if( $conf->posted ) {
720                 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
721         }
722 ?>
723
724 <form action="index.php" name="config" method="post">
725
726
727 <h2>Site config</h2>
728
729 <dl class="setup">
730         <dd>
731                 <?php
732                 aField( $conf, "Sitename", "Site name:" );
733                 ?>
734         </dd>
735         <dt>
736                 Your site name should be a relatively short word. It'll appear as the namespace
737                 name for 'meta' pages as well as throughout the user interface. Good site names
738                 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
739                 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
740                 which may cause problems.
741         </dt>
742
743         <dd>
744                 <?php
745                 aField( $conf, "EmergencyContact", "Contact e-mail" );
746                 ?>
747         </dd>
748         <dt>
749                 This will be used as the return address for password reminders and
750                 may be displayed in some error conditions so visitors can get in
751                 touch with you. It is also be used as the default sender address of e-mail
752                 notifications (enotifs).
753         </dt>
754
755         <dd>
756                 <label class='column' for="LanguageCode">Language</label>
757                 <select id="LanguageCode" name="LanguageCode">
758
759                 <?php
760                         $list = getLanguageList();
761                         foreach( $list as $code => $name ) {
762                                 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
763                                 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
764                         }
765                 ?>
766                 </select>
767         </dd>
768         <dt>
769                 You may select the language for the user interface of the wiki...
770                 Some localizations are less complete than others. Unicode (UTF-8 encoding)
771                 is used for all localizations.
772         </dt>
773
774         <dd>
775                 <label class='column'>Copyright/license metadata</label>
776                 <div>Select one:</div>
777
778                 <ul class="plain">
779                 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
780                 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
781                 <li><?php
782                         aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
783                         $partner = "MediaWiki";
784                         $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
785                         $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
786                         $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
787                         print "<a href=\"$ccApp\">choose</a>";
788                         ?> (link will wipe out any other data in this form!)
789                 <?php if( $conf->License == "cc" ) { ?>
790                         <ul>
791                                 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
792                                 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
793                                 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
794                                 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
795                         </ul>
796                 <?php } ?>
797                         </li>
798                 </ul>
799         </dd>
800         <dt>
801                 MediaWiki can include a basic license notice, icon, and machine-readable
802                 copyright metadata if your wiki's content is to be licensed under
803                 the GNU FDL or a Creative Commons license. If you're not sure, leave
804                 it at "none".
805         </dt>
806
807
808         <dd>
809                 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
810         </dd>
811         <dd>
812                 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
813         </dd>
814         <dd>
815                 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
816         </dd>
817         <dt>
818                 A sysop user account can lock or delete pages, block problematic IP
819                 addresses from editing, and other maintenance tasks. If creating a new
820                 wiki database, a sysop account will be created with the given name
821                 and password.
822         </dt>
823
824         <dd>
825                 <label class='column'>Shared memory caching</label>
826                 <div>Select one:</div>
827
828                 <ul class="plain">
829                 <li><?php aField( $conf, "Shm", "no caching", "radio", "none" ); ?></li>
830                 <?php
831                         if ( $conf->turck ) {
832                                 echo "<li>";
833                                 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
834                                 echo "</li>";
835                         }
836                 ?>
837                 <?php
838                         if ( $conf->eaccel ) {
839                                 echo "<li>";
840                                 aField( $conf, "Shm", "eAccelerator", "radio", "eaccel" );
841                                 echo "</li>";
842                         }
843                 ?>
844                 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
845                 <li><?php aField( $conf, "MCServers", "Memcached servers", "" ) ?></li>
846                 </ul>
847         </dd>
848         <dt>
849                 Using a shared memory system such as Turck MMCache, eAccelerator, or Memcached will speed
850                 up MediaWiki significantly. Memcached is the best solution but needs to be
851                 installed. Specify the server addresses and ports in a comma-separted list. Only
852                 use Turck shared memory if the wiki will be running on a single Apache server.
853         </dl>
854
855 <h2>E-mail, e-mail notification and authentication setup</h2>
856
857 <dl class="setup">
858         <dd>
859                 <label class='column'>E-mail (general)</label>
860                 <div>Select one:</div>
861
862                 <ul class="plain">
863                 <li><?php aField( $conf, "Email", "enabled", "radio", "email_enabled" ); ?></li>
864                 <li><?php aField( $conf, "Email", "disabled", "radio", "email_disabled" ); ?></li>
865                 </ul>
866         </dd>
867         <dt>
868                 Use this to disable all e-mail functions (send a password reminder, user-to-user e-mail and e-mail notification),
869                 if sending e-mails on your server doesn't work.
870         </dt>
871         <dd>
872                 <label class='column'>User-to-user e-mail</label>
873                 <div>Select one:</div>
874
875                 <ul class="plain">
876                 <li><?php aField( $conf, "Emailuser", "enabled", "radio", "emailuser_enabled" ); ?></li>
877                 <li><?php aField( $conf, "Emailuser", "disabled", "radio", "emailuser_disabled" ); ?></li>
878                 </ul>
879         </dd>
880         <dt>
881                 Use this to disable only the user-to-user e-mail function (EmailUser).
882         </dt>
883         <dd>
884                 <label class='column'>E-mail notification</label>
885                 <div>Select one:</div>
886
887                 <ul class="plain">
888                 <li><?php aField( $conf, "Enotif", "disabled", "radio", "enotif_disabled" ); ?></li>
889                 <li><?php aField( $conf, "Enotif", "enabled for changes of watch-listed and user_talk pages (recommended for small wikis; perhaps not suited for large wikis)", "radio", "enotif_allpages" ); ?></li>
890                 <li><?php aField( $conf, "Enotif", "enabled for changes of user_talk pages only (suited for small and large wikis)", "radio", "enotif_usertalk" ); ?></li>
891                 </ul>
892         </dd>
893         <dt>
894                 <p>
895                 E-mail notification sends a notification e-mail to a user, when the user_talk page is changed
896                 and/or when watch-listed pages are changed, depending on the above settings.
897                 When testing this feature, be reminded, that obviously an e-mail address must be present in your preferences
898                 and that your own changes never trigger notifications to be sent to yourself.</p>
899
900                 <p>Users get corresponding options to select or deselect in their users' preferences.
901                 The user options are not shown on the preference page, if e-mail notification is disabled.</p>
902
903                 <p>There are additional options for fine tuning in /includes/DefaultSettings.php .</p>
904         </dt>
905
906         <dd>
907                 <label class='column'>E-mail address authentication</label>
908                 <div>Select one:</div>
909
910                 <ul class="plain">
911                 <li><?php aField( $conf, "Eauthent", "disabled", "radio", "eauthent_disabled" ); ?></li>
912                 <li><?php aField( $conf, "Eauthent", "enabled", "radio", "eauthent_enabled" ); ?></li>
913                 </ul>
914         </dd>
915         <dt>
916                 <p>E-mail address authentication uses a scheme to authenticate e-mail addresses of the users. The user who initially enters or changes his/her stored e-mail address
917                 gets a link with a token mailed to that address. The stored e-mail address is authenticated at the moment the user comes back to the wiki via the link.</p>
918
919                 <p>The e-mail address stays authenticated as long as the user does not change it; the time of authentication is indicated
920                 on the user preference page.</p>
921
922                 <p>If the option is enabled, only authenticated e-mail addresses can receive EmailUser mails and/or
923                 e-mail notification mails.</p>
924         </dt>
925
926         </dl>
927
928 <h2>Database config</h2>
929
930 <dl class="setup">
931         <dd><?php
932                 aField( $conf, "DBserver", "MySQL server" );
933         ?></dd>
934         <dt>
935                 If your database server isn't on your web server, enter the name
936                 or IP address here.
937         </dt>
938
939         <dd><?php
940                 aField( $conf, "DBname", "Database name" );
941         ?></dd>
942         <dd><?php
943                 aField( $conf, "DBuser", "DB username" );
944         ?></dd>
945         <dd><?php
946                 aField( $conf, "DBpassword", "DB password", "password" );
947         ?></dd>
948         <dd><?php
949                 aField( $conf, "DBpassword2", "again", "password" );
950         ?></dd>
951         <dt>
952                 If you only have a single user account and database available,
953                 enter those here. If you have database root access (see below)
954                 you can specify new accounts/databases to be created.
955         </dt>
956
957         <dd><?php
958                 aField( $conf, "DBprefix", "Database table prefix" );
959         ?></dd>
960         <dt>
961                 <p>If you need to share one database between multiple wikis, or
962                 MediaWiki and another web application, you may choose to
963                 add a prefix to all the table names to avoid conflicts.</p>
964
965                 <p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
966         </dt>
967         
968         <dd><label class="column">Database charset</label>
969                 <div>Select one:</div>
970                 <ul class="plain">
971                 <li><?php aField( $conf, "DBmysql5", "Backwards-compatible UTF-8", "radio", "false" ); ?></li>
972                 <li><?php aField( $conf, "DBmysql5", "Experimental MySQL 4.1/5.0 UTF-8", "radio", "true" ); ?></li>
973                 </ul>
974         </dd>
975         <dt>
976                 <b>EXPERIMENTAL:</b> You can enable explicit Unicode charset support
977                 for MySQL 4.1 and 5.0 servers. This is not well tested and may
978                 cause things to break. <b>If upgrading an older installation, leave
979                 in backwards-compatible mode.</b>
980         </dt>
981
982         <dd>
983                 <?php
984                 aField( $conf, "RootUser", "Super user:", "text" );
985                 ?>
986         </dd>
987
988         <dd>
989                 <?php
990                 aField( $conf, "RootPW", "Password:", "password" );
991                 ?>
992         </dd>
993         <dt>
994                 If the database user specified above does not exist, or does not have permissions to create
995                 the database or tables required, please provide details of a superuser account, such as <strong>root</strong>,
996                 which does. If this is not needed, leave the password set to <strong>-</strong>.
997         </dt>
998
999         <dd>
1000                 <label class='column'>&nbsp;</label>
1001                 <input type="submit" value="Install!" />
1002         </dd>
1003 </dl>
1004
1005
1006 </form>
1007
1008 <?php
1009 }
1010
1011 /* -------------------------------------------------------------------------------------- */
1012 function writeSuccessMessage() {
1013         global $conf;
1014         if ( ini_get( 'safe_mode' ) && !ini_get( 'open_basedir' ) ) {
1015                 echo <<<EOT
1016 <p>Installation successful!</p>
1017 <p>To complete the installation, please do the following:
1018 <ol>
1019         <li>Download config/LocalSettings.php with your FTP client or file manager</li>
1020         <li>Upload it to the parent directory</li>
1021         <li>Delete config/LocalSettings.php</li>
1022         <li>Start using <a href='../index.php'>your wiki</a>!
1023 </ol>
1024 <p>If you are in a shared hosting environment, do <strong>not</strong> just move LocalSettings.php
1025 remotely. LocalSettings.php is currently owned by the user your webserver is running under,
1026 which means that anyone on the same server can read your database password! Downloading
1027 it and uploading it again will hopefully change the ownership to a user ID specific to you.</p>
1028 EOT;
1029         } else {
1030                 echo "<p>Installation successful! Move the config/LocalSettings.php file into the parent directory, then follow
1031                         <a href='../index.php'>this link</a> to your wiki.</p>\n";
1032         }
1033 }
1034
1035
1036 function escapePhpString( $string ) {
1037         return strtr( $string,
1038                 array(
1039                         "\n" => "\\n",
1040                         "\r" => "\\r",
1041                         "\t" => "\\t",
1042                         "\\" => "\\\\",
1043                         "\$" => "\\\$",
1044                         "\"" => "\\\""
1045                 ));
1046 }
1047
1048 function writeLocalSettings( $conf ) {
1049         $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
1050         $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
1051         $conf->PasswordSender = $conf->EmergencyContact;
1052         $zlib = ($conf->zlib ? "" : "# ");
1053         $magic = ($conf->ImageMagick ? "" : "# ");
1054         $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
1055         $pretty = ($conf->prettyURLs ? "" : "# ");
1056         $ugly = ($conf->prettyURLs ? "# " : "");
1057         $rights = ($conf->RightsUrl) ? "" : "# ";
1058         $hashedUploads = $conf->safeMode ? '' : '# ';
1059
1060         switch ( $conf->Shm ) {
1061                 case 'memcached':
1062                         $cacheType = 'CACHE_MEMCACHED';
1063                         $mcservers = var_export( $conf->MCServerArray, true );
1064                         break;
1065                 case 'turck':
1066                 case 'eaccel':
1067                         $cacheType = 'CACHE_ACCEL';
1068                         $mcservers = 'array()';
1069                         break;
1070                 default:
1071                         $cacheType = 'CACHE_NONE';
1072                         $mcservers = 'array()';
1073         }
1074
1075         if ( $conf->Email == 'email_enabled' ) {
1076                 $enableemail = 'true';
1077                 $enableuseremail = ( $conf->Emailuser == 'emailuser_enabled' ) ? 'true' : 'false' ;
1078                 $eauthent = ( $conf->Eauthent == 'eauthent_enabled' ) ? 'true' : 'false' ;
1079                 switch ( $conf->Enotif ) {
1080                         case 'enotif_usertalk':
1081                                 $enotifusertalk = 'true';
1082                                 $enotifwatchlist = 'false';
1083                                 break;
1084                         case 'enotif_allpages':
1085                                 $enotifusertalk = 'true';
1086                                 $enotifwatchlist = 'true';
1087                                 break;
1088                         default:
1089                                 $enotifusertalk = 'false';
1090                                 $enotifwatchlist = 'false';
1091                 }
1092         } else {
1093                 $enableuseremail = 'false';
1094                 $enableemail = 'false';
1095                 $eauthent = 'false';
1096                 $enotifusertalk = 'false';
1097                 $enotifwatchlist = 'false';
1098         }
1099
1100         $file = @fopen( "/dev/urandom", "r" );
1101         if ( $file ) {
1102                 $secretKey = bin2hex( fread( $file, 32 ) );
1103                 fclose( $file );
1104         } else {
1105                 $secretKey = "";
1106                 for ( $i=0; $i<8; $i++ ) {
1107                         $secretKey .= dechex(mt_rand(0, 0x7fffffff));
1108                 }
1109                 print "<li>Warning: \$wgSecretKey key is insecure, generated with mt_rand(). Consider changing it manually.</li>\n";
1110         }
1111
1112         # Add slashes to strings for double quoting
1113         $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
1114         if( $conf->License == 'gfdl' ) {
1115                 # Needs literal string interpolation for the current style path
1116                 $slconf['RightsIcon'] = $conf->RightsIcon;
1117         }
1118
1119         $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
1120         $localsettings = "
1121 # This file was automatically generated by the MediaWiki installer.
1122 # If you make manual changes, please keep track in case you need to
1123 # recreate them later.
1124
1125 \$IP = \"{$slconf['IP']}\";
1126 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
1127 require_once( \"includes/DefaultSettings.php\" );
1128
1129 # If PHP's memory limit is very low, some operations may fail.
1130 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
1131
1132 if ( \$wgCommandLineMode ) {
1133         if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
1134                 die( \"This script must be run from the command line\\n\" );
1135         }
1136 } elseif ( empty( \$wgNoOutputBuffer ) ) {
1137         ## Compress output if the browser supports it
1138         {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
1139 }
1140
1141 \$wgSitename         = \"{$slconf['Sitename']}\";
1142
1143 \$wgScriptPath      = \"{$slconf['ScriptPath']}\";
1144 \$wgScript           = \"\$wgScriptPath/index.php\";
1145 \$wgRedirectScript   = \"\$wgScriptPath/redirect.php\";
1146
1147 ## If using PHP as a CGI module, use the ugly URLs
1148 {$pretty}\$wgArticlePath      = \"\$wgScript/\$1\";
1149 {$ugly}\$wgArticlePath      = \"\$wgScript?title=\$1\";
1150
1151 \$wgStylePath        = \"\$wgScriptPath/skins\";
1152 \$wgStyleDirectory   = \"\$IP/skins\";
1153 \$wgLogo             = \"\$wgStylePath/common/images/wiki.png\";
1154
1155 \$wgUploadPath       = \"\$wgScriptPath/images\";
1156 \$wgUploadDirectory  = \"\$IP/images\";
1157
1158 \$wgEnableEmail = $enableemail;
1159 \$wgEnableUserEmail = $enableuseremail;
1160
1161 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
1162 \$wgPasswordSender      = \"{$slconf['PasswordSender']}\";
1163
1164 ## For a detailed description of the following switches see
1165 ## http://meta.wikimedia.org/Enotif and http://meta.wikimedia.org/Eauthent
1166 ## There are many more options for fine tuning available see
1167 ## /includes/DefaultSettings.php
1168 ## UPO means: this is also a user preference option
1169 \$wgEnotifUserTalk = $enotifusertalk; # UPO
1170 \$wgEnotifWatchlist = $enotifwatchlist; # UPO
1171 \$wgEmailAuthentication = $eauthent;
1172
1173 \$wgDBserver         = \"{$slconf['DBserver']}\";
1174 \$wgDBname           = \"{$slconf['DBname']}\";
1175 \$wgDBuser           = \"{$slconf['DBuser']}\";
1176 \$wgDBpassword       = \"{$slconf['DBpassword']}\";
1177 \$wgDBprefix         = \"{$slconf['DBprefix']}\";
1178
1179 # If you're on MySQL 3.x, this next line must be FALSE:
1180 \$wgDBmysql4 = {$conf->DBmysql4};
1181
1182 # Experimental charset support for MySQL 4.1/5.0.
1183 \$wgDBmysql5 = {$conf->DBmysql5};
1184
1185 ## Shared memory settings
1186 \$wgMainCacheType = $cacheType;
1187 \$wgMemCachedServers = $mcservers;
1188
1189 ## To enable image uploads, make sure the 'images' directory
1190 ## is writable, then uncomment this:
1191 # \$wgEnableUploads             = true;
1192 \$wgUseImageResize              = {$conf->UseImageResize};
1193 {$magic}\$wgUseImageMagick = true;
1194 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
1195
1196 ## If you want to use image uploads under safe mode,
1197 ## create the directories images/archive, images/thumb and
1198 ## images/temp, and make them all writable. Then uncomment
1199 ## this, if it's not already uncommented:
1200 {$hashedUploads}\$wgHashedUploadDirectory = false;
1201
1202 ## If you have the appropriate support software installed
1203 ## you can enable inline LaTeX equations:
1204 # \$wgUseTeX                    = true;
1205 \$wgMathPath         = \"{\$wgUploadPath}/math\";
1206 \$wgMathDirectory    = \"{\$wgUploadDirectory}/math\";
1207 \$wgTmpDirectory     = \"{\$wgUploadDirectory}/tmp\";
1208
1209 \$wgLocalInterwiki   = \$wgSitename;
1210
1211 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
1212
1213 \$wgProxyKey = \"$secretKey\";
1214
1215 ## Default skin: you can change the default skin. Use the internal symbolic
1216 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
1217 # \$wgDefaultSkin = 'monobook';
1218
1219 ## For attaching licensing metadata to pages, and displaying an
1220 ## appropriate copyright notice / icon. GNU Free Documentation
1221 ## License and Creative Commons licenses are supported so far.
1222 {$rights}\$wgEnableCreativeCommonsRdf = true;
1223 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
1224 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
1225 \$wgRightsText = \"{$slconf['RightsText']}\";
1226 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
1227 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
1228
1229 \$wgDiff3 = \"{$slconf['diff3']}\";
1230 ";
1231         // Keep things in Unix line endings internally;
1232         // the system will write out as local text type.
1233         return str_replace( "\r\n", "\n", $localsettings );
1234 }
1235
1236 function dieout( $text ) {
1237         die( $text . "\n\n</body>\n</html>" );
1238 }
1239
1240 function importVar( &$var, $name, $default = "" ) {
1241         if( isset( $var[$name] ) ) {
1242                 $retval = $var[$name];
1243                 if ( get_magic_quotes_gpc() ) {
1244                         $retval = stripslashes( $retval );
1245                 }
1246         } else {
1247                 $retval = $default;
1248         }
1249         return $retval;
1250 }
1251
1252 function importPost( $name, $default = "" ) {
1253         return importVar( $_POST, $name, $default );
1254 }
1255
1256 function importRequest( $name, $default = "" ) {
1257         return importVar( $_REQUEST, $name, $default );
1258 }
1259
1260 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
1261         if( $type != "" ) {
1262                 $xtype = "type=\"$type\"";
1263         } else {
1264                 $xtype = "";
1265         }
1266
1267         if(!(isset($id)) or ($id == "") ) $id = $field;
1268         $nolabel = ($type == "radio") || ($type == "hidden");
1269         if( $nolabel ) {
1270                 echo "\t\t<label>";
1271         } else {
1272                 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1273         }
1274
1275         if( $type == "radio" && $value == $conf->$field ) {
1276                 $checked = "checked='checked'";
1277         } else {
1278                 $checked = "";
1279         }
1280         echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
1281         if( $type == "radio" ) {
1282                 echo htmlspecialchars( $value );
1283         } else {
1284                 echo htmlspecialchars( $conf->$field );
1285         }
1286         echo "\" />\n";
1287         if( $nolabel ) {
1288                 echo " $text</label>\n";
1289         }
1290
1291         global $errs;
1292         if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1293 }
1294
1295 function getLanguageList() {
1296         global $wgLanguageNames;
1297         if( !isset( $wgLanguageNames ) ) {
1298                 $wgContLanguageCode = "xxx";
1299                 function wfLocalUrl( $x ) { return $x; }
1300                 function wfLocalUrlE( $x ) { return $x; }
1301                 require_once( "languages/Names.php" );
1302         }
1303
1304         $codes = array();
1305
1306         $d = opendir( "../languages" );
1307         while( false !== ($f = readdir( $d ) ) ) {
1308                 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1309                         $code = str_replace( '_', '-', strtolower( $m[1] ) );
1310                         if( isset( $wgLanguageNames[$code] ) ) {
1311                                 $name = $code . ' - ' . $wgLanguageNames[$code];
1312                         } else {
1313                                 $name = $code;
1314                         }
1315                         $codes[$code] = $name;
1316                 }
1317         }
1318         closedir( $d );
1319         ksort( $codes );
1320         return $codes;
1321 }
1322
1323 #Check for location of an executable
1324 # @param string $loc single location to check
1325 # @param array $names filenames to check for.
1326 # @param mixed $versioninfo array of details to use when checking version, use false for no version checking
1327 function locate_executable($loc, $names, $versioninfo = false) {
1328         if (!is_array($names))
1329                 $names = array($names);
1330
1331         foreach ($names as $name) {
1332                 if (file_exists("$loc/$name")) {
1333                         if (!$versioninfo)
1334                                 return "$loc/$name";
1335
1336                         $file = str_replace('$1', "$loc/$name", $versioninfo[0]);
1337                         if (strstr(`$file`, $versioninfo[1]) !== false)
1338                                 return "$loc/$name";
1339                 }
1340         }
1341         return false;
1342 }
1343
1344 # Test a memcached server
1345 function testMemcachedServer( $server ) {
1346         $hostport = explode(":", $server);
1347         $errstr = false;
1348         $fp = false;
1349         if ( !function_exists( 'fsockopen' ) ) {
1350                 $errstr = "Can't connect to memcached, fsockopen() not present";
1351         }
1352         if ( !$errstr &&  count( $hostport ) != 2 ) {
1353                 $errstr = 'Please specify host and port';
1354                 var_dump( $hostport );
1355         }
1356         if ( !$errstr ) {
1357                 list( $host, $port ) = $hostport;
1358                 $errno = 0;
1359                 $fsockerr = '';
1360
1361                 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1362                 if ( $fp === false ) {
1363                         $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1364                 }
1365         }
1366         if ( !$errstr ) {
1367                 $command = "version\r\n";
1368                 $bytes = fwrite( $fp, $command );
1369                 if ( $bytes != strlen( $command ) ) {
1370                         $errstr = "Cannot write to memcached socket on $host:$port";
1371                 }
1372         }
1373         if ( !$errstr ) {
1374                 $expected = "VERSION ";
1375                 $response = fread( $fp, strlen( $expected ) );
1376                 if ( $response != $expected ) {
1377                         $errstr = "Didn't get correct memcached response from $host:$port";
1378                 }
1379         }
1380         if ( $fp ) {
1381                 fclose( $fp );
1382         }
1383         if ( !$errstr ) {
1384                 echo "<li>Connected to memcached on $host:$port successfully";
1385         }
1386         return $errstr;
1387 }
1388 ?>
1389
1390 </body>
1391 </html>