Index: trunk/phase3/includes/upload/UploadFromStash.php |
— | — | @@ -1,56 +1,61 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | class UploadFromStash extends UploadBase { |
| 5 | + |
4 | 6 | static function isValidSessionKey( $key, $sessionData ) { |
5 | 7 | return !empty( $key ) && |
6 | 8 | is_array( $sessionData ) && |
7 | 9 | isset( $sessionData[$key] ) && |
8 | 10 | isset( $sessionData[$key]['version'] ) && |
9 | | - $sessionData[$key]['version'] == self::SESSION_VERSION |
10 | | - ; |
| 11 | + $sessionData[$key]['version'] == self::SESSION_VERSION; |
11 | 12 | } |
12 | | - static function isValidRequest(& $request ) { |
13 | | - $sessionData = $request->getSessionData('wsUploadData'); |
| 13 | + |
| 14 | + static function isValidRequest( &$request ) { |
| 15 | + $sessionData = $request->getSessionData( 'wsUploadData' ); |
14 | 16 | return self::isValidSessionKey( |
15 | 17 | $request->getInt( 'wpSessionKey' ), |
16 | 18 | $sessionData |
17 | 19 | ); |
18 | | - } |
| 20 | + } |
| 21 | + |
19 | 22 | function initialize( $name, $sessionData ) { |
20 | 23 | /** |
21 | 24 | * Confirming a temporarily stashed upload. |
22 | 25 | * We don't want path names to be forged, so we keep |
23 | 26 | * them in the session on the server and just give |
24 | 27 | * an opaque key to the user agent. |
25 | | - */ |
26 | | - parent::initialize( $name, |
27 | | - $sessionData['mTempPath'], |
| 28 | + */ |
| 29 | + parent::initialize( $name, |
| 30 | + $sessionData['mTempPath'], |
28 | 31 | $sessionData['mFileSize'], |
29 | 32 | false |
30 | 33 | ); |
31 | 34 | |
32 | | - $this->mFileProps = $sessionData['mFileProps']; |
| 35 | + $this->mFileProps = $sessionData['mFileProps']; |
33 | 36 | } |
34 | | - function initializeFromRequest( &$request ) { |
| 37 | + |
| 38 | + function initializeFromRequest( &$request ) { |
35 | 39 | $sessionKey = $request->getInt( 'wpSessionKey' ); |
36 | 40 | $sessionData = $request->getSessionData('wsUploadData'); |
37 | | - |
| 41 | + |
38 | 42 | $desiredDestName = $request->getText( 'wpDestFile' ); |
39 | 43 | if( !$desiredDestName ) |
40 | | - $desiredDestName = $request->getText( 'wpUploadFile' ); |
| 44 | + $desiredDestName = $request->getText( 'wpUploadFile' ); |
41 | 45 | return $this->initialize( $desiredDestName, $sessionData[$sessionKey] ); |
42 | 46 | } |
43 | | - |
| 47 | + |
44 | 48 | /** |
45 | 49 | * File has been previously verified so no need to do so again. |
46 | 50 | */ |
47 | 51 | protected function verifyFile( $tmpfile ) { |
48 | 52 | return true; |
49 | 53 | } |
| 54 | + |
50 | 55 | /** |
51 | 56 | * We're here from "ignore warnings anyway" so return just OK |
52 | 57 | */ |
53 | 58 | function checkWarnings() { |
54 | 59 | return array(); |
55 | 60 | } |
56 | | -} |
57 | | -?> |
\ No newline at end of file |
| 61 | + |
| 62 | +} |
\ No newline at end of file |
Index: trunk/phase3/includes/upload/UploadFromUrl.php |
— | — | @@ -1,80 +1,108 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | class UploadFromUrl extends UploadBase { |
4 | 5 | protected $mTempDownloadPath; |
5 | | - |
6 | | - //by default do a SYNC_DOWNLOAD |
| 6 | + |
| 7 | + // by default do a SYNC_DOWNLOAD |
7 | 8 | protected $dl_mode = null; |
8 | | - |
| 9 | + |
| 10 | + /** |
| 11 | + * Checks if the user is allowed to use the upload-by-URL feature |
| 12 | + */ |
9 | 13 | static function isAllowed( $user ) { |
10 | 14 | if( !$user->isAllowed( 'upload_by_url' ) ) |
11 | 15 | return 'upload_by_url'; |
12 | 16 | return parent::isAllowed( $user ); |
13 | 17 | } |
| 18 | + |
| 19 | + /** |
| 20 | + * Checks if the upload from URL feature is enabled |
| 21 | + */ |
14 | 22 | static function isEnabled() { |
15 | 23 | global $wgAllowCopyUploads; |
16 | 24 | return $wgAllowCopyUploads && parent::isEnabled(); |
17 | | - } |
18 | | - /*entry point for Api upload:: ASYNC_DOWNLOAD (if possible) */ |
19 | | - function initialize( $name, $url, $asyncdownload = false) { |
20 | | - global $wgTmpDirectory, $wgPhpCliPath; |
21 | | - |
22 | | - //check for $asyncdownload request: |
23 | | - if($asyncdownload !== false){ |
24 | | - if($wgPhpCliPath && wfShellExecEnabled() ){ |
| 25 | + } |
| 26 | + |
| 27 | + /* entry point for API upload:: ASYNC_DOWNLOAD (if possible) */ |
| 28 | + function initialize( $name, $url, $asyncdownload = false ) { |
| 29 | + global $wgTmpDirectory, $wgPhpCliPath; |
| 30 | + |
| 31 | + // check for $asyncdownload request: |
| 32 | + if( $asyncdownload !== false){ |
| 33 | + if( $wgPhpCliPath && wfShellExecEnabled() ){ |
25 | 34 | $this->dl_mode = Http::ASYNC_DOWNLOAD; |
26 | | - }else{ |
27 | | - $this->dl_mode = Http::SYNC_DOWNLOAD; |
| 35 | + } else { |
| 36 | + $this->dl_mode = Http::SYNC_DOWNLOAD; |
28 | 37 | } |
29 | 38 | } |
30 | | - |
| 39 | + |
31 | 40 | $local_file = tempnam( $wgTmpDirectory, 'WEBUPLOAD' ); |
32 | 41 | parent::initialize( $name, $local_file, 0, true ); |
33 | | - |
34 | | - $this->mUrl = trim( $url ); |
| 42 | + |
| 43 | + $this->mUrl = trim( $url ); |
35 | 44 | } |
| 45 | + |
36 | 46 | public function isAsync(){ |
37 | 47 | return $this->dl_mode == Http::ASYNC_DOWNLOAD; |
38 | 48 | } |
39 | | - /*entry point for SpecialUpload no ASYNC_DOWNLOAD possible: */ |
40 | | - function initializeFromRequest( &$request ) { |
41 | 49 | |
42 | | - //set dl mode if not set: |
43 | | - if(!$this->dl_mode) |
| 50 | + /** |
| 51 | + * Entry point for SpecialUpload no ASYNC_DOWNLOAD possible |
| 52 | + * @param $request Object: WebRequest object |
| 53 | + */ |
| 54 | + function initializeFromRequest( &$request ) { |
| 55 | + |
| 56 | + // set dl mode if not set: |
| 57 | + if( !$this->dl_mode ) |
44 | 58 | $this->dl_mode = Http::SYNC_DOWNLOAD; |
45 | | - |
| 59 | + |
46 | 60 | $desiredDestName = $request->getText( 'wpDestFile' ); |
47 | 61 | if( !$desiredDestName ) |
48 | | - $desiredDestName = $request->getText( 'wpUploadFile' ); |
49 | | - return $this->initialize( |
50 | | - $desiredDestName, |
51 | | - $request->getVal('wpUploadFileURL') |
| 62 | + $desiredDestName = $request->getText( 'wpUploadFile' ); |
| 63 | + return $this->initialize( |
| 64 | + $desiredDestName, |
| 65 | + $request->getVal( 'wpUploadFileURL' ) |
52 | 66 | ); |
53 | 67 | } |
| 68 | + |
54 | 69 | /** |
55 | 70 | * Do the real fetching stuff |
56 | 71 | */ |
57 | | - function fetchFile( ) { |
58 | | - //entry point for SpecialUplaod |
59 | | - if( self::isValidURI($this->mUrl) === false) { |
60 | | - return Status::newFatal('upload-proto-error'); |
61 | | - } |
62 | | - //now do the actual download to the target file: |
63 | | - $status = Http::doDownload ( $this->mUrl, $this->mTempPath, $this->dl_mode ); |
64 | | - |
65 | | - //update the local filesize var: |
66 | | - $this->mFileSize = filesize( $this->mTempPath ); |
67 | | - |
68 | | - return $status; |
| 72 | + function fetchFile() { |
| 73 | + // entry point for SpecialUplaod |
| 74 | + if( self::isValidURI( $this->mUrl ) === false ) { |
| 75 | + return Status::newFatal( 'upload-proto-error' ); |
| 76 | + } |
| 77 | + |
| 78 | + // now do the actual download to the target file: |
| 79 | + $status = Http::doDownload( $this->mUrl, $this->mTempPath, $this->dl_mode ); |
| 80 | + |
| 81 | + // update the local filesize var: |
| 82 | + $this->mFileSize = filesize( $this->mTempPath ); |
| 83 | + |
| 84 | + return $status; |
69 | 85 | } |
70 | | - |
| 86 | + |
| 87 | + /** |
| 88 | + * @param $request Object: WebRequest object |
| 89 | + */ |
71 | 90 | static function isValidRequest( $request ){ |
72 | | - if( !$request->getVal('wpUploadFileURL') ) |
| 91 | + if( !$request->getVal( 'wpUploadFileURL' ) ) |
73 | 92 | return false; |
74 | | - //check that is a valid url: |
75 | | - return self::isValidURI( $request->getVal('wpUploadFileURL') ); |
| 93 | + // check that is a valid url: |
| 94 | + return self::isValidURI( $request->getVal( 'wpUploadFileURL' ) ); |
76 | 95 | } |
| 96 | + |
| 97 | + /** |
| 98 | + * Checks that the given URI is a valid one |
| 99 | + * @param $uri Mixed: URI to check for validity |
| 100 | + */ |
77 | 101 | static function isValidURI( $uri ){ |
78 | | - return preg_match('/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/', |
79 | | - $uri, $matches); |
| 102 | + return preg_match( |
| 103 | + '/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/', |
| 104 | + $uri, |
| 105 | + $matches |
| 106 | + ); |
80 | 107 | } |
| 108 | + |
81 | 109 | } |
\ No newline at end of file |
Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -40,6 +40,7 @@ |
41 | 41 | } |
42 | 42 | return true; |
43 | 43 | } |
| 44 | + |
44 | 45 | /** |
45 | 46 | * Returns true if the user can use this upload module or else a string |
46 | 47 | * identifying the missing permission. |
— | — | @@ -53,6 +54,7 @@ |
54 | 55 | |
55 | 56 | // Upload handlers. Should probably just be a global |
56 | 57 | static $uploadHandlers = array( 'Stash', 'File', 'Url' ); |
| 58 | + |
57 | 59 | /** |
58 | 60 | * Create a form of UploadBase depending on wpSourceType and initializes it |
59 | 61 | */ |
— | — | @@ -62,16 +64,15 @@ |
63 | 65 | if( !$type ) |
64 | 66 | return null; |
65 | 67 | |
66 | | - $type = ucfirst($type); |
67 | | - $className = 'UploadFrom'.$type; |
68 | | - wfDebug( __METHOD__.": class name: $className"); |
| 68 | + $type = ucfirst( $type ); |
| 69 | + $className = 'UploadFrom' . $type; |
| 70 | + wfDebug( __METHOD__ . ": class name: $className" ); |
69 | 71 | if( !in_array( $type, self::$uploadHandlers ) ) |
70 | 72 | return null; |
71 | 73 | |
72 | 74 | if( !call_user_func( array( $className, 'isEnabled' ) ) ) |
73 | 75 | return null; |
74 | 76 | |
75 | | - |
76 | 77 | if( !call_user_func( array( $className, 'isValidRequest' ), $request ) ) |
77 | 78 | return null; |
78 | 79 | |
— | — | @@ -80,6 +81,7 @@ |
81 | 82 | $handler->initializeFromRequest( $request ); |
82 | 83 | return $handler; |
83 | 84 | } |
| 85 | + |
84 | 86 | /** |
85 | 87 | * Check whether a request if valid for this handler |
86 | 88 | */ |
— | — | @@ -105,10 +107,14 @@ |
106 | 108 | function fetchFile() { |
107 | 109 | return Status::newGood(); |
108 | 110 | } |
109 | | - //return the file size |
| 111 | + |
| 112 | + /** |
| 113 | + * Return the file size |
| 114 | + */ |
110 | 115 | function isEmptyFile(){ |
111 | | - return empty( $this->mFileSize); |
| 116 | + return empty( $this->mFileSize ); |
112 | 117 | } |
| 118 | + |
113 | 119 | /** |
114 | 120 | * Verify whether the upload is sane. |
115 | 121 | * Returns self::OK or else an array with error information |
— | — | @@ -117,7 +123,6 @@ |
118 | 124 | /** |
119 | 125 | * If there was no filename or a zero size given, give up quick. |
120 | 126 | */ |
121 | | - |
122 | 127 | if( $this->isEmptyFile() ) |
123 | 128 | return array( 'status' => self::EMPTY_FILE ); |
124 | 129 | |
— | — | @@ -173,7 +178,7 @@ |
174 | 179 | */ |
175 | 180 | protected function verifyFile( $tmpfile ) { |
176 | 181 | $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension ); |
177 | | - $this->checkMacBinary( ); |
| 182 | + $this->checkMacBinary(); |
178 | 183 | |
179 | 184 | #magically determine mime type |
180 | 185 | $magic = MimeMagic::singleton(); |
— | — | @@ -181,7 +186,7 @@ |
182 | 187 | |
183 | 188 | #check mime type, if desired |
184 | 189 | global $wgVerifyMimeType; |
185 | | - if( isset($wgMimeTypeBlacklist) && !is_null($wgMimeTypeBlacklist) ) { |
| 190 | + if( isset( $wgMimeTypeBlacklist ) && !is_null( $wgMimeTypeBlacklist ) ) { |
186 | 191 | if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) |
187 | 192 | return array( 'filetype-badmime', $mime ); |
188 | 193 | |
— | — | @@ -198,9 +203,8 @@ |
199 | 204 | } |
200 | 205 | } |
201 | 206 | |
202 | | - |
203 | 207 | #check for htmlish code and javascript |
204 | | - if( $this->detectScript ( $tmpfile, $mime, $this->mFinalExtension ) ) { |
| 208 | + if( $this->detectScript( $tmpfile, $mime, $this->mFinalExtension ) ) { |
205 | 209 | return 'uploadscripted'; |
206 | 210 | } |
207 | 211 | if( $this->mFinalExtension == 'svg' || $mime == 'image/svg+xml' ) { |
— | — | @@ -212,11 +216,11 @@ |
213 | 217 | /** |
214 | 218 | * Scan the uploaded file for viruses |
215 | 219 | */ |
216 | | - $virus = $this->detectVirus($tmpfile); |
| 220 | + $virus = $this->detectVirus( $tmpfile ); |
217 | 221 | if ( $virus ) { |
218 | 222 | return array( 'uploadvirus', $virus ); |
219 | 223 | } |
220 | | - wfDebug( __METHOD__.": all clear; passing.\n" ); |
| 224 | + wfDebug( __METHOD__ . ": all clear; passing.\n" ); |
221 | 225 | return true; |
222 | 226 | } |
223 | 227 | |
— | — | @@ -255,7 +259,7 @@ |
256 | 260 | /* |
257 | 261 | * Check whether the resulting filename is different from the desired one, |
258 | 262 | * but ignore things like ucfirst() and spaces/underscore things |
259 | | - **/ |
| 263 | + */ |
260 | 264 | $comparableName = str_replace( ' ', '_', $this->mDesiredDestName ); |
261 | 265 | global $wgCapitalLinks, $wgContLang; |
262 | 266 | if ( $wgCapitalLinks ) { |
— | — | @@ -288,7 +292,7 @@ |
289 | 293 | && self::isThumbName( $this->mLocalFile->getName() ) ){ |
290 | 294 | //make the title: |
291 | 295 | $nt = $this->getTitle(); |
292 | | - $warning['file-thumbnail-no'] = substr( $filename , 0, |
| 296 | + $warning['file-thumbnail-no'] = substr( $filename, 0, |
293 | 297 | strpos( $nt->getText() , '-' ) +1 ); |
294 | 298 | } |
295 | 299 | |
— | — | @@ -329,7 +333,7 @@ |
330 | 334 | * Really perform the upload. |
331 | 335 | */ |
332 | 336 | function performUpload( $comment, $pageText, $watch, $user ) { |
333 | | - wfDebug("\n\n\performUpload: sum:" . $comment . ' c: ' . $pageText . ' w:' .$watch); |
| 337 | + wfDebug( "\n\n\performUpload: sum:" . $comment . ' c: ' . $pageText . ' w:' . $watch ); |
334 | 338 | $status = $this->mLocalFile->upload( $this->mTempPath, $comment, $pageText, |
335 | 339 | File::DELETE_SOURCE, $this->mFileProps, false, $user ); |
336 | 340 | |
— | — | @@ -354,7 +358,6 @@ |
355 | 359 | * filter out illegal characters, and try to make a legible name |
356 | 360 | * out of it. We'll strip some silently that Title would die on. |
357 | 361 | */ |
358 | | - |
359 | 362 | $basename = $this->mDesiredDestName; |
360 | 363 | |
361 | 364 | $this->mFilteredName = wfStripIllegalFilenameChars( $basename ); |
— | — | @@ -436,10 +439,11 @@ |
437 | 440 | $status = $repo->storeTemp( $saveName, $tempName ); |
438 | 441 | return $status; |
439 | 442 | } |
| 443 | + |
440 | 444 | /* append to a stashed file */ |
441 | | - function appendToUploadFile($srcPath, $toAppendPath ){ |
| 445 | + function appendToUploadFile( $srcPath, $toAppendPath ){ |
442 | 446 | $repo = RepoGroup::singleton()->getLocalRepo(); |
443 | | - $status = $repo->append($srcPath, $toAppendPath); |
| 447 | + $status = $repo->append( $srcPath, $toAppendPath ); |
444 | 448 | return $status; |
445 | 449 | } |
446 | 450 | |
— | — | @@ -459,19 +463,22 @@ |
460 | 464 | return false; |
461 | 465 | } |
462 | 466 | $mTempPath = $status->value; |
463 | | - session_start();//start up the session (might have been previously closed to prevent php session locking) |
464 | | - $key = $this->getSessionKey (); |
| 467 | + session_start(); // start up the session (might have been previously closed to prevent php session locking) |
| 468 | + $key = $this->getSessionKey(); |
465 | 469 | $_SESSION['wsUploadData'][$key] = array( |
466 | 470 | 'mTempPath' => $mTempPath, |
467 | 471 | 'mFileSize' => $this->mFileSize, |
468 | 472 | 'mSrcName' => $this->mSrcName, |
469 | 473 | 'mFileProps' => $this->mFileProps, |
470 | 474 | 'version' => self::SESSION_VERSION, |
471 | | - ); |
472 | | - session_write_close(); |
| 475 | + ); |
| 476 | + session_write_close(); |
473 | 477 | return $key; |
474 | 478 | } |
475 | | - //pull session Key gen from stash in cases where we want to start an upload without much information |
| 479 | + |
| 480 | + /** |
| 481 | + * Pull session key gen from stash in cases where we want to start an upload without much information |
| 482 | + */ |
476 | 483 | function getSessionKey(){ |
477 | 484 | $key = mt_rand( 0, 0x7fffffff ); |
478 | 485 | $_SESSION['wsUploadData'][$key] = array(); |
— | — | @@ -495,7 +502,7 @@ |
496 | 503 | */ |
497 | 504 | function cleanupTempFile() { |
498 | 505 | if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) { |
499 | | - wfDebug( __METHOD__.": Removing temporary file {$this->mTempPath}\n" ); |
| 506 | + wfDebug( __METHOD__ . ": Removing temporary file {$this->mTempPath}\n" ); |
500 | 507 | unlink( $this->mTempPath ); |
501 | 508 | } |
502 | 509 | } |
— | — | @@ -504,8 +511,7 @@ |
505 | 512 | return $this->mTempPath; |
506 | 513 | } |
507 | 514 | |
508 | | - |
509 | | - /** |
| 515 | + /** |
510 | 516 | * Split a file into a base name and all dot-delimited 'extensions' |
511 | 517 | * on the end. Some web server configurations will fall back to |
512 | 518 | * earlier pseudo-'extensions' to determine type and execute |
— | — | @@ -548,7 +554,6 @@ |
549 | 555 | return false; |
550 | 556 | } |
551 | 557 | |
552 | | - |
553 | 558 | /** |
554 | 559 | * Checks if the mime type of the uploaded file matches the file extension. |
555 | 560 | * |
— | — | @@ -559,30 +564,30 @@ |
560 | 565 | public static function verifyExtension( $mime, $extension ) { |
561 | 566 | $magic = MimeMagic::singleton(); |
562 | 567 | |
563 | | - if ( ! $mime || $mime == 'unknown' || $mime == 'unknown/unknown' ) |
564 | | - if ( ! $magic->isRecognizableExtension( $extension ) ) { |
565 | | - wfDebug( __METHOD__.": passing file with unknown detected mime type; " . |
| 568 | + if ( !$mime || $mime == 'unknown' || $mime == 'unknown/unknown' ) |
| 569 | + if ( !$magic->isRecognizableExtension( $extension ) ) { |
| 570 | + wfDebug( __METHOD__ . ": passing file with unknown detected mime type; " . |
566 | 571 | "unrecognized extension '$extension', can't verify\n" ); |
567 | 572 | return true; |
568 | 573 | } else { |
569 | | - wfDebug( __METHOD__.": rejecting file with unknown detected mime type; ". |
| 574 | + wfDebug( __METHOD__ . ": rejecting file with unknown detected mime type; ". |
570 | 575 | "recognized extension '$extension', so probably invalid file\n" ); |
571 | 576 | return false; |
572 | 577 | } |
573 | 578 | |
574 | | - $match= $magic->isMatchingExtension($extension,$mime); |
| 579 | + $match = $magic->isMatchingExtension( $extension, $mime ); |
575 | 580 | |
576 | | - if ($match===NULL) { |
577 | | - wfDebug( __METHOD__.": no file extension known for mime type $mime, passing file\n" ); |
| 581 | + if ( $match === NULL ) { |
| 582 | + wfDebug( __METHOD__ . ": no file extension known for mime type $mime, passing file\n" ); |
578 | 583 | return true; |
579 | | - } elseif ($match===true) { |
580 | | - wfDebug( __METHOD__.": mime type $mime matches extension $extension, passing file\n" ); |
| 584 | + } elseif( $match === true ) { |
| 585 | + wfDebug( __METHOD__ . ": mime type $mime matches extension $extension, passing file\n" ); |
581 | 586 | |
582 | 587 | #TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it! |
583 | 588 | return true; |
584 | 589 | |
585 | 590 | } else { |
586 | | - wfDebug( __METHOD__.": mime type $mime mismatches file extension $extension, rejecting file\n" ); |
| 591 | + wfDebug( __METHOD__ . ": mime type $mime mismatches file extension $extension, rejecting file\n" ); |
587 | 592 | return false; |
588 | 593 | } |
589 | 594 | } |
— | — | @@ -597,38 +602,44 @@ |
598 | 603 | * @param string $extension The extension of the file |
599 | 604 | * @return bool true if the file contains something looking like embedded scripts |
600 | 605 | */ |
601 | | - function detectScript($file, $mime, $extension) { |
| 606 | + function detectScript( $file, $mime, $extension ) { |
602 | 607 | global $wgAllowTitlesInSVG; |
603 | 608 | |
604 | 609 | #ugly hack: for text files, always look at the entire file. |
605 | 610 | #For binary field, just check the first K. |
606 | 611 | |
607 | | - if (strpos($mime,'text/')===0) $chunk = file_get_contents( $file ); |
| 612 | + if( strpos( $mime,'text/' ) === 0 ) |
| 613 | + $chunk = file_get_contents( $file ); |
608 | 614 | else { |
609 | 615 | $fp = fopen( $file, 'rb' ); |
610 | 616 | $chunk = fread( $fp, 1024 ); |
611 | 617 | fclose( $fp ); |
612 | 618 | } |
613 | 619 | |
614 | | - $chunk= strtolower( $chunk ); |
| 620 | + $chunk = strtolower( $chunk ); |
615 | 621 | |
616 | | - if (!$chunk) return false; |
| 622 | + if( !$chunk ) |
| 623 | + return false; |
617 | 624 | |
618 | 625 | #decode from UTF-16 if needed (could be used for obfuscation). |
619 | | - if (substr($chunk,0,2)=="\xfe\xff") $enc= "UTF-16BE"; |
620 | | - elseif (substr($chunk,0,2)=="\xff\xfe") $enc= "UTF-16LE"; |
621 | | - else $enc= NULL; |
| 626 | + if( substr( $chunk, 0, 2 ) == "\xfe\xff" ) |
| 627 | + $enc = "UTF-16BE"; |
| 628 | + elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) |
| 629 | + $enc = "UTF-16LE"; |
| 630 | + else |
| 631 | + $enc = NULL; |
622 | 632 | |
623 | | - if ($enc) $chunk= iconv($enc,"ASCII//IGNORE",$chunk); |
| 633 | + if( $enc ) |
| 634 | + $chunk = iconv( $enc, "ASCII//IGNORE", $chunk ); |
624 | 635 | |
625 | | - $chunk= trim($chunk); |
| 636 | + $chunk = trim( $chunk ); |
626 | 637 | |
627 | 638 | #FIXME: convert from UTF-16 if necessarry! |
| 639 | + wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n" ); |
628 | 640 | |
629 | | - wfDebug("SpecialUpload::detectScript: checking for embedded scripts and HTML stuff\n"); |
630 | | - |
631 | 641 | #check for HTML doctype |
632 | | - if (eregi("<!DOCTYPE *X?HTML",$chunk)) return true; |
| 642 | + if( eregi( "<!DOCTYPE *X?HTML", $chunk ) ) |
| 643 | + return true; |
633 | 644 | |
634 | 645 | /** |
635 | 646 | * Internet Explorer for Windows performs some really stupid file type |
— | — | @@ -645,7 +656,6 @@ |
646 | 657 | * Also returns true if Safari would mistake the given file for HTML |
647 | 658 | * when served with a generic content-type. |
648 | 659 | */ |
649 | | - |
650 | 660 | $tags = array( |
651 | 661 | '<a', |
652 | 662 | '<body', |
— | — | @@ -655,8 +665,9 @@ |
656 | 666 | '<pre', |
657 | 667 | '<script', #also in safari |
658 | 668 | '<table' |
659 | | - ); |
660 | | - if( ! $wgAllowTitlesInSVG && $extension !== 'svg' && $mime !== 'image/svg' ) { |
| 669 | + ); |
| 670 | + |
| 671 | + if( !$wgAllowTitlesInSVG && $extension !== 'svg' && $mime !== 'image/svg' ) { |
661 | 672 | $tags[] = '<title'; |
662 | 673 | } |
663 | 674 | |
— | — | @@ -667,22 +678,25 @@ |
668 | 679 | } |
669 | 680 | |
670 | 681 | /* |
671 | | - * look for javascript |
672 | | - */ |
| 682 | + * look for JavaScript |
| 683 | + */ |
673 | 684 | |
674 | 685 | #resolve entity-refs to look at attributes. may be harsh on big files... cache result? |
675 | 686 | $chunk = Sanitizer::decodeCharReferences( $chunk ); |
676 | 687 | |
677 | 688 | #look for script-types |
678 | | - if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim',$chunk)) return true; |
| 689 | + if( preg_match( '!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) ) |
| 690 | + return true; |
679 | 691 | |
680 | 692 | #look for html-style script-urls |
681 | | - if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true; |
| 693 | + if( preg_match( '!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) |
| 694 | + return true; |
682 | 695 | |
683 | 696 | #look for css-style script-urls |
684 | | - if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true; |
| 697 | + if( preg_match( '!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) |
| 698 | + return true; |
685 | 699 | |
686 | | - wfDebug("SpecialUpload::detectScript: no scripts found\n"); |
| 700 | + wfDebug( __METHOD__ . ": no scripts found\n" ); |
687 | 701 | return false; |
688 | 702 | } |
689 | 703 | |
— | — | @@ -721,8 +735,6 @@ |
722 | 736 | return array_pop( $parts ); |
723 | 737 | } |
724 | 738 | |
725 | | - |
726 | | - |
727 | 739 | /** |
728 | 740 | * Generic wrapper function for a virus scanner program. |
729 | 741 | * This relies on the $wgAntivirus and $wgAntivirusSetup variables. |
— | — | @@ -733,18 +745,18 @@ |
734 | 746 | * or a string containing feedback from the virus scanner if a virus was found. |
735 | 747 | * If textual feedback is missing but a virus was found, this function returns true. |
736 | 748 | */ |
737 | | - function detectVirus($file) { |
| 749 | + function detectVirus( $file ) { |
738 | 750 | global $wgAntivirus, $wgAntivirusSetup, $wgAntivirusRequired, $wgOut; |
739 | 751 | |
740 | 752 | if ( !$wgAntivirus ) { |
741 | | - wfDebug( __METHOD__.": virus scanner disabled\n"); |
| 753 | + wfDebug( __METHOD__ . ": virus scanner disabled\n" ); |
742 | 754 | return NULL; |
743 | 755 | } |
744 | 756 | |
745 | 757 | if ( !$wgAntivirusSetup[$wgAntivirus] ) { |
746 | | - wfDebug( __METHOD__.": unknown virus scanner: $wgAntivirus\n" ); |
| 758 | + wfDebug( __METHOD__ . ": unknown virus scanner: $wgAntivirus\n" ); |
747 | 759 | $wgOut->wrapWikiMsg( '<div class="error">$1</div>', array( 'virus-badscanner', $wgAntivirus ) ); |
748 | | - return wfMsg('virus-unknownscanner') . " $wgAntivirus"; |
| 760 | + return wfMsg( 'virus-unknownscanner' ) . " $wgAntivirus"; |
749 | 761 | } |
750 | 762 | |
751 | 763 | # look up scanner configuration |
— | — | @@ -761,7 +773,7 @@ |
762 | 774 | $command = str_replace( "%f", wfEscapeShellArg( $file ), $command ); |
763 | 775 | } |
764 | 776 | |
765 | | - wfDebug( __METHOD__.": running virus scan: $command \n" ); |
| 777 | + wfDebug( __METHOD__ . ": running virus scan: $command \n" ); |
766 | 778 | |
767 | 779 | # execute virus scanner |
768 | 780 | $exitCode = false; |
— | — | @@ -788,20 +800,20 @@ |
789 | 801 | |
790 | 802 | if ( $mappedCode === AV_SCAN_FAILED ) { |
791 | 803 | # scan failed (code was mapped to false by $exitCodeMap) |
792 | | - wfDebug( __METHOD__.": failed to scan $file (code $exitCode).\n" ); |
| 804 | + wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" ); |
793 | 805 | |
794 | 806 | if ( $wgAntivirusRequired ) { |
795 | | - return wfMsg('virus-scanfailed', array( $exitCode ) ); |
| 807 | + return wfMsg( 'virus-scanfailed', array( $exitCode ) ); |
796 | 808 | } else { |
797 | 809 | return NULL; |
798 | 810 | } |
799 | 811 | } else if ( $mappedCode === AV_SCAN_ABORTED ) { |
800 | 812 | # scan failed because filetype is unknown (probably imune) |
801 | | - wfDebug( __METHOD__.": unsupported file type $file (code $exitCode).\n" ); |
| 813 | + wfDebug( __METHOD__ . ": unsupported file type $file (code $exitCode).\n" ); |
802 | 814 | return NULL; |
803 | 815 | } else if ( $mappedCode === AV_NO_VIRUS ) { |
804 | 816 | # no virus found |
805 | | - wfDebug( __METHOD__.": file passed virus scan.\n" ); |
| 817 | + wfDebug( __METHOD__ . ": file passed virus scan.\n" ); |
806 | 818 | return false; |
807 | 819 | } else { |
808 | 820 | $output = join( "\n", $output ); |
— | — | @@ -818,7 +830,7 @@ |
819 | 831 | } |
820 | 832 | } |
821 | 833 | |
822 | | - wfDebug( __METHOD__.": FOUND VIRUS! scanner feedback: $output \n" ); |
| 834 | + wfDebug( __METHOD__ . ": FOUND VIRUS! scanner feedback: $output \n" ); |
823 | 835 | return $output; |
824 | 836 | } |
825 | 837 | } |
— | — | @@ -834,10 +846,10 @@ |
835 | 847 | function checkMacBinary() { |
836 | 848 | $macbin = new MacBinary( $this->mTempPath ); |
837 | 849 | if( $macbin->isValid() ) { |
838 | | - $dataFile = tempnam( wfTempDir(), "WikiMacBinary" ); |
| 850 | + $dataFile = tempnam( wfTempDir(), 'WikiMacBinary' ); |
839 | 851 | $dataHandle = fopen( $dataFile, 'wb' ); |
840 | 852 | |
841 | | - wfDebug( "SpecialUpload::checkMacBinary: Extracting MacBinary data fork to $dataFile\n" ); |
| 853 | + wfDebug( __METHOD__ . ": Extracting MacBinary data fork to $dataFile\n" ); |
842 | 854 | $macbin->extractData( $dataHandle ); |
843 | 855 | |
844 | 856 | $this->mTempPath = $dataFile; |
— | — | @@ -870,8 +882,8 @@ |
871 | 883 | return 'fileexists-shared-forbidden'; |
872 | 884 | |
873 | 885 | return true; |
| 886 | + } |
874 | 887 | |
875 | | - } |
876 | 888 | /** |
877 | 889 | * Check if a user is the last uploader |
878 | 890 | * |
— | — | @@ -969,5 +981,4 @@ |
970 | 982 | return $blacklist; |
971 | 983 | } |
972 | 984 | |
973 | | - |
974 | 985 | } |
Index: trunk/phase3/includes/upload/UploadFromChunks.php |
— | — | @@ -1,13 +1,13 @@ |
2 | 2 | <?php |
3 | | -/* |
4 | | -* first destination checks are made (if ignorewarnings is not checked) errors / warning is returned. |
5 | | -* |
6 | | -* we return the uploadUrl |
7 | | -* we then accept chunk uploads from the client. |
8 | | -* return chunk id on each POSTED chunk |
9 | | -* once the client posts done=1 concatenated the files together. |
10 | | -* more info at: http://firefogg.org/dev/chunk_post.html |
11 | | -*/ |
| 3 | +/** |
| 4 | + * first destination checks are made (if ignorewarnings is not checked) errors / warning is returned. |
| 5 | + * |
| 6 | + * we return the uploadUrl |
| 7 | + * we then accept chunk uploads from the client. |
| 8 | + * return chunk id on each POSTED chunk |
| 9 | + * once the client posts done=1 concatenated the files together. |
| 10 | + * more info at: http://firefogg.org/dev/chunk_post.html |
| 11 | + */ |
12 | 12 | class UploadFromChunks extends UploadBase { |
13 | 13 | |
14 | 14 | var $chunk_mode; //init, chunk, done |
— | — | @@ -18,24 +18,23 @@ |
19 | 19 | const CHUNK = 2; |
20 | 20 | const DONE = 3; |
21 | 21 | |
22 | | - function initializeFromParams( $param , &$request) { |
| 22 | + function initializeFromParams( $param, &$request ) { |
23 | 23 | $this->initFromSessionKey( $param['chunksessionkey'], $request ); |
24 | | - //set the chunk mode: |
| 24 | + // set the chunk mode: |
25 | 25 | if( !$this->mSessionKey && !$param['done'] ){ |
26 | | - //session key not set init the chunk upload system: |
| 26 | + // session key not set init the chunk upload system: |
27 | 27 | $this->chunk_mode = UploadFromChunks::INIT; |
28 | 28 | $this->mDesiredDestName = $param['filename']; |
29 | | - |
30 | | - }else if( $this->mSessionKey && !$param['done']){ |
31 | | - //this is a chunk piece |
| 29 | + } else if( $this->mSessionKey && !$param['done'] ){ |
| 30 | + // this is a chunk piece |
32 | 31 | $this->chunk_mode = UploadFromChunks::CHUNK; |
33 | | - }else if( $this->mSessionKey && $param['done']){ |
34 | | - //this is the last chunk |
| 32 | + } else if( $this->mSessionKey && $param['done'] ){ |
| 33 | + // this is the last chunk |
35 | 34 | $this->chunk_mode = UploadFromChunks::DONE; |
36 | 35 | } |
37 | 36 | if( $this->chunk_mode == UploadFromChunks::CHUNK || |
38 | | - $this->chunk_mode == UploadFromChunks::DONE ){ |
39 | | - //set chunk related vars: |
| 37 | + $this->chunk_mode == UploadFromChunks::DONE ){ |
| 38 | + // set chunk related vars: |
40 | 39 | $this->mTempPath = $request->getFileTempName( 'chunk' ); |
41 | 40 | $this->mFileSize = $request->getFileSize( 'chunk' ); |
42 | 41 | } |
— | — | @@ -44,188 +43,197 @@ |
45 | 44 | } |
46 | 45 | |
47 | 46 | static function isValidRequest( $request ) { |
48 | | - $sessionData = $request->getSessionData('wsUploadData'); |
49 | | - if(! self::isValidSessionKey( |
| 47 | + $sessionData = $request->getSessionData( 'wsUploadData' ); |
| 48 | + if( !self::isValidSessionKey( |
50 | 49 | $request->getInt( 'wpSessionKey' ), |
51 | | - $sessionData) ) |
| 50 | + $sessionData ) ) |
52 | 51 | return false; |
53 | | - //check for the file: |
| 52 | + // check for the file: |
54 | 53 | return (bool)$request->getFileTempName( 'file' ); |
55 | 54 | } |
56 | 55 | |
57 | | - /* check warnings depending on chunk_mode*/ |
| 56 | + /* check warnings depending on chunk_mode */ |
58 | 57 | function checkWarnings(){ |
59 | 58 | $warning = array(); |
60 | 59 | return $warning; |
61 | 60 | } |
62 | 61 | |
63 | 62 | function isEmptyFile(){ |
64 | | - //does not apply to chunk init |
65 | | - if( $this->chunk_mode == UploadFromChunks::INIT ){ |
| 63 | + // does not apply to chunk init |
| 64 | + if( $this->chunk_mode == UploadFromChunks::INIT ){ |
66 | 65 | return false; |
67 | | - }else{ |
| 66 | + } else { |
68 | 67 | return parent::isEmptyFile(); |
69 | 68 | } |
70 | 69 | } |
71 | | - /* Verify whether the upload is sane. |
| 70 | + |
| 71 | + /** |
| 72 | + * Verify whether the upload is sane. |
72 | 73 | * Returns self::OK or else an array with error information |
73 | 74 | */ |
74 | 75 | function verifyUpload( $resultDetails ) { |
75 | | - //no checks on chunk upload mode: |
| 76 | + // no checks on chunk upload mode: |
76 | 77 | if( $this->chunk_mode == UploadFromChunks::INIT ) |
77 | 78 | return self::OK; |
78 | 79 | |
79 | | - //verify on init and last chunk request |
| 80 | + // verify on init and last chunk request |
80 | 81 | if( $this->chunk_mode == UploadFromChunks::CHUNK || |
81 | 82 | $this->chunk_mode == UploadFromChunks::DONE ) |
82 | 83 | return parent::verifyUpload( $resultDetails ); |
83 | 84 | } |
84 | | - //only run verifyFile on completed uploaded chunks |
| 85 | + |
| 86 | + // only run verifyFile on completed uploaded chunks |
85 | 87 | function verifyFile( $tmpFile ){ |
86 | 88 | if( $this->chunk_mode == UploadFromChunks::DONE ){ |
87 | | - //first append last chunk (so we can do a real verifyFile check... (check file type etc) |
| 89 | + // first append last chunk (so we can do a real verifyFile check... (check file type etc) |
88 | 90 | $status = $this->doChunkAppend(); |
89 | 91 | if( $status->isOK() ){ |
90 | 92 | $this->mTempPath = $this->getRealPath( $this->mTempAppendPath ); |
91 | | - //verify the completed merged chunks as if it was the file that got uploaded: |
92 | | - return parent::verifyFile( $this->mTempPath ) ; |
93 | | - }else{ |
94 | | - //conflict of status returns (have to return the error ary) ... why we don't consistantly use a status object is beyond me.. |
| 93 | + // verify the completed merged chunks as if it was the file that got uploaded: |
| 94 | + return parent::verifyFile( $this->mTempPath ); |
| 95 | + } else { |
| 96 | + // conflict of status returns (have to return the error ary) ... why we don't consistantly use a status object is beyond me.. |
95 | 97 | return $status->getErrorsArray(); |
96 | 98 | } |
97 | | - }else{ |
| 99 | + } else { |
98 | 100 | return true; |
99 | 101 | } |
100 | 102 | } |
101 | | - function getRealPath($srcPath){ |
| 103 | + |
| 104 | + function getRealPath( $srcPath ){ |
102 | 105 | $repo = RepoGroup::singleton()->getLocalRepo(); |
103 | | - if ( $repo->isVirtualUrl( $srcPath) ) { |
| 106 | + if ( $repo->isVirtualUrl( $srcPath ) ) { |
104 | 107 | return $repo->resolveVirtualUrl( $srcPath ); |
105 | 108 | } |
106 | 109 | } |
107 | | - //pretty ugly inter-mixing of mParam and local vars |
| 110 | + |
| 111 | + // pretty ugly inter-mixing of mParam and local vars |
108 | 112 | function setupChunkSession( $summary, $comment, $watch ) { |
109 | 113 | $this->mSessionKey = $this->getSessionKey(); |
110 | | - $_SESSION['wsUploadData'][ $this->mSessionKey ] = array( |
| 114 | + $_SESSION['wsUploadData'][$this->mSessionKey] = array( |
111 | 115 | 'mComment' => $comment, |
112 | 116 | 'mSummary' => $summary, |
113 | 117 | 'mWatch' => $watch, |
114 | 118 | 'mFilteredName' => $this->mFilteredName, |
115 | | - 'mTempAppendPath' => null, //the repo append path (not temporary local node mTempPath) |
| 119 | + 'mTempAppendPath' => null, // the repo append path (not temporary local node mTempPath) |
116 | 120 | 'mDesiredDestName' => $this->mDesiredDestName, |
117 | | - 'version' => self::SESSION_VERSION, |
118 | | - ); |
119 | | - return $this->mSessionKey; |
| 121 | + 'version' => self::SESSION_VERSION, |
| 122 | + ); |
| 123 | + return $this->mSessionKey; |
120 | 124 | } |
121 | | - function initFromSessionKey( $sessionKey, $request ){ |
| 125 | + |
| 126 | + function initFromSessionKey( $sessionKey, $request ){ |
122 | 127 | if( !$sessionKey || empty( $sessionKey ) ){ |
123 | 128 | return false; |
124 | 129 | } |
125 | 130 | $this->mSessionKey = $sessionKey; |
126 | | - //load the sessionData array: |
127 | | - $sessionData = $request->getSessionData('wsUploadData'); |
| 131 | + // load the sessionData array: |
| 132 | + $sessionData = $request->getSessionData( 'wsUploadData' ); |
128 | 133 | |
129 | 134 | if( isset( $sessionData[$this->mSessionKey]['version'] ) && |
130 | 135 | $sessionData[$this->mSessionKey]['version'] == self::SESSION_VERSION ) { |
131 | | - //update the local object from the session // |
132 | | - $this->mComment = $sessionData[ $this->mSessionKey ][ 'mComment' ]; |
133 | | - $this->mSummary = $sessionData[ $this->mSessionKey ][ 'mSummary' ]; |
134 | | - $this->mWatch = $sessionData[ $this->mSessionKey ][ 'mWatch' ]; |
135 | | - $this->mIgnorewarnings = $sessionData[ $this->mSessionKey ][ 'mIgnorewarnings' ]; |
136 | | - $this->mFilteredName = $sessionData[ $this->mSessionKey ][ 'mFilteredName' ]; |
137 | | - $this->mTempAppendPath = $sessionData[ $this->mSessionKey ][ 'mTempAppendPath' ]; |
138 | | - $this->mDesiredDestName = $sessionData[ $this->mSessionKey ][ 'mDesiredDestName' ]; |
139 | | - }else{ |
140 | | - $this->status = Array( 'error'=> 'missing session data'); |
| 136 | + // update the local object from the session |
| 137 | + $this->mComment = $sessionData[$this->mSessionKey]['mComment']; |
| 138 | + $this->mSummary = $sessionData[$this->mSessionKey]['mSummary']; |
| 139 | + $this->mWatch = $sessionData[$this->mSessionKey]['mWatch']; |
| 140 | + $this->mIgnorewarnings = $sessionData[$this->mSessionKey]['mIgnorewarnings']; |
| 141 | + $this->mFilteredName = $sessionData[$this->mSessionKey]['mFilteredName']; |
| 142 | + $this->mTempAppendPath = $sessionData[$this->mSessionKey]['mTempAppendPath']; |
| 143 | + $this->mDesiredDestName = $sessionData[$this->mSessionKey]['mDesiredDestName']; |
| 144 | + } else { |
| 145 | + $this->status = array( 'error' => 'missing session data' ); |
141 | 146 | return false; |
142 | 147 | } |
143 | 148 | } |
144 | | - //lets us return an api result (as flow for chunk uploads is kind of different than others. |
145 | | - function performUpload($summary='', $comment='', $watch='', $user){ |
| 149 | + |
| 150 | + // Lets us return an api result (as flow for chunk uploads is kind of different than others. |
| 151 | + function performUpload( $summary = '', $comment = '', $watch = '', $user ){ |
146 | 152 | global $wgServer, $wgScriptPath, $wgUser; |
| 153 | + |
147 | 154 | if( $this->chunk_mode == UploadFromChunks::INIT ){ |
148 | | - //firefogg expects a specific result per: |
149 | | - //http://www.firefogg.org/dev/chunk_post.html |
| 155 | + // firefogg expects a specific result per: |
| 156 | + // http://www.firefogg.org/dev/chunk_post.html |
150 | 157 | |
151 | | - //its oky to return the token here because |
152 | | - //a) the user must have requested the token to get here and |
153 | | - //b) should only happen over POST |
154 | | - //c) (we need the token to validate chunks are coming from a non-xss request) |
| 158 | + // it's okay to return the token here because |
| 159 | + // a) the user must have requested the token to get here and |
| 160 | + // b) should only happen over POST |
| 161 | + // c) (we need the token to validate chunks are coming from a non-xss request) |
155 | 162 | $token = urlencode( $wgUser->editToken() ); |
156 | 163 | ob_clean(); |
157 | 164 | echo ApiFormatJson::getJsonEncode( array( |
158 | | - "uploadUrl" => "{$wgServer}{$wgScriptPath}/api.php?action=upload&". |
| 165 | + 'uploadUrl' => "{$wgServer}{$wgScriptPath}/api.php?action=upload&". |
159 | 166 | "token={$token}&format=json&enablechunks=true&chunksessionkey=". |
160 | 167 | $this->setupChunkSession($summary, $comment, $watch ) ) ); |
161 | | - exit(0); |
162 | | - }else if( $this->chunk_mode == UploadFromChunks::CHUNK ){ |
| 168 | + exit( 0 ); |
| 169 | + } else if( $this->chunk_mode == UploadFromChunks::CHUNK ){ |
163 | 170 | $status = $this->doChunkAppend(); |
164 | 171 | if( $status->isOK() ){ |
165 | | - //return success: |
166 | | - //firefogg expects a specific result per: |
167 | | - //http://www.firefogg.org/dev/chunk_post.html |
| 172 | + // return success: |
| 173 | + // firefogg expects a specific result per: |
| 174 | + // http://www.firefogg.org/dev/chunk_post.html |
168 | 175 | ob_clean(); |
169 | 176 | echo ApiFormatJson::getJsonEncode( array( |
170 | | - "result"=>1, |
171 | | - "filesize"=> filesize( $this->getRealPath( $this->mTempAppendPath ) ) |
| 177 | + 'result' => 1, |
| 178 | + 'filesize' => filesize( $this->getRealPath( $this->mTempAppendPath ) ) |
172 | 179 | ) |
173 | 180 | ); |
174 | | - exit(0); |
| 181 | + exit( 0 ); |
175 | 182 | /*return array( |
176 | 183 | 'result' => 1 |
177 | 184 | );*/ |
178 | | - }else{ |
| 185 | + } else { |
179 | 186 | return $status; |
180 | 187 | } |
181 | | - }else if( $this->chunk_mode == UploadFromChunks::DONE ){ |
182 | | - //update the values from the local (session init) if not paseed again) |
183 | | - if($summary == '') |
184 | | - $summary = $this->mSummary; |
| 188 | + } else if( $this->chunk_mode == UploadFromChunks::DONE ){ |
| 189 | + // update the values from the local (session init) if not paseed again) |
| 190 | + if( $summary == '' ) |
| 191 | + $summary = $this->mSummary; |
185 | 192 | |
186 | | - if($comment == '') |
187 | | - $comment = $this->mComment; |
| 193 | + if( $comment == '' ) |
| 194 | + $comment = $this->mComment; |
188 | 195 | |
189 | | - if($watch == '') |
190 | | - $watch = $this->mWatch; |
191 | | - $status = parent::performUpload($summary, $comment, $watch, $user ); |
| 196 | + if( $watch == '' ) |
| 197 | + $watch = $this->mWatch; |
| 198 | + $status = parent::performUpload( $summary, $comment, $watch, $user ); |
192 | 199 | if( !$status->isGood() ) { |
193 | 200 | return $status; |
194 | 201 | } |
195 | 202 | $file = $this->getLocalFile(); |
196 | | - //firefogg expects a specific result per: |
197 | | - //http://www.firefogg.org/dev/chunk_post.html |
| 203 | + // firefogg expects a specific result per: |
| 204 | + // http://www.firefogg.org/dev/chunk_post.html |
198 | 205 | ob_clean(); |
199 | 206 | echo ApiFormatJson::getJsonEncode( array( |
200 | | - "result"=>1, |
201 | | - "done"=>1, |
202 | | - "resultUrl"=> $file->getDescriptionUrl() |
| 207 | + 'result' => 1, |
| 208 | + 'done' => 1, |
| 209 | + 'resultUrl' => $file->getDescriptionUrl() |
203 | 210 | ) |
204 | 211 | ); |
205 | | - exit(0); |
| 212 | + exit( 0 ); |
206 | 213 | |
207 | 214 | } |
208 | 215 | } |
209 | | - //append the given chunk to the temporary uploaded file. (if no temporary uploaded file exists created it. |
| 216 | + |
| 217 | + // append the given chunk to the temporary uploaded file. (if no temporary uploaded file exists created it. |
210 | 218 | function doChunkAppend(){ |
211 | | - //if we don't have a mTempAppendPath to generate a file from the chunk packaged var: |
212 | | - if( ! $this->mTempAppendPath ){ |
213 | | - //die(); |
214 | | - //get temp name: |
215 | | - //make a chunk store path. (append tmp file to chunk) |
| 219 | + // if we don't have a mTempAppendPath to generate a file from the chunk packaged var: |
| 220 | + if( !$this->mTempAppendPath ){ |
| 221 | + // get temp name: |
| 222 | + // make a chunk store path. (append tmp file to chunk) |
216 | 223 | $status = $this->saveTempUploadedFile( $this->mDestName, $this->mTempPath ); |
217 | 224 | |
218 | 225 | if( $status->isOK() ) { |
219 | 226 | $this->mTempAppendPath = $status->value; |
220 | | - $_SESSION[ 'wsUploadData' ][ $this->mSessionKey ][ 'mTempAppendPath' ] = $this->mTempAppendPath; |
| 227 | + $_SESSION['wsUploadData'][$this->mSessionKey]['mTempAppendPath'] = $this->mTempAppendPath; |
221 | 228 | } |
222 | 229 | return $status; |
223 | | - }else{ |
| 230 | + } else { |
224 | 231 | if( is_file( $this->getRealPath( $this->mTempAppendPath ) ) ){ |
225 | | - $status = $this->appendToUploadFile( $this->mTempAppendPath, $this->mTempPath ); |
226 | | - }else{ |
| 232 | + $status = $this->appendToUploadFile( $this->mTempAppendPath, $this->mTempPath ); |
| 233 | + } else { |
227 | 234 | $status->fatal( 'filenotfound', $this->mTempAppendPath ); |
228 | 235 | } |
229 | 236 | return $status; |
230 | 237 | } |
231 | 238 | } |
| 239 | + |
232 | 240 | } |