From a11ac13c642e76dc3ecbfd2bf6445fa8587aa775 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 6 Dec 2010 21:01:26 +0000 Subject: [PATCH] Revert unintended changes in r77908 --- includes/DefaultSettings.php | 5 --- includes/upload/UploadStash.php | 68 +++++++++++++-------------------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 5c4dfd6605..4a19266f48 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -959,11 +959,6 @@ $wgDjvuPostProcessor = 'pnmtojpeg'; */ $wgDjvuOutputExtension = 'jpg'; -/** - * How long (in seconds) stashed uploads are kept in cache. - */ -$wgUploadStashExpiry = 3600; // 1 hour - /** @} */ # end of file uploads } /************************************************************************//** diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index d874c54a6a..94c38c7884 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -9,6 +9,7 @@ * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL. * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access * the session, even the uploading user. See SpecialUploadStash, which implements a web interface to some files stored this way. + * */ class UploadStash { @@ -21,12 +22,6 @@ class UploadStash { // array of initialized objects obtained from session (lazily initialized upon getFile()) private $files = array(); - - // Session ID - private $sessionID; - - // Cache to store stash metadata in - private $cache; // TODO: Once UploadBase starts using this, switch to use these constants rather than UploadBase::SESSION* // const SESSION_VERSION = 2; @@ -46,13 +41,14 @@ class UploadStash { $this->repo = $repo; - if ( session_id() === '' ) { - // FIXME: Should we just start a session in this case? - // Anonymous uploading could be allowed - throw new UploadStashNotAvailableException( 'no session ID' ); + if ( ! isset( $_SESSION ) ) { + throw new UploadStashNotAvailableException( 'no session variable' ); } - $this->sessionID = ''; - $this->cache = wfGetCache( CACHE_ANYTHING ); + + if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME] ) ) { + $_SESSION[UploadBase::SESSION_KEYNAME] = array(); + } + } /** @@ -68,35 +64,30 @@ class UploadStash { if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) { throw new UploadStashBadPathException( "key '$key' is not in a proper format" ); } - + if ( !isset( $this->files[$key] ) ) { - $cacheKey = wfMemcKey( 'uploadstash', $this->sessionID, $key ); - $data = $this->cache->get( $cacheKey ); - if ( !$data ) { + if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME][$key] ) ) { throw new UploadStashFileNotFoundException( "key '$key' not found in stash" ); } - $this->files[$key] = $this->getFileFromData( $data ); + $data = $_SESSION[UploadBase::SESSION_KEYNAME][$key]; + // guards against PHP class changing while session data doesn't + if ($data['version'] !== UploadBase::SESSION_VERSION ) { + throw new UploadStashBadVersionException( $data['version'] . " does not match current version " . UploadBase::SESSION_VERSION ); + } + + // separate the stashData into the path, and then the rest of the data + $path = $data['mTempPath']; + unset( $data['mTempPath'] ); - } - return $this->files[$key]; - } - - protected function getFileFromData( $data ) { - // guards against PHP class changing while session data doesn't - if ( $data['version'] !== UploadBase::SESSION_VERSION ) { - throw new UploadStashBadVersionException( $data['version'] . " does not match current version " . UploadBase::SESSION_VERSION ); - } - - // separate the stashData into the path, and then the rest of the data - $path = $data['mTempPath']; - unset( $data['mTempPath'] ); + $file = new UploadStashFile( $this, $this->repo, $path, $key, $data ); + if ( $file->getSize === 0 ) { + throw new UploadStashZeroLengthFileException( "File is zero length" ); + } + $this->files[$key] = $file; - $file = new UploadStashFile( $this, $this->repo, $path, $key, $data ); - if ( $file->getSize() === 0 ) { - throw new UploadStashZeroLengthFileException( "File is zero length" ); } - return $file; + return $this->files[$key]; } /** @@ -172,15 +163,10 @@ class UploadStash { // now, merge required info and extra data into the session. (The extra data changes from application to application. // UploadWizard wants different things than say FirefoggChunkedUpload.) - $finalData = array_merge( $data, $requiredData ); - - global $wgUploadStashExpiry; wfDebug( __METHOD__ . " storing under $key\n" ); - $cacheKey = wfMemcKey( 'uploadstash', $this->sessionID, $key ); - $this->cache->set( $cacheKey, array_merge( $data, $requiredData ), $wgUploadStashExpiry ); + $_SESSION[UploadBase::SESSION_KEYNAME][$key] = array_merge( $data, $requiredData ); - $this->files[$key] = $this->getFileFromData( $data ); - return $this->files[$key]; + return $this->getFile( $key ); } /** -- 2.20.1