Merge "Allow patrol of uploads"
[lhc/web/wiklou.git] / includes / changes / ChangesList.php
index fdc9944..1741e64 100644 (file)
@@ -36,8 +36,8 @@ class ChangesList extends ContextSource {
        protected $rclistOpen;
        protected $rcMoveIndex;
 
-       /** @var MapCacheLRU */
-       protected $watchingCache;
+       /** @var BagOStuff */
+       protected $watchMsgCache;
 
        /**
         * Changeslist constructor
@@ -53,7 +53,7 @@ class ChangesList extends ContextSource {
                        $this->skin = $obj;
                }
                $this->preCacheMessages();
-               $this->watchingCache = new MapCacheLRU( 50 );
+               $this->watchMsgCache = new HashBagOStuff( array( 'maxKeys' => 50 ) );
        }
 
        /**
@@ -76,6 +76,21 @@ class ChangesList extends ContextSource {
                }
        }
 
+       /**
+        * Format a line
+        *
+        * @since 1.27
+        *
+        * @param RecentChange $rc Passed by reference
+        * @param bool $watched (default false)
+        * @param int $linenumber (default null)
+        *
+        * @return string|bool
+        */
+       public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
+               throw new RuntimeException( 'recentChangesLine should be implemented' );
+       }
+
        /**
         * Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag
         * @param bool $value
@@ -305,7 +320,11 @@ class ChangesList extends ContextSource {
         */
        public function insertDiffHist( &$s, &$rc, $unpatrolled ) {
                # Diff link
-               if ( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
+               if (
+                       $rc->mAttribs['rc_type'] == RC_NEW ||
+                       $rc->mAttribs['rc_type'] == RC_LOG ||
+                       $rc->mAttribs['rc_type'] == RC_CATEGORIZE
+               ) {
                        $diffLink = $this->message['diff'];
                } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
                        $diffLink = $this->message['diff'];
@@ -323,29 +342,46 @@ class ChangesList extends ContextSource {
                                $query
                        );
                }
-               $diffhist = $diffLink . $this->message['pipe-separator'];
-               # History link
-               $diffhist .= Linker::linkKnown(
-                       $rc->getTitle(),
-                       $this->message['hist'],
-                       array(),
-                       array(
-                               'curid' => $rc->mAttribs['rc_cur_id'],
-                               'action' => 'history'
-                       )
-               );
+               if ( $rc->mAttribs['rc_type'] == RC_CATEGORIZE ) {
+                       $diffhist = $diffLink . $this->message['pipe-separator'] . $this->message['hist'];
+               } else {
+                       $diffhist = $diffLink . $this->message['pipe-separator'];
+                       # History link
+                       $diffhist .= Linker::linkKnown(
+                               $rc->getTitle(),
+                               $this->message['hist'],
+                               array(),
+                               array(
+                                       'curid' => $rc->mAttribs['rc_cur_id'],
+                                       'action' => 'history'
+                               )
+                       );
+               }
+
                // @todo FIXME: Hard coded ". .". Is there a message for this? Should there be?
                $s .= $this->msg( 'parentheses' )->rawParams( $diffhist )->escaped() .
                        ' <span class="mw-changeslist-separator">. .</span> ';
        }
 
        /**
-        * @param string $s HTML to update
+        * @param string $s Article link will be appended to this string, in place.
         * @param RecentChange $rc
         * @param bool $unpatrolled
         * @param bool $watched
+        * @deprecated since 1.27, use getArticleLink instead.
         */
-       public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
+       public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, $watched ) {
+               $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
+       }
+
+       /**
+        * @param RecentChange $rc
+        * @param bool $unpatrolled
+        * @param bool $watched
+        * @return string HTML
+        * @since 1.26
+        */
+       public function getArticleLink( &$rc, $unpatrolled, $watched ) {
                $params = array();
                if ( $rc->getTitle()->isRedirect() ) {
                        $params = array( 'redirect' => 'no' );
@@ -365,23 +401,12 @@ class ChangesList extends ContextSource {
                # RTL/LTR marker
                $articlelink .= $this->getLanguage()->getDirMark();
 
+               # TODO: Deprecate the $s argument, it seems happily unused.
+               $s = '';
                Hooks::run( 'ChangesListInsertArticleLink',
                        array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
 
-               $s .= " $articlelink";
-       }
-
-       /**
-        * @param RecentChange $rc
-        * @param bool $unpatrolled
-        * @param bool $watched
-        * @return string
-        * @since 1.26
-        */
-       public function getArticleLink( RecentChange $rc, $unpatrolled, $watched ) {
-               $s = '';
-               $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
-               return $s;
+               return "{$s} {$articlelink}";
        }
 
        /**
@@ -456,37 +481,23 @@ class ChangesList extends ContextSource {
                }
        }
 
-       /**
-        * Check whether to enable recent changes patrol features
-        *
-        * @deprecated since 1.22
-        * @return bool
-        */
-       public static function usePatrol() {
-               global $wgUser;
-
-               wfDeprecated( __METHOD__, '1.22' );
-
-               return $wgUser->useRCPatrol();
-       }
-
        /**
         * Returns the string which indicates the number of watching users
         * @param int $count Number of user watching a page
         * @return string
         */
        protected function numberofWatchingusers( $count ) {
-               $cache = $this->watchingCache;
-               if ( $count > 0 ) {
-                       if ( !$cache->has( $count ) ) {
-                               $cache->set( $count, $this->msg( 'number_of_watching_users_RCview' )
-                                       ->numParams( $count )->escaped() );
-                       }
-
-                       return $cache->get( $count );
-               } else {
+               if ( $count <= 0 ) {
                        return '';
                }
+               $cache = $this->watchMsgCache;
+               $that = $this;
+               return $cache->getWithSetCallback( $count, $cache::TTL_INDEFINITE,
+                       function () use ( $that, $count ) {
+                               return $that->msg( 'number_of_watching_users_RCview' )
+                                       ->numParams( $count )->escaped();
+                       }
+               );
        }
 
        /**
@@ -614,9 +625,11 @@ class ChangesList extends ContextSource {
                if ( $rc instanceof RecentChange ) {
                        $isPatrolled = $rc->mAttribs['rc_patrolled'];
                        $rcType = $rc->mAttribs['rc_type'];
+                       $rcLogType = $rc->mAttribs['rc_log_type'];
                } else {
                        $isPatrolled = $rc->rc_patrolled;
                        $rcType = $rc->rc_type;
+                       $rcLogType = $rc->rc_log_type;
                }
 
                if ( !$isPatrolled ) {
@@ -626,8 +639,26 @@ class ChangesList extends ContextSource {
                        if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
                                return true;
                        }
+                       if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
+                               return true;
+                       }
                }
 
                return false;
        }
+
+       /**
+        * Determines whether a revision is linked to this change; this may not be the case
+        * when the categorization wasn't done by an edit but a conditional parser function
+        *
+        * @since 1.27
+        *
+        * @param RecentChange|RCCacheEntry $rcObj
+        * @return bool
+        */
+       protected function isCategorizationWithoutRevision( $rcObj ) {
+               return intval( $rcObj->getAttribute( 'rc_type' ) ) === RC_CATEGORIZE
+                       && intval( $rcObj->getAttribute( 'rc_this_oldid' ) ) === 0;
+       }
+
 }