http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70049

Revision: 70049
Author:   btongminh
Date:     2010-07-27 21:53:52 +0000 (Tue, 27 Jul 2010)

Log Message:
-----------
Follow-up r70037: Fix ApiUpload by passing a WebRequestUpload to the the 
initializer
Follow-up r64403 and r69911: Fix broken upload from stash in Api. 

Please tests your commits, even if the change seems totally harmless. You can 
use 
<http://mwclient.svn.sourceforge.net/viewvc/mwclient/tests/upload_api_test.py?revision=HEAD&view=markup>
 to automatically test uploading via the Api.

Modified Paths:
--------------
    trunk/phase3/includes/api/ApiUpload.php
    trunk/phase3/includes/upload/UploadFromFile.php

Modified: trunk/phase3/includes/api/ApiUpload.php
===================================================================
--- trunk/phase3/includes/api/ApiUpload.php     2010-07-27 21:43:37 UTC (rev 
70048)
+++ trunk/phase3/includes/api/ApiUpload.php     2010-07-27 21:53:52 UTC (rev 
70049)
@@ -54,72 +54,65 @@
                // One and only one of the following parameters is needed
                $this->requireOnlyOneParameter( $this->mParams,
                        'sessionkey', 'file', 'url' );
+               // And this one is needed
+               if ( !isset( $this->mParams['filename'] ) ) {
+                       $this->dieUsageMsg( array( 'missingparam', 'filename' ) 
);
+               }
 
+
                if ( $this->mParams['sessionkey'] ) {
-                       /**
-                        * Upload stashed in a previous request
-                        */
-                       // Check the session key
-                       if ( !isset( 
$_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] ) ) {
+                       // Upload stashed in a previous request
+                       $sessionData = $request->getSessionData( 
UploadBase::SESSION_KEYNAME );
+                       if ( !UploadFromStash::isValidSessionKey( 
$this->mParams['sessionkey'], $sessionData ) ) {
                                $this->dieUsageMsg( array( 
'invalid-session-key' ) );
                        }
 
                        $this->mUpload = new UploadFromStash();
                        $this->mUpload->initialize( $this->mParams['filename'],
                                $this->mParams['sessionkey'],
-                               
$_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] );
-               } elseif ( isset( $this->mParams['filename'] ) ) {
-                       /**
-                        * Upload from URL, etc.
-                        * Parameter filename is required
-                        */
-                       if ( isset( $this->mParams['file'] ) ) {
-                               $this->mUpload = new UploadFromFile();
-                               $this->mUpload->initialize(
-                                       $this->mParams['filename'],
-                                       $request->getFileTempName( 'file' ),
-                                       $request->getFileSize( 'file' )
-                               );
-                       } elseif ( isset( $this->mParams['url'] ) ) {
-                               // make sure upload by URL is enabled:
-                               if ( !$wgAllowCopyUploads ) {
-                                       $this->dieUsageMsg( array( 
'copyuploaddisabled' ) );
-                               }
+                               $sessionData[$this->mParams['sessionkey']] );
+                       
+                       
+               } elseif ( isset( $this->mParams['file'] ) ) {
+                       $this->mUpload = new UploadFromFile();
+                       $this->mUpload->initialize(
+                               $this->mParams['filename'],
+                               $request->getUpload( 'file' )
+                       );      
+               } elseif ( isset( $this->mParams['url'] ) ) {
+                       // Make sure upload by URL is enabled:
+                       if ( !$wgAllowCopyUploads ) {
+                               $this->dieUsageMsg( array( 'copyuploaddisabled' 
) );
+                       }
 
-                               // make sure the current user can upload
-                               if ( !$wgUser->isAllowed( 'upload_by_url' ) ) {
-                                       $this->dieUsageMsg( array( 
'badaccess-groups' ) );
-                               }
+                       $this->mUpload = new UploadFromUrl;
+                       $async = $this->mParams['asyncdownload'] ? 'async' : 
null;
+                       $this->checkPermissions( $wgUser );
 
-                               $this->mUpload = new UploadFromUrl;
-                               $async = $this->mParams['asyncdownload'] ? 
'async' : null;
+                       $result = $this->mUpload->initialize( 
+                                       $this->mParams['filename'],
+                                       $this->mParams['url'],
+                                       $this->mParams['comment'],
+                                       $this->mParams['watchlist'],
+                                       $this->mParams['ignorewarnings'],
+                                       $async );
+                               
+                       if ( $async ) {
+                               $this->getResult()->addValue( null,
+                                                                               
          $this->getModuleName(),
+                                                                               
          array( 'queued' => $result ) );
+                               return;
+                       }
 
-                               $result = $this->mUpload->initialize( 
$this->mParams['filename'],
-                                               $this->mParams['url'],
-                                               $this->mParams['comment'],
-                                               $this->mParams['watchlist'],
-                                               
$this->mParams['ignorewarnings'],
-                                               $async );
-
-                               $this->checkPermissions( $wgUser );
-                               if ( $async ) {
-                                       $this->getResult()->addValue( null,
-                                                                               
                  $this->getModuleName(),
-                                                                               
                  array( 'queued' => $result ) );
-                                       return;
-                               }
-
-                               $status = $this->mUpload->retrieveFileFromUrl();
-                               if ( !$status->isGood() ) {
-                                       $this->getResult()->addValue( null,
-                                                                               
                  $this->getModuleName(),
-                                                                               
                  array( 'error' => $status ) );
-                                       return;
-                               }
+                       $status = $this->mUpload->retrieveFileFromUrl();
+                       if ( !$status->isGood() ) {
+                               $this->getResult()->addValue( null,
+                                                                               
          $this->getModuleName(),
+                                                                               
          array( 'error' => $status ) );
+                               return;
                        }
-               } else {
-                       $this->dieUsageMsg( array( 'missingparam', 'filename' ) 
);
                }
