Followup r72866, make 100 in 100+ a param. Makes raising the limit easier :)
[lhc/web/wiklou.git] / config / Installer.php
index 45d6d6e..9d8855c 100644 (file)
@@ -1,23 +1,27 @@
 <?php
-
-# 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
+/**
+ * MediaWiki web-based config/installation
+ *
+ * Copyright © 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
+ *
+ * @file
+ */
 
 if( !defined( 'MEDIAWIKI_INSTALL' ) ) {
        die( 'Not an entry point.' );
@@ -83,6 +87,15 @@ $ourdb['sqlite'] = array(
        'serverless' =>  true
 );
 
+$ourdb['mssql'] = array(
+       'fullname'   => 'Microsoft SQL Server',
+       'havedriver' => 0,
+       'compile'    => 'sqlsrv',
+       'bgcolor'    => '#cccccc',
+       'rootuser'   => 'root',
+       'serverless' => false
+);
+
 $ourdb['ibm_db2'] = array(
        'fullname'   => 'DB2',
        'havedriver' => 0,
@@ -264,9 +277,6 @@ if( !is_writable( "." ) ) {
        <p>Afterwards retry to start the <a href=\"\">setup</a>.</p>" );
 }
 
-
-require_once( "$IP/maintenance/updaters.inc" );
-
 class ConfigData {
        function getEncoded( $data ) {
                # removing latin1 support, no need...
@@ -333,7 +343,7 @@ 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 ) ) ) {
+       if( wfDl( $compname ) ) {
                array_push($phpdatabases, $db);
                $ourdb[$db]['havedriver'] = 1;
        }
@@ -631,9 +641,7 @@ print "<li style='font-weight:bold;color:green;font-size:110%'>Environment check
        $conf->SQLiteDataDir = importPost( "SQLiteDataDir", "$IP/../data" );
 
        ## DB2 specific:
-       // New variable in order to have a different default port number
        $conf->DBport_db2   = importPost( "DBport_db2",      "50000" );
-       $conf->DBcataloged  = importPost( "DBcataloged",  "cataloged" );
        $conf->DBdb2schema  = importPost( "DBdb2schema",  "mediawiki" );
 
        // Oracle specific
@@ -824,7 +832,9 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                }
 
                ## DB2 specific:
-               $wgDBcataloged = $conf->DBcataloged;
+               if ( $conf->DBtype == 'ibm_db2' ) {
+                       $wgDBport      = $conf->DBport_db2;
+               }
 
                $wgCommandLineMode = true;
                if (! defined ( 'STDERR' ) )
@@ -906,6 +916,41 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
 
                        if( !$ok ) { continue; }
                }
+               else if ( $conf->DBtype == 'mssql' ) {
+                       # Possible connect as a superuser
+                       if ( $useRoot ) {
+                               echo( "<li>Attempting to connect to database \"{$conf->DBtype}\" as superuser \"{$conf->RootUser}\"" );
+                               $wgDatabase = $dbc->newFromParams(
+                                                                               $conf->DBserver,
+                                                                               $conf->RootUser,
+                                                                               $conf->RootPW,
+                                                                               false,
+                                                                               false,
+                                                                               1
+                                                                       );
+                               if ( !$wgDatabase->isOpen() ) {
+                                       echo( " error: {$wgDatabase->lastError()}</li>\n" );
+                                       $errs['DBserver'] = 'Could not connect to database as superuser';
+                                       $errs['RootUser'] = 'Check username';
+                                       $errs['RootPW'] = 'and password';
+                                       continue;
+                               }
+                               $wgDatabase->initial_setup( $conf->DBname, $conf->DBuser, $conf->DBpassword );
+                       }
+                       echo( "<li>Attempting to connect to database \"{$wgDBname}\" as \"{$wgDBuser}\"..." );
+                       $wgDatabase = $dbc->newFromParams(
+                                                                       $conf->DBserver,
+                                                                       $conf->DBuser,
+                                                                       $conf->DBpassword,
+                                                                       $conf->DBname,
+                                                                       1
+                                                               );
+                       if ( !$wgDatabase->isOpen() ) {
+                               echo( " error: {$wgDatabase->lastError()} </li>\n" );
+                       } else {
+                               $myver = $wgDatabase->getServerVersion();
+                       }
+               }
                else if( $conf->DBtype == 'ibm_db2' ) {
                        if( $useRoot ) {
                                $db_user = $conf->RootUser;
@@ -994,7 +1039,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                echo "<li>Connect failed.</li>";
                                if ($useRoot) {
                                        if (ini_get('oci8.privileged_connect') === false) {
-                                               echo "<li>Privileged connect disabled, please set oci8.privileged_connect or run maintenance/ora/user.sql script manually prior to continuing.</li>";
+                                               echo "<li>Privileged connect disabled, please set oci8.privileged_connect or run maintenance/oracle/user.sql script manually prior to continuing.</li>";
                                                $ok = false;
                                        } else {
                                                $wgDBadminuser = $conf->RootUser;
@@ -1004,7 +1049,8 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                                if ($wgDatabase->isOpen()) {
                                                        $wgDBOracleDefTS = $conf->DBdefTS_ora;
                                                        $wgDBOracleTempTS = $conf->DBtempTS_ora;
-                                                       $wgDatabase->sourceFile( "../maintenance/ora/user.sql"  );
+                                                       $res = $wgDatabase->sourceFile( "../maintenance/oracle/user.sql"  );
+                                                       if ($res !== true) dieout($res);
                                                } else {
                                                        echo "<li>Invalid database superuser, please supply a valid superuser account.</li>";
                                                        echo "<li>ERR: ".print_r(oci_error(), true)."</li>";
@@ -1028,14 +1074,12 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                        }
                } else { # not mysql
                        error_reporting( E_ALL | E_STRICT );
-                       $wgSuperUser = '';
                        ## Possible connect as a superuser
                        // Changed !mysql to postgres check since it seems to only apply to postgres
                        if( $useRoot && $conf->DBtype == 'postgres' ) {
-                               $wgDBsuperuser = $conf->RootUser;
                                echo( "<li>Attempting to connect to database \"postgres\" as superuser \"" .
-                                       htmlspecialchars( $wgDBsuperuser ) . "\"..." );
-                               $wgDatabase = $dbc->newFromParams($wgDBserver, $wgDBsuperuser, $conf->RootPW, "postgres", 1);
+                                       htmlspecialchars( $conf->RootUser ) . "\"..." );
+                               $wgDatabase = $dbc->newFromParams($wgDBserver, $conf->RootUser, $conf->RootPW, "postgres", 1);
                                if (!$wgDatabase->isOpen()) {
                                        print " error: " . htmlspecialchars( $wgDatabase->lastError() ) . "</li>\n";
                                        $errs["DBserver"] = "Could not connect to database as superuser";
@@ -1043,7 +1087,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                        $errs["RootPW"] = "and password";
                                        continue;
                                }
-                               $wgDatabase->initial_setup($conf->RootPW, 'postgres');
+                               $wgDatabase->initial_setup($conf->RootUser, $conf->RootPW, 'postgres');
                        }
                        echo( "<li>Attempting to connect to database \"" . htmlspecialchars( $wgDBname ) .
                                "\" as \"" . htmlspecialchars( $wgDBuser ) . "\"..." );
@@ -1181,14 +1225,22 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                                        print " <b class='error'>If the next step fails, see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'>http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
                                                }
                                                print "</li>\n";
-                                               $wgDatabase->sourceFile( "../maintenance/users.sql" );
+                                               $res = $wgDatabase->sourceFile( "../maintenance/users.sql" );
+                                               if ($res !== true) dieout($res);
                                        }
                                }
                        }
                        print "</ul><pre>\n";
                        chdir( ".." );
                        flush();
-                       do_all_updates();
+
+                       define( 'MW_NO_SETUP', true );
+                       $updater = DatabaseUpdater::newForDb( $wgDatabase, false );
+                       $updater->doUpdates();
+                       foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
+                               call_user_func_array( array( new $maint, 'execute' ), array() );
+                       }
+
                        chdir( "config" );
                        print "</pre>\n";
                        print "<ul><li>Finished update checks.</li>\n";
@@ -1204,7 +1256,6 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                                break;
                                        }
                                }
-                               $wgDatabase->freeResult( $res );
                                if ( !$found && $conf->DBengine != 'MyISAM' ) {
                                        echo "<li><strong>Warning:</strong> " . htmlspecialchars( $conf->DBengine ) .
                                                " storage engine not available, " .
@@ -1213,11 +1264,19 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                }
                        }
 
-                       # FIXME: Check for errors
                        print "<li>Creating tables...";
                        if ($conf->DBtype == 'mysql') {
-                               $wgDatabase->sourceFile( "../maintenance/tables.sql" );
-                               $wgDatabase->sourceFile( "../maintenance/interwiki.sql" );
+                               $res = $wgDatabase->sourceFile( "../maintenance/tables.sql" );
+                               if ($res === true) {
+                                       print " done.</li>\n<li>Populating interwiki table... \n";
+                                       $res = $wgDatabase->sourceFile( "../maintenance/interwiki.sql" );
+                               }
+                               if ($res === true) {
+                                       print " done.</li>\n";
+                               } else {
+                                       print " <b>FAILED</b></li>\n";
+                                       dieout( htmlspecialchars( $res ) );
+                               }
                        } elseif (is_callable(array($wgDatabase, 'setup_database'))) {
                                $wgDatabase->setup_database();
                        }
