38 protected $expiryFormFieldName =
'expiry';
41 protected $watchedItem =
false;
44 private $watchlistManager;
60 parent::__construct( $page, $context );
61 $this->watchlistExpiry = $this->
getContext()->getConfig()->get( MainConfigNames::WatchlistExpiry );
62 if ( $this->watchlistExpiry ) {
69 $this->watchlistManager = $watchlistManager;
87 $result = $this->watchlistManager->setWatch(
91 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
94 return Status::wrap( $result );
102 parent::checkCanExecute( $user );
111 if ( !$this->watchlistExpiry ) {
116 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
122 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
124 $this->expiryFormFieldName => [
126 'label-message' =>
'confirm-watch-label',
127 'options' => $expiryOptions[
'options'],
128 'default' => $expiryOptions[
'default'],
146 $expiryOptions = self::getExpiryOptionsFromMessage( $msgLocalizer );
147 $default = in_array(
'infinite', $expiryOptions )
149 : current( $expiryOptions );
153 $default = $watchedItem->
getExpiry( TS_ISO_8601 );
155 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
158 'options' => $expiryOptions,
159 'default' => $default,
171 private static function getExpiryOptionsFromMessage(
174 $expiryOptionsMsg = $msgLocalizer->msg(
'watchlist-expiry-options' );
175 $optionsText = !
$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage(
$lang )->text();
181 foreach ( $options as $label => $value ) {
183 $expiryOptions[$label] = $value;
189 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
190 return self::getExpiryOptionsFromMessage( $msgLocalizer,
'en' );
193 return $expiryOptions;
197 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
199 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
217 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
219 $submittedExpiry = $this->
getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
220 if ( $submittedExpiry ) {
223 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS_ISO_8601 );
226 $expiryDays = WatchedItem::calculateExpiryInDays( $expiry );
227 $defaultLabels = static::getExpiryOptions( $this->
getContext(),
false )[
'options'];
228 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
229 $expiryLabel = $expiryDays && $localizedExpiry ===
false
230 ? $this->
getContext()->msg(
'days', $expiryDays )->text()
235 $isTalk = $this->
getTitle()->isTalkPage();
237 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
238 } elseif ( $expiryDays > 0 ) {
239 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
240 } elseif ( $expiryDays < 1 ) {
241 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
244 $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()
getRequest()
Get the WebRequest being used for this instance.
A class containing constants representing the names of configuration variables.
Redirect a user to the login page.
isNamed()
Is the user a normal non-temporary registered user?
Page addition to a user's watchlist.
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.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
false WatchedItem $watchedItem
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
__construct(Page $page, IContextSource $context, WatchlistManager $watchlistManager, WatchedItemStore $watchedItemStore)
Only public since 1.21.
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.
static parseOptionsMessage(string $msg)
Parse labels and values out of a comma- and colon-separated list of options, such as is used for expi...
Interface for objects which can provide a MediaWiki context on request.
Interface for localizing messages in MediaWiki.
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
if(!isset( $args[0])) $lang