stylize.php on API code
[lhc/web/wiklou.git] / includes / api / ApiUndelete.php
index b9f01c0..8a8513d 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,62 +32,63 @@ 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'));
-
-               if(!$wgUser->isAllowed('undelete'))
-                       $this->dieUsageMsg(array('permdenied-undelete'));
-               if($wgUser->isBlocked())
-                       $this->dieUsageMsg(array('blockedtext'));
-               if(wfReadOnly())
-                       $this->dieUsageMsg(array('readonlytext'));
-               if(!$wgUser->matchEditToken($params['token']))
-                       $this->dieUsageMsg(array('sessionfailure'));
-
-               $titleObj = Title::newFromText($params['title']);
-               if(!$titleObj)
-                       $this->dieUsageMsg(array('invalidtitle', $params['title']));
-                       
-               if ($titleObj->getNamespace() == NS_IMAGE)
-                       $this->dieUsage('File undeletion is not supported', 'fileundeletionunsupported');
+               $titleObj = null;
+               if ( !isset( $params['title'] ) )
+                       $this->dieUsageMsg( array( 'missingparam', 'title' ) );
+               if ( !isset( $params['token'] ) )
+                       $this->dieUsageMsg( array( 'missingparam', 'token' ) );
 
-               // Convert timestamps
-               if(!is_array($params['timestamps']))
-                       $params['timestamps'] = array($params['timestamps']);
-               foreach($params['timestamps'] as $i => $ts)
-                       $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
+               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' ) );
+
+               $titleObj = Title::newFromText( $params['title'] );
+               if ( !$titleObj )
+                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
 
-               $pa = new PageArchive($titleObj);
-               $dbw = wfGetDb(DB_MASTER);
+               // 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 )
+                       $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
+
+               $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' ) );
 
-               //wfRunHooks( 'FileUndeleteComplete', array(
-               //      $titleObj, $this->mFileVersions, $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 isWriteMode() {
+               return true;
+       }
+
        public function getAllowedParams() {
                return array (
                        'title' => null,