(bug 26130) Revert changes to WebStart.php in r72349, which turn out to have been...
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 6 Dec 2010 20:57:42 +0000 (20:57 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 6 Dec 2010 20:57:42 +0000 (20:57 +0000)
includes/DefaultSettings.php
includes/WebStart.php
includes/upload/UploadStash.php

index 4a19266..5c4dfd6 100644 (file)
@@ -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 }
 
 /************************************************************************//**
index f05d563..fede558 100644 (file)
@@ -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' );
 }
index 94c38c7..d874c54 100644 (file)
@@ -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];
        }
 
        /**