Follow up r85922 moving the </caption> to another line, fixing one of the tests added...
[lhc/web/wiklou.git] / includes / actions / WatchAction.php
1 <?php
2 /**
3 * Performs the watch and unwatch actions on a page
4 *
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.
9 *
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.
14 *
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
18 *
19 * @file
20 * @ingroup Actions
21 */
22
23 class WatchAction extends FormlessAction {
24
25 public function getName(){
26 return 'watch';
27 }
28
29 public function getRestriction(){
30 return 'read';
31 }
32
33 protected function getDescription(){
34 return wfMsg( 'addedwatch' );
35 }
36
37 protected function checkCanExecute( User $user ){
38 if ( $user->isAnon() ) {
39 throw new ErrorPageError( 'watchnologin', 'watchnologintext' );
40 }
41 return parent::checkCanExecute( $user );
42 }
43
44 public function onView() {
45 wfProfileIn( __METHOD__ );
46
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 ) );
51 }
52
53 wfProfileOut( __METHOD__ );
54
55 return wfMessage( 'addedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
56 }
57 }
58
59 class UnwatchAction extends WatchAction {
60
61 public function getName(){
62 return 'unwatch';
63 }
64
65 protected function getDescription(){
66 return wfMsg( 'removedwatch' );
67 }
68
69 public function onView() {
70 wfProfileIn( __METHOD__ );
71
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 ) );
76 }
77
78 wfProfileOut( __METHOD__ );
79
80 return wfMessage( 'removedwatchtext', $this->getTitle()->getPrefixedText() )->parse();
81 }
82 }