Clean up recentChangesFlags rollups
[lhc/web/wiklou.git] / includes / changes / EnhancedChangesList.php
index f10307d..ed374b0 100644 (file)
@@ -178,18 +178,24 @@ class EnhancedChangesList extends ChangesList {
                # Collate list of users
                $userlinks = array();
                # Other properties
-               $unpatrolled = false;
-               $isnew = false;
-               $allBots = true;
-               $allMinors = true;
                $curId = 0;
                # Some catalyst variables...
                $namehidden = true;
                $allLogs = true;
                $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
+               $collectedRcFlags = array(
+                       // All are by bots?
+                       'bot' => true,
+                       // Includes a new page?
+                       'newpage' => false,
+                       // All are minor edits?
+                       'minor' => true,
+                       // Contains an unpatrolled edit?
+                       'unpatrolled' => false,
+               );
                foreach ( $block as $rcObj ) {
                        if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
-                               $isnew = true;
+                               $collectedRcFlags['newpage'] = true;
                        }
                        // If all log actions to this page were hidden, then don't
                        // give the name of the affected page for this block!
@@ -201,7 +207,7 @@ class EnhancedChangesList extends ChangesList {
                                $userlinks[$u] = 0;
                        }
                        if ( $rcObj->unpatrolled ) {
-                               $unpatrolled = true;
+                               $collectedRcFlags['unpatrolled'] = true;
                        }
                        if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
                                $allLogs = false;
@@ -213,10 +219,10 @@ class EnhancedChangesList extends ChangesList {
                        }
 
                        if ( !$rcObj->mAttribs['rc_bot'] ) {
-                               $allBots = false;
+                               $collectedRcFlags['bot'] = false;
                        }
                        if ( !$rcObj->mAttribs['rc_minor'] ) {
-                               $allMinors = false;
+                               $collectedRcFlags['minor'] = false;
                        }
 
                        $userlinks[$u]++;
@@ -247,12 +253,9 @@ class EnhancedChangesList extends ChangesList {
                $r .= "<td>$tl</td>";
 
                # Main line
-               $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags( array(
-                       'newpage' => $isnew, # show, when one have this flag
-                       'minor' => $allMinors, # show only, when all have this flag
-                       'unpatrolled' => $unpatrolled, # show, when one have this flag
-                       'bot' => $allBots, # show only, when all have this flag
-               ) );
+               $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags(
+                       $collectedRcFlags
+               );
 
                # Timestamp
                $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
@@ -289,7 +292,8 @@ class EnhancedChangesList extends ChangesList {
                        return '';
                }
 
-               $r .= $this->getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden );
+               $r .= $this->getLogText( $block, $queryParams, $allLogs,
+                       $collectedRcFlags['newpage'], $namehidden );
 
                $r .= ' <span class="mw-changeslist-separator">. .</span> ';
 
@@ -406,6 +410,8 @@ class EnhancedChangesList extends ChangesList {
 
                if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
                        $data['logEntry'] = $this->insertLogEntry( $rcObj );
+               } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
+                       $data['comment'] = $this->insertComment( $rcObj );
                } else {
                        # User links
                        $data['userLink'] = $rcObj->userlink;
@@ -498,7 +504,7 @@ class EnhancedChangesList extends ChangesList {
                /** @var $block0 RecentChange */
                $block0 = $block[0];
                $last = $block[count( $block ) - 1];
-               if ( !$allLogs ) {
+               if ( !$allLogs && $rcObj->mAttribs['rc_type'] != RC_CATEGORIZE ) {
                        if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
                                $links['total-changes'] = $nchanges[$n];
                        } elseif ( $isnew ) {
@@ -530,7 +536,7 @@ class EnhancedChangesList extends ChangesList {
                }
 
                # History
-               if ( $allLogs ) {
+               if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
                        // don't show history link for logs
                } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
                        $links['history'] = $this->message['enhancedrc-history'];
@@ -606,15 +612,9 @@ class EnhancedChangesList extends ChangesList {
                }
 
                # Diff and hist links
-               if ( $type != RC_LOG ) {
+               if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
                        $query['action'] = 'history';
-                       $data['historyLink'] = ' ' . $this->msg( 'parentheses' )
-                               ->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
-                                       $rcObj->getTitle(),
-                                       $this->message['hist'],
-                                       array(),
-                                       $query
-                               ) )->escaped();
+                       $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
                }
                $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
 
@@ -629,10 +629,15 @@ class EnhancedChangesList extends ChangesList {
 
                if ( $type == RC_LOG ) {
                        $data['logEntry'] = $this->insertLogEntry( $rcObj );
+               } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) {
+                       $data['comment'] = $this->insertComment( $rcObj );
                } else {
                        $data['userLink'] = $rcObj->userlink;
                        $data['userTalkLink'] = $rcObj->usertalklink;
                        $data['comment'] = $this->insertComment( $rcObj );
+                       if ( $type == RC_CATEGORIZE ) {
+                               $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
+                       }
                        $data['rollback'] = $this->getRollback( $rcObj );
                }
 
@@ -673,6 +678,33 @@ class EnhancedChangesList extends ChangesList {
                return $line;
        }
 
+       /**
+        * Returns value to be used in 'historyLink' element of $data param in
+        * EnhancedChangesListModifyBlockLineData hook.
+        *
+        * @since 1.27
+        *
+        * @param RCCacheEntry $rc
+        * @param array $query array of key/value pairs to append as a query string
+        * @return string HTML
+        */
+       public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
+               $pageTitle = $rc->getTitle();
+               if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
+                       // For categorizations we must swap the category title with the page title!
+                       $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
+               }
+
+               $retVal = ' ' . $this->msg( 'parentheses' )
+                               ->rawParams( $rc->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
+                                               $pageTitle,
+                                               $this->message['hist'],
+                                               array(),
+                                               $query
+                                       ) )->escaped();
+               return $retVal;
+       }
+
        /**
         * If enhanced RC is in use, this function takes the previously cached
         * RC lines, arranges them, and outputs the HTML