@@ -1226,8 +1285,6 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                continue;
                        }
 
-                       print " done.</li>\n";
-
 
                        if ( $conf->DBtype == 'ibm_db2' ) {
                                // Now that table creation is done, make sure everything is committed
@@ -1268,8 +1325,13 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                } else {
                                        # Yes, so run the grants
                                        echo( "<li>" . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) );
-                                       $wgDatabase->sourceFile( "../maintenance/users.sql" );
-                                       echo( "success.</li>\n" );
+                                       $res = $wgDatabase->sourceFile( "../maintenance/users.sql" );
+                                       if ( $res === true ) {
+                                               echo( " success.</li>\n" );
+                                       } else {
+                                               echo( " <b>FAILED</b>.</li>\n" );
+                                               dieout( $res );
+                                       }
                                }
                        }
 
@@ -1317,7 +1379,7 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                $localSettings = str_replace( "\r\n", "\n", $localSettings );
                $f = fopen( "LocalSettings.php", 'xt' );
 
-               if( $f == false ) {
+               if( !$f ) {
                        print( "</li>\n" );
                        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" .
                        "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
@@ -1502,8 +1564,8 @@ if( count( $errs ) ) {
                <label class='column'>E-mail notification about changes:</label>
                <ul class="plain">
                <li><?php aField( $conf, "Enotif", "Disabled", "radio", "enotif_disabled" ); ?></li>
-               <li><?php aField( $conf, "Enotif", "Enabled for changes to user discussion pages only", "radio", "enotif_usertalk" ); ?></li>
-               <li><?php aField( $conf, "Enotif", "Enabled for changes to user discussion pages, and to pages on watchlists (not recommended for large wikis)", "radio", "enotif_allpages" ); ?></li>
+               <li><?php aField( $conf, "Enotif", "Changes to user discussion pages only", "radio", "enotif_usertalk" ); ?></li>
+               <li><?php aField( $conf, "Enotif", "Changes to user discussion pages, and to pages on watchlists (not recommended for large wikis)", "radio", "enotif_allpages" ); ?></li>
                </ul>
        </div>
        <div class="config-desc">
@@ -1540,7 +1602,7 @@ if( count( $errs ) ) {
        }
 ?>
        <ul class='plain'><?php
-               database_picker($conf);
+               database_picker($ourdb, $conf);
        ?></ul>
        </div>
 
@@ -1569,7 +1631,7 @@ if( count( $errs ) ) {
                <div class="config-input">
                        <label class="column">Superuser account:</label>
                        <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?> />
-                       &nbsp;<label for="useroot">Use superuser account</label>
+                       &#160;<label for="useroot">Use superuser account</label>
                </div>
                <div class="config-input"><?php aField( $conf, "RootUser", "Superuser name:", "text" ); ?></div>
                <div class="config-input"><?php aField( $conf, "RootPW", "Superuser password:", "password" ); ?></div>
@@ -1581,7 +1643,7 @@ if( count( $errs ) ) {
                </p>
        </div>
 
-       <?php database_switcher('mysql'); ?>
+       <?php database_switcher($ourdb, 'mysql'); ?>
        <div class="config-input"><?php aField( $conf, "DBprefix", "Database table prefix:" ); ?></div>
        <div class="config-desc">
                <p>If you need to share one database between multiple wikis, or
@@ -1620,7 +1682,7 @@ if( count( $errs ) ) {
        </p>
        </fieldset>
 
-       <?php database_switcher('postgres'); ?>
+       <?php database_switcher($ourdb, 'postgres'); ?>
        <div class="config-input"><?php aField( $conf, "DBport", "Database port:" ); ?></div>
        <div class="config-input"><?php aField( $conf, "DBpgschema", "Schema for mediawiki:" ); ?></div>
        <div class="config-input"><?php aField( $conf, "DBts2schema", "Schema for tsearch2:" ); ?></div>
@@ -1631,7 +1693,7 @@ if( count( $errs ) ) {
        </div>
        </fieldset>
 
-       <?php database_switcher('sqlite'); ?>
+       <?php database_switcher($ourdb, 'sqlite'); ?>
        <div class="config-input"><?php
                aField( $conf, "SQLiteDataDir", "SQLite data directory:" );
        ?></div>
@@ -1643,18 +1705,24 @@ if( count( $errs ) ) {
        </div>
        </fieldset>
 
-       <?php database_switcher('ibm_db2'); ?>
+       
+       <?php database_switcher($ourdb, 'mssql' ); ?>
+       <div class="config-desc">
+               <p>No MS SQL Server specific options at this time.</p>
+       </div>
+       </fieldset>
+       
+       
+       <?php database_switcher($ourdb, 'ibm_db2'); ?>
        <div class="config-input"><?php
                aField( $conf, "DBport_db2", "Database port:" );
        ?></div>
+       <div class="config-desc">
+               <p>50000 is the usual DB2 port.</p>
+       </div>
        <div class="config-input"><?php
                aField( $conf, "DBdb2schema", "Schema for mediawiki:" );
        ?></div>
-       <div>Select one:</div>
-               <ul class="plain">
-               <li><?php aField( $conf, "DBcataloged", "Cataloged (DB2 installed locally)", "radio", "cataloged" ); ?></li>
-               <li><?php aField( $conf, "DBcataloged", "Uncataloged (remote DB2 through ODBC)", "radio", "uncataloged" ); ?></li>
-               </ul>
        <div class="config-desc">
                <p>If you need to share one database between multiple wikis, or
                between MediaWiki and another web application, you may specify
@@ -1662,7 +1730,7 @@ if( count( $errs ) ) {
        </div>
        </fieldset>
 
-       <?php database_switcher('oracle'); ?>
+       <?php database_switcher($ourdb, 'oracle'); ?>
        <div class="config-input"><?php aField( $conf, "DBprefix_ora", "Database table prefix:" ); ?></div>
        <div class="config-desc">
                <p>If you need to share one database between multiple wikis, or
@@ -1676,7 +1744,7 @@ if( count( $errs ) ) {
        </fieldset>
 
        <div class="config-input" style="padding:2em 0 3em">
-               <label class='column'>&nbsp;</label>
+               <label class='column'>&#160;</label>
                <input type="submit" value="Install MediaWiki!" class="btn-install" />
        </div>
 </div>
@@ -1845,15 +1913,15 @@ function writeLocalSettings( $conf ) {
 "# SQLite-specific settings
 \$wgSQLiteDataDir    = \"{$sqliteDataDir}\";";
        } elseif( $conf->DBtype == 'ibm_db2' ) {
-               $dbsettings =
-"# DB2 specific settings
-\$wgDBport_db2       = \"{$slconf['DBport_db2']}\";
-\$wgDBmwschema       = \"{$slconf['DBdb2schema']}\";
-\$wgDBcataloged      = \"{$slconf['DBcataloged']}\";";
+               $dbsettings = <<<MULTILINE
+# DB2 specific settings
+\$wgDBport           = "{$slconf['DBport_db2']}";
+\$wgDBmwschema       = "{$slconf['DBdb2schema']}";
+MULTILINE;
        } elseif( $conf->DBtype == 'oracle' ) {
                $dbsettings =
 "# Oracle specific settings
-\$wgDBprefix         = \"{$slconf['DBprefix']}\";";
+\$wgDBprefix         = \"{$slconf['DBprefix_ora']}\";";
        } else {
                // ummm... :D
                $dbsettings = '';
@@ -2152,8 +2220,7 @@ function testMemcachedServer( $server ) {
        return $errstr;
 }
 
-function database_picker($conf) {
-       global $ourdb;
+function database_picker($ourdb, $conf) {
        print "\n";
        foreach(array_keys($ourdb) as $db) {
                if ($ourdb[$db]['havedriver']) {
@@ -2165,8 +2232,7 @@ function database_picker($conf) {
        print "\n\t";
 }
 
-function database_switcher($db) {
-       global $ourdb;
+function database_switcher($ourdb, $db) {
        $color = $ourdb[$db]['bgcolor'];
        $full = $ourdb[$db]['fullname'];
        print "<fieldset id='$db' style='clear:both'><legend>$full-specific options</legend>\n";
@@ -2241,17 +2307,6 @@ function getShellLocale( $wikiLang ) {
        return false;
 }
 
-function wfArrayMap( $function, $input ) {
-       $ret = array_map( $function, $input );
-       foreach ( $ret as $key => $value ) {
-               $taint = istainted( $input[$key] );
-               if ( $taint ) {
-                       taint( $ret[$key], $taint );
-               }
-       }
-       return $ret;
-}
-
 ?>
 
        <div class="license">
@@ -2291,7 +2346,7 @@ function wfArrayMap( $function, $input ) {
                        <li><a href="http://www.mediawiki.org/wiki/Manual:Contents">Administrator's Guide</a></li>
                        <li><a href="http://www.mediawiki.org/wiki/Manual:FAQ">FAQ</a></li>
                </ul>
-               <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright © 2001-2009 by Magnus Manske, Brion Vibber,
+               <p style="font-size:90%;margin-top:1em">MediaWiki is Copyright © 2001-2010 by Magnus Manske, Brion Vibber,
                 Lee Daniel Crocker, Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason, Niklas Laxström,
                 Domas Mituzas, Rob Church, Yuri Astrakhan, Aryeh Gregor, Aaron Schulz and others.</p>
        </div></div>