Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / includes / api / ApiPatrol.php
blobc33542f1c7aa2ea87bf5f7623a9924bbbbb69130
1 <?php
2 /**
3 * API for MediaWiki 1.14+
5 * Created on Sep 2, 2008
7 * Copyright © 2008 Soxred93 soxred93@gmail.com,
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * Allows user to patrol pages
29 * @ingroup API
31 class ApiPatrol extends ApiBase {
33 /**
34 * Patrols the article or provides the reason the patrol failed.
36 public function execute() {
37 $params = $this->extractRequestParams();
38 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
40 if ( isset( $params['rcid'] ) ) {
41 $rc = RecentChange::newFromId( $params['rcid'] );
42 if ( !$rc ) {
43 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
45 } else {
46 $rev = Revision::newFromId( $params['revid'] );
47 if ( !$rev ) {
48 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
50 $rc = $rev->getRecentChange();
51 if ( !$rc ) {
52 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
56 $user = $this->getUser();
57 $tags = $params['tags'];
59 // Check if user can add tags
60 if ( !is_null( $tags ) ) {
61 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $user );
62 if ( !$ableToTag->isOK() ) {
63 $this->dieStatus( $ableToTag );
67 $retval = $rc->doMarkPatrolled( $user, false, $tags );
69 if ( $retval ) {
70 $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
73 $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
74 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
75 $this->getResult()->addValue( null, $this->getModuleName(), $result );
78 public function mustBePosted() {
79 return true;
82 public function isWriteMode() {
83 return true;
86 public function getAllowedParams() {
87 return [
88 'rcid' => [
89 ApiBase::PARAM_TYPE => 'integer'
91 'revid' => [
92 ApiBase::PARAM_TYPE => 'integer'
94 'tags' => [
95 ApiBase::PARAM_TYPE => 'tags',
96 ApiBase::PARAM_ISMULTI => true,
101 public function needsToken() {
102 return 'patrol';
105 protected function getExamplesMessages() {
106 return [
107 'action=patrol&token=123ABC&rcid=230672766'
108 => 'apihelp-patrol-example-rcid',
109 'action=patrol&token=123ABC&revid=230672766'
110 => 'apihelp-patrol-example-revid',
114 public function getHelpUrls() {
115 return 'https://www.mediawiki.org/wiki/API:Patrol';