| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
use MediaWiki\Context\IContextSource; |
| 24 |
use MediaWiki\HTMLForm\HTMLForm; |
| 25 |
use MediaWiki\Watchlist\WatchedItemStore; |
| 26 |
use MediaWiki\Watchlist\WatchlistManager; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class UnwatchAction extends WatchAction { |
| 34 |
|
| 35 |
private WatchlistManager $watchlistManager; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
} |