From OrganicDesign Wiki
<?php
# NOTE: This version of MediaWiki's config/index.php has been modified to add SQLite to the supported databases
# MediaWiki web-based config/installation
# Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2006 Rob Church <robchur@gmail.com>
# http://www.mediawiki.org/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# http://www.gnu.org/copyleft/gpl.html
error_reporting( E_ALL );
header( "Content-type: text/html; charset=utf-8" );
@ini_set( "display_errors", true );
# In case of errors, let output be clean.
$wgRequestTime = microtime( true );
# Attempt to set up the include path, to fix problems with relative includes
$IP = dirname( dirname( __FILE__ ) );
define( 'MW_INSTALL_PATH', $IP );
# Define an entry point and include some files
define( "MEDIAWIKI", true );
define( "MEDIAWIKI_INSTALL", true );
// Run version checks before including other files
// so people don't see a scary parse error.
require_once( "$IP/install-utils.inc" );
install_version_checks();
require_once( "$IP/includes/Defines.php" );
require_once( "$IP/includes/DefaultSettings.php" );
require_once( "$IP/includes/AutoLoader.php" );
require_once( "$IP/includes/MagicWord.php" );
require_once( "$IP/includes/Namespace.php" );
require_once( "$IP/includes/ProfilerStub.php" );
require_once( "$IP/includes/GlobalFunctions.php" );
require_once( "$IP/includes/Hooks.php" );
# If we get an exception, the user needs to know
# all the details
$wgShowExceptionDetails = true;
## Databases we support:
$ourdb = array();
$ourdb['mysql']['fullname'] = 'MySQL';
$ourdb['mysql']['havedriver'] = 0;
$ourdb['mysql']['compile'] = 'mysql';
$ourdb['mysql']['bgcolor'] = '#ffe5a7';
$ourdb['mysql']['rootuser'] = 'root';
$ourdb['postgres']['fullname'] = 'PostgreSQL';
$ourdb['postgres']['havedriver'] = 0;
$ourdb['postgres']['compile'] = 'pgsql';
$ourdb['postgres']['bgcolor'] = '#aaccff';
$ourdb['postgres']['rootuser'] = 'postgres';
# MediaWikiLite
$ourdb['sqlite']['fullname'] = 'SQLite';
$ourdb['sqlite']['havedriver'] = 0;
$ourdb['sqlite']['compile'] = 'pdo_sqlite';
$ourdb['sqlite']['bgcolor'] = '#ffe5a7';
$ourdb['sqlite']['rootuser'] = 'root';
require_once("$IP/extensions/MediaWikiLite.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>MediaWiki <?php echo( $wgVersion ); ?> Installation</title>
<style type="text/css">
@import "../skins/monobook/main.css";
.env-check {
font-size: 90%;
margin: 1em 0 1em 2.5em;
}
.config-section {
margin-top: 2em;
}
.config-section label.column {
clear: left;
font-weight: bold;
width: 13em;
float: left;
text-align: right;
padding-right: 1em;
padding-top: .2em;
}
.config-input {
clear: left;
zoom: 100%; /* IE hack */
}
.config-section .config-desc {
clear: left;
margin: 0 0 2em 18em;
padding-top: 1em;
font-size: 85%;
}
.iput-text, .iput-password {
width: 14em;
margin-right: 1em;
}
.error {
color: red;
background-color: #fff;
font-weight: bold;
left: 1em;
font-size: 100%;
}
.error-top {
color: red;
background-color: #FFF0F0;
border: 2px solid red;
font-size: 130%;
font-weight: bold;
padding: 1em 1.5em;
margin: 2em 0 1em;
}
ul.plain {
list-style-type: none;
list-style-image: none;
float: left;
margin: 0;
padding: 0;
}
.btn-install {
font-weight: bold;
font-size: 110%;
padding: .2em .3em;
}
.license {
font-size: 85%;
padding-top: 3em;
}
span.success-message {
font-weight: bold;
font-size: 110%;
color: green;
}
.success-box {
font-size: 130%;
}
</style>
<script type="text/javascript">
<!--
function hideall() {
<?php foreach (array_keys($ourdb) as $db) {
echo "\n document.getElementById('$db').style.display='none';";
}
?>
}
function toggleDBarea(id,defaultroot) {
hideall();
var dbarea = document.getElementById(id).style;
dbarea.display = (dbarea.display == 'none') ? 'block' : 'none';
var db = document.getElementById('RootUser');
if (defaultroot) {
<?php foreach (array_keys($ourdb) as $db) {
echo " if (id == '$db') { db.value = '".$ourdb[$db]['rootuser']."';}\n";
}?>
}
}
// -->
</script>
</head>
<body>
<div id="globalWrapper">
<div id="column-content">
<div id="content">
<div id="bodyContent">
<h1>MediaWiki <?php print $wgVersion ?> Installation</h1>
<?php
/* Check for existing configurations and bug out! */
if( file_exists( "../LocalSettings.php" ) ) {
$script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
dieout( "<p><strong>Setup has completed, <a href='../$script'>your wiki</a> is configured.</strong></p>
<p>Please delete the /config directory for extra security.</p></div></div></div></div>" );
}
if( file_exists( "./LocalSettings.php" ) ) {
writeSuccessMessage();
dieout( '' );
}
if( !is_writable( "." ) ) {
dieout( "<h2>Can't write config file, aborting</h2>
<p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
writable by the web server. Once configuration is done you'll move the created
<tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
then remove the <tt>config</tt> subdirectory entirely.</p>
<p>To make the directory writable on a Unix/Linux system:</p>
<pre>
cd <i>/path/to/wiki</i>
chmod a+w config
</pre>
<p>Afterwards retry to start the <a href=\"\">setup</a>.</p>" );
}
require_once( "$IP/install-utils.inc" );
require_once( "$IP/maintenance/updaters.inc" );
class ConfigData {
function getEncoded( $data ) {
# removing latin1 support, no need...
return $data;
}
function getSitename() { return $this->getEncoded( $this->Sitename ); }
function getSysopName() { return $this->getEncoded( $this->SysopName ); }
function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
function setSchema( $schema, $engine ) {
$this->DBschema = $schema;
if ( !preg_match( '/^\w*$/', $engine ) ){
$engine = 'InnoDB';
}
switch ( $this->DBschema ) {
case 'mysql5':
$this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=utf8";
$this->DBmysql5 = 'true';
break;
case 'mysql5-binary':
$this->DBTableOptions = "ENGINE=$engine, DEFAULT CHARSET=binary";
$this->DBmysql5 = 'true';
break;
default:
$this->DBTableOptions = "TYPE=$engine";
$this->DBmysql5 = 'false';
}
$this->DBengine = $engine;
# Set the global for use during install
global $wgDBTableOptions;
$wgDBTableOptions = $this->DBTableOptions;
}
}
?>
<ul>
<li>
<b>Don't forget security updates!</b> Keep an eye on the
<a href="http://mail.wikimedia.org/mailman/listinfo/mediawiki-announce">low-traffic
release announcements mailing list</a>.
</li>
</ul>
<h2>Checking environment...</h2>
<p><em>Please include all of the lines below when reporting installation problems.</em></p>
<ul class="env-check">
<?php
$endl = "
";
define( 'MW_NO_OUTPUT_BUFFER', 1 );
$conf = new ConfigData;
install_version_checks();
$self = 'Installer'; # Maintenance script name, to please Setup.php
print "<li>PHP " . phpversion() . " installed</li>\n";
error_reporting( 0 );
$phpdatabases = array();
foreach (array_keys($ourdb) as $db) {
$compname = $ourdb[$db]['compile'];
if( extension_loaded( $compname ) || ( mw_have_dl() && dl( "{$compname}." . PHP_SHLIB_SUFFIX ) ) ) {
array_push($phpdatabases, $db);
$ourdb[$db]['havedriver'] = 1;
}
}
error_reporting( E_ALL );
if (!$phpdatabases) {
print "Could not find a suitable database driver!<ul>";
foreach (array_keys($ourdb) AS $db) {
$comp = $ourdb[$db]['compile'];
$full = $ourdb[$db]['fullname'];
print "<li>For <b>$full</b>, compile PHP using <b>--with-$comp</b>, "
."or install the $comp.so module</li>\n";
}
dieout( "</ul></ul>" );
}
print "<li>Found database drivers for:";
$DefaultDBtype = '';
foreach (array_keys($ourdb) AS $db) {
if ($ourdb[$db]['havedriver']) {
if ( $DefaultDBtype == '' ) {
$DefaultDBtype = $db;
}
print " ".$ourdb[$db]['fullname'];
}
}
print "</li>\n";
if( ini_get( "register_globals" ) ) {
?>
<li>
<div style="font-size:110%">
<strong class="error">Warning:</strong>
<strong>PHP's <tt><a href="http://php.net/register_globals">register_globals</a></tt> option is enabled. Disable it if you can.</strong>
</div>
MediaWiki will work, but your server is more exposed to PHP-based security vulnerabilities.
</li>
<?php
}
$fatal = false;
if( ini_get( "magic_quotes_runtime" ) ) {
$fatal = true;
?><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>
This option corrupts data input unpredictably; you cannot install or use
MediaWiki unless this option is disabled.
<?php
}
if( ini_get( "magic_quotes_sybase" ) ) {
$fatal = true;
?><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>
This option corrupts data input unpredictably; you cannot install or use
MediaWiki unless this option is disabled.
<?php
}
if( ini_get( "mbstring.func_overload" ) ) {
$fatal = true;
?><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>
This option causes errors and may corrupt data unpredictably;
you cannot install or use MediaWiki unless this option is disabled.
<?php
}
if( ini_get( "zend.ze1_compatibility_mode" ) ) {
$fatal = true;
?><li class="error"><strong>Fatal: <a href="http://www.php.net/manual/en/ini.core.php">zend.ze1_compatibility_mode</a> is active!</strong>
This option causes horrible bugs with MediaWiki; you cannot install or use
MediaWiki unless this option is disabled.
<?php
}
if( $fatal ) {
dieout( "</ul><p>Cannot install MediaWiki.</p>" );
}
if( ini_get( "safe_mode" ) ) {
$conf->safeMode = true;
?>
<li><b class='error'>Warning:</b> <strong>PHP's
<a href='http://www.php.net/features.safe-mode'>safe mode</a> is active.</strong>
You may have problems caused by this, particularly if using image uploads.
</li>
<?php
} else {
$conf->safeMode = false;
}
$sapi = php_sapi_name();
print "<li>PHP server API is $sapi; ";
$script = defined('MW_INSTALL_PHP5_EXT') ? 'index.php5' : 'index.php';
if( $wgUsePathInfo ) {
print "ok, using pretty URLs (<tt>$script/Page_Title</tt>)";
} else {
print "using ugly URLs (<tt>$script?title=Page_Title</tt>)";
}
print "</li>\n";
$conf->xml = function_exists( "utf8_encode" );
if( $conf->xml ) {
print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
} else {
dieout( "PHP's XML module is missing; the wiki requires functions in
this module and won't work in this configuration.
If you're running Mandrake, install the php-xml package." );
}
# Check for session support
if( !function_exists( 'session_name' ) )
dieout( "PHP's session module is missing. MediaWiki requires session support in order to function." );
# session.save_path doesn't *have* to be set, but if it is, and it's
# not valid/writable/etc. then it can cause problems
$sessionSavePath = mw_get_session_save_path();
$ssp = htmlspecialchars( $sessionSavePath );
# Warn the user if it's not set, but let them proceed
if( !$sessionSavePath ) {
print "<li><strong>Warning:</strong> A value for <tt>session.save_path</tt>
has not been set in PHP.ini. If the default value causes problems with
saving session data, set it to a valid path which is read/write/execute
for the user your web server is running under.</li>";
} elseif ( is_dir( $sessionSavePath ) && is_writable( $sessionSavePath ) ) {
# All good? Let the user know
print "<li>Session save path (<tt>{$ssp}</tt>) appears to be valid.</li>";
} else {
# Something not right? Warn the user, but let them proceed
print "<li><strong>Warning:</strong> Your <tt>session.save_path</tt> value (<tt>{$ssp}</tt>)
appears to be invalid or is not writable. PHP needs to be able to save data to
this location for correct session operation.</li>";
}
# Check for PCRE support
if( !function_exists( 'preg_match' ) )
dieout( "The PCRE support module appears to be missing. MediaWiki requires the
Perl-compatible regular expression functions." );
$memlimit = ini_get( "memory_limit" );
$conf->raiseMemory = false;
if( empty( $memlimit ) || $memlimit == -1 ) {
print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
} else {
print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". ";
$n = intval( $memlimit );
if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
$n = intval( $m[1] * (1024*1024) );
}
if( $n < 20*1024*1024 ) {
print "Attempting to raise limit to 20M... ";
if( false === ini_set( "memory_limit", "20M" ) ) {
print "failed.<br /><b>" . htmlspecialchars( $memlimit ) . " seems too low, installation may fail!</b>";
} else {
$conf->raiseMemory = true;
print "ok.";
}
}
print "</li>\n";
}
$conf->turck = function_exists( 'mmcache_get' );
if ( $conf->turck ) {
print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
}
$conf->xcache = function_exists( 'xcache_get' );
if( $conf->xcache )
print "<li><a href=\"http://trac.lighttpd.net/xcache/\">XCache</a> installed</li>";
$conf->apc = function_exists('apc_fetch');
if ($conf->apc ) {
print "<li><a href=\"http://www.php.net/apc\">APC</a> installed</li>";
}
$conf->eaccel = function_exists( 'eaccelerator_get' );
if ( $conf->eaccel ) {
$conf->turck = 'eaccelerator';
print "<li><a href=\"http://eaccelerator.sourceforge.net/\">eAccelerator</a> installed</li>\n";
}
if( !( $conf->turck || $conf->eaccel || $conf->apc || $conf->xcache ) ) {
echo( '<li>Couldn\'t find <a href="http://turck-mmcache.sourceforge.net">Turck MMCache</a>,
<a href="http://eaccelerator.sourceforge.net">eAccelerator</a>,
<a href="http://www.php.net/apc">APC</a> or <a href="http://trac.lighttpd.net/xcache/">XCache</a>;
cannot use these for object caching.</li>' );
}
$conf->diff3 = false;
$diff3locations = array_merge(
array(
"/usr/bin",
"/usr/local/bin",
"/opt/csw/bin",
"/usr/gnu/bin",
"/usr/sfw/bin" ),
explode( PATH_SEPARATOR, getenv( "PATH" ) ) );
$diff3names = array( "gdiff3", "diff3", "diff3.exe" );
$diff3versioninfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
foreach ($diff3locations as $loc) {
$exe = locate_executable($loc, $diff3names, $diff3versioninfo);
if ($exe !== false) {
$conf->diff3 = $exe;
break;
}
}
if ($conf->diff3)
print "<li>Found GNU diff3: <tt>$conf->diff3</tt>.</li>";
else
print "<li>GNU diff3 not found.</li>";
$conf->ImageMagick = false;
$imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
foreach( $imcheck as $dir ) {
$im = "$dir/convert";
if( file_exists( $im ) ) {
print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
$conf->ImageMagick = $im;
break;
}
}
$conf->HaveGD = function_exists( "imagejpeg" );
if( $conf->HaveGD ) {
print "<li>Found GD graphics library built-in";
if( !$conf->ImageMagick ) {
print ", image thumbnailing will be enabled if you enable uploads";
}
print ".</li>\n";
} else {
if( !$conf->ImageMagick ) {
print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
}
}
$conf->IP = dirname( dirname( __FILE__ ) );
print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
// PHP_SELF isn't available sometimes, such as when PHP is CGI but
// cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
// to get the path to the current script... hopefully it's reliable. SIGH
$path = ($_SERVER["PHP_SELF"] === '')
? $_SERVER["SCRIPT_NAME"]
: $_SERVER["PHP_SELF"];
$conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $path );
print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
// We may be installing from *.php5 extension file, if so, print message
$conf->ScriptExtension = '.php';
if (defined('MW_INSTALL_PHP5_EXT')) {
$conf->ScriptExtension = '.php5';
print "<li>Installing MediaWiki with <tt>php5</tt> file extensions</li>\n";
} else {
print "<li>Installing MediaWiki with <tt>php</tt> file extensions</li>\n";
}
print "<li style='font-weight:bold;color:green;font-size:110%'>Environment checked. You can install MediaWiki.</li>\n";
$conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
$conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
$defaultEmail = empty( $_SERVER["SERVER_ADMIN"] )
? 'root@localhost'
: $_SERVER["SERVER_ADMIN"];
$conf->EmergencyContact = importPost( "EmergencyContact", $defaultEmail );
$conf->DBtype = importPost( "DBtype", $DefaultDBtype );
?>
<?php
$conf->DBserver = importPost( "DBserver", "localhost" );
$conf->DBname = importPost( "DBname", "wikidb" );
$conf->DBuser = importPost( "DBuser", "wikiuser" );
$conf->DBpassword = importPost( "DBpassword" );
$conf->DBpassword2 = importPost( "DBpassword2" );
$conf->SysopName = importPost( "SysopName", "WikiSysop" );
$conf->SysopPass = importPost( "SysopPass" );
$conf->SysopPass2 = importPost( "SysopPass2" );
$conf->RootUser = importPost( "RootUser", "root" );
$conf->RootPW = importPost( "RootPW", "" );
$useRoot = importCheck( 'useroot', false );
$conf->LanguageCode = importPost( "LanguageCode", "en" );
## MySQL specific:
$conf->DBprefix = importPost( "DBprefix" );
$conf->setSchema(
importPost( "DBschema", "mysql4" ),
importPost( "DBengine", "InnoDB" ) );
## Postgres specific:
$conf->DBport = importPost( "DBport", "5432" );
$conf->DBmwschema = importPost( "DBmwschema", "mediawiki" );
$conf->DBts2schema = importPost( "DBts2schema", "public" );
/* Check for validity */
$errs = array();
if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
$errs["Sitename"] = "Must not be blank or \"MediaWiki\"";
}
if( $conf->DBuser == "" ) {
$errs["DBuser"] = "Must not be blank";
}
if( ($conf->DBtype == 'mysql') && (strlen($conf->DBuser) > 16) ) {
$errs["DBuser"] = "Username too long";
}
if( $conf->DBpassword == "" && $conf->DBtype != "postgres" ) {
$errs["DBpassword"] = "Must not be blank";
}
if( $conf->DBpassword != $conf->DBpassword2 ) {
$errs["DBpassword2"] = "Passwords don't match!";
}
if( !preg_match( '/^[A-Za-z_0-9]*$/', $conf->DBprefix ) ) {
$errs["DBprefix"] = "Invalid table prefix";
}
error_reporting( E_ALL );
/**
* Initialise $wgLang and $wgContLang to something so we can
* call case-folding methods. Per Brion, this is English for
* now, although we could be clever and initialise to the
* user-selected language.
*/
$wgContLang = Language::factory( 'en' );
$wgLang = $wgContLang;
/**
* We're messing about with users, so we need a stub
* authentication plugin...
*/
$wgAuth = new AuthPlugin();
/**
* Validate the initial administrator account; username,
* password checks, etc.
*/
if( $conf->SysopName ) {
# Check that the user can be created
$u = User::newFromName( $conf->SysopName );
if( is_a($u, 'User') ) { // please do not use instanceof, it breaks PHP4
# Various password checks
if( $conf->SysopPass != '' ) {
if( $conf->SysopPass == $conf->SysopPass2 ) {
if( !$u->isValidPassword( $conf->SysopPass ) ) {
$errs['SysopPass'] = "Bad password";
}
} else {
$errs['SysopPass2'] = "Passwords don't match";
}
} else {
$errs['SysopPass'] = "Cannot be blank";
}
unset( $u );
} else {
$errs['SysopName'] = "Bad username";
}
}
$conf->License = importRequest( "License", "none" );
if( $conf->License == "gfdl" ) {
$conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
$conf->RightsText = "GNU Free Documentation License 1.2";
$conf->RightsCode = "gfdl";
$conf->RightsIcon = '${wgScriptPath}/skins/common/images/gnu-fdl.png';
} elseif( $conf->License == "none" ) {
$conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
} else {
$conf->RightsUrl = importRequest( "RightsUrl", "" );
$conf->RightsText = importRequest( "RightsText", "" );
$conf->RightsCode = importRequest( "RightsCode", "" );
$conf->RightsIcon = importRequest( "RightsIcon", "" );
}
$conf->Shm = importRequest( "Shm", "none" );
$conf->MCServers = importRequest( "MCServers" );
/* Test memcached servers */
if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
$conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
foreach ( $conf->MCServerArray as $server ) {
$error = testMemcachedServer( $server );
if ( $error ) {
$errs["MCServers"] = $error;
break;
}
}
} else if ( $conf->Shm == 'memcached' ) {
$errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
}
/* default values for installation */
$conf->Email = importRequest("Email", "email_enabled");
$conf->Emailuser = importRequest("Emailuser", "emailuser_enabled");
$conf->Enotif = importRequest("Enotif", "enotif_allpages");
$conf->Eauthent = importRequest("Eauthent", "eauthent_enabled");
if( $conf->posted && ( 0 == count( $errs ) ) ) {
do { /* So we can 'continue' to end prematurely */
$conf->Root = ($conf->RootPW != "");
/* Load up the settings and get installin' */
$local = writeLocalSettings( $conf );
echo "<li style=\"list-style: none\">\n";
echo "<p><b>Generating configuration file...</b></p>\n";
echo "</li>\n";
$wgCommandLineMode = false;
chdir( ".." );
$ok = eval( $local );
if( $ok === false ) {
dieout( "Errors in generated configuration; " .
"most likely due to a bug in the installer... " .
"Config file was: " .
"<pre>" .
htmlspecialchars( $local ) .
"</pre>" .
"</ul>" );
}
$conf->DBtypename = '';
foreach (array_keys($ourdb) as $db) {
if ($conf->DBtype === $db)
$conf->DBtypename = $ourdb[$db]['fullname'];
}
if ( ! strlen($conf->DBtype)) {
$errs["DBpicktype"] = "Please choose a database type";
continue;
}
if (! $conf->DBtypename) {
$errs["DBtype"] = "Unknown database type '$conf->DBtype'";
continue;
}
print "<li>Database type: {$conf->DBtypename}</li>\n";
$dbclass = 'Database'.ucfirst($conf->DBtype);
$wgDBtype = $conf->DBtype;
$wgDBadminuser = "root";
$wgDBadminpassword = $conf->RootPW;
## Mysql specific:
$wgDBprefix = $conf->DBprefix;
## Postgres specific:
$wgDBport = $conf->DBport;
$wgDBmwschema = $conf->DBmwschema;
$wgDBts2schema = $conf->DBts2schema;
$wgCommandLineMode = true;
$wgUseDatabaseMessages = false; /* FIXME: For database failure */
require_once( "$IP/includes/Setup.php" );
chdir( "config" );
$wgTitle = Title::newFromText( "Installation script" );
error_reporting( E_ALL );
print "<li>Loading class: $dbclass";
$dbc = new $dbclass;
if( $conf->DBtype == 'mysql' ) {
$mysqlOldClient = version_compare( mysql_get_client_info(), "4.1.0", "lt" );
if( $mysqlOldClient ) {
print "<li><b>PHP is linked with old MySQL client libraries. If you are
using a MySQL 4.1 server and have problems connecting to the database,
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></li>\n";
}
$ok = true; # Let's be optimistic
# Decide if we're going to use the superuser or the regular database user
$conf->Root = $useRoot;
if( $conf->Root ) {
$db_user = $conf->RootUser;
$db_pass = $conf->RootPW;
} else {
$db_user = $wgDBuser;
$db_pass = $wgDBpassword;
}
# Attempt to connect
echo( "<li>Attempting to connect to database server as $db_user..." );
$wgDatabase = Database::newFromParams( $wgDBserver, $db_user, $db_pass, '', 1 );
# Check the connection and respond to errors
if( $wgDatabase->isOpen() ) {
# Seems OK
$ok = true;
$wgDBadminuser = $db_user;
$wgDBadminpassword = $db_pass;
echo( "success.</li>\n" );
$wgDatabase->ignoreErrors( true );
$myver = $wgDatabase->getServerVersion();
} else {
# There were errors, report them and back out
$ok = false;
$errno = mysql_errno();
$errtx = htmlspecialchars( mysql_error() );
switch( $errno ) {
case 1045:
case 2000:
echo( "failed due to authentication errors. Check passwords.</li>" );
if( $conf->Root ) {
# The superuser details are wrong
$errs["RootUser"] = "Check username";
$errs["RootPW"] = "and password";
} else {
# The regular user details are wrong
$errs["DBuser"] = "Check username";
$errs["DBpassword"] = "and password";
}
break;
case 2002:
case 2003:
default:
# General connection problem
echo( "failed with error [$errno] $errtx.</li>\n" );
$errs["DBserver"] = "Connection failed";
break;
} # switch
} #conn. att.
if( !$ok ) { continue; }
} else /* not mysql */ {
error_reporting( E_ALL );
$wgSuperUser = '';
## Possible connect as a superuser
if( $useRoot ) {
$wgDBsuperuser = $conf->RootUser;
echo( "<li>Attempting to connect to database \"postgres\" as superuser \"$wgDBsuperuser\"..." );
$wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
if (!$wgDatabase->isOpen()) {
print " error: " . $wgDatabase->lastError() . "</li>\n";
$errs["DBserver"] = "Could not connect to database as superuser";
$errs["RootUser"] = "Check username";
$errs["RootPW"] = "and password";
continue;
}
}
echo( "<li>Attempting to connect to database \"$wgDBname\" as \"$wgDBuser\"..." );
$wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBuser,