3 use Wikimedia\Rdbms\IDatabase
;
4 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface
;
5 use MediaWiki\Linker\LinkTarget
;
6 use MediaWiki\MediaWikiServices
;
7 use Wikimedia\Assert\Assert
;
8 use Wikimedia\ScopedCallback
;
9 use Wikimedia\Rdbms\LoadBalancer
;
12 * Storage layer class for WatchedItems.
13 * Database interaction & caching
14 * TODO caching should be factored out into a CachingWatchedItemStore class
19 class WatchedItemStore
implements WatchedItemStoreInterface
, StatsdAwareInterface
{
24 private $loadBalancer;
29 private $readOnlyMode;
37 * @var array[] Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key'
38 * The index is needed so that on mass changes all relevant items can be un-cached.
39 * For example: Clearing a users watchlist of all items or updating notification timestamps
40 * for all users watching a single target.
42 private $cacheIndex = [];
47 private $deferredUpdatesAddCallableUpdateCallback;
52 private $revisionGetTimestampFromIdCallback;
57 private $updateRowsPerQuery;
60 * @var StatsdDataFactoryInterface
65 * @param LoadBalancer $loadBalancer
66 * @param HashBagOStuff $cache
67 * @param ReadOnlyMode $readOnlyMode
68 * @param int $updateRowsPerQuery
70 public function __construct(
71 LoadBalancer
$loadBalancer,
73 ReadOnlyMode
$readOnlyMode,
76 $this->loadBalancer
= $loadBalancer;
77 $this->cache
= $cache;
78 $this->readOnlyMode
= $readOnlyMode;
79 $this->stats
= new NullStatsdDataFactory();
80 $this->deferredUpdatesAddCallableUpdateCallback
=
81 [ DeferredUpdates
::class, 'addCallableUpdate' ];
82 $this->revisionGetTimestampFromIdCallback
=
83 [ Revision
::class, 'getTimestampFromId' ];
84 $this->updateRowsPerQuery
= $updateRowsPerQuery;
88 * @param StatsdDataFactoryInterface $stats
90 public function setStatsdDataFactory( StatsdDataFactoryInterface
$stats ) {
91 $this->stats
= $stats;
95 * Overrides the DeferredUpdates::addCallableUpdate callback
96 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
98 * @param callable $callback
100 * @see DeferredUpdates::addCallableUpdate for callback signiture
102 * @return ScopedCallback to reset the overridden value
103 * @throws MWException
105 public function overrideDeferredUpdatesAddCallableUpdateCallback( callable
$callback ) {
106 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
107 throw new MWException(
108 'Cannot override DeferredUpdates::addCallableUpdate callback in operation.'
111 $previousValue = $this->deferredUpdatesAddCallableUpdateCallback
;
112 $this->deferredUpdatesAddCallableUpdateCallback
= $callback;
113 return new ScopedCallback( function () use ( $previousValue ) {
114 $this->deferredUpdatesAddCallableUpdateCallback
= $previousValue;
119 * Overrides the Revision::getTimestampFromId callback
120 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
122 * @param callable $callback
123 * @see Revision::getTimestampFromId for callback signiture
125 * @return ScopedCallback to reset the overridden value
126 * @throws MWException
128 public function overrideRevisionGetTimestampFromIdCallback( callable
$callback ) {
129 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
130 throw new MWException(
131 'Cannot override Revision::getTimestampFromId callback in operation.'
134 $previousValue = $this->revisionGetTimestampFromIdCallback
;
135 $this->revisionGetTimestampFromIdCallback
= $callback;
136 return new ScopedCallback( function () use ( $previousValue ) {
137 $this->revisionGetTimestampFromIdCallback
= $previousValue;
141 private function getCacheKey( User
$user, LinkTarget
$target ) {
142 return $this->cache
->makeKey(
143 (string)$target->getNamespace(),
145 (string)$user->getId()
149 private function cache( WatchedItem
$item ) {
150 $user = $item->getUser();
151 $target = $item->getLinkTarget();
152 $key = $this->getCacheKey( $user, $target );
153 $this->cache
->set( $key, $item );
154 $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] = $key;
155 $this->stats
->increment( 'WatchedItemStore.cache' );
158 private function uncache( User
$user, LinkTarget
$target ) {
159 $this->cache
->delete( $this->getCacheKey( $user, $target ) );
160 unset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] );
161 $this->stats
->increment( 'WatchedItemStore.uncache' );
164 private function uncacheLinkTarget( LinkTarget
$target ) {
165 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget' );
166 if ( !isset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] ) ) {
169 foreach ( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] as $key ) {
170 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget.items' );
171 $this->cache
->delete( $key );
175 private function uncacheUser( User
$user ) {
176 $this->stats
->increment( 'WatchedItemStore.uncacheUser' );
177 foreach ( $this->cacheIndex
as $ns => $dbKeyArray ) {
178 foreach ( $dbKeyArray as $dbKey => $userArray ) {
179 if ( isset( $userArray[$user->getId()] ) ) {
180 $this->stats
->increment( 'WatchedItemStore.uncacheUser.items' );
181 $this->cache
->delete( $userArray[$user->getId()] );
189 * @param LinkTarget $target
191 * @return WatchedItem|false
193 private function getCached( User
$user, LinkTarget
$target ) {
194 return $this->cache
->get( $this->getCacheKey( $user, $target ) );
198 * Return an array of conditions to select or update the appropriate database
202 * @param LinkTarget $target
206 private function dbCond( User
$user, LinkTarget
$target ) {
208 'wl_user' => $user->getId(),
209 'wl_namespace' => $target->getNamespace(),
210 'wl_title' => $target->getDBkey(),
215 * @param int $dbIndex DB_MASTER or DB_REPLICA
218 * @throws MWException
220 private function getConnectionRef( $dbIndex ) {
221 return $this->loadBalancer
->getConnectionRef( $dbIndex, [ 'watchlist' ] );
225 * Deletes ALL watched items for the given user when under
226 * $updateRowsPerQuery entries exist.
232 * @return bool true on success, false when too many items are watched
234 public function clearUserWatchedItems( User
$user ) {
235 if ( $this->countWatchedItems( $user ) > $this->updateRowsPerQuery
) {
239 $dbw = $this->loadBalancer
->getConnectionRef( DB_MASTER
);
242 [ 'wl_user' => $user->getId() ],
245 $this->uncacheAllItemsForUser( $user );
250 private function uncacheAllItemsForUser( User
$user ) {
251 $userId = $user->getId();
252 foreach ( $this->cacheIndex
as $ns => $dbKeyIndex ) {
253 foreach ( $dbKeyIndex as $dbKey => $userIndex ) {
254 if ( array_key_exists( $userId, $userIndex ) ) {
255 $this->cache
->delete( $userIndex[$userId] );
256 unset( $this->cacheIndex
[$ns][$dbKey][$userId] );
261 // Cleanup empty cache keys
262 foreach ( $this->cacheIndex
as $ns => $dbKeyIndex ) {
263 foreach ( $dbKeyIndex as $dbKey => $userIndex ) {
264 if ( empty( $this->cacheIndex
[$ns][$dbKey] ) ) {
265 unset( $this->cacheIndex
[$ns][$dbKey] );
268 if ( empty( $this->cacheIndex
[$ns] ) ) {
269 unset( $this->cacheIndex
[$ns] );
275 * Queues a job that will clear the users watchlist using the Job Queue.
281 public function clearUserWatchedItemsUsingJobQueue( User
$user ) {
282 $job = ClearUserWatchlistJob
::newForUser( $user, $this->getMaxId() );
284 JobQueueGroup
::singleton()->push( $job );
289 * @return int The maximum current wl_id
291 public function getMaxId() {
292 $dbr = $this->getConnectionRef( DB_REPLICA
);
293 return (int)$dbr->selectField(
306 public function countWatchedItems( User
$user ) {
307 $dbr = $this->getConnectionRef( DB_REPLICA
);
308 $return = (int)$dbr->selectField(
312 'wl_user' => $user->getId()
322 * @param LinkTarget $target
325 public function countWatchers( LinkTarget
$target ) {
326 $dbr = $this->getConnectionRef( DB_REPLICA
);
327 $return = (int)$dbr->selectField(
331 'wl_namespace' => $target->getNamespace(),
332 'wl_title' => $target->getDBkey(),
342 * @param LinkTarget $target
343 * @param string|int $threshold
346 public function countVisitingWatchers( LinkTarget
$target, $threshold ) {
347 $dbr = $this->getConnectionRef( DB_REPLICA
);
348 $visitingWatchers = (int)$dbr->selectField(
352 'wl_namespace' => $target->getNamespace(),
353 'wl_title' => $target->getDBkey(),
354 'wl_notificationtimestamp >= ' .
355 $dbr->addQuotes( $dbr->timestamp( $threshold ) ) .
356 ' OR wl_notificationtimestamp IS NULL'
361 return $visitingWatchers;
366 * @param LinkTarget[] $targets
367 * @param array $options
370 public function countWatchersMultiple( array $targets, array $options = [] ) {
371 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
373 $dbr = $this->getConnectionRef( DB_REPLICA
);
375 if ( array_key_exists( 'minimumWatchers', $options ) ) {
376 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers'];
379 $lb = new LinkBatch( $targets );
382 [ 'wl_title', 'wl_namespace', 'watchers' => 'COUNT(*)' ],
383 [ $lb->constructSet( 'wl', $dbr ) ],
389 foreach ( $targets as $linkTarget ) {
390 $watchCounts[$linkTarget->getNamespace()][$linkTarget->getDBkey()] = 0;
393 foreach ( $res as $row ) {
394 $watchCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
402 * @param array $targetsWithVisitThresholds
403 * @param int|null $minimumWatchers
406 public function countVisitingWatchersMultiple(
407 array $targetsWithVisitThresholds,
408 $minimumWatchers = null
410 if ( $targetsWithVisitThresholds === [] ) {
411 // No titles requested => no results returned
415 $dbr = $this->getConnectionRef( DB_REPLICA
);
417 $conds = $this->getVisitingWatchersCondition( $dbr, $targetsWithVisitThresholds );
419 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
420 if ( $minimumWatchers !== null ) {
421 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$minimumWatchers;
425 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
432 foreach ( $targetsWithVisitThresholds as list( $target ) ) {
433 /* @var LinkTarget $target */
434 $watcherCounts[$target->getNamespace()][$target->getDBkey()] = 0;
437 foreach ( $res as $row ) {
438 $watcherCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
441 return $watcherCounts;
445 * Generates condition for the query used in a batch count visiting watchers.
447 * @param IDatabase $db
448 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget, last visit threshold)
451 private function getVisitingWatchersCondition(
453 array $targetsWithVisitThresholds
455 $missingTargets = [];
456 $namespaceConds = [];
457 foreach ( $targetsWithVisitThresholds as list( $target, $threshold ) ) {
458 if ( $threshold === null ) {
459 $missingTargets[] = $target;
462 /* @var LinkTarget $target */
463 $namespaceConds[$target->getNamespace()][] = $db->makeList( [
464 'wl_title = ' . $db->addQuotes( $target->getDBkey() ),
466 'wl_notificationtimestamp >= ' . $db->addQuotes( $db->timestamp( $threshold ) ),
467 'wl_notificationtimestamp IS NULL'
473 foreach ( $namespaceConds as $namespace => $pageConds ) {
474 $conds[] = $db->makeList( [
475 'wl_namespace = ' . $namespace,
476 '(' . $db->makeList( $pageConds, LIST_OR
) . ')'
480 if ( $missingTargets ) {
481 $lb = new LinkBatch( $missingTargets );
482 $conds[] = $lb->constructSet( 'wl', $db );
485 return $db->makeList( $conds, LIST_OR
);
491 * @param LinkTarget $target
494 public function getWatchedItem( User
$user, LinkTarget
$target ) {
495 if ( $user->isAnon() ) {
499 $cached = $this->getCached( $user, $target );
501 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.cached' );
504 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.load' );
505 return $this->loadWatchedItem( $user, $target );
511 * @param LinkTarget $target
512 * @return WatchedItem|bool
514 public function loadWatchedItem( User
$user, LinkTarget
$target ) {
515 // Only loggedin user can have a watchlist
516 if ( $user->isAnon() ) {
520 $dbr = $this->getConnectionRef( DB_REPLICA
);
521 $row = $dbr->selectRow(
523 'wl_notificationtimestamp',
524 $this->dbCond( $user, $target ),
532 $item = new WatchedItem(
535 wfTimestampOrNull( TS_MW
, $row->wl_notificationtimestamp
)
537 $this->cache( $item );
545 * @param array $options
546 * @return WatchedItem[]
548 public function getWatchedItemsForUser( User
$user, array $options = [] ) {
549 $options +
= [ 'forWrite' => false ];
552 if ( array_key_exists( 'sort', $options ) ) {
554 ( in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ) ),
555 '$options[\'sort\']',
556 'must be SORT_ASC or SORT_DESC'
558 $dbOptions['ORDER BY'] = [
559 "wl_namespace {$options['sort']}",
560 "wl_title {$options['sort']}"
563 $db = $this->getConnectionRef( $options['forWrite'] ? DB_MASTER
: DB_REPLICA
);
567 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
568 [ 'wl_user' => $user->getId() ],
574 foreach ( $res as $row ) {
575 // @todo: Should we add these to the process cache?
576 $watchedItems[] = new WatchedItem(
578 new TitleValue( (int)$row->wl_namespace
, $row->wl_title
),
579 $row->wl_notificationtimestamp
583 return $watchedItems;
589 * @param LinkTarget $target
592 public function isWatched( User
$user, LinkTarget
$target ) {
593 return (bool)$this->getWatchedItem( $user, $target );
599 * @param LinkTarget[] $targets
602 public function getNotificationTimestampsBatch( User
$user, array $targets ) {
604 foreach ( $targets as $target ) {
605 $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
608 if ( $user->isAnon() ) {
613 foreach ( $targets as $target ) {
614 $cachedItem = $this->getCached( $user, $target );
616 $timestamps[$target->getNamespace()][$target->getDBkey()] =
617 $cachedItem->getNotificationTimestamp();
619 $targetsToLoad[] = $target;
623 if ( !$targetsToLoad ) {
627 $dbr = $this->getConnectionRef( DB_REPLICA
);
629 $lb = new LinkBatch( $targetsToLoad );
632 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
634 $lb->constructSet( 'wl', $dbr ),
635 'wl_user' => $user->getId(),
640 foreach ( $res as $row ) {
641 $timestamps[$row->wl_namespace
][$row->wl_title
] =
642 wfTimestampOrNull( TS_MW
, $row->wl_notificationtimestamp
);
651 * @param LinkTarget $target
653 public function addWatch( User
$user, LinkTarget
$target ) {
654 $this->addWatchBatchForUser( $user, [ $target ] );
660 * @param LinkTarget[] $targets
663 public function addWatchBatchForUser( User
$user, array $targets ) {
664 if ( $this->readOnlyMode
->isReadOnly() ) {
667 // Only loggedin user can have a watchlist
668 if ( $user->isAnon() ) {
678 foreach ( $targets as $target ) {
680 'wl_user' => $user->getId(),
681 'wl_namespace' => $target->getNamespace(),
682 'wl_title' => $target->getDBkey(),
683 'wl_notificationtimestamp' => null,
685 $items[] = new WatchedItem(
690 $this->uncache( $user, $target );
693 $dbw = $this->getConnectionRef( DB_MASTER
);
694 foreach ( array_chunk( $rows, 100 ) as $toInsert ) {
695 // Use INSERT IGNORE to avoid overwriting the notification timestamp
696 // if there's already an entry for this page
697 $dbw->insert( 'watchlist', $toInsert, __METHOD__
, 'IGNORE' );
699 // Update process cache to ensure skin doesn't claim that the current
700 // page is unwatched in the response of action=watch itself (T28292).
701 // This would otherwise be re-queried from a replica by isWatched().
702 foreach ( $items as $item ) {
703 $this->cache( $item );
712 * @param LinkTarget $target
715 public function removeWatch( User
$user, LinkTarget
$target ) {
716 // Only logged in user can have a watchlist
717 if ( $this->readOnlyMode
->isReadOnly() ||
$user->isAnon() ) {
721 $this->uncache( $user, $target );
723 $dbw = $this->getConnectionRef( DB_MASTER
);
724 $dbw->delete( 'watchlist',
726 'wl_user' => $user->getId(),
727 'wl_namespace' => $target->getNamespace(),
728 'wl_title' => $target->getDBkey(),
731 $success = (bool)$dbw->affectedRows();
739 * @param string|int $timestamp
740 * @param LinkTarget[] $targets
743 public function setNotificationTimestampsForUser( User
$user, $timestamp, array $targets = [] ) {
744 // Only loggedin user can have a watchlist
745 if ( $user->isAnon() ) {
749 $dbw = $this->getConnectionRef( DB_MASTER
);
751 $conds = [ 'wl_user' => $user->getId() ];
753 $batch = new LinkBatch( $targets );
754 $conds[] = $batch->constructSet( 'wl', $dbw );
757 if ( $timestamp !== null ) {
758 $timestamp = $dbw->timestamp( $timestamp );
761 $success = $dbw->update(
763 [ 'wl_notificationtimestamp' => $timestamp ],
768 $this->uncacheUser( $user );
773 public function resetAllNotificationTimestampsForUser( User
$user ) {
774 // Only loggedin user can have a watchlist
775 if ( $user->isAnon() ) {
779 // If the page is watched by the user (or may be watched), update the timestamp
780 $job = new ClearWatchlistNotificationsJob(
781 $user->getUserPage(),
782 [ 'userId' => $user->getId(), 'casTime' => time() ]
785 // Try to run this post-send
786 // Calls DeferredUpdates::addCallableUpdate in normal operation
788 $this->deferredUpdatesAddCallableUpdateCallback
,
789 function () use ( $job ) {
797 * @param User $editor
798 * @param LinkTarget $target
799 * @param string|int $timestamp
802 public function updateNotificationTimestamp( User
$editor, LinkTarget
$target, $timestamp ) {
803 $dbw = $this->getConnectionRef( DB_MASTER
);
804 $uids = $dbw->selectFieldValues(
808 'wl_user != ' . intval( $editor->getId() ),
809 'wl_namespace' => $target->getNamespace(),
810 'wl_title' => $target->getDBkey(),
811 'wl_notificationtimestamp IS NULL',
816 $watchers = array_map( 'intval', $uids );
818 // Update wl_notificationtimestamp for all watching users except the editor
820 DeferredUpdates
::addCallableUpdate(
821 function () use ( $timestamp, $watchers, $target, $fname ) {
822 global $wgUpdateRowsPerQuery;
824 $dbw = $this->getConnectionRef( DB_MASTER
);
825 $factory = MediaWikiServices
::getInstance()->getDBLoadBalancerFactory();
826 $ticket = $factory->getEmptyTransactionTicket( $fname );
828 $watchersChunks = array_chunk( $watchers, $wgUpdateRowsPerQuery );
829 foreach ( $watchersChunks as $watchersChunk ) {
830 $dbw->update( 'watchlist',
832 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
833 ], [ /* WHERE - TODO Use wl_id T130067 */
834 'wl_user' => $watchersChunk,
835 'wl_namespace' => $target->getNamespace(),
836 'wl_title' => $target->getDBkey(),
839 if ( count( $watchersChunks ) > 1 ) {
840 $factory->commitAndWaitForReplication(
841 $fname, $ticket, [ 'domain' => $dbw->getDomainID() ]
845 $this->uncacheLinkTarget( $target );
847 DeferredUpdates
::POSTSEND
,
858 * @param Title $title
859 * @param string $force
863 public function resetNotificationTimestamp( User
$user, Title
$title, $force = '', $oldid = 0 ) {
864 // Only loggedin user can have a watchlist
865 if ( $this->readOnlyMode
->isReadOnly() ||
$user->isAnon() ) {
870 if ( $force != 'force' ) {
871 $item = $this->loadWatchedItem( $user, $title );
872 if ( !$item ||
$item->getNotificationTimestamp() === null ) {
877 // If the page is watched by the user (or may be watched), update the timestamp
878 $job = new ActivityUpdateJob(
881 'type' => 'updateWatchlistNotification',
882 'userid' => $user->getId(),
883 'notifTime' => $this->getNotificationTimestamp( $user, $title, $item, $force, $oldid ),
888 // Try to run this post-send
889 // Calls DeferredUpdates::addCallableUpdate in normal operation
891 $this->deferredUpdatesAddCallableUpdateCallback
,
892 function () use ( $job ) {
897 $this->uncache( $user, $title );
902 private function getNotificationTimestamp( User
$user, Title
$title, $item, $force, $oldid ) {
904 // No oldid given, assuming latest revision; clear the timestamp.
908 if ( !$title->getNextRevisionID( $oldid ) ) {
909 // Oldid given and is the latest revision for this title; clear the timestamp.
913 if ( $item === null ) {
914 $item = $this->loadWatchedItem( $user, $title );
918 // This can only happen if $force is enabled.
922 // Oldid given and isn't the latest; update the timestamp.
923 // This will result in no further notification emails being sent!
924 // Calls Revision::getTimestampFromId in normal operation
925 $notificationTimestamp = call_user_func(
926 $this->revisionGetTimestampFromIdCallback
,
931 // We need to go one second to the future because of various strict comparisons
932 // throughout the codebase
933 $ts = new MWTimestamp( $notificationTimestamp );
934 $ts->timestamp
->add( new DateInterval( 'PT1S' ) );
935 $notificationTimestamp = $ts->getTimestamp( TS_MW
);
937 if ( $notificationTimestamp < $item->getNotificationTimestamp() ) {
938 if ( $force != 'force' ) {
941 // This is a little silly…
942 return $item->getNotificationTimestamp();
946 return $notificationTimestamp;
952 * @param int|null $unreadLimit
955 public function countUnreadNotifications( User
$user, $unreadLimit = null ) {
957 if ( $unreadLimit !== null ) {
958 $unreadLimit = (int)$unreadLimit;
959 $queryOptions['LIMIT'] = $unreadLimit;
962 $dbr = $this->getConnectionRef( DB_REPLICA
);
963 $rowCount = $dbr->selectRowCount(
967 'wl_user' => $user->getId(),
968 'wl_notificationtimestamp IS NOT NULL',
974 if ( !isset( $unreadLimit ) ) {
978 if ( $rowCount >= $unreadLimit ) {
987 * @param LinkTarget $oldTarget
988 * @param LinkTarget $newTarget
990 public function duplicateAllAssociatedEntries( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
991 $oldTarget = Title
::newFromLinkTarget( $oldTarget );
992 $newTarget = Title
::newFromLinkTarget( $newTarget );
994 $this->duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
995 $this->duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );
1000 * @param LinkTarget $oldTarget
1001 * @param LinkTarget $newTarget
1003 public function duplicateEntry( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
1004 $dbw = $this->getConnectionRef( DB_MASTER
);
1006 $result = $dbw->select(
1008 [ 'wl_user', 'wl_notificationtimestamp' ],
1010 'wl_namespace' => $oldTarget->getNamespace(),
1011 'wl_title' => $oldTarget->getDBkey(),
1017 $newNamespace = $newTarget->getNamespace();
1018 $newDBkey = $newTarget->getDBkey();
1020 # Construct array to replace into the watchlist
1022 foreach ( $result as $row ) {
1024 'wl_user' => $row->wl_user
,
1025 'wl_namespace' => $newNamespace,
1026 'wl_title' => $newDBkey,
1027 'wl_notificationtimestamp' => $row->wl_notificationtimestamp
,
1031 if ( !empty( $values ) ) {
1033 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
1034 # some other DBMSes, mostly due to poor simulation by us
1037 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],