Catch error 2000, too. Some mysql servers return 2000 instead of 1045
[lhc/web/wiklou.git] / config / index.php
1 <?php
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 error_reporting( E_ALL );
22 header( "Content-type: text/html; charset=utf-8" );
23 @ini_set( "display_errors", true );
24
25 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
26 "http://www.w3.org/TR/html4/loose.dtd">
27 <html>
28 <head>
29 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
30 <meta name="robots" content="noindex,nofollow">
31 <title>MediaWiki installation</title>
32 <style type="text/css">
33 #credit {
34 float: right;
35 width: 200px;
36 font-size: 0.7em;
37 background-color: #eee;
38 color: black;
39 border: solid 1px #444;
40 padding: 8px;
41 margin-left: 8px;
42 }
43
44 dl.setup dd {
45 margin-left: 0;
46 }
47 dl.setup dd label.column {
48 clear: left;
49 font-weight: bold;
50 width: 12em;
51 float: left;
52 text-align: right;
53 padding-right: 1em;
54 }
55 dl.setup dt {
56 clear: left;
57 font-size: 0.8em;
58 margin-left: 10em;
59 /* margin-right: 200px; */
60 margin-bottom: 2em;
61 }
62 .error {
63 color: red;
64 }
65 ul.plain {
66 list-style: none;
67 clear: both;
68 margin-left: 12em;
69 }
70 </style>
71 </head>
72
73 <body>
74
75 <div id="credit">
76 <center>
77 <a href="http://www.mediawiki.org/"><img
78 src="../skins/common/images/wiki.png" width="135" height="135" alt="" border="0" /></a>
79 </center>
80
81 <b><a href="http://www.mediawiki.org/">MediaWiki</a></b> is
82 Copyright (C) 2001-2004 by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
83 Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
84
85 <ul>
86 <li><a href="../README">Readme</a></li>
87 <li><a href="../RELEASE-NOTES">Release notes</a></li>
88 <li><a href="../docs/">doc/</a></li>
89 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
90 </ul>
91
92 <p>This program is free software; you can redistribute it and/or modify
93 it under the terms of the GNU General Public License as published by
94 the Free Software Foundation; either version 2 of the License, or
95 (at your option) any later version.</p>
96
97 <p>This program is distributed in the hope that it will be useful,
98 but WITHOUT ANY WARRANTY; without even the implied warranty of
99 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100 GNU General Public License for more details.</p>
101
102 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
103 along with this program; if not, write to the Free Software
104 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
105 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
106 </div>
107
108 <?php
109
110 $IP = ".."; # Just to suppress notices, not for anything useful
111 define( "MEDIAWIKI", true );
112 define( "MEDIAWIKI_INSTALL", true );
113 require_once( "../includes/Defines.php" );
114 require_once( "../includes/DefaultSettings.php" );
115 require_once( "../includes/MagicWord.php" );
116 require_once( "../includes/Namespace.php" );
117 ?>
118
119 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
120
121
122 <?php
123
124 /* Check for existing configurations and bug out! */
125
126 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
127 dieout( "<h2>Wiki is configured.</h2>
128
129 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
130
131 <p>(You should probably remove this directory for added security.)</p>" );
132 }
133
134 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
135 dieout( "<h2>You're configured!</h2>
136
137 <p>Please move <tt>LocalSettings.php</tt> to the parent directory, then
138 <a href='../index.php'>try out your wiki</a>.
139 (You should remove this config directory for added security once you're done.)</p>" );
140 }
141
142 if( !is_writable( "." ) ) {
143 dieout( "<h2>Can't write config file, aborting</h2>
144
145 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
146 writable by the web server. Once configuration is done you'll move the created
147 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
148 then remove the <tt>config</tt> subdirectory entirely.</p>
149
150 <p>To make the directory writable on a Unix/Linux system:</p>
151
152 <pre>
153 cd <i>/path/to/wiki</i>
154 chmod a+w config
155 </pre>" );
156 }
157
158
159 require_once( "../install-utils.inc" );
160 require_once( "../maintenance/updaters.inc" );
161 require_once( "../maintenance/convertLinks.inc" );
162 require_once( "../maintenance/archives/moveCustomMessages.inc" );
163
164 class ConfigData {
165 function getEncoded( $data ) {
166 # Hackish
167 global $wgUseLatin1;
168 if( $wgUseLatin1 ) {
169 return utf8_decode( $data ); /* to latin1 wikis */
170 } else {
171 return $data;
172 }
173 }
174 function getSitename() { return $this->getEncoded( $this->Sitename ); }
175 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
176 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
177 }
178
179 ?>
180
181 <p><i>Please include all of the lines below when reporting installation problems.</i></p>
182
183 <h2>Checking environment...</h2>
184 <ul>
185 <?php
186 $endl = "
187 ";
188 $wgConfiguring = true;
189 $conf = new ConfigData;
190
191 install_version_checks();
192
193 print "<li>PHP " . phpversion() . ": ";
194 if( version_compare( phpversion(), "5.0", "lt" ) ) {
195 print "ok";
196 } else {
197 print " <b>the MonoBook skin will be disabled due to an incompatibility
198 between the PHPTAL template library and PHP 5</b>. The wiki should
199 function normally, but with the older look and feel.";
200 }
201 print "</li>\n";
202
203 if( ini_get( "register_globals" ) ) {
204 ?>
205 <li><b class='error'>Warning:</b> <b>PHP's
206 <tt><a href="http://php.net/register_globals">register_globals</a></tt>
207 option is enabled.</b> MediaWiki will work correctly, but this setting
208 increases your exposure to potential security vulnerabilities in PHP-based
209 software running on your server. <b>You should disable it if you are able.</b></li>
210 <?php
211 }
212
213 if( ini_get( "safe_mode" ) ) {
214 ?>
215 <li class='error'><b>Warning: PHP's
216 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
217 You will likely have problems caused by this. You may need to make the
218 'images' subdirectory writable or specify a TMP environment variable pointing to
219 a writable temporary directory owned by you, since safe mode breaks the system
220 temporary directory.</li>
221 <?php
222 }
223
224 $sapi = php_sapi_name();
225 $conf->prettyURLs = true;
226 print "<li>PHP server API is $sapi; ";
227 switch( $sapi ) {
228 case "apache":
229 case "apache2handler":
230 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
231 break;
232 case "cgi":
233 case "cgi-fcgi":
234 case "apache2filter":
235 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
236 $conf->prettyURLs = false;
237 break;
238 default:
239 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
240 }
241 print "</li>\n";
242
243 $conf->xml = function_exists( "utf8_encode" );
244 if( $conf->xml ) {
245 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
246 } else {
247 dieout( "PHP's XML module is missing; the wiki requires functions in
248 this module and won't work in this configuration.
249 If you're running Mandrake, install the php-xml package." );
250 }
251
252 $memlimit = ini_get( "memory_limit" );
253 $conf->raiseMemory = false;
254 if( empty( $memlimit ) ) {
255 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
256 } else {
257 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <b>If this is too low, installation may fail!</b> ";
258 $n = IntVal( $memlimit );
259 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
260 $n = IntVal( $m[1] * (1024*1024) );
261 }
262 if( $n < 20*1024*1024 ) {
263 print "Attempting to raise limit to 20M... ";
264 if( false === ini_set( "memory_limit", "20M" ) ) {
265 print "failed.";
266 } else {
267 $conf->raiseMemory = true;
268 print "ok.";
269 }
270 }
271 print "</li>\n";
272 }
273
274 $conf->zlib = function_exists( "gzencode" );
275 if( $conf->zlib ) {
276 print "<li>Have zlib support; enabling output compression.</li>\n";
277 } else {
278 print "<li>No zlib support.</li>\n";
279 }
280
281 $conf->ImageMagick = false;
282 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
283 foreach( $imcheck as $dir ) {
284 $im = "$dir/convert";
285 if( file_exists( $im ) ) {
286 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
287 $conf->ImageMagick = $im;
288 break;
289 }
290 }
291
292 $conf->HaveGD = function_exists( "imagejpeg" );
293 if( $conf->HaveGD ) {
294 print "<li>Found GD graphics library built-in";
295 if( !$conf->ImageMagick ) {
296 print ", image thumbnailing will be enabled if you enable uploads";
297 }
298 print ".</li>\n";
299 } else {
300 if( !$conf->ImageMagick ) {
301 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
302 }
303 }
304
305 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
306
307 # $conf->IP = "/Users/brion/Sites/inplace";
308 $conf->IP = dirname( dirname( __FILE__ ) );
309 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
310
311 # $conf->ScriptPath = "/~brion/inplace";
312 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
313 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
314
315 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
316
317 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
318 $conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
319 $conf->DBserver = importPost( "DBserver", "localhost" );
320 $conf->DBname = importPost( "DBname", "wikidb" );
321 $conf->DBuser = importPost( "DBuser", "wikiuser" );
322 $conf->DBpassword = importPost( "DBpassword" );
323 $conf->DBpassword2 = importPost( "DBpassword2" );
324 $conf->RootPW = importPost( "RootPW" );
325 $conf->LanguageCode = importPost( "LanguageCode", "en" );
326 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
327 $conf->SysopPass = importPost( "SysopPass" );
328 $conf->SysopPass2 = importPost( "SysopPass2" );
329
330 /* Check for validity */
331 $errs = array();
332
333 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
334 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
335 }
336 if( $conf->DBuser == "" ) {
337 $errs["DBuser"] = "Must not be blank";
338 }
339 if( $conf->DBpassword == "" ) {
340 $errs["DBpassword"] = "Must not be blank";
341 }
342 if( $conf->DBpassword != $conf->DBpassword2 ) {
343 $errs["DBpassword2"] = "Passwords don't match!";
344 }
345
346 if( $conf->SysopPass == "" ) {
347 $errs["SysopPass"] = "Must not be blank";
348 }
349 if( $conf->SysopPass != $conf->SysopPass2 ) {
350 $errs["SysopPass2"] = "Passwords don't match!";
351 }
352
353 $conf->License = importRequest( "License", "none" );
354 if( $conf->License == "gfdl" ) {
355 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
356 $conf->RightsText = "GNU Free Documentation License 1.2";
357 $conf->RightsCode = "gfdl";
358 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
359 } elseif( $conf->License == "none" ) {
360 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
361 } else {
362 $conf->RightsUrl = importRequest( "RightsUrl", "" );
363 $conf->RightsText = importRequest( "RightsText", "" );
364 $conf->RightsCode = importRequest( "RightsCode", "" );
365 $conf->RightsIcon = importRequest( "RightsIcon", "" );
366 }
367
368 if( $conf->posted && ( 0 == count( $errs ) ) ) {
369 do { /* So we can 'continue' to end prematurely */
370 $conf->Root = ($conf->RootPW != "");
371
372 /* Load up the settings and get installin' */
373 $local = writeLocalSettings( $conf );
374 $wgCommandLineMode = false;
375 chdir( ".." );
376 eval($local);
377 $wgDBadminuser = "root";
378 $wgDBadminpassword = $conf->RootPW;
379 $wgCommandLineMode = true;
380 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
381 require_once( "includes/Setup.php" );
382 chdir( "config" );
383
384 require_once( "../maintenance/InitialiseMessages.inc" );
385
386 $wgTitle = Title::newFromText( "Installation script" );
387 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
388 $wgDatabase->mIgnoreErrors = true;
389
390 @$myver = mysql_get_server_info( $wgDatabase->mConn );
391 if( $myver ) {
392 $conf->Root = true;
393 print "<li>Connected as root (automatic)</li>\n";
394 } else {
395 print "<li>MySQL error " . ($err = mysql_errno() ) .
396 ": " . htmlspecialchars( mysql_error() );
397 $ok = false;
398 switch( $err ) {
399 case 1045:
400 case 2000:
401 if( $conf->Root ) {
402 $errs["RootPW"] = "Check password";
403 } else {
404 print "<li>Trying regular user...\n";
405 /* Try the regular user... */
406 $wgDBadminuser = $wgDBuser;
407 $wgDBadminpassword = $wgDBpassword;
408 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
409 $wgDatabase->isOpen();
410 $wgDatabase->mIgnoreErrors = true;
411 @$myver = mysql_get_server_info( $wgDatabase->mConn );
412 if( !$myver ) {
413 $errs["DBuser"] = "Check name/pass";
414 $errs["DBpassword"] = "or enter root";
415 $errs["DBpassword2"] = "password below";
416 $errs["RootPW"] = "Got root?";
417 print " need password.</li>\n";
418 } else {
419 $conf->Root = false;
420 $conf->RootPW = "";
421 print " ok.</li>\n";
422 # And keep going...
423 $ok = true;
424 }
425 break;
426 }
427 case 2002:
428 case 2003:
429 $errs["DBserver"] = "Connection failed";
430 break;
431 default:
432 $errs["DBserver"] = "Couldn't connect to database";
433 break;
434 }
435 if( !$ok ) continue;
436 }
437
438 if ( !$wgDatabase->isOpen() ) {
439 $errs["DBserver"] = "Couldn't connect to database";
440 continue;
441 }
442
443 print "<li>Connected to database... $myver";
444 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
445 print "; enabling MySQL 4 enhancements";
446 $conf->DBmysql4 = true;
447 $local = writeLocalSettings( $conf );
448 }
449 print "</li>\n";
450
451 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
452 if( $sel ) {
453 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
454 } else {
455 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
456 if( !$res ) {
457 print "<li>Couldn't create database <tt>" .
458 htmlspecialchars( $wgDBname ) .
459 "</tt>; try with root access or check your username/pass.</li>\n";
460 $errs["RootPW"] = "&lt;- Enter";
461 continue;
462 }
463 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
464 }
465
466 $wgDatabase->selectDB( $wgDBname );
467
468 if( $wgDatabase->tableExists( "cur" ) ) {
469 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
470
471 # Create user if required
472 if ( $conf->Root ) {
473 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
474 if ( $conn->isOpen() ) {
475 print "<li>DB user account ok</li>\n";
476 $conn->close();
477 } else {
478 print "<li>Granting user permissions...</li>\n";
479 dbsource( "../maintenance/users.sql", $wgDatabase );
480 }
481 }
482 print "<pre>\n";
483 chdir( ".." );
484 flush();
485
486
487 # Add missing tables
488 foreach ( $wgNewTables as $tableRecord ) {
489 add_table( $tableRecord[0], $tableRecord[1] );
490 flush();
491 }
492
493 # Add missing fields
494 foreach ( $wgNewFields as $fieldRecord ) {
495 add_table( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
496 flush();
497 }
498
499 # Do schema updates which require special handling
500 do_interwiki_update(); flush();
501 do_index_update(); flush();
502 do_linkscc_1_3_update(); flush();
503 convertLinks(); flush();
504 do_image_name_unique_update(); flush();
505
506 if ( isTemplateInitialised() ) {
507 print "Template namespace already initialised\n";
508 } else {
509 moveCustomMessages( 1 ); flush();
510 moveCustomMessages( 2 ); flush();
511 moveCustomMessages( 3 ); flush();
512 }
513
514 initialiseMessages(); flush();
515 chdir( "config" );
516
517 print "</pre>\n";
518 print "<li>Finished update checks.</li>\n";
519 } else {
520 # FIXME: Check for errors
521 print "<li>Creating tables...";
522 dbsource( "../maintenance/tables.sql", $wgDatabase );
523 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
524 print " done.</li>\n";
525
526 print "<li>Initializing data...";
527 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
528 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
529 # setting up the db user
530 if( $conf->Root ) {
531 print "<li>Granting user permissions...</li>\n";
532 dbsource( "../maintenance/users.sql", $wgDatabase );
533 }
534
535 if( $conf->SysopName ) {
536 $u = User::newFromName( $conf->getSysopName() );
537 if ( 0 == $u->idForName() ) {
538 $u->addToDatabase();
539 $u->setPassword( $conf->getSysopPass() );
540 $u->addRight( "sysop" );
541 $u->addRight( "bureaucrat" );
542 $u->saveSettings();
543 print "<li>Created sysop account <tt>" .
544 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
545 } else {
546 print "<li>Could not create user - already exists!</li>\n";
547 }
548 } else {
549 print "<li>Skipped sysop account creation, no name given.</li>\n";
550 }
551
552 print "<li>Initialising log pages...";
553 $logs = array(
554 "uploadlogpage" => "uploadlogpagetext",
555 "dellogpage" => "dellogpagetext",
556 "protectlogpage" => "protectlogtext",
557 "blocklogpage" => "blocklogtext"
558 );
559 $metaNamespace = Namespace::getWikipedia();
560 $now = wfTimestampNow();
561 $won = wfInvertTimestamp( $now );
562 foreach( $logs as $page => $text ) {
563 $logTitle = $wgDatabase->strencode( $wgLang->ucfirst( str_replace( " ", "_", wfMsgNoDB( $page ) ) ) );
564 $logText = $wgDatabase->strencode( wfMsgNoDB( $text ) );
565 $wgDatabase->query( "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
566 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) " .
567 "VALUES ($metaNamespace,'$logTitle','$logText','sysop','$now','$won','$now')" );
568 }
569 print "</li>\n";
570
571 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
572 $title = $titleobj->getDBkey();
573 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched,cur_user,cur_user_text) " .
574 "VALUES (0,'$title','" .
575 wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) .
576 "','$now','$won','$now',0,'MediaWiki default')";
577 $wgDatabase->query( $sql, $fname );
578
579 print "<li><pre>";
580 initialiseMessages();
581 print "</pre></li>\n";
582 }
583
584 /* Write out the config file now that all is well */
585 print "<p>Creating LocalSettings.php...</p>\n\n";
586 $localSettings = "<" . "?php$endl$local$endl?" . ">";
587
588 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
589 $xt = "xt"; # Refuse to overwrite an existing file
590 } else {
591 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
592 }
593 $f = fopen( "LocalSettings.php", $xt );
594
595 if( $f == false ) {
596 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" .
597 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
598 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
599 }
600 fwrite( $f, $localSettings );
601 fclose( $f );
602
603 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
604 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
605
606 } while( false );
607 }
608 ?>
609 </ul>
610
611
612 <?php
613
614 if( count( $errs ) ) {
615 /* Display options form */
616
617 if( $conf->posted ) {
618 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
619 }
620 ?>
621
622 <form name="config" method="post">
623
624
625 <h2>Site config</h2>
626
627 <dl class="setup">
628 <dd>
629 <?php
630 aField( $conf, "Sitename", "Site name:" );
631 ?>
632 </dd>
633 <dt>
634 Your site name should be a relatively short word. It'll appear as the namespace
635 name for 'meta' pages as well as throughout the user interface. Good site names
636 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
637 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
638 which may cause problems.
639 </dt>
640
641 <dd>
642 <?php
643 aField( $conf, "EmergencyContact", "Contact e-mail" );
644 ?>
645 </dd>
646 <dt>
647 This will be used as the return address for password reminders and
648 may be displayed in some error conditions so visitors can get in
649 touch with you.
650 </dt>
651
652 <dd>
653 <label class='column' for="LanguageCode">Language</label>
654 <select id="LanguageCode" name="LanguageCode">
655 <?php
656 $list = getLanguageList();
657 foreach( $list as $code => $name ) {
658 $sel = ($code == $conf->LanguageCode) ? "selected" : "";
659 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
660 }
661 ?>
662 </select>
663 </dd>
664 <dt>
665 You may select the language for the user interface of the wiki...
666 Some localizations are less complete than others. This also controls
667 the character encoding; Unicode is more flexible, but Latin-1 may be
668 more compatible with older browsers for some languages. Unicode will
669 be used where not specified otherwise.
670 </dt>
671
672 <dd>
673 <label class='column'>Copyright/license metadata</label>
674 <div>Select one:</div>
675
676 <ul class="plain">
677 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
678 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
679 <li><?php
680 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
681 $partner = "MediaWiki";
682 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
683 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
684 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
685 print "<a href=\"$ccApp\">choose</a>";
686 ?> (link will wipe out any other data in this form!)
687 <?php if( $conf->License == "cc" ) { ?>
688 <ul>
689 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
690 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
691 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
692 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
693 </ul>
694 <?php } ?>
695 </li>
696 </ul>
697 </dd>
698 <dt>
699 MediaWiki can include a basic license notice, icon, and machine-reable
700 copyright metadata if your wiki's content is to be licensed under
701 the GNU FDL or a Creative Commons license. If you're not sure, leave
702 it at "none".
703 </dt>
704
705
706 <dd>
707 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
708 </dd>
709 <dd>
710 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
711 </dd>
712 <dd>
713 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
714 </dd>
715 <dt>
716 A sysop user account can lock or delete pages, block problematic IP
717 addresses from editing, and other maintenance tasks. If creating a new
718 wiki database, a sysop account will be created with the given name
719 and password.
720 </dt>
721 </dl>
722
723 <h2>Database config</h2>
724
725 <dl class="setup">
726 <dd><?php
727 aField( $conf, "DBserver", "MySQL server" );
728 ?></dd>
729 <dt>
730 If your database server isn't on your web server, enter the name
731 or IP address here.
732 </dt>
733
734 <dd><?php
735 aField( $conf, "DBname", "Database name" );
736 ?></dd>
737 <dd><?php
738 aField( $conf, "DBuser", "DB username" );
739 ?></dd>
740 <dd><?php
741 aField( $conf, "DBpassword", "DB password", "password" );
742 ?></dd>
743 <dd><?php
744 aField( $conf, "DBpassword2", "again", "password" );
745 ?></dd>
746 <dt>
747 If you only have a single user account and database available,
748 enter those here. If you have database root access (see below)
749 you can specify new accounts/databases to be created.
750 </dt>
751
752
753 <dd>
754 <?php
755 aField( $conf, "RootPW", "DB root password", "password" );
756 ?>
757 </dd>
758 <dt>
759 You will only need this if the database and/or user account
760 above don't already exist.
761 Do <em>not</em> type in your machine's root password! MySQL
762 has its own "root" user with a separate password. (It might
763 even be blank, depending on your configuration.)
764 </dt>
765
766 <dd>
767 <label class='column'>&nbsp;</label>
768 <input type="submit" value="Install!" />
769 </dd>
770 </dl>
771
772
773 </form>
774
775 <?php
776 }
777
778 /* -------------------------------------------------------------------------------------- */
779
780 function writeAdminSettings( $conf ) {
781 return "
782 \$wgDBadminuser = \"{$conf->DBadminuser}\";
783 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
784 ";
785 }
786
787 function escapePhpString( $string ) {
788 return strtr( $string,
789 array(
790 "\n" => "\\n",
791 "\r" => "\\r",
792 "\t" => "\\t",
793 "\\" => "\\\\",
794 "\$" => "\\\$",
795 "\"" => "\\\""
796 ));
797 }
798
799 function writeLocalSettings( $conf ) {
800 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
801 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
802 $conf->PasswordSender = $conf->EmergencyContact;
803 if( preg_match( '/^([a-z]+)-latin1$/', $conf->LanguageCode, $m ) ) {
804 $conf->LanguageCode = $m[1];
805 $conf->Latin1 = true;
806 } else {
807 $conf->Latin1 = false;
808 }
809 $zlib = ($conf->zlib ? "" : "# ");
810 $magic = ($conf->ImageMagick ? "" : "# ");
811 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
812 $pretty = ($conf->prettyURLs ? "" : "# ");
813 $ugly = ($conf->prettyURLs ? "# " : "");
814 $rights = ($conf->RightsUrl) ? "" : "# ";
815
816 $file = @fopen( "/dev/urandom", "r" );
817 if ( $file ) {
818 $proxyKey = bin2hex( fread( $file, 32 ) );
819 fclose( $file );
820 } else {
821 $proxyKey = "";
822 for ( $i=0; $i<8; $i++ ) {
823 $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
824 }
825 print "<li>Warning: \$wgProxyKey is insecure</li>\n";
826 }
827
828 # Add slashes to strings for double quoting
829 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
830 if( $conf->License == 'gfdl' ) {
831 # Needs literal string interpolation for the current style path
832 $slconf['RightsIcon'] = $conf->RightsIcon;
833 }
834
835 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
836 return "
837 # This file was automatically generated by the MediaWiki installer.
838 # If you make manual changes, please keep track in case you need to
839 # recreate them later.
840
841 \$IP = \"{$slconf['IP']}\";
842 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
843 require_once( \"includes/DefaultSettings.php\" );
844
845 # If PHP's memory limit is very low, some operations may fail.
846 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
847
848 if ( \$wgCommandLineMode ) {
849 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
850 die( \"This script must be run from the command line\\n\" );
851 }
852 } elseif ( empty( \$wgConfiguring ) ) {
853 ## Compress output if the browser supports it
854 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
855 }
856
857 \$wgSitename = \"{$slconf['Sitename']}\";
858
859 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
860 \$wgScript = \"\$wgScriptPath/index.php\";
861 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
862
863 ## If using PHP as a CGI module, use the ugly URLs
864 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
865 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
866
867 \$wgStylePath = \"\$wgScriptPath/skins\";
868 \$wgStyleDirectory = \"\$IP/skins\";
869 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
870
871 \$wgUploadPath = \"\$wgScriptPath/images\";
872 \$wgUploadDirectory = \"\$IP/images\";
873
874 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
875 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
876
877 \$wgDBserver = \"{$slconf['DBserver']}\";
878 \$wgDBname = \"{$slconf['DBname']}\";
879 \$wgDBuser = \"{$slconf['DBuser']}\";
880 \$wgDBpassword = \"{$slconf['DBpassword']}\";
881
882 ## To allow SQL queries through the wiki's Special:Askaql page,
883 ## uncomment the next lines. THIS IS VERY INSECURE. If you want
884 ## to allow semipublic read-only SQL access for your sysops,
885 ## you should define a MySQL user with limited privileges.
886 ## See MySQL docs: http://www.mysql.com/doc/en/GRANT.html
887 #
888 # \$wgAllowSysopQueries = true;
889 # \$wgDBsqluser = \"sqluser\";
890 # \$wgDBsqlpassword = \"sqlpass\";
891
892 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
893
894 ## To enable image uploads, make sure the 'images' directory
895 ## is writable, then uncomment this:
896 # \$wgDisableUploads = false;
897 \$wgUseImageResize = {$conf->UseImageResize};
898 {$magic}\$wgUseImageMagick = true;
899 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
900
901 ## If you have the appropriate support software installed
902 ## you can enable inline LaTeX equations:
903 # \$wgUseTeX = true;
904 \$wgMathPath = \"{\$wgUploadPath}/math\";
905 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
906 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
907
908 \$wgLocalInterwiki = \$wgSitename;
909
910 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
911 \$wgUseLatin1 = " . ($conf->Latin1 ? 'true' : 'false') . ";\n
912
913 \$wgProxyKey = \"$proxyKey\";
914
915 ## Default skin: you can change the default skin. Use the internal symbolic
916 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
917 # \$wgDefaultSkin = 'monobook';
918
919 ## For attaching licensing metadata to pages, and displaying an
920 ## appropriate copyright notice / icon. GNU Free Documentation
921 ## License and Creative Commons licenses are supported so far.
922 {$rights}\$wgEnableCreativeCommonsRdf = true;
923 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
924 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
925 \$wgRightsText = \"{$slconf['RightsText']}\";
926 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
927 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
928 ";
929 }
930
931 function dieout( $text ) {
932 die( $text . "\n\n</body>\n</html>" );
933 }
934
935 function importVar( &$var, $name, $default = "" ) {
936 if( isset( $var[$name] ) ) {
937 $retval = $var[$name];
938 if ( get_magic_quotes_gpc() ) {
939 $retval = stripslashes( $retval );
940 }
941 } else {
942 $retval = $default;
943 }
944 return $retval;
945 }
946
947 function importPost( $name, $default = "" ) {
948 return importVar( $_POST, $name, $default );
949 }
950
951 function importRequest( $name, $default = "" ) {
952 return importVar( $_REQUEST, $name, $default );
953 }
954
955 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
956 if( $type != "" ) {
957 $xtype = "type=\"$type\"";
958 } else {
959 $xtype = "";
960 }
961
962 if(!(isset($id)) or ($id == "") ) $id = $field;
963 $nolabel = ($type == "radio") || ($type == "hidden");
964 if( $nolabel ) {
965 echo "\t\t<label>";
966 } else {
967 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
968 }
969
970 if( $type == "radio" && $value == $conf->$field ) {
971 $checked = "checked='checked'";
972 } else {
973 $checked = "";
974 }
975 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
976 if( $type == "radio" ) {
977 echo htmlspecialchars( $value );
978 } else {
979 echo htmlspecialchars( $conf->$field );
980 }
981 echo "\" />\n";
982 if( $nolabel ) {
983 echo " $text</label>\n";
984 }
985
986 global $errs;
987 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
988 }
989
990 function getLanguageList() {
991 global $wgLanguageNames;
992 if( !isset( $wgLanguageNames ) ) {
993 $wgContLanguageCode = "xxx";
994 function wfLocalUrl( $x ) { return $x; }
995 function wfLocalUrlE( $x ) { return $x; }
996 require_once( "../languages/Names.php" );
997 }
998
999 $codes = array();
1000 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
1001
1002 $d = opendir( "../languages" );
1003 while( false !== ($f = readdir( $d ) ) ) {
1004 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1005 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1006 if( in_array( $code, $latin1 ) ) {
1007 $codes[$code] = "$code - " . $wgLanguageNames[$code] . " - Unicode";
1008 $codes[$code.'-latin1'] = "$code - " . $wgLanguageNames[$code] . " - Latin-1";
1009 } else {
1010 $codes[$code] = "$code - " . $wgLanguageNames[$code];
1011 }
1012 }
1013 }
1014 closedir( $d );
1015 ksort( $codes );
1016 return $codes;
1017 }
1018
1019 ?>
1020
1021 </body>
1022 </html>