MediaWiki  master
WatchedItem.php
Go to the documentation of this file.
1 <?php
24 
33 class WatchedItem {
37  private $linkTarget;
38 
42  private $user;
43 
48 
52  private $expiry;
53 
61  private const SECONDS_IN_A_DAY = 86400;
62 
69  public function __construct(
73  ?string $expiry = null
74  ) {
75  $this->user = $user;
76  $this->linkTarget = $linkTarget;
77  $this->notificationTimestamp = $notificationTimestamp;
78  $this->expiry = $expiry;
79  }
80 
87  public static function newFromRecentChange( RecentChange $recentChange, UserIdentity $user ) {
88  return new self(
89  $user,
90  $recentChange->getTitle(),
91  $recentChange->notificationtimestamp,
92  $recentChange->watchlistExpiry
93  );
94  }
95 
100  public function getUser() {
101  return User::newFromIdentity( $this->user );
102  }
103 
107  public function getUserIdentity() {
108  return $this->user;
109  }
110 
114  public function getLinkTarget() {
115  return $this->linkTarget;
116  }
117 
123  public function getNotificationTimestamp() {
125  }
126 
134  public function getExpiry(): ?string {
135  return $this->expiry;
136  }
137 
145  public function isExpired(): bool {
146  if ( $this->getExpiry() === null ) {
147  return false;
148  }
149 
150  $unix = MWTimestamp::convert( TS_UNIX, $this->getExpiry() );
151  return $unix < wfTimestamp();
152  }
153 
161  public function getExpiryInDays(): ?int {
162  if ( $this->getExpiry() === null ) {
163  return null;
164  }
165 
166  $unixTimeExpiry = MWTimestamp::convert( TS_UNIX, $this->getExpiry() );
167  $diffInSeconds = $unixTimeExpiry - wfTimestamp();
168  $diffInDays = $diffInSeconds / self::SECONDS_IN_A_DAY;
169 
170  if ( $diffInDays < 1 ) {
171  return 0;
172  }
173 
174  return (int)ceil( $diffInDays );
175  }
176 }
WatchedItem\$notificationTimestamp
null string $notificationTimestamp
the value of the wl_notificationtimestamp field
Definition: WatchedItem.php:47
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:72
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1808
User\newFromIdentity
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
Definition: User.php:595
WatchedItem\newFromRecentChange
static newFromRecentChange(RecentChange $recentChange, UserIdentity $user)
Definition: WatchedItem.php:87
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
WatchedItem\$user
UserIdentity $user
Definition: WatchedItem.php:42
WatchedItem\__construct
__construct(UserIdentity $user, LinkTarget $linkTarget, $notificationTimestamp, ?string $expiry=null)
Definition: WatchedItem.php:69
WatchedItem\getUserIdentity
getUserIdentity()
Definition: WatchedItem.php:107
WatchedItem\getUser
getUser()
Definition: WatchedItem.php:100
WatchedItem
Representation of a pair of user and title for watchlist entries.
Definition: WatchedItem.php:33
WatchedItem\getExpiry
getExpiry()
When the watched item will expire.
Definition: WatchedItem.php:134
WatchedItem\SECONDS_IN_A_DAY
const SECONDS_IN_A_DAY
Used to calculate how many days are remaining until a watched item will expire.
Definition: WatchedItem.php:61
WatchedItem\getLinkTarget
getLinkTarget()
Definition: WatchedItem.php:114
WatchedItem\isExpired
isExpired()
Has the watched item expired?
Definition: WatchedItem.php:145
WatchedItem\getNotificationTimestamp
getNotificationTimestamp()
Get the notification timestamp of this entry.
Definition: WatchedItem.php:123
WatchedItem\$expiry
string null $expiry
When to automatically unwatch the page.
Definition: WatchedItem.php:52
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
RecentChange\getTitle
& getTitle()
Definition: RecentChange.php:291
WatchedItem\$linkTarget
LinkTarget $linkTarget
Definition: WatchedItem.php:37
WatchedItem\getExpiryInDays
getExpiryInDays()
Get days remaining until a watched item expires.
Definition: WatchedItem.php:161