MediaWiki  master
WatchedItemStore Class Reference

Storage layer class for WatchedItems. More...

Inheritance diagram for WatchedItemStore:
Collaboration diagram for WatchedItemStore:

Public Member Functions

 __construct (ServiceOptions $options, ILBFactory $lbFactory, JobQueueGroup $queueGroup, BagOStuff $stash, HashBagOStuff $cache, ReadOnlyMode $readOnlyMode, NamespaceInfo $nsInfo, RevisionLookup $revisionLookup, HookContainer $hookContainer, LinkBatchFactory $linkBatchFactory)
 
 addWatch (UserIdentity $user, LinkTarget $target, ?string $expiry=null)
 
 addWatchBatchForUser (UserIdentity $user, array $targets, ?string $expiry=null)
 Add multiple items to the user's watchlist. More...
 
 clearUserWatchedItems (UserIdentity $user)
 Deletes ALL watched items for the given user when under $updateRowsPerQuery entries exist. More...
 
 clearUserWatchedItemsUsingJobQueue (UserIdentity $user)
 Queues a job that will clear the users watchlist using the Job Queue. More...
 
 countExpired ()
 Get the number of watchlist items that expire before the current time.
Since
1.35
Returns
int
More...
 
 countUnreadNotifications (UserIdentity $user, $unreadLimit=null)
 
 countVisitingWatchers (LinkTarget $target, $threshold)
 
 countVisitingWatchersMultiple (array $targetsWithVisitThresholds, $minimumWatchers=null)
 
 countWatchedItems (UserIdentity $user)
 
 countWatchers (LinkTarget $target)
 
 countWatchersMultiple (array $targets, array $options=[])
 
 duplicateAllAssociatedEntries (LinkTarget $oldTarget, LinkTarget $newTarget)
 
 duplicateEntry (LinkTarget $oldTarget, LinkTarget $newTarget)
 
 enqueueWatchlistExpiryJob (float $watchlistPurgeRate)
 Probabilistically add a job to purge the expired watchlist items.
Since
1.35
Parameters
float$watchlistPurgeRateThe value of the $wgWatchlistPurgeRate configuration variable.
More...
 
 getLatestNotificationTimestamp ( $timestamp, UserIdentity $user, LinkTarget $target)
 Convert $timestamp to TS_MW or return null if the page was visited since then by $user. More...
 
 getMaxId ()
 
 getNotificationTimestampsBatch (UserIdentity $user, array $targets)
 
 getWatchedItem (UserIdentity $user, LinkTarget $target)
 
 getWatchedItemsForUser (UserIdentity $user, array $options=[])
 
 isTempWatched (UserIdentity $user, LinkTarget $target)
 Check if the user is temporarily watching the page. More...
 
 isWatched (UserIdentity $user, LinkTarget $target)
 
 loadWatchedItem (UserIdentity $user, LinkTarget $target)
 
 mustClearWatchedItemsUsingJobQueue (UserIdentity $user)
 Does the size of the users watchlist require clearUserWatchedItemsUsingJobQueue() to be used instead of clearUserWatchedItems() More...
 
 overrideDeferredUpdatesAddCallableUpdateCallback (callable $callback)
 Overrides the DeferredUpdates::addCallableUpdate callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. More...
 
 removeExpired (int $limit, bool $deleteOrphans=false)
 Remove some number of expired watchlist items.
Since
1.35
Parameters
int$limitThe number of items to remove.
bool$deleteOrphansWhether to also delete watchlist_expiry rows that have no related watchlist rows (because not all code knows about the expiry table yet). This runs two extra queries, so is only done from the purgeExpiredWatchlistItems.php maintenance script.
More...
 
 removeWatch (UserIdentity $user, LinkTarget $target)
 
 removeWatchBatchForUser (UserIdentity $user, array $titles)
 
 resetAllNotificationTimestampsForUser (UserIdentity $user, $timestamp=null)
 Schedule a DeferredUpdate that sets all of the "last viewed" timestamps for a given user to the same value. More...
 
 resetNotificationTimestamp (UserIdentity $user, LinkTarget $title, $force='', $oldid=0)
 
 setNotificationTimestampsForUser (UserIdentity $user, $timestamp, array $targets=[])
 Set the "last viewed" timestamps for certain titles on a user's watchlist. More...
 
 setStatsdDataFactory (StatsdDataFactoryInterface $stats)
 
 updateNotificationTimestamp (UserIdentity $editor, LinkTarget $target, $timestamp)
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 
- Public Attributes inherited from WatchedItemStoreInterface
const SORT_ASC = 'ASC'
 
const SORT_DESC = 'DESC'
 

Private Member Functions

 cache (WatchedItem $item)
 
 fetchWatchedItems (IDatabase $db, UserIdentity $user, array $vars, array $options=[], ?LinkTarget $target=null)
 Fetches either a single or all watched items for the given user. More...
 
 fetchWatchedItemsForPage (IDatabase $dbw, LinkTarget $target)
 
 getCached (UserIdentity $user, LinkTarget $target)
 
 getCacheKey (UserIdentity $user, LinkTarget $target)
 
 getConnectionRef ( $dbIndex)
 
 getNotificationTimestamp (UserIdentity $user, LinkTarget $title, $item, $force, $oldid)
 
 getPageSeenKey (LinkTarget $target)
 
 getPageSeenTimestamps (UserIdentity $user)
 
 getPageSeenTimestampsKey (UserIdentity $user)
 
 getTitleDbKeysGroupedByNamespace (array $titles)
 
 getVisitingWatchersCondition (IDatabase $db, array $targetsWithVisitThresholds)
 Generates condition for the query used in a batch count visiting watchers. More...
 
 getWatchedItemFromRow (UserIdentity $user, LinkTarget $target, stdClass $row)
 Construct a new WatchedItem given a row from watchlist/watchlist_expiry. More...
 
 uncache (UserIdentity $user, LinkTarget $target)
 
 uncacheAllItemsForUser (UserIdentity $user)
 
 uncacheLinkTarget (LinkTarget $target)
 
 uncacheTitlesForUser (UserIdentity $user, array $titles)
 
 uncacheUser (UserIdentity $user)
 
 updateExpiries (IDatabase $dbw, string $expiry, string $cond)
 Update the expiries for items found with the given $cond. More...
 
 updateExpiriesAfterMove (IDatabase $dbw, array $expiries, int $namespace, string $dbKey)
 
 updateOrDeleteExpiries (IDatabase $dbw, int $userId, array $rows, ?string $expiry=null)
 Insert/update expiries, or delete them if the expiry is 'infinity'. More...
 

Private Attributes

HashBagOStuff $cache
 
array[][] $cacheIndex = []
 Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key' The index is needed so that on mass changes all relevant items can be un-cached. More...
 
callable null $deferredUpdatesAddCallableUpdateCallback
 
bool $expiryEnabled
 Correlates to $wgWatchlistExpiry feature flag. More...
 
HookRunner $hookRunner
 
HashBagOStuff $latestUpdateCache
 
ILBFactory $lbFactory
 
LinkBatchFactory $linkBatchFactory
 
LoadBalancer $loadBalancer
 
string null $maxExpiryDuration
 Maximum configured relative expiry. More...
 
NamespaceInfo $nsInfo
 
JobQueueGroup $queueGroup
 
ReadOnlyMode $readOnlyMode
 
RevisionLookup $revisionLookup
 
BagOStuff $stash
 
StatsdDataFactoryInterface $stats
 
int $updateRowsPerQuery
 

Detailed Description

Storage layer class for WatchedItems.

Database interaction & caching TODO caching should be factored out into a CachingWatchedItemStore class

Author
Addshore
Since
1.27

Definition at line 27 of file WatchedItemStore.php.

Constructor & Destructor Documentation

◆ __construct()

WatchedItemStore::__construct ( ServiceOptions  $options,
ILBFactory  $lbFactory,
JobQueueGroup  $queueGroup,
BagOStuff  $stash,
HashBagOStuff  $cache,
ReadOnlyMode  $readOnlyMode,
NamespaceInfo  $nsInfo,
RevisionLookup  $revisionLookup,
HookContainer  $hookContainer,
LinkBatchFactory  $linkBatchFactory 
)
Parameters
ServiceOptions$options
ILBFactory$lbFactory
JobQueueGroup$queueGroup
BagOStuff$stash
HashBagOStuff$cache
ReadOnlyMode$readOnlyMode
NamespaceInfo$nsInfo
RevisionLookup$revisionLookup
HookContainer$hookContainer
LinkBatchFactory$linkBatchFactory

Definition at line 139 of file WatchedItemStore.php.

References $cache, $lbFactory, $linkBatchFactory, $nsInfo, $queueGroup, $readOnlyMode, $revisionLookup, $stash, MediaWiki\Config\ServiceOptions\assertRequiredOptions(), cache(), MediaWiki\Config\ServiceOptions\get(), and Wikimedia\Rdbms\ILBFactory\getMainLB().

Member Function Documentation

◆ addWatch()

WatchedItemStore::addWatch ( UserIdentity  $user,
LinkTarget  $target,
?string  $expiry = null 
)
Since
1.27 Method added.
1.35 Accepts $expiry parameter.
Parameters
UserIdentity$user
LinkTarget$target
string | null$expiryOptional expiry in any format acceptable to wfTimestamp(). null will not create an expiry, or leave it unchanged should one already exist.

Implements WatchedItemStoreInterface.

Definition at line 957 of file WatchedItemStore.php.

◆ addWatchBatchForUser()

WatchedItemStore::addWatchBatchForUser ( UserIdentity  $user,
array  $targets,
?string  $expiry = null 
)

Add multiple items to the user's watchlist.

If you know you're adding a single page (and/or its talk page) use self::addWatch(), since it will add the WatchedItem to the process cache.

Since
1.27 Method added.
1.35 Accepts $expiry parameter.
Parameters
UserIdentity$user
LinkTarget[]$targets
string | null$expiryOptional expiry in a format acceptable to wfTimestamp(), null will not create expiries, or leave them unchanged should they already exist.
Returns
bool Whether database transactions were performed.

Implements WatchedItemStoreInterface.

Definition at line 993 of file WatchedItemStore.php.

References DB_MASTER, MediaWiki\User\UserIdentity\getId(), and MediaWiki\User\UserIdentity\isRegistered().

◆ cache()

◆ clearUserWatchedItems()

WatchedItemStore::clearUserWatchedItems ( UserIdentity  $user)

Deletes ALL watched items for the given user when under $updateRowsPerQuery entries exist.

Since
1.30
Parameters
UserIdentity$user
Returns
bool true on success, false when too many items are watched

Implements WatchedItemStoreInterface.

Definition at line 283 of file WatchedItemStore.php.

References DB_MASTER, MediaWiki\User\UserIdentity\getId(), mustClearWatchedItemsUsingJobQueue(), and uncacheAllItemsForUser().

◆ clearUserWatchedItemsUsingJobQueue()

WatchedItemStore::clearUserWatchedItemsUsingJobQueue ( UserIdentity  $user)

Queues a job that will clear the users watchlist using the Job Queue.

Since
1.31
Parameters
UserIdentity$user

Implements WatchedItemStoreInterface.

Definition at line 360 of file WatchedItemStore.php.

References $job, getMaxId(), and ClearUserWatchlistJob\newForUser().

◆ countExpired()

WatchedItemStore::countExpired ( )

Get the number of watchlist items that expire before the current time.

Since
1.35
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 1727 of file WatchedItemStore.php.

References $dbr, and DB_REPLICA.

◆ countUnreadNotifications()

WatchedItemStore::countUnreadNotifications ( UserIdentity  $user,
  $unreadLimit = null 
)
Since
1.27
Parameters
UserIdentity$user
int | null$unreadLimit
Returns
int|bool

Implements WatchedItemStoreInterface.

Definition at line 1527 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, and MediaWiki\User\UserIdentity\getId().

◆ countVisitingWatchers()

WatchedItemStore::countVisitingWatchers ( LinkTarget  $target,
  $threshold 
)
Since
1.27
Parameters
LinkTarget$target
string | int$threshold
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 457 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), and MediaWiki\Linker\LinkTarget\getNamespace().

◆ countVisitingWatchersMultiple()

WatchedItemStore::countVisitingWatchersMultiple ( array  $targetsWithVisitThresholds,
  $minimumWatchers = null 
)
Since
1.27
Parameters
array$targetsWithVisitThresholds
int | null$minimumWatchers
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 604 of file WatchedItemStore.php.

References $dbr, $res, DB_REPLICA, getConnectionRef(), and getVisitingWatchersCondition().

