MediaWiki  1.30.0
WatchedItemStore Class Reference

Storage layer class for WatchedItems. More...

Inheritance diagram for WatchedItemStore:
Collaboration diagram for WatchedItemStore:

Public Member Functions

 __construct (LoadBalancer $loadBalancer, HashBagOStuff $cache, ReadOnlyMode $readOnlyMode)
 
 addWatch (User $user, LinkTarget $target)
 Must be called separately for Subject & Talk namespaces. More...
 
 addWatchBatchForUser (User $user, array $targets)
 
 countUnreadNotifications (User $user, $unreadLimit=null)
 
 countVisitingWatchers (LinkTarget $target, $threshold)
 Number of page watchers who also visited a "recent" edit. More...
 
 countVisitingWatchersMultiple (array $targetsWithVisitThresholds, $minimumWatchers=null)
 Number of watchers of each page who have visited recent edits to that page. More...
 
 countWatchedItems (User $user)
 Count the number of individual items that are watched by the user. More...
 
 countWatchers (LinkTarget $target)
 
 countWatchersMultiple (array $targets, array $options=[])
 
 duplicateAllAssociatedEntries (LinkTarget $oldTarget, LinkTarget $newTarget)
 Check if the given title already is watched by the user, and if so add a watch for the new title. More...
 
 duplicateEntry (LinkTarget $oldTarget, LinkTarget $newTarget)
 Check if the given title already is watched by the user, and if so add a watch for the new title. More...
 
 getNotificationTimestampsBatch (User $user, array $targets)
 
 getWatchedItem (User $user, LinkTarget $target)
 Get an item (may be cached) More...
 
 getWatchedItemsForUser (User $user, array $options=[])
 
 isWatched (User $user, LinkTarget $target)
 Must be called separately for Subject & Talk namespaces. More...
 
 loadWatchedItem (User $user, LinkTarget $target)
 Loads an item from the db. 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...
 
 overrideRevisionGetTimestampFromIdCallback (callable $callback)
 Overrides the Revision::getTimestampFromId callback This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. More...
 
 removeWatch (User $user, LinkTarget $target)
 Removes the an entry for the User watching the LinkTarget Must be called separately for Subject & Talk namespaces. More...
 
 resetNotificationTimestamp (User $user, Title $title, $force='', $oldid=0)
 Reset the notification timestamp of this entry. More...
 
 setNotificationTimestampsForUser (User $user, $timestamp, array $targets=[])
 
 setStatsdDataFactory (StatsdDataFactoryInterface $stats)
 Sets a StatsdDataFactory instance on the object. More...
 
 updateNotificationTimestamp (User $editor, LinkTarget $target, $timestamp)
 

Public Attributes

const SORT_ASC = 'ASC'
 
const SORT_DESC = 'DESC'
 

Private Member Functions

 cache (WatchedItem $item)
 
 dbCond (User $user, LinkTarget $target)
 Return an array of conditions to select or update the appropriate database row. More...
 
 getCached (User $user, LinkTarget $target)
 
 getCacheKey (User $user, LinkTarget $target)
 
 getConnectionRef ( $dbIndex)
 
 getNotificationTimestamp (User $user, Title $title, $item, $force, $oldid)
 
 getVisitingWatchersCondition (IDatabase $db, array $targetsWithVisitThresholds)
 Generates condition for the query used in a batch count visiting watchers. More...
 
 uncache (User $user, LinkTarget $target)
 
 uncacheLinkTarget (LinkTarget $target)
 
 uncacheUser (User $user)
 

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
 
LoadBalancer $loadBalancer
 
ReadOnlyMode $readOnlyMode
 
callable null $revisionGetTimestampFromIdCallback
 
StatsdDataFactoryInterface $stats
 

Detailed Description

Storage layer class for WatchedItems.

Database interaction.

Uses database because this uses User::isAnon

Database

Author
Addshore
Since
1.27

Definition at line 23 of file WatchedItemStore.php.

Constructor & Destructor Documentation

◆ __construct()

