3 use Wikimedia\Rdbms\IDatabase
;
4 use MediaWiki\Linker\LinkTarget
;
5 use Wikimedia\Assert\Assert
;
6 use Wikimedia\Rdbms\LoadBalancer
;
9 * Class performing complex database queries related to WatchedItems.
16 * @license GNU GPL v2+
18 class WatchedItemQueryService
{
20 const DIR_OLDER
= 'older';
21 const DIR_NEWER
= 'newer';
23 const INCLUDE_FLAGS
= 'flags';
24 const INCLUDE_USER
= 'user';
25 const INCLUDE_USER_ID
= 'userid';
26 const INCLUDE_COMMENT
= 'comment';
27 const INCLUDE_PATROL_INFO
= 'patrol';
28 const INCLUDE_AUTOPATROL_INFO
= 'autopatrol';
29 const INCLUDE_SIZES
= 'sizes';
30 const INCLUDE_LOG_INFO
= 'loginfo';
31 const INCLUDE_TAGS
= 'tags';
33 // FILTER_* constants are part of public API (are used in ApiQueryWatchlist and
34 // ApiQueryWatchlistRaw classes) and should not be changed.
35 // Changing values of those constants will result in a breaking change in the API
36 const FILTER_MINOR
= 'minor';
37 const FILTER_NOT_MINOR
= '!minor';
38 const FILTER_BOT
= 'bot';
39 const FILTER_NOT_BOT
= '!bot';
40 const FILTER_ANON
= 'anon';
41 const FILTER_NOT_ANON
= '!anon';
42 const FILTER_PATROLLED
= 'patrolled';
43 const FILTER_NOT_PATROLLED
= '!patrolled';
44 const FILTER_AUTOPATROLLED
= 'autopatrolled';
45 const FILTER_NOT_AUTOPATROLLED
= '!autopatrolled';
46 const FILTER_UNREAD
= 'unread';
47 const FILTER_NOT_UNREAD
= '!unread';
48 const FILTER_CHANGED
= 'changed';
49 const FILTER_NOT_CHANGED
= '!changed';
51 const SORT_ASC
= 'ASC';
52 const SORT_DESC
= 'DESC';
57 private $loadBalancer;
59 /** @var WatchedItemQueryServiceExtension[]|null */
60 private $extensions = null;
62 /** @var CommentStore */
63 private $commentStore;
65 /** @var ActorMigration */
66 private $actorMigration;
68 public function __construct(
69 LoadBalancer
$loadBalancer,
70 CommentStore
$commentStore,
71 ActorMigration
$actorMigration
73 $this->loadBalancer
= $loadBalancer;
74 $this->commentStore
= $commentStore;
75 $this->actorMigration
= $actorMigration;
79 * @return WatchedItemQueryServiceExtension[]
81 private function getExtensions() {
82 if ( $this->extensions
=== null ) {
83 $this->extensions
= [];
84 Hooks
::run( 'WatchedItemQueryServiceExtensions', [ &$this->extensions
, $this ] );
86 return $this->extensions
;
93 private function getConnection() {
94 return $this->loadBalancer
->getConnectionRef( DB_REPLICA
, [ 'watchlist' ] );
99 * @param array $options Allowed keys:
100 * 'includeFields' => string[] RecentChange fields to be included in the result,
101 * self::INCLUDE_* constants should be used
102 * 'filters' => string[] optional filters to narrow down resulted items
103 * 'namespaceIds' => int[] optional namespace IDs to filter by
104 * (defaults to all namespaces)
105 * 'allRevisions' => bool return multiple revisions of the same page if true,
106 * only the most recent if false (default)
107 * 'rcTypes' => int[] which types of RecentChanges to include
108 * (defaults to all types), allowed values: RC_EDIT, RC_NEW,
109 * RC_LOG, RC_EXTERNAL, RC_CATEGORIZE
110 * 'onlyByUser' => string only list changes by a specified user
111 * 'notByUser' => string do not incluide changes by a specified user
112 * 'dir' => string in which direction to enumerate, accepted values:
113 * - DIR_OLDER list newest first
114 * - DIR_NEWER list oldest first
115 * 'start' => string (format accepted by wfTimestamp) requires 'dir' option,
116 * timestamp to start enumerating from
117 * 'end' => string (format accepted by wfTimestamp) requires 'dir' option,
118 * timestamp to end enumerating
119 * 'watchlistOwner' => User user whose watchlist items should be listed if different
120 * than the one specified with $user param,
121 * requires 'watchlistOwnerToken' option
122 * 'watchlistOwnerToken' => string a watchlist token used to access another user's
123 * watchlist, used with 'watchlistOwnerToken' option
124 * 'limit' => int maximum numbers of items to return
125 * 'usedInGenerator' => bool include only RecentChange id field required by the
126 * generator ('rc_cur_id' or 'rc_this_oldid') if true, or all
127 * id fields ('rc_cur_id', 'rc_this_oldid', 'rc_last_oldid')
129 * @param array|null &$startFrom Continuation value: [ string $rcTimestamp, int $rcId ]
130 * @return array of pairs ( WatchedItem $watchedItem, string[] $recentChangeInfo ),
131 * where $recentChangeInfo contains the following keys:
138 * Additional keys could be added by specifying the 'includeFields' option
140 public function getWatchedItemsWithRecentChangeInfo(
141 User
$user, array $options = [], &$startFrom = null
144 'includeFields' => [],
145 'namespaceIds' => [],
147 'allRevisions' => false,
148 'usedInGenerator' => false
152 !isset( $options['rcTypes'] )
153 ||
!array_diff( $options['rcTypes'], [ RC_EDIT
, RC_NEW
, RC_LOG
, RC_EXTERNAL
, RC_CATEGORIZE
] ),
154 '$options[\'rcTypes\']',
155 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
158 !isset( $options['dir'] ) ||
in_array( $options['dir'], [ self
::DIR_OLDER
, self
::DIR_NEWER
] ),
160 'must be DIR_OLDER or DIR_NEWER'
163 !isset( $options['start'] ) && !isset( $options['end'] ) && $startFrom === null
164 ||
isset( $options['dir'] ),
166 'must be provided when providing the "start" or "end" options or the $startFrom parameter'
169 !isset( $options['startFrom'] ),
170 '$options[\'startFrom\']',
171 'must not be provided, use $startFrom instead'
174 !isset( $startFrom ) ||
( is_array( $startFrom ) && count( $startFrom ) === 2 ),
176 'must be a two-element array'
178 if ( array_key_exists( 'watchlistOwner', $options ) ) {
179 Assert
::parameterType(
181 $options['watchlistOwner'],
182 '$options[\'watchlistOwner\']'
185 isset( $options['watchlistOwnerToken'] ),
186 '$options[\'watchlistOwnerToken\']',
187 'must be provided when providing watchlistOwner option'
191 $db = $this->getConnection();
193 $tables = $this->getWatchedItemsWithRCInfoQueryTables( $options );
194 $fields = $this->getWatchedItemsWithRCInfoQueryFields( $options );
195 $conds = $this->getWatchedItemsWithRCInfoQueryConds( $db, $user, $options );
196 $dbOptions = $this->getWatchedItemsWithRCInfoQueryDbOptions( $options );
197 $joinConds = $this->getWatchedItemsWithRCInfoQueryJoinConds( $options );
199 if ( $startFrom !== null ) {
200 $conds[] = $this->getStartFromConds( $db, $options, $startFrom );
203 foreach ( $this->getExtensions() as $extension ) {
204 $extension->modifyWatchedItemsWithRCInfoQuery(
205 $user, $options, $db,
223 $limit = isset( $dbOptions['LIMIT'] ) ?
$dbOptions['LIMIT'] : INF
;
226 foreach ( $res as $row ) {
227 if ( --$limit <= 0 ) {
228 $startFrom = [ $row->rc_timestamp
, $row->rc_id
];
235 new TitleValue( (int)$row->rc_namespace
, $row->rc_title
),
236 $row->wl_notificationtimestamp
238 $this->getRecentChangeFieldsFromRow( $row )
242 foreach ( $this->getExtensions() as $extension ) {
243 $extension->modifyWatchedItemsWithRCInfo( $user, $options, $db, $items, $res, $startFrom );
250 * For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser
253 * @param array $options Allowed keys:
254 * 'sort' => string optional sorting by namespace ID and title
255 * one of the self::SORT_* constants
256 * 'namespaceIds' => int[] optional namespace IDs to filter by (defaults to all namespaces)
257 * 'limit' => int maximum number of items to return
258 * 'filter' => string optional filter, one of the self::FILTER_* contants
259 * 'from' => LinkTarget requires 'sort' key, only return items starting from
260 * those related to the link target
261 * 'until' => LinkTarget requires 'sort' key, only return items until
262 * those related to the link target
263 * 'startFrom' => LinkTarget requires 'sort' key, only return items starting from
264 * those related to the link target, allows to skip some link targets
265 * specified using the form option
266 * @return WatchedItem[]
268 public function getWatchedItemsForUser( User
$user, array $options = [] ) {
269 if ( $user->isAnon() ) {
270 // TODO: should this just return an empty array or rather complain loud at this point
271 // as e.g. ApiBase::getWatchlistUser does?
275 $options +
= [ 'namespaceIds' => [] ];
278 !isset( $options['sort'] ) ||
in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ),
279 '$options[\'sort\']',
280 'must be SORT_ASC or SORT_DESC'
283 !isset( $options['filter'] ) ||
in_array(
284 $options['filter'], [ self
::FILTER_CHANGED
, self
::FILTER_NOT_CHANGED
]
286 '$options[\'filter\']',
287 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
290 !isset( $options['from'] ) && !isset( $options['until'] ) && !isset( $options['startFrom'] )
291 ||
isset( $options['sort'] ),
292 '$options[\'sort\']',
293 'must be provided if any of "from", "until", "startFrom" options is provided'
296 $db = $this->getConnection();
298 $conds = $this->getWatchedItemsForUserQueryConds( $db, $user, $options );
299 $dbOptions = $this->getWatchedItemsForUserQueryDbOptions( $options );
303 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
310 foreach ( $res as $row ) {
311 // todo these could all be cached at some point?
312 $watchedItems[] = new WatchedItem(
314 new TitleValue( (int)$row->wl_namespace
, $row->wl_title
),
315 $row->wl_notificationtimestamp
319 return $watchedItems;
322 private function getRecentChangeFieldsFromRow( stdClass
$row ) {
323 // FIXME: This can be simplified to single array_filter call filtering by key value,
324 // now we have stopped supporting PHP 5.5
325 $allFields = get_object_vars( $row );
326 $rcKeys = array_filter(
327 array_keys( $allFields ),
329 return substr( $key, 0, 3 ) === 'rc_';
332 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
335 private function getWatchedItemsWithRCInfoQueryTables( array $options ) {
336 $tables = [ 'recentchanges', 'watchlist' ];
337 if ( !$options['allRevisions'] ) {
340 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
341 $tables +
= $this->commentStore
->getJoin( 'rc_comment' )['tables'];
343 if ( in_array( self
::INCLUDE_TAGS
, $options['includeFields'] ) ) {
344 $tables[] = 'tag_summary';
346 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
347 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
348 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
349 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
350 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
352 $tables +
= $this->actorMigration
->getJoin( 'rc_user' )['tables'];
357 private function getWatchedItemsWithRCInfoQueryFields( array $options ) {
365 'wl_notificationtimestamp'
373 if ( $options['usedInGenerator'] ) {
374 if ( $options['allRevisions'] ) {
375 $rcIdFields = [ 'rc_this_oldid' ];
377 $rcIdFields = [ 'rc_cur_id' ];
380 $fields = array_merge( $fields, $rcIdFields );
382 if ( in_array( self
::INCLUDE_FLAGS
, $options['includeFields'] ) ) {
383 $fields = array_merge( $fields, [ 'rc_type', 'rc_minor', 'rc_bot' ] );
385 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ) {
386 $fields['rc_user_text'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user_text'];
388 if ( in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ) {
389 $fields['rc_user'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user'];
391 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
392 $fields +
= $this->commentStore
->getJoin( 'rc_comment' )['fields'];
394 if ( in_array( self
::INCLUDE_PATROL_INFO
, $options['includeFields'] ) ) {
395 $fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] );
397 if ( in_array( self
::INCLUDE_SIZES
, $options['includeFields'] ) ) {
398 $fields = array_merge( $fields, [ 'rc_old_len', 'rc_new_len' ] );
400 if ( in_array( self
::INCLUDE_LOG_INFO
, $options['includeFields'] ) ) {
401 $fields = array_merge( $fields, [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ] );
403 if ( in_array( self
::INCLUDE_TAGS
, $options['includeFields'] ) ) {
404 // prefixed with rc_ to include the field in getRecentChangeFieldsFromRow
405 $fields['rc_tags'] = 'ts_tags';
411 private function getWatchedItemsWithRCInfoQueryConds(
416 $watchlistOwnerId = $this->getWatchlistOwnerId( $user, $options );
417 $conds = [ 'wl_user' => $watchlistOwnerId ];
419 if ( !$options['allRevisions'] ) {
420 $conds[] = $db->makeList(
421 [ 'rc_this_oldid=page_latest', 'rc_type=' . RC_LOG
],
426 if ( $options['namespaceIds'] ) {
427 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
430 if ( array_key_exists( 'rcTypes', $options ) ) {
431 $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] );
434 $conds = array_merge(
436 $this->getWatchedItemsWithRCInfoQueryFilterConds( $user, $options )
439 $conds = array_merge( $conds, $this->getStartEndConds( $db, $options ) );
441 if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
442 if ( $db->getType() === 'mysql' ) {
443 // This is an index optimization for mysql
444 $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
448 $conds = array_merge( $conds, $this->getUserRelatedConds( $db, $user, $options ) );
450 $deletedPageLogCond = $this->getExtraDeletedPageLogEntryRelatedCond( $db, $user );
451 if ( $deletedPageLogCond ) {
452 $conds[] = $deletedPageLogCond;
458 private function getWatchlistOwnerId( User
$user, array $options ) {
459 if ( array_key_exists( 'watchlistOwner', $options ) ) {
460 /** @var User $watchlistOwner */
461 $watchlistOwner = $options['watchlistOwner'];
462 $ownersToken = $watchlistOwner->getOption( 'watchlisttoken' );
463 $token = $options['watchlistOwnerToken'];
464 if ( $ownersToken == '' ||
!hash_equals( $ownersToken, $token ) ) {
465 throw ApiUsageException
::newWithMessage( null, 'apierror-bad-watchlist-token', 'bad_wltoken' );
467 return $watchlistOwner->getId();
469 return $user->getId();
472 private function getWatchedItemsWithRCInfoQueryFilterConds( User
$user, array $options ) {
475 if ( in_array( self
::FILTER_MINOR
, $options['filters'] ) ) {
476 $conds[] = 'rc_minor != 0';
477 } elseif ( in_array( self
::FILTER_NOT_MINOR
, $options['filters'] ) ) {
478 $conds[] = 'rc_minor = 0';
481 if ( in_array( self
::FILTER_BOT
, $options['filters'] ) ) {
482 $conds[] = 'rc_bot != 0';
483 } elseif ( in_array( self
::FILTER_NOT_BOT
, $options['filters'] ) ) {
484 $conds[] = 'rc_bot = 0';
487 if ( in_array( self
::FILTER_ANON
, $options['filters'] ) ) {
488 $conds[] = $this->actorMigration
->isAnon(
489 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
491 } elseif ( in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ) {
492 $conds[] = $this->actorMigration
->isNotAnon(
493 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
497 if ( $user->useRCPatrol() ||
$user->useNPPatrol() ) {
498 // TODO: not sure if this should simply ignore patrolled filters if user does not have the patrol
499 // right, or maybe rather fail loud at this point, same as e.g. ApiQueryWatchlist does?
500 if ( in_array( self
::FILTER_PATROLLED
, $options['filters'] ) ) {
501 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
502 } elseif ( in_array( self
::FILTER_NOT_PATROLLED
, $options['filters'] ) ) {
503 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
506 if ( in_array( self
::FILTER_AUTOPATROLLED
, $options['filters'] ) ) {
507 $conds['rc_patrolled'] = RecentChange
::PRC_AUTOPATROLLED
;
508 } elseif ( in_array( self
::FILTER_NOT_AUTOPATROLLED
, $options['filters'] ) ) {
509 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
;
513 if ( in_array( self
::FILTER_UNREAD
, $options['filters'] ) ) {
514 $conds[] = 'rc_timestamp >= wl_notificationtimestamp';
515 } elseif ( in_array( self
::FILTER_NOT_UNREAD
, $options['filters'] ) ) {
516 // TODO: should this be changed to use Database::makeList?
517 $conds[] = 'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
523 private function getStartEndConds( IDatabase
$db, array $options ) {
524 if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
530 if ( isset( $options['start'] ) ) {
531 $after = $options['dir'] === self
::DIR_OLDER ?
'<=' : '>=';
532 $conds[] = 'rc_timestamp ' . $after . ' ' .
533 $db->addQuotes( $db->timestamp( $options['start'] ) );
535 if ( isset( $options['end'] ) ) {
536 $before = $options['dir'] === self
::DIR_OLDER ?
'>=' : '<=';
537 $conds[] = 'rc_timestamp ' . $before . ' ' .
538 $db->addQuotes( $db->timestamp( $options['end'] ) );
544 private function getUserRelatedConds( IDatabase
$db, User
$user, array $options ) {
545 if ( !array_key_exists( 'onlyByUser', $options ) && !array_key_exists( 'notByUser', $options ) ) {
551 if ( array_key_exists( 'onlyByUser', $options ) ) {
552 $byUser = User
::newFromName( $options['onlyByUser'], false );
553 $conds[] = $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'];
554 } elseif ( array_key_exists( 'notByUser', $options ) ) {
555 $byUser = User
::newFromName( $options['notByUser'], false );
556 $conds[] = 'NOT(' . $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'] . ')';
559 // Avoid brute force searches (T19342)
561 if ( !$user->isAllowed( 'deletedhistory' ) ) {
562 $bitmask = Revision
::DELETED_USER
;
563 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
564 $bitmask = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
567 $conds[] = $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask";
573 private function getExtraDeletedPageLogEntryRelatedCond( IDatabase
$db, User
$user ) {
574 // LogPage::DELETED_ACTION hides the affected page, too. So hide those
575 // entirely from the watchlist, or someone could guess the title.
577 if ( !$user->isAllowed( 'deletedhistory' ) ) {
578 $bitmask = LogPage
::DELETED_ACTION
;
579 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
580 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
583 return $db->makeList( [
584 'rc_type != ' . RC_LOG
,
585 $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
591 private function getStartFromConds( IDatabase
$db, array $options, array $startFrom ) {
592 $op = $options['dir'] === self
::DIR_OLDER ?
'<' : '>';
593 list( $rcTimestamp, $rcId ) = $startFrom;
594 $rcTimestamp = $db->addQuotes( $db->timestamp( $rcTimestamp ) );
596 return $db->makeList(
598 "rc_timestamp $op $rcTimestamp",
601 "rc_timestamp = $rcTimestamp",
611 private function getWatchedItemsForUserQueryConds( IDatabase
$db, User
$user, array $options ) {
612 $conds = [ 'wl_user' => $user->getId() ];
613 if ( $options['namespaceIds'] ) {
614 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
616 if ( isset( $options['filter'] ) ) {
617 $filter = $options['filter'];
618 if ( $filter === self
::FILTER_CHANGED
) {
619 $conds[] = 'wl_notificationtimestamp IS NOT NULL';
621 $conds[] = 'wl_notificationtimestamp IS NULL';
625 if ( isset( $options['from'] ) ) {
626 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
627 $conds[] = $this->getFromUntilTargetConds( $db, $options['from'], $op );
629 if ( isset( $options['until'] ) ) {
630 $op = $options['sort'] === self
::SORT_ASC ?
'<' : '>';
631 $conds[] = $this->getFromUntilTargetConds( $db, $options['until'], $op );
633 if ( isset( $options['startFrom'] ) ) {
634 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
635 $conds[] = $this->getFromUntilTargetConds( $db, $options['startFrom'], $op );
642 * Creates a query condition part for getting only items before or after the given link target
643 * (while ordering using $sort mode)
645 * @param IDatabase $db
646 * @param LinkTarget $target
647 * @param string $op comparison operator to use in the conditions
650 private function getFromUntilTargetConds( IDatabase
$db, LinkTarget
$target, $op ) {
651 return $db->makeList(
653 "wl_namespace $op " . $target->getNamespace(),
656 'wl_namespace = ' . $target->getNamespace(),
657 "wl_title $op= " . $db->addQuotes( $target->getDBkey() )
666 private function getWatchedItemsWithRCInfoQueryDbOptions( array $options ) {
669 if ( array_key_exists( 'dir', $options ) ) {
670 $sort = $options['dir'] === self
::DIR_OLDER ?
' DESC' : '';
671 $dbOptions['ORDER BY'] = [ 'rc_timestamp' . $sort, 'rc_id' . $sort ];
674 if ( array_key_exists( 'limit', $options ) ) {
675 $dbOptions['LIMIT'] = (int)$options['limit'] +
1;
681 private function getWatchedItemsForUserQueryDbOptions( array $options ) {
683 if ( array_key_exists( 'sort', $options ) ) {
684 $dbOptions['ORDER BY'] = [
685 "wl_namespace {$options['sort']}",
686 "wl_title {$options['sort']}"
688 if ( count( $options['namespaceIds'] ) === 1 ) {
689 $dbOptions['ORDER BY'] = "wl_title {$options['sort']}";
692 if ( array_key_exists( 'limit', $options ) ) {
693 $dbOptions['LIMIT'] = (int)$options['limit'];
698 private function getWatchedItemsWithRCInfoQueryJoinConds( array $options ) {
700 'watchlist' => [ 'INNER JOIN',
702 'wl_namespace=rc_namespace',
707 if ( !$options['allRevisions'] ) {
708 $joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
710 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
711 $joinConds +
= $this->commentStore
->getJoin( 'rc_comment' )['joins'];
713 if ( in_array( self
::INCLUDE_TAGS
, $options['includeFields'] ) ) {
714 $joinConds['tag_summary'] = [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ];
716 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
717 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
718 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
719 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
720 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
722 $joinConds +
= $this->actorMigration
->getJoin( 'rc_user' )['joins'];