<?php
-use Wikimedia\Rdbms\IDatabase;
use MediaWiki\Linker\LinkTarget;
+use MediaWiki\User\UserIdentity;
use Wikimedia\Assert\Assert;
+use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\LoadBalancer;
/**
* 'end' => string (format accepted by wfTimestamp) requires 'dir' option,
* timestamp to end enumerating
* 'watchlistOwner' => User user whose watchlist items should be listed if different
- * than the one specified with $user param,
- * requires 'watchlistOwnerToken' option
+ * than the one specified with $user param, requires
+ * 'watchlistOwnerToken' option
* 'watchlistOwnerToken' => string a watchlist token used to access another user's
* watchlist, used with 'watchlistOwnerToken' option
* 'limit' => int maximum numbers of items to return
* id fields ('rc_cur_id', 'rc_this_oldid', 'rc_last_oldid')
* if false (default)
* @param array|null &$startFrom Continuation value: [ string $rcTimestamp, int $rcId ]
- * @return array of pairs ( WatchedItem $watchedItem, string[] $recentChangeInfo ),
+ * @return array[] Array of pairs ( WatchedItem $watchedItem, string[] $recentChangeInfo ),
* where $recentChangeInfo contains the following keys:
* - 'rc_id',
* - 'rc_namespace',
/**
* For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser
*
- * @param User $user
+ * @param UserIdentity $user
* @param array $options Allowed keys:
* 'sort' => string optional sorting by namespace ID and title
* one of the self::SORT_* constants
* specified using the form option
* @return WatchedItem[]
*/
- public function getWatchedItemsForUser( User $user, array $options = [] ) {
- if ( $user->isAnon() ) {
+ public function getWatchedItemsForUser( UserIdentity $user, array $options = [] ) {
+ if ( !$user->isRegistered() ) {
// TODO: should this just return an empty array or rather complain loud at this point
// as e.g. ApiBase::getWatchlistUser does?
return [];
$conds = array_merge( $conds, $this->getStartEndConds( $db, $options ) );
- if ( !isset( $options['start'] ) && !isset( $options['end'] ) ) {
- if ( $db->getType() === 'mysql' ) {
- // This is an index optimization for mysql
- $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
- }
+ if ( !isset( $options['start'] ) && !isset( $options['end'] ) && $db->getType() === 'mysql' ) {
+ // This is an index optimization for mysql
+ $conds[] = 'rc_timestamp > ' . $db->addQuotes( '' );
}
$conds = array_merge( $conds, $this->getUserRelatedConds( $db, $user, $options ) );
return $conds;
}
- private function getWatchlistOwnerId( User $user, array $options ) {
+ private function getWatchlistOwnerId( UserIdentity $user, array $options ) {
if ( array_key_exists( 'watchlistOwner', $options ) ) {
/** @var User $watchlistOwner */
$watchlistOwner = $options['watchlistOwner'];
- $ownersToken = $watchlistOwner->getOption( 'watchlisttoken' );
+ $ownersToken =
+ $watchlistOwner->getOption( 'watchlisttoken' );
$token = $options['watchlistOwnerToken'];
if ( $ownersToken == '' || !hash_equals( $ownersToken, $token ) ) {
throw ApiUsageException::newWithMessage( null, 'apierror-bad-watchlist-token', 'bad_wltoken' );
);
}
- private function getWatchedItemsForUserQueryConds( IDatabase $db, User $user, array $options ) {
+ private function getWatchedItemsForUserQueryConds(
+ IDatabase $db, UserIdentity $user, array $options
+ ) {
$conds = [ 'wl_user' => $user->getId() ];
if ( $options['namespaceIds'] ) {
$conds['wl_namespace'] = array_map( 'intval', $options['namespaceIds'] );