NoWriteWatchedItemStore.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 MediaWiki\User\UserIdentity;
  23. use Wikimedia\Rdbms\DBReadOnlyError;
  24. /**
  25. * @internal
  26. * @since 1.31
  27. */
  28. class NoWriteWatchedItemStore implements WatchedItemStoreInterface {
  29. /**
  30. * @var WatchedItemStoreInterface
  31. */
  32. private $actualStore;
  33. const DB_READONLY_ERROR = 'The watchlist is currently readonly.';
  34. /**
  35. * Initialy set WatchedItemStore that will be used in cases where writing is not needed.
  36. * @param WatchedItemStoreInterface $actualStore
  37. */
  38. public function __construct( WatchedItemStoreInterface $actualStore ) {
  39. $this->actualStore = $actualStore;
  40. }
  41. public function countWatchedItems( UserIdentity $user ) {
  42. return $this->actualStore->countWatchedItems( $user );
  43. }
  44. public function countWatchers( LinkTarget $target ) {
  45. return $this->actualStore->countWatchers( $target );
  46. }
  47. public function countVisitingWatchers( LinkTarget $target, $threshold ) {
  48. return $this->actualStore->countVisitingWatchers( $target, $threshold );
  49. }
  50. public function countWatchersMultiple( array $targets, array $options = [] ) {
  51. return $this->actualStore->countVisitingWatchersMultiple(
  52. $targets,
  53. $options['minimumWatchers'] ?? null
  54. );
  55. }
  56. public function countVisitingWatchersMultiple(
  57. array $targetsWithVisitThresholds,
  58. $minimumWatchers = null
  59. ) {
  60. return $this->actualStore->countVisitingWatchersMultiple(
  61. $targetsWithVisitThresholds,
  62. $minimumWatchers
  63. );
  64. }
  65. public function getWatchedItem( UserIdentity $user, LinkTarget $target ) {
  66. return $this->actualStore->getWatchedItem( $user, $target );
  67. }
  68. public function loadWatchedItem( UserIdentity $user, LinkTarget $target ) {
  69. return $this->actualStore->loadWatchedItem( $user, $target );
  70. }
  71. public function getWatchedItemsForUser( UserIdentity $user, array $options = [] ) {
  72. return $this->actualStore->getWatchedItemsForUser( $user, $options );
  73. }
  74. public function isWatched( UserIdentity $user, LinkTarget $target ) {
  75. return $this->actualStore->isWatched( $user, $target );
  76. }
  77. public function getNotificationTimestampsBatch( UserIdentity $user, array $targets ) {
  78. return $this->actualStore->getNotificationTimestampsBatch( $user, $targets );
  79. }
  80. public function countUnreadNotifications( UserIdentity $user, $unreadLimit = null ) {
  81. return $this->actualStore->countUnreadNotifications( $user, $unreadLimit );
  82. }
  83. public function duplicateAllAssociatedEntries( LinkTarget $oldTarget, LinkTarget $newTarget ) {
  84. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  85. }
  86. public function duplicateEntry( LinkTarget $oldTarget, LinkTarget $newTarget ) {
  87. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  88. }
  89. public function addWatch( UserIdentity $user, LinkTarget $target ) {
  90. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  91. }
  92. public function addWatchBatchForUser( UserIdentity $user, array $targets ) {
  93. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  94. }
  95. public function removeWatch( UserIdentity $user, LinkTarget $target ) {
  96. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  97. }
  98. public function setNotificationTimestampsForUser(
  99. UserIdentity $user,
  100. $timestamp,
  101. array $targets = []
  102. ) {
  103. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  104. }
  105. public function updateNotificationTimestamp(
  106. UserIdentity $editor, LinkTarget $target, $timestamp
  107. ) {
  108. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  109. }
  110. public function resetAllNotificationTimestampsForUser( UserIdentity $user ) {
  111. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  112. }
  113. public function resetNotificationTimestamp(
  114. UserIdentity $user,
  115. LinkTarget $title,
  116. $force = '',
  117. $oldid = 0
  118. ) {
  119. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  120. }
  121. public function clearUserWatchedItems( UserIdentity $user ) {
  122. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  123. }
  124. public function clearUserWatchedItemsUsingJobQueue( UserIdentity $user ) {
  125. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  126. }
  127. public function removeWatchBatchForUser( UserIdentity $user, array $titles ) {
  128. throw new DBReadOnlyError( null, self::DB_READONLY_ERROR );
  129. }
  130. public function getLatestNotificationTimestamp(
  131. $timestamp, UserIdentity $user, LinkTarget $target
  132. ) {
  133. return wfTimestampOrNull( TS_MW, $timestamp );
  134. }
  135. }