]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/api/ApiPatrol.php
MediaWiki 1.16.0
[autoinstalls/mediawiki.git] / includes / api / ApiPatrol.php
1 <?php
2
3 /*
4  * Created on Sep 2, 2008
5  *
6  * API for MediaWiki 1.14+
7  *
8  * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  * http://www.gnu.org/copyleft/gpl.html
24  */
25
26 if ( !defined( 'MEDIAWIKI' ) ) {
27         require_once ( 'ApiBase.php' );
28 }
29
30 /**
31  * Allows user to patrol pages
32  * @ingroup API
33  */
34 class ApiPatrol extends ApiBase {
35
36         public function __construct( $main, $action ) {
37                 parent :: __construct( $main, $action );
38         }
39
40         /**
41          * Patrols the article or provides the reason the patrol failed.
42          */
43         public function execute() {
44                 $params = $this->extractRequestParams();
45                 
46                 if ( !isset( $params['rcid'] ) )
47                         $this->dieUsageMsg( array( 'missingparam', 'rcid' ) );
48
49                 $rc = RecentChange::newFromID( $params['rcid'] );
50                 if ( !$rc instanceof RecentChange )
51                         $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
52                 $retval = RecentChange::markPatrolled( $params['rcid'] );
53                         
54                 if ( $retval )
55                         $this->dieUsageMsg( reset( $retval ) );
56                 
57                 $result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
58                 ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
59                 $this->getResult()->addValue( null, $this->getModuleName(), $result );
60         }
61
62         public function isWriteMode() {
63                 return true;
64         }
65
66         public function getAllowedParams() {
67                 return array (
68                         'token' => null,
69                         'rcid' => array(
70                                 ApiBase :: PARAM_TYPE => 'integer'
71                         ),
72                 );
73         }
74
75         public function getParamDescription() {
76                 return array (
77                         'token' => 'Patrol token obtained from list=recentchanges',
78                         'rcid' => 'Recentchanges ID to patrol',
79                 );
80         }
81
82         public function getDescription() {
83                 return array (
84                         'Patrol a page or revision. '
85                 );
86         }
87         
88     public function getPossibleErrors() {
89                 return array_merge( parent::getPossibleErrors(), array(
90                         array( 'missingparam', 'rcid' ),
91                         array( 'nosuchrcid', 'rcid' ),
92         ) );
93         }
94         
95         public function getTokenSalt() {
96                 return '';
97         }
98
99         protected function getExamples() {
100                 return array(
101                         'api.php?action=patrol&token=123abc&rcid=230672766'
102                 );
103         }
104
105         public function getVersion() {
106                 return __CLASS__ . ': $Id: ApiPatrol.php 69578 2010-07-20 02:46:20Z tstarling $';
107         }
108 }