cb5e081ad6c2428934e25c79a132b647a7d32d12
[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 public function __construct( $main, $action ) {
34 parent::__construct( $main, $action );
35 }
36
37 /**
38 * Patrols the article or provides the reason the patrol failed.
39 */
40 public function execute() {
41 $params = $this->extractRequestParams();
42
43 $rc = RecentChange::newFromID( $params['rcid'] );
44 if ( !$rc instanceof RecentChange ) {
45 $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
46 }
47 $retval = $rc->doMarkPatrolled( $this->getUser() );
48
49 if ( $retval ) {
50 $this->dieUsageMsg( reset( $retval ) );
51 }
52
53 $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
54 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
55 $this->getResult()->addValue( null, $this->getModuleName(), $result );
56 }
57
58 public function mustBePosted() {
59 return true;
60 }
61
62 public function isWriteMode() {
63 return true;
64 }
65
66 public function getAllowedParams() {
67 return array(
68 'token' => array(
69 ApiBase::PARAM_TYPE => 'string',
70 ApiBase::PARAM_REQUIRED => true
71 ),
72 'rcid' => array(
73 ApiBase::PARAM_TYPE => 'integer',
74 ApiBase::PARAM_REQUIRED => true
75 ),
76 );
77 }
78
79 public function getParamDescription() {
80 return array(
81 'token' => 'Patrol token obtained from list=recentchanges',
82 'rcid' => 'Recentchanges ID to patrol',
83 );
84 }
85
86 public function getResultProperties() {
87 return array(
88 '' => array(
89 'rcid' => 'integer',
90 'ns' => 'namespace',
91 'title' => 'string'
92 )
93 );
94 }
95
96 public function getDescription() {
97 return 'Patrol a page or revision';
98 }
99
100 public function getPossibleErrors() {
101 return array_merge( parent::getPossibleErrors(), array(
102 array( 'nosuchrcid', 'rcid' ),
103 ) );
104 }
105
106 public function needsToken() {
107 return true;
108 }
109
110 public function getTokenSalt() {
111 return 'patrol';
112 }
113
114 public function getExamples() {
115 return array(
116 'api.php?action=patrol&token=123abc&rcid=230672766'
117 );
118 }
119
120 public function getHelpUrls() {
121 return 'https://www.mediawiki.org/wiki/API:Patrol';
122 }
123
124 public function getVersion() {
125 return __CLASS__ . ': $Id$';
126 }
127 }