Provide some info on which case value was not handled in ApiLogin
[lhc/web/wiklou.git] / includes / api / ApiUndelete.php
index 56ce3c6..412e283 100644 (file)
@@ -28,7 +28,7 @@ if (!defined('MEDIAWIKI')) {
 }
 
 /**
- * @addtogroup API
+ * @ingroup API
  */
 class ApiUndelete extends ApiBase {
 
@@ -40,27 +40,29 @@ class ApiUndelete extends ApiBase {
                global $wgUser;
                $this->getMain()->requestWriteMode();
                $params = $this->extractRequestParams();
-               
+
                $titleObj = NULL;
                if(!isset($params['title']))
-                       $this->dieUsage('The title parameter must be set', 'notitle');
+                       $this->dieUsageMsg(array('missingparam', 'title'));
                if(!isset($params['token']))
-                       $this->dieUsage('The token parameter must be set', 'notoken');
+                       $this->dieUsageMsg(array('missingparam', 'token'));
 
                if(!$wgUser->isAllowed('undelete'))
-                       $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');
+                       $this->dieUsageMsg(array('permdenied-undelete'));
                if($wgUser->isBlocked())
-                       $this->dieUsage('You have been blocked from editing', 'blocked');
+                       $this->dieUsageMsg(array('blockedtext'));
                if(wfReadOnly())
-                       $this->dieUsage('The wiki is in read-only mode', 'readonly');
+                       $this->dieUsageMsg(array('readonlytext'));
                if(!$wgUser->matchEditToken($params['token']))
-                       $this->dieUsage('Invalid token', 'badtoken');
+                       $this->dieUsageMsg(array('sessionfailure'));
 
                $titleObj = Title::newFromText($params['title']);
                if(!$titleObj)
-                       $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');
+                       $this->dieUsageMsg(array('invalidtitle', $params['title']));
 
                // Convert timestamps
+               if(!isset($params['timestamps']))
+                       $params['timestamps'] = array();
                if(!is_array($params['timestamps']))
                        $params['timestamps'] = array($params['timestamps']);
                foreach($params['timestamps'] as $i => $ts)
@@ -71,25 +73,22 @@ class ApiUndelete extends ApiBase {
                $dbw->begin();
                $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
                if(!is_array($retval))
-                       switch($retval)
-                       {
-                               case PageArchive::UNDELETE_NOTHINGRESTORED:
-                                       $this->dieUsage('No revisions could be restored', 'norevs');
-                               case PageArchive::UNDELETE_NOTAVAIL:
-                                       $this->dieUsage('Not all requested revisions could be found', 'revsnotfound');
-                               case PageArchive::UNDELETE_UNKNOWNERR:
-                                       $this->dieUsage('Undeletion failed with unknown error', 'unknownerror');
-                       }
-               $dbw->commit();
-               
+                       $this->dieUsageMsg(array('cannotundelete'));
+
+               if($retval[1])
+                       wfRunHooks( 'FileUndeleteComplete', 
+                               array($titleObj, array(), $wgUser, $params['reason']) );
+
                $info['title'] = $titleObj->getPrefixedText();
                $info['revisions'] = $retval[0];
                $info['fileversions'] = $retval[1];
                $info['reason'] = $retval[2];
                $this->getResult()->addValue(null, $this->getModuleName(), $info);
        }
-       
-       protected function getAllowedParams() {
+
+       public function mustBePosted() { return true; }
+
+       public function getAllowedParams() {
                return array (
                        'title' => null,
                        'token' => null,
@@ -100,7 +99,7 @@ class ApiUndelete extends ApiBase {
                );
        }
 
-       protected function getParamDescription() {
+       public function getParamDescription() {
                return array (
                        'title' => 'Title of the page you want to restore.',
                        'token' => 'An undelete token previously retrieved through list=deletedrevs',
@@ -109,7 +108,7 @@ class ApiUndelete extends ApiBase {
                );
        }
 
-       protected function getDescription() {
+       public function getDescription() {
                return array(
                        'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
                        'retrieved through list=deletedrevs'