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
21 use MediaWiki\Linker\LinkTarget
;
24 * Representation of a pair of user and title for watchlist entries.
26 * @author Tim Starling
34 * @deprecated since 1.27, see User::IGNORE_USER_RIGHTS
36 const IGNORE_USER_RIGHTS
= User
::IGNORE_USER_RIGHTS
;
39 * @deprecated since 1.27, see User::CHECK_USER_RIGHTS
41 const CHECK_USER_RIGHTS
= User
::CHECK_USER_RIGHTS
;
44 * @deprecated Internal class use only
46 const DEPRECATED_USAGE_TIMESTAMP
= -100;
50 * @deprecated Internal class use only
52 public $checkRights = User
::CHECK_USER_RIGHTS
;
56 * @deprecated Internal class use only
71 * @var null|string the value of the wl_notificationtimestamp field
73 private $notificationTimestamp;
77 * @param LinkTarget $linkTarget
78 * @param null|string $notificationTimestamp the value of the wl_notificationtimestamp field
79 * @param bool|null $checkRights DO NOT USE - used internally for backward compatibility
81 public function __construct(
83 LinkTarget
$linkTarget,
84 $notificationTimestamp,
88 $this->linkTarget
= $linkTarget;
89 $this->notificationTimestamp
= $notificationTimestamp;
90 if ( $checkRights !== null ) {
91 $this->checkRights
= $checkRights;
98 public function getUser() {
105 public function getLinkTarget() {
106 return $this->linkTarget
;
110 * Get the notification timestamp of this entry.
112 * @return bool|null|string
114 public function getNotificationTimestamp() {
115 // Back compat for objects constructed using self::fromUserTitle
116 if ( $this->notificationTimestamp
=== self
::DEPRECATED_USAGE_TIMESTAMP
) {
117 // wfDeprecated( __METHOD__, '1.27' );
118 if ( $this->checkRights
&& !$this->user
->isAllowed( 'viewmywatchlist' ) ) {
121 $item = WatchedItemStore
::getDefaultInstance()
122 ->loadWatchedItem( $this->user
, $this->linkTarget
);
124 $this->notificationTimestamp
= $item->getNotificationTimestamp();
126 $this->notificationTimestamp
= false;
129 return $this->notificationTimestamp
;
133 * Back compat pre 1.27 with the WatchedItemStore introduction
134 * @todo remove in 1.28/9
135 * -------------------------------------------------
140 * @deprecated Internal class use only
142 public function getTitle() {
143 if ( !$this->title
) {
144 $this->title
= Title
::newFromLinkTarget( $this->linkTarget
);
150 * @deprecated since 1.27 Use the constructor, WatchedItemStore::getWatchedItem()
151 * or WatchedItemStore::loadWatchedItem()
153 public static function fromUserTitle( $user, $title, $checkRights = User
::CHECK_USER_RIGHTS
) {
154 // wfDeprecated( __METHOD__, '1.27' );
155 return new self( $user, $title, self
::DEPRECATED_USAGE_TIMESTAMP
, (bool)$checkRights );
159 * @deprecated since 1.27 Use WatchedItemStore::resetNotificationTimestamp()
161 public function resetNotificationTimestamp( $force = '', $oldid = 0 ) {
162 // wfDeprecated( __METHOD__, '1.27' );
163 if ( $this->checkRights
&& !$this->user
->isAllowed( 'editmywatchlist' ) ) {
166 WatchedItemStore
::getDefaultInstance()->resetNotificationTimestamp(
175 * @deprecated since 1.27 Use WatchedItemStore::addWatchBatch()
177 public static function batchAddWatch( array $items ) {
178 // wfDeprecated( __METHOD__, '1.27' );
185 /** @var WatchedItem $watchedItem */
186 foreach ( $items as $watchedItem ) {
187 $user = $watchedItem->getUser();
188 if ( $watchedItem->checkRights
&& !$user->isAllowed( 'editmywatchlist' ) ) {
191 $userId = $user->getId();
192 $users[$userId] = $user;
193 $targets[$userId][] = $watchedItem->getTitle()->getSubjectPage();
194 $targets[$userId][] = $watchedItem->getTitle()->getTalkPage();
197 $store = WatchedItemStore
::getDefaultInstance();
199 foreach ( $users as $userId => $user ) {
200 $success &= $store->addWatchBatchForUser( $user, $targets[$userId] );
207 * @deprecated since 1.27 Use User::addWatch()
210 public function addWatch() {
211 // wfDeprecated( __METHOD__, '1.27' );
212 $this->user
->addWatch( $this->getTitle(), $this->checkRights
);
217 * @deprecated since 1.27 Use User::removeWatch()
220 public function removeWatch() {
221 // wfDeprecated( __METHOD__, '1.27' );
222 if ( $this->checkRights
&& !$this->user
->isAllowed( 'editmywatchlist' ) ) {
225 $this->user
->removeWatch( $this->getTitle(), $this->checkRights
);
230 * @deprecated since 1.27 Use User::isWatched()
233 public function isWatched() {
234 // wfDeprecated( __METHOD__, '1.27' );
235 return $this->user
->isWatched( $this->getTitle(), $this->checkRights
);
239 * @deprecated since 1.27 Use WatchedItemStore::duplicateAllAssociatedEntries()
241 public static function duplicateEntries( Title
$oldTitle, Title
$newTitle ) {
242 // wfDeprecated( __METHOD__, '1.27' );
243 $store = WatchedItemStore
::getDefaultInstance();
244 $store->duplicateAllAssociatedEntries( $oldTitle, $newTitle );