MediaWiki  master
UnwatchAction.php
Go to the documentation of this file.
1 <?php
24 
30 class UnwatchAction extends WatchAction {
31 
34 
41  public function __construct(
42  Page $page,
45  WatchedItemStore $watchedItemStore
46  ) {
47  parent::__construct( $page, $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->getContext()->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 }
UnwatchAction\doesWrites
doesWrites()
Definition: UnwatchAction.php:85
Page
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition: Page.php:29
UnwatchAction\onSuccess
onSuccess()
Show one of 8 possible success messages.
Definition: UnwatchAction.php:80
UnwatchAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: UnwatchAction.php:74
getAuthority
getAuthority()
WatchAction
Page addition to a user's watchlist.
Definition: WatchAction.php:31
UnwatchAction
Page removal from a user's watchlist.
Definition: UnwatchAction.php:30
UnwatchAction\__construct
__construct(Page $page, IContextSource $context, WatchlistManager $watchlistManager, WatchedItemStore $watchedItemStore)
Definition: UnwatchAction.php:41
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:132
MediaWiki\Watchlist\WatchlistManager
WatchlistManager service.
Definition: WatchlistManager.php:52
UnwatchAction\getName
getName()
Return the name of the action this object responds to.
Definition: UnwatchAction.php:51
UnwatchAction\onSubmit
onSubmit( $data)
Process the form on POST submission.
Definition: UnwatchAction.php:55
UnwatchAction\$watchlistManager
WatchlistManager $watchlistManager
Definition: UnwatchAction.php:33
Action\$context
IContextSource $context
IContextSource if specified; otherwise we'll use the Context from the Page.
Definition: Action.php:66
Action\getTitle
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:216
UnwatchAction\getFormFields
getFormFields()
Get an HTMLForm descriptor array.
Definition: UnwatchAction.php:64
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
WatchedItemStore
Storage layer class for WatchedItems.
Definition: WatchedItemStore.php:26
HTMLForm\setSubmitTextMsg
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
Definition: HTMLForm.php:1420
Action\$page
WikiPage Article ImagePage CategoryPage Page $page
Page on which we're performing the action.
Definition: Action.php:53
Action\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:228
HTMLForm\setWrapperLegendMsg
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
Definition: HTMLForm.php:1625
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:156
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:143