30use Wikimedia\Timestamp\TimestampFormat as TS;
67 parent::__construct( $article,
$context );
69 if ( $this->watchlistExpiry ) {
76 $this->watchlistManager = $watchlistManager;
77 $this->userOptionsLookup = $userOptionsLookup;
99 $result = $this->watchlistManager->setWatch(
103 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
106 return Status::wrap( $result );
122 parent::checkCanExecute( $user );
127 return 'editmywatchlist';
138 if ( !$this->watchlistExpiry ) {
143 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
150 $default = $this->userOptionsLookup->getOption( $this->
getUser(),
'watchstar-expiry' );
151 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem, $default );
153 $this->expiryFormFieldName => [
155 'label-message' =>
'confirm-watch-label',
156 'options' => $expiryOptions[
'options'],
157 'default' => $expiryOptions[
'default'],
177 string $defaultExpiry =
'infinite'
181 if ( !in_array( $defaultExpiry, $expiryOptions ) ) {
182 $expiryOptions = array_merge( [ $defaultExpiry => $defaultExpiry ], $expiryOptions );
189 $expiryOptions = array_merge( [ $daysLeft => $currentExpiry ], $expiryOptions );
192 $defaultExpiry = $currentExpiry;
196 'options' => $expiryOptions,
197 'default' => $defaultExpiry,
213 $expiryOptionsMsg = $msgLocalizer->
msg(
'watchlist-expiry-options' );
214 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
220 foreach ( $options as $label => $value ) {
222 $expiryOptions[$label] = $value;
228 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
232 return $expiryOptions;
236 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
238 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
256 $submittedExpiry = $this->getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
257 $this->getOutput()->addWikiMsg( $this->makeSuccessMessage( $submittedExpiry ) );
261 $msgKey = $this->getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
263 if ( $submittedExpiry ) {
266 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS::ISO_8601 );
270 $defaultLabels = static::getExpiryOptionsFromMessage( $this->getContext() );
271 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
275 $isTalk = $this->getTitle()->isTalkPage();
277 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
278 } elseif ( $expiryDays >= 1 ) {
279 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
280 $params[] = $localizedExpiry ===
false
281 ? $this->getContext()->msg(
'days', $expiryDays )->text()
285 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
288 return MessageValue::new( $msgKey )->params( $this->getTitle()->getPrefixedText(), ...$params );
298class_alias( WatchAction::class,
'WatchAction' );
wfIsInfinity( $str)
Determine input string is represents as infinity.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
Legacy class representing an editable page and handling UI for some page actions.
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.