◆ countWatchedItems()

WatchedItemStore::countWatchedItems ( UserIdentity  $user)
Since
1.31
Parameters
UserIdentity$user
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 395 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, getConnectionRef(), and MediaWiki\User\UserIdentity\getId().

Referenced by mustClearWatchedItemsUsingJobQueue().

◆ countWatchers()

WatchedItemStore::countWatchers ( LinkTarget  $target)
Since
1.27
Parameters
LinkTarget$target
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 424 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), and MediaWiki\Linker\LinkTarget\getNamespace().

◆ countWatchersMultiple()

WatchedItemStore::countWatchersMultiple ( array  $targets,
array  $options = [] 
)
Since
1.27
Parameters
LinkTarget[]$targets
array$options
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 556 of file WatchedItemStore.php.

References $dbr, $res, DB_REPLICA, and getConnectionRef().

◆ duplicateAllAssociatedEntries()

WatchedItemStore::duplicateAllAssociatedEntries ( LinkTarget  $oldTarget,
LinkTarget  $newTarget 
)
Since
1.27
Parameters
LinkTarget$oldTarget
LinkTarget$newTarget

Implements WatchedItemStoreInterface.

Definition at line 1559 of file WatchedItemStore.php.

◆ duplicateEntry()

WatchedItemStore::duplicateEntry ( LinkTarget  $oldTarget,
LinkTarget  $newTarget 
)
Since
1.27
Parameters
LinkTarget$oldTarget
LinkTarget$newTarget

Implements WatchedItemStoreInterface.

Definition at line 1576 of file WatchedItemStore.php.

References DB_MASTER, MediaWiki\Linker\LinkTarget\getDBkey(), and MediaWiki\Linker\LinkTarget\getNamespace().

◆ enqueueWatchlistExpiryJob()

WatchedItemStore::enqueueWatchlistExpiryJob ( float  $watchlistPurgeRate)

Probabilistically add a job to purge the expired watchlist items.

Since
1.35
Parameters
float$watchlistPurgeRateThe value of the $wgWatchlistPurgeRate configuration variable.

Implements WatchedItemStoreInterface.

Definition at line 368 of file WatchedItemStore.php.

◆ fetchWatchedItems()

WatchedItemStore::fetchWatchedItems ( IDatabase  $db,
UserIdentity  $user,
array  $vars,
array  $options = [],
?LinkTarget  $target = null 
)
private

Fetches either a single or all watched items for the given user.

If a $target is given, IDatabase::selectRow() is called, otherwise select(). If $wgWatchlistExpiry is enabled, expired items are not returned.

Parameters
IDatabase$db
UserIdentity$user
array$varswe_expiry is added when $wgWatchlistExpiry is enabled.
array$options
LinkTarget | null$targetnull if selecting all watched items.
Returns
IResultWrapper|stdClass|false

Definition at line 832 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\addQuotes(), MediaWiki\User\UserIdentity\getId(), and Wikimedia\Rdbms\IDatabase\timestamp().

Referenced by getWatchedItemsForUser(), and loadWatchedItem().

◆ fetchWatchedItemsForPage()

WatchedItemStore::fetchWatchedItemsForPage ( IDatabase  $dbw,
LinkTarget  $target 
)
private
Parameters
IDatabase$dbw
LinkTarget$target
Returns
IResultWrapper

Definition at line 1622 of file WatchedItemStore.php.

References MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\Linker\LinkTarget\getNamespace(), and Wikimedia\Rdbms\IDatabase\select().

◆ getCached()

WatchedItemStore::getCached ( UserIdentity  $user,
LinkTarget  $target 
)
private
Parameters
UserIdentity$user
LinkTarget$target
Returns
WatchedItem|false

Definition at line 260 of file WatchedItemStore.php.

References cache(), and getCacheKey().

Referenced by getWatchedItem().

◆ getCacheKey()

WatchedItemStore::getCacheKey ( UserIdentity  $user,
LinkTarget  $target 
)
private

◆ getConnectionRef()

WatchedItemStore::getConnectionRef (   $dbIndex)
private

◆ getLatestNotificationTimestamp()

WatchedItemStore::getLatestNotificationTimestamp (   $timestamp,
UserIdentity  $user,
LinkTarget  $target 
)

Convert $timestamp to TS_MW or return null if the page was visited since then by $user.

Use this only on single-user methods (having higher read-after-write expectations) and not in places involving arbitrary batches of different users

Usage of this method should be limited to WatchedItem* classes

Parameters
string | null$timestampValue of wl_notificationtimestamp from the DB
UserIdentity$user
LinkTarget$target
Returns
string|null TS_MW timestamp of first unseen revision or null if there isn't one

Implements WatchedItemStoreInterface.

Definition at line 1207 of file WatchedItemStore.php.

References wfTimestampOrNull().

Referenced by getWatchedItemFromRow().

◆ getMaxId()

WatchedItemStore::getMaxId ( )
Since
1.31
Returns
int The maximum current wl_id

Definition at line 380 of file WatchedItemStore.php.

References $dbr, DB_REPLICA, and getConnectionRef().

Referenced by clearUserWatchedItemsUsingJobQueue().

◆ getNotificationTimestamp()

WatchedItemStore::getNotificationTimestamp ( UserIdentity  $user,
LinkTarget  $title,
  $item,
  $force,
  $oldid 
)
private
Parameters
UserIdentity$user
LinkTarget$title
WatchedItem$item
bool$force
int | bool$oldidThe ID of the last revision that the user viewed
Returns
bool|string|null

Definition at line 1468 of file WatchedItemStore.php.

References $title.

◆ getNotificationTimestampsBatch()

