61 parent::__construct( $article,
$context );
62 $this->watchlistExpiry = $this->
getContext()->getConfig()->get( MainConfigNames::WatchlistExpiry );
63 if ( $this->watchlistExpiry ) {
70 $this->watchlistManager = $watchlistManager;
88 $result = $this->watchlistManager->setWatch(
92 $this->
getRequest()->getVal(
'wp' . $this->expiryFormFieldName )
95 return Status::wrap( $result );
105 parent::checkCanExecute( $user );
109 return 'editmywatchlist';
118 if ( !$this->watchlistExpiry ) {
123 'default' => $this->
msg(
'confirm-watch-top' )->parse(),
129 $expiryOptions = static::getExpiryOptions( $this->
getContext(), $this->watchedItem );
131 $this->expiryFormFieldName => [
133 'label-message' =>
'confirm-watch-label',
134 'options' => $expiryOptions[
'options'],
135 'default' => $expiryOptions[
'default'],
153 $expiryOptions = self::getExpiryOptionsFromMessage( $msgLocalizer );
154 $default = in_array(
'infinite', $expiryOptions )
156 : current( $expiryOptions );
162 $expiryOptions = array_merge( [ $daysLeft => $default ], $expiryOptions );
165 'options' => $expiryOptions,
166 'default' => $default,
178 private static function getExpiryOptionsFromMessage(
181 $expiryOptionsMsg = $msgLocalizer->
msg(
'watchlist-expiry-options' );
182 $optionsText = !$lang ? $expiryOptionsMsg->text() : $expiryOptionsMsg->inLanguage( $lang )->text();
188 foreach ( $options as $label => $value ) {
190 $expiryOptions[$label] = $value;
196 if ( !$expiryOptions && $expiryOptionsMsg->getLanguage()->getCode() !==
'en' ) {
197 return self::getExpiryOptionsFromMessage( $msgLocalizer,
'en' );
200 return $expiryOptions;
204 $msg = $this->watchlistExpiry && $this->watchedItem ?
'updatewatchlist' :
'addwatch';
206 $submitMsg = $this->watchlistExpiry ?
'confirm-watch-button-expiry' :
'confirm-watch-button';
224 $msgKey = $this->
getTitle()->isTalkPage() ?
'addedwatchtext-talk' :
'addedwatchtext';
226 $submittedExpiry = $this->
getContext()->getRequest()->getText(
'wp' . $this->expiryFormFieldName );
227 if ( $submittedExpiry ) {
230 $expiry = ExpiryDef::normalizeExpiry( $submittedExpiry, TS_ISO_8601 );
234 $defaultLabels = static::getExpiryOptions( $this->
getContext(),
false )[
'options'];
235 $localizedExpiry = array_search( $submittedExpiry, $defaultLabels );
236 $expiryLabel = $expiryDays && $localizedExpiry ===
false
237 ? $this->
getContext()->msg(
'days', $expiryDays )->text()
242 $isTalk = $this->
getTitle()->isTalkPage();
244 $msgKey = $isTalk ?
'addedwatchindefinitelytext-talk' :
'addedwatchindefinitelytext';
245 } elseif ( $expiryDays > 0 ) {
246 $msgKey = $isTalk ?
'addedwatchexpirytext-talk' :
'addedwatchexpirytext';
247 } elseif ( $expiryDays < 1 ) {
248 $msgKey = $isTalk ?
'addedwatchexpiryhours-talk' :
'addedwatchexpiryhours';
251 $this->getOutput()->addWikiMsg( $msgKey, $this->
getTitle()->getPrefixedText(), $expiryLabel );
wfIsInfinity( $str)
Determine input string is represents as infinity.
IContextSource null $context
IContextSource if specified; otherwise we'll use the Context from the Page.
getTitle()
Shortcut to get the Title object from the page.
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.
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)
Checks if the given user (identified by an object) can perform this action.
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 calculateExpiryInDays(?string $expiry)
Get the number of days remaining until the given expiry time.
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.