MessageCache invalidation improvements
[mediawiki.git] / includes / actions / MarkpatrolledAction.php
blob8df60445da00a3678ba3d59e5fd4cb3be0177f5a
1 <?php
2 /**
3 * Copyright © 2011 Alexandre Emsenhuber
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
19 * @file
20 * @ingroup Actions
23 /**
24 * Mark a revision as patrolled on a page
26 * @ingroup Actions
28 class MarkpatrolledAction extends FormAction {
30 public function getName() {
31 return 'markpatrolled';
34 protected function getDescription() {
35 // Disable default header "subtitle"
36 return '';
39 public function getRestriction() {
40 return 'patrol';
43 protected function getRecentChange( $data = null ) {
44 $rc = null;
45 // Note: This works both on initial GET url and after submitting the form
46 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
47 if ( $rcId ) {
48 $rc = RecentChange::newFromId( $rcId );
50 if ( !$rc ) {
51 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
53 return $rc;
56 protected function preText() {
57 $rc = $this->getRecentChange();
58 $title = $rc->getTitle();
60 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
61 $revId = $rc->getAttribute( 'rc_this_oldid' );
62 $query = [
63 'curid' => $rc->getAttribute( 'rc_cur_id' ),
64 'diff' => $revId,
65 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
67 $revlink = Linker::link( $title, htmlspecialchars( $revId ), [], $query );
68 $pagelink = Linker::link( $title, htmlspecialchars( $title->getPrefixedText() ) );
70 return $this->msg( 'confirm-markpatrolled-top' )->params(
71 $title->getPrefixedText(),
72 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
73 Message::rawParam( $pagelink ),
74 Message::rawParam( $revlink )
75 )->parse();
78 protected function alterForm( HTMLForm $form ) {
79 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
80 $form->setTokenSalt( 'patrol' );
81 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
84 /**
85 * @return bool|array True for success, false for didn't-try, array of errors on failure
87 public function onSubmit( $data ) {
88 $user = $this->getUser();
89 $rc = $this->getRecentChange( $data );
90 $errors = $rc->doMarkPatrolled( $user );
92 if ( in_array( [ 'rcpatroldisabled' ], $errors ) ) {
93 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
96 // Guess where the user came from
97 // TODO: Would be nice to see where the user actually came from
98 if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
99 $returnTo = 'Newpages';
100 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
101 $returnTo = 'Newfiles';
102 } else {
103 $returnTo = 'Recentchanges';
105 $return = SpecialPage::getTitleFor( $returnTo );
107 if ( in_array( [ 'markedaspatrollederror-noautopatrol' ], $errors ) ) {
108 $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrollederror' ) );
109 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
110 $this->getOutput()->returnToMain( null, $return );
111 return true;
114 if ( $errors ) {
115 if ( !in_array( [ 'hookaborted' ], $errors ) ) {
116 throw new PermissionsError( 'patrol', $errors );
118 // The hook itself has handled any output
119 return $errors;
122 $this->getOutput()->setPageTitle( $this->msg( 'markedaspatrolled' ) );
123 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
124 $this->getOutput()->returnToMain( null, $return );
125 return true;
128 public function onSuccess() {
129 // Required by parent class. Redundant as our onSubmit handles output already.
132 public function doesWrites() {
133 return true;