Followup r63914, function must match parent
[mediawiki.git] / includes / upload / UploadFromStash.php
blob17e922b0ad72f573978d3bb9bd48a80f65c76839
1 <?php
2 /**
3 * @file
4 * @ingroup upload
6 * Implements uploading from previously stored file.
8 * @author Bryan Tong Minh
9 */
11 class UploadFromStash extends UploadBase {
12 public static function isValidSessionKey( $key, $sessionData ) {
13 return !empty( $key ) &&
14 is_array( $sessionData ) &&
15 isset( $sessionData[$key] ) &&
16 isset( $sessionData[$key]['version'] ) &&
17 $sessionData[$key]['version'] == self::SESSION_VERSION;
20 public static function isValidRequest( $request ) {
21 $sessionData = $request->getSessionData( 'wsUploadData' );
22 return self::isValidSessionKey(
23 $request->getInt( 'wpSessionKey' ),
24 $sessionData
28 public function initialize( $name, $sessionKey, $sessionData ) {
29 /**
30 * Confirming a temporarily stashed upload.
31 * We don't want path names to be forged, so we keep
32 * them in the session on the server and just give
33 * an opaque key to the user agent.
36 $this->initializePathInfo( $name,
37 $this->getRealPath ( $sessionData['mTempPath'] ),
38 $sessionData['mFileSize'],
39 false
42 $this->mSessionKey = $sessionKey;
43 $this->mVirtualTempPath = $sessionData['mTempPath'];
44 $this->mFileProps = $sessionData['mFileProps'];
47 public function initializeFromRequest( &$request ) {
48 $sessionKey = $request->getInt( 'wpSessionKey' );
49 $sessionData = $request->getSessionData('wsUploadData');
51 $desiredDestName = $request->getText( 'wpDestFile' );
52 if( !$desiredDestName )
53 $desiredDestName = $request->getText( 'wpUploadFile' );
54 return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
57 /**
58 * File has been previously verified so no need to do so again.
60 protected function verifyFile() {
61 return true;
65 /**
66 * There is no need to stash the image twice
68 public function stashSession() {
69 if ( !empty( $this->mSessionKey ) )
70 return $this->mSessionKey;
71 return parent::stashSession();
74 /**
75 * Remove a temporarily kept file stashed by saveTempUploadedFile().
76 * @return success
78 public function unsaveUploadedFile() {
79 $repo = RepoGroup::singleton()->getLocalRepo();
80 $success = $repo->freeTemp( $this->mVirtualTempPath );
81 return $success;