MediaWiki  master
UnwatchAction.php
Go to the documentation of this file.
1 <?php
24 
30 class UnwatchAction extends WatchAction {
31 
33  private $watchlistManager;
34 
41  public function __construct(
42  Article $article,
44  WatchlistManager $watchlistManager,
45  WatchedItemStore $watchedItemStore
46  ) {
47  parent::__construct( $article, $context, $watchlistManager, $watchedItemStore );
48  $this->watchlistManager = $watchlistManager;
49  }
50 
51  public function getName() {
52  return 'unwatch';
53  }
54 
55  public function onSubmit( $data ) {
56  $this->watchlistManager->removeWatch(
57  $this->getAuthority(),
58  $this->getTitle()
59  );
60 
61  return true;
62  }
63 
64  protected function getFormFields() {
65  return [
66  'intro' => [
67  'type' => 'info',
68  'raw' => true,
69  'default' => $this->msg( 'confirm-unwatch-top' )->parse()
70  ]
71  ];
72  }
73 
74  protected function alterForm( HTMLForm $form ) {
75  parent::alterForm( $form );
76  $form->setWrapperLegendMsg( 'removewatch' );
77  $form->setSubmitTextMsg( 'confirm-unwatch-button' );
78  }
79 
80  public function onSuccess() {
81  $msgKey = $this->getTitle()->isTalkPage() ? 'removedwatchtext-talk' : 'removedwatchtext';
82  $this->getOutput()->addWikiMsg( $msgKey, $this->getTitle()->getPrefixedText() );
83  }
84 
85  public function doesWrites() {
86  return true;
87  }
88 }
IContextSource null $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition: Action.php:57
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:224
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:154
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:236
getAuthority()
Shortcut to get the Authority executing this instance.
Definition: Action.php:174
Legacy class representing an editable page and handling UI for some page actions.
Definition: Article.php:48
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:150
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1613
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1818
Page removal from a user's watchlist.
onSubmit( $data)
Process the form on POST submission.
getFormFields()
Get an HTMLForm descriptor array.
__construct(Article $article, IContextSource $context, WatchlistManager $watchlistManager, WatchedItemStore $watchedItemStore)
getName()
Return the name of the action this object responds to.
onSuccess()
Show one of 8 possible success messages.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Page addition to a user's watchlist.
Definition: WatchAction.php:32
Storage layer class for WatchedItems.
Interface for objects which can provide a MediaWiki context on request.