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