3 use MediaWiki\Linker\LinkTarget
;
4 use MediaWiki\User\UserIdentity
;
5 use Wikimedia\Assert\Assert
;
6 use Wikimedia\Rdbms\IDatabase
;
7 use Wikimedia\Rdbms\LoadBalancer
;
10 * Class performing complex database queries related to WatchedItems.
17 * @license GPL-2.0-or-later
19 class WatchedItemQueryService
{
21 const DIR_OLDER
= 'older';
22 const DIR_NEWER
= 'newer';
24 const INCLUDE_FLAGS
= 'flags';
25 const INCLUDE_USER
= 'user';
26 const INCLUDE_USER_ID
= 'userid';
27 const INCLUDE_COMMENT
= 'comment';
28 const INCLUDE_PATROL_INFO
= 'patrol';
29 const INCLUDE_AUTOPATROL_INFO
= 'autopatrol';
30 const INCLUDE_SIZES
= 'sizes';
31 const INCLUDE_LOG_INFO
= 'loginfo';
32 const INCLUDE_TAGS
= 'tags';
34 // FILTER_* constants are part of public API (are used in ApiQueryWatchlist and
35 // ApiQueryWatchlistRaw classes) and should not be changed.
36 // Changing values of those constants will result in a breaking change in the API
37 const FILTER_MINOR
= 'minor';
38 const FILTER_NOT_MINOR
= '!minor';
39 const FILTER_BOT
= 'bot';
40 const FILTER_NOT_BOT
= '!bot';
41 const FILTER_ANON
= 'anon';
42 const FILTER_NOT_ANON
= '!anon';
43 const FILTER_PATROLLED
= 'patrolled';
44 const FILTER_NOT_PATROLLED
= '!patrolled';
45 const FILTER_AUTOPATROLLED
= 'autopatrolled';
46 const FILTER_NOT_AUTOPATROLLED
= '!autopatrolled';
47 const FILTER_UNREAD
= 'unread';
48 const FILTER_NOT_UNREAD
= '!unread';
49 const FILTER_CHANGED
= 'changed';
50 const FILTER_NOT_CHANGED
= '!changed';
52 const SORT_ASC
= 'ASC';
53 const SORT_DESC
= 'DESC';
58 private $loadBalancer;
60 /** @var WatchedItemQueryServiceExtension[]|null */
61 private $extensions = null;
63 /** @var CommentStore */
64 private $commentStore;
66 /** @var ActorMigration */
67 private $actorMigration;
69 /** @var WatchedItemStoreInterface */
70 private $watchedItemStore;
72 public function __construct(
73 LoadBalancer
$loadBalancer,
74 CommentStore
$commentStore,
75 ActorMigration
$actorMigration,
76 WatchedItemStoreInterface
$watchedItemStore
78 $this->loadBalancer
= $loadBalancer;
79 $this->commentStore
= $commentStore;
80 $this->actorMigration
= $actorMigration;
81 $this->watchedItemStore
= $watchedItemStore;
85 * @return WatchedItemQueryServiceExtension[]
87 private function getExtensions() {
88 if ( $this->extensions
=== null ) {
89 $this->extensions
= [];
90 Hooks
::run( 'WatchedItemQueryServiceExtensions', [ &$this->extensions
, $this ] );
92 return $this->extensions
;
98 private function getConnection() {
99 return $this->loadBalancer
->getConnectionRef( DB_REPLICA
, [ 'watchlist' ] );
104 * @param array $options Allowed keys:
105 * 'includeFields' => string[] RecentChange fields to be included in the result,
106 * self::INCLUDE_* constants should be used
107 * 'filters' => string[] optional filters to narrow down resulted items
108 * 'namespaceIds' => int[] optional namespace IDs to filter by
109 * (defaults to all namespaces)
110 * 'allRevisions' => bool return multiple revisions of the same page if true,
111 * only the most recent if false (default)
112 * 'rcTypes' => int[] which types of RecentChanges to include
113 * (defaults to all types), allowed values: RC_EDIT, RC_NEW,
114 * RC_LOG, RC_EXTERNAL, RC_CATEGORIZE
115 * 'onlyByUser' => string only list changes by a specified user
116 * 'notByUser' => string do not incluide changes by a specified user
117 * 'dir' => string in which direction to enumerate, accepted values:
118 * - DIR_OLDER list newest first
119 * - DIR_NEWER list oldest first
120 * 'start' => string (format accepted by wfTimestamp) requires 'dir' option,
121 * timestamp to start enumerating from
122 * 'end' => string (format accepted by wfTimestamp) requires 'dir' option,
123 * timestamp to end enumerating
124 * 'watchlistOwner' => User user whose watchlist items should be listed if different
125 * than the one specified with $user param, requires
126 * 'watchlistOwnerToken' option
127 * 'watchlistOwnerToken' => string a watchlist token used to access another user's
128 * watchlist, used with 'watchlistOwnerToken' option
129 * 'limit' => int maximum numbers of items to return
130 * 'usedInGenerator' => bool include only RecentChange id field required by the
131 * generator ('rc_cur_id' or 'rc_this_oldid') if true, or all
132 * id fields ('rc_cur_id', 'rc_this_oldid', 'rc_last_oldid')
134 * @param array|null &$startFrom Continuation value: [ string $rcTimestamp, int $rcId ]
135 * @return array[] Array of pairs ( WatchedItem $watchedItem, string[] $recentChangeInfo ),
136 * where $recentChangeInfo contains the following keys:
143 * Additional keys could be added by specifying the 'includeFields' option
145 public function getWatchedItemsWithRecentChangeInfo(
146 User
$user, array $options = [], &$startFrom = null
149 'includeFields' => [],
150 'namespaceIds' => [],
152 'allRevisions' => false,
153 'usedInGenerator' => false
157 !isset( $options['rcTypes'] )
158 ||
!array_diff( $options['rcTypes'], [ RC_EDIT
, RC_NEW
, RC_LOG
, RC_EXTERNAL
, RC_CATEGORIZE
] ),
159 '$options[\'rcTypes\']',
160 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
163 !isset( $options['dir'] ) ||
in_array( $options['dir'], [ self
::DIR_OLDER
, self
::DIR_NEWER
] ),
165 'must be DIR_OLDER or DIR_NEWER'
168 !isset( $options['start'] ) && !isset( $options['end'] ) && $startFrom === null
169 ||
isset( $options['dir'] ),
171 'must be provided when providing the "start" or "end" options or the $startFrom parameter'
174 !isset( $options['startFrom'] ),
175 '$options[\'startFrom\']',
176 'must not be provided, use $startFrom instead'
179 !isset( $startFrom ) ||
( is_array( $startFrom ) && count( $startFrom ) === 2 ),
181 'must be a two-element array'
183 if ( array_key_exists( 'watchlistOwner', $options ) ) {
184 Assert
::parameterType(
186 $options['watchlistOwner'],
187 '$options[\'watchlistOwner\']'
190 isset( $options['watchlistOwnerToken'] ),
191 '$options[\'watchlistOwnerToken\']',
192 'must be provided when providing watchlistOwner option'
196 $db = $this->getConnection();
198 $tables = $this->getWatchedItemsWithRCInfoQueryTables( $options );
199 $fields = $this->getWatchedItemsWithRCInfoQueryFields( $options );
200 $conds = $this->getWatchedItemsWithRCInfoQueryConds( $db, $user, $options );
201 $dbOptions = $this->getWatchedItemsWithRCInfoQueryDbOptions( $options );
202 $joinConds = $this->getWatchedItemsWithRCInfoQueryJoinConds( $options );
204 if ( $startFrom !== null ) {
205 $conds[] = $this->getStartFromConds( $db, $options, $startFrom );
208 foreach ( $this->getExtensions() as $extension ) {
209 $extension->modifyWatchedItemsWithRCInfoQuery(
210 $user, $options, $db,
228 $limit = $dbOptions['LIMIT'] ?? INF
;
231 foreach ( $res as $row ) {
232 if ( --$limit <= 0 ) {
233 $startFrom = [ $row->rc_timestamp
, $row->rc_id
];
237 $target = new TitleValue( (int)$row->rc_namespace
, $row->rc_title
);
242 $this->watchedItemStore
->getLatestNotificationTimestamp(
243 $row->wl_notificationtimestamp
, $user, $target
246 $this->getRecentChangeFieldsFromRow( $row )
250 foreach ( $this->getExtensions() as $extension ) {
251 $extension->modifyWatchedItemsWithRCInfo( $user, $options, $db, $items, $res, $startFrom );
258 * For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser
260 * @param UserIdentity $user
261 * @param array $options Allowed keys:
262 * 'sort' => string optional sorting by namespace ID and title
263 * one of the self::SORT_* constants
264 * 'namespaceIds' => int[] optional namespace IDs to filter by (defaults to all namespaces)
265 * 'limit' => int maximum number of items to return
266 * 'filter' => string optional filter, one of the self::FILTER_* contants
267 * 'from' => LinkTarget requires 'sort' key, only return items starting from
268 * those related to the link target
269 * 'until' => LinkTarget requires 'sort' key, only return items until
270 * those related to the link target
271 * 'startFrom' => LinkTarget requires 'sort' key, only return items starting from
272 * those related to the link target, allows to skip some link targets
273 * specified using the form option
274 * @return WatchedItem[]
276 public function getWatchedItemsForUser( UserIdentity
$user, array $options = [] ) {
277 if ( !$user->isRegistered() ) {
278 // TODO: should this just return an empty array or rather complain loud at this point
279 // as e.g. ApiBase::getWatchlistUser does?
283 $options +
= [ 'namespaceIds' => [] ];
286 !isset( $options['sort'] ) ||
in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ),
287 '$options[\'sort\']',
288 'must be SORT_ASC or SORT_DESC'
291 !isset( $options['filter'] ) ||
in_array(
292 $options['filter'], [ self
::FILTER_CHANGED
, self
::FILTER_NOT_CHANGED
]
294 '$options[\'filter\']',
295 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
298 !isset( $options['from'] ) && !isset( $options['until'] ) && !isset( $options['startFrom'] )
299 ||
isset( $options['sort'] ),
300 '$options[\'sort\']',
301 'must be provided if any of "from", "until", "startFrom" options is provided'
304 $db = $this->getConnection();
306 $conds = $this->getWatchedItemsForUserQueryConds( $db, $user, $options );
307 $dbOptions = $this->getWatchedItemsForUserQueryDbOptions( $options );
311 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
318 foreach ( $res as $row ) {
319 $target = new TitleValue( (int)$row->wl_namespace
, $row->wl_title
);
320 // todo these could all be cached at some point?
321 $watchedItems[] = new WatchedItem(
324 $this->watchedItemStore
->getLatestNotificationTimestamp(
325 $row->wl_notificationtimestamp
, $user, $target
330 return $watchedItems;
333 private function getRecentChangeFieldsFromRow( stdClass
$row ) {
334 // FIXME: This can be simplified to single array_filter call filtering by key value,
335 // now we have stopped supporting PHP 5.5
336 $allFields = get_object_vars( $row );
337 $rcKeys = array_filter(
338 array_keys( $allFields ),
340 return substr( $key, 0, 3 ) === 'rc_';
343 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
346 private function getWatchedItemsWithRCInfoQueryTables( array $options ) {
347 $tables = [ 'recentchanges', 'watchlist' ];
348 if ( !$options['allRevisions'] ) {
351 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
352 $tables +
= $this->commentStore
->getJoin( 'rc_comment' )['tables'];
354 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
355 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
356 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
357 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
358 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
360 $tables +
= $this->actorMigration
->getJoin( 'rc_user' )['tables'];
365 private function getWatchedItemsWithRCInfoQueryFields( array $options ) {
373 'wl_notificationtimestamp'
381 if ( $options['usedInGenerator'] ) {
382 if ( $options['allRevisions'] ) {
383 $rcIdFields = [ 'rc_this_oldid' ];
385 $rcIdFields = [ 'rc_cur_id' ];
388 $fields = array_merge( $fields, $rcIdFields );
390 if ( in_array( self
::INCLUDE_FLAGS
, $options['includeFields'] ) ) {
391 $fields = array_merge( $fields, [ 'rc_type', 'rc_minor', 'rc_bot' ] );
393 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ) {
394 $fields['rc_user_text'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user_text'];
396 if ( in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ) {
397 $fields['rc_user'] = $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user'];
399 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
400 $fields +
= $this->commentStore
->getJoin( 'rc_comment' )['fields'];
402 if ( in_array( self
::INCLUDE_PATROL_INFO
, $options['includeFields'] ) ) {
403 $fields = array_merge( $fields, [ 'rc_patrolled', 'rc_log_type' ] );
405 if ( in_array( self
::INCLUDE_SIZES
, $options['includeFields'] ) ) {
406 $fields = array_merge( $fields, [ 'rc_old_len', 'rc_new_len' ] );
408 if ( in_array( self
::INCLUDE_LOG_INFO
, $options['includeFields'] ) ) {
409 $fields = array_merge( $fields, [ 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ] );
411 if ( in_array( self
::INCLUDE_TAGS
, $options['includeFields'] ) ) {
412 // prefixed with rc_ to include the field in getRecentChangeFieldsFromRow
413 $fields['rc_tags'] = ChangeTags
::makeTagSummarySubquery( 'recentchanges' );
419 private function getWatchedItemsWithRCInfoQueryConds(
424 $watchlistOwnerId = $this->getWatchlistOwnerId( $user, $options );
425 $conds = [ 'wl_user' => $watchlistOwnerId ];
427 if ( !$options['allRevisions'] ) {
428 $conds[] = $db->makeList(
429 [ 'rc_this_oldid=page_latest', 'rc_type=' . RC_LOG
],
434 if ( $options['namespaceIds'] ) {
435 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
438 if ( array_key_exists( 'rcTypes', $options ) ) {
439 $conds['rc_type'] = array_map( 'intval', $options['rcTypes'] );
442 $conds = array_merge(
444 $this->getWatchedItemsWithRCInfoQueryFilterConds( $user, $options )
447 $conds = array_merge( $conds, $this->getStartEndConds( $db, $options ) );
449 if ( !isset( $options['start'] ) && !isset( $options['end'] ) && $db->getType() === 'mysql' ) {
450 // This is an index optimization for mysql
451 $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
454 $conds = array_merge( $conds, $this->getUserRelatedConds( $db, $user, $options ) );
456 $deletedPageLogCond = $this->getExtraDeletedPageLogEntryRelatedCond( $db, $user );
457 if ( $deletedPageLogCond ) {
458 $conds[] = $deletedPageLogCond;
464 private function getWatchlistOwnerId( UserIdentity
$user, array $options ) {
465 if ( array_key_exists( 'watchlistOwner', $options ) ) {
466 /** @var User $watchlistOwner */
467 $watchlistOwner = $options['watchlistOwner'];
469 $watchlistOwner->getOption( 'watchlisttoken' );
470 $token = $options['watchlistOwnerToken'];
471 if ( $ownersToken == '' ||
!hash_equals( $ownersToken, $token ) ) {
472 throw ApiUsageException
::newWithMessage( null, 'apierror-bad-watchlist-token', 'bad_wltoken' );
474 return $watchlistOwner->getId();
476 return $user->getId();
479 private function getWatchedItemsWithRCInfoQueryFilterConds( User
$user, array $options ) {
482 if ( in_array( self
::FILTER_MINOR
, $options['filters'] ) ) {
483 $conds[] = 'rc_minor != 0';
484 } elseif ( in_array( self
::FILTER_NOT_MINOR
, $options['filters'] ) ) {
485 $conds[] = 'rc_minor = 0';
488 if ( in_array( self
::FILTER_BOT
, $options['filters'] ) ) {
489 $conds[] = 'rc_bot != 0';
490 } elseif ( in_array( self
::FILTER_NOT_BOT
, $options['filters'] ) ) {
491 $conds[] = 'rc_bot = 0';
494 if ( in_array( self
::FILTER_ANON
, $options['filters'] ) ) {
495 $conds[] = $this->actorMigration
->isAnon(
496 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
498 } elseif ( in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ) {
499 $conds[] = $this->actorMigration
->isNotAnon(
500 $this->actorMigration
->getJoin( 'rc_user' )['fields']['rc_user']
504 if ( $user->useRCPatrol() ||
$user->useNPPatrol() ) {
505 // TODO: not sure if this should simply ignore patrolled filters if user does not have the patrol
506 // right, or maybe rather fail loud at this point, same as e.g. ApiQueryWatchlist does?
507 if ( in_array( self
::FILTER_PATROLLED
, $options['filters'] ) ) {
508 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_UNPATROLLED
;
509 } elseif ( in_array( self
::FILTER_NOT_PATROLLED
, $options['filters'] ) ) {
510 $conds['rc_patrolled'] = RecentChange
::PRC_UNPATROLLED
;
513 if ( in_array( self
::FILTER_AUTOPATROLLED
, $options['filters'] ) ) {
514 $conds['rc_patrolled'] = RecentChange
::PRC_AUTOPATROLLED
;
515 } elseif ( in_array( self
::FILTER_NOT_AUTOPATROLLED
, $options['filters'] ) ) {
516 $conds[] = 'rc_patrolled != ' . RecentChange
::PRC_AUTOPATROLLED
;
520 if ( in_array( self
::FILTER_UNREAD
, $options['filters'] ) ) {
521 $conds[] = 'rc_timestamp >= wl_notificationtimestamp';
522 } elseif ( in_array( self
::FILTER_NOT_UNREAD
, $options['filters'] ) ) {
523 // TODO: should this be changed to use Database::makeList?
524 $conds[] = 'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
530 private function getStartEndConds( IDatabase
$db, array $options ) {
531 if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
537 if ( isset( $options['start'] ) ) {
538 $after = $options['dir'] === self
::DIR_OLDER ?
'<=' : '>=';
539 $conds[] = 'rc_timestamp ' . $after . ' ' .
540 $db->addQuotes( $db->timestamp( $options['start'] ) );
542 if ( isset( $options['end'] ) ) {
543 $before = $options['dir'] === self
::DIR_OLDER ?
'>=' : '<=';
544 $conds[] = 'rc_timestamp ' . $before . ' ' .
545 $db->addQuotes( $db->timestamp( $options['end'] ) );
551 private function getUserRelatedConds( IDatabase
$db, User
$user, array $options ) {
552 if ( !array_key_exists( 'onlyByUser', $options ) && !array_key_exists( 'notByUser', $options ) ) {
558 if ( array_key_exists( 'onlyByUser', $options ) ) {
559 $byUser = User
::newFromName( $options['onlyByUser'], false );
560 $conds[] = $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'];
561 } elseif ( array_key_exists( 'notByUser', $options ) ) {
562 $byUser = User
::newFromName( $options['notByUser'], false );
563 $conds[] = 'NOT(' . $this->actorMigration
->getWhere( $db, 'rc_user', $byUser )['conds'] . ')';
566 // Avoid brute force searches (T19342)
568 if ( !$user->isAllowed( 'deletedhistory' ) ) {
569 $bitmask = Revision
::DELETED_USER
;
570 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
571 $bitmask = Revision
::DELETED_USER | Revision
::DELETED_RESTRICTED
;
574 $conds[] = $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask";
580 private function getExtraDeletedPageLogEntryRelatedCond( IDatabase
$db, User
$user ) {
581 // LogPage::DELETED_ACTION hides the affected page, too. So hide those
582 // entirely from the watchlist, or someone could guess the title.
584 if ( !$user->isAllowed( 'deletedhistory' ) ) {
585 $bitmask = LogPage
::DELETED_ACTION
;
586 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
587 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
590 return $db->makeList( [
591 'rc_type != ' . RC_LOG
,
592 $db->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
598 private function getStartFromConds( IDatabase
$db, array $options, array $startFrom ) {
599 $op = $options['dir'] === self
::DIR_OLDER ?
'<' : '>';
600 list( $rcTimestamp, $rcId ) = $startFrom;
601 $rcTimestamp = $db->addQuotes( $db->timestamp( $rcTimestamp ) );
603 return $db->makeList(
605 "rc_timestamp $op $rcTimestamp",
608 "rc_timestamp = $rcTimestamp",
618 private function getWatchedItemsForUserQueryConds(
619 IDatabase
$db, UserIdentity
$user, array $options
621 $conds = [ 'wl_user' => $user->getId() ];
622 if ( $options['namespaceIds'] ) {
623 $conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );
625 if ( isset( $options['filter'] ) ) {
626 $filter = $options['filter'];
627 if ( $filter === self
::FILTER_CHANGED
) {
628 $conds[] = 'wl_notificationtimestamp IS NOT NULL';
630 $conds[] = 'wl_notificationtimestamp IS NULL';
634 if ( isset( $options['from'] ) ) {
635 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
636 $conds[] = $this->getFromUntilTargetConds( $db, $options['from'], $op );
638 if ( isset( $options['until'] ) ) {
639 $op = $options['sort'] === self
::SORT_ASC ?
'<' : '>';
640 $conds[] = $this->getFromUntilTargetConds( $db, $options['until'], $op );
642 if ( isset( $options['startFrom'] ) ) {
643 $op = $options['sort'] === self
::SORT_ASC ?
'>' : '<';
644 $conds[] = $this->getFromUntilTargetConds( $db, $options['startFrom'], $op );
651 * Creates a query condition part for getting only items before or after the given link target
652 * (while ordering using $sort mode)
654 * @param IDatabase $db
655 * @param LinkTarget $target
656 * @param string $op comparison operator to use in the conditions
659 private function getFromUntilTargetConds( IDatabase
$db, LinkTarget
$target, $op ) {
660 return $db->makeList(
662 "wl_namespace $op " . $target->getNamespace(),
665 'wl_namespace = ' . $target->getNamespace(),
666 "wl_title $op= " . $db->addQuotes( $target->getDBkey() )
675 private function getWatchedItemsWithRCInfoQueryDbOptions( array $options ) {
678 if ( array_key_exists( 'dir', $options ) ) {
679 $sort = $options['dir'] === self
::DIR_OLDER ?
' DESC' : '';
680 $dbOptions['ORDER BY'] = [ 'rc_timestamp' . $sort, 'rc_id' . $sort ];
683 if ( array_key_exists( 'limit', $options ) ) {
684 $dbOptions['LIMIT'] = (int)$options['limit'] +
1;
690 private function getWatchedItemsForUserQueryDbOptions( array $options ) {
692 if ( array_key_exists( 'sort', $options ) ) {
693 $dbOptions['ORDER BY'] = [
694 "wl_namespace {$options['sort']}",
695 "wl_title {$options['sort']}"
697 if ( count( $options['namespaceIds'] ) === 1 ) {
698 $dbOptions['ORDER BY'] = "wl_title {$options['sort']}";
701 if ( array_key_exists( 'limit', $options ) ) {
702 $dbOptions['LIMIT'] = (int)$options['limit'];
707 private function getWatchedItemsWithRCInfoQueryJoinConds( array $options ) {
709 'watchlist' => [ 'JOIN',
711 'wl_namespace=rc_namespace',
716 if ( !$options['allRevisions'] ) {
717 $joinConds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
719 if ( in_array( self
::INCLUDE_COMMENT
, $options['includeFields'] ) ) {
720 $joinConds +
= $this->commentStore
->getJoin( 'rc_comment' )['joins'];
722 if ( in_array( self
::INCLUDE_USER
, $options['includeFields'] ) ||
723 in_array( self
::INCLUDE_USER_ID
, $options['includeFields'] ) ||
724 in_array( self
::FILTER_ANON
, $options['filters'] ) ||
725 in_array( self
::FILTER_NOT_ANON
, $options['filters'] ) ||
726 array_key_exists( 'onlyByUser', $options ) ||
array_key_exists( 'notByUser', $options )
728 $joinConds +
= $this->actorMigration
->getJoin( 'rc_user' )['joins'];