Merge "SpecialWatchlist: Display 'wlnote' message even when showing "all" days"
[lhc/web/wiklou.git] / maintenance / rebuildrecentchanges.php
index 203d795..34560fd 100644 (file)
@@ -41,16 +41,16 @@ class RebuildRecentchanges extends Maintenance {
                $this->rebuildRecentChangesTablePass2();
                $this->rebuildRecentChangesTablePass3();
                $this->rebuildRecentChangesTablePass4();
+               $this->rebuildRecentChangesTablePass5();
                $this->purgeFeeds();
                $this->output( "Done.\n" );
        }
 
        /**
-        * Rebuild pass 1
-        * DOCUMENT ME!
+        * Rebuild pass 1: Insert `recentchanges` entries for page revisions.
         */
        private function rebuildRecentChangesTablePass1() {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
 
                $dbw->delete( 'recentchanges', '*' );
 
@@ -100,11 +100,11 @@ class RebuildRecentchanges extends Maintenance {
        }
 
        /**
-        * Rebuild pass 2
-        * DOCUMENT ME!
+        * 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).
         */
        private function rebuildRecentChangesTablePass2() {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
                list( $recentchanges, $revision ) = $dbw->tableNamesN( 'recentchanges', 'revision' );
 
                $this->output( "Updating links and size differences...\n" );
@@ -167,11 +167,10 @@ class RebuildRecentchanges extends Maintenance {
        }
 
        /**
-        * Rebuild pass 3
-        * DOCUMENT ME!
+        * Rebuild pass 3: Insert `recentchanges` entries for action logs.
         */
        private function rebuildRecentChangesTablePass3() {
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
 
                $this->output( "Loading from user, page, and logging tables...\n" );
 
@@ -179,13 +178,6 @@ class RebuildRecentchanges extends Maintenance {
                // Some logs don't go in RC. This should check for that
                $basicRCLogs = array_diff( $wgLogTypes, array_keys( $wgLogRestrictions ) );
 
-               // Escape...blah blah
-               $selectLogs = array();
-               foreach ( $basicRCLogs as $logtype ) {
-                       $safetype = $dbw->strencode( $logtype );
-                       $selectLogs[] = "'$safetype'";
-               }
-
                $cutoff = time() - $wgRCMaxAge;
                list( $logging, $page ) = $dbw->tableNamesN( 'logging', 'page' );
                $dbw->insertSelect(
@@ -219,7 +211,7 @@ class RebuildRecentchanges extends Maintenance {
                        array(
                                'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
                                'log_user=user_id',
-                               'log_type IN(' . implode( ',', $selectLogs ) . ')'
+                               'log_type' => $basicRCLogs,
                        ),
                        __METHOD__,
                        array(), // INSERT options
@@ -228,13 +220,12 @@ class RebuildRecentchanges extends Maintenance {
        }
 
        /**
-        * Rebuild pass 4
-        * DOCUMENT ME!
+        * Rebuild pass 4: Mark bot and autopatrolled entries.
         */
        private function rebuildRecentChangesTablePass4() {
                global $wgUseRCPatrol;
 
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
 
                list( $recentchanges, $usergroups, $user ) =
                        $dbw->tableNamesN( 'recentchanges', 'user_groups', 'user' );
@@ -291,6 +282,46 @@ 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, ...).
+        */
+       private function rebuildRecentChangesTablePass5() {
+               $dbw = wfGetDB( DB_MASTER );
+
+               $this->output( "Removing duplicate revision and logging entries...\n" );
+
+               $res = $dbw->select(
+                       array( 'logging', 'log_search' ),
+                       array( 'ls_value', 'ls_log_id' ),
+                       array(
+                               'ls_log_id = log_id',
+                               'ls_field' => 'associated_rev_id',
+                               'log_type' => 'upload',
+                       ),
+                       __METHOD__
+               );
+               foreach ( $res as $obj ) {
+                       $rev_id = $obj->ls_value;
+                       $log_id = $obj->ls_log_id;
+
+                       // Mark the logging row as having an associated rev id
+                       $dbw->update(
+                               'recentchanges',
+                               /*SET*/ array( 'rc_this_oldid' => $rev_id ),
+                               /*WHERE*/ array( 'rc_logid' => $log_id ),
+                               __METHOD__
+                       );
+
+                       // Delete the revision row
+                       $dbw->delete(
+                               'recentchanges',
+                               /*WHERE*/ array( 'rc_this_oldid' => $rev_id, 'rc_logid' => 0 ),
+                               __METHOD__
+                       );
+               }
+       }
+
        /**
         * Purge cached feeds in $messageMemc
         */