3 * Performs the watch and unwatch actions on a page
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 class WatchAction
extends FormlessAction
{
25 public function getName() {
29 public function getRestriction() {
33 public function requiresUnblock() {
37 protected function getDescription() {
38 return wfMsg( 'addedwatch' );
41 protected function checkCanExecute( User
$user ) {
42 if ( $user->isAnon() ) {
43 throw new ErrorPageError( 'watchnologin', 'watchnologintext' );
45 return parent
::checkCanExecute( $user );
48 public function onView() {
49 wfProfileIn( __METHOD__
);
51 $user = $this->getUser();
52 if ( wfRunHooks( 'WatchArticle', array( &$user, &$this->page
) ) ) {
53 $this->getUser()->addWatch( $this->getTitle() );
54 wfRunHooks( 'WatchArticleComplete', array( &$user, &$this->page
) );
57 wfProfileOut( __METHOD__
);
59 return wfMessage( 'addedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
63 class UnwatchAction
extends WatchAction
{
65 public function getName() {
69 protected function getDescription() {
70 return wfMsg( 'removedwatch' );
73 public function onView() {
74 wfProfileIn( __METHOD__
);
76 $user = $this->getUser();
77 if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$this->page
) ) ) {
78 $this->getUser()->removeWatch( $this->getTitle() );
79 wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$this->page
) );
82 wfProfileOut( __METHOD__
);
84 return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse();