resources: Collapse all jQuery UI modules into one deprecated mega-module
[lhc/web/wiklou.git] / maintenance / rebuildrecentchanges.php
index d86c8ed..7267b2c 100644 (file)
@@ -80,6 +80,8 @@ class RebuildRecentchanges extends Maintenance {
 
        /**
         * Rebuild pass 1: Insert `recentchanges` entries for page revisions.
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass1( ILBFactory $lbFactory ) {
                $dbw = $this->getDB( DB_MASTER );
@@ -177,6 +179,8 @@ class RebuildRecentchanges extends Maintenance {
        /**
         * Rebuild pass 2: Enhance entries for page revisions with references to the previous revision
         * (rc_last_oldid, rc_new etc.) and size differences (rc_old_len, rc_new_len).
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass2( ILBFactory $lbFactory ) {
                $dbw = $this->getDB( DB_MASTER );
@@ -199,29 +203,29 @@ class RebuildRecentchanges extends Maintenance {
                $lastOldId = 0;
                $lastSize = null;
                $updated = 0;
-               foreach ( $res as $obj ) {
+               foreach ( $res as $row ) {
                        $new = 0;
 
-                       if ( $obj->rc_cur_id != $lastCurId ) {
+                       if ( $row->rc_cur_id != $lastCurId ) {
                                # Switch! Look up the previous last edit, if any
-                               $lastCurId = intval( $obj->rc_cur_id );
-                               $emit = $obj->rc_timestamp;
+                               $lastCurId = intval( $row->rc_cur_id );
+                               $emit = $row->rc_timestamp;
 
-                               $row = $dbw->selectRow(
+                               $revRow = $dbw->selectRow(
                                        'revision',
                                        [ 'rev_id', 'rev_len' ],
                                        [ 'rev_page' => $lastCurId, "rev_timestamp < " . $dbw->addQuotes( $emit ) ],
                                        __METHOD__,
                                        [ 'ORDER BY' => 'rev_timestamp DESC' ]
                                );
-                               if ( $row ) {
-                                       $lastOldId = intval( $row->rev_id );
+                               if ( $revRow ) {
+                                       $lastOldId = intval( $revRow->rev_id );
                                        # Grab the last text size if available
-                                       $lastSize = !is_null( $row->rev_len ) ? intval( $row->rev_len ) : null;
+                                       $lastSize = !is_null( $revRow->rev_len ) ? intval( $revRow->rev_len ) : null;
                                } else {
                                        # No previous edit
                                        $lastOldId = 0;
-                                       $lastSize = null;
+                                       $lastSize = 0;
                                        $new = 1; // probably true
                                }
                        }
@@ -233,7 +237,7 @@ class RebuildRecentchanges extends Maintenance {
                                $size = (int)$dbw->selectField(
                                        'revision',
                                        'rev_len',
-                                       [ 'rev_id' => $obj->rc_this_oldid ],
+                                       [ 'rev_id' => $row->rc_this_oldid ],
                                        __METHOD__
                                );
 
@@ -249,13 +253,13 @@ class RebuildRecentchanges extends Maintenance {
                                        ],
                                        [
                                                'rc_cur_id' => $lastCurId,
-                                               'rc_this_oldid' => $obj->rc_this_oldid,
-                                               'rc_timestamp' => $obj->rc_timestamp // index usage
+                                               'rc_this_oldid' => $row->rc_this_oldid,
+                                               'rc_timestamp' => $row->rc_timestamp // index usage
                                        ],
                                        __METHOD__
                                );
 
-                               $lastOldId = intval( $obj->rc_this_oldid );
+                               $lastOldId = intval( $row->rc_this_oldid );
                                $lastSize = $size;
 
                                if ( ( ++$updated % $this->getBatchSize() ) == 0 ) {
@@ -267,24 +271,29 @@ class RebuildRecentchanges extends Maintenance {
 
        /**
         * Rebuild pass 3: Insert `recentchanges` entries for action logs.
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass3( ILBFactory $lbFactory ) {
-               global $wgLogRestrictions;
+               global $wgLogRestrictions, $wgFilterLogTypes;
 
                $dbw = $this->getDB( DB_MASTER );
                $commentStore = CommentStore::getStore();
+               $nonRCLogs = array_merge( array_keys( $wgLogRestrictions ),
+                       array_keys( $wgFilterLogTypes ),
+                       [ 'create' ] );
 
-               $this->output( "Loading from user, page, and logging tables...\n" );
+               $this->output( "Loading from user and logging tables...\n" );
 
                $commentQuery = $commentStore->getJoin( 'log_comment' );
                $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
                $res = $dbw->select(
-                       [ 'logging', 'page' ] + $commentQuery['tables'] + $actorQuery['tables'],
+                       [ 'logging' ] + $commentQuery['tables'] + $actorQuery['tables'],
                        [
                                'log_timestamp',
                                'log_namespace',
                                'log_title',
-                               'page_id',
+                               'log_page',
                                'log_type',
                                'log_action',
                                'log_id',
@@ -294,16 +303,12 @@ class RebuildRecentchanges extends Maintenance {
                        [
                                'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffFrom ) ),
                                'log_timestamp < ' . $dbw->addQuotes( $dbw->timestamp( $this->cutoffTo ) ),
-                               // Some logs don't go in RC since they are private.
-                               // @FIXME: core/extensions also have spammy logs that don't go in RC.
-                               'log_type' => array_diff( LogPage::validTypes(), array_keys( $wgLogRestrictions ) ),
+                               // Some logs don't go in RC since they are private, or are included in the filterable log types.
+                               'log_type' => array_diff( LogPage::validTypes(), $nonRCLogs ),
                        ],
                        __METHOD__,
                        [ 'ORDER BY' => 'log_timestamp DESC' ],
-                       [
-                               'page' =>
-                                       [ 'LEFT JOIN', [ 'log_namespace=page_namespace', 'log_title=page_title' ] ]
-                       ] + $commentQuery['joins'] + $actorQuery['joins']
+                       $commentQuery['joins'] + $actorQuery['joins']
                );
 
                $field = $dbw->fieldInfo( 'recentchanges', 'rc_cur_id' );
@@ -328,8 +333,8 @@ class RebuildRecentchanges extends Maintenance {
                                        'rc_type' => RC_LOG,
                                        'rc_source' => RecentChange::SRC_LOG,
                                        'rc_cur_id' => $field->isNullable()
-                                               ? $row->page_id
-                                               : (int)$row->page_id, // NULL => 0,
+                                               ? $row->log_page
+                                               : (int)$row->log_page, // NULL => 0,
                                        'rc_log_type' => $row->log_type,
                                        'rc_log_action' => $row->log_action,
                                        'rc_logid' => $row->log_id,
@@ -348,6 +353,8 @@ class RebuildRecentchanges extends Maintenance {
 
        /**
         * Rebuild pass 4: Mark bot and autopatrolled entries.
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass4( ILBFactory $lbFactory ) {
                global $wgUseRCPatrol, $wgMiserMode;
@@ -360,7 +367,9 @@ class RebuildRecentchanges extends Maintenance {
                # @NOTE: users with 'bot' rights choose when edits are bot edits or not. That information
                # may be lost at this point (aside from joining on the patrol log table entries).
                $botgroups = [ 'bot' ];
-               $autopatrolgroups = $wgUseRCPatrol ? User::getGroupsWithPermission( 'autopatrol' ) : [];
+               $autopatrolgroups = $wgUseRCPatrol ? MediaWikiServices::getInstance()
+                       ->getPermissionManager()
+                       ->getGroupsWithPermission( 'autopatrol' ) : [];
 
                # Flag our recent bot edits
                if ( $botgroups ) {
@@ -373,12 +382,12 @@ class RebuildRecentchanges extends Maintenance {
                                [ 'ug_group' => $botgroups ],
                                __METHOD__,
                                [ 'DISTINCT' ],
-                               [ 'user_group' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
+                               [ 'user_groups' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
                        );
 
                        $botusers = [];
-                       foreach ( $res as $obj ) {
-                               $botusers[] = User::newFromRow( $obj );
+                       foreach ( $res as $row ) {
+                               $botusers[] = User::newFromRow( $row );
                        }
 
                        # Fill in the rc_bot field
@@ -426,11 +435,11 @@ class RebuildRecentchanges extends Maintenance {
                                [ 'ug_group' => $autopatrolgroups ],
                                __METHOD__,
                                [ 'DISTINCT' ],
-                               [ 'user_group' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
+                               [ 'user_groups' => [ 'JOIN', 'user_id = ug_user' ] ] + $userQuery['joins']
                        );
 
-                       foreach ( $res as $obj ) {
-                               $patrolusers[] = User::newFromRow( $obj );
+                       foreach ( $res as $row ) {
+                               $patrolusers[] = User::newFromRow( $row );
                        }
 
                        # Fill in the rc_patrolled field
@@ -454,8 +463,10 @@ class RebuildRecentchanges extends Maintenance {
        }
 
        /**
-        * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry
-        * for a single action (upload only, at the moment, but potentially also move, protect, ...).
+        * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log
+        * entry for a single action (upload only, at the moment, but potentially move, protect, ...).
+        *
+        * @param ILBFactory $lbFactory
         */
        private function rebuildRecentChangesTablePass5( ILBFactory $lbFactory ) {
                $dbw = wfGetDB( DB_MASTER );
@@ -476,9 +487,9 @@ class RebuildRecentchanges extends Maintenance {
                );
 
                $updates = 0;
-               foreach ( $res as $obj ) {
-                       $rev_id = $obj->ls_value;
-                       $log_id = $obj->ls_log_id;
+               foreach ( $res as $row ) {
+                       $rev_id = $row->ls_value;
+                       $log_id = $row->ls_log_id;
 
                        // Mark the logging row as having an associated rev id
                        $dbw->update(