MediaWiki master
UnwatchAction.php
Go to the documentation of this file.
1<?php
27
34
35 private WatchlistManager $watchlistManager;
36
43 public function __construct(
44 Article $article,
45 IContextSource $context,
46 WatchlistManager $watchlistManager,
47 WatchedItemStore $watchedItemStore
48 ) {
49 parent::__construct( $article, $context, $watchlistManager, $watchedItemStore );
50 $this->watchlistManager = $watchlistManager;
51 }
52
53 public function getName() {
54 return 'unwatch';
55 }
56
57 public function onSubmit( $data ) {
58 $this->watchlistManager->removeWatch(
59 $this->getAuthority(),
60 $this->getTitle()
61 );
62
63 return true;
64 }
65
66 protected function getFormFields() {
67 return [
68 'intro' => [
69 'type' => 'info',
70 'raw' => true,
71 'default' => $this->msg( 'confirm-unwatch-top' )->parse()
72 ]
73 ];
74 }
75
76 protected function alterForm( HTMLForm $form ) {
77 parent::alterForm( $form );
78 $form->setWrapperLegendMsg( 'removewatch' );
79 $form->setSubmitTextMsg( 'confirm-unwatch-button' );
80 }
81
82 public function onSuccess() {
83 $msgKey = $this->getTitle()->isTalkPage() ? 'removedwatchtext-talk' : 'removedwatchtext';
84 $this->getOutput()->addWikiMsg( $msgKey, $this->getTitle()->getPrefixedText() );
85 }
86
87 public function doesWrites() {
88 return true;
89 }
90}
getAuthority()
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:141
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:223
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:70
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:208
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.
Storage layer class for WatchedItems.
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.
Interface for objects which can provide a MediaWiki context on request.