75 parent::__construct( $article,
$context );
77 if ( $this->watchlistExpiry ) {
84 $this->watchlistManager = $watchlistManager;
102 $result = $this->watchlistManager->setWatch(
106 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
109 return Status::wrap( $result );
125 parent::checkCanExecute( $user );
129 return 'editmywatchlist';
138 if ( !$this->watchlistExpiry ) {
143 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
149 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
151 $this->expiryFormFieldName => [
153 'label-message' =>
'confirm-watch-label',
154 'options' => $expiryOptions[
'options'],
155 'default' => $expiryOptions[
'default'],
173 $expiryOptions = self::getExpiryOptionsFromMessage( $msgLocalizer );
174 $default = in_array(
'infinite', $expiryOptions )
176 : current( $expiryOptions );
182 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
185 'options' => $expiryOptions,
186 'default' => $default,
198 private static function getExpiryOptionsFromMessage(
201 $expiryOptionsMsg = $msgLocalizer->
msg(
'watchlist-expiry-options' );
202 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
208 foreach ( $options as $label => $value ) {
210 $expiryOptions[$label] = $value;
216 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
217 return self::getExpiryOptionsFromMessage( $msgLocalizer,
'en' );
220 return $expiryOptions;
224 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
226 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
244 $submittedExpiry = $this->getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
245 $this->getOutput()->addWikiMsg( $this->makeSuccessMessage( $submittedExpiry ) );
249 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
251 if ( $submittedExpiry ) {
258 $defaultLabels = static::getExpiryOptions( $this->getContext(),
false )[
'options'];
259 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
263 $isTalk = $this->
getTitle()->isTalkPage();
265 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
266 } elseif ( $expiryDays >= 1 ) {
267 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
268 $params[] = $localizedExpiry ===
false
269 ? $this->getContext()->msg(
'days', $expiryDays )->text()
272 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
284class_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.