Moved action=deletetrackback and action=markpatrolled to Action class.
[lhc/web/wiklou.git] / includes / actions / MarkpatrolledAction.php
1 <?php
2 /**
3 * Mark a revision as patrolled on a page
4 *
5 * Copyright © 2011 Alexandre Emsenhuber
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * @file
22 * @ingroup Actions
23 */
24
25 class MarkpatrolledAction extends FormlessAction {
26
27 public function getName() {
28 return 'markpatrolled';
29 }
30
31 public function getRestriction() {
32 return 'read';
33 }
34
35 protected function getDescription() {
36 return '';
37 }
38
39 protected function checkCanExecute( User $user ) {
40 if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ), $this->getRequest()->getInt( 'rcid' ) ) ) {
41 throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' );
42 }
43
44 return parent::checkCanExecute( $user );
45 }
46
47 public function onView() {
48 $rc = RecentChange::newFromId( $this->getRequest()->getInt( 'rcid' ) );
49
50 if ( is_null( $rc ) ) {
51 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
52 }
53
54 # It would be nice to see where the user had actually come from, but for now just guess
55 $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
56 $return = SpecialPage::getTitleFor( $returnto );
57
58 $errors = $rc->doMarkPatrolled();
59
60 if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
61 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
62 }
63
64 if ( in_array( array( 'hookaborted' ), $errors ) ) {
65 // The hook itself has handled any output
66 return;
67 }
68
69 if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
70 $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
71 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
72 $this->getOutput()->returnToMain( null, $return );
73 return;
74 }
75
76 if ( !empty( $errors ) ) {
77 $this->getOutput()->showPermissionsErrorPage( $errors );
78 return;
79 }
80
81 # Inform the user
82 $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrolled' ) );
83 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
84 $this->getOutput()->returnToMain( null, $return );
85 }
86 }