Index: branches/new-upload/phase3/includes/filerepo/FSRepo.php |
— | — | @@ -274,13 +274,13 @@ |
275 | 275 | * @param string $virtualUrl The virtual URL returned by storeTemp |
276 | 276 | * @return boolean True on success, false on failure |
277 | 277 | */ |
278 | | - function freeTemp( $virtualUrl ) { |
279 | | - $temp = "mwrepo://{$this->name}/temp"; |
| 278 | + function freeTemp( $virtualUrl ) { |
| 279 | + $temp = "mwrepo://{$this->name}/temp"; |
280 | 280 | if ( substr( $virtualUrl, 0, strlen( $temp ) ) != $temp ) { |
281 | 281 | wfDebug( __METHOD__.": Invalid virtual URL\n" ); |
282 | 282 | return false; |
283 | | - } |
284 | | - $path = $this->resolveVirtualUrl( $virtualUrl ); |
| 283 | + } |
| 284 | + $path = $this->resolveVirtualUrl( $virtualUrl ); |
285 | 285 | wfSuppressWarnings(); |
286 | 286 | $success = unlink( $path ); |
287 | 287 | wfRestoreWarnings(); |
Index: branches/new-upload/phase3/includes/UploadFromUrl.php |
— | — | @@ -52,40 +52,11 @@ |
53 | 53 | //now do the actual download to the shared target: |
54 | 54 | $status = Http::doDownload ( $this->mUrl, $this->mTempPath, $this->dl_mode); |
55 | 55 | //update the local filesize var: |
56 | | - $this->mFileSize = filesize($this->mTempPath); |
57 | | - |
58 | | - return $status; |
| 56 | + $this->mFileSize = filesize( $this->mTempPath ); |
| 57 | + return $status; |
59 | 58 | |
60 | | - /* |
61 | | - $res = $this->curlCopy(); |
62 | | - if( $res !== true ) { |
63 | | - return array( |
64 | | - 'status' => self::BEFORE_PROCESSING, |
65 | | - 'error' => $res, |
66 | | - ); |
67 | | - }*/ |
68 | | - |
69 | 59 | } |
70 | 60 | |
71 | | - |
72 | | - /** |
73 | | - * Callback function for CURL-based web transfer |
74 | | - * Write data to file unless we've passed the length limit; |
75 | | - * if so, abort immediately. |
76 | | - * @access private |
77 | | - |
78 | | - function uploadCurlCallback( $ch, $data ) { |
79 | | - global $wgMaxUploadSize; |
80 | | - $length = strlen( $data ); |
81 | | - $this->mFileSize += $length; |
82 | | - if( $this->mFileSize > $wgMaxUploadSize ) { |
83 | | - return 0; |
84 | | - } |
85 | | - fwrite( $this->mCurlDestHandle, $data ); |
86 | | - return $length; |
87 | | - } |
88 | | -*/ |
89 | | - //this can be deprecated in favor of http_request2 functions |
90 | 61 | static function isValidRequest( $request ){ |
91 | 62 | if( !$request->getVal('wpUploadFileURL') ) |
92 | 63 | return false; |
Index: branches/new-upload/phase3/includes/UploadFromStash.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | class UploadFromStash extends UploadBase { |
4 | | - static function isValidSessionKey( $key, $sessionData ) { |
| 4 | + static function isValidSessionKey( $key, $sessionData ) { |
5 | 5 | return !empty( $key ) && |
6 | 6 | is_array( $sessionData ) && |
7 | 7 | isset( $sessionData[$key] ) && |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | $sessionData[$key]['version'] == self::SESSION_VERSION |
10 | 10 | ; |
11 | 11 | } |
12 | | - static function isValidRequest( $request ) { |
| 12 | + static function isValidRequest(& $request ) { |
13 | 13 | $sessionData = $request->getSessionData('wsUploadData'); |
14 | 14 | return self::isValidSessionKey( |
15 | 15 | $request->getInt( 'wpSessionKey' ), |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | * We don't want path names to be forged, so we keep |
23 | 23 | * them in the session on the server and just give |
24 | 24 | * an opaque key to the user agent. |
25 | | - */ |
| 25 | + */ |
26 | 26 | parent::initialize( $name, |
27 | 27 | $sessionData['mTempPath'], |
28 | 28 | $sessionData['mFileSize'], |
Index: branches/new-upload/phase3/includes/UploadFromChunks.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | const DONE = 3; |
21 | 21 | |
22 | 22 | function initializeFromParams( &$param , &$request) { |
23 | | - $this->initFromSessionKey( $param['chunksessionkey'] ); |
| 23 | + $this->initFromSessionKey( $param['chunksessionkey'], $request ); |
24 | 24 | //set the chunk mode: |
25 | 25 | if( !$this->mSessionKey && !$param['done'] ){ |
26 | 26 | //session key not set init the chunk upload system: |
— | — | @@ -43,19 +43,22 @@ |
44 | 44 | return $this->status; |
45 | 45 | } |
46 | 46 | |
47 | | - function initFromSessionKey( $sessionKey ){ |
| 47 | + function initFromSessionKey( $sessionKey, $request ){ |
48 | 48 | if( !$sessionKey || empty( $sessionKey ) ){ |
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | $this->mSessionKey = $sessionKey; |
52 | | - if( isset( $_SESSION['wsUploadData'][$this->mSessionKey]['version'] ) && |
53 | | - $_SESSION['wsUploadData'][$this->mSessionKey]['version'] == self::SESSION_VERSION ) { |
| 52 | + //load the sessionData array: |
| 53 | + $sessionData = $request->getSessionData('wsUploadData'); |
| 54 | + |
| 55 | + if( isset( $sessionData[$this->mSessionKey]['version'] ) && |
| 56 | + $sessionData[$this->mSessionKey]['version'] == self::SESSION_VERSION ) { |
54 | 57 | //update the local object from the session |
55 | | - $this->mComment = $_SESSION[ 'wsUploadData' ][ $this->mSessionKey ][ 'mComment' ]; |
56 | | - $this->mWatch = $_SESSION[ 'wsUploadData' ][ $this->mSessionKey ][ 'mWatch' ]; |
57 | | - $this->mFilteredName = $_SESSION[ 'wsUploadData' ][ $this->mSessionKey ][ 'mFilteredName' ]; |
58 | | - $this->mTempAppendPath = $_SESSION[ 'wsUploadData' ][ $this->mSessionKey ][ 'mTempAppendPath' ]; |
59 | | - $this->mDesiredDestName = $_SESSION[ 'wsUploadData' ][ $this->mSessionKey ][ 'mDesiredDestName' ]; |
| 58 | + $this->mComment = $sessionData[ $this->mSessionKey ][ 'mComment' ]; |
| 59 | + $this->mWatch = $sessionData[ $this->mSessionKey ][ 'mWatch' ]; |
| 60 | + $this->mFilteredName = $sessionData[ $this->mSessionKey ][ 'mFilteredName' ]; |
| 61 | + $this->mTempAppendPath = $sessionData[ $this->mSessionKey ][ 'mTempAppendPath' ]; |
| 62 | + $this->mDesiredDestName = $sessionData[ $this->mSessionKey ][ 'mDesiredDestName' ]; |
60 | 63 | }else{ |
61 | 64 | $this->status = Array( 'error'=> 'missing session data'); |
62 | 65 | return false; |
Index: branches/new-upload/phase3/includes/HttpFunctions.php |
— | — | @@ -27,8 +27,7 @@ |
28 | 28 | return $req->request(); |
29 | 29 | } |
30 | 30 | public static function doDownload( $url, $target_file_path , $dl_mode = self::SYNC_DOWNLOAD ){ |
31 | | - global $wgPhpCliPath, $wgMaxUploadSize; |
32 | | - print "doDownload:$target_file_path"; |
| 31 | + global $wgPhpCliPath, $wgMaxUploadSize; |
33 | 32 | //do a quick check to HEAD to insure the file size is not > $wgMaxUploadSize to large no need to download it |
34 | 33 | $head = get_headers($url, 1); |
35 | 34 | if(isset($head['Content-Length']) && $head['Content-Length'] > $wgMaxUploadSize){ |
Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | * implements Special:Upload |
20 | 20 | * @ingroup SpecialPage |
21 | 21 | */ |
22 | | -class UploadForm { |
| 22 | +class UploadForm extends SpecialPage { |
23 | 23 | /**#@+ |
24 | 24 | * @access private |
25 | 25 | */ |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | * Get data POSTed through the form and assign them to the object |
43 | 43 | * @param $request Data posted. |
44 | 44 | */ |
45 | | - function __construct( &$request ) { |
| 45 | + function __construct( &$request ) { |
46 | 46 | // Guess the desired name from the filename if not provided |
47 | 47 | $this->mDesiredDestName = $request->getText( 'wpDestFile' ); |
48 | 48 | if( !$this->mDesiredDestName ) |
— | — | @@ -72,7 +72,8 @@ |
73 | 73 | $this->mReUpload = $request->getCheck( 'wpReUpload' ); |
74 | 74 | |
75 | 75 | $this->mAction = $request->getVal( 'action' ); |
76 | | - $this->mUpload = UploadBase::createFromRequest( $request ); |
| 76 | + |
| 77 | + $this->mUpload = UploadBase::createFromRequest( $request ); |
77 | 78 | } |
78 | 79 | |
79 | 80 | |
— | — | @@ -80,8 +81,8 @@ |
81 | 82 | * Start doing stuff |
82 | 83 | * @access public |
83 | 84 | */ |
84 | | - function execute() { |
85 | | - global $wgUser, $wgOut; |
| 85 | + function execute() { |
| 86 | + global $wgUser, $wgOut; |
86 | 87 | |
87 | 88 | # Check uploading enabled |
88 | 89 | if( !UploadBase::isEnabled() ) { |
— | — | @@ -114,9 +115,9 @@ |
115 | 116 | $wgOut->readOnlyPage(); |
116 | 117 | return; |
117 | 118 | } |
118 | | - if( $this->mReUpload ) { |
119 | | - // User did not choose to ignore warnings |
120 | | - if( !$this->mUpload->unsaveUploadedFile() ) { |
| 119 | + if( $this->mReUpload ) { |
| 120 | + // User choose to cancel upload |
| 121 | + if( !$this->mUpload->unsaveUploadedFile() ) { |
121 | 122 | return; |
122 | 123 | } |
123 | 124 | # Because it is probably checked and shouldn't be |
— | — | @@ -484,16 +485,13 @@ |
485 | 486 | global $wgOut, $wgUser; |
486 | 487 | global $wgUseCopyrightUpload; |
487 | 488 | |
488 | | - $sessionData = $this->mUpload->stashSession(); |
| 489 | + $this->mSessionKey = $this->mUpload->stashSession(); |
489 | 490 | |
490 | 491 | if( $sessionData === false ) { |
491 | 492 | # Couldn't save file; an error has been displayed so let's go. |
492 | 493 | return; |
493 | | - } |
| 494 | + } |
494 | 495 | |
495 | | - $this->mSessionKey = mt_rand( 0, 0x7fffffff ); |
496 | | - $_SESSION['wsUploadData'][$this->mSessionKey] = $sessionData; |
497 | | - |
498 | 496 | $sk = $wgUser->getSkin(); |
499 | 497 | |
500 | 498 | $wgOut->addHTML( '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" ); |
Index: branches/new-upload/phase3/includes/UploadBase.php |
— | — | @@ -57,9 +57,11 @@ |
58 | 58 | * Create a form of UploadBase depending on wpSourceType and initializes it |
59 | 59 | */ |
60 | 60 | static function createFromRequest( &$request, $type = null ) { |
61 | | - $type = $type ? $type : $request->getVal( 'wpSourceType' ); |
| 61 | + $type = $type ? $type : $request->getVal( 'wpSourceType' ); |
| 62 | + |
62 | 63 | if( !$type ) |
63 | 64 | return null; |
| 65 | + |
64 | 66 | $type = ucfirst($type); |
65 | 67 | $className = 'UploadFrom'.$type; |
66 | 68 | if( !in_array( $type, self::$uploadHandlers ) ) |
— | — | @@ -67,11 +69,12 @@ |
68 | 70 | |
69 | 71 | if( !call_user_func( array( $className, 'isEnabled' ) ) ) |
70 | 72 | return null; |
71 | | - |
| 73 | + |
72 | 74 | if( !call_user_func( array( $className, 'isValidRequest' ), $request ) ) |
73 | 75 | return null; |
74 | | - |
| 76 | + |
75 | 77 | $handler = new $className; |
| 78 | + |
76 | 79 | $handler->initializeFromRequest( $request ); |
77 | 80 | return $handler; |
78 | 81 | } |
— | — | @@ -98,7 +101,7 @@ |
99 | 102 | * Fetch the file. Usually a no-op |
100 | 103 | */ |
101 | 104 | function fetchFile() { |
102 | | - return self::OK; |
| 105 | + return Status::newGood(); |
103 | 106 | } |
104 | 107 | //return the file size |
105 | 108 | function isEmptyFile(){ |
— | — | @@ -280,9 +283,12 @@ |
281 | 284 | |
282 | 285 | // Check whether this may be a thumbnail |
283 | 286 | if( $exists !== false && $exists[0] != 'thumb' |
284 | | - && self::isThumbName( $this->mLocalFile->getName() ) ) |
| 287 | + && self::isThumbName( $this->mLocalFile->getName() ) ){ |
| 288 | + //make the title: |
| 289 | + $nt = $this->getTitle(); |
285 | 290 | $warning['file-thumbnail-no'] = substr( $filename , 0, |
286 | 291 | strpos( $nt->getText() , '-' ) +1 ); |
| 292 | + } |
287 | 293 | |
288 | 294 | // Check dupes against existing files |
289 | 295 | $hash = File::sha1Base36( $this->mTempPath ); |
— | — | @@ -444,16 +450,16 @@ |
445 | 451 | * @access private |
446 | 452 | */ |
447 | 453 | function stashSession() { |
448 | | - $stash = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath ); |
449 | | - |
450 | | - if( !$stash ) { |
| 454 | + $status = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath ); |
| 455 | + if( !$status->isOK() ) { |
451 | 456 | # Couldn't save the file. |
452 | 457 | return false; |
453 | 458 | } |
| 459 | + $mTempPath = $status->value; |
454 | 460 | |
455 | 461 | $key = $this->getSessionKey (); |
456 | 462 | $_SESSION['wsUploadData'][$key] = array( |
457 | | - 'mTempPath' => $stash, |
| 463 | + 'mTempPath' => $mTempPath, |
458 | 464 | 'mFileSize' => $this->mFileSize, |
459 | 465 | 'mSrcName' => $this->mSrcName, |
460 | 466 | 'mFileProps' => $this->mFileProps, |
— | — | @@ -472,9 +478,10 @@ |
473 | 479 | * Remove a temporarily kept file stashed by saveTempUploadedFile(). |
474 | 480 | * @return success |
475 | 481 | */ |
476 | | - function unsaveUploadedFile() { |
477 | | - $repo = RepoGroup::singleton()->getLocalRepo(); |
478 | | - $success = $repo->freeTemp( $this->mTempPath ); |
| 482 | + function unsaveUploadedFile() { |
| 483 | + $repo = RepoGroup::singleton()->getLocalRepo(); |
| 484 | + print "free temp: {$this->mTempPath}\n"; |
| 485 | + $success = $repo->freeTemp( $this->mTempPath ); |
479 | 486 | return $success; |
480 | 487 | } |
481 | 488 | |
— | — | @@ -483,7 +490,7 @@ |
484 | 491 | * on exit to clean up. |
485 | 492 | * @access private |
486 | 493 | */ |
487 | | - function cleanupTempFile() { |
| 494 | + function cleanupTempFile() { |
488 | 495 | if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) { |
489 | 496 | wfDebug( __METHOD__.": Removing temporary file {$this->mTempPath}\n" ); |
490 | 497 | unlink( $this->mTempPath ); |