X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=includes%2FWatchedItemQueryService.php;h=bc57049801fed421facfb695fed8540e680e9075;hb=11cf01dd9a8512ad4d9bded43cf22ebd38af8818;hp=dd23310356d9194288a054fbcd8019427259f56f;hpb=64df456b39647723f1aac44e4ba7db69e8404d0d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WatchedItemQueryService.php b/includes/WatchedItemQueryService.php index dd23310356..d0f45bec17 100644 --- a/includes/WatchedItemQueryService.php +++ b/includes/WatchedItemQueryService.php @@ -1,5 +1,6 @@ loadBalancer = $loadBalancer; } @@ -77,6 +82,13 @@ 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: @@ -171,13 +183,9 @@ class WatchedItemQueryService { ); } - $tables = [ 'recentchanges', 'watchlist' ]; - if ( !$options['allRevisions'] ) { - $tables[] = 'page'; - } - $db = $this->getConnection(); + $tables = $this->getWatchedItemsWithRCInfoQueryTables( $options ); $fields = $this->getWatchedItemsWithRCInfoQueryFields( $options ); $conds = $this->getWatchedItemsWithRCInfoQueryConds( $db, $user, $options ); $dbOptions = $this->getWatchedItemsWithRCInfoQueryDbOptions( $options ); @@ -312,13 +320,24 @@ class WatchedItemQueryService { $allFields = get_object_vars( $row ); $rcKeys = array_filter( array_keys( $allFields ), - function( $key ) { + function ( $key ) { return substr( $key, 0, 3 ) === 'rc_'; } ); return array_intersect_key( $allFields, array_flip( $rcKeys ) ); } + private function getWatchedItemsWithRCInfoQueryTables( array $options ) { + $tables = [ 'recentchanges', 'watchlist' ]; + if ( !$options['allRevisions'] ) { + $tables[] = 'page'; + } + if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) { + $tables += $this->getCommentStore()->getJoin()['tables']; + } + return $tables; + } + private function getWatchedItemsWithRCInfoQueryFields( array $options ) { $fields = [ 'rc_id', @@ -354,7 +373,7 @@ class WatchedItemQueryService { $fields[] = 'rc_user'; } if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) { - $fields[] = 'rc_comment'; + $fields += $this->getCommentStore()->getJoin()['fields']; } if ( in_array( self::INCLUDE_PATROL_INFO, $options['includeFields'] ) ) { $fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] ); @@ -389,7 +408,7 @@ class WatchedItemQueryService { } if ( array_key_exists( 'rcTypes', $options ) ) { - $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] ); + $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] ); } $conds = array_merge( @@ -402,7 +421,7 @@ class WatchedItemQueryService { if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) { if ( $db->getType() === 'mysql' ) { // This is an index optimization for mysql - $conds[] = "rc_timestamp > ''"; + $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' ); } } @@ -505,7 +524,7 @@ class WatchedItemQueryService { $conds[] = 'rc_user_text != ' . $db->addQuotes( $options['notByUser'] ); } - // Avoid brute force searches (bug 17342) + // Avoid brute force searches (T19342) $bitmask = 0; if ( !$user->isAllowed( 'deletedhistory' ) ) { $bitmask = Revision::DELETED_USER; @@ -564,7 +583,7 @@ class WatchedItemQueryService { } if ( isset( $options['filter'] ) ) { $filter = $options['filter']; - if ( $filter === self::FILTER_CHANGED ) { + if ( $filter === self::FILTER_CHANGED ) { $conds[] = 'wl_notificationtimestamp IS NOT NULL'; } else { $conds[] = 'wl_notificationtimestamp IS NULL'; @@ -656,6 +675,9 @@ class WatchedItemQueryService { if ( !$options['allRevisions'] ) { $joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ]; } + if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) { + $joinConds += $this->getCommentStore()->getJoin()['joins']; + } return $joinConds; }