Index: trunk/phase3/includes/api/ApiFormatBase.php |
— | — | @@ -36,6 +36,7 @@ |
37 | 37 | abstract class ApiFormatBase extends ApiBase { |
38 | 38 | |
39 | 39 | private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared; |
| 40 | + private $mBufferResult = false, $mBuffer; |
40 | 41 | |
41 | 42 | /** |
42 | 43 | * Constructor |
— | — | @@ -188,10 +189,11 @@ |
189 | 190 | * @param $text string |
190 | 191 | */ |
191 | 192 | public function printText($text) { |
192 | | - if ($this->getIsHtml()) |
| 193 | + if ($this->mBufferResult) { |
| 194 | + $this->mBuffer = $text; |
| 195 | + } elseif ($this->getIsHtml()) { |
193 | 196 | echo $this->formatHTML($text); |
194 | | - else |
195 | | - { |
| 197 | + } else { |
196 | 198 | // For non-HTML output, clear all errors that might have been |
197 | 199 | // displayed if display_errors=On |
198 | 200 | // Do this only once, of course |
— | — | @@ -203,6 +205,19 @@ |
204 | 206 | echo $text; |
205 | 207 | } |
206 | 208 | } |
| 209 | + |
| 210 | + /** |
| 211 | + * Get the contents of the buffer. |
| 212 | + */ |
| 213 | + public function getBuffer() { |
| 214 | + return $this->mBuffer; |
| 215 | + } |
| 216 | + /** |
| 217 | + * Set the flag to buffer the result instead of printing it. |
| 218 | + */ |
| 219 | + public function setBufferResult( $value ) { |
| 220 | + $this->mBufferResult = $value; |
| 221 | + } |
207 | 222 | |
208 | 223 | /** |
209 | 224 | * Sets whether the pretty-printer should format *bold* and $italics$ |
Index: trunk/phase3/includes/api/ApiUpload.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | $this->mParams = $this->extractRequestParams(); |
46 | 46 | $request = $this->getMain()->getRequest(); |
47 | 47 | |
48 | | - // do token checks: |
| 48 | + // Do token checks: |
49 | 49 | if ( is_null( $this->mParams['token'] ) ) |
50 | 50 | $this->dieUsageMsg( array( 'missingparam', 'token' ) ); |
51 | 51 | if ( !$wgUser->matchEditToken( $this->mParams['token'] ) ) |
— | — | @@ -57,21 +57,23 @@ |
58 | 58 | // Check whether upload is enabled |
59 | 59 | if ( !UploadBase::isEnabled() ) |
60 | 60 | $this->dieUsageMsg( array( 'uploaddisabled' ) ); |
61 | | - |
| 61 | + |
62 | 62 | // One and only one of the following parameters is needed |
63 | 63 | $this->requireOnlyOneParameter( $this->mParams, |
64 | | - 'sessionkey', 'file', 'url', 'enablechunks' ); |
| 64 | + 'sessionkey', 'file', 'url', 'enablechunks' ); |
| 65 | + |
| 66 | + if ( $this->mParams['enablechunks'] ) { |
| 67 | + /** |
| 68 | + * Chunked upload mode |
| 69 | + */ |
65 | 70 | |
66 | | - if ( $this->mParams['enablechunks'] ) { |
67 | | - // chunks upload enabled |
68 | 71 | $this->mUpload = new UploadFromChunks(); |
69 | 72 | $status = $this->mUpload->initializeFromParams( $this->mParams, $request ); |
70 | 73 | |
71 | 74 | if( isset( $status['error'] ) ) |
72 | 75 | $this->dieUsageMsg( $status['error'] ); |
73 | 76 | |
74 | | - } elseif ( $this->mParams['internalhttpsession'] ) { |
75 | | - // TODO: Move to subclass |
| 77 | + } elseif ( isset( $this->mParams['internalhttpsession'] ) && $this->mParams['internalhttpsession'] ) { |
76 | 78 | $sd = & $_SESSION['wsDownload'][ $this->mParams['internalhttpsession'] ]; |
77 | 79 | |
78 | 80 | //wfDebug("InternalHTTP:: " . print_r($this->mParams, true)); |
— | — | @@ -82,16 +84,17 @@ |
83 | 85 | $sd['target_file_path'], |
84 | 86 | filesize( $sd['target_file_path'] ) |
85 | 87 | ); |
86 | | - |
87 | 88 | } elseif ( $this->mParams['httpstatus'] && $this->mParams['sessionkey'] ) { |
88 | | - // return the status of the given upload session_key: |
| 89 | + /** |
| 90 | + * Return the status of the given background upload session_key: |
| 91 | + */ |
89 | 92 | |
90 | 93 | // Check the session key |
91 | 94 | if( !isset( $_SESSION['wsDownload'][$this->mParams['sessionkey']] ) ) |
92 | 95 | return $this->dieUsageMsg( array( 'invalid-session-key' ) ); |
93 | 96 | |
94 | 97 | $sd =& $_SESSION['wsDownload'][$this->mParams['sessionkey']]; |
95 | | - // keep passing down the upload sessionkey |
| 98 | + // Keep passing down the upload sessionkey |
96 | 99 | $statusResult = array( |
97 | 100 | 'upload_session_key' => $this->mParams['sessionkey'] |
98 | 101 | ); |
— | — | @@ -105,16 +108,20 @@ |
106 | 109 | $statusResult['content_length'] = $sd['content_length']; |
107 | 110 | |
108 | 111 | return $this->getResult()->addValue( null, |
109 | | - $this->getModuleName(), $statusResult); |
| 112 | + $this->getModuleName(), $statusResult ); |
110 | 113 | |
111 | | - } else if( $this->mParams['sessionkey'] ) { |
112 | | - // Stashed upload |
| 114 | + } elseif( $this->mParams['sessionkey'] ) { |
| 115 | + /** |
| 116 | + * Upload stashed in a previous request |
| 117 | + */ |
113 | 118 | $this->mUpload = new UploadFromStash(); |
114 | 119 | $this->mUpload->initialize( $this->mParams['filename'], |
115 | 120 | $_SESSION['wsUploadData'][$this->mParams['sessionkey']] ); |
116 | 121 | } else { |
117 | | - // Upload from url or file |
118 | | - // Parameter filename is required |
| 122 | + /** |
| 123 | + * Upload from url or file |
| 124 | + * Parameter filename is required |
| 125 | + */ |
119 | 126 | if ( !isset( $this->mParams['filename'] ) ) |
120 | 127 | $this->dieUsageMsg( array( 'missingparam', 'filename' ) ); |
121 | 128 | |
— | — | @@ -132,7 +139,7 @@ |
133 | 140 | $this->mParams['url'], $this->mParams['asyncdownload'] ); |
134 | 141 | |
135 | 142 | $status = $this->mUpload->fetchFile(); |
136 | | - if( !$status->isOK() ){ |
| 143 | + if( !$status->isOK() ) { |
137 | 144 | return $this->dieUsage( 'fetchfileerror', $status->getWikiText() ); |
138 | 145 | } |
139 | 146 | |
— | — | @@ -152,15 +159,16 @@ |
153 | 160 | array( 'upload_session_key' => $upload_session_key |
154 | 161 | )); |
155 | 162 | } |
156 | | - //else the file downloaded in place continue with validation: |
157 | 163 | } |
158 | 164 | } |
159 | | - |
| 165 | + |
160 | 166 | if( !isset( $this->mUpload ) ) |
161 | 167 | $this->dieUsage( 'No upload module set', 'nomodule' ); |
| 168 | + |
| 169 | + |
| 170 | + // Finish up the exec command: |
| 171 | + $this->doExecUpload(); |
162 | 172 | |
163 | | - //finish up the exec command: |
164 | | - $this->doExecUpload(); |
165 | 173 | } |
166 | 174 | |
167 | 175 | protected function doExecUpload(){ |
— | — | @@ -287,8 +295,6 @@ |
288 | 296 | $result['filename'] = $file->getName(); |
289 | 297 | |
290 | 298 | // Append imageinfo to the result |
291 | | - |
292 | | - //get all the image properties: |
293 | 299 | $imParam = ApiQueryImageInfo::getPropertyNames(); |
294 | 300 | $result['imageinfo'] = ApiQueryImageInfo::getInfo( $file, |
295 | 301 | array_flip( $imParam ), $this->getResult() ); |
— | — | @@ -322,12 +328,15 @@ |
323 | 329 | 'url' => null, |
324 | 330 | 'httpstatus' => false, |
325 | 331 | 'sessionkey' => null, |
326 | | - 'internalhttpsession' => null, |
327 | 332 | ); |
| 333 | + |
| 334 | + if ( $this->getMain()->isInternalMode() ) |
| 335 | + $params['internalhttpsession'] = null; |
328 | 336 | if($wgEnableAsyncDownload){ |
329 | 337 | $params['asyncdownload'] = false; |
330 | 338 | } |
331 | 339 | return $params; |
| 340 | + |
332 | 341 | } |
333 | 342 | |
334 | 343 | public function getParamDescription() { |
— | — | @@ -386,3 +395,4 @@ |
387 | 396 | } |
388 | 397 | } |
389 | 398 | |
| 399 | + |