3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 namespace MediaWiki\Watchlist
;
24 use MediaWiki\Linker\LinkTarget
;
25 use MediaWiki\Page\PageIdentity
;
26 use MediaWiki\User\UserIdentity
;
30 * @since 1.31 interface created. WatchedItemStore implementation available since 1.27
32 interface WatchedItemStoreInterface
{
37 public const SORT_ASC
= 'ASC';
42 public const SORT_DESC
= 'DESC';
45 * Count the number of individual items that are watched by the user.
46 * If a subject and corresponding talk page are watched this will return 2.
50 * @param UserIdentity $user
54 public function countWatchedItems( UserIdentity
$user );
59 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
63 public function countWatchers( $target );
66 * Number of page watchers who also visited a "recent" edit
70 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
71 * @param mixed $threshold timestamp accepted by wfTimestamp
75 public function countVisitingWatchers( $target, $threshold );
80 * @param LinkTarget[]|PageIdentity[] $targets deprecated passing LinkTarget[] since 1.36
81 * @param array $options Allowed keys:
82 * 'minimumWatchers' => int
84 * @return array multi dimensional like $return[$namespaceId][$titleString] = int $watchers
85 * All targets will be present in the result. 0 either means no watchers or the number
86 * of watchers was below the minimumWatchers option if passed.
88 public function countWatchersMultiple( array $targets, array $options = [] );
91 * Number of watchers of each page who have visited recent edits to that page
95 * @param array $targetsWithVisitThresholds array of pairs (LinkTarget|PageIdentity $target,
98 * - a timestamp of the recent edit if $target exists (format accepted by wfTimestamp)
99 * - null if $target doesn't exist
100 * deprecated passing LinkTarget since 1.36
101 * @param int|null $minimumWatchers
103 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $watchers,
104 * where $watchers is an int:
105 * - if the page exists, number of users watching who have visited the page recently
106 * - if the page doesn't exist, number of users that have the page on their watchlist
107 * - 0 means there are no visiting watchers or their number is below the
109 * option (if passed).
111 public function countVisitingWatchersMultiple(
112 array $targetsWithVisitThresholds,
113 $minimumWatchers = null
117 * Get an item (may be cached)
121 * @param UserIdentity $user
122 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
124 * @return WatchedItem|false
126 public function getWatchedItem( UserIdentity
$user, $target );
129 * Loads an item from the db
133 * @param UserIdentity $user
134 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
136 * @return WatchedItem|false
138 public function loadWatchedItem( UserIdentity
$user, $target );
141 * Loads a set of WatchedItems from the db.
145 * @param UserIdentity $user
146 * @param LinkTarget[]|PageIdentity[] $targets deprecated passing LinkTarget[] since 1.36
148 * @return WatchedItem[]|false
150 public function loadWatchedItemsBatch( UserIdentity
$user, array $targets );
153 * @since 1.31 Method Added
154 * @since 1.35 Allows 'sortByExpiry' as a key in $options
156 * @param UserIdentity $user
157 * @param array $options Allowed keys:
158 * 'forWrite' => bool defaults to false
159 * 'sort' => string optional sorting by namespace ID and title
160 * one of the self::SORT_* constants
161 * 'sortByExpiry' => bool optional sorts by expiration date, with the titles
162 * that will expire soonest at the top.
164 * @return WatchedItem[]
166 public function getWatchedItemsForUser( UserIdentity
$user, array $options = [] );
169 * Must be called separately for Subject & Talk namespaces
173 * @param UserIdentity $user
174 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
178 public function isWatched( UserIdentity
$user, $target );
181 * Whether the page is only being watched temporarily (has expiry).
182 * Must be called separately for Subject & Talk namespaces.
186 * @param UserIdentity $user
187 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
191 public function isTempWatched( UserIdentity
$user, $target ): bool;
196 * @param UserIdentity $user
197 * @param LinkTarget[]|PageIdentity[] $targets deprecated passing LinkTarget[] since 1.36
199 * @return array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp,
200 * where $timestamp is:
201 * - string|null value of wl_notificationtimestamp,
202 * - false if $target is not watched by $user.
204 public function getNotificationTimestampsBatch( UserIdentity
$user, array $targets );
207 * Must be called separately for Subject & Talk namespaces
209 * @since 1.31 Method added.
210 * @since 1.35 Accepts $expiry parameter.
212 * @param UserIdentity $user
213 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
214 * @param string|null $expiry Optional expiry timestamp in any format acceptable to wfTimestamp().
215 * null will not create an expiry, or leave it unchanged should one already exist.
217 public function addWatch( UserIdentity
$user, $target, ?
string $expiry = null );
220 * @since 1.31 Method added.
221 * @since 1.35 Accepts $expiry parameter.
223 * @param UserIdentity $user
224 * @param LinkTarget[]|PageIdentity[] $targets deprecated passing LinkTarget[] since 1.36
225 * @param string|null $expiry Optional expiry timestamp in any format acceptable to wfTimestamp(),
226 * null will not create expiries, or leave them unchanged should they already exist.
228 * @return bool success
230 public function addWatchBatchForUser( UserIdentity
$user, array $targets, ?
string $expiry = null );
233 * Removes an entry for the UserIdentity watching the target (LinkTarget or PageIdentity)
234 * Must be called separately for Subject & Talk namespaces
238 * @param UserIdentity $user
239 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
241 * @return bool success
243 public function removeWatch( UserIdentity
$user, $target );
248 * @param UserIdentity $user The user to set the timestamps for
249 * @param string|null $timestamp Set the update timestamp to this value
250 * @param LinkTarget[]|PageIdentity[] $targets List of targets to update. Default to all targets.
251 * deprecated passing LinkTarget[] since 1.36
253 * @return bool success
255 public function setNotificationTimestampsForUser(
262 * Reset all watchlist notification timestamps for a user using the job queue
266 * @param UserIdentity $user The user to reset the timestamps for
267 * @param string|int|null $timestamp Value to set all timestamps to, null to clear them
269 public function resetAllNotificationTimestampsForUser( UserIdentity
$user, $timestamp = null );
274 * @param UserIdentity $editor The editor that triggered the update. Their notification
275 * timestamp will not be updated(they have already seen it)
276 * @param LinkTarget|PageIdentity $target The target to update timestamps for
277 * deprecated passing LinkTarget since 1.36
278 * @param string $timestamp Set the update (first unseen revision) timestamp to this value
280 * @return int[] Array of user IDs the timestamp has been updated for
282 public function updateNotificationTimestamp(
283 UserIdentity
$editor, $target, $timestamp );
286 * Reset the notification timestamp of this entry
290 * @param UserIdentity $user
291 * @param LinkTarget|PageIdentity $title deprecated passing LinkTarget since 1.36
292 * @param string $force Whether to force the write query to be executed even if the
293 * page is not watched or the notification timestamp is already NULL.
294 * 'force' in order to force
295 * @param int $oldid The revision id being viewed. If not given or 0, latest revision is
298 * @return bool success Whether a job was enqueued
300 public function resetNotificationTimestamp(
301 UserIdentity
$user, $title, $force = '', $oldid = 0 );
306 * @param UserIdentity $user
307 * @param int|null $unreadLimit
309 * @return int|bool The number of unread notifications
310 * true if greater than or equal to $unreadLimit
312 public function countUnreadNotifications( UserIdentity
$user, $unreadLimit = null );
315 * Check if the given title already is watched by the user, and if so
316 * add a watch for the new title.
318 * To be used for page renames and such.
322 * @param LinkTarget|PageIdentity $oldTarget deprecated passing LinkTarget since 1.36
323 * @param LinkTarget|PageIdentity $newTarget deprecated passing LinkTarget since 1.36
325 public function duplicateAllAssociatedEntries( $oldTarget, $newTarget );
328 * Check if the given title already is watched by the user, and if so
329 * add a watch for the new title.
331 * To be used for page renames and such.
332 * This must be called separately for Subject and Talk pages
336 * @param LinkTarget|PageIdentity $oldTarget deprecated passing LinkTarget since 1.36
337 * @param LinkTarget|PageIdentity $newTarget deprecated passing LinkTarget since 1.36
339 public function duplicateEntry( $oldTarget, $newTarget );
342 * Synchronously clear the users watchlist.
346 * @param UserIdentity $user
347 * @return bool True on success, false if {@see clearUserWatchedItemsUsingJobQueue} must be used
350 public function clearUserWatchedItems( UserIdentity
$user );
353 * Does the size of the users watchlist require clearUserWatchedItemsUsingJobQueue() to be used
354 * instead of clearUserWatchedItems()
358 * @param UserIdentity $user
361 public function mustClearWatchedItemsUsingJobQueue( UserIdentity
$user ): bool;
364 * Queues a job that will clear the users watchlist using the Job Queue.
368 * @param UserIdentity $user
370 public function clearUserWatchedItemsUsingJobQueue( UserIdentity
$user );
373 * Probabilistically add a job to purge the expired watchlist items, if watchlist
374 * expiration is enabled, based on the value of $wgWatchlistPurgeRate
378 public function maybeEnqueueWatchlistExpiryJob(): void
;
383 * @param UserIdentity $user
384 * @param LinkTarget[]|PageIdentity[] $targets deprecated passing LinkTarget[] since 1.36
386 * @return bool success
388 public function removeWatchBatchForUser( UserIdentity
$user, array $targets );
391 * Convert $timestamp to TS_MW or return null if the page was visited since then by $user
393 * Use this only on single-user methods (having higher read-after-write expectations)
394 * and not in places involving arbitrary batches of different users
396 * Usage of this method should be limited to WatchedItem* classes
398 * @param string|null $timestamp Value of wl_notificationtimestamp from the DB
399 * @param UserIdentity $user
400 * @param LinkTarget|PageIdentity $target deprecated passing LinkTarget since 1.36
401 * @return string|null TS_MW timestamp of first unseen revision or null if there isn't one
403 public function getLatestNotificationTimestamp(
404 $timestamp, UserIdentity
$user, $target );
407 * Get the number of watchlist items that expire before the current time.
413 public function countExpired(): int;
416 * Remove some number of expired watchlist items.
420 * @param int $limit The number of items to remove.
421 * @param bool $deleteOrphans Whether to also delete `watchlist_expiry` rows that have no
422 * related `watchlist` rows (because not all code knows about the expiry table yet). This runs
423 * two extra queries, so is only done from the purgeExpiredWatchlistItems.php maintenance script.
425 public function removeExpired( int $limit, bool $deleteOrphans = false ): void
;
427 /** @deprecated class alias since 1.43 */
428 class_alias( WatchedItemStoreInterface
::class, 'WatchedItemStoreInterface' );