]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiUndelete.php
MediaWiki 1.16.1
[autoinstallsdev/mediawiki.git] / includes / api / ApiUndelete.php
index 7ae9a3c08536b541871812cb048419b8a3bf8fed..ae705b69ef860498ee15c25ee10efe9e2cf237a4 100644 (file)
@@ -22,9 +22,9 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ("ApiBase.php");
+       require_once ( "ApiBase.php" );
 }
 
 /**
@@ -32,59 +32,61 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiUndelete extends ApiBase {
 
-       public function __construct($main, $action) {
-               parent :: __construct($main, $action);
+       public function __construct( $main, $action ) {
+               parent :: __construct( $main, $action );
        }
 
        public function execute() {
                global $wgUser;
-               $this->getMain()->requestWriteMode();
                $params = $this->extractRequestParams();
 
-               $titleObj = NULL;
-               if(!isset($params['title']))
-                       $this->dieUsageMsg(array('missingparam', 'title'));
-               if(!isset($params['token']))
-                       $this->dieUsageMsg(array('missingparam', 'token'));
+               $titleObj = null;
+               if ( !isset( $params['title'] ) )
+                       $this->dieUsageMsg( array( 'missingparam', 'title' ) );
 
-               if(!$wgUser->isAllowed('undelete'))
-                       $this->dieUsageMsg(array('permdenied-undelete'));
-               if($wgUser->isBlocked())
-                       $this->dieUsageMsg(array('blockedtext'));
-               if(!$wgUser->matchEditToken($params['token']))
-                       $this->dieUsageMsg(array('sessionfailure'));
+               if ( !$wgUser->isAllowed( 'undelete' ) )
+                       $this->dieUsageMsg( array( 'permdenied-undelete' ) );
 
-               $titleObj = Title::newFromText($params['title']);
-               if(!$titleObj)
-                       $this->dieUsageMsg(array('invalidtitle', $params['title']));
+               if ( $wgUser->isBlocked() )
+                       $this->dieUsageMsg( array( 'blockedtext' ) );
+
+               $titleObj = Title::newFromText( $params['title'] );
+               if ( !$titleObj )
+                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
 
                // Convert timestamps
-               if(!isset($params['timestamps']))
+               if ( !isset( $params['timestamps'] ) )
                        $params['timestamps'] = array();
-               if(!is_array($params['timestamps']))
-                       $params['timestamps'] = array($params['timestamps']);
-               foreach($params['timestamps'] as $i => $ts)
-                       $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
+               if ( !is_array( $params['timestamps'] ) )
+                       $params['timestamps'] = array( $params['timestamps'] );
+               foreach ( $params['timestamps'] as $i => $ts )
+                       $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
 
-               $pa = new PageArchive($titleObj);
-               $dbw = wfGetDB(DB_MASTER);
+               $pa = new PageArchive( $titleObj );
+               $dbw = wfGetDB( DB_MASTER );
                $dbw->begin();
-               $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
-               if(!is_array($retval))
-                       $this->dieUsageMsg(array('cannotundelete'));
+               $retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] );
+               if ( !is_array( $retval ) )
+                       $this->dieUsageMsg( array( 'cannotundelete' ) );
 
-               if($retval[1])
-                       wfRunHooks( 'FileUndeleteComplete', 
-                               array($titleObj, array(), $wgUser, $params['reason']) );
+               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);
+               $info['revisions'] = intval( $retval[0] );
+               $info['fileversions'] = intval( $retval[1] );
+               $info['reason'] = intval( $retval[2] );
+               $this->getResult()->addValue( null, $this->getModuleName(), $info );
+       }
+
+       public function mustBePosted() {
+               return true;
        }
 
-       public function mustBePosted() { return true; }
+       public function isWriteMode() {
+               return true;
+       }
 
        public function getAllowedParams() {
                return array (
@@ -112,6 +114,24 @@ class ApiUndelete extends ApiBase {
                        'retrieved through list=deletedrevs'
                );
        }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'missingparam', 'title' ),
+                       array( 'permdenied-undelete' ),
+                       array( 'blockedtext' ),
+                       array( 'invalidtitle', 'title' ),
+                       array( 'cannotundelete' ),
+               ) );
+       }
+       
+       public function needsToken() {
+               return true;
+       }
+
+       public function getTokenSalt() {
+               return '';
+       }
 
        protected function getExamples() {
                return array (
@@ -121,6 +141,6 @@ class ApiUndelete extends ApiBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiUndelete.php 43270 2008-11-06 22:30:55Z siebrand $';
+               return __CLASS__ . ': $Id: ApiUndelete.php 74217 2010-10-03 15:53:07Z reedy $';
        }
 }