+       
 
                $this->checkPermissions( $wgUser );
 

Modified: trunk/phase3/includes/upload/UploadFromFile.php
===================================================================
--- trunk/phase3/includes/upload/UploadFromFile.php     2010-07-27 21:43:37 UTC 
(rev 70048)
+++ trunk/phase3/includes/upload/UploadFromFile.php     2010-07-27 21:53:52 UTC 
(rev 70049)
@@ -8,25 +8,24 @@
  * Implements regular file uploads
  */
 class UploadFromFile extends UploadBase {
-       protected $mWebUpload = null;
+       protected $mUpload = null;
 
        function initializeFromRequest( &$request ) {
-               $this->mWebUpload = $request->getUpload( 'wpUploadFile' );      
        
-               
+               $upload = $request->getUpload( 'wpUploadFile' );                
                $desiredDestName = $request->getText( 'wpDestFile' );
                if( !$desiredDestName )
-                       $desiredDestName = $this->mWebUpload->getName();
-               return $this->initializePathInfo(
-                       $desiredDestName,
-                       $this->mWebUpload->getTempName(),
-                       $this->mWebUpload->getSize()
-               );
+                       $desiredDestName = $upload->getName();
+                       
+               return $this->initialize( $desiredDestName, $upload );
        }
+       
        /**
-        * Entry point for upload from file.
+        * Initialize from a filename and a WebRequestUpload
         */
-       function initialize( $name, $tempPath, $fileSize ) {
-                return $this->initializePathInfo( $name, $tempPath, $fileSize 
);
+       function initialize( $name, $webRequestUpload ) {
+               $this->mUpload = $webRequestUpload;
+               return $this->initializePathInfo( $name, 
+                       $this->mUpload->getTempName(), 
$this->mUpload->getSize() );
        }
        static function isValidRequest( $request ) {
                # Allow all requests, even if no file is present, so that an 
error
@@ -38,7 +37,7 @@
                # Check for a post_max_size or upload_max_size overflow, so 
that a 
                # proper error can be shown to the user
                if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
-                       if ( $this->mWebUpload->isIniSizeOverflow() ) {
+                       if ( $this->mUpload->isIniSizeOverflow() ) {
                                global $wgMaxUploadSize;
                                return array( 
                                        'status' => self::FILE_TOO_LARGE,



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to