r73644 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73643‎ | r73644 | r73645 >
Date:21:13, 23 September 2010
Author:neilk
Status:deferred
Tags:
Comment:
reverting some changes unrelated to previous merge; will commit separately
Modified paths:
  • /branches/uploadwizard/extensions/UploadWizard/SessionStash.php (modified) (history)
  • /branches/uploadwizard/extensions/UploadWizard/UploadWizardMessages.php (modified) (history)

Diff [purge]

Index: branches/uploadwizard/extensions/UploadWizard/UploadWizardMessages.php
@@ -49,7 +49,8 @@
5050 $messagesForJs[ $key ] = wfMsgGetKey( $key, /*DB*/true, $language, /*Transform*/false );
5151 }
5252
53 - $messagesJson = FormatJson::encode( $messagesForJs );
 53+ $json = new Services_JSON();
 54+ $messagesJson = $json->encode( $messagesForJs );
5455 return 'mw.addMessages(' . $messagesJson . ');';
5556 }
5657
@@ -68,3 +69,5 @@
6970 }
7071
7172 }
 73+
 74+?>
Index: branches/uploadwizard/extensions/UploadWizard/SessionStash.php
@@ -1,14 +1,4 @@
22 <?php
3 -/**
4 - * SessionStash is intended to accomplish a few things:
5 - * - enable applications to temporarily stash files without publishing them to the wiki.
6 - * - Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension
7 - * the idea is to unify them all here
8 - * - enable applications to find said files later, as long as the session or temp files haven't been purged.
9 - * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL.
10 - * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access
11 - * the session, even the uploading user.
12 - */
133
144 class SessionStash {
155 // repository that this uses to store temp files
@@ -17,12 +7,9 @@
188 // array of initialized objects obtained from session (lazily initialized upon getFile())
199 private $files = array();
2010
21 - // the base URL for files in the stash
22 - private $baseUrl;
23 -
24 - // TODO: Once UploadBase starts using this, switch to use these constants rather than UploadBase::SESSION*
25 - // const SESSION_VERSION = 2;
26 - // const SESSION_KEYNAME = 'wsUploadData';
 11+ const SESSION_VERSION = 2;
 12+ const SESSION_KEYNAME = 'wsUploadData';
 13+ const SESSION_THUMB_KEYNAME = 'wsUploadDataThumb';
2714
2815 /**
2916 * Represents the session which contain temporarily stored files.
@@ -40,15 +27,14 @@
4128 throw new MWException( 'session not available' );
4229 }
4330
44 - if ( ! array_key_exists( UploadBase::SESSION_KEYNAME, $_SESSION ) ) {
45 - $_SESSION[UploadBase::SESSION_KEYNAME] = array();
 31+ if ( ! array_key_exists( self::SESSION_KEYNAME, $_SESSION ) ) {
 32+ $_SESSION[self::SESSION_KEYNAME] = array();
4633 }
47 -
48 - $this->baseUrl = SpecialPage::getTitleFor( 'SessionStash' )->getLocalURL();
4934 }
5035
5136 public function getBaseUrl() {
52 - return $this->baseUrl;
 37+ // XXX do this better
 38+ return '/wiki/Special:SessionStash';
5339 }
5440
5541 /**
@@ -59,9 +45,9 @@
6046 */
6147 public function getFile( $key ) {
6248 if ( !array_key_exists( $key, $this->files ) ) {
63 - $stashData = $_SESSION[UploadBase::SESSION_KEYNAME][$key];
 49+ $stashData = $_SESSION[self::SESSION_KEYNAME][$key];
6450
65 - if ($stashData['version'] !== UploadBase::SESSION_VERSION ) {
 51+ if ($stashData['version'] !== self::SESSION_VERSION ) {
6652 throw new MWException( 'session item schema does not match current software' );
6753 }
6854
@@ -110,7 +96,7 @@
11197 'mTempPath' => $stashPath,
11298 'mFileSize' => $fileSize,
11399 'mFileProps' => $fileProps,
114 - 'version' => UploadBase::SESSION_VERSION
 100+ 'version' => self::SESSION_VERSION
115101 );
116102
117103 // put extended info into the session (this changes from application to application).
@@ -121,7 +107,7 @@
122108 }
123109 }
124110
125 - $_SESSION[UploadBase::SESSION_KEYNAME][$key] = $stashData;
 111+ $_SESSION[self::SESSION_KEYNAME][$key] = $stashData;
126112
127113 wfDebug( "SESSION\n=====\n " . print_r( $_SESSION, 1 ) . "\n" );
128114
@@ -170,9 +156,6 @@
171157 * Find or guess extension -- ensuring that our extension matches our mime type.
172158 * Since these files are constructed from php tempnames they may not start off
173159 * with an extension
174 - * This does not override getExtension because things like getMimeType already call getExtension,
175 - * and that results in infinite recursion. So, we preemptively *set* the extension so getExtension can find it.
176 - * For obvious reasons this should be called as early as possible, as part of initialization
177160 */
178161 public function setExtension() {
179162 // Does this have an extension?
@@ -196,7 +179,7 @@
197180 throw 'cannot determine extension';
198181 }
199182
200 - $this->extension = parent::normalizeExtension( $extension );
 183+ return parent::normalizeExtension( $extension );
201184 }
202185
203186 /**
@@ -205,7 +188,7 @@
206189 * buggy code elsewhere that expects a boolean 'suffix'
207190 *
208191 * @param {String|false} name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path
209 - * @return {String} path thumbnail should take on filesystem, or containing directory if thumbname is false
 192+ * @param {String} path thumbnail should take on filesystem, or containing directory if thumbname is false
210193 */
211194 public function getThumbPath( $thumbName=false ) {
212195 $path = dirname( $this->path );
@@ -268,7 +251,6 @@
269252 /**
270253 * Return the URL of the file, if for some reason we wanted to download it
271254 * We tend not to do this for the original file, but we do want thumb icons
272 - * @return {String} url
273255 */
274256 public function getUrl() {
275257 if ( !isset( $this->url ) ) {
@@ -286,7 +268,7 @@
287269 public function transform( $params, $flags=0 ) {
288270
289271 // force it to get a thumbnail right away
290 - $flags |= self::RENDER_NOW;
 272+ $flags &= self::RENDER_NOW;
291273
292274 // returns a ThumbnailImage object containing the url and path. Note. NOT A FILE OBJECT.
293275 $thumb = parent::transform( $params, $flags );
@@ -300,10 +282,12 @@
301283 }
302284
303285 $stashedThumbFile = $this->sessionStash->stashFile( $key, $thumb->path );
304 - $thumb->url = $stashedThumbFile->getUrl();
 286+ $thumb->url = $this->sessionStash->getBaseUrl() . '/' . $key . "." . $stashedThumbFile->extension;
305287
306288 return $thumb;
307289
308290 }
309291
310292 }
 293+
 294+?>

Status & tagging log