Index: trunk/phase3/includes/upload/UploadFromChunks.php |
— | — | @@ -42,13 +42,10 @@ |
43 | 43 | throw new MWException( 'not implemented' ); |
44 | 44 | } |
45 | 45 | |
46 | | - public function initialize( &$request ) { |
47 | | - $done = $request->getText( 'done' ); |
48 | | - $filename = $request->getText( 'filename' ); |
49 | | - $sessionKey = $request->getText( 'chunksessionkey' ); |
| 46 | + public function initialize( $done, $filename, $sessionKey, $path, |
| 47 | + $fileSize, $sessionData ) { |
| 48 | + $this->initFromSessionKey( $sessionKey, $sessionData ); |
50 | 49 | |
51 | | - $this->initFromSessionKey( $sessionKey, $request ); |
52 | | - |
53 | 50 | if ( !$this->sessionKey && !$done ) { |
54 | 51 | // session key not set, init the chunk upload system: |
55 | 52 | $this->chunkMode = self::INIT; |
— | — | @@ -60,8 +57,8 @@ |
61 | 58 | } |
62 | 59 | |
63 | 60 | if ( $this->chunkMode == self::CHUNK || $this->chunkMode == self::DONE ) { |
64 | | - $this->mTempPath = $request->getFileTempName( 'chunk' ); |
65 | | - $this->fileSize += $request->getFileSize( 'chunk' ); |
| 61 | + $this->mTempPath = $path; |
| 62 | + $this->fileSize += $fileSize; |
66 | 63 | } |
67 | 64 | } |
68 | 65 | |
— | — | @@ -94,14 +91,12 @@ |
95 | 92 | * |
96 | 93 | * @returns void |
97 | 94 | */ |
98 | | - protected function initFromSessionKey( $sessionKey, $request ) { |
| 95 | + protected function initFromSessionKey( $sessionKey, $sessionData ) { |
99 | 96 | if ( !$sessionKey || empty( $sessionKey ) ) { |
100 | 97 | $this->status = Status::newFromFatal( 'Missing session data.' ); |
101 | 98 | return; |
102 | 99 | } |
103 | 100 | $this->sessionKey = $sessionKey; |
104 | | - // load the sessionData array: |
105 | | - $sessionData = $request->getSessionData( 'wsUploadData' ); |
106 | 101 | |
107 | 102 | if ( isset( $sessionData[$this->sessionKey]['version'] ) |
108 | 103 | && $sessionData[$this->sessionKey]['version'] == self::SESSION_VERSION ) { |
— | — | @@ -124,7 +119,7 @@ |
125 | 120 | */ |
126 | 121 | public function performUpload( $comment, $pageText, $watch, $user ) { |
127 | 122 | wfDebug( "\n\n\performUpload(chunked): sum:" . $comment . ' c: ' . $pageText . ' w:' . $watch ); |
128 | | - global $wgUser; |
| 123 | + global $wgUser, $wgOut; |
129 | 124 | |
130 | 125 | if ( $this->chunkMode == self::INIT ) { |
131 | 126 | // firefogg expects a specific result per: |
— | — | @@ -140,7 +135,7 @@ |
141 | 136 | 'uploadUrl' => wfExpandUrl( wfScript( 'api' ) ) . "?action=upload&" . |
142 | 137 | "token={$token}&format=json&enablechunks=true&chunksessionkey=" . |
143 | 138 | $this->setupChunkSession( $comment, $pageText, $watch ) ) ); |
144 | | - exit( 0 ); |
| 139 | + $wgOut->disable(); |
145 | 140 | } else if ( $this->chunkMode == self::CHUNK ) { |
146 | 141 | $status = $this->appendChunk(); |
147 | 142 | if ( !$status->isOK() ) { |
— | — | @@ -153,7 +148,7 @@ |
154 | 149 | echo FormatJson::encode( |
155 | 150 | array( 'result' => 1, 'filesize' => $this->fileSize ) |
156 | 151 | ); |
157 | | - exit( 0 ); |
| 152 | + $wgOut->disable(); |
158 | 153 | } else if ( $this->chunkMode == self::DONE ) { |
159 | 154 | if ( $comment == '' ) |
160 | 155 | $comment = $this->comment; |
— | — | @@ -178,7 +173,7 @@ |
179 | 174 | 'done' => 1, |
180 | 175 | 'resultUrl' => $file->getDescriptionUrl() ) |
181 | 176 | ); |
182 | | - exit( 0 ); |
| 177 | + $wgOut->disable(); |
183 | 178 | } |
184 | 179 | } |
185 | 180 | |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -84,7 +84,13 @@ |
85 | 85 | // Initialize $this->mUpload |
86 | 86 | if ( $this->mParams['enablechunks'] ) { |
87 | 87 | $this->mUpload = new UploadFromChunks(); |
88 | | - $this->mUpload->initialize( $request ); |
| 88 | + $this->mUpload->initialize |
| 89 | + ( $request->getText( 'done' ), |
| 90 | + $request->getText( 'filename' ), |
| 91 | + $request->getText( 'chunksessionkey' ), |
| 92 | + $request->getFileTempName( 'chunk' ), |
| 93 | + $request->getFileSize( 'chunk' ), |
| 94 | + $request->getSessionData( 'wsUploadData' ) ); |
89 | 95 | |
90 | 96 | if ( !$this->mUpload->status->isOK() ) { |
91 | 97 | return $this->dieUsageMsg( $this->mUpload->status->getWikiText(), |
— | — | @@ -278,7 +284,7 @@ |
279 | 285 | 'watch' => false, |
280 | 286 | 'ignorewarnings' => false, |
281 | 287 | 'file' => null, |
282 | | - 'enablechunks' => null, |
| 288 | + 'enablechunks' => false, |
283 | 289 | 'chunksessionkey' => null, |
284 | 290 | 'chunk' => null, |
285 | 291 | 'done' => false, |
— | — | @@ -302,6 +308,9 @@ |
303 | 309 | 'ignorewarnings' => 'Ignore any warnings', |
304 | 310 | 'file' => 'File contents', |
305 | 311 | 'enablechunks' => 'Set to use chunk mode; see http://firefogg.org/dev/chunk_post.html for protocol', |
| 312 | + 'chunksessionkey' => 'The session key, established on the first contact during the chunked upload', |
| 313 | + 'chunk' => 'The data in this chunk of a chunked upload', |
| 314 | + 'done' => 'Set to 1 on the last chunk of a chunked upload', |
306 | 315 | 'url' => 'Url to fetch the file from', |
307 | 316 | 'sessionkey' => array( |
308 | 317 | 'Session key returned by a previous upload that failed due to warnings', |