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 protected function getDescription(){
34 return wfMsg( 'addedwatch' );
37 protected function checkCanExecute( User
$user ){
38 if ( $user->isAnon() ) {
39 throw new ErrorPageError( 'watchnologin', 'watchnologintext' );
41 return parent
::checkCanExecute( $user );
44 public function onView() {
45 wfProfileIn( __METHOD__
);
47 $user = $this->getUser();
48 if ( wfRunHooks( 'WatchArticle', array( &$user, &$this->page
) ) ) {
49 $this->getUser()->addWatch( $this->getTitle() );
50 wfRunHooks( 'WatchArticleComplete', array( &$user, &$this->page
) );
53 wfProfileOut( __METHOD__
);
55 return wfMessage( 'addedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
59 class UnwatchAction
extends WatchAction
{
61 public function getName(){
65 protected function getDescription(){
66 return wfMsg( 'removedwatch' );
69 public function onView() {
70 wfProfileIn( __METHOD__
);
72 $user = $this->getUser();
73 if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$this->page
) ) ) {
74 $this->getUser()->removeWatch( $this->getTitle() );
75 wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$this->page
) );
78 wfProfileOut( __METHOD__
);
80 return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse();