WatchedItemStoreInterface.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /**
  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.
  7. *
  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.
  12. *
  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
  17. *
  18. * @file
  19. * @ingroup Watchlist
  20. */
  21. use MediaWiki\Linker\LinkTarget;
  22. use Wikimedia\Rdbms\DBUnexpectedError;
  23. /**
  24. * @author Addshore
  25. * @since 1.31 interface created. WatchedItemStore implementation available since 1.27
  26. */
  27. interface WatchedItemStoreInterface {
  28. /**
  29. * @since 1.31
  30. */
  31. const SORT_ASC = 'ASC';
  32. /**
  33. * @since 1.31
  34. */
  35. const SORT_DESC = 'DESC';
  36. /**
  37. * Count the number of individual items that are watched by the user.
  38. * If a subject and corresponding talk page are watched this will return 2.
  39. *
  40. * @since 1.31
  41. *
  42. * @param User $user
  43. *
  44. * @return int
  45. */
  46. public function countWatchedItems( User $user );
  47. /**
  48. * @since 1.31
  49. *
  50. * @param LinkTarget $target
  51. *
  52. * @return int
  53. */
  54. public function countWatchers( LinkTarget $target );
  55. /**
  56. * Number of page watchers who also visited a "recent" edit
  57. *
  58. * @since 1.31
  59. *
  60. * @param LinkTarget $target
  61. * @param mixed $threshold timestamp accepted by wfTimestamp
  62. *
  63. * @return int
  64. * @throws DBUnexpectedError
  65. * @throws MWException
  66. */
  67. public function countVisitingWatchers( LinkTarget $target, $threshold );
  68. /**
  69. * @since 1.31
  70. *
  71. * @param LinkTarget[] $targets
  72. * @param array $options Allowed keys:
  73. * 'minimumWatchers' => int
  74. *
  75. * @return array multi dimensional like $return[$namespaceId][$titleString] = int $watchers
  76. * All targets will be present in the result. 0 either means no watchers or the number
  77. * of watchers was below the minimumWatchers option if passed.
  78. */
  79. public function countWatchersMultiple( array $targets, array $options = [] );
  80. /**
  81. * Number of watchers of each page who have visited recent edits to that page
  82. *
  83. * @since 1.31
  84. *
  85. * @param array $targetsWithVisitThresholds array of pairs (LinkTarget $target, mixed
  86. * $threshold),
  87. * $threshold is:
  88. * - a timestamp of the recent edit if $target exists (format accepted by wfTimestamp)
  89. * - null if $target doesn't exist
  90. * @param int|null $minimumWatchers
  91. *
  92. * @return array multi-dimensional like $return[$namespaceId][$titleString] = $watchers,
  93. * where $watchers is an int:
  94. * - if the page exists, number of users watching who have visited the page recently
  95. * - if the page doesn't exist, number of users that have the page on their watchlist
  96. * - 0 means there are no visiting watchers or their number is below the
  97. * minimumWatchers
  98. * option (if passed).
  99. */
  100. public function countVisitingWatchersMultiple(
  101. array $targetsWithVisitThresholds,
  102. $minimumWatchers = null
  103. );
  104. /**
  105. * Get an item (may be cached)
  106. *
  107. * @since 1.31
  108. *
  109. * @param User $user
  110. * @param LinkTarget $target
  111. *
  112. * @return WatchedItem|false
  113. */
  114. public function getWatchedItem( User $user, LinkTarget $target );
  115. /**
  116. * Loads an item from the db
  117. *
  118. * @since 1.31
  119. *
  120. * @param User $user
  121. * @param LinkTarget $target
  122. *
  123. * @return WatchedItem|false
  124. */
  125. public function loadWatchedItem( User $user, LinkTarget $target );
  126. /**
  127. * @since 1.31
  128. *
  129. * @param User $user
  130. * @param array $options Allowed keys:
  131. * 'forWrite' => bool defaults to false
  132. * 'sort' => string optional sorting by namespace ID and title
  133. * one of the self::SORT_* constants
  134. *
  135. * @return WatchedItem[]
  136. */
  137. public function getWatchedItemsForUser( User $user, array $options = [] );
  138. /**
  139. * Must be called separately for Subject & Talk namespaces
  140. *
  141. * @since 1.31
  142. *
  143. * @param User $user
  144. * @param LinkTarget $target
  145. *
  146. * @return bool
  147. */
  148. public function isWatched( User $user, LinkTarget $target );
  149. /**
  150. * @since 1.31
  151. *
  152. * @param User $user
  153. * @param LinkTarget[] $targets
  154. *
  155. * @return array multi-dimensional like $return[$namespaceId][$titleString] = $timestamp,
  156. * where $timestamp is:
  157. * - string|null value of wl_notificationtimestamp,
  158. * - false if $target is not watched by $user.
  159. */
  160. public function getNotificationTimestampsBatch( User $user, array $targets );
  161. /**
  162. * Must be called separately for Subject & Talk namespaces
  163. *
  164. * @since 1.31
  165. *
  166. * @param User $user
  167. * @param LinkTarget $target
  168. */
  169. public function addWatch( User $user, LinkTarget $target );
  170. /**
  171. * @since 1.31
  172. *
  173. * @param User $user
  174. * @param LinkTarget[] $targets
  175. *
  176. * @return bool success
  177. */
  178. public function addWatchBatchForUser( User $user, array $targets );
  179. /**
  180. * Removes the an entry for the User watching the LinkTarget
  181. * Must be called separately for Subject & Talk namespaces
  182. *
  183. * @since 1.31
  184. *
  185. * @param User $user
  186. * @param LinkTarget $target
  187. *
  188. * @return bool success
  189. * @throws DBUnexpectedError
  190. * @throws MWException
  191. */
  192. public function removeWatch( User $user, LinkTarget $target );
  193. /**
  194. * @since 1.31
  195. *
  196. * @param User $user The user to set the timestamps for
  197. * @param string|null $timestamp Set the update timestamp to this value
  198. * @param LinkTarget[] $targets List of targets to update. Default to all targets
  199. *
  200. * @return bool success
  201. */
  202. public function setNotificationTimestampsForUser(
  203. User $user,
  204. $timestamp,
  205. array $targets = []
  206. );
  207. /**
  208. * Reset all watchlist notificaton timestamps for a user using the job queue
  209. *
  210. * @since 1.31
  211. *
  212. * @param User $user The user to reset the timestamps for
  213. */
  214. public function resetAllNotificationTimestampsForUser( User $user );
  215. /**
  216. * @since 1.31
  217. *
  218. * @param User $editor The editor that triggered the update. Their notification
  219. * timestamp will not be updated(they have already seen it)
  220. * @param LinkTarget $target The target to update timestamps for
  221. * @param string $timestamp Set the update timestamp to this value
  222. *
  223. * @return int[] Array of user IDs the timestamp has been updated for
  224. */
  225. public function updateNotificationTimestamp( User $editor, LinkTarget $target, $timestamp );
  226. /**
  227. * Reset the notification timestamp of this entry
  228. *
  229. * @since 1.31
  230. *
  231. * @param User $user
  232. * @param Title $title
  233. * @param string $force Whether to force the write query to be executed even if the
  234. * page is not watched or the notification timestamp is already NULL.
  235. * 'force' in order to force
  236. * @param int $oldid The revision id being viewed. If not given or 0, latest revision is
  237. * assumed.
  238. *
  239. * @return bool success Whether a job was enqueued
  240. */
  241. public function resetNotificationTimestamp( User $user, Title $title, $force = '', $oldid = 0 );
  242. /**
  243. * @since 1.31
  244. *
  245. * @param User $user
  246. * @param int|null $unreadLimit
  247. *
  248. * @return int|bool The number of unread notifications
  249. * true if greater than or equal to $unreadLimit
  250. */
  251. public function countUnreadNotifications( User $user, $unreadLimit = null );
  252. /**
  253. * Check if the given title already is watched by the user, and if so
  254. * add a watch for the new title.
  255. *
  256. * To be used for page renames and such.
  257. *
  258. * @since 1.31
  259. *
  260. * @param LinkTarget $oldTarget
  261. * @param LinkTarget $newTarget
  262. */
  263. public function duplicateAllAssociatedEntries( LinkTarget $oldTarget, LinkTarget $newTarget );
  264. /**
  265. * Check if the given title already is watched by the user, and if so
  266. * add a watch for the new title.
  267. *
  268. * To be used for page renames and such.
  269. * This must be called separately for Subject and Talk pages
  270. *
  271. * @since 1.31
  272. *
  273. * @param LinkTarget $oldTarget
  274. * @param LinkTarget $newTarget
  275. */
  276. public function duplicateEntry( LinkTarget $oldTarget, LinkTarget $newTarget );
  277. /**
  278. * Queues a job that will clear the users watchlist using the Job Queue.
  279. *
  280. * @since 1.31
  281. *
  282. * @param User $user
  283. */
  284. public function clearUserWatchedItems( User $user );
  285. /**
  286. * Queues a job that will clear the users watchlist using the Job Queue.
  287. *
  288. * @since 1.31
  289. *
  290. * @param User $user
  291. */
  292. public function clearUserWatchedItemsUsingJobQueue( User $user );
  293. }