Resubmit "Add support for mysqli extension"
[lhc/web/wiklou.git] / includes / installer / MysqlUpdater.php
index df1f610..2842bba 100644 (file)
@@ -195,9 +195,9 @@ class MysqlUpdater extends DatabaseUpdater {
 
                        // 1.19
                        array( 'addIndex', 'logging',       'type_action',      'patch-logging-type-action-index.sql'),
+                       array( 'addField', 'revision',      'rev_sha1',         'patch-rev_sha1.sql' ),
                        array( 'doMigrateUserOptions' ),
                        array( 'dropField', 'user',         'user_options', 'patch-drop-user_options.sql' ),
-                       array( 'addField', 'revision',      'rev_sha1',         'patch-rev_sha1.sql' ),
                        array( 'addField', 'archive',       'ar_sha1',          'patch-ar_sha1.sql' ),
                        array( 'addIndex', 'page', 'page_redirect_namespace_len', 'patch-page_redirect_namespace_len.sql' ),
                        array( 'addField',      'uploadstash',  'us_chunk_inx',         'patch-uploadstash_chunk.sql' ),
@@ -247,11 +247,8 @@ class MysqlUpdater extends DatabaseUpdater {
                        return true;
                }
 
-               $tableName = $this->db->tableName( $table );
-               $res = $this->db->query( "SELECT $field FROM $tableName LIMIT 0", __METHOD__ );
-               $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
-
-               if ( in_array( 'binary', $flags ) ) {
+               $fieldInfo = $this->db->fieldInfo( $table, $field );
+               if ( $fieldInfo->isBinary() ) {
                        $this->output( "...$table table has correct $field encoding.\n" );
                } else {
                        $this->applyPatch( $patchFile, false, "Fixing $field encoding on $table table" );
@@ -276,11 +273,13 @@ class MysqlUpdater extends DatabaseUpdater {
                        foreach ( $info as $row ) {
                                if ( $row->Column_name == $field ) {
                                        $this->output( "...index $index on table $table includes field $field.\n" );
+
                                        return true;
                                }
                        }
                }
                $this->output( "...index $index on table $table has no field $field; added.\n" );
+
                return false;
        }
 
@@ -296,6 +295,7 @@ class MysqlUpdater extends DatabaseUpdater {
 
                if ( $this->db->tableExists( "interwiki", __METHOD__ ) ) {
                        $this->output( "...already have interwiki table\n" );
+
                        return;
                }
 
@@ -313,6 +313,7 @@ class MysqlUpdater extends DatabaseUpdater {
                }
                if ( $meta->isMultipleKey() ) {
                        $this->output( "...indexes seem up to 20031107 standards.\n" );
+
                        return;
                }
 
@@ -328,10 +329,11 @@ class MysqlUpdater extends DatabaseUpdater {
                $info = $this->db->fieldInfo( 'imagelinks', 'il_from' );
                if ( !$info || $info->type() !== 'string' ) {
                        $this->output( "...il_from OK\n" );
+
                        return;
                }
 
-               if( $this->applyPatch( 'patch-fix-il_from.sql', false, "Fixing ancient broken imagelinks table." ) ) {
+               if ( $this->applyPatch( 'patch-fix-il_from.sql', false, "Fixing ancient broken imagelinks table." ) ) {
                        $this->output( "NOTE: you will have to run maintenance/refreshLinks.php after this." );
                }
        }
@@ -344,6 +346,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $nontalk = $this->db->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', __METHOD__ );
                if ( $talk == $nontalk ) {
                        $this->output( "...watchlist talk page rows already present.\n" );
+
                        return;
                }
 
@@ -361,6 +364,7 @@ class MysqlUpdater extends DatabaseUpdater {
        function doSchemaRestructuring() {
                if ( $this->db->tableExists( 'page', __METHOD__ ) ) {
                        $this->output( "...page table already exists.\n" );
+
                        return;
                }
 
@@ -368,7 +372,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $this->output( wfTimestamp( TS_DB ) );
                $this->output( "......checking for duplicate entries.\n" );
 
-               list ( $cur, $old, $page, $revision, $text ) = $this->db->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
+               list( $cur, $old, $page, $revision, $text ) = $this->db->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
 
                $rows = $this->db->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
                                FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", __METHOD__ );
@@ -379,7 +383,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        $this->output( sprintf( "<b>      %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
                        $duplicate = array();
                        foreach ( $rows as $row ) {
-                               if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
+                               if ( !isset( $duplicate[$row->cur_namespace] ) ) {
                                        $duplicate[$row->cur_namespace] = array();
                                }
                                $duplicate[$row->cur_namespace][] = $row->cur_title;
@@ -525,12 +529,12 @@ class MysqlUpdater extends DatabaseUpdater {
 
        protected function doNamespaceSize() {
                $tables = array(
-                       'page'          => 'page',
-                       'archive'       => 'ar',
+                       'page' => 'page',
+                       'archive' => 'ar',
                        'recentchanges' => 'rc',
-                       'watchlist'     => 'wl',
-                       'querycache'    => 'qc',
-                       'logging'       => 'log',
+                       'watchlist' => 'wl',
+                       'querycache' => 'qc',
+                       'logging' => 'log',
                );
                foreach ( $tables as $table => $prefix ) {
                        $field = $prefix . '_namespace';
@@ -552,6 +556,7 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doPagelinksUpdate() {
                if ( $this->db->tableExists( 'pagelinks', __METHOD__ ) ) {
                        $this->output( "...already have pagelinks table.\n" );
+
                        return;
                }
 
@@ -589,6 +594,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $duper = new UserDupes( $this->db, array( $this, 'output' ) );
                if ( $duper->hasUniqueIndex() ) {
                        $this->output( "...already have unique user_name index.\n" );
+
                        return;
                }
 
@@ -621,6 +627,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        } else {
                                $this->output( "...user_groups table exists and is in current format.\n" );
                        }
+
                        return;
                }
 
@@ -633,6 +640,7 @@ class MysqlUpdater extends DatabaseUpdater {
                                $this->output( "*** WARNING: couldn't locate user_rights table or field for upgrade.\n" );
                                $this->output( "*** You may need to manually configure some sysops by manipulating\n" );
                                $this->output( "*** the user_groups table.\n" );
+
                                return;
                        }
                }
@@ -651,7 +659,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        foreach ( $groups as $group ) {
                                $this->db->insert( 'user_groups',
                                        array(
-                                               'ug_user'  => $row->ur_user,
+                                               'ug_user' => $row->ur_user,
                                                'ug_group' => $group ),
                                        __METHOD__ );
                        }
@@ -670,6 +678,7 @@ class MysqlUpdater extends DatabaseUpdater {
                }
                if ( $info->isNullable() ) {
                        $this->output( "...wl_notificationtimestamp is already nullable.\n" );
+
                        return;
                }
 
@@ -686,7 +695,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $this->db->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", __METHOD__ );
                $rows = $this->db->affectedRows();
 
-               if( $rows ) {
+               if ( $rows ) {
                        $this->output( "Set page_random to a random value on $rows rows where it was set to 0\n" );
                } else {
                        $this->output( "...no page_random rows needed to be set\n" );
@@ -696,6 +705,7 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doTemplatelinksUpdate() {
                if ( $this->db->tableExists( 'templatelinks', __METHOD__ ) ) {
                        $this->output( "...templatelinks table already exists\n" );
+
                        return;
                }
 
@@ -719,7 +729,6 @@ class MysqlUpdater extends DatabaseUpdater {
                                                'tl_title' => $row->pl_title,
                                        ), __METHOD__
                                );
-
                        }
                } else {
                        // Fast update
@@ -739,8 +748,8 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doBacklinkingIndicesUpdate() {
                if ( !$this->indexHasField( 'pagelinks', 'pl_namespace', 'pl_from' ) ||
                        !$this->indexHasField( 'templatelinks', 'tl_namespace', 'tl_from' ) ||
-                       !$this->indexHasField( 'imagelinks', 'il_to', 'il_from' ) )
-               {
+                       !$this->indexHasField( 'imagelinks', 'il_to', 'il_from' )
+               {
                        $this->applyPatch( 'patch-backlinkindexes.sql', false, "Updating backlinking indices" );
                }
        }
@@ -753,6 +762,7 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doRestrictionsUpdate() {
                if ( $this->db->tableExists( 'page_restrictions', __METHOD__ ) ) {
                        $this->output( "...page_restrictions table already exists.\n" );
+
                        return;
                }
 
@@ -774,6 +784,7 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doCategoryPopulation() {
                if ( $this->updateRowExists( 'populate category' ) ) {
                        $this->output( "...category table already populated.\n" );
+
                        return;
                }
 
@@ -807,7 +818,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        return true;
                }
 
-               if ( $wgProfileToDatabase === true && ! $this->db->tableExists( 'profiling', __METHOD__ ) ) {
+               if ( $wgProfileToDatabase === true && !$this->db->tableExists( 'profiling', __METHOD__ ) ) {
                        $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' );
                }
        }
@@ -821,8 +832,10 @@ class MysqlUpdater extends DatabaseUpdater {
                        return true;
                } elseif ( $this->db->fieldExists( 'profiling', 'pf_memory', __METHOD__ ) ) {
                        $this->output( "...profiling table has pf_memory field.\n" );
+
                        return true;
                }
+
                return $this->applyPatch( 'patch-profiling-memory.sql', false, "Adding pf_memory field to table profiling" );
        }
 
@@ -831,6 +844,7 @@ class MysqlUpdater extends DatabaseUpdater {
                if ( !$info ) {
                        $this->applyPatch( 'patch-filearchive-user-index.sql', false, "Updating filearchive indices" );
                }
+
                return true;
        }
 
@@ -838,10 +852,12 @@ class MysqlUpdater extends DatabaseUpdater {
                $info = $this->db->indexInfo( 'pagelinks', 'pl_namespace' );
                if ( is_array( $info ) && !$info[0]->Non_unique ) {
                        $this->output( "...pl_namespace, tl_namespace, il_to indices are already UNIQUE.\n" );
+
                        return true;
                }
                if ( $this->skipSchema ) {
                        $this->output( "...skipping schema change (making pl_namespace, tl_namespace and il_to indices UNIQUE).\n" );
+
                        return false;
                }
 
@@ -851,6 +867,7 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doUpdateMimeMinorField() {
                if ( $this->updateRowExists( 'mime_minor_length' ) ) {
                        $this->output( "...*_mime_minor fields are already long enough.\n" );
+
                        return;
                }
 
@@ -860,6 +877,7 @@ class MysqlUpdater extends DatabaseUpdater {
        protected function doClFieldsUpdate() {
                if ( $this->updateRowExists( 'cl_fields_update' ) ) {
                        $this->output( "...categorylinks up-to-date.\n" );
+
                        return;
                }
 
@@ -889,6 +907,7 @@ class MysqlUpdater extends DatabaseUpdater {
                }
                if ( $info->isNullable() ) {
                        $this->output( "...user_last_timestamp is already nullable.\n" );
+
                        return;
                }
 
@@ -899,10 +918,12 @@ class MysqlUpdater extends DatabaseUpdater {
                $info = $this->db->indexInfo( 'iwlinks', 'iwl_prefix_title_from' );
                if ( is_array( $info ) && $info[0]->Non_unique ) {
                        $this->output( "...iwl_prefix_title_from index is already non-UNIQUE.\n" );
+
                        return true;
                }
                if ( $this->skipSchema ) {
                        $this->output( "...skipping schema change (making iwl_prefix_title_from index non-UNIQUE).\n" );
+
                        return false;
                }