WatchedItemStore::__construct ( LoadBalancer  $loadBalancer,
HashBagOStuff  $cache,
ReadOnlyMode  $readOnlyMode 
)
Parameters
LoadBalancer$loadBalancer
HashBagOStuff$cache
ReadOnlyMode$readOnlyMode

Definition at line 71 of file WatchedItemStore.php.

References $cache, $loadBalancer, $readOnlyMode, and cache().

Member Function Documentation

◆ addWatch()

WatchedItemStore::addWatch ( User  $user,
LinkTarget  $target 
)

Must be called separately for Subject & Talk namespaces.

Parameters
User$user
LinkTarget$target

Definition at line 597 of file WatchedItemStore.php.

References addWatchBatchForUser().

◆ addWatchBatchForUser()

WatchedItemStore::addWatchBatchForUser ( User  $user,
array  $targets 
)
Parameters
User$user
LinkTarget[]$targets
Returns
bool success

Definition at line 607 of file WatchedItemStore.php.

References $rows, $user, as, cache(), DB_MASTER, getConnectionRef(), and uncache().

Referenced by addWatch().

◆ cache()

◆ countUnreadNotifications()

WatchedItemStore::countUnreadNotifications ( User  $user,
  $unreadLimit = null 
)
Parameters
User$user
int$unreadLimit
Returns
int|bool The number of unread notifications true if greater than or equal to $unreadLimit

Definition at line 888 of file WatchedItemStore.php.

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

◆ countVisitingWatchers()

WatchedItemStore::countVisitingWatchers ( LinkTarget  $target,
  $threshold 
)

Number of page watchers who also visited a "recent" edit.

Parameters
LinkTarget$target
mixed$thresholdtimestamp accepted by wfTimestamp
Returns
int
Exceptions
DBUnexpectedError
MWException

Definition at line 270 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 
)

Number of watchers of each page who have visited recent edits to that page.

Parameters
array$targetsWithVisitThresholdsarray of pairs (LinkTarget $target, mixed $threshold), $threshold is:
  • a timestamp of the recent edit if $target exists (format accepted by wfTimestamp)
  • null if $target doesn't exist
int | null$minimumWatchers
Returns
array multi-dimensional like $return[$namespaceId][$titleString] = $watchers, where $watchers is an int:
  • if the page exists, number of users watching who have visited the page recently
  • if the page doesn't exist, number of users that have the page on their watchlist
  • 0 means there are no visiting watchers or their number is below the minimumWatchers option (if passed).

Definition at line 342 of file WatchedItemStore.php.

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

◆ countWatchedItems()

WatchedItemStore::countWatchedItems ( User  $user)

Count the number of individual items that are watched by the user.

If a subject and corresponding talk page are watched this will return 2.

Parameters
User$user
Returns
int

Definition at line 226 of file WatchedItemStore.php.

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

◆ countWatchers()

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

Definition at line 245 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 = [] 
)
Parameters
LinkTarget[]$targets
array$optionsAllowed keys: 'minimumWatchers' => int
Returns
array multi dimensional like $return[$namespaceId][$titleString] = int $watchers All targets will be present in the result. 0 either means no watchers or the number of watchers was below the minimumWatchers option if passed.

Definition at line 297 of file WatchedItemStore.php.

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

◆ dbCond()

WatchedItemStore::dbCond ( User  $user,
LinkTarget  $target 
)
private

Return an array of conditions to select or update the appropriate database row.

Parameters
User$user
LinkTarget$target
Returns
array

Definition at line 200 of file WatchedItemStore.php.

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

Referenced by loadWatchedItem().

◆ duplicateAllAssociatedEntries()

WatchedItemStore::duplicateAllAssociatedEntries ( LinkTarget  $oldTarget,
LinkTarget  $newTarget 
)

Check if the given title already is watched by the user, and if so add a watch for the new title.

To be used for page renames and such.

Parameters
LinkTarget$oldTarget
LinkTarget$newTarget

Definition at line 927 of file WatchedItemStore.php.

References duplicateEntry(), and Title\newFromLinkTarget().

◆ duplicateEntry()