WatchedItemStore::getNotificationTimestampsBatch ( UserIdentity  $user,
array  $targets 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget[]$targets
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 901 of file WatchedItemStore.php.

References $dbr, $res, DB_REPLICA, MediaWiki\User\UserIdentity\getId(), and MediaWiki\User\UserIdentity\isRegistered().

◆ getPageSeenKey()

WatchedItemStore::getPageSeenKey ( LinkTarget  $target)
private
Parameters
LinkTarget$target
Returns
string

Definition at line 1456 of file WatchedItemStore.php.

◆ getPageSeenTimestamps()

WatchedItemStore::getPageSeenTimestamps ( UserIdentity  $user)
private
Parameters
UserIdentity$user
Returns
MapCacheLRU|null The map contains prefixed title keys and TS_MW values

Definition at line 1428 of file WatchedItemStore.php.

◆ getPageSeenTimestampsKey()

WatchedItemStore::getPageSeenTimestampsKey ( UserIdentity  $user)
private
Parameters
UserIdentity$user
Returns
string

Definition at line 1444 of file WatchedItemStore.php.

References MediaWiki\User\UserIdentity\getId().

Referenced by uncacheUser().

◆ getTitleDbKeysGroupedByNamespace()

WatchedItemStore::getTitleDbKeysGroupedByNamespace ( array  $titles)
private
Parameters
LinkTarget[]$titles
Returns
array

Definition at line 1705 of file WatchedItemStore.php.

References $title.

Referenced by removeWatchBatchForUser().

◆ getVisitingWatchersCondition()

WatchedItemStore::getVisitingWatchersCondition ( IDatabase  $db,
array  $targetsWithVisitThresholds 
)
private

Generates condition for the query used in a batch count visiting watchers.

Parameters
IDatabase$db
array$targetsWithVisitThresholdsarray of pairs (LinkTarget, last visit threshold)
Returns
string

Definition at line 660 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\addQuotes(), LIST_AND, LIST_OR, Wikimedia\Rdbms\IDatabase\makeList(), and Wikimedia\Rdbms\IDatabase\timestamp().

Referenced by countVisitingWatchersMultiple().

◆ getWatchedItem()

WatchedItemStore::getWatchedItem ( UserIdentity  $user,
LinkTarget  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget$target
Returns
WatchedItem|false

Implements WatchedItemStoreInterface.

Definition at line 703 of file WatchedItemStore.php.

References getCached(), MediaWiki\User\UserIdentity\isRegistered(), and loadWatchedItem().

◆ getWatchedItemFromRow()

WatchedItemStore::getWatchedItemFromRow ( UserIdentity  $user,
LinkTarget  $target,
stdClass  $row 
)
private

Construct a new WatchedItem given a row from watchlist/watchlist_expiry.

Parameters
UserIdentity$user
LinkTarget$target
stdClass$row
Returns
WatchedItem

Definition at line 806 of file WatchedItemStore.php.

References getLatestNotificationTimestamp(), and wfTimestampOrNull().

Referenced by getWatchedItemsForUser(), and loadWatchedItem().

◆ getWatchedItemsForUser()

WatchedItemStore::getWatchedItemsForUser ( UserIdentity  $user,
array  $options = [] 
)
Since
1.27
Parameters
UserIdentity$user
array$options
Returns
WatchedItem[]

Implements WatchedItemStoreInterface.

Definition at line 755 of file WatchedItemStore.php.

References $res, DB_MASTER, DB_REPLICA, fetchWatchedItems(), getConnectionRef(), and getWatchedItemFromRow().

◆ isTempWatched()

WatchedItemStore::isTempWatched ( UserIdentity  $user,
LinkTarget  $target 
)

Check if the user is temporarily watching the page.

Since
1.35
Parameters
UserIdentity$user
LinkTarget$target
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 890 of file WatchedItemStore.php.

◆ isWatched()

WatchedItemStore::isWatched ( UserIdentity  $user,
LinkTarget  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget$target
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 879 of file WatchedItemStore.php.

◆ loadWatchedItem()

WatchedItemStore::loadWatchedItem ( UserIdentity  $user,
LinkTarget  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget$target
Returns
WatchedItem|false

Implements WatchedItemStoreInterface.

Definition at line 723 of file WatchedItemStore.php.

References $dbr, cache(), DB_REPLICA, fetchWatchedItems(), getConnectionRef(), getWatchedItemFromRow(), and MediaWiki\User\UserIdentity\isRegistered().

Referenced by getWatchedItem().

◆ mustClearWatchedItemsUsingJobQueue()

WatchedItemStore::mustClearWatchedItemsUsingJobQueue ( UserIdentity  $user)

Does the size of the users watchlist require clearUserWatchedItemsUsingJobQueue() to be used instead of clearUserWatchedItems()

Since
1.35
Parameters
UserIdentity$user
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 325 of file WatchedItemStore.php.

References $updateRowsPerQuery, and countWatchedItems().

Referenced by clearUserWatchedItems().

◆ overrideDeferredUpdatesAddCallableUpdateCallback()

WatchedItemStore::overrideDeferredUpdatesAddCallableUpdateCallback ( callable  $callback)

Overrides the DeferredUpdates::addCallableUpdate callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.

Parameters
callable$callback
See also
DeferredUpdates::addCallableUpdate for callback signiture
Returns
ScopedCallback to reset the overridden value
Exceptions
MWException

Definition at line 191 of file WatchedItemStore.php.

References $deferredUpdatesAddCallableUpdateCallback.

◆ removeExpired()

WatchedItemStore::removeExpired ( int  $limit,
bool  $deleteOrphans = false 
)

Remove some number of expired watchlist items.

Since
1.35
Parameters
int$limitThe number of items to remove.
bool$deleteOrphansWhether to also delete watchlist_expiry rows that have no related watchlist rows (because not all code knows about the expiry table yet). This runs two extra queries, so is only done from the purgeExpiredWatchlistItems.php maintenance script.

Implements WatchedItemStoreInterface.

Definition at line 1740 of file WatchedItemStore.php.

References $dbr, DB_MASTER, DB_REPLICA, and LIST_OR.

◆ removeWatch()

WatchedItemStore::removeWatch ( UserIdentity  $user,
LinkTarget  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget$target
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 1135 of file WatchedItemStore.php.

◆ removeWatchBatchForUser()

WatchedItemStore::removeWatchBatchForUser ( UserIdentity  $user,
array  $titles 
)

◆ resetAllNotificationTimestampsForUser()

WatchedItemStore::resetAllNotificationTimestampsForUser ( UserIdentity  $user,
  $timestamp = null 
)

Schedule a DeferredUpdate that sets all of the "last viewed" timestamps for a given user to the same value.

Parameters
UserIdentity$user
string | int | null$timestampValue to set all timestamps to, null to clear them

Implements WatchedItemStoreInterface.

Definition at line 1233 of file WatchedItemStore.php.

References $job, MediaWiki\User\UserIdentity\getId(), and MediaWiki\User\UserIdentity\isRegistered().

◆ resetNotificationTimestamp()

WatchedItemStore::resetNotificationTimestamp ( UserIdentity  $user,
LinkTarget  $title,
  $force = '',
  $oldid = 0 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget$title
string$force
int$oldid
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 1334 of file WatchedItemStore.php.

References $cache, $job, $title, Title\castFromLinkTarget(), MediaWiki\User\UserIdentity\getId(), MediaWiki\User\UserIdentity\isRegistered(), User\newFromId(), and wfTimestamp().

◆ setNotificationTimestampsForUser()

WatchedItemStore::setNotificationTimestampsForUser ( UserIdentity  $user,
  $timestamp,
array  $targets = [] 
)

Set the "last viewed" timestamps for certain titles on a user's watchlist.

If the $targets parameter is omitted or set to [], this method simply wraps resetAllNotificationTimestampsForUser(), and in that case you should instead call that method directly; support for omitting $targets is for backwards compatibility.

If $targets is omitted or set to [], timestamps will be updated for every title on the user's watchlist, and this will be done through a DeferredUpdate. If $targets is a non-empty array, only the specified titles will be updated, and this will be done immediately (not deferred).

Since
1.27
Parameters
UserIdentity$user
string | int$timestampValue to set the "last viewed" timestamp to (null to clear)
LinkTarget[]$targetsTitles to set the timestamp for; [] means the entire watchlist
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 1156 of file WatchedItemStore.php.

References DB_MASTER, MediaWiki\User\UserIdentity\getId(), and MediaWiki\User\UserIdentity\isRegistered().

◆ setStatsdDataFactory()

WatchedItemStore::setStatsdDataFactory ( StatsdDataFactoryInterface  $stats)
Parameters
StatsdDataFactoryInterface$stats

Implements StatsdAwareInterface.

Definition at line 176 of file WatchedItemStore.php.

References $stats.

◆ uncache()

◆ uncacheAllItemsForUser()

WatchedItemStore::uncacheAllItemsForUser ( UserIdentity  $user)
private

Definition at line 329 of file WatchedItemStore.php.

References cache(), and MediaWiki\User\UserIdentity\getId().

Referenced by clearUserWatchedItems().

◆ uncacheLinkTarget()

WatchedItemStore::uncacheLinkTarget ( LinkTarget  $target)
private

◆ uncacheTitlesForUser()

WatchedItemStore::uncacheTitlesForUser ( UserIdentity  $user,
array  $titles 
)
private
Parameters
UserIdentity$user
LinkTarget[]$titles

Definition at line 1718 of file WatchedItemStore.php.

References $title.

Referenced by removeWatchBatchForUser().

◆ uncacheUser()

WatchedItemStore::uncacheUser ( UserIdentity  $user)
private

◆ updateExpiries()

WatchedItemStore::updateExpiries ( IDatabase  $dbw,
string  $expiry,
string  $cond 
)
private

Update the expiries for items found with the given $cond.

Parameters
IDatabase$dbw
string$expiry
string$cond
Returns
int Number of affected rows.

Definition at line 1102 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\affectedRows(), Wikimedia\Rdbms\IDatabase\selectFieldValues(), Wikimedia\Rdbms\IDatabase\timestamp(), and Wikimedia\Rdbms\IDatabase\upsert().

◆ updateExpiriesAfterMove()

WatchedItemStore::updateExpiriesAfterMove ( IDatabase  $dbw,
array  $expiries,
int  $namespace,
string  $dbKey 
)
private
Parameters
IDatabase$dbw
array$expiries
int$namespace
string$dbKey

Definition at line 1655 of file WatchedItemStore.php.

References $res, DeferredUpdates\addCallableUpdate(), Wikimedia\Rdbms\IDatabase\insert(), DeferredUpdates\POSTSEND, and Wikimedia\Rdbms\IDatabase\select().

◆ updateNotificationTimestamp()

WatchedItemStore::updateNotificationTimestamp ( UserIdentity  $editor,
LinkTarget  $target,
  $timestamp 
)
Since
1.27
Parameters
UserIdentity$editor
LinkTarget$target
string | int$timestamp
Returns
int[]

Implements WatchedItemStoreInterface.

Definition at line 1261 of file WatchedItemStore.php.

References DeferredUpdates\addCallableUpdate(), DB_MASTER, MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\User\UserIdentity\getId(), MediaWiki\Linker\LinkTarget\getNamespace(), and DeferredUpdates\POSTSEND.

◆ updateOrDeleteExpiries()

WatchedItemStore::updateOrDeleteExpiries ( IDatabase  $dbw,
int  $userId,
array  $rows,
?string  $expiry = null 
)
private

Insert/update expiries, or delete them if the expiry is 'infinity'.

Parameters
IDatabase$dbw
int$userId
array$rows
string | null$expiry
Returns
int Number of affected rows.

Definition at line 1053 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\affectedRows(), Wikimedia\Rdbms\IDatabase\deleteJoin(), LIST_AND, LIST_OR, Wikimedia\Rdbms\IDatabase\makeList(), and wfIsInfinity().

Member Data Documentation

◆ $cache

HashBagOStuff WatchedItemStore::$cache
private

Definition at line 66 of file WatchedItemStore.php.

Referenced by __construct().

◆ $cacheIndex

array [][] WatchedItemStore::$cacheIndex = []
private

Looks like $cacheIndex[Namespace ID][Target DB Key][User Id] => 'key' The index is needed so that on mass changes all relevant items can be un-cached.

For example: Clearing a users watchlist of all items or updating notification timestamps for all users watching a single target. -var array<int,array<string,array<int,string>>>

Definition at line 80 of file WatchedItemStore.php.

◆ $deferredUpdatesAddCallableUpdateCallback

callable null WatchedItemStore::$deferredUpdatesAddCallableUpdateCallback
private

◆ $expiryEnabled

bool WatchedItemStore::$expiryEnabled
private

Correlates to $wgWatchlistExpiry feature flag.

Definition at line 110 of file WatchedItemStore.php.

◆ $hookRunner

HookRunner WatchedItemStore::$hookRunner
private

Definition at line 115 of file WatchedItemStore.php.

◆ $latestUpdateCache

HashBagOStuff WatchedItemStore::$latestUpdateCache
private

Definition at line 71 of file WatchedItemStore.php.

◆ $lbFactory

ILBFactory WatchedItemStore::$lbFactory
private

Definition at line 41 of file WatchedItemStore.php.

Referenced by __construct().

◆ $linkBatchFactory

LinkBatchFactory WatchedItemStore::$linkBatchFactory
private

Definition at line 120 of file WatchedItemStore.php.

Referenced by __construct().

◆ $loadBalancer

LoadBalancer WatchedItemStore::$loadBalancer
private

Definition at line 46 of file WatchedItemStore.php.

◆ $maxExpiryDuration

string null WatchedItemStore::$maxExpiryDuration
private

Maximum configured relative expiry.

Definition at line 125 of file WatchedItemStore.php.

◆ $nsInfo

NamespaceInfo WatchedItemStore::$nsInfo
private

Definition at line 95 of file WatchedItemStore.php.

Referenced by __construct().

◆ $queueGroup

JobQueueGroup WatchedItemStore::$queueGroup
private

Definition at line 51 of file WatchedItemStore.php.

Referenced by __construct().

◆ $readOnlyMode

ReadOnlyMode WatchedItemStore::$readOnlyMode
private

Definition at line 61 of file WatchedItemStore.php.

Referenced by __construct().

◆ $revisionLookup

RevisionLookup WatchedItemStore::$revisionLookup
private

Definition at line 100 of file WatchedItemStore.php.

Referenced by __construct().

◆ $stash

BagOStuff WatchedItemStore::$stash
private

Definition at line 56 of file WatchedItemStore.php.

Referenced by __construct().

◆ $stats

StatsdDataFactoryInterface WatchedItemStore::$stats
private

Definition at line 105 of file WatchedItemStore.php.

Referenced by setStatsdDataFactory().

◆ $updateRowsPerQuery

int WatchedItemStore::$updateRowsPerQuery
private

Definition at line 90 of file WatchedItemStore.php.

Referenced by mustClearWatchedItemsUsingJobQueue().

◆ CONSTRUCTOR_OPTIONS

const WatchedItemStore::CONSTRUCTOR_OPTIONS
Initial value:
= [
'UpdateRowsPerQuery',
'WatchlistExpiry',
'WatchlistExpiryMaxDuration',
]

Definition at line 32 of file WatchedItemStore.php.


The documentation for this class was generated from the following file: