3 use MediaWiki\Linker\LinkTarget
;
4 use MediaWiki\Storage\RevisionRecord
;
5 use MediaWiki\User\UserIdentity
;
6 use Wikimedia\Assert\Assert
;
7 use Wikimedia\Rdbms\IDatabase
;
8 use Wikimedia\Rdbms\ILoadBalancer
;
11 * Class performing complex database queries related to WatchedItems.
18 * @license GPL-2.0-or-later
20 class WatchedItemQueryService
{
22 const DIR_OLDER
= 'older';
23 const DIR_NEWER
= 'newer';
25 const INCLUDE_FLAGS
= 'flags';
26 const INCLUDE_USER
= 'user';
27 const INCLUDE_USER_ID
= 'userid';
28 const INCLUDE_COMMENT
= 'comment';
29 const INCLUDE_PATROL_INFO
= 'patrol';
30 const INCLUDE_AUTOPATROL_INFO
= 'autopatrol';
31 const INCLUDE_SIZES
= 'sizes';
32 const INCLUDE_LOG_INFO
= 'loginfo';
33 const INCLUDE_TAGS
= 'tags';
35 // FILTER_* constants are part of public API (are used in ApiQueryWatchlist and
36 // ApiQueryWatchlistRaw classes) and should not be changed.
37 // Changing values of those constants will result in a breaking change in the API
38 const FILTER_MINOR
= 'minor';
39 const FILTER_NOT_MINOR
= '!minor';
40 const FILTER_BOT
= 'bot';
41 const FILTER_NOT_BOT
= '!bot';
42 const FILTER_ANON
= 'anon';
43 const FILTER_NOT_ANON
= '!anon';
44 const FILTER_PATROLLED
= 'patrolled';
45 const FILTER_NOT_PATROLLED
= '!patrolled';
46 const FILTER_AUTOPATROLLED
= 'autopatrolled';
47 const FILTER_NOT_AUTOPATROLLED
= '!autopatrolled';
48 const FILTER_UNREAD
= 'unread';
49 const FILTER_NOT_UNREAD
= '!unread';
50 const FILTER_CHANGED
= 'changed';
51 const FILTER_NOT_CHANGED
= '!changed';
53 const SORT_ASC
= 'ASC';
54 const SORT_DESC
= 'DESC';
59 private $loadBalancer;
61 /** @var WatchedItemQueryServiceExtension[]|null */
62 private $extensions = null;
64 /** @var CommentStore */
65 private $commentStore;
67 /** @var ActorMigration */
68 private $actorMigration;
70 /** @var WatchedItemStoreInterface */
71 private $watchedItemStore;
73 public function __construct(
74 ILoadBalancer
$loadBalancer,
75 CommentStore
$commentStore,
76 ActorMigration
$actorMigration,
77 WatchedItemStoreInterface
$watchedItemStore
79 $this->loadBalancer
= $loadBalancer;
80 $this->commentStore
= $commentStore;
81 $this->actorMigration
= $actorMigration;
82 $this->watchedItemStore
= $watchedItemStore;
86 * @return WatchedItemQueryServiceExtension[]
88 private function getExtensions() {
89 if ( $this->extensions
=== null ) {
90 $this->extensions
= [];
91 Hooks
::run( 'WatchedItemQueryServiceExtensions', [ &$this->extensions
, $this ] );
93 return $this->extensions
;
99 private function getConnection() {
100 return $this->loadBalancer
->getConnectionRef( DB_REPLICA
, [ 'watchlist' ] );
105 * @param array $options Allowed keys:
106 * 'includeFields' => string[] RecentChange fields to be included in the result,
107 * self::INCLUDE_* constants should be used
108 * 'filters' => string[] optional filters to narrow down resulted items
109 * 'namespaceIds' => int[] optional namespace IDs to filter by
110 * (defaults to all namespaces)
111 * 'allRevisions' => bool return multiple revisions of the same page if true,
112 * only the most recent if false (default)
113 * 'rcTypes' => int[] which types of RecentChanges to include
114 * (defaults to all types), allowed values: RC_EDIT, RC_NEW,
115 * RC_LOG, RC_EXTERNAL, RC_CATEGORIZE
116 * 'onlyByUser' => string only list changes by a specified user
117 * 'notByUser' => string do not incluide changes by a specified user
118 * 'dir' => string in which direction to enumerate, accepted values:
119 * - DIR_OLDER list newest first
120 * - DIR_NEWER list oldest first
121 * 'start' => string (format accepted by wfTimestamp) requires 'dir' option,
122 * timestamp to start enumerating from
123 * 'end' => string (format accepted by wfTimestamp) requires 'dir' option,
124 * timestamp to end enumerating
125 * 'watchlistOwner' => User user whose watchlist items should be listed if different
126 * than the one specified with $user param, requires
127 * 'watchlistOwnerToken' option
128 * 'watchlistOwnerToken' => string a watchlist token used to access another user's
129 * watchlist, used with 'watchlistOwnerToken' option
130 * 'limit' => int maximum numbers of items to return
131 * 'usedInGenerator' => bool include only RecentChange id field required by the
132 * generator ('rc_cur_id' or 'rc_this_oldid') if true, or all
133 * id fields ('rc_cur_id', 'rc_this_oldid', 'rc_last_oldid')
135 * @param array|null &$startFrom Continuation value: [ string $rcTimestamp, int $rcId ]
136 * @return array[] Array of pairs ( WatchedItem $watchedItem, string[] $recentChangeInfo ),
137 * where $recentChangeInfo contains the following keys:
144 * Additional keys could be added by specifying the 'includeFields' option
146 public function getWatchedItemsWithRecentChangeInfo(
147 User
$user, array $options = [], &$startFrom = null
150 'includeFields' => [],
151 'namespaceIds' => [],
153 'allRevisions' => false,
154 'usedInGenerator' => false
158 !isset( $options['rcTypes'] )
159 ||
!array_diff( $options['rcTypes'], [ RC_EDIT
, RC_NEW
, RC_LOG
, RC_EXTERNAL
, RC_CATEGORIZE
] ),
160 '$options[\'rcTypes\']',
161 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
164 !isset( $options['dir'] ) ||
in_array( $options['dir'], [ self
::DIR_OLDER
, self
::DIR_NEWER
] ),
166 'must be DIR_OLDER or DIR_NEWER'
169 !isset( $options['start'] ) && !isset( $options['end'] ) && $startFrom === null
170 ||
isset( $options['dir'] ),
172 'must be provided when providing the "start" or "end" options or the $startFrom parameter'
175 !isset( $options['startFrom'] ),
176 '$options[\'startFrom\']',
177 'must not be provided, use $startFrom instead'
180 !isset( $startFrom ) ||
( is_array( $startFrom ) && count( $startFrom ) === 2 ),
182 'must be a two-element array'
184 if ( array_key_exists( 'watchlistOwner', $options ) ) {
185 Assert
::parameterType(
187 $options['watchlistOwner'],
188 '$options[\'watchlistOwner\']'
191 isset( $options['watchlistOwnerToken'] ),
192 '$options[\'watchlistOwnerToken\']',
193 'must be provided when providing watchlistOwner option'
197 $db = $this->getConnection();
199 $tables = $this->getWatchedItemsWithRCInfoQueryTables( $options );
200 $fields = $this->getWatchedItemsWithRCInfoQueryFields( $options );
201 $conds = $this->getWatchedItemsWithRCInfoQueryConds( $db, $user, $options );
202 $dbOptions = $this->getWatchedItemsWithRCInfoQueryDbOptions( $options );
203 $joinConds = $this->getWatchedItemsWithRCInfoQueryJoinConds( $options );
205 if ( $startFrom !== null ) {
206 $conds[] = $this->getStartFromConds( $db, $options, $startFrom );
209 foreach ( $this->getExtensions() as $extension ) {
210 $extension->modifyWatchedItemsWithRCInfoQuery(
211 $user, $options, $db,
229 $limit = $dbOptions['LIMIT'] ?? INF
;
232 foreach ( $res as $row ) {
233 if ( --$limit <= 0 ) {
234 $startFrom = [ $row->rc_timestamp
, $row->rc_id
];
238 $target = new TitleValue( (int)$row->rc_namespace
, $row->rc_title
);
243 $this->watchedItemStore
->getLatestNotificationTimestamp(
244 $row->wl_notificationtimestamp
, $user, $target
247 $this->getRecentChangeFieldsFromRow( $row )
251 foreach ( $this->getExtensions() as $extension ) {
252 $extension->modifyWatchedItemsWithRCInfo( $user, $options, $db, $items, $res, $startFrom );
259 * For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser
261 * @param UserIdentity $user
262 * @param array $options Allowed keys:
263 * 'sort' => string optional sorting by namespace ID and title
264 * one of the self::SORT_* constants
265 * 'namespaceIds' => int[] optional namespace IDs to filter by (defaults to all namespaces)
266 * 'limit' => int maximum number of items to return
267 * 'filter' => string optional filter, one of the self::FILTER_* contants
268 * 'from' => LinkTarget requires 'sort' key, only return items starting from
269 * those related to the link target
270 * 'until' => LinkTarget requires 'sort' key, only return items until
271 * those related to the link target
272 * 'startFrom' => LinkTarget requires 'sort' key, only return items starting from
273 * those related to the link target, allows to skip some link targets
274 * specified using the form option
275 * @return WatchedItem[]
277 public function getWatchedItemsForUser( UserIdentity
$user, array $options = [] ) {
278 if ( !$user->isRegistered() ) {
279 // TODO: should this just return an empty array or rather complain loud at this point
280 // as e.g. ApiBase::getWatchlistUser does?
284 $options +
= [ 'namespaceIds' => [] ];
287 !isset( $options['sort'] ) ||
in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ),
288 '$options[\'sort\']',
289 'must be SORT_ASC or SORT_DESC'
292 !isset( $options['filter'] ) ||
in_array(
293 $options['filter'], [ self
::FILTER_CHANGED
, self
::FILTER_NOT_CHANGED
]
295 '$options[\'filter\']',
296 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
299 !isset( $options['from'] ) && !isset( $options['until'] ) && !isset( $options['startFrom'] )
300 ||
isset( $options['sort'] ),
301 '$options[\'sort\']',
302 'must be provided if any of "from", "until", "startFrom" options is provided'
305 $db = $this->getConnection();
307 $conds = $this->getWatchedItemsForUserQueryConds( $db, $user, $options );
308 $dbOptions = $this->getWatchedItemsForUserQueryDbOptions( $options );
312 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
319 foreach ( $res as $row ) {
320 $target = new TitleValue( (int)$row->wl_namespace
, $row->wl_title
);
321 // todo these could all be cached at some point?
322 $watchedItems[] = new WatchedItem(
325 $this->watchedItemStore
->getLatestNotificationTimestamp(
326 $row->wl_notificationtimestamp
, $user, $target
331 return $watchedItems;
334 private function getRecentChangeFieldsFromRow( stdClass
$row ) {
335 // FIXME: This can be simplified to single array_filter call filtering by key value,
336 // now we have stopped supporting PHP 5.5
337 $allFields = get_object_vars( $row );
338 $rcKeys = array_filter(
339 array_keys( $allFields ),
341 return substr( $key, 0, 3 ) === 'rc_';
344 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
347 private function getWatchedItemsWithRCInfoQueryTables( array $options ) {
348 $tables = [ 'recentchanges', 'watchlist' ];
349 if ( !$options['allRevisions'] ) {
352 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
353 $tables +
= $this->commentStore
->getJoin( 'rc_comment' )['tables'];
355 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
356 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
357 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
358 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
359 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
361 $tables +
= $this->actorMigration
->getJoin( 'rc_user' )['tables'];
366 private function getWatchedItemsWithRCInfoQueryFields( array $options ) {
374 'wl_notificationtimestamp'
382 if ( $options['usedInGenerator'] ) {
383 if ( $options['allRevisions'] ) {
384 $rcIdFields = [ 'rc_this_oldid' ];
386 $rcIdFields = [ 'rc_cur_id' ];
389 $fields = array_merge( $fields, $rcIdFields );
391 if ( in_array( self
::INCLUDE_FLAGS
, $options['includeFields'] ) ) {
392 $fields = array_merge( $fields, [ 'rc_type', 'rc_minor', 'rc_bot' ] );
394 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ) {
395 $fields['rc_user_text'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user_text'];
397 if ( in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ) {
398 $fields['rc_user'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user'];
400 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
401 $fields +
= $this->commentStore
->getJoin( 'rc_comment' )['fields'];
403 if ( in_array( self
::INCLUDE_PATROL_INFO
, $options['includeFields'] ) ) {
404 $fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] );
406 if ( in_array( self
::INCLUDE_SIZES
, $options['includeFields'] ) ) {
407 $fields = array_merge( $fields, [ 'rc_old_len', 'rc_new_len' ] );
409 if ( in_array( self
::INCLUDE_LOG_INFO
, $options['includeFields'] ) ) {
410 $fields = array_merge( $fields, [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ] );
412 if ( in_array( self
::INCLUDE_TAGS
, $options['includeFields'] ) ) {
413 // prefixed with rc_ to include the field in getRecentChangeFieldsFromRow
414 $fields['rc_tags'] = ChangeTags
::makeTagSummarySubquery( 'recentchanges' );
420 private function getWatchedItemsWithRCInfoQueryConds(
425 $watchlistOwnerId = $this->getWatchlistOwnerId( $user, $options );
426 $conds = [ 'wl_user' => $watchlistOwnerId ];
428 if ( !$options['allRevisions'] ) {
429 $conds[] = $db->makeList(
430 [ 'rc_this_oldid=page_latest', 'rc_type=' . RC_LOG
],
435 if ( $options['namespaceIds'] ) {
436 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
439 if ( array_key_exists( 'rcTypes', $options ) ) {
440 $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] );
443 $conds = array_merge(
445 $this->getWatchedItemsWithRCInfoQueryFilterConds( $user, $options )
448 $conds = array_merge( $conds, $this->getStartEndConds( $db, $options ) );
450 if ( !isset( $options['start'] ) && !isset( $options['end'] ) && $db->getType() === 'mysql' ) {
451 // This is an index optimization for mysql
452 $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
455 $conds = array_merge( $conds, $this->getUserRelatedConds( $db, $user, $options ) );
457 $deletedPageLogCond = $this->getExtraDeletedPageLogEntryRelatedCond( $db, $user );
458 if ( $deletedPageLogCond ) {
459 $conds[] = $deletedPageLogCond;
465 private function getWatchlistOwnerId( UserIdentity
$user, array $options ) {
466 if ( array_key_exists( 'watchlistOwner', $options ) ) {
467 /** @var User $watchlistOwner */
468 $watchlistOwner = $options['watchlistOwner'];
470 $watchlistOwner->getOption( 'watchlisttoken' );
471 $token = $options['watchlistOwnerToken'];
472 if ( $ownersToken == '' ||
!hash_equals( $ownersToken, $token ) ) {
473 throw ApiUsageException
::newWithMessage( null, 'apierror-bad-watchlist-token', 'bad_wltoken' );
475 return $watchlistOwner->getId();
477 return $user->getId();
480 private function getWatchedItemsWithRCInfoQueryFilterConds( User
$user, array $options ) {
483 if ( in_array( self
::FILTER_MINOR
, $options['filters'] ) ) {
484 $conds[] = 'rc_minor != 0';
485 } elseif ( in_array( self
::FILTER_NOT_MINOR
, $options['filters'] ) ) {
486 $conds[] = 'rc_minor = 0';
489 if ( in_array( self
::FILTER_BOT
, $options['filters'] ) ) {
490 $conds[] = 'rc_bot != 0';
491 } elseif ( in_array( self
::FILTER_NOT_BOT
, $options['filters'] ) ) {
492 $conds[] = 'rc_bot = 0';
495 if ( in_array( self
::FILTER_ANON
, $options['filters'] ) ) {
496 $conds[] = $this->actorMigration
->isAnon(
497 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
499 } elseif ( in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ) {
500 $conds[] = $this->actorMigration
->isNotAnon(
501 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
505 if ( $user->useRCPatrol() ||
$user->useNPPatrol() ) {
506 // TODO: not sure if this should simply ignore patrolled filters if user does not have the patrol
507 // right, or maybe rather fail loud at this point, same as e.g. ApiQueryWatchlist does?
508 if ( in_array( self
::FILTER_PATROLLED
, $options['filters'] ) ) {
509 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
510 } elseif ( in_array( self
::FILTER_NOT_PATROLLED
, $options['filters'] ) ) {
511 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
514 if ( in_array( self
::FILTER_AUTOPATROLLED
, $options['filters'] ) ) {
515 $conds['rc_patrolled'] = RecentChange
::PRC_AUTOPATROLLED
;
516 } elseif ( in_array( self
::FILTER_NOT_AUTOPATROLLED
, $options['filters'] ) ) {
517 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
;
521 if ( in_array( self
::FILTER_UNREAD
, $options['filters'] ) ) {
522 $conds[] = 'rc_timestamp >= wl_notificationtimestamp';
523 } elseif ( in_array( self
::FILTER_NOT_UNREAD
, $options['filters'] ) ) {
524 // TODO: should this be changed to use Database::makeList?
525 $conds[] = 'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
531 private function getStartEndConds( IDatabase
$db, array $options ) {
532 if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
538 if ( isset( $options['start'] ) ) {
539 $after = $options['dir'] === self
::DIR_OLDER ?
'<=' : '>=';
540 $conds[] = 'rc_timestamp ' . $after . ' ' .
541 $db->addQuotes( $db->timestamp( $options['start'] ) );
543 if ( isset( $options['end'] ) ) {
544 $before = $options['dir'] === self
::DIR_OLDER ?
'>=' : '<=';
545 $conds[] = 'rc_timestamp ' . $before . ' ' .
546 $db->addQuotes( $db->timestamp( $options['end'] ) );
552 private function getUserRelatedConds( IDatabase
$db, User
$user, array $options ) {
553 if ( !array_key_exists( 'onlyByUser', $options ) && !array_key_exists( 'notByUser', $options ) ) {
559 if ( array_key_exists( 'onlyByUser', $options ) ) {
560 $byUser = User
::newFromName( $options['onlyByUser'], false );
561 $conds[] = $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'];
562 } elseif ( array_key_exists( 'notByUser', $options ) ) {
563 $byUser = User
::newFromName( $options['notByUser'], false );
564 $conds[] = 'NOT(' . $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'] . ')';
567 // Avoid brute force searches (T19342)
569 if ( !$user->isAllowed( 'deletedhistory' ) ) {
570 $bitmask = RevisionRecord
::DELETED_USER
;
571 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
572 $bitmask = RevisionRecord
::DELETED_USER | RevisionRecord
::DELETED_RESTRICTED
;
575 $conds[] = $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask";
581 private function getExtraDeletedPageLogEntryRelatedCond( IDatabase
$db, User
$user ) {
582 // LogPage::DELETED_ACTION hides the affected page, too. So hide those
583 // entirely from the watchlist, or someone could guess the title.
585 if ( !$user->isAllowed( 'deletedhistory' ) ) {
586 $bitmask = LogPage
::DELETED_ACTION
;
587 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
588 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
591 return $db->makeList( [
592 'rc_type != ' . RC_LOG
,
593 $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
599 private function getStartFromConds( IDatabase
$db, array $options, array $startFrom ) {
600 $op = $options['dir'] === self
::DIR_OLDER ?
'<' : '>';
601 list( $rcTimestamp, $rcId ) = $startFrom;
602 $rcTimestamp = $db->addQuotes( $db->timestamp( $rcTimestamp ) );
604 return $db->makeList(
606 "rc_timestamp $op $rcTimestamp",
609 "rc_timestamp = $rcTimestamp",
619 private function getWatchedItemsForUserQueryConds(
620 IDatabase
$db, UserIdentity
$user, array $options
622 $conds = [ 'wl_user' => $user->getId() ];
623 if ( $options['namespaceIds'] ) {
624 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
626 if ( isset( $options['filter'] ) ) {
627 $filter = $options['filter'];
628 if ( $filter === self
::FILTER_CHANGED
) {
629 $conds[] = 'wl_notificationtimestamp IS NOT NULL';
631 $conds[] = 'wl_notificationtimestamp IS NULL';
635 if ( isset( $options['from'] ) ) {
636 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
637 $conds[] = $this->getFromUntilTargetConds( $db, $options['from'], $op );
639 if ( isset( $options['until'] ) ) {
640 $op = $options['sort'] === self
::SORT_ASC ?
'<' : '>';
641 $conds[] = $this->getFromUntilTargetConds( $db, $options['until'], $op );
643 if ( isset( $options['startFrom'] ) ) {
644 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
645 $conds[] = $this->getFromUntilTargetConds( $db, $options['startFrom'], $op );
652 * Creates a query condition part for getting only items before or after the given link target
653 * (while ordering using $sort mode)
655 * @param IDatabase $db
656 * @param LinkTarget $target
657 * @param string $op comparison operator to use in the conditions
660 private function getFromUntilTargetConds( IDatabase
$db, LinkTarget
$target, $op ) {
661 return $db->makeList(
663 "wl_namespace $op " . $target->getNamespace(),
666 'wl_namespace = ' . $target->getNamespace(),
667 "wl_title $op= " . $db->addQuotes( $target->getDBkey() )
676 private function getWatchedItemsWithRCInfoQueryDbOptions( array $options ) {
679 if ( array_key_exists( 'dir', $options ) ) {
680 $sort = $options['dir'] === self
::DIR_OLDER ?
' DESC' : '';
681 $dbOptions['ORDER BY'] = [ 'rc_timestamp' . $sort, 'rc_id' . $sort ];
684 if ( array_key_exists( 'limit', $options ) ) {
685 $dbOptions['LIMIT'] = (int)$options['limit'] +
1;
691 private function getWatchedItemsForUserQueryDbOptions( array $options ) {
693 if ( array_key_exists( 'sort', $options ) ) {
694 $dbOptions['ORDER BY'] = [
695 "wl_namespace {$options['sort']}",
696 "wl_title {$options['sort']}"
698 if ( count( $options['namespaceIds'] ) === 1 ) {
699 $dbOptions['ORDER BY'] = "wl_title {$options['sort']}";
702 if ( array_key_exists( 'limit', $options ) ) {
703 $dbOptions['LIMIT'] = (int)$options['limit'];
708 private function getWatchedItemsWithRCInfoQueryJoinConds( array $options ) {
710 'watchlist' => [ 'JOIN',
712 'wl_namespace=rc_namespace',
717 if ( !$options['allRevisions'] ) {
718 $joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
720 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
721 $joinConds +
= $this->commentStore
->getJoin( 'rc_comment' )['joins'];
723 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
724 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
725 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
726 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
727 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
729 $joinConds +
= $this->actorMigration
->getJoin( 'rc_user' )['joins'];