41 protected $expiryFormFieldName =
'expiry';
44 protected $watchedItem =
false;
62 parent::__construct( $article, $context );
63 $this->watchlistExpiry = $this->
getContext()->getConfig()->get( MainConfigNames::WatchlistExpiry );
64 if ( $this->watchlistExpiry ) {
71 $this->watchlistManager = $watchlistManager;
89 $result = $this->watchlistManager->setWatch(
93 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
96 return Status::wrap( $result );
112 parent::checkCanExecute( $user );
116 return 'editmywatchlist';
125 if ( !$this->watchlistExpiry ) {
130 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
136 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
138 $this->expiryFormFieldName => [
140 'label-message' =>
'confirm-watch-label',
141 'options' => $expiryOptions[
'options'],
142 'default' => $expiryOptions[
'default'],
160 $expiryOptions = self::getExpiryOptionsFromMessage( $msgLocalizer );
161 $default = in_array(
'infinite', $expiryOptions )
163 : current( $expiryOptions );
167 $default = $watchedItem->
getExpiry( TS_ISO_8601 );
169 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
172 'options' => $expiryOptions,
173 'default' => $default,
185 private static function getExpiryOptionsFromMessage(
188 $expiryOptionsMsg = $msgLocalizer->msg(
'watchlist-expiry-options' );
189 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
190 $options = XmlSelect::parseOptionsMessage(
195 foreach ( $options as $label => $value ) {
197 $expiryOptions[$label] = $value;
203 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
204 return self::getExpiryOptionsFromMessage( $msgLocalizer,
'en' );
207 return $expiryOptions;
211 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
212 $form->setWrapperLegendMsg( $msg );
213 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
214 $form->setSubmitTextMsg( $submitMsg );
215 $form->setTokenSalt(
'watch' );
231 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
233 $submittedExpiry = $this->
getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
234 if ( $submittedExpiry ) {
237 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS_ISO_8601 );
240 $expiryDays = WatchedItem::calculateExpiryInDays( $expiry );
241 $defaultLabels = static::getExpiryOptions( $this->
getContext(),
false )[
'options'];
242 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
243 $expiryLabel = $expiryDays && $localizedExpiry ===
false
244 ? $this->
getContext()->msg(
'days', $expiryDays )->text()
249 $isTalk = $this->
getTitle()->isTalkPage();
251 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
252 } elseif ( $expiryDays > 0 ) {
253 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
254 } elseif ( $expiryDays < 1 ) {
255 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
258 $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.
Storage layer class for WatchedItems.
getWatchedItem(UserIdentity $user, $target)
Representation of a pair of user and title for watchlist entries.
getExpiryInDaysText(MessageLocalizer $msgLocalizer, $isDropdownOption=false)
Get days remaining until a watched item expires as a text.
getExpiry(?int $style=TS_MW)
When the watched item will expire.
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.