(bug 38190) Add "required" flag to some token params
[lhc/web/wiklou.git] / includes / api / ApiFileRevert.php
index 6f2916a..08a9c8e 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( "ApiBase.php" );
-}
-
 /**
  * @ingroup API
  */
@@ -47,14 +42,12 @@ class ApiFileRevert extends ApiBase {
        }
 
        public function execute() {
-               global $wgUser;
-
                $this->params = $this->extractRequestParams();
                // Extract the file and archiveName from the request parameters
                $this->validateParameters();
 
                // Check whether we're allowed to revert this file
-               $this->checkPermissions( $wgUser );
+               $this->checkPermissions( $this->getUser() );
 
                $sourceUrl = $this->file->getArchiveVirtualUrl( $this->archiveName );
                $status = $this->file->upload( $sourceUrl, $this->params['comment'], $this->params['comment'] );
@@ -133,21 +126,38 @@ class ApiFileRevert extends ApiBase {
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_REQUIRED => true,
                        ),
-                       'token' => null,
+                       'token' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       ),
                );
 
        }
 
        public function getParamDescription() {
-               $params = array(
-                       'filename' => 'Target filename',
+               return array(
+                       'filename' => 'Target filename without the File: prefix',
                        'token' => 'Edit token. You can get one of these through prop=info',
                        'comment' => 'Upload comment',
                        'archivename' => 'Archive name of the revision to revert to',
                );
+       }
 
-               return $params;
-
+       public function getResultProperties() {
+               return array(
+                       '' => array(
+                               'result' => array(
+                                       ApiBase::PROP_TYPE => array(
+                                               'Success',
+                                               'Failure'
+                                       )
+                               ),
+                               'errors' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       )
+               );
        }
 
        public function getDescription() {
@@ -176,17 +186,13 @@ class ApiFileRevert extends ApiBase {
                return '';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
-                       'Revert Wiki.png to the version of 20110305152740:',
-                       '    api.php?action=filerevert&filename=Wiki.png&comment=Revert&archivename=20110305152740!Wiki.png&token=+\\',
+                       'api.php?action=filerevert&filename=Wiki.png&comment=Revert&archivename=20110305152740!Wiki.png&token=+\\'
+                               => 'Revert Wiki.png to the version of 20110305152740',
                );
        }
 
-       public function getHelpUrls() {
-               return '';
-       }
-
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }