46 protected $expiryFormFieldName =
'expiry';
49 protected $watchedItem =
false;
67 parent::__construct( $article, $context );
68 $this->watchlistExpiry = $this->
getContext()->getConfig()->get( MainConfigNames::WatchlistExpiry );
69 if ( $this->watchlistExpiry ) {
76 $this->watchlistManager = $watchlistManager;
94 $result = $this->watchlistManager->setWatch(
98 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
101 return Status::wrap( $result );
117 parent::checkCanExecute( $user );
121 return 'editmywatchlist';
130 if ( !$this->watchlistExpiry ) {
135 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
141 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
143 $this->expiryFormFieldName => [
145 'label-message' =>
'confirm-watch-label',
146 'options' => $expiryOptions[
'options'],
147 'default' => $expiryOptions[
'default'],
165 $expiryOptions = self::getExpiryOptionsFromMessage( $msgLocalizer );
166 $default = in_array(
'infinite', $expiryOptions )
168 : current( $expiryOptions );
172 $default = $watchedItem->
getExpiry( TS_ISO_8601 );
174 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
177 'options' => $expiryOptions,
178 'default' => $default,
190 private static function getExpiryOptionsFromMessage(
193 $expiryOptionsMsg = $msgLocalizer->msg(
'watchlist-expiry-options' );
194 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
195 $options = XmlSelect::parseOptionsMessage(
200 foreach ( $options as $label => $value ) {
202 $expiryOptions[$label] = $value;
208 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
209 return self::getExpiryOptionsFromMessage( $msgLocalizer,
'en' );
212 return $expiryOptions;
216 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
218 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
236 $submittedExpiry = $this->getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
237 $this->getOutput()->addWikiMsg( $this->makeSuccessMessage( $submittedExpiry ) );
241 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
243 if ( $submittedExpiry ) {
246 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS_ISO_8601 );
249 $expiryDays = WatchedItem::calculateExpiryInDays( $expiry );
250 $defaultLabels = static::getExpiryOptions( $this->getContext(),
false )[
'options'];
251 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
255 $isTalk = $this->
getTitle()->isTalkPage();
257 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
258 } elseif ( $expiryDays >= 1 ) {
259 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
260 $params[] = $localizedExpiry ===
false
261 ? $this->getContext()->msg(
'days', $expiryDays )->text()
264 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
267 return MessageValue::new( $msgKey )->params( $this->
getTitle()->getPrefixedText(), ...
$params );
wfIsInfinity( $str)
Determine input string is represents as infinity.
array $params
The job parameters.
getContext()
Get the IContextSource in use here.
getUser()
Shortcut to get the User being used for this instance.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getAuthority()
Shortcut to get the Authority executing this instance.
getRequest()
Get the WebRequest being used for this instance.
Legacy class representing an editable page and handling UI for some page actions.
A class containing constants representing the names of configuration variables.
Redirect a user to the login page or account creation page.
Page addition to a user's watchlist.
getRestriction()
Get the permission required to perform this action.
static getExpiryOptions(MessageLocalizer $msgLocalizer, $watchedItem)
Get options and default for a watchlist expiry select list.
getDescription()
Returns the description that goes below the <h1> element.
string $expiryFormFieldName
bool $watchlistExpiry
The value of the $wgWatchlistExpiry configuration variable.
requiresUnblock()
Whether this action can still be executed by a blocked user.
getFormFields()
Get an HTMLForm descriptor array.
usesOOUI()
Whether the form should use OOUI.
__construct(Article $article, IContextSource $context, WatchlistManager $watchlistManager, WatchedItemStore $watchedItemStore)
Only public since 1.21.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
false WatchedItem $watchedItem
checkCanExecute(User $user)
onSuccess()
Show one of 8 possible success messages.
onSubmit( $data)
Process the form on POST submission.
getName()
Return the name of the action this object responds to.
makeSuccessMessage(string $submittedExpiry)
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.