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
26 * Allows user to patrol pages
29 class ApiPatrol
extends ApiBase
{
32 * Patrols the article or provides the reason the patrol failed.
34 public function execute() {
35 $params = $this->extractRequestParams();
36 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
38 if ( isset( $params['rcid'] ) ) {
39 $rc = RecentChange
::newFromId( $params['rcid'] );
41 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
44 $rev = Revision
::newFromId( $params['revid'] );
46 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
48 $rc = $rev->getRecentChange();
50 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
54 $user = $this->getUser();
55 $tags = $params['tags'];
57 // Check if user can add tags
58 if ( !is_null( $tags ) ) {
59 $ableToTag = ChangeTags
::canAddTagsAccompanyingChange( $tags, $user );
60 if ( !$ableToTag->isOK() ) {
61 $this->dieStatus( $ableToTag );
65 $retval = $rc->doMarkPatrolled( $user, false, $tags );
68 $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
71 $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
72 ApiQueryBase
::addTitleInfo( $result, $rc->getTitle() );
73 $this->getResult()->addValue( null, $this->getModuleName(), $result );
76 public function mustBePosted() {
80 public function isWriteMode() {
84 public function getAllowedParams() {
87 ApiBase
::PARAM_TYPE
=> 'integer'
90 ApiBase
::PARAM_TYPE
=> 'integer'
93 ApiBase
::PARAM_TYPE
=> 'tags',
94 ApiBase
::PARAM_ISMULTI
=> true,
99 public function needsToken() {
103 protected function getExamplesMessages() {
105 'action=patrol&token=123ABC&rcid=230672766'
106 => 'apihelp-patrol-example-rcid',
107 'action=patrol&token=123ABC&revid=230672766'
108 => 'apihelp-patrol-example-revid',
112 public function getHelpUrls() {
113 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';