32use Wikimedia\Timestamp\TimestampFormat as TS;
44 private bool $enableWatchlistLabels;
63 parent::__construct( $article,
$context );
66 if ( $this->watchlistExpiry || $this->enableWatchlistLabels ) {
94 $result = $this->watchlistManager->setWatch(
98 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
101 $labelIds = $this->
getRequest()->getArray(
'wplabels' );
103 $this->watchedItemStore->addLabels( $this->
getUser(), [ $this->
getTitle() ], $labelIds );
106 return Status::wrap( $result );
122 parent::checkCanExecute( $user );
127 return 'editmywatchlist';
138 if ( !$this->watchlistExpiry && !$this->enableWatchlistLabels ) {
143 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
152 if ( $this->watchlistExpiry ) {
153 $default = $this->userOptionsLookup->getOption( $this->
getUser(),
'watchstar-expiry' );
154 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem, $default );
157 'label-message' =>
'confirm-watch-label',
158 'options' => $expiryOptions[
'options'],
159 'default' => $expiryOptions[
'default'],
164 if ( $this->enableWatchlistLabels ) {
166 foreach ( $this->watchlistLabelStore->loadAllForUser( $this->getUser() ) as $label ) {
167 $options[ htmlspecialchars( $label->getName() ) ] = $label->getId();
170 'label-message' =>
'watchlistlabels-watchaction-label',
171 'type' =>
'multiselect',
172 'options' => $options,
194 string $defaultExpiry =
'infinite'
198 if ( !in_array( $defaultExpiry, $expiryOptions ) ) {
199 $expiryOptions = array_merge( [ $defaultExpiry => $defaultExpiry ], $expiryOptions );
206 $expiryOptions = array_merge( [ $daysLeft => $currentExpiry ], $expiryOptions );
209 $defaultExpiry = $currentExpiry;
213 'options' => $expiryOptions,
214 'default' => $defaultExpiry,
230 $expiryOptionsMsg = $msgLocalizer->
msg(
'watchlist-expiry-options' );
231 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
237 foreach ( $options as $label => $value ) {
239 $expiryOptions[$label] = $value;
245 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
249 return $expiryOptions;
253 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
255 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
274 $submittedExpiry = $this->getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
275 $this->getOutput()->addWikiMsg( $this->makeSuccessMessage( $submittedExpiry ) );
277 $labelIds = $this->getRequest()->getArray(
'wplabels' );
279 $this->getOutput()->addWikiMsg(
280 'watchlistlabels-watchaction-success',
288 $msgKey = $this->getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
290 if ( $submittedExpiry ) {
293 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS::ISO_8601 );
297 $defaultLabels = static::getExpiryOptionsFromMessage( $this->getContext() );
298 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
302 $isTalk = $this->getTitle()->isTalkPage();
304 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
305 } elseif ( $expiryDays >= 1 ) {
306 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
307 $params[] = $localizedExpiry ===
false
308 ? $this->getContext()->msg(
'days', $expiryDays )->text()
312 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
315 return MessageValue::new( $msgKey )->params( $this->getTitle()->getPrefixedText(), ...$params );
325class_alias( WatchAction::class,
'WatchAction' );
wfIsInfinity( $str)
Determine input string is represents as infinity.
A class containing constants representing the names of configuration variables.
const EnableWatchlistLabels
Name constant for the EnableWatchlistLabels setting, for use with Config::get()
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.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Interface for objects which can provide a MediaWiki context on request.