Index: trunk/phase3/includes/upload/UploadStash.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL. |
11 | 11 | * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access |
12 | 12 | * the session, even the uploading user. See SpecialUploadStash, which implements a web interface to some files stored this way. |
| 13 | + * |
13 | 14 | */ |
14 | 15 | class UploadStash { |
15 | 16 | |
— | — | @@ -21,12 +22,6 @@ |
22 | 23 | |
23 | 24 | // array of initialized objects obtained from session (lazily initialized upon getFile()) |
24 | 25 | private $files = array(); |
25 | | - |
26 | | - // Session ID |
27 | | - private $sessionID; |
28 | | - |
29 | | - // Cache to store stash metadata in |
30 | | - private $cache; |
31 | 26 | |
32 | 27 | // TODO: Once UploadBase starts using this, switch to use these constants rather than UploadBase::SESSION* |
33 | 28 | // const SESSION_VERSION = 2; |
— | — | @@ -46,13 +41,14 @@ |
47 | 42 | |
48 | 43 | $this->repo = $repo; |
49 | 44 | |
50 | | - if ( session_id() === '' ) { |
51 | | - // FIXME: Should we just start a session in this case? |
52 | | - // Anonymous uploading could be allowed |
53 | | - throw new UploadStashNotAvailableException( 'no session ID' ); |
| 45 | + if ( ! isset( $_SESSION ) ) { |
| 46 | + throw new UploadStashNotAvailableException( 'no session variable' ); |
54 | 47 | } |
55 | | - $this->sessionID = ''; |
56 | | - $this->cache = wfGetCache( CACHE_ANYTHING ); |
| 48 | + |
| 49 | + if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME] ) ) { |
| 50 | + $_SESSION[UploadBase::SESSION_KEYNAME] = array(); |
| 51 | + } |
| 52 | + |
57 | 53 | } |
58 | 54 | |
59 | 55 | /** |
— | — | @@ -68,37 +64,32 @@ |
69 | 65 | if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) { |
70 | 66 | throw new UploadStashBadPathException( "key '$key' is not in a proper format" ); |
71 | 67 | } |
72 | | - |
| 68 | + |
73 | 69 | if ( !isset( $this->files[$key] ) ) { |
74 | | - $cacheKey = wfMemcKey( 'uploadstash', $this->sessionID, $key ); |
75 | | - $data = $this->cache->get( $cacheKey ); |
76 | | - if ( !$data ) { |
| 70 | + if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME][$key] ) ) { |
77 | 71 | throw new UploadStashFileNotFoundException( "key '$key' not found in stash" ); |
78 | 72 | } |
79 | 73 | |
80 | | - $this->files[$key] = $this->getFileFromData( $data ); |
| 74 | + $data = $_SESSION[UploadBase::SESSION_KEYNAME][$key]; |
| 75 | + // guards against PHP class changing while session data doesn't |
| 76 | + if ($data['version'] !== UploadBase::SESSION_VERSION ) { |
| 77 | + throw new UploadStashBadVersionException( $data['version'] . " does not match current version " . UploadBase::SESSION_VERSION ); |
| 78 | + } |
| 79 | + |
| 80 | + // separate the stashData into the path, and then the rest of the data |
| 81 | + $path = $data['mTempPath']; |
| 82 | + unset( $data['mTempPath'] ); |
81 | 83 | |
| 84 | + $file = new UploadStashFile( $this, $this->repo, $path, $key, $data ); |
| 85 | + if ( $file->getSize === 0 ) { |
| 86 | + throw new UploadStashZeroLengthFileException( "File is zero length" ); |
| 87 | + } |
| 88 | + $this->files[$key] = $file; |
| 89 | + |
82 | 90 | } |
83 | 91 | return $this->files[$key]; |
84 | 92 | } |
85 | | - |
86 | | - protected function getFileFromData( $data ) { |
87 | | - // guards against PHP class changing while session data doesn't |
88 | | - if ( $data['version'] !== UploadBase::SESSION_VERSION ) { |
89 | | - throw new UploadStashBadVersionException( $data['version'] . " does not match current version " . UploadBase::SESSION_VERSION ); |
90 | | - } |
91 | | - |
92 | | - // separate the stashData into the path, and then the rest of the data |
93 | | - $path = $data['mTempPath']; |
94 | | - unset( $data['mTempPath'] ); |
95 | 93 | |
96 | | - $file = new UploadStashFile( $this, $this->repo, $path, $key, $data ); |
97 | | - if ( $file->getSize() === 0 ) { |
98 | | - throw new UploadStashZeroLengthFileException( "File is zero length" ); |
99 | | - } |
100 | | - return $file; |
101 | | - } |
102 | | - |
103 | 94 | /** |
104 | 95 | * Stash a file in a temp directory and record that we did this in the session, along with other metadata. |
105 | 96 | * We store data in a flat key-val namespace because that's how UploadBase did it. This also means we have to |
— | — | @@ -172,15 +163,10 @@ |
173 | 164 | |
174 | 165 | // now, merge required info and extra data into the session. (The extra data changes from application to application. |
175 | 166 | // UploadWizard wants different things than say FirefoggChunkedUpload.) |
176 | | - $finalData = array_merge( $data, $requiredData ); |
177 | | - |
178 | | - global $wgUploadStashExpiry; |
179 | 167 | wfDebug( __METHOD__ . " storing under $key\n" ); |
180 | | - $cacheKey = wfMemcKey( 'uploadstash', $this->sessionID, $key ); |
181 | | - $this->cache->set( $cacheKey, array_merge( $data, $requiredData ), $wgUploadStashExpiry ); |
| 168 | + $_SESSION[UploadBase::SESSION_KEYNAME][$key] = array_merge( $data, $requiredData ); |
182 | 169 | |
183 | | - $this->files[$key] = $this->getFileFromData( $data ); |
184 | | - return $this->files[$key]; |
| 170 | + return $this->getFile( $key ); |
185 | 171 | } |
186 | 172 | |
187 | 173 | /** |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -959,11 +959,6 @@ |
960 | 960 | */ |
961 | 961 | $wgDjvuOutputExtension = 'jpg'; |
962 | 962 | |
963 | | -/** |
964 | | - * How long (in seconds) stashed uploads are kept in cache. |
965 | | - */ |
966 | | -$wgUploadStashExpiry = 3600; // 1 hour |
967 | | - |
968 | 963 | /** @} */ # end of file uploads } |
969 | 964 | |
970 | 965 | /************************************************************************//** |