WatchedItemStore::duplicateEntry ( LinkTarget  $oldTarget,
LinkTarget  $newTarget 
)

Check if the given title already is watched by the user, and if so add a watch for the new title.

To be used for page renames and such. This must be called separately for Subject and Talk pages

Parameters
LinkTarget$oldTarget
LinkTarget$newTarget

Definition at line 945 of file WatchedItemStore.php.

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

Referenced by duplicateAllAssociatedEntries().

◆ getCached()

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

Definition at line 187 of file WatchedItemStore.php.

References cache(), and getCacheKey().

Referenced by getNotificationTimestampsBatch(), and getWatchedItem().

◆ getCacheKey()

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

◆ getConnectionRef()

◆ getNotificationTimestamp()

WatchedItemStore::getNotificationTimestamp ( User  $user,
Title  $title,
  $item,
  $force,
  $oldid 
)
private

Definition at line 834 of file WatchedItemStore.php.

References $title, and loadWatchedItem().

Referenced by resetNotificationTimestamp().

◆ getNotificationTimestampsBatch()

WatchedItemStore::getNotificationTimestampsBatch ( User  $user,
array  $targets 
)
Parameters
User$user
LinkTarget[]$targets
Returns
array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp, where $timestamp is:
  • string|null value of wl_notificationtimestamp,
  • false if $target is not watched by $user.

Definition at line 545 of file WatchedItemStore.php.

References $dbr, $res, $user, as, DB_REPLICA, getCached(), getConnectionRef(), and wfTimestampOrNull().

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

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

Referenced by countVisitingWatchersMultiple().

◆ getWatchedItem()

WatchedItemStore::getWatchedItem ( User  $user,
LinkTarget  $target 
)

Get an item (may be cached)

Parameters
User$user
LinkTarget$target
Returns
WatchedItem|false

Definition at line 427 of file WatchedItemStore.php.

References $user, getCached(), and loadWatchedItem().

Referenced by isWatched().

◆ getWatchedItemsForUser()

WatchedItemStore::getWatchedItemsForUser ( User  $user,
array  $options = [] 
)
Parameters
User$user
array$optionsAllowed keys: 'forWrite' => bool defaults to false 'sort' => string optional sorting by namespace ID and title one of the self::SORT_* constants
Returns
WatchedItem[]

Definition at line 486 of file WatchedItemStore.php.

References $options, $res, $user, as, DB_MASTER, DB_REPLICA, false, and getConnectionRef().

◆ isWatched()

WatchedItemStore::isWatched ( User  $user,
LinkTarget  $target 
)

Must be called separately for Subject & Talk namespaces.

Parameters
User$user
LinkTarget$target
Returns
bool

Definition at line 532 of file WatchedItemStore.php.

References getWatchedItem().

◆ loadWatchedItem()

WatchedItemStore::loadWatchedItem ( User  $user,
LinkTarget  $target 
)

Loads an item from the db.

Parameters
User$user
LinkTarget$target
Returns
WatchedItem|false

Definition at line 449 of file WatchedItemStore.php.

References $dbr, $user, cache(), DB_REPLICA, dbCond(), getConnectionRef(), and wfTimestampOrNull().

Referenced by getNotificationTimestamp(), getWatchedItem(), and resetNotificationTimestamp().

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

References $deferredUpdatesAddCallableUpdateCallback, and use.

◆ overrideRevisionGetTimestampFromIdCallback()

WatchedItemStore::overrideRevisionGetTimestampFromIdCallback ( callable  $callback)

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

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

Definition at line 122 of file WatchedItemStore.php.

References $revisionGetTimestampFromIdCallback, and use.

◆ removeWatch()

WatchedItemStore::removeWatch ( User  $user,
LinkTarget  $target 
)

Removes the an entry for the User watching the LinkTarget Must be called separately for Subject & Talk namespaces.

Parameters
User$user
LinkTarget$target
Returns
bool success
Exceptions
DBUnexpectedError
MWException

Definition at line 664 of file WatchedItemStore.php.

References $success, $user, DB_MASTER, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\Linker\LinkTarget\getNamespace(), and uncache().

