summaryrefslogtreecommitdiff
path: root/includes/upload/UploadFromStash.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-07-28 11:52:48 +0200
commit222b01f5169f1c7e69762e0e8904c24f78f71882 (patch)
tree8e932e12546bb991357ec48eb1638d1770be7a35 /includes/upload/UploadFromStash.php
parent00ab76a6b686e98a914afc1975812d2b1aaa7016 (diff)
update to MediaWiki 1.16.0
Diffstat (limited to 'includes/upload/UploadFromStash.php')
-rw-r--r--includes/upload/UploadFromStash.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/includes/upload/UploadFromStash.php b/includes/upload/UploadFromStash.php
new file mode 100644
index 00000000..17e922b0
--- /dev/null
+++ b/includes/upload/UploadFromStash.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @file
+ * @ingroup upload
+ *
+ * Implements uploading from previously stored file.
+ *
+ * @author Bryan Tong Minh
+ */
+
+class UploadFromStash extends UploadBase {
+ public static function isValidSessionKey( $key, $sessionData ) {
+ return !empty( $key ) &&
+ is_array( $sessionData ) &&
+ isset( $sessionData[$key] ) &&
+ isset( $sessionData[$key]['version'] ) &&
+ $sessionData[$key]['version'] == self::SESSION_VERSION;
+ }
+
+ public static function isValidRequest( $request ) {
+ $sessionData = $request->getSessionData( 'wsUploadData' );
+ return self::isValidSessionKey(
+ $request->getInt( 'wpSessionKey' ),
+ $sessionData
+ );
+ }
+
+ public function initialize( $name, $sessionKey, $sessionData ) {
+ /**
+ * Confirming a temporarily stashed upload.
+ * We don't want path names to be forged, so we keep
+ * them in the session on the server and just give
+ * an opaque key to the user agent.
+ */
+
+ $this->initializePathInfo( $name,
+ $this->getRealPath ( $sessionData['mTempPath'] ),
+ $sessionData['mFileSize'],
+ false
+ );
+
+ $this->mSessionKey = $sessionKey;
+ $this->mVirtualTempPath = $sessionData['mTempPath'];
+ $this->mFileProps = $sessionData['mFileProps'];
+ }
+
+ public function initializeFromRequest( &$request ) {
+ $sessionKey = $request->getInt( 'wpSessionKey' );
+ $sessionData = $request->getSessionData('wsUploadData');
+
+ $desiredDestName = $request->getText( 'wpDestFile' );
+ if( !$desiredDestName )
+ $desiredDestName = $request->getText( 'wpUploadFile' );
+ return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
+ }
+
+ /**
+ * File has been previously verified so no need to do so again.
+ */
+ protected function verifyFile() {
+ return true;
+ }
+
+
+ /**
+ * There is no need to stash the image twice
+ */
+ public function stashSession() {
+ if ( !empty( $this->mSessionKey ) )
+ return $this->mSessionKey;
+ return parent::stashSession();
+ }
+
+ /**
+ * Remove a temporarily kept file stashed by saveTempUploadedFile().
+ * @return success
+ */
+ public function unsaveUploadedFile() {
+ $repo = RepoGroup::singleton()->getLocalRepo();
+ $success = $repo->freeTemp( $this->mVirtualTempPath );
+ return $success;
+ }
+
+} \ No newline at end of file