From 195217ba89505f4b49b3f5fd6a228bf76a839d70 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 6 Dec 2010 20:57:42 +0000 Subject: [PATCH] (bug 26130) Revert changes to WebStart.php in r72349, which turn out to have been misguided. This should fix double-gzip issues --- includes/DefaultSettings.php | 5 +++ includes/WebStart.php | 7 +--- includes/upload/UploadStash.php | 68 ++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4a19266f48..5c4dfd6605 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -959,6 +959,11 @@ $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/WebStart.php b/includes/WebStart.php index f05d563066..fede558acb 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -126,15 +126,10 @@ wfProfileOut( 'WebStart.php-conf' ); wfProfileIn( 'WebStart.php-ob_start' ); # Initialise output buffering - # Check that there is no previous output or previously set up buffers, because # that would cause us to potentially mix gzip and non-gzip output, creating a # big mess. -# In older versions of PHP ob_get_level() returns 0 if there is no buffering or -# previous output, in newer versions the default output buffer is always set up -# and ob_get_level() returns 1. In this case we check that the buffer is empty. -# FIXME: Check that this is the right way to handle this -if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ( ob_get_level() == 0 || ( ob_get_level() == 1 && ob_get_contents() === '' ) ) ) { +if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) { require_once( "$IP/includes/OutputHandler.php" ); ob_start( 'wfOutputHandler' ); } diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 94c38c7884..d874c54a6a 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -9,7 +9,6 @@ * - 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 { @@ -22,6 +21,12 @@ 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; @@ -41,14 +46,13 @@ class UploadStash { $this->repo = $repo; - if ( ! isset( $_SESSION ) ) { - throw new UploadStashNotAvailableException( 'no session variable' ); + 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[UploadBase::SESSION_KEYNAME] ) ) { - $_SESSION[UploadBase::SESSION_KEYNAME] = array(); - } - + $this->sessionID = ''; + $this->cache = wfGetCache( CACHE_ANYTHING ); } /** @@ -64,31 +68,36 @@ 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] ) ) { - if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME][$key] ) ) { + $cacheKey = wfMemcKey( 'uploadstash', $this->sessionID, $key ); + $data = $this->cache->get( $cacheKey ); + if ( !$data ) { throw new UploadStashFileNotFoundException( "key '$key' not found in stash" ); } - $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'] ); - - $file = new UploadStashFile( $this, $this->repo, $path, $key, $data ); - if ( $file->getSize === 0 ) { - throw new UploadStashZeroLengthFileException( "File is zero length" ); - } - $this->files[$key] = $file; + $this->files[$key] = $this->getFileFromData( $data ); } 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" ); + } + return $file; + } /** * Stash a file in a temp directory and record that we did this in the session, along with other metadata. @@ -163,10 +172,15 @@ 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" ); - $_SESSION[UploadBase::SESSION_KEYNAME][$key] = array_merge( $data, $requiredData ); + $cacheKey = wfMemcKey( 'uploadstash', $this->sessionID, $key ); + $this->cache->set( $cacheKey, array_merge( $data, $requiredData ), $wgUploadStashExpiry ); - return $this->getFile( $key ); + $this->files[$key] = $this->getFileFromData( $data ); + return $this->files[$key]; } /** -- 2.20.1