Was occassionally failing due to race condition caused by mt_rand behaviour:
[mediawiki.git] / includes / api / ApiPatrol.php
blob83dcbdb9b876c0d81f7d41d851b64dad65a9e857
1 <?php
3 /*
4 * Created on Sep 2, 2008
6 * API for MediaWiki 1.14+
8 * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
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.
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.
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
26 if (!defined('MEDIAWIKI')) {
27 require_once ('ApiBase.php');
30 /**
31 * Allows user to patrol pages
32 * @ingroup API
34 class ApiPatrol extends ApiBase {
36 public function __construct($main, $action) {
37 parent :: __construct($main, $action);
40 /**
41 * Patrols the article or provides the reason the patrol failed.
43 public function execute() {
44 global $wgUser;
45 $params = $this->extractRequestParams();
47 if(!isset($params['token']))
48 $this->dieUsageMsg(array('missingparam', 'token'));
49 if(!isset($params['rcid']))
50 $this->dieUsageMsg(array('missingparam', 'rcid'));
51 if(!$wgUser->matchEditToken($params['token']))
52 $this->dieUsageMsg(array('sessionfailure'));
54 $rc = RecentChange::newFromID($params['rcid']);
55 if(!$rc instanceof RecentChange)
56 $this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
57 $retval = RecentChange::markPatrolled($params['rcid']);
59 if($retval)
60 $this->dieUsageMsg(reset($retval));
62 $result = array('rcid' => intval($rc->getAttribute('rc_id')));
63 ApiQueryBase::addTitleInfo($result, $rc->getTitle());
64 $this->getResult()->addValue(null, $this->getModuleName(), $result);
67 public function isWriteMode() {
68 return true;
71 public function getAllowedParams() {
72 return array (
73 'token' => null,
74 'rcid' => array(
75 ApiBase :: PARAM_TYPE => 'integer'
80 public function getParamDescription() {
81 return array (
82 'token' => 'Patrol token obtained from list=recentchanges',
83 'rcid' => 'Recentchanges ID to patrol',
87 public function getDescription() {
88 return array (
89 'Patrol a page or revision. '
93 protected function getExamples() {
94 return array(
95 'api.php?action=patrol&token=123abc&rcid=230672766'
99 public function getVersion() {
100 return __CLASS__ . ': $Id$';