Merge "Typo fix"
[mediawiki.git] / includes / api / ApiPatrol.php
blobbd2fde2b392d799e61553db3d9d41a5c93ce4aef
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->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
45 } else {
46 $rev = Revision::newFromId( $params['revid'] );
47 if ( !$rev ) {
48 $this->dieUsageMsg( array( 'nosuchrevid', $params['revid'] ) );
50 $rc = $rev->getRecentChange();
51 if ( !$rc ) {
52 $this->dieUsage(
53 'The revision ' . $params['revid'] . " can't be patrolled as it's too old",
54 'notpatrollable'
59 $retval = $rc->doMarkPatrolled( $this->getUser() );
61 if ( $retval ) {
62 $this->dieUsageMsg( reset( $retval ) );
65 $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
66 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
67 $this->getResult()->addValue( null, $this->getModuleName(), $result );
70 public function mustBePosted() {
71 return true;
74 public function isWriteMode() {
75 return true;
78 public function getAllowedParams() {
79 return array(
80 'token' => array(
81 ApiBase::PARAM_TYPE => 'string',
82 ApiBase::PARAM_REQUIRED => true
84 'rcid' => array(
85 ApiBase::PARAM_TYPE => 'integer'
87 'revid' => array(
88 ApiBase::PARAM_TYPE => 'integer'
93 public function getParamDescription() {
94 return array(
95 'token' => 'Patrol token obtained from list=recentchanges',
96 'rcid' => 'Recentchanges ID to patrol',
97 'revid' => 'Revision ID to patrol',
101 public function getResultProperties() {
102 return array(
103 '' => array(
104 'rcid' => 'integer',
105 'ns' => 'namespace',
106 'title' => 'string'
111 public function getDescription() {
112 return 'Patrol a page or revision';
115 public function getPossibleErrors() {
116 return array_merge(
117 parent::getPossibleErrors(),
118 parent::getRequireOnlyOneParameterErrorMessages( array( 'rcid', 'revid' ) ),
119 array(
120 array( 'nosuchrcid', 'rcid' ),
121 array( 'nosuchrevid', 'revid' ),
122 array(
123 'code' => 'notpatrollable',
124 'info' => "The revision can't be patrolled as it's too old"
126 ) );
129 public function needsToken() {
130 return true;
133 public function getTokenSalt() {
134 return 'patrol';
137 public function getExamples() {
138 return array(
139 'api.php?action=patrol&token=123abc&rcid=230672766',
140 'api.php?action=patrol&token=123abc&revid=230672766'
144 public function getHelpUrls() {
145 return 'https://www.mediawiki.org/wiki/API:Patrol';