Index: trunk/phase3/includes/upload/UploadFromFile.php |
— | — | @@ -8,25 +8,24 @@ |
9 | 9 | * Implements regular file uploads |
10 | 10 | */ |
11 | 11 | class UploadFromFile extends UploadBase { |
12 | | - protected $mWebUpload = null; |
| 12 | + protected $mUpload = null; |
13 | 13 | |
14 | 14 | function initializeFromRequest( &$request ) { |
15 | | - $this->mWebUpload = $request->getUpload( 'wpUploadFile' ); |
16 | | - |
| 15 | + $upload = $request->getUpload( 'wpUploadFile' ); |
17 | 16 | $desiredDestName = $request->getText( 'wpDestFile' ); |
18 | 17 | if( !$desiredDestName ) |
19 | | - $desiredDestName = $this->mWebUpload->getName(); |
20 | | - return $this->initializePathInfo( |
21 | | - $desiredDestName, |
22 | | - $this->mWebUpload->getTempName(), |
23 | | - $this->mWebUpload->getSize() |
24 | | - ); |
| 18 | + $desiredDestName = $upload->getName(); |
| 19 | + |
| 20 | + return $this->initialize( $desiredDestName, $upload ); |
25 | 21 | } |
| 22 | + |
26 | 23 | /** |
27 | | - * Entry point for upload from file. |
| 24 | + * Initialize from a filename and a WebRequestUpload |
28 | 25 | */ |
29 | | - function initialize( $name, $tempPath, $fileSize ) { |
30 | | - return $this->initializePathInfo( $name, $tempPath, $fileSize ); |
| 26 | + function initialize( $name, $webRequestUpload ) { |
| 27 | + $this->mUpload = $webRequestUpload; |
| 28 | + return $this->initializePathInfo( $name, |
| 29 | + $this->mUpload->getTempName(), $this->mUpload->getSize() ); |
31 | 30 | } |
32 | 31 | static function isValidRequest( $request ) { |
33 | 32 | # Allow all requests, even if no file is present, so that an error |
— | — | @@ -38,7 +37,7 @@ |
39 | 38 | # Check for a post_max_size or upload_max_size overflow, so that a |
40 | 39 | # proper error can be shown to the user |
41 | 40 | if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) { |
42 | | - if ( $this->mWebUpload->isIniSizeOverflow() ) { |
| 41 | + if ( $this->mUpload->isIniSizeOverflow() ) { |
43 | 42 | global $wgMaxUploadSize; |
44 | 43 | return array( |
45 | 44 | 'status' => self::FILE_TOO_LARGE, |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -54,72 +54,65 @@ |
55 | 55 | // One and only one of the following parameters is needed |
56 | 56 | $this->requireOnlyOneParameter( $this->mParams, |
57 | 57 | 'sessionkey', 'file', 'url' ); |
| 58 | + // And this one is needed |
| 59 | + if ( !isset( $this->mParams['filename'] ) ) { |
| 60 | + $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); |
| 61 | + } |
58 | 62 | |
| 63 | + |
59 | 64 | if ( $this->mParams['sessionkey'] ) { |
60 | | - /** |
61 | | - * Upload stashed in a previous request |
62 | | - */ |
63 | | - // Check the session key |
64 | | - if ( !isset( $_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] ) ) { |
| 65 | + // Upload stashed in a previous request |
| 66 | + $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME ); |
| 67 | + if ( !UploadFromStash::isValidSessionKey( $this->mParams['sessionkey'], $sessionData ) ) { |
65 | 68 | $this->dieUsageMsg( array( 'invalid-session-key' ) ); |
66 | 69 | } |
67 | 70 | |
68 | 71 | $this->mUpload = new UploadFromStash(); |
69 | 72 | $this->mUpload->initialize( $this->mParams['filename'], |
70 | 73 | $this->mParams['sessionkey'], |
71 | | - $_SESSION[$this->mUpload->getSessionKey()][$this->mParams['sessionkey']] ); |
72 | | - } elseif ( isset( $this->mParams['filename'] ) ) { |
73 | | - /** |
74 | | - * Upload from URL, etc. |
75 | | - * Parameter filename is required |
76 | | - */ |
77 | | - if ( isset( $this->mParams['file'] ) ) { |
78 | | - $this->mUpload = new UploadFromFile(); |
79 | | - $this->mUpload->initialize( |
80 | | - $this->mParams['filename'], |
81 | | - $request->getFileTempName( 'file' ), |
82 | | - $request->getFileSize( 'file' ) |
83 | | - ); |
84 | | - } elseif ( isset( $this->mParams['url'] ) ) { |
85 | | - // make sure upload by URL is enabled: |
86 | | - if ( !$wgAllowCopyUploads ) { |
87 | | - $this->dieUsageMsg( array( 'copyuploaddisabled' ) ); |
88 | | - } |
| 74 | + $sessionData[$this->mParams['sessionkey']] ); |
| 75 | + |
| 76 | + |
| 77 | + } elseif ( isset( $this->mParams['file'] ) ) { |
| 78 | + $this->mUpload = new UploadFromFile(); |
| 79 | + $this->mUpload->initialize( |
| 80 | + $this->mParams['filename'], |
| 81 | + $request->getUpload( 'file' ) |
| 82 | + ); |
| 83 | + } elseif ( isset( $this->mParams['url'] ) ) { |
| 84 | + // Make sure upload by URL is enabled: |
| 85 | + if ( !$wgAllowCopyUploads ) { |
| 86 | + $this->dieUsageMsg( array( 'copyuploaddisabled' ) ); |
| 87 | + } |
89 | 88 | |
90 | | - // make sure the current user can upload |
91 | | - if ( !$wgUser->isAllowed( 'upload_by_url' ) ) { |
92 | | - $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
93 | | - } |
| 89 | + $this->mUpload = new UploadFromUrl; |
| 90 | + $async = $this->mParams['asyncdownload'] ? 'async' : null; |
| 91 | + $this->checkPermissions( $wgUser ); |
94 | 92 | |
95 | | - $this->mUpload = new UploadFromUrl; |
96 | | - $async = $this->mParams['asyncdownload'] ? 'async' : null; |
| 93 | + $result = $this->mUpload->initialize( |
| 94 | + $this->mParams['filename'], |
| 95 | + $this->mParams['url'], |
| 96 | + $this->mParams['comment'], |
| 97 | + $this->mParams['watchlist'], |
| 98 | + $this->mParams['ignorewarnings'], |
| 99 | + $async ); |
| 100 | + |
| 101 | + if ( $async ) { |
| 102 | + $this->getResult()->addValue( null, |
| 103 | + $this->getModuleName(), |
| 104 | + array( 'queued' => $result ) ); |
| 105 | + return; |
| 106 | + } |
97 | 107 | |
98 | | - $result = $this->mUpload->initialize( $this->mParams['filename'], |
99 | | - $this->mParams['url'], |
100 | | - $this->mParams['comment'], |
101 | | - $this->mParams['watchlist'], |
102 | | - $this->mParams['ignorewarnings'], |
103 | | - $async ); |
104 | | - |
105 | | - $this->checkPermissions( $wgUser ); |
106 | | - if ( $async ) { |
107 | | - $this->getResult()->addValue( null, |
108 | | - $this->getModuleName(), |
109 | | - array( 'queued' => $result ) ); |
110 | | - return; |
111 | | - } |
112 | | - |
113 | | - $status = $this->mUpload->retrieveFileFromUrl(); |
114 | | - if ( !$status->isGood() ) { |
115 | | - $this->getResult()->addValue( null, |
116 | | - $this->getModuleName(), |
117 | | - array( 'error' => $status ) ); |
118 | | - return; |
119 | | - } |
| 108 | + $status = $this->mUpload->retrieveFileFromUrl(); |
| 109 | + if ( !$status->isGood() ) { |
| 110 | + $this->getResult()->addValue( null, |
| 111 | + $this->getModuleName(), |
| 112 | + array( 'error' => $status ) ); |
| 113 | + return; |
120 | 114 | } |
121 | | - } else { |
122 | | - $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); |
123 | 115 | } |
| 116 | + |
124 | 117 | |
125 | 118 | $this->checkPermissions( $wgUser ); |
126 | 119 | |