50 $this->watchlistExpiry = $this->
getContext()->getConfig()->get(
'WatchlistExpiry' );
51 if ( $this->watchlistExpiry ) {
53 $this->watchedItem = MediaWikiServices::getInstance()
54 ->getWatchedItemStore()
72 $expiry = $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName );
84 parent::checkCanExecute( $user );
93 if ( !$this->watchlistExpiry ) {
97 'vertical-label' =>
true,
99 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
105 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
107 $this->expiryFormFieldName => [
109 'label-message' =>
'confirm-watch-label',
110 'options' => $expiryOptions[
'options'],
111 'default' => $expiryOptions[
'default'],
130 $default = in_array(
'infinite', $expiryOptions )
132 : current( $expiryOptions );
138 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
141 'options' => $expiryOptions,
142 'default' => $default,
157 $expiryOptionsMsg = $msgLocalizer->
msg(
'watchlist-expiry-options' );
158 $optionsText = !
$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage(
$lang )->text();
164 foreach ( $options as $label => $value ) {
166 $expiryOptions[$label] = $value;
172 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
176 return $expiryOptions;
180 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
182 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
200 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
202 $submittedExpiry = $this->
getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
203 if ( $submittedExpiry ) {
206 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS_ISO_8601 );
209 $expiryDays = WatchedItem::calculateExpiryInDays( $expiry );
210 $defaultLabels = static::getExpiryOptions( $this->
getContext(),
null )[
'options'];
211 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
212 $expiryLabel = $expiryDays && $localizedExpiry ===
false
213 ? $this->
getContext()->msg(
'days', $expiryDays )->text()
218 $isTalk = $this->
getTitle()->isTalkPage();
220 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
221 } elseif ( $expiryDays > 0 ) {
222 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
223 } elseif ( $expiryDays < 1 ) {
224 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
227 $this->getOutput()->addWikiMsg( $msgKey, $this->
getTitle()->getPrefixedText(), $expiryLabel );
245 string $expiry =
null
249 return Status::newGood();
253 $oldWatchedItem = MediaWikiServices::getInstance()->getWatchedItemStore()
254 ->getWatchedItem( $user,
$title );
255 $changingWatchStatus = (bool)$oldWatchedItem !== $watch;
256 if ( $oldWatchedItem && $expiry !==
null ) {
258 $oldWatchPeriod = $oldWatchedItem->getExpiry() ===
null
260 : $oldWatchedItem->getExpiry();
261 $changingWatchStatus = $changingWatchStatus ||
262 $oldWatchPeriod !== ExpiryDef::normalizeExpiry( $expiry, TS_MW );
265 if ( $changingWatchStatus ) {
271 return self::doUnwatch(
$title, $user );
275 return Status::newGood();
293 ?
string $expiry =
null
295 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
296 if ( $checkRights && !$permissionManager->userHasRight( $user,
'editmywatchlist' ) ) {
300 $page = WikiPage::factory(
$title );
302 $status = Status::newFatal(
'hookaborted' );
303 if ( Hooks::runner()->onWatchArticle( $user, $page, $status, $expiry ) ) {
304 $status = Status::newGood();
306 Hooks::runner()->onWatchArticleComplete( $user, $page );
320 if ( !MediaWikiServices::getInstance()
322 ->userHasRight( $user,
'editmywatchlist' ) ) {
326 $page = WikiPage::factory(
$title );
328 $status = Status::newFatal(
'hookaborted' );
329 if ( Hooks::runner()->onUnwatchArticle( $user, $page, $status ) ) {
330 $status = Status::newGood();
332 Hooks::runner()->onUnwatchArticleComplete( $user, $page );
348 if ( $action !=
'unwatch' ) {
wfIsInfinity( $str)
Determine input string is represents as infinity.
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
getTitle()
Shortcut to get the Title object from the page.
getContext()
Get the IContextSource in use here.
getUser()
Shortcut to get the User being used for this instance.
IContextSource $context
IContextSource if specified; otherwise we'll use the Context from the Page.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getRequest()
Get the WebRequest being used for this instance.
Represents a title within MediaWiki.
Redirect a user to the login page.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getEditToken( $salt='', $request=null)
Initialize (if necessary) and return a session token value which can be used in edit forms to show th...
removeWatch( $title, $checkRights=self::CHECK_USER_RIGHTS)
Stop watching an article.
addWatch( $title, $checkRights=self::CHECK_USER_RIGHTS, ?string $expiry=null)
Watch an article.
isLoggedIn()
Get whether the user is registered.
static newFatalPermissionDeniedStatus( $permission)
Factory function for fatal permission-denied errors.
isAnon()
Get whether the user is anonymous.
Page addition to a user's watchlist.
static getExpiryOptions(MessageLocalizer $msgLocalizer, $watchedItem)
Get options and default for a watchlist expiry select list.
getDescription()
Returns the description that goes below the <h1> tag.
string $expiryFormFieldName
bool $watchlistExpiry
The value of the $wgWatchlistExpiry configuration variable.
requiresUnblock()
Whether this action can still be executed by a blocked user.
static getExpiryOptionsFromMessage(MessageLocalizer $msgLocalizer, ?string $lang=null)
Parse expiry options message.
getFormFields()
Get an HTMLForm descriptor array Stable to override.
static doUnwatch(Title $title, User $user)
Unwatch a page.
usesOOUI()
Whether the form should use OOUI Stable to override.
static doWatchOrUnwatch( $watch, Title $title, User $user, string $expiry=null)
Watch or unwatch a page.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially Stable to override.
false WatchedItem $watchedItem
static doWatch(Title $title, User $user, $checkRights=User::CHECK_USER_RIGHTS, ?string $expiry=null)
Watch a page.
__construct(Page $page, IContextSource $context=null)
Only public since 1.21.
static getWatchToken(Title $title, User $user, $action='watch')
Get token to watch (or unwatch) a page for a user.
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
doesWrites()
Stable to override.
onSuccess()
Show one of 8 possible success messages.
onSubmit( $data)
Process the form on POST submission.
getName()
Return the name of the action this object responds to.
Representation of a pair of user and title for watchlist entries.
getExpiryInDaysText(MessageLocalizer $msgLocalizer, $isDropdownOption=false)
Get days remaining until a watched item expires as a text.
getExpiry(?int $style=TS_MW)
When the watched item will expire.
static parseOptionsMessage(string $msg)
Parse labels and values out of a comma- and colon-separated list of options, such as is used for expi...
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
if(!isset( $args[0])) $lang