107 $this->deferredUpdatesAddCallableUpdateCallback =
108 [ DeferredUpdates::class,
'addCallableUpdate' ];
109 $this->revisionGetTimestampFromIdCallback =
110 [ Revision::class,
'getTimestampFromId' ];
113 $this->latestUpdateCache =
new HashBagOStuff( [
'maxKeys' => 3 ] );
135 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
137 'Cannot override DeferredUpdates::addCallableUpdate callback in operation.'
141 $this->deferredUpdatesAddCallableUpdateCallback = $callback;
142 return new ScopedCallback(
function () use ( $previousValue ) {
158 if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
160 'Cannot override Revision::getTimestampFromId callback in operation.'
164 $this->revisionGetTimestampFromIdCallback = $callback;
165 return new ScopedCallback(
function () use ( $previousValue ) {
171 return $this->
cache->makeKey(
174 (
string)$user->getId()
179 $user = $item->getUser();
180 $target = $item->getLinkTarget();
182 $this->
cache->set( $key, $item );
183 $this->cacheIndex[$target->getNamespace()][$target->getDBkey()][$user->getId()] = $key;
184 $this->stats->increment(
'WatchedItemStore.cache' );
190 $this->stats->increment(
'WatchedItemStore.uncache' );
194 $this->stats->increment(
'WatchedItemStore.uncacheLinkTarget' );
199 $this->stats->increment(
'WatchedItemStore.uncacheLinkTarget.items' );
200 $this->
cache->delete( $key );
205 $this->stats->increment(
'WatchedItemStore.uncacheUser' );
206 foreach ( $this->cacheIndex as $ns => $dbKeyArray ) {
207 foreach ( $dbKeyArray as $dbKey => $userArray ) {
208 if (
isset( $userArray[$user->getId()] ) ) {
209 $this->stats->increment(
'WatchedItemStore.uncacheUser.items' );
210 $this->
cache->delete( $userArray[$user->getId()] );
216 $this->latestUpdateCache->delete( $pageSeenKey );
217 $this->stash->delete( $pageSeenKey );
241 'wl_user' => $user->getId(),
254 return $this->loadBalancer->getConnectionRef( $dbIndex, [
'watchlist' ] );
272 $dbw = $this->loadBalancer->getConnectionRef(
DB_MASTER );
275 [
'wl_user' => $user->getId() ],
284 $userId = $user->getId();
285 foreach ( $this->cacheIndex as $ns => $dbKeyIndex ) {
286 foreach ( $dbKeyIndex as $dbKey => $userIndex ) {
288 $this->
cache->delete( $userIndex[$userId] );
289 unset( $this->cacheIndex[$ns][$dbKey][$userId] );
295 foreach ( $this->cacheIndex as $ns => $dbKeyIndex ) {
296 foreach ( $dbKeyIndex as $dbKey => $userIndex ) {
297 if ( empty( $this->cacheIndex[$ns][$dbKey] ) ) {
298 unset( $this->cacheIndex[$ns][$dbKey] );
301 if ( empty( $this->cacheIndex[$ns] ) ) {
302 unset( $this->cacheIndex[$ns] );
316 $this->queueGroup->push(
$job );
325 return (
int)
$dbr->selectField(
340 $return = (
int)
$dbr->selectField(
344 'wl_user' => $user->getId()
359 $return = (
int)
$dbr->selectField(
380 $visitingWatchers = (
int)
$dbr->selectField(
386 'wl_notificationtimestamp >= ' .
387 $dbr->addQuotes(
$dbr->timestamp( $threshold ) ) .
388 ' OR wl_notificationtimestamp IS NULL'
403 if ( $this->readOnlyMode->isReadOnly() ) {
406 if ( $user->isAnon() ) {
417 $ticket = count(
$titles ) > $this->updateRowsPerQuery ?
418 $this->lbFactory->getEmptyTransactionTicket( __METHOD__ ) :
null;
422 foreach (
$rows as $namespace => $namespaceTitles ) {
423 $rowBatches =
array_chunk( $namespaceTitles, $this->updateRowsPerQuery );
424 foreach ( $rowBatches as $toDelete ) {
425 $dbw->delete(
'watchlist', [
426 'wl_user' => $user->getId(),
427 'wl_namespace' => $namespace,
428 'wl_title' => $toDelete
430 $affectedRows += $dbw->affectedRows();
432 $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
447 $dbOptions = [
'GROUP BY' => [
'wl_namespace',
'wl_title' ] ];
452 $dbOptions[
'HAVING'] =
'COUNT(*) >= ' . (
int)
$options[
'minimumWatchers'];
458 [
'wl_title',
'wl_namespace',
'watchers' =>
'COUNT(*)' ],
459 [ $lb->constructSet(
'wl',
$dbr ) ],
465 foreach ( $targets as $linkTarget ) {
466 $watchCounts[$linkTarget->getNamespace()][$linkTarget->getDBkey()] = 0;
469 foreach (
$res as $row ) {
470 $watchCounts[$row->wl_namespace][$row->wl_title] = (
int)$row->watchers;
483 array $targetsWithVisitThresholds,
484 $minimumWatchers =
null
486 if ( $targetsWithVisitThresholds === [] ) {
495 $dbOptions = [
'GROUP BY' => [
'wl_namespace',
'wl_title' ] ];
496 if ( $minimumWatchers !==
null ) {
497 $dbOptions[
'HAVING'] =
'COUNT(*) >= ' . (
int)$minimumWatchers;
501 [
'wl_namespace',
'wl_title',
'watchers' =>
'COUNT(*)' ],
508 foreach ( $targetsWithVisitThresholds as
list( $target ) ) {
510 $watcherCounts[$target->getNamespace()][$target->getDBkey()] = 0;
513 foreach (
$res as $row ) {
514 $watcherCounts[$row->wl_namespace][$row->wl_title] = (
int)$row->watchers;
529 array $targetsWithVisitThresholds
531 $missingTargets = [];
532 $namespaceConds = [];
533 foreach ( $targetsWithVisitThresholds as
list( $target, $threshold ) ) {
534 if ( $threshold ===
null ) {
535 $missingTargets[] = $target;
539 $namespaceConds[$target->getNamespace()][] = $db->
makeList( [
540 'wl_title = ' . $db->
addQuotes( $target->getDBkey() ),
543 'wl_notificationtimestamp IS NULL'
549 foreach ( $namespaceConds as $namespace => $pageConds ) {
551 'wl_namespace = ' . $namespace,
556 if ( $missingTargets ) {
558 $conds[] = $lb->constructSet(
'wl', $db );
571 if ( $user->isAnon() ) {
575 $cached = $this->
getCached( $user, $target );
577 $this->stats->increment(
'WatchedItemStore.getWatchedItem.cached' );
580 $this->stats->increment(
'WatchedItemStore.getWatchedItem.load' );
592 if ( $user->isAnon() ) {
598 $row =
$dbr->selectRow(
600 'wl_notificationtimestamp',
601 $this->
dbCond( $user, $target ),
614 $this->
cache( $item );
632 '$options[\'sort\']',
633 'must be SORT_ASC or SORT_DESC'
635 $dbOptions[
'ORDER BY'] = [
636 "wl_namespace {$options['sort']}",
637 "wl_title {$options['sort']}"
644 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
645 [
'wl_user' => $user->getId() ],
651 foreach (
$res as $row ) {
652 $target =
new TitleValue( (
int)$row->wl_namespace, $row->wl_title );
656 new TitleValue( (
int)$row->wl_namespace, $row->wl_title ),
657 $this->getLatestNotificationTimestamp(
658 $row->wl_notificationtimestamp, $user, $target )
683 foreach ( $targets as $target ) {
684 $timestamps[$target->getNamespace()][$target->getDBkey()] =
false;
687 if ( $user->isAnon() ) {
692 foreach ( $targets as $target ) {
693 $cachedItem = $this->
getCached( $user, $target );
695 $timestamps[$target->getNamespace()][$target->getDBkey()] =
696 $cachedItem->getNotificationTimestamp();
698 $targetsToLoad[] = $target;
702 if ( !$targetsToLoad ) {
711 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
713 $lb->constructSet(
'wl',
$dbr ),
714 'wl_user' => $user->getId(),
719 foreach (
$res as $row ) {
720 $target =
new TitleValue( (
int)$row->wl_namespace, $row->wl_title );
721 $timestamps[$row->wl_namespace][$row->wl_title] =
723 $row->wl_notificationtimestamp, $user, $target );
747 if ( $this->readOnlyMode->isReadOnly() ) {
751 if ( $user->isAnon() ) {
761 foreach ( $targets as $target ) {
763 'wl_user' => $user->getId(),
764 'wl_namespace' => $target->getNamespace(),
765 'wl_title' => $target->getDBkey(),
766 'wl_notificationtimestamp' =>
null,
773 $this->
uncache( $user, $target );
777 $ticket = count( $targets ) > $this->updateRowsPerQuery ?
778 $this->lbFactory->getEmptyTransactionTicket( __METHOD__ ) :
null;
781 foreach ( $rowBatches as $toInsert ) {
784 $dbw->insert(
'watchlist', $toInsert, __METHOD__,
'IGNORE' );
785 $affectedRows += $dbw->affectedRows();
787 $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
793 foreach ( $items as $item ) {
794 $this->
cache( $item );
830 if ( $user->isAnon() || $this->readOnlyMode->isReadOnly() ) {
843 if ( $timestamp !==
null ) {
844 $timestamp = $dbw->timestamp( $timestamp );
846 $ticket = $this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
847 $affectedSinceWait = 0;
850 foreach (
$rows as $namespace => $namespaceTitles ) {
851 $rowBatches =
array_chunk( $namespaceTitles, $this->updateRowsPerQuery );
852 foreach ( $rowBatches as $toUpdate ) {
855 [
'wl_notificationtimestamp' => $timestamp ],
857 'wl_user' => $user->getId(),
858 'wl_namespace' => $namespace,
859 'wl_title' => $toUpdate
862 $affectedSinceWait += $dbw->affectedRows();
864 if ( $affectedSinceWait >= $this->updateRowsPerQuery ) {
865 $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
866 $affectedSinceWait = 0;
878 if ( $timestamp ===
null ) {
885 $seenTimestamps->get( $this->getPageSeenKey( $target ) ) >= $timestamp
902 if ( $user->isAnon() ) {
908 $user->getUserPage(),
909 [
'userId' => $user->getId(),
'timestamp' => $timestamp,
'casTime' => time() ]
915 $this->deferredUpdatesAddCallableUpdateCallback,
916 function () use (
$job ) {
931 $uids = $dbw->selectFieldValues(
938 'wl_notificationtimestamp IS NULL',
943 $watchers =
array_map(
'intval', $uids );
947 DeferredUpdates::addCallableUpdate(
948 function () use ( $timestamp, $watchers, $target,
$fname ) {
950 $ticket = $this->lbFactory->getEmptyTransactionTicket(
$fname );
952 $watchersChunks =
array_chunk( $watchers, $this->updateRowsPerQuery );
953 foreach ( $watchersChunks as $watchersChunk ) {
954 $dbw->update(
'watchlist',
956 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
958 'wl_user' => $watchersChunk,
963 if ( count( $watchersChunks ) > 1 ) {
964 $this->lbFactory->commitAndWaitForReplication(
965 $fname, $ticket, [
'domain' => $dbw->getDomainID() ]
971 DeferredUpdates::POSTSEND,
991 if ( $this->readOnlyMode->isReadOnly() || $user->isAnon() ) {
995 if ( !Hooks::run(
'BeforeResetNotificationTimestamp', [ &$user, &$title, $force, &$oldid ] ) ) {
1000 if ( $force !=
'force' ) {
1002 if ( !$item || $item->getNotificationTimestamp() ===
null ) {
1009 $this->revisionGetTimestampFromIdCallback,
1011 $oldid ?: $title->getLatestRevID()
1015 $this->stash->merge(
1017 function (
$cache, $key, $current ) use ( $title, $seenTime ) {
1021 if ( $seenTime >
$value->get( $subKey ) ) {
1023 $value->set( $subKey, $seenTime );
1024 $this->latestUpdateCache->set( $key,
$value, IExpiringStore::TTL_PROC_LONG );
1025 }
elseif ( $seenTime ===
false ) {
1028 $this->latestUpdateCache->set( $key,
$value, IExpiringStore::TTL_PROC_LONG );
1035 IExpiringStore::TTL_HOUR
1042 'type' =>
'updateWatchlistNotification',
1043 'userid' => $user->getId(),
1044 'notifTime' => $this->getNotificationTimestamp( $user, $title, $item, $force, $oldid ),
1049 $this->queueGroup->lazyPush(
$job );
1051 $this->
uncache( $user, $title );
1063 return $this->latestUpdateCache->getWithSetCallback(
1065 IExpiringStore::TTL_PROC_LONG,
1066 function () use ( $key ) {
1067 return $this->stash->get( $key ) ?:
null;
1077 return $this->stash->makeGlobalKey(
1078 'watchlist-recent-updates',
1079 $this->lbFactory->getLocalDomainID(),
1089 return "{$target->getNamespace()}:{$target->getDBkey()}";
1098 if ( !$title->getNextRevisionID( $oldid ) ) {
1103 if ( $item ===
null ) {
1116 $this->revisionGetTimestampFromIdCallback,
1125 $notificationTimestamp = $ts->getTimestamp( TS_MW );
1128 if ( $force !=
'force' ) {
1132 return $item->getNotificationTimestamp();
1136 return $notificationTimestamp;
1149 if ( $unreadLimit !==
null ) {
1150 $unreadLimit = (
int)$unreadLimit;
1155 'wl_user' => $user->getId(),
1156 'wl_notificationtimestamp IS NOT NULL'
1159 $rowCount =
$dbr->selectRowCount(
'watchlist',
'1', $conds, __METHOD__, $queryOptions );
1161 if ( $unreadLimit ===
null ) {
1165 if ( $rowCount >= $unreadLimit ) {
1178 $oldTarget = Title::newFromLinkTarget( $oldTarget );
1179 $newTarget = Title::newFromLinkTarget( $newTarget );
1181 $this->
duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
1182 $this->
duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );
1193 $result = $dbw->select(
1195 [
'wl_user',
'wl_notificationtimestamp' ],
1197 'wl_namespace' => $oldTarget->getNamespace(),
1198 'wl_title' => $oldTarget->getDBkey(),
1204 $newNamespace = $newTarget->getNamespace();
1205 $newDBkey = $newTarget->getDBkey();
1207 # Construct array to replace into the watchlist
1209 foreach ( $result as $row ) {
1211 'wl_user' => $row->wl_user,
1214 'wl_notificationtimestamp' => $row->wl_notificationtimestamp,
1218 if ( !empty( $values ) ) {
1220 # Note that multi-row replace is very efficient for MySQL but may be inefficient for
1221 # some other DBMSes, mostly due to poor simulation by us
1224 [ [
'wl_user',
'wl_namespace',
'wl_title' ] ],
1237 foreach (
$titles as $title ) {
1239 $rows[ $title->getNamespace() ][] = $title->getDBkey();
1249 foreach (
$titles as $title ) {
1250 $this->
uncache( $user, $title );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Job for updating user activity like "last viewed" timestamps.
Class representing a cache/ephemeral data store.
static newForUser(User $user, $maxWatchlistId)
Job for clearing all of the "last viewed" timestamps for a user's watchlist, or setting them all to t...
Simple store for keeping values in an associative array for the current process.
Class to handle enqueueing of background jobs.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Library for creating and parsing MW-style timestamps.
Handles a simple LRU key/value map with a maximum number of entries.
A service class for fetching the wiki's current read-only mode.
Represents a page (or page fragment) title within MediaWiki.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Storage layer class for WatchedItems.
getLatestNotificationTimestamp( $timestamp, User $user, LinkTarget $target)
Convert $timestamp to TS_MW or return null if the page was visited since then by $user.
uncacheTitlesForUser(User $user, array $titles)
getCacheKey(User $user, LinkTarget $target)
countWatchedItems(User $user)
uncacheLinkTarget(LinkTarget $target)
callable null $deferredUpdatesAddCallableUpdateCallback
loadWatchedItem(User $user, LinkTarget $target)
removeWatchBatchForUser(User $user, array $titles)
duplicateEntry(LinkTarget $oldTarget, LinkTarget $newTarget)
duplicateAllAssociatedEntries(LinkTarget $oldTarget, LinkTarget $newTarget)
setNotificationTimestampsForUser(User $user, $timestamp, array $targets=[])
Set the "last viewed" timestamps for certain titles on a user's watchlist.
countVisitingWatchersMultiple(array $targetsWithVisitThresholds, $minimumWatchers=null)
countUnreadNotifications(User $user, $unreadLimit=null)
ReadOnlyMode $readOnlyMode
HashBagOStuff $latestUpdateCache
updateNotificationTimestamp(User $editor, LinkTarget $target, $timestamp)
getNotificationTimestamp(User $user, Title $title, $item, $force, $oldid)
uncache(User $user, LinkTarget $target)
countVisitingWatchers(LinkTarget $target, $threshold)
resetAllNotificationTimestampsForUser(User $user, $timestamp=null)
Schedule a DeferredUpdate that sets all of the "last viewed" timestamps for a given user to the same ...
getPageSeenTimestampsKey(User $user)
setStatsdDataFactory(StatsdDataFactoryInterface $stats)
JobQueueGroup $queueGroup
addWatchBatchForUser(User $user, array $targets)
getWatchedItemsForUser(User $user, array $options=[])
dbCond(User $user, LinkTarget $target)
Return an array of conditions to select or update the appropriate database row.
getPageSeenKey(LinkTarget $target)
__construct(ILBFactory $lbFactory, JobQueueGroup $queueGroup, BagOStuff $stash, HashBagOStuff $cache, ReadOnlyMode $readOnlyMode, $updateRowsPerQuery)
callable null $revisionGetTimestampFromIdCallback
uncacheAllItemsForUser(User $user)
getConnectionRef( $dbIndex)
countWatchers(LinkTarget $target)
overrideRevisionGetTimestampFromIdCallback(callable $callback)
Overrides the Revision::getTimestampFromId callback This is intended for use while testing and will f...
resetNotificationTimestamp(User $user, Title $title, $force='', $oldid=0)
addWatch(User $user, LinkTarget $target)
countWatchersMultiple(array $targets, array $options=[])
isWatched(User $user, LinkTarget $target)
clearUserWatchedItemsUsingJobQueue(User $user)
Queues a job that will clear the users watchlist using the Job Queue.
StatsdDataFactoryInterface $stats
getNotificationTimestampsBatch(User $user, array $targets)
getWatchedItem(User $user, LinkTarget $target)
getVisitingWatchersCondition(IDatabase $db, array $targetsWithVisitThresholds)
Generates condition for the query used in a batch count visiting watchers.
removeWatch(User $user, LinkTarget $target)
getTitleDbKeysGroupedByNamespace(array $titles)
getCached(User $user, LinkTarget $target)
getPageSeenTimestamps(User $user)
LoadBalancer $loadBalancer
overrideDeferredUpdatesAddCallableUpdateCallback(callable $callback)
Overrides the DeferredUpdates::addCallableUpdate callback This is intended for use while testing and ...
array[] $cacheIndex
Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key' The index is needed so that on ...
clearUserWatchedItems(User $user)
Deletes ALL watched items for the given user when under $updateRowsPerQuery entries exist.
Representation of a pair of user and title for watchlist entries.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
see documentation in includes Linker php for Linker::makeImageLink & $time
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error etc yourself modifying $error and returning true will cause the contents of $error to be echoed at the top of the edit form as wikitext Return true without altering $error to allow the edit to proceed & $editor
processing should stop and the error should be shown to the user * false
Describes a Statsd aware interface.
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
you have access to all of the normal MediaWiki so you can get a DB use the cache
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(count( $args)< 1) $job