re bug #25523: add mime.info and mime.types for *.dwg files so that when people add...
[lhc/web/wiklou.git] / includes / upload / UploadFromStash.php
1 <?php
2 /**
3 * Implements uploading from previously stored file.
4 *
5 * @file
6 * @ingroup upload
7 * @author Bryan Tong Minh
8 */
9
10 class UploadFromStash extends UploadBase {
11 public static function isValidSessionKey( $key, $sessionData ) {
12 return !empty( $key ) &&
13 is_array( $sessionData ) &&
14 isset( $sessionData[$key] ) &&
15 isset( $sessionData[$key]['version'] ) &&
16 $sessionData[$key]['version'] == UploadBase::SESSION_VERSION;
17 }
18
19 public static function isValidRequest( $request ) {
20 $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME );
21 return self::isValidSessionKey(
22 $request->getText( 'wpSessionKey' ),
23 $sessionData
24 );
25 }
26
27 public function initialize( $name, $sessionKey, $sessionData ) {
28 /**
29 * Confirming a temporarily stashed upload.
30 * We don't want path names to be forged, so we keep
31 * them in the session on the server and just give
32 * an opaque key to the user agent.
33 */
34
35 $this->initializePathInfo( $name,
36 $this->getRealPath ( $sessionData['mTempPath'] ),
37 $sessionData['mFileSize'],
38 false
39 );
40
41 $this->mSessionKey = $sessionKey;
42 $this->mVirtualTempPath = $sessionData['mTempPath'];
43 $this->mFileProps = $sessionData['mFileProps'];
44 $this->mSourceType = isset( $sessionData['mSourceType'] ) ?
45 $sessionData['mSourceType'] : null;
46 }
47
48 public function initializeFromRequest( &$request ) {
49 $sessionKey = $request->getText( 'wpSessionKey' );
50 $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME );
51
52 $desiredDestName = $request->getText( 'wpDestFile' );
53 if( !$desiredDestName )
54 $desiredDestName = $request->getText( 'wpUploadFile' );
55 return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
56 }
57
58 public function getSourceType() {
59 return $this->mSourceType;
60 }
61
62 /**
63 * File has been previously verified so no need to do so again.
64 */
65 protected function verifyFile() {
66 return true;
67 }
68
69
70 /**
71 * There is no need to stash the image twice
72 */
73 public function stashSession( $key = null ) {
74 if ( !empty( $this->mSessionKey ) )
75 return $this->mSessionKey;
76 return parent::stashSession();
77 }
78
79 /**
80 * Remove a temporarily kept file stashed by saveTempUploadedFile().
81 * @return success
82 */
83 public function unsaveUploadedFile() {
84 $repo = RepoGroup::singleton()->getLocalRepo();
85 $success = $repo->freeTemp( $this->mVirtualTempPath );
86 return $success;
87 }
88
89 }