X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fwatcheditem%2FWatchedItemQueryService.php;h=b91e36e5f18c74d4ef5864cd674a8b267ec80106;hb=6bc0e36d8b33b6d0602b912fba75938368e09406;hp=abe9b89fb2a2a001d5cd5b275c28a884d098f25c;hpb=b610a3b617f7616b2f1db12498cbad5aeae12576;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/watcheditem/WatchedItemQueryService.php b/includes/watcheditem/WatchedItemQueryService.php index abe9b89fb2..b91e36e5f1 100644 --- a/includes/watcheditem/WatchedItemQueryService.php +++ b/includes/watcheditem/WatchedItemQueryService.php @@ -25,6 +25,7 @@ class WatchedItemQueryService { const INCLUDE_USER_ID = 'userid'; const INCLUDE_COMMENT = 'comment'; const INCLUDE_PATROL_INFO = 'patrol'; + const INCLUDE_AUTOPATROL_INFO = 'autopatrol'; const INCLUDE_SIZES = 'sizes'; const INCLUDE_LOG_INFO = 'loginfo'; const INCLUDE_TAGS = 'tags'; @@ -40,6 +41,8 @@ class WatchedItemQueryService { const FILTER_NOT_ANON = '!anon'; const FILTER_PATROLLED = 'patrolled'; const FILTER_NOT_PATROLLED = '!patrolled'; + const FILTER_AUTOPATROLLED = 'autopatrolled'; + const FILTER_NOT_AUTOPATROLLED = '!autopatrolled'; const FILTER_UNREAD = 'unread'; const FILTER_NOT_UNREAD = '!unread'; const FILTER_CHANGED = 'changed'; @@ -59,12 +62,17 @@ class WatchedItemQueryService { /** @var CommentStore */ private $commentStore; + /** @var ActorMigration */ + private $actorMigration; + public function __construct( LoadBalancer $loadBalancer, - CommentStore $commentStore + CommentStore $commentStore, + ActorMigration $actorMigration ) { $this->loadBalancer = $loadBalancer; $this->commentStore = $commentStore; + $this->actorMigration = $actorMigration; } /** @@ -312,8 +320,8 @@ class WatchedItemQueryService { } private function getRecentChangeFieldsFromRow( stdClass $row ) { - // This can be simplified to single array_filter call filtering by key value, - // once we stop supporting PHP 5.5 + // FIXME: This can be simplified to single array_filter call filtering by key value, + // now we have stopped supporting PHP 5.5 $allFields = get_object_vars( $row ); $rcKeys = array_filter( array_keys( $allFields ), @@ -335,6 +343,14 @@ class WatchedItemQueryService { if ( in_array( self::INCLUDE_TAGS, $options['includeFields'] ) ) { $tables[] = 'tag_summary'; } + if ( in_array( self::INCLUDE_USER, $options['includeFields'] ) || + in_array( self::INCLUDE_USER_ID, $options['includeFields'] ) || + in_array( self::FILTER_ANON, $options['filters'] ) || + in_array( self::FILTER_NOT_ANON, $options['filters'] ) || + array_key_exists( 'onlyByUser', $options ) || array_key_exists( 'notByUser', $options ) + ) { + $tables += $this->actorMigration->getJoin( 'rc_user' )['tables']; + } return $tables; } @@ -367,10 +383,10 @@ class WatchedItemQueryService { $fields = array_merge( $fields, [ 'rc_type', 'rc_minor', 'rc_bot' ] ); } if ( in_array( self::INCLUDE_USER, $options['includeFields'] ) ) { - $fields[] = 'rc_user_text'; + $fields['rc_user_text'] = $this->actorMigration->getJoin( 'rc_user' )['fields']['rc_user_text']; } if ( in_array( self::INCLUDE_USER_ID, $options['includeFields'] ) ) { - $fields[] = 'rc_user'; + $fields['rc_user'] = $this->actorMigration->getJoin( 'rc_user' )['fields']['rc_user']; } if ( in_array( self::INCLUDE_COMMENT, $options['includeFields'] ) ) { $fields += $this->commentStore->getJoin( 'rc_comment' )['fields']; @@ -469,18 +485,28 @@ class WatchedItemQueryService { } if ( in_array( self::FILTER_ANON, $options['filters'] ) ) { - $conds[] = 'rc_user = 0'; + $conds[] = $this->actorMigration->isAnon( + $this->actorMigration->getJoin( 'rc_user' )['fields']['rc_user'] + ); } elseif ( in_array( self::FILTER_NOT_ANON, $options['filters'] ) ) { - $conds[] = 'rc_user != 0'; + $conds[] = $this->actorMigration->isNotAnon( + $this->actorMigration->getJoin( 'rc_user' )['fields']['rc_user'] + ); } if ( $user->useRCPatrol() || $user->useNPPatrol() ) { // TODO: not sure if this should simply ignore patrolled filters if user does not have the patrol // right, or maybe rather fail loud at this point, same as e.g. ApiQueryWatchlist does? if ( in_array( self::FILTER_PATROLLED, $options['filters'] ) ) { - $conds[] = 'rc_patrolled != 0'; + $conds[] = 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED; } elseif ( in_array( self::FILTER_NOT_PATROLLED, $options['filters'] ) ) { - $conds[] = 'rc_patrolled = 0'; + $conds['rc_patrolled'] = RecentChange::PRC_UNPATROLLED; + } + + if ( in_array( self::FILTER_AUTOPATROLLED, $options['filters'] ) ) { + $conds['rc_patrolled'] = RecentChange::PRC_AUTOPATROLLED; + } elseif ( in_array( self::FILTER_NOT_AUTOPATROLLED, $options['filters'] ) ) { + $conds[] = 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED; } } @@ -523,9 +549,11 @@ class WatchedItemQueryService { $conds = []; if ( array_key_exists( 'onlyByUser', $options ) ) { - $conds['rc_user_text'] = $options['onlyByUser']; + $byUser = User::newFromName( $options['onlyByUser'], false ); + $conds[] = $this->actorMigration->getWhere( $db, 'rc_user', $byUser )['conds']; } elseif ( array_key_exists( 'notByUser', $options ) ) { - $conds[] = 'rc_user_text != ' . $db->addQuotes( $options['notByUser'] ); + $byUser = User::newFromName( $options['notByUser'], false ); + $conds[] = 'NOT(' . $this->actorMigration->getWhere( $db, 'rc_user', $byUser )['conds'] . ')'; } // Avoid brute force searches (T19342) @@ -685,6 +713,14 @@ class WatchedItemQueryService { if ( in_array( self::INCLUDE_TAGS, $options['includeFields'] ) ) { $joinConds['tag_summary'] = [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ]; } + if ( in_array( self::INCLUDE_USER, $options['includeFields'] ) || + in_array( self::INCLUDE_USER_ID, $options['includeFields'] ) || + in_array( self::FILTER_ANON, $options['filters'] ) || + in_array( self::FILTER_NOT_ANON, $options['filters'] ) || + array_key_exists( 'onlyByUser', $options ) || array_key_exists( 'notByUser', $options ) + ) { + $joinConds += $this->actorMigration->getJoin( 'rc_user' )['joins']; + } return $joinConds; }