Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiPatrol.php
blobeba9431430069a5b2f78f2f353b63a5a31d86db8
1 <?php
2 /**
3 * API for MediaWiki 1.14+
5 * Copyright © 2008 Soxred93 soxred93@gmail.com,
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.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
25 namespace MediaWiki\Api;
27 use ChangeTags;
28 use MediaWiki\Revision\RevisionStore;
29 use RecentChange;
30 use Wikimedia\ParamValidator\ParamValidator;
32 /**
33 * Allows user to patrol pages
34 * @ingroup API
36 class ApiPatrol extends ApiBase {
37 private RevisionStore $revisionStore;
39 public function __construct(
40 ApiMain $main,
41 string $action,
42 RevisionStore $revisionStore
43 ) {
44 parent::__construct( $main, $action );
45 $this->revisionStore = $revisionStore;
48 /**
49 * Patrols the article or provides the reason the patrol failed.
51 public function execute() {
52 $params = $this->extractRequestParams();
53 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
55 if ( isset( $params['rcid'] ) ) {
56 $rc = RecentChange::newFromId( $params['rcid'] );
57 if ( !$rc ) {
58 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
60 } else {
61 $rev = $this->revisionStore->getRevisionById( $params['revid'] );
62 if ( !$rev ) {
63 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
65 $rc = $this->revisionStore->getRecentChange( $rev );
66 if ( !$rc ) {
67 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
71 $user = $this->getUser();
72 $tags = $params['tags'];
74 // Check if user can add tags
75 if ( $tags !== null ) {
76 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->getAuthority() );
77 if ( !$ableToTag->isOK() ) {
78 $this->dieStatus( $ableToTag );
82 $status = $rc->markPatrolled( $user, $tags );
84 if ( !$status->isGood() ) {
85 $this->dieStatus( $status );
88 $result = [ 'rcid' => (int)$rc->getAttribute( 'rc_id' ) ];
89 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
90 $this->getResult()->addValue( null, $this->getModuleName(), $result );
93 public function mustBePosted() {
94 return true;
97 public function isWriteMode() {
98 return true;
101 public function getAllowedParams() {
102 return [
103 'rcid' => [
104 ParamValidator::PARAM_TYPE => 'integer'
106 'revid' => [
107 ParamValidator::PARAM_TYPE => 'integer'
109 'tags' => [
110 ParamValidator::PARAM_TYPE => 'tags',
111 ParamValidator::PARAM_ISMULTI => true,
116 public function needsToken() {
117 return 'patrol';
120 protected function getExamplesMessages() {
121 return [
122 'action=patrol&token=123ABC&rcid=230672766'
123 => 'apihelp-patrol-example-rcid',
124 'action=patrol&token=123ABC&revid=230672766'
125 => 'apihelp-patrol-example-revid',
129 public function getHelpUrls() {
130 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';
134 /** @deprecated class alias since 1.43 */
135 class_alias( ApiPatrol::class, 'ApiPatrol' );