MediaWiki REL1_37
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, UserFactory $userFactory, TitleFactory $titleFactory)
 
 addWatch (UserIdentity $user, $target, ?string $expiry=null)
 
 addWatchBatchForUser (UserIdentity $user, array $targets, ?string $expiry=null)
 Add multiple items to the user's watchlist.
 
 clearUserWatchedItems (UserIdentity $user)
 Deletes ALL watched items for the given user when under $updateRowsPerQuery entries exist.
 
 clearUserWatchedItemsUsingJobQueue (UserIdentity $user)
 Queues a job that will clear the users watchlist using the Job Queue.
 
 countExpired ()
 Get the number of watchlist items that expire before the current time.
Since
1.35
Returns
int

 
 countUnreadNotifications (UserIdentity $user, $unreadLimit=null)
 
 countVisitingWatchers ( $target, $threshold)
 
 countVisitingWatchersMultiple (array $targetsWithVisitThresholds, $minimumWatchers=null)
 
 countWatchedItems (UserIdentity $user)
 
 countWatchers ( $target)
 
 countWatchersMultiple (array $targets, array $options=[])
 
 duplicateAllAssociatedEntries ( $oldTarget, $newTarget)
 
 duplicateEntry ( $oldTarget, $newTarget)
 
 getLatestNotificationTimestamp ( $timestamp, UserIdentity $user, $target)
 
 getMaxId ()
 
 getNotificationTimestampsBatch (UserIdentity $user, array $targets)
 
 getWatchedItem (UserIdentity $user, $target)
 
 getWatchedItemsForUser (UserIdentity $user, array $options=[])
 
 isTempWatched (UserIdentity $user, $target)
 Check if the user is temporarily watching the page.
 
 isWatched (UserIdentity $user, $target)
 
 loadWatchedItem (UserIdentity $user, $target)
 
 loadWatchedItemsBatch (UserIdentity $user, array $targets)
 
 maybeEnqueueWatchlistExpiryJob ()
 Probabilistically add a job to purge the expired watchlist items, if watchlist expiration is enabled, based on the value of $wgWatchlistPurgeRate.
Since
1.36

 
 mustClearWatchedItemsUsingJobQueue (UserIdentity $user)
 
 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.
 
 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.

 
 removeWatch (UserIdentity $user, $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.
 
 resetNotificationTimestamp (UserIdentity $user, $title, $force='', $oldid=0)
 
 setNotificationTimestampsForUser (UserIdentity $user, $timestamp, array $targets=[])
 Set the "last viewed" timestamps for certain titles on a user's watchlist.
 
 setStatsdDataFactory (StatsdDataFactoryInterface $stats)
 
 updateNotificationTimestamp (UserIdentity $editor, $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=[], $target=null)
 Fetches either a single or all watched items for the given user, or a specific set of items.
 
 fetchWatchedItemsForPage (IDatabase $dbw, $target)
 
 getCached (UserIdentity $user, $target)
 
 getCacheKey (UserIdentity $user, $target)
 
 getConnectionRef ( $dbIndex)
 
 getNotificationTimestamp (UserIdentity $user, $title, $item, $force, $oldid)
 
 getPageSeenKey ( $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.
 
 getWatchedItemFromRow (UserIdentity $user, $target, stdClass $row)
 Construct a new WatchedItem given a row from watchlist/watchlist_expiry.
 
 modifyForExpiry (array &$tables, array &$conds, array &$joinConds, IDatabase $db)
 Helper method to deduplicate logic around queries that need to be modified if watchlist expiration is enabled.
 
 uncache (UserIdentity $user, $target)
 
 uncacheAllItemsForUser (UserIdentity $user)
 
 uncacheLinkTarget ( $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.
 
 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'.
 

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.
 
callable null $deferredUpdatesAddCallableUpdateCallback
 
bool $expiryEnabled
 Correlates to $wgWatchlistExpiry feature flag.
 
HookRunner $hookRunner
 
HashBagOStuff $latestUpdateCache
 
ILBFactory $lbFactory
 
LinkBatchFactory $linkBatchFactory
 
LoadBalancer $loadBalancer
 
string null $maxExpiryDuration
 Maximum configured relative expiry.
 
NamespaceInfo $nsInfo
 
JobQueueGroup $queueGroup
 
ReadOnlyMode $readOnlyMode
 
RevisionLookup $revisionLookup
 
BagOStuff $stash
 
StatsdDataFactoryInterface $stats
 
TitleFactory $titleFactory
 
int $updateRowsPerQuery
 
UserFactory $userFactory
 
float $watchlistPurgeRate
 corresponds to $wgWatchlistPurgeRate value
 

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 29 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,
UserFactory  $userFactory,
TitleFactory  $titleFactory 
)
Parameters
ServiceOptions$options
ILBFactory$lbFactory
JobQueueGroup$queueGroup
BagOStuff$stash
HashBagOStuff$cache
ReadOnlyMode$readOnlyMode
NamespaceInfo$nsInfo
RevisionLookup$revisionLookup
HookContainer$hookContainer
LinkBatchFactory$linkBatchFactory
UserFactory$userFactory
TitleFactory$titleFactory

Definition at line 153 of file WatchedItemStore.php.

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

Member Function Documentation

◆ addWatch()

WatchedItemStore::addWatch ( UserIdentity  $user,
  $target,
?string  $expiry = null 
)
Since
1.27 Method added.
1.35 Accepts $expiry parameter.
Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
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 1053 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 1089 of file WatchedItemStore.php.

◆ cache()

WatchedItemStore::cache ( WatchedItem  $item)
private
Parameters
WatchedItem$item

Definition at line 239 of file WatchedItemStore.php.

References WatchedItem\getTarget(), and WatchedItem\getUserIdentity().

Referenced by __construct().

◆ 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 342 of file WatchedItemStore.php.

◆ 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 429 of file WatchedItemStore.php.

References $job, 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 1848 of file WatchedItemStore.php.

◆ countUnreadNotifications()

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

Implements WatchedItemStoreInterface.

Definition at line 1646 of file WatchedItemStore.php.

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

◆ countVisitingWatchers()

WatchedItemStore::countVisitingWatchers (   $target,
  $threshold 
)
Since
1.27
Parameters
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
string | int$threshold
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 519 of file WatchedItemStore.php.

◆ countVisitingWatchersMultiple()

WatchedItemStore::countVisitingWatchersMultiple ( array  $targetsWithVisitThresholds,
  $minimumWatchers = null 
)
Since
1.27
Parameters
array$targetsWithVisitThresholdsarray of LinkTarget[]|PageIdentity[] (not type hinted since it annoys phan) - deprecated passing LinkTarget[] since 1.36
int | null$minimumWatchers
Returns
int[][] two dimensional array, first is namespace, second is database key, value is the number of watchers

Implements WatchedItemStoreInterface.

Definition at line 669 of file WatchedItemStore.php.

◆ countWatchedItems()

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

Implements WatchedItemStoreInterface.

Definition at line 469 of file WatchedItemStore.php.

◆ countWatchers()

WatchedItemStore::countWatchers (   $target)
Since
1.27
Parameters
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
int

Implements WatchedItemStoreInterface.

Definition at line 492 of file WatchedItemStore.php.

◆ countWatchersMultiple()

WatchedItemStore::countWatchersMultiple ( array  $targets,
array  $options = [] 
)
Since
1.27
Parameters
LinkTarget[] | PageIdentity[]$targetsdeprecated passing LinkTarget[] since 1.36
array$optionsSupported options are:
  • 'minimumWatchers': filter for pages that have at least a minimum number of watchers
Returns
array

Implements WatchedItemStoreInterface.

Definition at line 618 of file WatchedItemStore.php.

◆ duplicateAllAssociatedEntries()

WatchedItemStore::duplicateAllAssociatedEntries (   $oldTarget,
  $newTarget 
)
Since
1.27
Parameters
LinkTarget | PageIdentity$oldTargetdeprecated passing LinkTarget since 1.36
LinkTarget | PageIdentity$newTargetdeprecated passing LinkTarget since 1.36

Implements WatchedItemStoreInterface.

Definition at line 1678 of file WatchedItemStore.php.

◆ duplicateEntry()

WatchedItemStore::duplicateEntry (   $oldTarget,
  $newTarget 
)
Since
1.27
Parameters
LinkTarget | PageIdentity$oldTargetdeprecated passing LinkTarget since 1.36
LinkTarget | PageIdentity$newTargetdeprecated passing LinkTarget since 1.36

Implements WatchedItemStoreInterface.

Definition at line 1696 of file WatchedItemStore.php.

References DB_PRIMARY, and Wikimedia\Rdbms\IDatabase\replace().

◆ fetchWatchedItems()

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

Fetches either a single or all watched items for the given user, or a specific set of items.

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 | LinkTarget[] | PageIdentity | PageIdentity[] | null$targetnull if selecting all watched items - deprecated passing LinkTarget or LinkTarget[] since 1.36
Returns
IResultWrapper|stdClass|false

Definition at line 917 of file WatchedItemStore.php.

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

◆ fetchWatchedItemsForPage()

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

Definition at line 1742 of file WatchedItemStore.php.

◆ getCached()

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

Definition at line 297 of file WatchedItemStore.php.

◆ getCacheKey()

WatchedItemStore::getCacheKey ( UserIdentity  $user,
  $target 
)
private
Parameters
UserIdentity$user
LinkTarget | PageIdentity$target
Returns
string

Definition at line 228 of file WatchedItemStore.php.

◆ getConnectionRef()

WatchedItemStore::getConnectionRef (   $dbIndex)
private
Parameters
int$dbIndexDB_PRIMARY or DB_REPLICA
Returns
IDatabase

Definition at line 306 of file WatchedItemStore.php.

◆ getLatestNotificationTimestamp()

WatchedItemStore::getLatestNotificationTimestamp (   $timestamp,
UserIdentity  $user,
  $target 
)
Parameters
string | null$timestamp
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
bool|string|null

Implements WatchedItemStoreInterface.

Definition at line 1311 of file WatchedItemStore.php.

References wfTimestampOrNull().

◆ getMaxId()

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

Definition at line 454 of file WatchedItemStore.php.

◆ getNotificationTimestamp()

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

Definition at line 1583 of file WatchedItemStore.php.

References $title.

◆ getNotificationTimestampsBatch()

WatchedItemStore::getNotificationTimestampsBatch ( UserIdentity  $user,
array  $targets 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget[]$targets
Returns
(bool|string|null)[][] two dimensional array, first is namespace, second is database key, value is the notification timestamp or null, or false if not available

Implements WatchedItemStoreInterface.

Definition at line 996 of file WatchedItemStore.php.

◆ getPageSeenKey()

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

Definition at line 1571 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 1543 of file WatchedItemStore.php.

◆ getPageSeenTimestampsKey()

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

Definition at line 1559 of file WatchedItemStore.php.

◆ getTitleDbKeysGroupedByNamespace()

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

Definition at line 1826 of file WatchedItemStore.php.

References $title.

◆ 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|PageIdentity, last visit threshold) - deprecated passing LinkTarget since 1.36
Returns
string

Definition at line 722 of file WatchedItemStore.php.

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

◆ getWatchedItem()

WatchedItemStore::getWatchedItem ( UserIdentity  $user,
  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
WatchedItem|false

Implements WatchedItemStoreInterface.

Definition at line 765 of file WatchedItemStore.php.

References MediaWiki\User\UserIdentity\isRegistered().

Referenced by WatchAction\__construct().

◆ getWatchedItemFromRow()

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

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

Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
stdClass$row
Returns
WatchedItem

Definition at line 890 of file WatchedItemStore.php.

◆ getWatchedItemsForUser()

WatchedItemStore::getWatchedItemsForUser ( UserIdentity  $user,
array  $options = [] 
)
Since
1.27
Parameters
UserIdentity$user
array$optionsSupported options are:
  • 'forWrite': whether to use the primary database instead of a replica
  • 'sort': how to sort the titles, either SORT_ASC or SORT_DESC
  • 'sortByExpiry': whether to also sort results by expiration, with temporarily watched titles above titles watched indefinitely and titles expiring soonest at the top
Returns
WatchedItem[]

Implements WatchedItemStoreInterface.

Definition at line 838 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\conditional().

◆ isTempWatched()

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

Check if the user is temporarily watching the page.

Since
1.35
Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 984 of file WatchedItemStore.php.

◆ isWatched()

WatchedItemStore::isWatched ( UserIdentity  $user,
  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 973 of file WatchedItemStore.php.

◆ loadWatchedItem()

WatchedItemStore::loadWatchedItem ( UserIdentity  $user,
  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
WatchedItem|false

Implements WatchedItemStoreInterface.

Definition at line 785 of file WatchedItemStore.php.

◆ loadWatchedItemsBatch()

WatchedItemStore::loadWatchedItemsBatch ( UserIdentity  $user,
array  $targets 
)
Since
1.36
Parameters
UserIdentity$user
LinkTarget[] | PageIdentity[]$targetsdeprecated passing LinkTarget[] since 1.36
Returns
WatchedItem[]|false

Implements WatchedItemStoreInterface.

Definition at line 796 of file WatchedItemStore.php.

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

◆ maybeEnqueueWatchlistExpiryJob()

WatchedItemStore::maybeEnqueueWatchlistExpiryJob ( )

Probabilistically add a job to purge the expired watchlist items, if watchlist expiration is enabled, based on the value of $wgWatchlistPurgeRate.

Since
1.36

Implements WatchedItemStoreInterface.

Definition at line 437 of file WatchedItemStore.php.

◆ modifyForExpiry()

WatchedItemStore::modifyForExpiry ( array &  $tables,
array &  $conds,
array &  $joinConds,
IDatabase  $db 
)
private

Helper method to deduplicate logic around queries that need to be modified if watchlist expiration is enabled.

Parameters
string[]&$tables
array&$conds
array[]&$joinConds
IDatabase$db

Definition at line 319 of file WatchedItemStore.php.

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

◆ mustClearWatchedItemsUsingJobQueue()

WatchedItemStore::mustClearWatchedItemsUsingJobQueue ( UserIdentity  $user)
Parameters
UserIdentity$user
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 391 of file WatchedItemStore.php.

◆ 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 210 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 1861 of file WatchedItemStore.php.

◆ removeWatch()

WatchedItemStore::removeWatch ( UserIdentity  $user,
  $target 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 1231 of file WatchedItemStore.php.

◆ removeWatchBatchForUser()

WatchedItemStore::removeWatchBatchForUser ( UserIdentity  $user,
array  $titles 
)
Parameters
UserIdentity$user
LinkTarget[] | PageIdentity[]$titlesdeprecated passing LinkTarget[] since 1.36
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 548 of file WatchedItemStore.php.

◆ 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 1339 of file WatchedItemStore.php.

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

◆ resetNotificationTimestamp()

WatchedItemStore::resetNotificationTimestamp ( UserIdentity  $user,
  $title,
  $force = '',
  $oldid = 0 
)
Since
1.27
Parameters
UserIdentity$user
LinkTarget | PageIdentity$titledeprecated passing LinkTarget since 1.36
string$force
int$oldid
Returns
bool

Implements WatchedItemStoreInterface.

Definition at line 1441 of file WatchedItemStore.php.

◆ 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 1252 of file WatchedItemStore.php.

◆ setStatsdDataFactory()

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

Implements StatsdAwareInterface.

Definition at line 195 of file WatchedItemStore.php.

References $stats.

◆ uncache()

WatchedItemStore::uncache ( UserIdentity  $user,
  $target 
)
private
Parameters
UserIdentity$user
LinkTarget | PageIdentity$target

Definition at line 252 of file WatchedItemStore.php.

References MediaWiki\User\UserIdentity\getId().

◆ uncacheAllItemsForUser()

WatchedItemStore::uncacheAllItemsForUser ( UserIdentity  $user)
private
Parameters
UserIdentity$user

Definition at line 398 of file WatchedItemStore.php.

References MediaWiki\User\UserIdentity\getId().

◆ uncacheLinkTarget()

WatchedItemStore::uncacheLinkTarget (   $target)
private
Parameters
LinkTarget | PageIdentity$target

Definition at line 261 of file WatchedItemStore.php.

◆ uncacheTitlesForUser()

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

Definition at line 1839 of file WatchedItemStore.php.

References $title.

◆ uncacheUser()

WatchedItemStore::uncacheUser ( UserIdentity  $user)
private
Parameters
UserIdentity$user

Definition at line 275 of file WatchedItemStore.php.

References MediaWiki\User\UserIdentity\getId().

◆ 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 1198 of file WatchedItemStore.php.

◆ updateExpiriesAfterMove()

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

Definition at line 1775 of file WatchedItemStore.php.

References $res, Wikimedia\Rdbms\IDatabase\replace(), and Wikimedia\Rdbms\IDatabase\select().

◆ updateNotificationTimestamp()

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

Implements WatchedItemStoreInterface.

Definition at line 1367 of file WatchedItemStore.php.

◆ 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 1149 of file WatchedItemStore.php.

Member Data Documentation

◆ $cache

HashBagOStuff WatchedItemStore::$cache
private

Definition at line 69 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.

Definition at line 83 of file WatchedItemStore.php.

◆ $deferredUpdatesAddCallableUpdateCallback

callable null WatchedItemStore::$deferredUpdatesAddCallableUpdateCallback
private

◆ $expiryEnabled

bool WatchedItemStore::$expiryEnabled
private

Correlates to $wgWatchlistExpiry feature flag.

Definition at line 113 of file WatchedItemStore.php.

◆ $hookRunner

HookRunner WatchedItemStore::$hookRunner
private

Definition at line 118 of file WatchedItemStore.php.

◆ $latestUpdateCache

HashBagOStuff WatchedItemStore::$latestUpdateCache
private

Definition at line 74 of file WatchedItemStore.php.

◆ $lbFactory

ILBFactory WatchedItemStore::$lbFactory
private

Definition at line 44 of file WatchedItemStore.php.

Referenced by __construct().

◆ $linkBatchFactory

LinkBatchFactory WatchedItemStore::$linkBatchFactory
private

Definition at line 123 of file WatchedItemStore.php.

Referenced by __construct().

◆ $loadBalancer

LoadBalancer WatchedItemStore::$loadBalancer
private

Definition at line 49 of file WatchedItemStore.php.

◆ $maxExpiryDuration

string null WatchedItemStore::$maxExpiryDuration
private

Maximum configured relative expiry.

Definition at line 134 of file WatchedItemStore.php.

◆ $nsInfo

NamespaceInfo WatchedItemStore::$nsInfo
private

Definition at line 98 of file WatchedItemStore.php.

Referenced by __construct().

◆ $queueGroup

JobQueueGroup WatchedItemStore::$queueGroup
private

Definition at line 54 of file WatchedItemStore.php.

Referenced by __construct().

◆ $readOnlyMode

ReadOnlyMode WatchedItemStore::$readOnlyMode
private

Definition at line 64 of file WatchedItemStore.php.

Referenced by __construct().

◆ $revisionLookup

RevisionLookup WatchedItemStore::$revisionLookup
private

Definition at line 103 of file WatchedItemStore.php.

Referenced by __construct().

◆ $stash

BagOStuff WatchedItemStore::$stash
private

Definition at line 59 of file WatchedItemStore.php.

Referenced by __construct().

◆ $stats

StatsdDataFactoryInterface WatchedItemStore::$stats
private

Definition at line 108 of file WatchedItemStore.php.

Referenced by setStatsdDataFactory().

◆ $titleFactory

TitleFactory WatchedItemStore::$titleFactory
private

Definition at line 129 of file WatchedItemStore.php.

Referenced by __construct().

◆ $updateRowsPerQuery

int WatchedItemStore::$updateRowsPerQuery
private

Definition at line 93 of file WatchedItemStore.php.

◆ $userFactory

UserFactory WatchedItemStore::$userFactory
private

Definition at line 126 of file WatchedItemStore.php.

Referenced by __construct().

◆ $watchlistPurgeRate

float WatchedItemStore::$watchlistPurgeRate
private

corresponds to $wgWatchlistPurgeRate value

Definition at line 137 of file WatchedItemStore.php.

◆ CONSTRUCTOR_OPTIONS

const WatchedItemStore::CONSTRUCTOR_OPTIONS
Initial value:
= [
'UpdateRowsPerQuery',
'WatchlistExpiry',
'WatchlistExpiryMaxDuration',
'WatchlistPurgeRate',
]
Access: internal
For use by ServiceWiring

Definition at line 34 of file WatchedItemStore.php.


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