45 protected $expiryFormFieldName =
'expiry';
48 protected $watchedItem =
false;
66 parent::__construct( $article, $context );
67 $this->watchlistExpiry = $this->
getContext()->getConfig()->get( MainConfigNames::WatchlistExpiry );
68 if ( $this->watchlistExpiry ) {
75 $this->watchlistManager = $watchlistManager;
93 $result = $this->watchlistManager->setWatch(
97 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
100 return Status::wrap( $result );
116 parent::checkCanExecute( $user );
120 return 'editmywatchlist';
129 if ( !$this->watchlistExpiry ) {
134 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
140 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
142 $this->expiryFormFieldName => [
144 'label-message' =>
'confirm-watch-label',
145 'options' => $expiryOptions[
'options'],
146 'default' => $expiryOptions[
'default'],
164 $expiryOptions = self::getExpiryOptionsFromMessage( $msgLocalizer );
165 $default = in_array(
'infinite', $expiryOptions )
167 : current( $expiryOptions );
171 $default = $watchedItem->
getExpiry( TS_ISO_8601 );
173 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
176 'options' => $expiryOptions,
177 'default' => $default,
189 private static function getExpiryOptionsFromMessage(
192 $expiryOptionsMsg = $msgLocalizer->msg(
'watchlist-expiry-options' );
193 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
194 $options = XmlSelect::parseOptionsMessage(
199 foreach ( $options as $label => $value ) {
201 $expiryOptions[$label] = $value;
207 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
208 return self::getExpiryOptionsFromMessage( $msgLocalizer,
'en' );
211 return $expiryOptions;
215 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
217 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
235 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
237 $submittedExpiry = $this->
getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
238 if ( $submittedExpiry ) {
241 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS_ISO_8601 );
244 $expiryDays = WatchedItem::calculateExpiryInDays( $expiry );
245 $defaultLabels = static::getExpiryOptions( $this->
getContext(),
false )[
'options'];
246 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
247 $expiryLabel = $expiryDays && $localizedExpiry ===
false
248 ? $this->
getContext()->msg(
'days', $expiryDays )->text()
253 $isTalk = $this->
getTitle()->isTalkPage();
255 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
256 } elseif ( $expiryDays > 0 ) {
257 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
258 } elseif ( $expiryDays < 1 ) {
259 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
262 $this->getOutput()->addWikiMsg( $msgKey, $this->
getTitle()->getPrefixedText(), $expiryLabel );
wfIsInfinity( $str)
Determine input string is represents as infinity.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
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.
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.
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.