MediaWiki master
UnwatchAction.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Actions;
11
19
26
27 public function __construct(
28 Article $article,
29 IContextSource $context,
30 private readonly WatchlistManager $watchlistManager,
31 WatchedItemStore $watchedItemStore,
32 WatchlistLabelStore $watchlistLabelStore,
33 UserOptionsLookup $userOptionsLookup,
34 ) {
35 parent::__construct( $article, $context, $watchlistManager, $watchedItemStore, $watchlistLabelStore,
36 $userOptionsLookup );
37 }
38
40 public function getName() {
41 return 'unwatch';
42 }
43
45 public function onSubmit( $data ) {
46 $this->watchlistManager->removeWatch(
47 $this->getAuthority(),
48 $this->getTitle()
49 );
50
51 return true;
52 }
53
55 protected function getFormFields() {
56 return [
57 'intro' => [
58 'type' => 'info',
59 'raw' => true,
60 'default' => $this->msg( 'confirm-unwatch-top' )->parse()
61 ]
62 ];
63 }
64
65 protected function alterForm( HTMLForm $form ) {
66 parent::alterForm( $form );
67 $form->setWrapperLegendMsg( 'removewatch' );
68 $form->setSubmitTextMsg( 'confirm-unwatch-button' );
69 }
70
72 public function onSuccess() {
73 $msgKey = $this->getTitle()->isTalkPage() ? 'removedwatchtext-talk' : 'removedwatchtext';
74 $this->getOutput()->addWikiMsg( $msgKey, $this->getTitle()->getPrefixedText() );
75 }
76
78 public function doesWrites() {
79 return true;
80 }
81}
82
84class_alias( UnwatchAction::class, 'UnwatchAction' );
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:205
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:191
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:122
getAuthority()
Shortcut to get the Authority executing this instance.
Definition Action.php:142
Page removal from a user's watchlist.
__construct(Article $article, IContextSource $context, private readonly WatchlistManager $watchlistManager, WatchedItemStore $watchedItemStore, WatchlistLabelStore $watchlistLabelStore, UserOptionsLookup $userOptionsLookup,)
getFormFields()
Get an HTMLForm descriptor array.to override array
onSubmit( $data)
Process the form on POST submission.If you don't want to do anything with the form,...
onSuccess()
Show one of 8 possible success messages.The messages are:addedwatchtextaddedwatchtext-talkaddedwatchi...
getName()
Return the name of the action this object responds to.1.17string Lowercase name
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:214
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:65
Provides access to user options.
Storage layer class for WatchedItems.
Service class for storage of watchlist labels.
Interface for objects which can provide a MediaWiki context on request.