http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73693
Revision: 73693
Author: neilk
Date: 2010-09-24 23:02:28 +0000 (Fri, 24 Sep 2010)
Log Message:
-----------
get baseUrl of Special page in proper way; properly add RENDER_NOW flag;
documentation fixes
Modified Paths:
--------------
branches/uploadwizard/extensions/UploadWizard/SessionStash.php
Modified: branches/uploadwizard/extensions/UploadWizard/SessionStash.php
===================================================================
--- branches/uploadwizard/extensions/UploadWizard/SessionStash.php
2010-09-24 22:42:14 UTC (rev 73692)
+++ branches/uploadwizard/extensions/UploadWizard/SessionStash.php
2010-09-24 23:02:28 UTC (rev 73693)
@@ -1,4 +1,14 @@
<?php
+/**
+ * SessionStash is intended to accomplish a few things:
+ * - enable applications to temporarily stash files without publishing them
to the wiki.
+ * - Several parts of MediaWiki do this in similar ways: UploadBase,
UploadWizard, and FirefoggChunkedExtension
+ * the idea is to unify them all here
+ * - enable applications to find said files later, as long as the session or
temp files haven't been purged.
+ * - 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.
+ */
class SessionStash {
// repository that this uses to store temp files
@@ -7,9 +17,12 @@
// array of initialized objects obtained from session (lazily
initialized upon getFile())
private $files = array();
- const SESSION_VERSION = 2;
- const SESSION_KEYNAME = 'wsUploadData';
- const SESSION_THUMB_KEYNAME = 'wsUploadDataThumb';
+ // the base URL for files in the stash
+ private $baseUrl;
+
+ // TODO: Once UploadBase starts using this, switch to use these
constants rather than UploadBase::SESSION*
+ // const SESSION_VERSION = 2;
+ // const SESSION_KEYNAME = 'wsUploadData';
/**
* Represents the session which contain temporarily stored files.
@@ -27,14 +40,15 @@
throw new MWException( 'session not available' );
}
- if ( ! array_key_exists( self::SESSION_KEYNAME, $_SESSION ) ) {
- $_SESSION[self::SESSION_KEYNAME] = array();
+ if ( ! array_key_exists( UploadBase::SESSION_KEYNAME, $_SESSION
) ) {
+ $_SESSION[UploadBase::SESSION_KEYNAME] = array();
}
+
+ $this->baseUrl = SpecialPage::getTitleFor( 'SessionStash'
)->getLocalURL();
}
public function getBaseUrl() {
- // XXX do this better
- return '/wiki/Special:SessionStash';
+ return $this->baseUrl;
}
/**
@@ -45,9 +59,9 @@
*/
public function getFile( $key ) {
if ( !array_key_exists( $key, $this->files ) ) {
- $stashData = $_SESSION[self::SESSION_KEYNAME][$key];
+ $stashData =
$_SESSION[UploadBase::SESSION_KEYNAME][$key];
- if ($stashData['version'] !== self::SESSION_VERSION ) {
+ if ($stashData['version'] !==
UploadBase::SESSION_VERSION ) {
throw new MWException( 'session item schema
does not match current software' );
}
@@ -96,7 +110,7 @@
'mTempPath' => $stashPath,
'mFileSize' => $fileSize,
'mFileProps' => $fileProps,
- 'version' => self::SESSION_VERSION
+ 'version' => UploadBase::SESSION_VERSION
);
// put extended info into the session (this changes from
application to application).
@@ -107,7 +121,7 @@
}
}
- $_SESSION[self::SESSION_KEYNAME][$key] = $stashData;
+ $_SESSION[UploadBase::SESSION_KEYNAME][$key] = $stashData;
wfDebug( "SESSION\n=====\n " . print_r( $_SESSION, 1 ) . "\n" );
@@ -156,6 +170,9 @@
* Find or guess extension -- ensuring that our extension matches our
mime type.
* Since these files are constructed from php tempnames they may not
start off
* with an extension
+ * This does not override getExtension because things like getMimeType
already call getExtension,
+ * and that results in infinite recursion. So, we preemptively *set*
the extension so getExtension can find it.
+ * For obvious reasons this should be called as early as possible, as
part of initialization
*/
public function setExtension() {
// Does this have an extension?
@@ -179,7 +196,7 @@
throw 'cannot determine extension';
}
- return parent::normalizeExtension( $extension );
+ $this->extension = parent::normalizeExtension( $extension );
}
/**
@@ -188,7 +205,7 @@
* buggy code elsewhere that expects a boolean 'suffix'
*
* @param {String|false} name of thumbnail (e.g. "120px-123456.jpg" ),
or false to just get the path
- * @param {String} path thumbnail should take on filesystem, or
containing directory if thumbname is false
+ * @return {String} path thumbnail should take on filesystem, or
containing directory if thumbname is false
*/
public function getThumbPath( $thumbName=false ) {
$path = dirname( $this->path );
@@ -251,6 +268,7 @@
/**
* Return the URL of the file, if for some reason we wanted to download
it
* We tend not to do this for the original file, but we do want thumb
icons
+ * @return {String} url
*/
public function getUrl() {
if ( !isset( $this->url ) ) {
@@ -268,7 +286,7 @@
public function transform( $params, $flags=0 ) {
// force it to get a thumbnail right away
- $flags &= self::RENDER_NOW;
+ $flags |= self::RENDER_NOW;
// returns a ThumbnailImage object containing the url and path.
Note. NOT A FILE OBJECT.
$thumb = parent::transform( $params, $flags );
@@ -282,12 +300,10 @@
}
$stashedThumbFile = $this->sessionStash->stashFile( $key,
$thumb->path );
- $thumb->url = $this->sessionStash->getBaseUrl() . '/' . $key .
"." . $stashedThumbFile->extension;
+ $thumb->url = $stashedThumbFile->getUrl();
return $thumb;
}
}
-
-?>
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs