Merge "Enable users to watch category membership changes #2"
[lhc/web/wiklou.git] / includes / changes / EnhancedChangesList.php
index 1dcb7ae..b59437e 100644 (file)
@@ -83,15 +83,16 @@ class EnhancedChangesList extends ChangesList {
        /**
         * Format a line for enhanced recentchange (aka with javascript and block of lines).
         *
-        * @param RecentChange $baseRC
+        * @param RecentChange $rc
         * @param bool $watched
+        * @param int $linenumber (default null)
         *
         * @return string
         */
-       public function recentChangesLine( &$baseRC, $watched = false ) {
+       public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
 
                $date = $this->getLanguage()->userDate(
-                       $baseRC->mAttribs['rc_timestamp'],
+                       $rc->mAttribs['rc_timestamp'],
                        $this->getUser()
                );
 
@@ -106,7 +107,7 @@ class EnhancedChangesList extends ChangesList {
                        $this->lastdate = $date;
                }
 
-               $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $baseRC, $watched );
+               $cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $rc, $watched );
                $this->addCacheEntry( $cacheEntry );
 
                return $ret;
@@ -405,6 +406,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;
@@ -497,7 +500,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 ) {
@@ -529,7 +532,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'];
@@ -605,15 +608,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> ';
 
@@ -628,10 +625,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 );
                }
 
@@ -672,6 +674,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