Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / actions / MarkpatrolledAction.php
blobaf9da4780d3c2d942a76b6bdaed76fd663e3e31a
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 use MediaWiki\Context\IContextSource;
24 use MediaWiki\HTMLForm\HTMLForm;
25 use MediaWiki\Linker\LinkRenderer;
26 use MediaWiki\Message\Message;
27 use MediaWiki\SpecialPage\SpecialPage;
29 /**
30 * Mark a revision as patrolled on a page
32 * @ingroup Actions
34 class MarkpatrolledAction extends FormAction {
36 private LinkRenderer $linkRenderer;
38 /**
39 * @param Article $article
40 * @param IContextSource $context
41 * @param LinkRenderer $linkRenderer
43 public function __construct(
44 Article $article,
45 IContextSource $context,
46 LinkRenderer $linkRenderer
47 ) {
48 parent::__construct( $article, $context );
49 $this->linkRenderer = $linkRenderer;
52 public function getName() {
53 return 'markpatrolled';
56 protected function getDescription() {
57 // Disable default header "subtitle"
58 return '';
61 public function getRestriction() {
62 return 'patrol';
65 protected function usesOOUI() {
66 return true;
69 protected function getRecentChange( $data = null ) {
70 $rc = null;
71 // Note: This works both on initial GET url and after submitting the form
72 $rcId = $data ? intval( $data['rcid'] ) : $this->getRequest()->getInt( 'rcid' );
73 if ( $rcId ) {
74 $rc = RecentChange::newFromId( $rcId );
76 if ( !$rc ) {
77 throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
79 return $rc;
82 protected function preText() {
83 $rc = $this->getRecentChange();
84 $title = $rc->getTitle();
86 // Based on logentry-patrol-patrol (see PatrolLogFormatter)
87 $revId = $rc->getAttribute( 'rc_this_oldid' );
88 $query = [
89 'curid' => $rc->getAttribute( 'rc_cur_id' ),
90 'diff' => $revId,
91 'oldid' => $rc->getAttribute( 'rc_last_oldid' )
93 $revlink = $this->linkRenderer->makeLink( $title, $revId, [], $query );
94 $pagelink = $this->linkRenderer->makeLink( $title, $title->getPrefixedText() );
96 return $this->msg( 'confirm-markpatrolled-top' )->params(
97 $title->getPrefixedText(),
98 // Provide pre-rendered link as parser would render [[:$1]] as bold non-link
99 Message::rawParam( $pagelink ),
100 Message::rawParam( $revlink )
101 )->parse();
104 protected function alterForm( HTMLForm $form ) {
105 $form->addHiddenField( 'rcid', $this->getRequest()->getInt( 'rcid' ) );
106 $form->setTokenSalt( 'patrol' );
107 $form->setSubmitTextMsg( 'confirm-markpatrolled-button' );
111 * @param array $data
112 * @return bool|StatusValue True for success, false for didn't-try, StatusValue on failure
114 public function onSubmit( $data ) {
115 $rc = $this->getRecentChange( $data );
116 $status = $rc->markPatrolled( $this->getAuthority() );
118 if ( $status->hasMessage( 'rcpatroldisabled' ) ) {
119 throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
122 // Guess where the user came from
123 // TODO: Would be nice to see where the user actually came from
124 if ( $rc->getAttribute( 'rc_type' ) == RC_NEW ) {
125 $returnTo = 'Newpages';
126 } elseif ( $rc->getAttribute( 'rc_log_type' ) == 'upload' ) {
127 $returnTo = 'Newfiles';
128 } else {
129 $returnTo = 'Recentchanges';
131 $return = SpecialPage::getTitleFor( $returnTo );
133 if ( $status->hasMessage( 'markedaspatrollederror-noautopatrol' ) ) {
134 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrollederror' ) );
135 $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
136 $this->getOutput()->returnToMain( null, $return );
137 return true;
140 if ( !$status->isGood() ) {
141 if ( !$status->hasMessage( 'hookaborted' ) ) {
142 throw new PermissionsError( 'patrol', $status );
144 // The MarkPatrolled hook itself has handled any output
145 return $status;
148 $this->getOutput()->setPageTitleMsg( $this->msg( 'markedaspatrolled' ) );
149 $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
150 $this->getOutput()->returnToMain( null, $return );
151 return true;
154 public function onSuccess() {
155 // Required by parent class. Redundant as our onSubmit handles output already.
158 public function doesWrites() {
159 return true;