Index: branches/staged-upload/maintenance/updaters.inc |
— | — | @@ -169,6 +169,7 @@ |
170 | 170 | // A field changed name mid-release cycle, so fix it for anyone using |
171 | 171 | // trunk |
172 | 172 | array( 'rename_eu_wiki_id' ), |
| 173 | + array( 'add_table', 'upload_stash', 'patch-upload_stash.sql' ), |
173 | 174 | ), |
174 | 175 | |
175 | 176 | 'sqlite' => array( |
— | — | @@ -197,6 +198,8 @@ |
198 | 199 | |
199 | 200 | // version-independent searchindex setup, added in 1.16 |
200 | 201 | array( 'sqlite_setup_searchindex' ), |
| 202 | + |
| 203 | + array( 'add_table', 'upload_stash', 'patch-upload_stash.sql' ), |
201 | 204 | ), |
202 | 205 | ); |
203 | 206 | |
Index: branches/staged-upload/maintenance/tables.sql |
— | — | @@ -1350,4 +1350,19 @@ |
1351 | 1351 | ) /*$wgDBTableOptions*/; |
1352 | 1352 | CREATE INDEX /*i*/lc_lang_key ON /*_*/l10n_cache (lc_lang, lc_key); |
1353 | 1353 | |
| 1354 | +CREATE TABLE /*_*/upload_stash ( |
| 1355 | + -- Numeric id |
| 1356 | + us_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 1357 | + -- User this upload belongs to |
| 1358 | + us_user int NOT NULL, |
| 1359 | + -- Timestamp this was uploaded |
| 1360 | + us_timestamp binary(14) NOT NULL default '19700101000000', |
| 1361 | + -- Timestamp of expiry |
| 1362 | + us_expiry binary(14) NOT NULL default '19700101000000', |
| 1363 | + -- Virtual path of the file |
| 1364 | + us_path varbinary(255) NOT NULL, |
| 1365 | + -- Other data stored as serialized PHP blob |
| 1366 | + us_data mediumblob NOT NULL |
| 1367 | +) /*$wgDBTableOptions*/; |
| 1368 | + |
1354 | 1369 | -- vim: sw=2 sts=2 et |
Index: branches/staged-upload/includes/upload/UploadFromStash.php |
— | — | @@ -9,40 +9,25 @@ |
10 | 10 | */ |
11 | 11 | |
12 | 12 | class UploadFromStash extends UploadBase { |
13 | | - public static function isValidSessionKey( $key, $sessionData ) { |
14 | | - return !empty( $key ) && |
15 | | - is_array( $sessionData ) && |
16 | | - isset( $sessionData[$key] ) && |
17 | | - isset( $sessionData[$key]['version'] ) && |
18 | | - $sessionData[$key]['version'] == self::SESSION_VERSION; |
19 | | - } |
20 | | - |
21 | 13 | public static function isValidRequest( $request ) { |
22 | | - $sessionData = $request->getSessionData( 'wsUploadData' ); |
23 | | - return self::isValidSessionKey( |
24 | | - $request->getInt( 'wpSessionKey' ), |
25 | | - $sessionData |
26 | | - ); |
| 14 | + $stash = RepoGroup::singleton()->getLocalRepo()->getStash(); |
| 15 | + return (bool)$stash->getUpload( $request->getInt( 'wpSessionKey' ) ); |
27 | 16 | } |
28 | | - /* |
| 17 | + /** |
29 | 18 | * some $na vars for uploadBase method compatibility. |
30 | 19 | */ |
31 | | - public function initialize( $name, $sessionData, $na=false, $na2=false ) { |
32 | | - /** |
33 | | - * Confirming a temporarily stashed upload. |
34 | | - * We don't want path names to be forged, so we keep |
35 | | - * them in the session on the server and just give |
36 | | - * an opaque key to the user agent. |
37 | | - */ |
| 20 | + public function initialize( $name, $id, $na=false, $na2=false ) { |
| 21 | + $this->mStash = RepoGroup::singleton()->getLocalRepo()->getStash(); |
| 22 | + $this->mTemporaryUpload = $this->mStash->getUpload( $id ); |
| 23 | + $data = $this->mTemporaryUpload->getData(); |
38 | 24 | |
39 | | - parent::initialize( $name, |
40 | | - $this->getRealPath ( $sessionData['mTempPath'] ), |
41 | | - $sessionData['mFileSize'], |
42 | | - false |
43 | | - ); |
| 25 | + parent::initialize( $name, |
| 26 | + $this->mTemporaryUpload->getRealPath(), |
| 27 | + $data['size'], |
| 28 | + /* $removeTempFile */ false |
| 29 | + ); |
44 | 30 | |
45 | | - $this->mVirtualTempPath = $sessionData['mTempPath']; |
46 | | - $this->mFileProps = $sessionData['mFileProps']; |
| 31 | + $this->mFileProps = $data['props']; |
47 | 32 | } |
48 | 33 | |
49 | 34 | public function initializeFromRequest( &$request ) { |
— | — | @@ -52,7 +37,7 @@ |
53 | 38 | $desiredDestName = $request->getText( 'wpDestFile' ); |
54 | 39 | if( !$desiredDestName ) |
55 | 40 | $desiredDestName = $request->getText( 'wpUploadFile' ); |
56 | | - return $this->initialize( $desiredDestName, $sessionData[$this->mSessionKey], false ); |
| 41 | + return $this->initialize( $desiredDestName, $this->mSessionKey, false ); |
57 | 42 | } |
58 | 43 | |
59 | 44 | /** |
— | — | @@ -77,8 +62,7 @@ |
78 | 63 | * @return success |
79 | 64 | */ |
80 | 65 | public function unsaveUploadedFile() { |
81 | | - $repo = RepoGroup::singleton()->getLocalRepo(); |
82 | | - $success = $repo->freeTemp( $this->mVirtualTempPath ); |
| 66 | + $success = $this->mStash->freeUpload( $this->mTemporaryUpload ); |
83 | 67 | return $success; |
84 | 68 | } |
85 | 69 | |
Index: branches/staged-upload/includes/upload/UploadBase.php |
— | — | @@ -452,24 +452,6 @@ |
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
456 | | - * Stash a file in a temporary directory for later processing |
457 | | - * after the user has confirmed it. |
458 | | - * |
459 | | - * If the user doesn't explicitly cancel or accept, these files |
460 | | - * can accumulate in the temp directory. |
461 | | - * |
462 | | - * @param string $saveName - the destination filename |
463 | | - * @param string $tempSrc - the source temporary file to save |
464 | | - * @return string - full path the stashed file, or false on failure |
465 | | - * @access private |
466 | | - */ |
467 | | - protected function saveTempUploadedFile( $saveName, $tempSrc ) { |
468 | | - $repo = RepoGroup::singleton()->getLocalRepo(); |
469 | | - $status = $repo->storeTemp( $saveName, $tempSrc ); |
470 | | - return $status; |
471 | | - } |
472 | | - |
473 | | - /** |
474 | 456 | * Stash a file in a temporary directory for later processing, |
475 | 457 | * and save the necessary descriptive info into the session. |
476 | 458 | * Returns a key value which will be passed through a form |
— | — | @@ -478,33 +460,23 @@ |
479 | 461 | * @return int Session key |
480 | 462 | */ |
481 | 463 | public function stashSession() { |
482 | | - $status = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath ); |
483 | | - if( !$status->isOK() ) { |
484 | | - # Couldn't save the file. |
| 464 | + $stash = RepoGroup::singleton()->getLocalRepo()->getStash(); |
| 465 | + |
| 466 | + global $wgUser, $wgTemporaryUploadExpiry; |
| 467 | + |
| 468 | + $upload = $stash->saveFile( $wgUser, time() + $wgTemporaryUploadExpiry, |
| 469 | + $this->mDestName, $this->mTempPath, array( |
| 470 | + 'size' => $this->mFileSize, |
| 471 | + 'props' => $this->mFileProps, |
| 472 | + ) ); |
| 473 | + |
| 474 | + if ( !$upload ) |
485 | 475 | return false; |
486 | | - } |
487 | | - if(!isset($_SESSION)) |
488 | | - session_start(); // start up the session (might have been previously closed to prevent php session locking) |
489 | | - $key = $this->getSessionKey(); |
490 | | - $_SESSION['wsUploadData'][$key] = array( |
491 | | - 'mTempPath' => $status->value, |
492 | | - 'mFileSize' => $this->mFileSize, |
493 | | - 'mFileProps' => $this->mFileProps, |
494 | | - 'version' => self::SESSION_VERSION, |
495 | | - ); |
496 | | - return $key; |
| 476 | + |
| 477 | + return $upload->getId(); |
497 | 478 | } |
498 | 479 | |
499 | | - /** |
500 | | - * Generate a random session key from stash in cases where we want to start an upload without much information |
501 | | - */ |
502 | | - protected function getSessionKey(){ |
503 | | - $key = mt_rand( 0, 0x7fffffff ); |
504 | | - $_SESSION['wsUploadData'][$key] = array(); |
505 | | - return $key; |
506 | | - } |
507 | 480 | |
508 | | - |
509 | 481 | /** |
510 | 482 | * If we've modified the upload file we need to manually remove it |
511 | 483 | * on exit to clean up. |
Index: branches/staged-upload/includes/filerepo/LocalRepo.php |
— | — | @@ -198,5 +198,15 @@ |
199 | 199 | $wgMemc->delete( $memcKey ); |
200 | 200 | } |
201 | 201 | } |
| 202 | + |
| 203 | + /** |
| 204 | + * Return a place to temporary store files |
| 205 | + * |
| 206 | + * @return UploadStash |
| 207 | + */ |
| 208 | + public function getStash() { |
| 209 | + return new UploadStash( $this ); |
| 210 | + } |
| 211 | + |
202 | 212 | } |
203 | 213 | |
Index: branches/staged-upload/includes/AutoLoader.php |
— | — | @@ -414,7 +414,9 @@ |
415 | 415 | 'LocalRepo' => 'includes/filerepo/LocalRepo.php', |
416 | 416 | 'OldLocalFile' => 'includes/filerepo/OldLocalFile.php', |
417 | 417 | 'RepoGroup' => 'includes/filerepo/RepoGroup.php', |
| 418 | + 'TemporaryUpload' => 'includes/filerepo/TemporaryUpload.php', |
418 | 419 | 'UnregisteredLocalFile' => 'includes/filerepo/UnregisteredLocalFile.php', |
| 420 | + 'UploadStash' => 'includes/filerepo/UploadStash.php', |
419 | 421 | |
420 | 422 | # includes/media |
421 | 423 | 'BitmapHandler' => 'includes/media/Bitmap.php', |