DI for CommentStore in WatchedItemQueryService
[lhc/web/wiklou.git] / includes / watcheditem / WatchedItemQueryService.php
index d0f45be..abe9b89 100644 (file)
@@ -27,6 +27,7 @@ class WatchedItemQueryService {
        const INCLUDE_PATROL_INFO = 'patrol';
        const INCLUDE_SIZES = 'sizes';
        const INCLUDE_LOG_INFO = 'loginfo';
+       const INCLUDE_TAGS = 'tags';
 
        // FILTER_* constants are part of public API (are used in ApiQueryWatchlist and
        // ApiQueryWatchlistRaw classes) and should not be changed.
@@ -55,12 +56,15 @@ class WatchedItemQueryService {
        /** @var WatchedItemQueryServiceExtension[]|null */
        private $extensions = null;
 
-       /**
-        * @var CommentStore|null */
-       private $commentStore = null;
+       /** @var CommentStore */
+       private $commentStore;
 
-       public function __construct( LoadBalancer $loadBalancer ) {
+       public function __construct(
+               LoadBalancer $loadBalancer,
+               CommentStore $commentStore
+       ) {
                $this->loadBalancer = $loadBalancer;
+               $this->commentStore = $commentStore;
        }
 
        /**
@@ -82,13 +86,6 @@ class WatchedItemQueryService {
                return $this->loadBalancer->getConnectionRef( DB_REPLICA, [ 'watchlist' ] );
        }
 
-       private function getCommentStore() {
-               if ( !$this->commentStore ) {
-                       $this->commentStore = new CommentStore( 'rc_comment' );
-               }
-               return $this->commentStore;
-       }
-
        /**
         * @param User $user
         * @param array $options Allowed keys:
@@ -333,7 +330,10 @@ class WatchedItemQueryService {
                        $tables[] = 'page';
                }
                if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) {
-                       $tables += $this->getCommentStore()->getJoin()['tables'];
+                       $tables += $this->commentStore->getJoin( 'rc_comment' )['tables'];
+               }
+               if ( in_array( self::INCLUDE_TAGS, $options['includeFields'] ) ) {
+                       $tables[] = 'tag_summary';
                }
                return $tables;
        }
@@ -373,7 +373,7 @@ class WatchedItemQueryService {
                        $fields[] = 'rc_user';
                }
                if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) {
-                       $fields += $this->getCommentStore()->getJoin()['fields'];
+                       $fields += $this->commentStore->getJoin( 'rc_comment' )['fields'];
                }
                if ( in_array( self::INCLUDE_PATROL_INFO, $options['includeFields'] ) ) {
                        $fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] );
@@ -384,6 +384,10 @@ class WatchedItemQueryService {
                if ( in_array( self::INCLUDE_LOG_INFO, $options['includeFields'] ) ) {
                        $fields = array_merge( $fields, [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ] );
                }
+               if ( in_array( self::INCLUDE_TAGS, $options['includeFields'] ) ) {
+                       // prefixed with rc_ to include the field in getRecentChangeFieldsFromRow
+                       $fields['rc_tags'] = 'ts_tags';
+               }
 
                return $fields;
        }
@@ -676,7 +680,10 @@ class WatchedItemQueryService {
                        $joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
                }
                if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) {
-                       $joinConds += $this->getCommentStore()->getJoin()['joins'];
+                       $joinConds += $this->commentStore->getJoin( 'rc_comment' )['joins'];
+               }
+               if ( in_array( self::INCLUDE_TAGS, $options['includeFields'] ) ) {
+                       $joinConds['tag_summary'] = [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ];
                }
                return $joinConds;
        }