]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/upload/UploadFromStash.php
MediaWiki 1.17.1
[autoinstallsdev/mediawiki.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         }
45
46         public function initializeFromRequest( &$request ) {
47                 $sessionKey = $request->getText( 'wpSessionKey' );
48                 $sessionData = $request->getSessionData( UploadBase::SESSION_KEYNAME );
49
50                 $desiredDestName = $request->getText( 'wpDestFile' );
51                 if( !$desiredDestName )
52                         $desiredDestName = $request->getText( 'wpUploadFile' );
53                 return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
54         }
55
56         /**
57          * File has been previously verified so no need to do so again.
58          */
59         protected function verifyFile() {
60                 return true;
61         }
62
63
64         /**
65          * There is no need to stash the image twice
66          */
67         public function stashSession( $key = null ) {
68                 if ( !empty( $this->mSessionKey ) )
69                         return $this->mSessionKey;
70                 return parent::stashSession();
71         }
72
73         /**
74          * Remove a temporarily kept file stashed by saveTempUploadedFile().
75          * @return success
76          */
77         public function unsaveUploadedFile() {
78                 $repo = RepoGroup::singleton()->getLocalRepo();
79                 $success = $repo->freeTemp( $this->mVirtualTempPath );
80                 return $success;
81         }
82
83 }