33use Wikimedia\Timestamp\TimestampFormat as TS;
45 private readonly
bool $enableWatchlistLabels;
64 parent::__construct( $article, $context );
67 if ( $this->watchlistExpiry || $this->enableWatchlistLabels ) {
95 $result = $this->watchlistManager->setWatch(
99 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName ),
100 $this->
getRequest()->getArray(
'wplabels', [] )
103 return Status::wrap( $result );
119 parent::checkCanExecute( $user );
124 return 'editmywatchlist';
135 if ( !$this->watchlistExpiry && !$this->enableWatchlistLabels ) {
140 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
149 if ( $this->watchlistExpiry ) {
150 $default = $this->userOptionsLookup->getOption( $this->
getUser(),
'watchstar-expiry' );
151 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem, $default );
154 'label-message' =>
'confirm-watch-label',
155 'options' => $expiryOptions[
'options'],
156 'default' => $expiryOptions[
'default'],
161 if ( $this->enableWatchlistLabels ) {
163 foreach ( $this->watchlistLabelStore->loadAllForUser( $this->getUser() ) as $label ) {
164 $options[ htmlspecialchars( $label->getName() ) ] = $label->getId();
166 $default = $this->watchedItem instanceof
WatchedItem
167 ? array_map(
static fn (
WatchlistLabel $l ) => $l->
getId(), $this->watchedItem->getLabels() )
170 'label-message' =>
'watchlistlabels-watchaction-label',
171 'type' =>
'multiselect',
172 'options' => $options,
173 'default' => $default,
195 string $defaultExpiry =
'infinite'
199 if ( !in_array( $defaultExpiry, $expiryOptions ) ) {
200 $expiryOptions = array_merge( [ $defaultExpiry => $defaultExpiry ], $expiryOptions );
207 $expiryOptions = array_merge( [ $daysLeft => $currentExpiry ], $expiryOptions );
210 $defaultExpiry = $currentExpiry;
214 'options' => $expiryOptions,
215 'default' => $defaultExpiry,
231 $expiryOptionsMsg = $msgLocalizer->
msg(
'watchlist-expiry-options' );
232 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
238 foreach ( $options as $label => $value ) {
240 $expiryOptions[$label] = $value;
246 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
250 return $expiryOptions;
254 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
256 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
275 $submittedExpiry = $this->getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
276 $this->getOutput()->addWikiMsg( $this->makeSuccessMessage( $submittedExpiry ) );
278 $labelIds = $this->getRequest()->getArray(
'wplabels' );
280 $this->getOutput()->addWikiMsg(
281 'watchlistlabels-watchaction-success',
289 $msgKey = $this->getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
291 if ( $submittedExpiry ) {
294 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS::ISO_8601 );
298 $defaultLabels = static::getExpiryOptionsFromMessage( $this->getContext() );
299 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
303 $isTalk = $this->getTitle()->isTalkPage();
305 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
306 } elseif ( $expiryDays >= 1 ) {
307 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
308 $params[] = $localizedExpiry ===
false
309 ? $this->getContext()->msg(
'days', $expiryDays )->text()
313 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
316 return MessageValue::new( $msgKey )->params( $this->getTitle()->getPrefixedText(), ...$params );
326class_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.