MediaWiki  1.27.2
WatchedItem.php
Go to the documentation of this file.
1 <?php
22 
31 class WatchedItem {
32 
37 
42 
47 
53 
58  private $title;
59 
63  private $linkTarget;
64 
68  private $user;
69 
74 
81  public function __construct(
82  User $user,
85  $checkRights = null
86  ) {
87  $this->user = $user;
88  $this->linkTarget = $linkTarget;
89  $this->notificationTimestamp = $notificationTimestamp;
90  if ( $checkRights !== null ) {
91  $this->checkRights = $checkRights;
92  }
93  }
94 
98  public function getUser() {
99  return $this->user;
100  }
101 
105  public function getLinkTarget() {
106  return $this->linkTarget;
107  }
108 
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' ) ) {
119  return false;
120  }
122  ->loadWatchedItem( $this->user, $this->linkTarget );
123  if ( $item ) {
124  $this->notificationTimestamp = $item->getNotificationTimestamp();
125  } else {
126  $this->notificationTimestamp = false;
127  }
128  }
130  }
131 
142  public function getTitle() {
143  if ( !$this->title ) {
144  $this->title = Title::newFromLinkTarget( $this->linkTarget );
145  }
146  return $this->title;
147  }
148 
154  // wfDeprecated( __METHOD__, '1.27' );
155  return new self( $user, $title, self::DEPRECATED_USAGE_TIMESTAMP, (bool)$checkRights );
156  }
157 
161  public function resetNotificationTimestamp( $force = '', $oldid = 0 ) {
162  // wfDeprecated( __METHOD__, '1.27' );
163  if ( $this->checkRights && !$this->user->isAllowed( 'editmywatchlist' ) ) {
164  return;
165  }
166  WatchedItemStore::getDefaultInstance()->resetNotificationTimestamp(
167  $this->user,
168  $this->getTitle(),
169  $force,
170  $oldid
171  );
172  }
173 
177  public static function batchAddWatch( array $items ) {
178  // wfDeprecated( __METHOD__, '1.27' );
179  if ( !$items ) {
180  return false;
181  }
182 
183  $targets = [];
184  $users = [];
186  foreach ( $items as $watchedItem ) {
187  $user = $watchedItem->getUser();
188  if ( $watchedItem->checkRights && !$user->isAllowed( 'editmywatchlist' ) ) {
189  continue;
190  }
191  $userId = $user->getId();
192  $users[$userId] = $user;
193  $targets[$userId][] = $watchedItem->getTitle()->getSubjectPage();
194  $targets[$userId][] = $watchedItem->getTitle()->getTalkPage();
195  }
196 
198  $success = true;
199  foreach ( $users as $userId => $user ) {
200  $success &= $store->addWatchBatchForUser( $user, $targets[$userId] );
201  }
202 
203  return $success;
204  }
205 
210  public function addWatch() {
211  // wfDeprecated( __METHOD__, '1.27' );
212  $this->user->addWatch( $this->getTitle(), $this->checkRights );
213  return true;
214  }
215 
220  public function removeWatch() {
221  // wfDeprecated( __METHOD__, '1.27' );
222  if ( $this->checkRights && !$this->user->isAllowed( 'editmywatchlist' ) ) {
223  return false;
224  }
225  $this->user->removeWatch( $this->getTitle(), $this->checkRights );
226  return true;
227  }
228 
233  public function isWatched() {
234  // wfDeprecated( __METHOD__, '1.27' );
235  return $this->user->isWatched( $this->getTitle(), $this->checkRights );
236  }
237 
241  public static function duplicateEntries( Title $oldTitle, Title $newTitle ) {
242  // wfDeprecated( __METHOD__, '1.27' );
244  $store->duplicateAllAssociatedEntries( $oldTitle, $newTitle );
245  }
246 
247 }
static batchAddWatch(array $items)
getNotificationTimestamp()
Get the notification timestamp of this entry.
the array() calling protocol came about after MediaWiki 1.4rc1.
LinkTarget $linkTarget
Definition: WatchedItem.php:63
null string $notificationTimestamp
the value of the wl_notificationtimestamp field
Definition: WatchedItem.php:73
$success
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
const DEPRECATED_USAGE_TIMESTAMP
Definition: WatchedItem.php:46
resetNotificationTimestamp($force= '', $oldid=0)
Represents a title within MediaWiki.
Definition: Title.php:34
Title $title
Definition: WatchedItem.php:58
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:251
getTitle()
Back compat pre 1.27 with the WatchedItemStore introduction.
const IGNORE_USER_RIGHTS
Definition: WatchedItem.php:36
isAllowed($action= '')
Internal mechanics of testing a permission.
Definition: User.php:3408
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
Definition: distributors.txt:9
static duplicateEntries(Title $oldTitle, Title $newTitle)
const IGNORE_USER_RIGHTS
Definition: User.php:84
title
Representation of a pair of user and title for watchlist entries.
Definition: WatchedItem.php:31
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
const CHECK_USER_RIGHTS
Definition: WatchedItem.php:41
getId()
Get the user's ID.
Definition: User.php:2061
versus $oldTitle
Definition: globals.txt:16
bool $checkRights
Definition: WatchedItem.php:52
getTalkPage()
Get this user's talk page title.
Definition: User.php:4089
const CHECK_USER_RIGHTS
Definition: User.php:79
static fromUserTitle($user, $title, $checkRights=User::CHECK_USER_RIGHTS)
__construct(User $user, LinkTarget $linkTarget, $notificationTimestamp, $checkRights=null)
Definition: WatchedItem.php:81