Removed 'Remember my login' preference
[lhc/web/wiklou.git] / includes / api / ApiPatrol.php
index cb5e081..00297ec 100644 (file)
  */
 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',
                );
        }
 
@@ -94,13 +109,22 @@ class ApiPatrol extends ApiBase {
        }
 
        public function getDescription() {
-               return 'Patrol a page or revision';
+               return 'Patrol a page or revision.';
        }
 
        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"
+                               )
+                       )
+               );
        }
 
        public function needsToken() {
@@ -113,15 +137,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$';
-       }
 }