* @file
* @ingroup Watchlist
*/
-use Wikimedia\Assert\Assert;
+use MediaWiki\Linker\LinkTarget;
/**
* Representation of a pair of user and title for watchlist entries.
*/
public function getTitle() {
if ( !$this->title ) {
- if ( $this->linkTarget instanceof Title ) {
- $this->title = $this->linkTarget;
- } else {
- $this->title = Title::newFromLinkTarget( $this->linkTarget );
- }
+ $this->title = Title::newFromLinkTarget( $this->linkTarget );
}
return $this->title;
}
*/
public static function batchAddWatch( array $items ) {
// wfDeprecated( __METHOD__, '1.27' );
- $userTargetCombinations = [];
+ if ( !$items ) {
+ return false;
+ }
+
+ $targets = [];
+ $users = [];
/** @var WatchedItem $watchedItem */
foreach ( $items as $watchedItem ) {
- if ( $watchedItem->checkRights && !$watchedItem->getUser()->isAllowed( 'editmywatchlist' ) ) {
+ $user = $watchedItem->getUser();
+ if ( $watchedItem->checkRights && !$user->isAllowed( 'editmywatchlist' ) ) {
continue;
}
- $userTargetCombinations[] = [
- $watchedItem->getUser(),
- $watchedItem->getTitle()->getSubjectPage()
- ];
- $userTargetCombinations[] = [
- $watchedItem->getUser(),
- $watchedItem->getTitle()->getTalkPage()
- ];
+ $userId = $user->getId();
+ $users[$userId] = $user;
+ $targets[$userId][] = $watchedItem->getTitle()->getSubjectPage();
+ $targets[$userId][] = $watchedItem->getTitle()->getTalkPage();
}
+
$store = WatchedItemStore::getDefaultInstance();
- return $store->addWatchBatch( $userTargetCombinations );
+ $success = true;
+ foreach ( $users as $userId => $user ) {
+ $success &= $store->addWatchBatchForUser( $user, $targets[$userId] );
+ }
+
+ return $success;
}
/**