Merge "Revert "selenium: add new message banner test to user spec""
[lhc/web/wiklou.git] / includes / api / ApiPatrol.php
1 <?php
2 /**
3 * API for MediaWiki 1.14+
4 *
5 * Copyright © 2008 Soxred93 soxred93@gmail.com,
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 */
24
25 /**
26 * Allows user to patrol pages
27 * @ingroup API
28 */
29 class ApiPatrol extends ApiBase {
30
31 /**
32 * Patrols the article or provides the reason the patrol failed.
33 */
34 public function execute() {
35 $params = $this->extractRequestParams();
36 $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
37
38 if ( isset( $params['rcid'] ) ) {
39 $rc = RecentChange::newFromId( $params['rcid'] );
40 if ( !$rc ) {
41 $this->dieWithError( [ 'apierror-nosuchrcid', $params['rcid'] ] );
42 }
43 } else {
44 $rev = Revision::newFromId( $params['revid'] );
45 if ( !$rev ) {
46 $this->dieWithError( [ 'apierror-nosuchrevid', $params['revid'] ] );
47 }
48 $rc = $rev->getRecentChange();
49 if ( !$rc ) {
50 $this->dieWithError( [ 'apierror-notpatrollable', $params['revid'] ] );
51 }
52 }
53
54 $user = $this->getUser();
55 $tags = $params['tags'];
56
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 );
62 }
63 }
64
65 $retval = $rc->doMarkPatrolled( $user, false, $tags );
66
67 if ( $retval ) {
68 $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
69 }
70
71 $result = [ 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) ];
72 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
73 $this->getResult()->addValue( null, $this->getModuleName(), $result );
74 }
75
76 public function mustBePosted() {
77 return true;
78 }
79
80 public function isWriteMode() {
81 return true;
82 }
83
84 public function getAllowedParams() {
85 return [
86 'rcid' => [
87 ApiBase::PARAM_TYPE => 'integer'
88 ],
89 'revid' => [
90 ApiBase::PARAM_TYPE => 'integer'
91 ],
92 'tags' => [
93 ApiBase::PARAM_TYPE => 'tags',
94 ApiBase::PARAM_ISMULTI => true,
95 ],
96 ];
97 }
98
99 public function needsToken() {
100 return 'patrol';
101 }
102
103 protected function getExamplesMessages() {
104 return [
105 'action=patrol&token=123ABC&rcid=230672766'
106 => 'apihelp-patrol-example-rcid',
107 'action=patrol&token=123ABC&revid=230672766'
108 => 'apihelp-patrol-example-revid',
109 ];
110 }
111
112 public function getHelpUrls() {
113 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Patrol';
114 }
115 }