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
23 * Representation of a pair of user and title for watchlist entries.
25 * @author Tim Starling
33 * @deprecated since 1.27, see User::IGNORE_USER_RIGHTS
35 const IGNORE_USER_RIGHTS
= User
::IGNORE_USER_RIGHTS
;
38 * @deprecated since 1.27, see User::CHECK_USER_RIGHTS
40 const CHECK_USER_RIGHTS
= User
::CHECK_USER_RIGHTS
;
43 * @deprecated Internal class use only
45 const DEPRECATED_USAGE_TIMESTAMP
= -100;
49 * @deprecated Internal class use only
51 public $checkRights = User
::CHECK_USER_RIGHTS
;
55 * @deprecated Internal class use only
70 * @var null|string the value of the wl_notificationtimestamp field
72 private $notificationTimestamp;
76 * @param LinkTarget $linkTarget
77 * @param null|string $notificationTimestamp the value of the wl_notificationtimestamp field
78 * @param bool|null $checkRights DO NOT USE - used internally for backward compatibility
80 public function __construct(
82 LinkTarget
$linkTarget,
83 $notificationTimestamp,
87 $this->linkTarget
= $linkTarget;
88 $this->notificationTimestamp
= $notificationTimestamp;
89 if ( $checkRights !== null ) {
90 $this->checkRights
= $checkRights;
97 public function getUser() {
104 public function getLinkTarget() {
105 return $this->linkTarget
;
109 * Get the notification timestamp of this entry.
111 * @return bool|null|string
113 public function getNotificationTimestamp() {
114 // Back compat for objects constructed using self::fromUserTitle
115 if ( $this->notificationTimestamp
=== self
::DEPRECATED_USAGE_TIMESTAMP
) {
116 // wfDeprecated( __METHOD__, '1.27' );
117 if ( $this->checkRights
&& !$this->user
->isAllowed( 'viewmywatchlist' ) ) {
120 $item = WatchedItemStore
::getDefaultInstance()
121 ->loadWatchedItem( $this->user
, $this->linkTarget
);
123 $this->notificationTimestamp
= $item->getNotificationTimestamp();
125 $this->notificationTimestamp
= false;
128 return $this->notificationTimestamp
;
132 * Back compat pre 1.27 with the WatchedItemStore introduction
133 * @todo remove in 1.28/9
134 * -------------------------------------------------
139 * @deprecated Internal class use only
141 public function getTitle() {
142 if ( !$this->title
) {
143 if ( $this->linkTarget
instanceof Title
) {
144 $this->title
= $this->linkTarget
;
146 $this->title
= Title
::newFromLinkTarget( $this->linkTarget
);
153 * @deprecated since 1.27 Use the constructor, WatchedItemStore::getWatchedItem()
154 * or WatchedItemStore::loadWatchedItem()
156 public static function fromUserTitle( $user, $title, $checkRights = User
::CHECK_USER_RIGHTS
) {
157 // wfDeprecated( __METHOD__, '1.27' );
158 return new self( $user, $title, self
::DEPRECATED_USAGE_TIMESTAMP
, (bool)$checkRights );
162 * @deprecated since 1.27 Use WatchedItemStore::resetNotificationTimestamp()
164 public function resetNotificationTimestamp( $force = '', $oldid = 0 ) {
165 // wfDeprecated( __METHOD__, '1.27' );
166 if ( $this->checkRights
&& !$this->user
->isAllowed( 'editmywatchlist' ) ) {
169 WatchedItemStore
::getDefaultInstance()->resetNotificationTimestamp(
178 * @deprecated since 1.27 Use WatchedItemStore::addWatchBatch()
180 public static function batchAddWatch( array $items ) {
181 // wfDeprecated( __METHOD__, '1.27' );
182 $userTargetCombinations = [];
183 /** @var WatchedItem $watchedItem */
184 foreach ( $items as $watchedItem ) {
185 if ( $watchedItem->checkRights
&& !$watchedItem->getUser()->isAllowed( 'editmywatchlist' ) ) {
188 $userTargetCombinations[] = [
189 $watchedItem->getUser(),
190 $watchedItem->getTitle()->getSubjectPage()
192 $userTargetCombinations[] = [
193 $watchedItem->getUser(),
194 $watchedItem->getTitle()->getTalkPage()
197 $store = WatchedItemStore
::getDefaultInstance();
198 return $store->addWatchBatch( $userTargetCombinations );
202 * @deprecated since 1.27 Use User::addWatch()
205 public function addWatch() {
206 // wfDeprecated( __METHOD__, '1.27' );
207 $this->user
->addWatch( $this->getTitle(), $this->checkRights
);
212 * @deprecated since 1.27 Use User::removeWatch()
215 public function removeWatch() {
216 // wfDeprecated( __METHOD__, '1.27' );
217 if ( $this->checkRights
&& !$this->user
->isAllowed( 'editmywatchlist' ) ) {
220 $this->user
->removeWatch( $this->getTitle(), $this->checkRights
);
225 * @deprecated since 1.27 Use User::isWatched()
228 public function isWatched() {
229 // wfDeprecated( __METHOD__, '1.27' );
230 return $this->user
->isWatched( $this->getTitle(), $this->checkRights
);
234 * @deprecated since 1.27 Use WatchedItemStore::duplicateAllAssociatedEntries()
236 public static function duplicateEntries( Title
$oldTitle, Title
$newTitle ) {
237 // wfDeprecated( __METHOD__, '1.27' );
238 $store = WatchedItemStore
::getDefaultInstance();
239 $store->duplicateAllAssociatedEntries( $oldTitle, $newTitle );