RELEASE-NOTES-1.19 for r103706, r103708
[lhc/web/wiklou.git] / includes / installer / DatabaseInstaller.php
index 957ee51..fca8661 100644 (file)
@@ -19,7 +19,7 @@ abstract class DatabaseInstaller {
         *
         * TODO: naming this parent is confusing, 'installer' would be clearer.
         *
-        * @var Installer
+        * @var WebInstaller
         */
        public $parent;
 
@@ -96,7 +96,7 @@ abstract class DatabaseInstaller {
 
        /**
         * Open a connection to the database using the administrative user/password
-        * currently defined in the session, without any caching. Returns a status 
+        * currently defined in the session, without any caching. Returns a status
         * object. On success, the status object will contain a Database object in
         * its value member.
         *
@@ -114,9 +114,9 @@ abstract class DatabaseInstaller {
 
        /**
         * Connect to the database using the administrative user/password currently
-        * defined in the session. Returns a status object. On success, the status 
+        * defined in the session. Returns a status object. On success, the status
         * object will contain a Database object in its value member.
-        * 
+        *
         * This will return a cached connection if one is available.
         *
         * @return Status
@@ -125,6 +125,7 @@ abstract class DatabaseInstaller {
                if ( $this->db ) {
                        return Status::newGood( $this->db );
                }
+
                $status = $this->openConnection();
                if ( $status->isOK() ) {
                        $this->db = $status->value;
@@ -147,15 +148,16 @@ abstract class DatabaseInstaller {
                }
                $this->db->selectDB( $this->getVar( 'wgDBname' ) );
 
-               if( $this->db->tableExists( 'user' ) ) {
+               if( $this->db->tableExists( 'user', __METHOD__ ) ) {
                        $status->warning( 'config-install-tables-exist' );
+                       $this->enableLB();
                        return $status;
                }
 
                $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
                $this->db->begin( __METHOD__ );
 
-               $error = $this->db->sourceFile( $this->db->getSchema() );
+               $error = $this->db->sourceFile( $this->db->getSchemaPath() );
                if( $error !== true ) {
                        $this->db->reportQueryError( $error, 0, '', __METHOD__ );
                        $this->db->rollback( __METHOD__ );
@@ -179,28 +181,10 @@ abstract class DatabaseInstaller {
                if ( !$status->isOK() ) {
                        return $status;
                }
-               $updater = DatabaseUpdater::newForDB( $this->db );
-               $extensionUpdates = $updater->getNewExtensions();
 
-               // No extensions need tables (or haven't updated to new installer support)
-               if( !count( $extensionUpdates ) ) {
-                       return $status;
-               }
+               // Now run updates to create tables for old extensions
+               DatabaseUpdater::newForDB( $this->db )->doUpdates( array( 'extensions' ) );
 
-               $ourExtensions = array_map( 'strtolower', $this->getVar( '_Extensions' ) );
-
-               foreach( $ourExtensions as $ext ) {
-                       if( isset( $extensionUpdates[$ext] ) ) {
-                               $this->db->begin( __METHOD__ );
-                               $error = $this->db->sourceFile( $extensionUpdates[$ext] );
-                               if( $error !== true ) {
-                                       $this->db->rollback( __METHOD__ );
-                                       $status->warning( 'config-install-tables-failed', $error );
-                               } else {
-                                       $this->db->commit( __METHOD__ );
-                               }
-                       }
-               }
                return $status;
        }
 
@@ -212,7 +196,7 @@ abstract class DatabaseInstaller {
        public abstract function getLocalSettings();
 
        /**
-        * Override this to provide DBMS-specific schema variables, to be 
+        * Override this to provide DBMS-specific schema variables, to be
         * substituted into tables.sql and other schema files.
         */
        public function getSchemaVars() {
@@ -236,7 +220,7 @@ abstract class DatabaseInstaller {
 
        /**
         * Set up LBFactory so that wfGetDB() etc. works.
-        * We set up a special LBFactory instance which returns the current 
+        * We set up a special LBFactory instance which returns the current
         * installer connection.
         */
        public function enableLB() {
@@ -297,6 +281,7 @@ abstract class DatabaseInstaller {
        /**
         * Construct and initialise parent.
         * This is typically only called from Installer::getDBInstaller()
+        * @param $parent
         */
        public function __construct( $parent ) {
                $this->parent = $parent;
@@ -307,6 +292,8 @@ abstract class DatabaseInstaller {
         * Check if a named extension is present.
         *
         * @see wfDl
+        * @param $name
+        * @return bool
         */
        protected static function checkExtension( $name ) {
                wfSuppressWarnings();
@@ -339,6 +326,9 @@ abstract class DatabaseInstaller {
 
        /**
         * Get a variable, taking local defaults into account.
+        * @param $var string
+        * @param $default null
+        * @return mixed
         */
        public function getVar( $var, $default = null ) {
                $defaults = $this->getGlobalDefaults();
@@ -353,6 +343,8 @@ abstract class DatabaseInstaller {
 
        /**
         * Convenience alias for $this->parent->setVar()
+        * @param $name string
+        * @param $value mixed
         */
        public function setVar( $name, $value ) {
                $this->parent->setVar( $name, $value );
@@ -360,6 +352,12 @@ abstract class DatabaseInstaller {
 
        /**
         * Get a labelled text box to configure a local variable.
+        *
+        * @param $var string
+        * @param $label string
+        * @param $attribs array
+        * @param $helpData string
+        * @return string
         */
        public function getTextBox( $var, $label, $attribs = array(), $helpData = "" ) {
                $name = $this->getName() . '_' . $var;
@@ -380,6 +378,12 @@ abstract class DatabaseInstaller {
        /**
         * Get a labelled password box to configure a local variable.
         * Implements password hiding.
+        *
+        * @param $var string
+        * @param $label string
+        * @param $attribs array
+        * @param $helpData string
+        * @return string
         */
        public function getPasswordBox( $var, $label, $attribs = array(), $helpData = "" ) {
                $name = $this->getName() . '_' . $var;
@@ -399,6 +403,8 @@ abstract class DatabaseInstaller {
 
        /**
         * Get a labelled checkbox to configure a local boolean variable.
+        *
+        * @return string
         */
        public function getCheckBox( $var, $label, $attribs = array(), $helpData = "" ) {
                $name = $this->getName() . '_' . $var;
@@ -460,7 +466,7 @@ abstract class DatabaseInstaller {
                if ( !$this->db->selectDB( $this->getVar( 'wgDBname' ) ) ) {
                        return false;
                }
-               return $this->db->tableExists( 'cur' ) || $this->db->tableExists( 'revision' );
+               return $this->db->tableExists( 'cur', __METHOD__ ) || $this->db->tableExists( 'revision', __METHOD__ );
        }
 
        /**
@@ -472,8 +478,8 @@ abstract class DatabaseInstaller {
                return
                        Html::openElement( 'fieldset' ) .
                        Html::element( 'legend', array(), wfMsg( 'config-db-install-account' ) ) .
-                       $this->getTextBox( '_InstallUser', 'config-db-username', array(), $this->parent->getHelpBox( 'config-db-install-username' ) ) .
-                       $this->getPasswordBox( '_InstallPassword', 'config-db-password', array(), $this->parent->getHelpBox( 'config-db-install-password' ) ) .
+                       $this->getTextBox( '_InstallUser', 'config-db-username', array( 'dir' => 'ltr' ), $this->parent->getHelpBox( 'config-db-install-username' ) ) .
+                       $this->getPasswordBox( '_InstallPassword', 'config-db-password', array( 'dir' => 'ltr' ), $this->parent->getHelpBox( 'config-db-install-password' ) ) .
                        Html::closeElement( 'fieldset' );
        }
 
@@ -493,13 +499,14 @@ abstract class DatabaseInstaller {
         * @return String
         */
        public function getWebUserBox( $noCreateMsg = false ) {
+               $wrapperStyle = $this->getVar( '_SameAccount' ) ? 'display: none' : '';
                $s = Html::openElement( 'fieldset' ) .
                        Html::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
                        $this->getCheckBox(
                                '_SameAccount', 'config-db-web-account-same',
                                array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' )
                        ) .
-                       Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => 'display: none;' ) ) .
+                       Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ) ) .
                        $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
                        $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
                        $this->parent->getHelpBox( 'config-db-web-help' );
@@ -527,6 +534,10 @@ abstract class DatabaseInstaller {
                        $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
                }
 
+               if( $this->getVar( '_CreateDBAccount' ) && strval( $this->getVar( 'wgDBpassword' ) ) == '' ) {
+                       return Status::newFatal( 'config-db-password-empty', $this->getVar( 'wgDBuser' ) );
+               }
+
                return Status::newGood();
        }
 
@@ -547,11 +558,13 @@ abstract class DatabaseInstaller {
                        return $status;
                }
                global $IP;
+               wfSuppressWarnings();
                $rows = file( "$IP/maintenance/interwiki.list",
                        FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
+               wfRestoreWarnings();
                $interwikis = array();
                if ( !$rows ) {
-                       return Status::newFatal( 'config-install-interwiki-sql' );
+                       return Status::newFatal( 'config-install-interwiki-list' );
                }
                foreach( $rows as $row ) {
                        $row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee