Merge "DumpUploads: output local path instead of mwstore path"
[lhc/web/wiklou.git] / includes / api / ApiPatrol.php
1 <?php
2 /**
3 * API for MediaWiki 1.14+
4 *
5 * Created on Sep 2, 2008
6 *
7 * Copyright © 2008 Soxred93 soxred93@gmail.com,
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * Allows user to patrol pages
29 * @ingroup API
30 */
31 class ApiPatrol extends ApiBase {
32
33 /**
34 * Patrols the article or provides the reason the patrol failed.
35 */
36 public function execute() {
37 $params = $this->extractRequestParams();
38 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
39
40 if ( isset( $params['rcid'] ) ) {
41 $rc = RecentChange::newFromId( $params['rcid'] );
42 if ( !$rc ) {
43 $this->dieUsageMsg( [ 'nosuchrcid', $params['rcid'] ] );
44 }
45 } else {
46 $rev = Revision::newFromId( $params['revid'] );
47 if ( !$rev ) {
48 $this->dieUsageMsg( [ 'nosuchrevid', $params['revid'] ] );
49 }
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'
55 );
56 }
57 }
58
59 $user = $this->getUser();
60 $tags = $params['tags'];
61
62 // Check if user can add tags
63 if ( !is_null( $tags ) ) {
64 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $user );
65 if ( !$ableToTag->isOK() ) {
66 $this->dieStatus( $ableToTag );
67 }
68 }
69
70 $retval = $rc->doMarkPatrolled( $user, false, $tags );
71
72 if ( $retval ) {
73 $this->dieUsageMsg( reset( $retval ) );
74 }
75
76 $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
77 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
78 $this->getResult()->addValue( null, $this->getModuleName(), $result );
79 }
80
81 public function mustBePosted() {
82 return true;
83 }
84
85 public function isWriteMode() {
86 return true;
87 }
88
89 public function getAllowedParams() {
90 return [
91 'rcid' => [
92 ApiBase::PARAM_TYPE => 'integer'
93 ],
94 'revid' => [
95 ApiBase::PARAM_TYPE => 'integer'
96 ],
97 'tags' => [
98 ApiBase::PARAM_TYPE => 'tags',
99 ApiBase::PARAM_ISMULTI => true,
100 ],
101 ];
102 }
103
104 public function needsToken() {
105 return 'patrol';
106 }
107
108 protected function getExamplesMessages() {
109 return [
110 'action=patrol&token=123ABC&rcid=230672766'
111 => 'apihelp-patrol-example-rcid',
112 'action=patrol&token=123ABC&revid=230672766'
113 => 'apihelp-patrol-example-revid',
114 ];
115 }
116
117 public function getHelpUrls() {
118 return 'https://www.mediawiki.org/wiki/API:Patrol';
119 }
120 }