summaryrefslogtreecommitdiff
path: root/includes/api/ApiPatrol.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiPatrol.php')
-rw-r--r--includes/api/ApiPatrol.php54
1 files changed, 37 insertions, 17 deletions
diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php
index cb5e081a..bd2fde2b 100644
--- a/includes/api/ApiPatrol.php
+++ b/includes/api/ApiPatrol.php
@@ -30,20 +30,32 @@
*/
class ApiPatrol extends ApiBase {
- public function __construct( $main, $action ) {
- parent::__construct( $main, $action );
- }
-
/**
* Patrols the article or provides the reason the patrol failed.
*/
public function execute() {
$params = $this->extractRequestParams();
-
- $rc = RecentChange::newFromID( $params['rcid'] );
- if ( !$rc instanceof RecentChange ) {
- $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
+ $this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
+
+ if ( isset( $params['rcid'] ) ) {
+ $rc = RecentChange::newFromID( $params['rcid'] );
+ if ( !$rc ) {
+ $this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
+ }
+ } else {
+ $rev = Revision::newFromId( $params['revid'] );
+ if ( !$rev ) {
+ $this->dieUsageMsg( array( 'nosuchrevid', $params['revid'] ) );
+ }
+ $rc = $rev->getRecentChange();
+ if ( !$rc ) {
+ $this->dieUsage(
+ 'The revision ' . $params['revid'] . " can't be patrolled as it's too old",
+ 'notpatrollable'
+ );
+ }
}
+
$retval = $rc->doMarkPatrolled( $this->getUser() );
if ( $retval ) {
@@ -70,8 +82,10 @@ class ApiPatrol extends ApiBase {
ApiBase::PARAM_REQUIRED => true
),
'rcid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ApiBase::PARAM_REQUIRED => true
+ ApiBase::PARAM_TYPE => 'integer'
+ ),
+ 'revid' => array(
+ ApiBase::PARAM_TYPE => 'integer'
),
);
}
@@ -80,6 +94,7 @@ class ApiPatrol extends ApiBase {
return array(
'token' => 'Patrol token obtained from list=recentchanges',
'rcid' => 'Recentchanges ID to patrol',
+ 'revid' => 'Revision ID to patrol',
);
}
@@ -98,8 +113,16 @@ class ApiPatrol extends ApiBase {
}
public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'nosuchrcid', 'rcid' ),
+ return array_merge(
+ parent::getPossibleErrors(),
+ parent::getRequireOnlyOneParameterErrorMessages( array( 'rcid', 'revid' ) ),
+ array(
+ array( 'nosuchrcid', 'rcid' ),
+ array( 'nosuchrevid', 'revid' ),
+ array(
+ 'code' => 'notpatrollable',
+ 'info' => "The revision can't be patrolled as it's too old"
+ )
) );
}
@@ -113,15 +136,12 @@ class ApiPatrol extends ApiBase {
public function getExamples() {
return array(
- 'api.php?action=patrol&token=123abc&rcid=230672766'
+ 'api.php?action=patrol&token=123abc&rcid=230672766',
+ 'api.php?action=patrol&token=123abc&revid=230672766'
);
}
public function getHelpUrls() {
return 'https://www.mediawiki.org/wiki/API:Patrol';
}
-
- public function getVersion() {
- return __CLASS__ . ': $Id$';
- }
}