Index: branches/ApiEdit_Vodafone/includes/SpecialUpload.php |
— | — | @@ -259,9 +259,7 @@ |
260 | 260 | } |
261 | 261 | $this->mainUploadForm(); |
262 | 262 | } else if( 'submit' == $this->mAction || $this->mUploadClicked ) { |
263 | | - $details = null; |
264 | | - $retval = $this->processUpload( $details ); |
265 | | - $this->processRest($retval, $details); |
| 263 | + $this->processUpload(); |
266 | 264 | } else { |
267 | 265 | $this->mainUploadForm(); |
268 | 266 | } |
— | — | @@ -269,11 +267,18 @@ |
270 | 268 | $this->cleanupTempFile(); |
271 | 269 | } |
272 | 270 | |
273 | | - function processRest($value, $details) { |
| 271 | + /** |
| 272 | + * Do the upload |
| 273 | + * Checks are made in SpecialUpload::execute() |
| 274 | + * |
| 275 | + * @access private |
| 276 | + */ |
| 277 | + function processUpload(){ |
274 | 278 | global $wgUser, $wgOut, $wgFileExtensions; |
275 | | - |
276 | | - switch ($value) |
277 | | - { |
| 279 | + $results = null; |
| 280 | + $value = null; |
| 281 | + $value = internalProcessUpload($results); |
| 282 | + switch($value) { |
278 | 283 | case self::SUCCESS: |
279 | 284 | $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() ); |
280 | 285 | break; |
— | — | @@ -335,28 +340,25 @@ |
336 | 341 | $warning = $details['warning']; |
337 | 342 | $this->uploadWarning( $warning ); |
338 | 343 | break; |
339 | | - |
340 | | - } |
| 344 | + } |
341 | 345 | } |
342 | 346 | |
343 | | - |
344 | | - /* -------------------------------------------------------------- */ |
345 | | - |
346 | 347 | /** |
347 | 348 | * Really do the upload |
348 | 349 | * Checks are made in SpecialUpload::execute() |
349 | | - * |
| 350 | + * |
350 | 351 | * @param array $resultDetails contains result-specific dict of additional values |
351 | | - * |
| 352 | + * |
352 | 353 | * @access private |
353 | 354 | */ |
354 | | - function processUpload( &$resultDetails="" ) { |
| 355 | + function internalProcessUpload( &$resultDetails="" ) { |
355 | 356 | global $wgUser, $wgOut; |
356 | 357 | |
357 | 358 | if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) ) |
358 | 359 | { |
359 | 360 | wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file." ); |
360 | 361 | return self::BEFORE_PROCESSING; |
| 362 | + |
361 | 363 | } |
362 | 364 | |
363 | 365 | /* Check for PHP error if any, requires php 4.2 or newer */ |
— | — | @@ -397,7 +399,8 @@ |
398 | 400 | for( $i = 0; $i < count( $ext ) - 1; $i++ ) |
399 | 401 | $partname .= '.' . $ext[$i]; |
400 | 402 | } |
401 | | - |
| 403 | + |
| 404 | + |
402 | 405 | if( strlen( $partname ) < 1 ) { |
403 | 406 | return self::MIN_LENGHT_PARTNAME; |
404 | 407 | } |
— | — | @@ -408,6 +411,7 @@ |
409 | 412 | */ |
410 | 413 | $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $filtered ); |
411 | 414 | $nt = Title::makeTitleSafe( NS_IMAGE, $filtered ); |
| 415 | + |
412 | 416 | if( is_null( $nt ) ) { |
413 | 417 | $resultDetails = array( 'filtered' => $filtered ); |
414 | 418 | return self::ILLEGAL_FILENAME; |
— | — | @@ -436,8 +440,10 @@ |
437 | 441 | /* Don't allow users to override the blacklist (check file extension) */ |
438 | 442 | global $wgStrictFileExtensions; |
439 | 443 | global $wgFileExtensions, $wgFileBlacklist; |
| 444 | + |
440 | 445 | if ($finalExt == '') { |
441 | 446 | return self::FILETYPE_MISSING; |
| 447 | + |
442 | 448 | } elseif ( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) || |
443 | 449 | ($wgStrictFileExtensions && !$this->checkFileExtension( $finalExt, $wgFileExtensions ) ) ) { |
444 | 450 | $resultDetails = array( 'finalExt' => $finalExt ); |
— | — | @@ -476,7 +482,6 @@ |
477 | 483 | */ |
478 | 484 | if ( ! $this->mIgnoreWarning ) { |
479 | 485 | $warning = ''; |
480 | | - |
481 | 486 | global $wgCapitalLinks; |
482 | 487 | if( $wgCapitalLinks ) { |
483 | 488 | $filtered = ucfirst( $filtered ); |
— | — | @@ -488,7 +493,7 @@ |
489 | 494 | global $wgCheckFileExtensions; |
490 | 495 | if ( $wgCheckFileExtensions ) { |
491 | 496 | if ( ! $this->checkFileExtension( $finalExt, $wgFileExtensions ) ) { |
492 | | - $warning .= '<li>'.wfMsgExt( 'filetype-badtype', array ( 'parseinline' ), |
| 497 | + $warning .= '<li>'.wfMsgExt( 'filetype-badtype', array ( 'parseinline' ), |
493 | 498 | htmlspecialchars( $finalExt ), implode ( ', ', $wgFileExtensions ) ).'</li>'; |
494 | 499 | } |
495 | 500 | } |
— | — | @@ -507,6 +512,7 @@ |
508 | 513 | if ( !$this->mDestWarningAck ) { |
509 | 514 | $warning .= self::getExistsWarning( $this->mLocalFile ); |
510 | 515 | } |
| 516 | + |
511 | 517 | if( $warning != '' ) { |
512 | 518 | /** |
513 | 519 | * Stash the file in a temporary location; the user can choose |
— | — | @@ -524,7 +530,7 @@ |
525 | 531 | $pageText = self::getInitialPageText( $this->mComment, $this->mLicense, |
526 | 532 | $this->mCopyrightStatus, $this->mCopyrightSource ); |
527 | 533 | |
528 | | - $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText, |
| 534 | + $status = $this->mLocalFile->upload( $this->mTempPath, $this->mComment, $pageText, |
529 | 535 | File::DELETE_SOURCE, $this->mFileProps ); |
530 | 536 | if ( !$status->isGood() ) { |
531 | 537 | $this->showError( $status->getWikiText() ); |
Index: branches/ApiEdit_Vodafone/includes/api/ApiUploadFile.php |
— | — | @@ -41,8 +41,8 @@ |
42 | 42 | const UPLOAD_BLOCKED_PAGE = -5;
|
43 | 43 | const UPLOAD_READ_ONLY = -6;
|
44 | 44 | const UPLOAD_BAD_TOKEN = -7;
|
| 45 | + const UPLOAD_WITHOUT_POSTPARAMETERS = -8;
|
45 | 46 |
|
46 | | -
|
47 | 47 | public function __construct($query, $moduleName) {
|
48 | 48 | parent :: __construct($query, $moduleName, 'up');
|
49 | 49 | }
|
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | // $this->cleanupTempFile();
|
149 | 149 |
|
150 | 150 | } else {
|
151 | | - $this->process( self::UPLOAD_INVALID );
|
| 151 | + $this->process( self::UPLOAD_WITHOUT_POSTPARAMETERS );
|
152 | 152 | }
|
153 | 153 | }
|
154 | 154 |
|
— | — | @@ -156,89 +156,93 @@ |
157 | 157 |
|
158 | 158 | switch ($value) {
|
159 | 159 | case ApiUploadFile::UPLOAD_INVALID :
|
160 | | - $result['result'] = 'Upload_Invalid';
|
| 160 | + $result['result'] = 'UPLOAD_INVALID';
|
161 | 161 | break;
|
162 | 162 |
|
163 | 163 | case ApiUploadFile::UPLOAD_ENABLED_UPLOADS :
|
164 | | - $result['result'] = 'Upload_Enabled_Uploads';
|
| 164 | + $result['result'] = 'UPLOAD_ENABLED_UPLOADS';
|
165 | 165 | break;
|
166 | 166 |
|
167 | 167 | case ApiUploadFile::UPLOAD_NOT_LOGGED :
|
168 | | - $result['result'] = 'Upload_Not_Logged';
|
| 168 | + $result['result'] = 'UPLOAD_NOT_LOGGED';
|
169 | 169 | break;
|
170 | 170 |
|
171 | 171 | case ApiUploadFile::UPLOAD_NOT_ALLOWED :
|
172 | | - $result['result'] = 'Upload_Not_Allowed';
|
| 172 | + $result['result'] = 'UPLOAD_NOT_ALLOWED';
|
173 | 173 | break;
|
174 | 174 |
|
175 | 175 | case ApiUploadFile::UPLOAD_BLOCKED_PAGE :
|
176 | | - $result['result'] = 'Upload_Blocked_Page';
|
| 176 | + $result['result'] = 'UPLOAD_BLOCKED_PAGE';
|
177 | 177 | break;
|
178 | 178 |
|
179 | 179 | case ApiUploadFile::UPLOAD_READ_ONLY :
|
180 | | - $result['result'] = 'Upload_Read_Only';
|
| 180 | + $result['result'] = 'UPLOAD_READ_ONLY';
|
181 | 181 | break;
|
182 | 182 |
|
183 | 183 | case ApiUploadFile::UPLOAD_BAD_TOKEN :
|
184 | 184 | $result['result'] = 'UPLOAD_BAD_TOKEN';
|
185 | 185 | break;
|
186 | 186 |
|
| 187 | + case ApiUploadFile::UPLOAD_WITHOUT_POSTPARAMETERS :
|
| 188 | + $result['result'] = 'UPLOAD_WITHOUT_POSTPARAMETERS';
|
| 189 | + break;
|
| 190 | +
|
187 | 191 | case UploadForm::SUCCESS :
|
188 | | - $result['result'] = 'Success';
|
| 192 | + $result['result'] = 'SUCCESS';
|
189 | 193 | $result['title'] = $wgRequest->getText( 'updestfile' );
|
190 | 194 | $result['ns'] = "6";
|
191 | 195 | break;
|
192 | 196 |
|
193 | 197 | case UploadForm::BEFORE_PROCESSING:
|
194 | | - $result['result'] = 'Upload_BeforeProcessing';
|
| 198 | + $result['result'] = 'UPLOAD_BEFORE_PROCESSING ';
|
195 | 199 | break;
|
196 | 200 |
|
197 | 201 | case UploadForm::LARGE_FILE_SERVER:
|
198 | | - $result['result'] = 'Upload_LargeFileServer';
|
| 202 | + $result['result'] = 'UPLOAD_LARGE_FILE_SERVER';
|
199 | 203 | break;
|
200 | 204 |
|
201 | 205 | case UploadForm::EMPTY_FILE:
|
202 | | - $result['result'] = 'Upload_EmptyFile';
|
| 206 | + $result['result'] = 'UPLOAD_EMPTY_FILE';
|
203 | 207 | break;
|
204 | 208 |
|
205 | 209 | case UploadForm::MIN_LENGHT_PARTNAME:
|
206 | | - $result['result'] = 'Upload_MinLenghtPartName';
|
| 210 | + $result['result'] = 'UPLOAD_MIN_LENGHT_PARTNAME';
|
207 | 211 | break;
|
208 | 212 |
|
209 | 213 | case UploadForm::ILLEGAL_FILENAME:
|
210 | | - $result['result'] = 'Upload_IllegalFilename';
|
| 214 | + $result['result'] = 'UPLOAD_ILLEGAL_FILENAME';
|
211 | 215 | break;
|
212 | 216 |
|
213 | 217 | case UploadForm::PROTECTED_PAGE:
|
214 | | - $result['result'] = 'Upload_ProtectedPage';
|
| 218 | + $result['result'] = 'UPLOAD_PROTECTED_PAGE';
|
215 | 219 | break;
|
216 | 220 |
|
217 | 221 | case UploadForm::OVERWRITE_EXISTING_FILE:
|
218 | | - $result['result'] = 'Upload_OverwriteExistingFile';
|
| 222 | + $result['result'] = 'UPLOAD_OVERWRITE_EXISTING_FILE';
|
219 | 223 | break;
|
220 | 224 |
|
221 | 225 | case UploadForm::FILETYPE_MISSING:
|
222 | | - $result['result'] = 'Upload_FiletypeMissing';
|
| 226 | + $result['result'] = 'UPLOAD_FILETYPE_MISSING';
|
223 | 227 | break;
|
224 | 228 |
|
225 | 229 | case UploadForm::FILETYPE_BADTYPE:
|
226 | | - $result['result'] = 'Upload_FiletypeBadType';
|
| 230 | + $result['result'] = 'UPLOAD_FILETYPE_BADTYPE';
|
227 | 231 | break;
|
228 | 232 |
|
229 | 233 | case UploadForm::VERIFICATION_ERROR:
|
230 | | - $result['result'] = 'Upload_VerificationError';
|
| 234 | + $result['result'] = 'UPLOAD_VERIFICATION_ERROR';
|
231 | 235 | break;
|
232 | 236 |
|
233 | 237 | case UploadForm::UPLOAD_VERIFICATION_ERROR:
|
234 | | - $result['result'] = 'Upload_UploadVerificationError';
|
| 238 | + $result['result'] = 'UPLOAD_UPLOADVERIFICATION_ERROR';
|
235 | 239 | break;
|
236 | 240 |
|
237 | 241 | case UploadForm::UPLOAD_WARNING:
|
238 | | - $result['result'] = 'Upload_Warning';
|
| 242 | + $result['result'] = 'UPLOAD_WARNING';
|
239 | 243 | break;
|
240 | 244 |
|
241 | 245 | default :
|
242 | | - $result['result'] = 'Upload_Invalid';
|
| 246 | + $result['result'] = 'UPLOAD_INVALID';
|
243 | 247 | }
|
244 | 248 |
|
245 | 249 | $this->getResult()->addValue(null, 'upload', $result);
|