Go to the documentation of this file.
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 );
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
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 ) {
293 ?
string $expiry =
null
295 $services = MediaWikiServices::getInstance();
296 $permissionManager = $services->getPermissionManager();
297 if ( $checkRights && !$permissionManager->userHasRight( $user,
'editmywatchlist' ) ) {
301 $page = $services->getWikiPageFactory()->newFromTitle(
$title );
321 $services = MediaWikiServices::getInstance();
322 if ( !$services->getPermissionManager()
323 ->userHasRight( $user,
'editmywatchlist' ) ) {
327 $page = $services->getWikiPageFactory()->newFromTitle(
$title );
349 if ( $action !=
'unwatch' ) {
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static doWatch(Title $title, User $user, $checkRights=User::CHECK_USER_RIGHTS, ?string $expiry=null)
Watch a page.
isAnon()
Get whether the user is anonymous.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially Stable to override.
onSuccess()
Show one of 8 possible success messages.
isRegistered()
Get whether the user is registered.
getRequest()
Get the WebRequest being used for this instance.
if(!isset( $args[0])) $lang
static newFatalPermissionDeniedStatus( $permission)
Factory function for fatal permission-denied errors.
requiresUnblock()
Whether this action can still be executed by a blocked user.
static doUnwatch(Title $title, User $user)
Unwatch a page.
Redirect a user to the login page.
string $expiryFormFieldName
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.
Page addition to a user's watchlist.
static parseOptionsMessage(string $msg)
Parse labels and values out of a comma- and colon-separated list of options, such as is used for expi...
onSubmit( $data)
Process the form on POST submission.
Interface for localizing messages in MediaWiki.
getFormFields()
Get an HTMLForm descriptor array Stable to override.
getContext()
Get the IContextSource in use here.
getExpiry(?int $style=TS_MW)
When the watched item will expire.
doesWrites()
Stable to override.
msg( $key,... $params)
This is the method for getting translated interface messages.
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
static calculateExpiryInDays(?string $expiry)
Get the number of days remaining until the given expiry time.
static getExpiryOptionsFromMessage(MessageLocalizer $msgLocalizer, ?string $lang=null)
Parse expiry options message.
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.
bool $watchlistExpiry
The value of the $wgWatchlistExpiry configuration variable.
static newGood( $value=null)
Factory function for good results.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
wfIsInfinity( $str)
Determine input string is represents as infinity.
Representation of a pair of user and title for watchlist entries.
addWatch( $title, $checkRights=self::CHECK_USER_RIGHTS, ?string $expiry=null)
Watch an article.
getTitle()
Shortcut to get the Title object from the page.
removeWatch( $title, $checkRights=self::CHECK_USER_RIGHTS)
Stop watching an article.
static doWatchOrUnwatch( $watch, Title $title, User $user, string $expiry=null)
Watch or unwatch a page.
__construct(Page $page, IContextSource $context=null)
Only public since 1.21.
Interface for objects which can provide a MediaWiki context on request.
getName()
Return the name of the action this object responds to.
Represents a title within MediaWiki.
getExpiryInDaysText(MessageLocalizer $msgLocalizer, $isDropdownOption=false)
Get days remaining until a watched item expires as a text.
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getOutput()
Get the OutputPage being used for this instance.
static getWatchToken(Title $title, User $user, $action='watch')
Get token to watch (or unwatch) a page for a user.
false WatchedItem $watchedItem
getEditToken( $salt='', $request=null)
Initialize (if necessary) and return a session token value which can be used in edit forms to show th...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
usesOOUI()
Whether the form should use OOUI Stable to override.