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