3 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface
;
4 use MediaWiki\MediaWikiServices
;
5 use MediaWiki\Linker\LinkTarget
;
6 use Wikimedia\Assert\Assert
;
9 * Storage layer class for WatchedItems.
10 * Database interaction.
16 class WatchedItemStore
implements StatsdAwareInterface
{
18 const SORT_DESC
= 'DESC';
19 const SORT_ASC
= 'ASC';
24 private $loadBalancer;
32 * @var array[] Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key'
33 * The index is needed so that on mass changes all relevant items can be un-cached.
34 * For example: Clearing a users watchlist of all items or updating notification timestamps
35 * for all users watching a single target.
37 private $cacheIndex = [];
42 private $deferredUpdatesAddCallableUpdateCallback;
47 private $revisionGetTimestampFromIdCallback;
50 * @var StatsdDataFactoryInterface
55 * @param LoadBalancer $loadBalancer
56 * @param HashBagOStuff $cache
58 public function __construct(
59 LoadBalancer
$loadBalancer,
62 $this->loadBalancer
= $loadBalancer;
63 $this->cache
= $cache;
64 $this->stats
= new NullStatsdDataFactory();
65 $this->deferredUpdatesAddCallableUpdateCallback
= [ 'DeferredUpdates', 'addCallableUpdate' ];
66 $this->revisionGetTimestampFromIdCallback
= [ 'Revision', 'getTimestampFromId' ];
69 public function setStatsdDataFactory( StatsdDataFactoryInterface
$stats ) {
70 $this->stats
= $stats;
74 * Overrides the DeferredUpdates::addCallableUpdate callback
75 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
77 * @param callable $callback
79 * @see DeferredUpdates::addCallableUpdate for callback signiture
81 * @return ScopedCallback to reset the overridden value
84 public function overrideDeferredUpdatesAddCallableUpdateCallback( $callback ) {
85 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
86 throw new MWException(
87 'Cannot override DeferredUpdates::addCallableUpdate callback in operation.'
90 Assert
::parameterType( 'callable', $callback, '$callback' );
92 $previousValue = $this->deferredUpdatesAddCallableUpdateCallback
;
93 $this->deferredUpdatesAddCallableUpdateCallback
= $callback;
94 return new ScopedCallback( function() use ( $previousValue ) {
95 $this->deferredUpdatesAddCallableUpdateCallback
= $previousValue;
100 * Overrides the Revision::getTimestampFromId callback
101 * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
103 * @param callable $callback
104 * @see Revision::getTimestampFromId for callback signiture
106 * @return ScopedCallback to reset the overridden value
107 * @throws MWException
109 public function overrideRevisionGetTimestampFromIdCallback( $callback ) {
110 if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
111 throw new MWException(
112 'Cannot override Revision::getTimestampFromId callback in operation.'
115 Assert
::parameterType( 'callable', $callback, '$callback' );
117 $previousValue = $this->revisionGetTimestampFromIdCallback
;
118 $this->revisionGetTimestampFromIdCallback
= $callback;
119 return new ScopedCallback( function() use ( $previousValue ) {
120 $this->revisionGetTimestampFromIdCallback
= $previousValue;
124 private function getCacheKey( User
$user, LinkTarget
$target ) {
125 return $this->cache
->makeKey(
126 (string)$target->getNamespace(),
128 (string)$user->getId()
132 private function cache( WatchedItem
$item ) {
133 $user = $item->getUser();
134 $target = $item->getLinkTarget();
135 $key = $this->getCacheKey( $user, $target );
136 $this->cache
->set( $key, $item );
137 $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] = $key;
138 $this->stats
->increment( 'WatchedItemStore.cache' );
141 private function uncache( User
$user, LinkTarget
$target ) {
142 $this->cache
->delete( $this->getCacheKey( $user, $target ) );
143 unset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()][$user->getId()] );
144 $this->stats
->increment( 'WatchedItemStore.uncache' );
147 private function uncacheLinkTarget( LinkTarget
$target ) {
148 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget' );
149 if ( !isset( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] ) ) {
152 foreach ( $this->cacheIndex
[$target->getNamespace()][$target->getDBkey()] as $key ) {
153 $this->stats
->increment( 'WatchedItemStore.uncacheLinkTarget.items' );
154 $this->cache
->delete( $key );
158 private function uncacheUser( User
$user ) {
159 $this->stats
->increment( 'WatchedItemStore.uncacheUser' );
160 foreach ( $this->cacheIndex
as $ns => $dbKeyArray ) {
161 foreach ( $dbKeyArray as $dbKey => $userArray ) {
162 if ( isset( $userArray[$user->getId()] ) ) {
163 $this->stats
->increment( 'WatchedItemStore.uncacheUser.items' );
164 $this->cache
->delete( $userArray[$user->getId()] );
172 * @param LinkTarget $target
174 * @return WatchedItem|null
176 private function getCached( User
$user, LinkTarget
$target ) {
177 return $this->cache
->get( $this->getCacheKey( $user, $target ) );
181 * Return an array of conditions to select or update the appropriate database
185 * @param LinkTarget $target
189 private function dbCond( User
$user, LinkTarget
$target ) {
191 'wl_user' => $user->getId(),
192 'wl_namespace' => $target->getNamespace(),
193 'wl_title' => $target->getDBkey(),
198 * @param int $slaveOrMaster DB_MASTER or DB_SLAVE
200 * @return DatabaseBase
201 * @throws MWException
203 private function getConnection( $slaveOrMaster ) {
204 return $this->loadBalancer
->getConnection( $slaveOrMaster, [ 'watchlist' ] );
208 * @param DatabaseBase $connection
210 * @throws MWException
212 private function reuseConnection( $connection ) {
213 $this->loadBalancer
->reuseConnection( $connection );
217 * Count the number of individual items that are watched by the user.
218 * If a subject and corresponding talk page are watched this will return 2.
224 public function countWatchedItems( User
$user ) {
225 $dbr = $this->getConnection( DB_SLAVE
);
226 $return = (int)$dbr->selectField(
230 'wl_user' => $user->getId()
234 $this->reuseConnection( $dbr );
240 * @param LinkTarget $target
244 public function countWatchers( LinkTarget
$target ) {
245 $dbr = $this->getConnection( DB_SLAVE
);
246 $return = (int)$dbr->selectField(
250 'wl_namespace' => $target->getNamespace(),
251 'wl_title' => $target->getDBkey(),
255 $this->reuseConnection( $dbr );
261 * Number of page watchers who also visited a "recent" edit
263 * @param LinkTarget $target
264 * @param mixed $threshold timestamp accepted by wfTimestamp
267 * @throws DBUnexpectedError
268 * @throws MWException
270 public function countVisitingWatchers( LinkTarget
$target, $threshold ) {
271 $dbr = $this->getConnection( DB_SLAVE
);
272 $visitingWatchers = (int)$dbr->selectField(
276 'wl_namespace' => $target->getNamespace(),
277 'wl_title' => $target->getDBkey(),
278 'wl_notificationtimestamp >= ' .
279 $dbr->addQuotes( $dbr->timestamp( $threshold ) ) .
280 ' OR wl_notificationtimestamp IS NULL'
284 $this->reuseConnection( $dbr );
286 return $visitingWatchers;
290 * @param LinkTarget[] $targets
291 * @param array $options Allowed keys:
292 * 'minimumWatchers' => int
294 * @return array multi dimensional like $return[$namespaceId][$titleString] = int $watchers
295 * All targets will be present in the result. 0 either means no watchers or the number
296 * of watchers was below the minimumWatchers option if passed.
298 public function countWatchersMultiple( array $targets, array $options = [] ) {
299 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
301 $dbr = $this->getConnection( DB_SLAVE
);
303 if ( array_key_exists( 'minimumWatchers', $options ) ) {
304 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$options['minimumWatchers'];
307 $lb = new LinkBatch( $targets );
310 [ 'wl_title', 'wl_namespace', 'watchers' => 'COUNT(*)' ],
311 [ $lb->constructSet( 'wl', $dbr ) ],
316 $this->reuseConnection( $dbr );
319 foreach ( $targets as $linkTarget ) {
320 $watchCounts[$linkTarget->getNamespace()][$linkTarget->getDBkey()] = 0;
323 foreach ( $res as $row ) {
324 $watchCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
331 * Number of watchers of each page who have visited recent edits to that page
333 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget $target, mixed $threshold),
335 * - a timestamp of the recent edit if $target exists (format accepted by wfTimestamp)
336 * - null if $target doesn't exist
337 * @param int|null $minimumWatchers
338 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $watchers,
339 * where $watchers is an int:
340 * - if the page exists, number of users watching who have visited the page recently
341 * - if the page doesn't exist, number of users that have the page on their watchlist
342 * - 0 means there are no visiting watchers or their number is below the minimumWatchers
343 * option (if passed).
345 public function countVisitingWatchersMultiple(
346 array $targetsWithVisitThresholds,
347 $minimumWatchers = null
349 $dbr = $this->getConnection( DB_SLAVE
);
351 $conds = $this->getVisitingWatchersCondition( $dbr, $targetsWithVisitThresholds );
353 $dbOptions = [ 'GROUP BY' => [ 'wl_namespace', 'wl_title' ] ];
354 if ( $minimumWatchers !== null ) {
355 $dbOptions['HAVING'] = 'COUNT(*) >= ' . (int)$minimumWatchers;
359 [ 'wl_namespace', 'wl_title', 'watchers' => 'COUNT(*)' ],
365 $this->reuseConnection( $dbr );
368 foreach ( $targetsWithVisitThresholds as list( $target ) ) {
369 /* @var LinkTarget $target */
370 $watcherCounts[$target->getNamespace()][$target->getDBkey()] = 0;
373 foreach ( $res as $row ) {
374 $watcherCounts[$row->wl_namespace
][$row->wl_title
] = (int)$row->watchers
;
377 return $watcherCounts;
381 * Generates condition for the query used in a batch count visiting watchers.
383 * @param IDatabase $db
384 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget, last visit threshold)
387 private function getVisitingWatchersCondition(
389 array $targetsWithVisitThresholds
391 $missingTargets = [];
392 $namespaceConds = [];
393 foreach ( $targetsWithVisitThresholds as list( $target, $threshold ) ) {
394 if ( $threshold === null ) {
395 $missingTargets[] = $target;
398 /* @var LinkTarget $target */
399 $namespaceConds[$target->getNamespace()][] = $db->makeList( [
400 'wl_title = ' . $db->addQuotes( $target->getDBkey() ),
402 'wl_notificationtimestamp >= ' . $db->addQuotes( $db->timestamp( $threshold ) ),
403 'wl_notificationtimestamp IS NULL'
409 foreach ( $namespaceConds as $namespace => $pageConds ) {
410 $conds[] = $db->makeList( [
411 'wl_namespace = ' . $namespace,
412 '(' . $db->makeList( $pageConds, LIST_OR
) . ')'
416 if ( $missingTargets ) {
417 $lb = new LinkBatch( $missingTargets );
418 $conds[] = $lb->constructSet( 'wl', $db );
421 return $db->makeList( $conds, LIST_OR
);
425 * Get an item (may be cached)
428 * @param LinkTarget $target
430 * @return WatchedItem|false
432 public function getWatchedItem( User
$user, LinkTarget
$target ) {
433 if ( $user->isAnon() ) {
437 $cached = $this->getCached( $user, $target );
439 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.cached' );
442 $this->stats
->increment( 'WatchedItemStore.getWatchedItem.load' );
443 return $this->loadWatchedItem( $user, $target );
447 * Loads an item from the db
450 * @param LinkTarget $target
452 * @return WatchedItem|false
454 public function loadWatchedItem( User
$user, LinkTarget
$target ) {
455 // Only loggedin user can have a watchlist
456 if ( $user->isAnon() ) {
460 $dbr = $this->getConnection( DB_SLAVE
);
461 $row = $dbr->selectRow(
463 'wl_notificationtimestamp',
464 $this->dbCond( $user, $target ),
467 $this->reuseConnection( $dbr );
473 $item = new WatchedItem(
476 $row->wl_notificationtimestamp
478 $this->cache( $item );
485 * @param array $options Allowed keys:
486 * 'forWrite' => bool defaults to false
487 * 'sort' => string optional sorting by namespace ID and title
488 * one of the self::SORT_* constants
490 * @return WatchedItem[]
492 public function getWatchedItemsForUser( User
$user, array $options = [] ) {
493 $options +
= [ 'forWrite' => false ];
496 if ( array_key_exists( 'sort', $options ) ) {
498 ( in_array( $options['sort'], [ self
::SORT_ASC
, self
::SORT_DESC
] ) ),
499 '$options[\'sort\']',
500 'must be SORT_ASC or SORT_DESC'
502 $dbOptions['ORDER BY'] = [
503 "wl_namespace {$options['sort']}",
504 "wl_title {$options['sort']}"
507 $db = $this->getConnection( $options['forWrite'] ? DB_MASTER
: DB_SLAVE
);
511 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
512 [ 'wl_user' => $user->getId() ],
516 $this->reuseConnection( $db );
519 foreach ( $res as $row ) {
520 // todo these could all be cached at some point?
521 $watchedItems[] = new WatchedItem(
523 new TitleValue( (int)$row->wl_namespace
, $row->wl_title
),
524 $row->wl_notificationtimestamp
528 return $watchedItems;
532 * Must be called separately for Subject & Talk namespaces
535 * @param LinkTarget $target
539 public function isWatched( User
$user, LinkTarget
$target ) {
540 return (bool)$this->getWatchedItem( $user, $target );
545 * @param LinkTarget[] $targets
547 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp,
548 * where $timestamp is:
549 * - string|null value of wl_notificationtimestamp,
550 * - false if $target is not watched by $user.
552 public function getNotificationTimestampsBatch( User
$user, array $targets ) {
554 foreach ( $targets as $target ) {
555 $timestamps[$target->getNamespace()][$target->getDBkey()] = false;
558 if ( $user->isAnon() ) {
563 foreach ( $targets as $target ) {
564 $cachedItem = $this->getCached( $user, $target );
566 $timestamps[$target->getNamespace()][$target->getDBkey()] =
567 $cachedItem->getNotificationTimestamp();
569 $targetsToLoad[] = $target;
573 if ( !$targetsToLoad ) {
577 $dbr = $this->getConnection( DB_SLAVE
);
579 $lb = new LinkBatch( $targetsToLoad );
582 [ 'wl_namespace', 'wl_title', 'wl_notificationtimestamp' ],
584 $lb->constructSet( 'wl', $dbr ),
585 'wl_user' => $user->getId(),
589 $this->reuseConnection( $dbr );
591 foreach ( $res as $row ) {
592 $timestamps[$row->wl_namespace
][$row->wl_title
] = $row->wl_notificationtimestamp
;
599 * Must be called separately for Subject & Talk namespaces
602 * @param LinkTarget $target
604 public function addWatch( User
$user, LinkTarget
$target ) {
605 $this->addWatchBatchForUser( $user, [ $target ] );
610 * @param LinkTarget[] $targets
612 * @return bool success
614 public function addWatchBatchForUser( User
$user, array $targets ) {
615 if ( $this->loadBalancer
->getReadOnlyReason() !== false ) {
618 // Only loggedin user can have a watchlist
619 if ( $user->isAnon() ) {
628 foreach ( $targets as $target ) {
630 'wl_user' => $user->getId(),
631 'wl_namespace' => $target->getNamespace(),
632 'wl_title' => $target->getDBkey(),
633 'wl_notificationtimestamp' => null,
635 $this->uncache( $user, $target );
638 $dbw = $this->getConnection( DB_MASTER
);
639 foreach ( array_chunk( $rows, 100 ) as $toInsert ) {
640 // Use INSERT IGNORE to avoid overwriting the notification timestamp
641 // if there's already an entry for this page
642 $dbw->insert( 'watchlist', $toInsert, __METHOD__
, 'IGNORE' );
644 $this->reuseConnection( $dbw );
650 * Removes the an entry for the User watching the LinkTarget
651 * Must be called separately for Subject & Talk namespaces
654 * @param LinkTarget $target
656 * @return bool success
657 * @throws DBUnexpectedError
658 * @throws MWException
660 public function removeWatch( User
$user, LinkTarget
$target ) {
661 // Only logged in user can have a watchlist
662 if ( $this->loadBalancer
->getReadOnlyReason() !== false ||
$user->isAnon() ) {
666 $this->uncache( $user, $target );
668 $dbw = $this->getConnection( DB_MASTER
);
669 $dbw->delete( 'watchlist',
671 'wl_user' => $user->getId(),
672 'wl_namespace' => $target->getNamespace(),
673 'wl_title' => $target->getDBkey(),
676 $success = (bool)$dbw->affectedRows();
677 $this->reuseConnection( $dbw );
683 * @param User $user The user to set the timestamp for
684 * @param string $timestamp Set the update timestamp to this value
685 * @param LinkTarget[] $targets List of targets to update. Default to all targets
687 * @return bool success
689 public function setNotificationTimestampsForUser( User
$user, $timestamp, array $targets = [] ) {
690 // Only loggedin user can have a watchlist
691 if ( $user->isAnon() ) {
695 $dbw = $this->getConnection( DB_MASTER
);
697 $conds = [ 'wl_user' => $user->getId() ];
699 $batch = new LinkBatch( $targets );
700 $conds[] = $batch->constructSet( 'wl', $dbw );
703 $success = $dbw->update(
705 [ 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp ) ],
710 $this->reuseConnection( $dbw );
712 $this->uncacheUser( $user );
718 * @param User $editor The editor that triggered the update. Their notification
719 * timestamp will not be updated(they have already seen it)
720 * @param LinkTarget $target The target to update timestamps for
721 * @param string $timestamp Set the update timestamp to this value
723 * @return int[] Array of user IDs the timestamp has been updated for
725 public function updateNotificationTimestamp( User
$editor, LinkTarget
$target, $timestamp ) {
726 $dbw = $this->getConnection( DB_MASTER
);
727 $res = $dbw->select( [ 'watchlist' ],
730 'wl_user != ' . intval( $editor->getId() ),
731 'wl_namespace' => $target->getNamespace(),
732 'wl_title' => $target->getDBkey(),
733 'wl_notificationtimestamp IS NULL',
738 foreach ( $res as $row ) {
739 $watchers[] = intval( $row->wl_user
);
743 // Update wl_notificationtimestamp for all watching users except the editor
745 $dbw->onTransactionIdle(
746 function () use ( $dbw, $timestamp, $watchers, $target, $fname ) {
747 global $wgUpdateRowsPerQuery;
749 $watchersChunks = array_chunk( $watchers, $wgUpdateRowsPerQuery );
750 foreach ( $watchersChunks as $watchersChunk ) {
751 $dbw->update( 'watchlist',
753 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
754 ], [ /* WHERE - TODO Use wl_id T130067 */
755 'wl_user' => $watchersChunk,
756 'wl_namespace' => $target->getNamespace(),
757 'wl_title' => $target->getDBkey(),
760 if ( count( $watchersChunks ) > 1 ) {
761 $dbw->commit( __METHOD__
, 'flush' );
762 wfGetLBFactory()->waitForReplication( [ 'wiki' => $dbw->getWikiID() ] );
765 $this->uncacheLinkTarget( $target );
770 $this->reuseConnection( $dbw );
776 * Reset the notification timestamp of this entry
779 * @param Title $title
780 * @param string $force Whether to force the write query to be executed even if the
781 * page is not watched or the notification timestamp is already NULL.
782 * 'force' in order to force
783 * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
785 * @return bool success
787 public function resetNotificationTimestamp( User
$user, Title
$title, $force = '', $oldid = 0 ) {
788 // Only loggedin user can have a watchlist
789 if ( $this->loadBalancer
->getReadOnlyReason() !== false ||
$user->isAnon() ) {
794 if ( $force != 'force' ) {
795 $item = $this->loadWatchedItem( $user, $title );
796 if ( !$item ||
$item->getNotificationTimestamp() === null ) {
801 // If the page is watched by the user (or may be watched), update the timestamp
802 $job = new ActivityUpdateJob(
805 'type' => 'updateWatchlistNotification',
806 'userid' => $user->getId(),
807 'notifTime' => $this->getNotificationTimestamp( $user, $title, $item, $force, $oldid ),
812 // Try to run this post-send
813 // Calls DeferredUpdates::addCallableUpdate in normal operation
815 $this->deferredUpdatesAddCallableUpdateCallback
,
816 function() use ( $job ) {
821 $this->uncache( $user, $title );
826 private function getNotificationTimestamp( User
$user, Title
$title, $item, $force, $oldid ) {
828 // No oldid given, assuming latest revision; clear the timestamp.
832 if ( !$title->getNextRevisionID( $oldid ) ) {
833 // Oldid given and is the latest revision for this title; clear the timestamp.
837 if ( $item === null ) {
838 $item = $this->loadWatchedItem( $user, $title );
842 // This can only happen if $force is enabled.
846 // Oldid given and isn't the latest; update the timestamp.
847 // This will result in no further notification emails being sent!
848 // Calls Revision::getTimestampFromId in normal operation
849 $notificationTimestamp = call_user_func(
850 $this->revisionGetTimestampFromIdCallback
,
855 // We need to go one second to the future because of various strict comparisons
856 // throughout the codebase
857 $ts = new MWTimestamp( $notificationTimestamp );
858 $ts->timestamp
->add( new DateInterval( 'PT1S' ) );
859 $notificationTimestamp = $ts->getTimestamp( TS_MW
);
861 if ( $notificationTimestamp < $item->getNotificationTimestamp() ) {
862 if ( $force != 'force' ) {
865 // This is a little silly…
866 return $item->getNotificationTimestamp();
870 return $notificationTimestamp;
875 * @param int $unreadLimit
877 * @return int|bool The number of unread notifications
878 * true if greater than or equal to $unreadLimit
880 public function countUnreadNotifications( User
$user, $unreadLimit = null ) {
882 if ( $unreadLimit !== null ) {
883 $unreadLimit = (int)$unreadLimit;
884 $queryOptions['LIMIT'] = $unreadLimit;
887 $dbr = $this->getConnection( DB_SLAVE
);
888 $rowCount = $dbr->selectRowCount(
892 'wl_user' => $user->getId(),
893 'wl_notificationtimestamp IS NOT NULL',
898 $this->reuseConnection( $dbr );
900 if ( !isset( $unreadLimit ) ) {
904 if ( $rowCount >= $unreadLimit ) {
912 * Check if the given title already is watched by the user, and if so
913 * add a watch for the new title.
915 * To be used for page renames and such.
917 * @param LinkTarget $oldTarget
918 * @param LinkTarget $newTarget
920 public function duplicateAllAssociatedEntries( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
921 $oldTarget = Title
::newFromLinkTarget( $oldTarget );
922 $newTarget = Title
::newFromLinkTarget( $newTarget );
924 $this->duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
925 $this->duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );
929 * Check if the given title already is watched by the user, and if so
930 * add a watch for the new title.
932 * To be used for page renames and such.
933 * This must be called separately for Subject and Talk pages
935 * @param LinkTarget $oldTarget
936 * @param LinkTarget $newTarget
938 public function duplicateEntry( LinkTarget
$oldTarget, LinkTarget
$newTarget ) {
939 $dbw = $this->getConnection( DB_MASTER
);
941 $result = $dbw->select(
943 [ 'wl_user', 'wl_notificationtimestamp' ],
945 'wl_namespace' => $oldTarget->getNamespace(),
946 'wl_title' => $oldTarget->getDBkey(),
952 $newNamespace = $newTarget->getNamespace();
953 $newDBkey = $newTarget->getDBkey();
955 # Construct array to replace into the watchlist
957 foreach ( $result as $row ) {
959 'wl_user' => $row->wl_user
,
960 'wl_namespace' => $newNamespace,
961 'wl_title' => $newDBkey,
962 'wl_notificationtimestamp' => $row->wl_notificationtimestamp
,
966 if ( !empty( $values ) ) {
968 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
969 # some other DBMSes, mostly due to poor simulation by us
972 [ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
978 $this->reuseConnection( $dbw );