r77909 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77908‎ | r77909 | r77910 >
Date:21:01, 6 December 2010
Author:catrope
Status:ok
Tags:
Comment:
Revert unintended changes in r77908
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadStash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadStash.php
@@ -9,6 +9,7 @@
1010 * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL.
1111 * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access
1212 * the session, even the uploading user. See SpecialUploadStash, which implements a web interface to some files stored this way.
 13+ *
1314 */
1415 class UploadStash {
1516
@@ -21,12 +22,6 @@
2223
2324 // array of initialized objects obtained from session (lazily initialized upon getFile())
2425 private $files = array();
25 -
26 - // Session ID
27 - private $sessionID;
28 -
29 - // Cache to store stash metadata in
30 - private $cache;
3126
3227 // TODO: Once UploadBase starts using this, switch to use these constants rather than UploadBase::SESSION*
3328 // const SESSION_VERSION = 2;
@@ -46,13 +41,14 @@
4742
4843 $this->repo = $repo;
4944
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' );
5447 }
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+
5753 }
5854
5955 /**
@@ -68,37 +64,32 @@
6965 if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
7066 throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
7167 }
72 -
 68+
7369 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] ) ) {
7771 throw new UploadStashFileNotFoundException( "key '$key' not found in stash" );
7872 }
7973
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'] );
8183
 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+
8290 }
8391 return $this->files[$key];
8492 }
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'] );
9593
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 -
10394 /**
10495 * Stash a file in a temp directory and record that we did this in the session, along with other metadata.
10596 * 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 @@
173164
174165 // now, merge required info and extra data into the session. (The extra data changes from application to application.
175166 // UploadWizard wants different things than say FirefoggChunkedUpload.)
176 - $finalData = array_merge( $data, $requiredData );
177 -
178 - global $wgUploadStashExpiry;
179167 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 );
182169
183 - $this->files[$key] = $this->getFileFromData( $data );
184 - return $this->files[$key];
 170+ return $this->getFile( $key );
185171 }
186172
187173 /**
Index: trunk/phase3/includes/DefaultSettings.php
@@ -959,11 +959,6 @@
960960 */
961961 $wgDjvuOutputExtension = 'jpg';
962962
963 -/**
964 - * How long (in seconds) stashed uploads are kept in cache.
965 - */
966 -$wgUploadStashExpiry = 3600; // 1 hour
967 -
968963 /** @} */ # end of file uploads }
969964
970965 /************************************************************************//**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77908(bug 26130) Revert changes to WebStart.php in r72349, which turn out to have ...catrope20:57, 6 December 2010

Status & tagging log