Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -745,11 +745,11 @@ |
746 | 746 | * @param $key String: (optional) the file key used to find the file info again. If not supplied, a key will be autogenerated. |
747 | 747 | * @return UploadStashFile stashed file |
748 | 748 | */ |
749 | | - public function stashFile( $key = null ) { |
| 749 | + public function stashFile() { |
750 | 750 | // was stashSessionFile |
751 | 751 | $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash(); |
752 | 752 | |
753 | | - $file = $stash->stashFile( $this->mTempPath, $this->getSourceType(), $key ); |
| 753 | + $file = $stash->stashFile( $this->mTempPath, $this->getSourceType() ); |
754 | 754 | $this->mLocalFile = $file; |
755 | 755 | return $file; |
756 | 756 | } |
— | — | @@ -760,8 +760,8 @@ |
761 | 761 | * @param $key String: (optional) the file key used to find the file info again. If not supplied, a key will be autogenerated. |
762 | 762 | * @return String: file key |
763 | 763 | */ |
764 | | - public function stashFileGetKey( $key = null ) { |
765 | | - return $this->stashFile( $key )->getFileKey(); |
| 764 | + public function stashFileGetKey() { |
| 765 | + return $this->stashFile()->getFileKey(); |
766 | 766 | } |
767 | 767 | |
768 | 768 | /** |
— | — | @@ -770,8 +770,8 @@ |
771 | 771 | * @param $key String: (optional) the file key used to find the file info again. If not supplied, a key will be autogenerated. |
772 | 772 | * @return String: file key |
773 | 773 | */ |
774 | | - public function stashSession( $key = null ) { |
775 | | - return $this->stashFileGetKey( $key ); |
| 774 | + public function stashSession() { |
| 775 | + return $this->stashFileGetKey(); |
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
Index: trunk/phase3/includes/upload/UploadStash.php |
— | — | @@ -161,7 +161,7 @@ |
162 | 162 | * @throws UploadStashNotLoggedInException |
163 | 163 | * @return UploadStashFile: file, or null on failure |
164 | 164 | */ |
165 | | - public function stashFile( $path, $sourceType = null, $key = null ) { |
| 165 | + public function stashFile( $path, $sourceType = null ) { |
166 | 166 | if ( ! file_exists( $path ) ) { |
167 | 167 | wfDebug( __METHOD__ . " tried to stash file at '$path', but it doesn't exist\n" ); |
168 | 168 | throw new UploadStashBadPathException( "path doesn't exist" ); |
— | — | @@ -181,17 +181,16 @@ |
182 | 182 | } |
183 | 183 | |
184 | 184 | // If no key was supplied, make one. a mysql insertid would be totally reasonable here, except |
185 | | - // that some users of this function might expect to supply the key instead of using the generated one. |
186 | | - if ( is_null( $key ) ) { |
187 | | - // some things that when combined will make a suitably unique key. |
188 | | - // see: http://www.jwz.org/doc/mid.html |
189 | | - list ($usec, $sec) = explode( ' ', microtime() ); |
190 | | - $usec = substr($usec, 2); |
191 | | - $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' . |
192 | | - wfBaseConvert( mt_rand(), 10, 36 ) . '.'. |
193 | | - $this->userId . '.' . |
194 | | - $extension; |
195 | | - } |
| 185 | + // that for historical reasons, the key is this random thing instead. At least it's not guessable. |
| 186 | + // |
| 187 | + // some things that when combined will make a suitably unique key. |
| 188 | + // see: http://www.jwz.org/doc/mid.html |
| 189 | + list ($usec, $sec) = explode( ' ', microtime() ); |
| 190 | + $usec = substr($usec, 2); |
| 191 | + $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' . |
| 192 | + wfBaseConvert( mt_rand(), 10, 36 ) . '.'. |
| 193 | + $this->userId . '.' . |
| 194 | + $extension; |
196 | 195 | |
197 | 196 | $this->fileProps[$key] = $fileProps; |
198 | 197 | |
— | — | @@ -232,31 +231,6 @@ |
233 | 232 | wfDebug( __METHOD__ . " inserting $stashPath under $key\n" ); |
234 | 233 | $dbw = $this->repo->getMasterDb(); |
235 | 234 | |
236 | | - // select happens on the master so this can all be in a transaction, which |
237 | | - // avoids a race condition that's likely with multiple people uploading from the same |
238 | | - // set of files |
239 | | - $dbw->begin(); |
240 | | - // first, check to see if it's already there. |
241 | | - $row = $dbw->selectRow( |
242 | | - 'uploadstash', |
243 | | - 'us_user, us_timestamp', |
244 | | - array( 'us_key' => $key ), |
245 | | - __METHOD__ |
246 | | - ); |
247 | | - |
248 | | - // The current user can't have this key if: |
249 | | - // - the key is owned by someone else and |
250 | | - // - the age of the key is less than $wgUploadStashMaxAge |
251 | | - if ( is_object( $row ) ) { |
252 | | - global $wgUploadStashMaxAge; |
253 | | - if ( $row->us_user != $this->userId && |
254 | | - $row->wfTimestamp( TS_UNIX, $row->us_timestamp ) > time() - $wgUploadStashMaxAge |
255 | | - ) { |
256 | | - $dbw->rollback(); |
257 | | - throw new UploadStashWrongOwnerException( "Attempting to upload a duplicate of a file that someone else has stashed" ); |
258 | | - } |
259 | | - } |
260 | | - |
261 | 235 | $this->fileMetadata[$key] = array( |
262 | 236 | 'us_user' => $this->userId, |
263 | 237 | 'us_key' => $key, |
— | — | @@ -275,13 +249,11 @@ |
276 | 250 | ); |
277 | 251 | |
278 | 252 | // if a row exists but previous checks on it passed, let the current user take over this key. |
279 | | - $dbw->replace( |
| 253 | + $dbw->insert( |
280 | 254 | 'uploadstash', |
281 | | - 'us_key', |
282 | 255 | $this->fileMetadata[$key], |
283 | 256 | __METHOD__ |
284 | 257 | ); |
285 | | - $dbw->commit(); |
286 | 258 | |
287 | 259 | // store the insertid in the class variable so immediate retrieval (possibly laggy) isn't necesary. |
288 | 260 | $this->fileMetadata[$key]['us_id'] = $dbw->insertId(); |
Index: trunk/phase3/includes/upload/UploadFromStash.php |
— | — | @@ -102,18 +102,18 @@ |
103 | 103 | /** |
104 | 104 | * There is no need to stash the image twice |
105 | 105 | */ |
106 | | - public function stashFile( $key = null ) { |
| 106 | + public function stashFile() { |
107 | 107 | if ( $this->mLocalFile ) { |
108 | 108 | return $this->mLocalFile; |
109 | 109 | } |
110 | | - return parent::stashFile( $key ); |
| 110 | + return parent::stashFile(); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Alias for stashFile |
115 | 115 | */ |
116 | | - public function stashSession( $key = null ) { |
117 | | - return $this->stashFile( $key ); |
| 116 | + public function stashSession() { |
| 117 | + return $this->stashFile(); |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
Index: trunk/phase3/includes/job/UploadFromUrlJob.php |
— | — | @@ -61,24 +61,24 @@ |
62 | 62 | if ( !$this->params['ignoreWarnings'] ) { |
63 | 63 | $warnings = $this->upload->checkWarnings(); |
64 | 64 | if ( $warnings ) { |
65 | | - wfSetupSession( $this->params['sessionId'] ); |
66 | 65 | |
| 66 | + # Stash the upload |
| 67 | + $key = $this->upload->stashFile(); |
| 68 | + |
67 | 69 | if ( $this->params['leaveMessage'] ) { |
68 | 70 | $this->user->leaveUserMessage( |
69 | 71 | wfMsg( 'upload-warning-subj' ), |
70 | 72 | wfMsg( 'upload-warning-msg', |
71 | | - $this->params['sessionKey'], |
| 73 | + $key, |
72 | 74 | $this->params['url'] ) |
73 | 75 | ); |
74 | 76 | } else { |
| 77 | + wfSetupSession( $this->params['sessionId'] ); |
75 | 78 | $this->storeResultInSession( 'Warning', |
76 | 79 | 'warnings', $warnings ); |
| 80 | + session_write_close(); |
77 | 81 | } |
78 | 82 | |
79 | | - # Stash the upload in the session |
80 | | - $this->upload->stashSession( $this->params['sessionKey'] ); |
81 | | - session_write_close(); |
82 | | - |
83 | 83 | return true; |
84 | 84 | } |
85 | 85 | } |