BUG#463 Strip first leading blank from preformatted text in output
[mediawiki.git] / config / index.php
blob6adbc3fb3d8643dd9ebec5684c953cd0e1c5930e
1 <?php
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
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.
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.
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
21 error_reporting( E_ALL );
22 header( "Content-type: text/html; charset=utf-8" );
23 @ini_set( "display_errors", true );
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;
44 dl.setup dd {
45 margin-left: 0;
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;
55 dl.setup dt {
56 clear: left;
57 font-size: 0.8em;
58 margin-left: 10em;
59 /* margin-right: 200px; */
60 margin-bottom: 2em;
62 .error {
63 color: red;
65 ul.plain {
66 list-style: none;
67 clear: both;
68 margin-left: 12em;
70 </style>
71 </head>
73 <body>
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>
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>
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>
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>
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>
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>
108 <?php
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" );
119 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
122 <?php
124 /* Check for existing configurations and bug out! */
126 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
127 dieout( "<h2>Wiki is configured.</h2>
129 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
131 <p>(You should probably remove this directory for added security.)</p>" );
134 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
135 dieout( "<h2>You're configured!</h2>
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>" );
142 if( !is_writable( "." ) ) {
143 dieout( "<h2>Can't write config file, aborting</h2>
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>
150 <p>To make the directory writable on a Unix/Linux system:</p>
152 <pre>
153 cd <i>/path/to/wiki</i>
154 chmod a+w config
155 </pre>" );
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" );
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;
174 function getSitename() { return $this->getEncoded( $this->Sitename ); }
175 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
176 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
181 <p><i>Please include all of the lines below when reporting installation problems.</i></p>
183 <h2>Checking environment...</h2>
184 <ul>
185 <?php
186 $endl = "
188 $wgConfiguring = true;
189 $conf = new ConfigData;
191 install_version_checks();
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.";
201 print "</li>\n";
203 if( ini_get( "register_globals" ) ) {
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
213 if( ini_get( "safe_mode" ) ) {
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
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>";
241 print "</li>\n";
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." );
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) );
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.";
271 print "</li>\n";
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";
281 $conf->ImageMagick = false;
283 $conf->HaveGD = function_exists( "imagejpeg" );
284 if( $conf->HaveGD ) {
285 print "<li>Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads.</li>\n";
286 } else {
287 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin" );
288 foreach( $imcheck as $dir ) {
289 $im = "$dir/convert";
290 if( file_exists( $im ) ) {
291 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
292 $conf->ImageMagick = $im;
293 break;
296 if( !$conf->ImageMagick ) {
297 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
301 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
303 # $conf->IP = "/Users/brion/Sites/inplace";
304 $conf->IP = dirname( dirname( __FILE__ ) );
305 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
307 # $conf->ScriptPath = "/~brion/inplace";
308 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
309 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
311 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
313 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
314 $conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
315 $conf->DBserver = importPost( "DBserver", "localhost" );
316 $conf->DBname = importPost( "DBname", "wikidb" );
317 $conf->DBuser = importPost( "DBuser", "wikiuser" );
318 $conf->DBpassword = importPost( "DBpassword" );
319 $conf->DBpassword2 = importPost( "DBpassword2" );
320 $conf->RootPW = importPost( "RootPW" );
321 $conf->LanguageCode = importPost( "LanguageCode", "en" );
322 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
323 $conf->SysopPass = importPost( "SysopPass" );
324 $conf->SysopPass2 = importPost( "SysopPass2" );
326 /* Check for validity */
327 $errs = array();
329 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
330 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
332 if( $conf->DBuser == "" ) {
333 $errs["DBuser"] = "Must not be blank";
335 if( $conf->DBpassword == "" ) {
336 $errs["DBpassword"] = "Must not be blank";
338 if( $conf->DBpassword != $conf->DBpassword2 ) {
339 $errs["DBpassword2"] = "Passwords don't match!";
342 if( $conf->SysopPass == "" ) {
343 $errs["SysopPass"] = "Must not be blank";
345 if( $conf->SysopPass != $conf->SysopPass2 ) {
346 $errs["SysopPass2"] = "Passwords don't match!";
349 $conf->License = importRequest( "License", "none" );
350 if( $conf->License == "gfdl" ) {
351 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
352 $conf->RightsText = "GNU Free Documentation License 1.2";
353 $conf->RightsCode = "gfdl";
354 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
355 } elseif( $conf->License == "none" ) {
356 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
357 } else {
358 $conf->RightsUrl = importRequest( "RightsUrl", "" );
359 $conf->RightsText = importRequest( "RightsText", "" );
360 $conf->RightsCode = importRequest( "RightsCode", "" );
361 $conf->RightsIcon = importRequest( "RightsIcon", "" );
364 if( $conf->posted && ( 0 == count( $errs ) ) ) {
365 do { /* So we can 'continue' to end prematurely */
366 $conf->Root = ($conf->RootPW != "");
368 /* Load up the settings and get installin' */
369 $local = writeLocalSettings( $conf );
370 $wgCommandLineMode = false;
371 chdir( ".." );
372 eval($local);
373 $wgDBadminuser = "root";
374 $wgDBadminpassword = $conf->RootPW;
375 $wgCommandLineMode = true;
376 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
377 require_once( "includes/Setup.php" );
378 chdir( "config" );
380 require_once( "../maintenance/InitialiseMessages.inc" );
382 $wgTitle = Title::newFromText( "Installation script" );
383 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
384 $wgDatabase->mIgnoreErrors = true;
386 @$myver = mysql_get_server_info( $wgDatabase->mConn );
387 if( $myver ) {
388 $conf->Root = true;
389 print "<li>Connected as root (automatic)</li>\n";
390 } else {
391 print "<li>MySQL error " . ($err = mysql_errno() ) .
392 ": " . htmlspecialchars( mysql_error() );
393 $ok = false;
394 switch( $err ) {
395 case 1045:
396 if( $conf->Root ) {
397 $errs["RootPW"] = "Check password";
398 } else {
399 print "<li>Trying regular user...\n";
400 /* Try the regular user... */
401 $wgDBadminuser = $wgDBuser;
402 $wgDBadminpassword = $wgDBpassword;
403 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
404 $wgDatabase->isOpen();
405 $wgDatabase->mIgnoreErrors = true;
406 @$myver = mysql_get_server_info( $wgDatabase->mConn );
407 if( !$myver ) {
408 $errs["DBuser"] = "Check name/pass";
409 $errs["DBpassword"] = "or enter root";
410 $errs["DBpassword2"] = "password below";
411 $errs["RootPW"] = "Got root?";
412 print " need password.</li>\n";
413 } else {
414 $conf->Root = false;
415 $conf->RootPW = "";
416 print " ok.</li>\n";
417 # And keep going...
418 $ok = true;
420 break;
422 case 2002:
423 case 2003:
424 $errs["DBserver"] = "Connection failed";
425 break;
426 default:
427 $errs["DBserver"] = "Couldn't connect to database";
428 break;
430 if( !$ok ) continue;
433 if ( !$wgDatabase->isOpen() ) {
434 $errs["DBserver"] = "Couldn't connect to database";
435 continue;
438 print "<li>Connected to database... $myver";
439 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
440 print "; enabling MySQL 4 enhancements";
441 $conf->DBmysql4 = true;
442 $local = writeLocalSettings( $conf );
444 print "</li>\n";
446 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
447 if( $sel ) {
448 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
449 } else {
450 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
451 if( !$res ) {
452 print "<li>Couldn't create database <tt>" .
453 htmlspecialchars( $wgDBname ) .
454 "</tt>; try with root access or check your username/pass.</li>\n";
455 $errs["RootPW"] = "&lt;- Enter";
456 continue;
458 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
461 $wgDatabase->selectDB( $wgDBname );
463 if( $wgDatabase->tableExists( "cur" ) ) {
464 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n<pre>";
466 chdir( ".." );
467 flush();
468 do_ipblocks_update(); flush();
469 do_interwiki_update(); flush();
470 do_index_update(); flush();
471 do_linkscc_update(); flush();
472 do_linkscc_1_3_update(); flush();
473 do_hitcounter_update(); flush();
474 do_recentchanges_update(); flush();
475 convertLinks(); flush();
476 do_user_real_name_update(); flush();
477 do_querycache_update(); flush();
478 do_objectcache_update(); flush();
479 do_categorylinks_update(); flush();
480 do_image_name_unique_update(); flush();
481 do_logging_update(); flush();
482 do_user_rights_update(); flush();
484 if ( isTemplateInitialised() ) {
485 print "Template namespace already initialised\n";
486 } else {
487 moveCustomMessages( 1 ); flush();
488 moveCustomMessages( 2 ); flush();
489 moveCustomMessages( 3 ); flush();
492 initialiseMessages(); flush();
493 chdir( "config" );
495 print "</pre>\n";
496 print "<li>Finished update checks.</li>\n";
497 } else {
498 # FIXME: Check for errors
499 print "<li>Creating tables...";
500 dbsource( "../maintenance/tables.sql", $wgDatabase );
501 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
502 print " done.</li>\n";
504 print "<li>Initializing data...";
505 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
506 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
507 # setting up the db user
508 if( $conf->Root ) {
509 print "<li>Granting user permissions...</li>\n";
510 dbsource( "../maintenance/users.sql", $wgDatabase );
513 if( $conf->SysopName ) {
514 $u = User::newFromName( $conf->getSysopName() );
515 if ( 0 == $u->idForName() ) {
516 $u->addToDatabase();
517 $u->setPassword( $conf->getSysopPass() );
518 $u->addRight( "sysop" );
519 $u->addRight( "bureaucrat" );
520 $u->saveSettings();
521 print "<li>Created sysop account <tt>" .
522 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
523 } else {
524 print "<li>Could not create user - already exists!</li>\n";
526 } else {
527 print "<li>Skipped sysop account creation, no name given.</li>\n";
530 print "<li>Initialising log pages...";
531 $logs = array(
532 "uploadlogpage" => "uploadlogpagetext",
533 "dellogpage" => "dellogpagetext",
534 "protectlogpage" => "protectlogtext",
535 "blocklogpage" => "blocklogtext"
537 $metaNamespace = Namespace::getWikipedia();
538 $now = wfTimestampNow();
539 $won = wfInvertTimestamp( $now );
540 foreach( $logs as $page => $text ) {
541 $logTitle = $wgDatabase->strencode( $wgLang->ucfirst( str_replace( " ", "_", wfMsgNoDB( $page ) ) ) );
542 $logText = $wgDatabase->strencode( wfMsgNoDB( $text ) );
543 $wgDatabase->query( "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
544 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) " .
545 "VALUES ($metaNamespace,'$logTitle','$logText','sysop','$now','$won','$now')" );
547 print "</li>\n";
549 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
550 $title = $titleobj->getDBkey();
551 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched,cur_user,cur_user_text) " .
552 "VALUES (0,'$title','" .
553 wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) .
554 "','$now','$won','$now',0,'MediaWiki default')";
555 $wgDatabase->query( $sql, $fname );
557 print "<li><pre>";
558 initialiseMessages();
559 print "</pre></li>\n";
562 /* Write out the config file now that all is well */
563 print "<p>Creating LocalSettings.php...</p>\n\n";
564 $localSettings = "<" . "?php$endl$local$endl?" . ">";
566 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
567 $xt = "xt"; # Refuse to overwrite an existing file
568 } else {
569 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
571 $f = fopen( "LocalSettings.php", $xt );
573 if( $f == false ) {
574 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" .
575 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
576 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
578 fwrite( $f, $localSettings );
579 fclose( $f );
581 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
582 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
584 } while( false );
587 </ul>
590 <?php
592 if( count( $errs ) ) {
593 /* Display options form */
595 if( $conf->posted ) {
596 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
600 <form name="config" method="post">
603 <h2>Site config</h2>
605 <dl class="setup">
606 <dd>
607 <?php
608 aField( $conf, "Sitename", "Site name:" );
610 </dd>
611 <dt>
612 Your site name should be a relatively short word. It'll appear as the namespace
613 name for 'meta' pages as well as throughout the user interface. Good site names
614 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
615 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
616 which may cause problems.
617 </dt>
619 <dd>
620 <?php
621 aField( $conf, "EmergencyContact", "Contact e-mail" );
623 </dd>
624 <dt>
625 This will be used as the return address for password reminders and
626 may be displayed in some error conditions so visitors can get in
627 touch with you.
628 </dt>
630 <dd>
631 <label class='column' for="LanguageCode">Language</label>
632 <select id="LanguageCode" name="LanguageCode">
633 <?php
634 $list = getLanguageList();
635 foreach( $list as $code => $name ) {
636 $sel = ($code == $conf->LanguageCode) ? "selected" : "";
637 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
640 </select>
641 </dd>
642 <dt>
643 You may select the language for the user interface of the wiki...
644 Some localizations are less complete than others. This also controls
645 the character encoding; Unicode is more flexible, but Latin-1 may be
646 more compatible with older browsers for some languages. Unicode will
647 be used where not specified otherwise.
648 </dt>
650 <dd>
651 <label class='column'>Copyright/license metadata</label>
652 <div>Select one:</div>
654 <ul class="plain">
655 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
656 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
657 <li><?php
658 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
659 $partner = "MediaWiki";
660 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
661 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
662 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
663 print "<a href=\"$ccApp\">choose</a>";
664 ?> (link will wipe out any other data in this form!)
665 <?php if( $conf->License == "cc" ) { ?>
666 <ul>
667 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
668 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
669 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
670 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
671 </ul>
672 <?php } ?>
673 </li>
674 </ul>
675 </dd>
676 <dt>
677 MediaWiki can include a basic license notice, icon, and machine-reable
678 copyright metadata if your wiki's content is to be licensed under
679 the GNU FDL or a Creative Commons license. If you're not sure, leave
680 it at "none".
681 </dt>
684 <dd>
685 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
686 </dd>
687 <dd>
688 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
689 </dd>
690 <dd>
691 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
692 </dd>
693 <dt>
694 A sysop user account can lock or delete pages, block problematic IP
695 addresses from editing, and other maintenance tasks. If creating a new
696 wiki database, a sysop account will be created with the given name
697 and password.
698 </dt>
699 </dl>
701 <h2>Database config</h2>
703 <dl class="setup">
704 <dd><?php
705 aField( $conf, "DBserver", "MySQL server" );
706 ?></dd>
707 <dt>
708 If your database server isn't on your web server, enter the name
709 or IP address here.
710 </dt>
712 <dd><?php
713 aField( $conf, "DBname", "Database name" );
714 ?></dd>
715 <dd><?php
716 aField( $conf, "DBuser", "DB username" );
717 ?></dd>
718 <dd><?php
719 aField( $conf, "DBpassword", "DB password", "password" );
720 ?></dd>
721 <dd><?php
722 aField( $conf, "DBpassword2", "again", "password" );
723 ?></dd>
724 <dt>
725 If you only have a single user account and database available,
726 enter those here. If you have database root access (see below)
727 you can specify new accounts/databases to be created.
728 </dt>
731 <dd>
732 <?php
733 aField( $conf, "RootPW", "DB root password", "password" );
735 </dd>
736 <dt>
737 You will only need this if the database and/or user account
738 above don't already exist.
739 Do <em>not</em> type in your machine's root password! MySQL
740 has its own "root" user with a separate password. (It might
741 even be blank, depending on your configuration.)
742 </dt>
744 <dd>
745 <label class='column'>&nbsp;</label>
746 <input type="submit" value="Install!" />
747 </dd>
748 </dl>
751 </form>
753 <?php
756 /* -------------------------------------------------------------------------------------- */
758 function writeAdminSettings( $conf ) {
759 return "
760 \$wgDBadminuser = \"{$conf->DBadminuser}\";
761 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
765 function escapePhpString( $string ) {
766 return strtr( $string,
767 array(
768 "\n" => "\\n",
769 "\r" => "\\r",
770 "\t" => "\\t",
771 "\\" => "\\\\",
772 "\$" => "\\\$",
773 "\"" => "\\\""
777 function writeLocalSettings( $conf ) {
778 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
779 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
780 $conf->PasswordSender = $conf->EmergencyContact;
781 if( preg_match( '/^([a-z]+)-latin1$/', $conf->LanguageCode, $m ) ) {
782 $conf->LanguageCode = $m[1];
783 $conf->Latin1 = true;
784 } else {
785 $conf->Latin1 = false;
787 $zlib = ($conf->zlib ? "" : "# ");
788 $magic = ($conf->ImageMagick ? "" : "# ");
789 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
790 $pretty = ($conf->prettyURLs ? "" : "# ");
791 $ugly = ($conf->prettyURLs ? "# " : "");
792 $rights = ($conf->RightsUrl) ? "" : "# ";
794 $file = @fopen( "/dev/urandom", "r" );
795 if ( $file ) {
796 $proxyKey = bin2hex( fread( $file, 32 ) );
797 fclose( $file );
798 } else {
799 $proxyKey = "";
800 for ( $i=0; $i<8; $i++ ) {
801 $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
803 print "<li>Warning: \$wgProxyKey is insecure</li>\n";
806 # Add slashes to strings for double quoting
807 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
808 if( $conf->License == 'gfdl' ) {
809 # Needs literal string interpolation for the current style path
810 $slconf['RightsIcon'] = $conf->RightsIcon;
813 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
814 return "
815 # This file was automatically generated by the MediaWiki installer.
816 # If you make manual changes, please keep track in case you need to
817 # recreate them later.
819 \$IP = \"{$slconf['IP']}\";
820 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
821 require_once( \"DefaultSettings.php\" );
823 # If PHP's memory limit is very low, some operations may fail.
824 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
826 if ( \$wgCommandLineMode ) {
827 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
828 die( \"This script must be run from the command line\\n\" );
830 } elseif ( empty( \$wgConfiguring ) ) {
831 ## Compress output if the browser supports it
832 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
835 \$wgSitename = \"{$slconf['Sitename']}\";
837 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
838 \$wgScript = \"\$wgScriptPath/index.php\";
839 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
841 ## If using PHP as a CGI module, use the ugly URLs
842 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
843 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
845 \$wgStylePath = \"\$wgScriptPath/skins\";
846 \$wgStyleDirectory = \"\$IP/skins\";
847 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
849 \$wgUploadPath = \"\$wgScriptPath/images\";
850 \$wgUploadDirectory = \"\$IP/images\";
852 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
853 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
855 \$wgDBserver = \"{$slconf['DBserver']}\";
856 \$wgDBname = \"{$slconf['DBname']}\";
857 \$wgDBuser = \"{$slconf['DBuser']}\";
858 \$wgDBpassword = \"{$slconf['DBpassword']}\";
860 ## To allow SQL queries through the wiki's Special:Askaql page,
861 ## uncomment the next lines. THIS IS VERY INSECURE. If you want
862 ## to allow semipublic read-only SQL access for your sysops,
863 ## you should define a MySQL user with limited privileges.
864 ## See MySQL docs: http://www.mysql.com/doc/en/GRANT.html
866 # \$wgAllowSysopQueries = true;
867 # \$wgDBsqluser = \"sqluser\";
868 # \$wgDBsqlpassword = \"sqlpass\";
870 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
872 ## To enable image uploads, make sure the 'images' directory
873 ## is writable, then uncomment this:
874 # \$wgDisableUploads = false;
875 \$wgUseImageResize = {$conf->UseImageResize};
876 {$magic}\$wgUseImageMagick = true;
877 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
879 ## If you have the appropriate support software installed
880 ## you can enable inline LaTeX equations:
881 # \$wgUseTeX = true;
882 \$wgMathPath = \"{\$wgUploadPath}/math\";
883 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
884 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
886 \$wgLocalInterwiki = \$wgSitename;
888 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
889 \$wgUseLatin1 = " . ($conf->Latin1 ? 'true' : 'false') . ";\n
891 \$wgProxyKey = \"$proxyKey\";
893 ## Default skin: you can change the default skin. Use the internal symbolic
894 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
895 # \$wgDefaultSkin = 'monobook';
897 ## For attaching licensing metadata to pages, and displaying an
898 ## appropriate copyright notice / icon. GNU Free Documentation
899 ## License and Creative Commons licenses are supported so far.
900 {$rights}\$wgEnableCreativeCommonsRdf = true;
901 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
902 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
903 \$wgRightsText = \"{$slconf['RightsText']}\";
904 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
905 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
909 function dieout( $text ) {
910 die( $text . "\n\n</body>\n</html>" );
913 function importVar( &$var, $name, $default = "" ) {
914 if( isset( $var[$name] ) ) {
915 $retval = $var[$name];
916 if ( get_magic_quotes_gpc() ) {
917 $retval = stripslashes( $retval );
919 } else {
920 $retval = $default;
922 return $retval;
925 function importPost( $name, $default = "" ) {
926 return importVar( $_POST, $name, $default );
929 function importRequest( $name, $default = "" ) {
930 return importVar( $_REQUEST, $name, $default );
933 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
934 if( $type != "" ) {
935 $xtype = "type=\"$type\"";
936 } else {
937 $xtype = "";
940 if(!(isset($id)) or ($id == "") ) $id = $field;
941 $nolabel = ($type == "radio") || ($type == "hidden");
942 if( $nolabel ) {
943 echo "\t\t<label>";
944 } else {
945 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
948 if( $type == "radio" && $value == $conf->$field ) {
949 $checked = "checked='checked'";
950 } else {
951 $checked = "";
953 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
954 if( $type == "radio" ) {
955 echo htmlspecialchars( $value );
956 } else {
957 echo htmlspecialchars( $conf->$field );
959 echo "\" />\n";
960 if( $nolabel ) {
961 echo " $text</label>\n";
964 global $errs;
965 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
968 function getLanguageList() {
969 global $wgLanguageNames;
970 if( !isset( $wgLanguageNames ) ) {
971 $wgLanguageCode = "xxx";
972 function wfLocalUrl( $x ) { return $x; }
973 function wfLocalUrlE( $x ) { return $x; }
974 require_once( "../languages/Names.php" );
977 $codes = array();
978 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
980 $d = opendir( "../languages" );
981 while( false !== ($f = readdir( $d ) ) ) {
982 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
983 $code = str_replace( '_', '-', strtolower( $m[1] ) );
984 if( in_array( $code, $latin1 ) ) {
985 $codes[$code] = "$code - " . $wgLanguageNames[$code] . " - Unicode";
986 $codes[$code.'-latin1'] = "$code - " . $wgLanguageNames[$code] . " - Latin-1";
987 } else {
988 $codes[$code] = "$code - " . $wgLanguageNames[$code];
992 closedir( $d );
993 ksort( $codes );
994 return $codes;
999 </body>
1000 </html>