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' );
}
* - 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 {
// 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;
$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 );
}
/**
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.
// 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];
}
/**