◆ resetNotificationTimestamp()

WatchedItemStore::resetNotificationTimestamp ( User  $user,
Title  $title,
  $force = '',
  $oldid = 0 
)

Reset the notification timestamp of this entry.

Parameters
User$user
Title$title
string$forceWhether to force the write query to be executed even if the page is not watched or the notification timestamp is already NULL. 'force' in order to force
int$oldidThe revision id being viewed. If not given or 0, latest revision is assumed.
Returns
bool success

Definition at line 795 of file WatchedItemStore.php.

References $job, $title, $user, getNotificationTimestamp(), loadWatchedItem(), uncache(), and use.

◆ setNotificationTimestampsForUser()

WatchedItemStore::setNotificationTimestampsForUser ( User  $user,
  $timestamp,
array  $targets = [] 
)
Parameters
User$userThe user to set the timestamp for
string | null$timestampSet the update timestamp to this value
LinkTarget[]$targetsList of targets to update. Default to all targets
Returns
bool success

Definition at line 692 of file WatchedItemStore.php.

References $batch, $success, $user, DB_MASTER, getConnectionRef(), and uncacheUser().

◆ setStatsdDataFactory()

WatchedItemStore::setStatsdDataFactory ( StatsdDataFactoryInterface  $statsFactory)

Sets a StatsdDataFactory instance on the object.

Parameters
StatsdDataFactoryInterface$statsFactory
Returns
null

Implements StatsdAwareInterface.

Definition at line 84 of file WatchedItemStore.php.

References $stats.

◆ uncache()

WatchedItemStore::uncache ( User  $user,
LinkTarget  $target 
)
private

◆ uncacheLinkTarget()

WatchedItemStore::uncacheLinkTarget ( LinkTarget  $target)
private

◆ uncacheUser()

WatchedItemStore::uncacheUser ( User  $user)
private

Definition at line 169 of file WatchedItemStore.php.

References $user, as, and cache().

Referenced by setNotificationTimestampsForUser().

◆ updateNotificationTimestamp()

WatchedItemStore::updateNotificationTimestamp ( User  $editor,
LinkTarget  $target,
  $timestamp 
)
Parameters
User$editorThe editor that triggered the update. Their notification timestamp will not be updated(they have already seen it)
LinkTarget$targetThe target to update timestamps for
string$timestampSet the update timestamp to this value
Returns
int[] Array of user IDs the timestamp has been updated for

Definition at line 730 of file WatchedItemStore.php.

References $editor, $fname, $wgUpdateRowsPerQuery, DeferredUpdates\addCallableUpdate(), as, captcha-old\count, DB_MASTER, getConnectionRef(), MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\Linker\LinkTarget\getNamespace(), global, DeferredUpdates\POSTSEND, uncacheLinkTarget(), and use.

Member Data Documentation

◆ $cache

HashBagOStuff WatchedItemStore::$cache
private

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

◆ $deferredUpdatesAddCallableUpdateCallback

callable null WatchedItemStore::$deferredUpdatesAddCallableUpdateCallback
private

◆ $loadBalancer

LoadBalancer WatchedItemStore::$loadBalancer
private

Definition at line 31 of file WatchedItemStore.php.

Referenced by __construct().

◆ $readOnlyMode

ReadOnlyMode WatchedItemStore::$readOnlyMode
private

Definition at line 36 of file WatchedItemStore.php.

Referenced by __construct().

◆ $revisionGetTimestampFromIdCallback

callable null WatchedItemStore::$revisionGetTimestampFromIdCallback
private

Definition at line 59 of file WatchedItemStore.php.

Referenced by overrideRevisionGetTimestampFromIdCallback().

◆ $stats

StatsdDataFactoryInterface WatchedItemStore::$stats
private

Definition at line 64 of file WatchedItemStore.php.

Referenced by setStatsdDataFactory().

◆ SORT_ASC

◆ SORT_DESC

const WatchedItemStore::SORT_DESC = 'DESC'

Definition at line 25 of file WatchedItemStore.php.

Referenced by ApiQueryWatchlistRaw\run().


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