MediaWiki REL1_41
WatchedItemStore Class Reference

Storage layer class for WatchedItems. More...

Inherits WatchedItemStoreInterface, and StatsdAwareInterface.

Collaboration diagram for WatchedItemStore:

Public Member Functions

 __construct (ServiceOptions $options, ILBFactory $lbFactory, JobQueueGroup $queueGroup, BagOStuff $stash, HashBagOStuff $cache, ReadOnlyMode $readOnlyMode, NamespaceInfo $nsInfo, RevisionLookup $revisionLookup, LinkBatchFactory $linkBatchFactory)
 
 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)
 Update wl_notificationtimestamp for all watching users except the editor.
 

Public Attributes

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

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 31 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,
LinkBatchFactory $linkBatchFactory )
Parameters
ServiceOptions$options
ILBFactory$lbFactory
JobQueueGroup$queueGroup
BagOStuff$stash
HashBagOStuff$cache
ReadOnlyMode$readOnlyMode
NamespaceInfo$nsInfo
RevisionLookup$revisionLookup
LinkBatchFactory$linkBatchFactory

Definition at line 136 of file WatchedItemStore.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), and MediaWiki\Config\ServiceOptions\get().

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 978 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 1014 of file WatchedItemStore.php.

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

References $job.

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

References Wikimedia\Rdbms\SelectQueryBuilder\fetchRowCount(), MediaWiki\User\UserIdentity\getId(), Wikimedia\Rdbms\SelectQueryBuilder\limit(), and Wikimedia\Rdbms\SelectQueryBuilder\select().

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

◆ countWatchedItems()

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

Implements WatchedItemStoreInterface.

Definition at line 424 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 442 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 555 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 1612 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 1630 of file WatchedItemStore.php.

References Wikimedia\Rdbms\IDatabase\newReplaceQueryBuilder().

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

References wfTimestampOrNull().

◆ getMaxId()

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

Definition at line 411 of file WatchedItemStore.php.

◆ getNotificationTimestampsBatch()

WatchedItemStore::getNotificationTimestampsBatch ( UserIdentity $user,
array $targets )
Since
1.27
Parameters
UserIdentity$user
LinkTarget[]$targets
Returns
(string|null|false)[][] 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 921 of file WatchedItemStore.php.

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

References MediaWiki\User\UserIdentity\isRegistered().

Referenced by WatchAction\__construct().

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

◆ 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 909 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 898 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 707 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 718 of file WatchedItemStore.php.

References 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 394 of file WatchedItemStore.php.

◆ mustClearWatchedItemsUsingJobQueue()

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

Implements WatchedItemStoreInterface.

Definition at line 348 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

Definition at line 185 of file WatchedItemStore.php.

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

References Wikimedia\Rdbms\IDatabase\newDeleteQueryBuilder().

◆ 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 1162 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 488 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 1280 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 1378 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 1183 of file WatchedItemStore.php.

◆ setStatsdDataFactory()

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

Implements StatsdAwareInterface.

Definition at line 171 of file WatchedItemStore.php.

◆ updateNotificationTimestamp()

WatchedItemStore::updateNotificationTimestamp ( UserIdentity $editor,
$target,
$timestamp )

Update wl_notificationtimestamp for all watching users except the editor.

Since
1.27
Parameters
UserIdentity$editor
LinkTarget | PageIdentity$targetdeprecated passing LinkTarget since 1.36
string | int$timestamp
Returns
int[]

Implements WatchedItemStoreInterface.

Definition at line 1309 of file WatchedItemStore.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

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

Definition at line 36 of file WatchedItemStore.php.


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