Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -40,8 +40,9 @@ |
41 | 41 | */ |
42 | 42 | public static function isEnabled() { |
43 | 43 | global $wgEnableUploads; |
44 | | - if ( !$wgEnableUploads ) |
| 44 | + if ( !$wgEnableUploads ) { |
45 | 45 | return false; |
| 46 | + } |
46 | 47 | |
47 | 48 | # Check php's file_uploads setting |
48 | 49 | if( !wfIniGetBool( 'file_uploads' ) ) { |
— | — | @@ -56,8 +57,9 @@ |
57 | 58 | * Can be overriden by subclasses. |
58 | 59 | */ |
59 | 60 | public static function isAllowed( $user ) { |
60 | | - if( !$user->isAllowed( 'upload' ) ) |
| 61 | + if( !$user->isAllowed( 'upload' ) ) { |
61 | 62 | return 'upload'; |
| 63 | + } |
62 | 64 | return true; |
63 | 65 | } |
64 | 66 | |
— | — | @@ -70,8 +72,9 @@ |
71 | 73 | public static function createFromRequest( &$request, $type = null ) { |
72 | 74 | $type = $type ? $type : $request->getVal( 'wpSourceType', 'File' ); |
73 | 75 | |
74 | | - if( !$type ) |
| 76 | + if( !$type ) { |
75 | 77 | return null; |
| 78 | + } |
76 | 79 | |
77 | 80 | // Get the upload class |
78 | 81 | $type = ucfirst( $type ); |
— | — | @@ -82,17 +85,20 @@ |
83 | 86 | if ( is_null( $className ) ) { |
84 | 87 | $className = 'UploadFrom' . $type; |
85 | 88 | wfDebug( __METHOD__ . ": class name: $className\n" ); |
86 | | - if( !in_array( $type, self::$uploadHandlers ) ) |
| 89 | + if( !in_array( $type, self::$uploadHandlers ) ) { |
87 | 90 | return null; |
| 91 | + } |
88 | 92 | } |
89 | 93 | |
90 | 94 | // Check whether this upload class is enabled |
91 | | - if( !call_user_func( array( $className, 'isEnabled' ) ) ) |
| 95 | + if( !call_user_func( array( $className, 'isEnabled' ) ) ) { |
92 | 96 | return null; |
| 97 | + } |
93 | 98 | |
94 | 99 | // Check whether the request is valid |
95 | | - if( !call_user_func( array( $className, 'isValidRequest' ), $request ) ) |
| 100 | + if( !call_user_func( array( $className, 'isValidRequest' ), $request ) ) { |
96 | 101 | return null; |
| 102 | + } |
97 | 103 | |
98 | 104 | $handler = new $className; |
99 | 105 | |
— | — | @@ -139,16 +145,15 @@ |
140 | 146 | /** |
141 | 147 | * Return the file size |
142 | 148 | */ |
143 | | - public function isEmptyFile(){ |
| 149 | + public function isEmptyFile() { |
144 | 150 | return empty( $this->mFileSize ); |
145 | 151 | } |
146 | 152 | |
147 | 153 | /** |
148 | | - * getRealPath |
149 | | - * @param string $srcPath the source path |
150 | | - * @returns the real path if it was a virtual url |
151 | | - */ |
152 | | - function getRealPath( $srcPath ){ |
| 154 | + * @param string $srcPath the source path |
| 155 | + * @returns the real path if it was a virtual URL |
| 156 | + */ |
| 157 | + function getRealPath( $srcPath ) { |
153 | 158 | $repo = RepoGroup::singleton()->getLocalRepo(); |
154 | 159 | if ( $repo->isVirtualUrl( $srcPath ) ) { |
155 | 160 | return $repo->resolveVirtualUrl( $srcPath ); |
— | — | @@ -164,8 +169,9 @@ |
165 | 170 | /** |
166 | 171 | * If there was no filename or a zero size given, give up quick. |
167 | 172 | */ |
168 | | - if( $this->isEmptyFile() ) |
| 173 | + if( $this->isEmptyFile() ) { |
169 | 174 | return array( 'status' => self::EMPTY_FILE ); |
| 175 | + } |
170 | 176 | |
171 | 177 | /** |
172 | 178 | * Look at the contents of the file; if we can recognize the |
— | — | @@ -174,20 +180,24 @@ |
175 | 181 | */ |
176 | 182 | $verification = $this->verifyFile(); |
177 | 183 | if( $verification !== true ) { |
178 | | - if( !is_array( $verification ) ) |
| 184 | + if( !is_array( $verification ) ) { |
179 | 185 | $verification = array( $verification ); |
180 | | - return array( 'status' => self::VERIFICATION_ERROR, |
181 | | - 'details' => $verification ); |
182 | | - |
| 186 | + } |
| 187 | + return array( |
| 188 | + 'status' => self::VERIFICATION_ERROR, |
| 189 | + 'details' => $verification |
| 190 | + ); |
183 | 191 | } |
184 | 192 | |
185 | 193 | $nt = $this->getTitle(); |
186 | 194 | if( is_null( $nt ) ) { |
187 | 195 | $result = array( 'status' => $this->mTitleError ); |
188 | | - if( $this->mTitleError == self::ILLEGAL_FILENAME ) |
| 196 | + if( $this->mTitleError == self::ILLEGAL_FILENAME ) { |
189 | 197 | $result['filtered'] = $this->mFilteredName; |
190 | | - if ( $this->mTitleError == self::FILETYPE_BADTYPE ) |
| 198 | + } |
| 199 | + if ( $this->mTitleError == self::FILETYPE_BADTYPE ) { |
191 | 200 | $result['finalExt'] = $this->mFinalExtension; |
| 201 | + } |
192 | 202 | return $result; |
193 | 203 | } |
194 | 204 | $this->mDestName = $this->getLocalFile()->getName(); |
— | — | @@ -196,8 +206,12 @@ |
197 | 207 | * In some cases we may forbid overwriting of existing files. |
198 | 208 | */ |
199 | 209 | $overwrite = $this->checkOverwrite(); |
200 | | - if( $overwrite !== true ) |
201 | | - return array( 'status' => self::OVERWRITE_EXISTING_FILE, 'overwrite' => $overwrite ); |
| 210 | + if( $overwrite !== true ) { |
| 211 | + return array( |
| 212 | + 'status' => self::OVERWRITE_EXISTING_FILE, |
| 213 | + 'overwrite' => $overwrite |
| 214 | + ); |
| 215 | + } |
202 | 216 | |
203 | 217 | $error = ''; |
204 | 218 | if( !wfRunHooks( 'UploadVerification', |
— | — | @@ -218,16 +232,17 @@ |
219 | 233 | $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension ); |
220 | 234 | $this->checkMacBinary(); |
221 | 235 | |
222 | | - #magically determine mime type |
| 236 | + # magically determine mime type |
223 | 237 | $magic = MimeMagic::singleton(); |
224 | 238 | $mime = $magic->guessMimeType( $this->mTempPath, false ); |
225 | 239 | |
226 | | - #check mime type, if desired |
| 240 | + # check mime type, if desired |
227 | 241 | global $wgVerifyMimeType; |
228 | 242 | if ( $wgVerifyMimeType ) { |
229 | 243 | global $wgMimeTypeBlacklist; |
230 | | - if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) |
| 244 | + if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) { |
231 | 245 | return array( 'filetype-badmime', $mime ); |
| 246 | + } |
232 | 247 | |
233 | 248 | # Check IE type |
234 | 249 | $fp = fopen( $this->mTempPath, 'rb' ); |
— | — | @@ -242,7 +257,7 @@ |
243 | 258 | } |
244 | 259 | } |
245 | 260 | |
246 | | - #check for htmlish code and javascript |
| 261 | + # check for htmlish code and javascript |
247 | 262 | if( self::detectScript( $this->mTempPath, $mime, $this->mFinalExtension ) ) { |
248 | 263 | return 'uploadscripted'; |
249 | 264 | } |
— | — | @@ -276,8 +291,9 @@ |
277 | 292 | * to modify it by uploading a new revision. |
278 | 293 | */ |
279 | 294 | $nt = $this->getTitle(); |
280 | | - if( is_null( $nt ) ) |
| 295 | + if( is_null( $nt ) ) { |
281 | 296 | return true; |
| 297 | + } |
282 | 298 | $permErrors = $nt->getUserPermissionsErrors( 'edit', $user ); |
283 | 299 | $permErrorsUpload = $nt->getUserPermissionsErrors( 'upload', $user ); |
284 | 300 | $permErrorsCreate = ( $nt->exists() ? array() : $nt->getUserPermissionsErrors( 'create', $user ) ); |
— | — | @@ -302,34 +318,38 @@ |
303 | 319 | $n = strrpos( $filename, '.' ); |
304 | 320 | $partname = $n ? substr( $filename, 0, $n ) : $filename; |
305 | 321 | |
306 | | - /* |
| 322 | + /** |
307 | 323 | * Check whether the resulting filename is different from the desired one, |
308 | 324 | * but ignore things like ucfirst() and spaces/underscore things |
309 | 325 | */ |
310 | 326 | $comparableName = str_replace( ' ', '_', $this->mDesiredDestName ); |
311 | 327 | $comparableName = Title::capitalize( $comparableName, NS_FILE ); |
312 | 328 | |
313 | | - if( $this->mDesiredDestName != $filename && $comparableName != $filename ) |
| 329 | + if( $this->mDesiredDestName != $filename && $comparableName != $filename ) { |
314 | 330 | $warnings['badfilename'] = $filename; |
| 331 | + } |
315 | 332 | |
316 | 333 | // Check whether the file extension is on the unwanted list |
317 | 334 | global $wgCheckFileExtensions, $wgFileExtensions; |
318 | 335 | if ( $wgCheckFileExtensions ) { |
319 | | - if ( !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) ) |
| 336 | + if ( !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) ) { |
320 | 337 | $warnings['filetype-unwanted-type'] = $this->mFinalExtension; |
| 338 | + } |
321 | 339 | } |
322 | 340 | |
323 | 341 | global $wgUploadSizeWarning; |
324 | | - if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) ) |
| 342 | + if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) ) { |
325 | 343 | $warnings['large-file'] = $wgUploadSizeWarning; |
| 344 | + } |
326 | 345 | |
327 | | - if ( $this->mFileSize == 0 ) |
| 346 | + if ( $this->mFileSize == 0 ) { |
328 | 347 | $warnings['emptyfile'] = true; |
| 348 | + } |
329 | 349 | |
330 | | - |
331 | 350 | $exists = self::getExistsWarning( $localFile ); |
332 | | - if( $exists !== false ) |
| 351 | + if( $exists !== false ) { |
333 | 352 | $warnings['exists'] = $exists; |
| 353 | + } |
334 | 354 | |
335 | 355 | // Check dupes against existing files |
336 | 356 | $hash = File::sha1Base36( $this->mTempPath ); |
— | — | @@ -337,16 +357,19 @@ |
338 | 358 | $title = $this->getTitle(); |
339 | 359 | // Remove all matches against self |
340 | 360 | foreach ( $dupes as $key => $dupe ) { |
341 | | - if( $title->equals( $dupe->getTitle() ) ) |
| 361 | + if( $title->equals( $dupe->getTitle() ) ) { |
342 | 362 | unset( $dupes[$key] ); |
| 363 | + } |
343 | 364 | } |
344 | | - if( $dupes ) |
| 365 | + if( $dupes ) { |
345 | 366 | $warnings['duplicate'] = $dupes; |
| 367 | + } |
346 | 368 | |
347 | 369 | // Check dupes against archives |
348 | 370 | $archivedImage = new ArchivedFile( null, 0, "{$hash}.{$this->mFinalExtension}" ); |
349 | | - if ( $archivedImage->getID() > 0 ) |
| 371 | + if ( $archivedImage->getID() > 0 ) { |
350 | 372 | $warnings['duplicate-archive'] = $archivedImage->getName(); |
| 373 | + } |
351 | 374 | |
352 | 375 | return $warnings; |
353 | 376 | } |
— | — | @@ -362,11 +385,13 @@ |
363 | 386 | $status = $this->getLocalFile()->upload( $this->mTempPath, $comment, $pageText, |
364 | 387 | File::DELETE_SOURCE, $this->mFileProps, false, $user ); |
365 | 388 | |
366 | | - if( $status->isGood() && $watch ) |
| 389 | + if( $status->isGood() && $watch ) { |
367 | 390 | $user->addWatch( $this->getLocalFile()->getTitle() ); |
| 391 | + } |
368 | 392 | |
369 | | - if( $status->isGood() ) |
| 393 | + if( $status->isGood() ) { |
370 | 394 | wfRunHooks( 'UploadComplete', array( &$this ) ); |
| 395 | + } |
371 | 396 | |
372 | 397 | return $status; |
373 | 398 | } |
— | — | @@ -378,8 +403,9 @@ |
379 | 404 | * @return Title The title of the file or null in case the name was illegal |
380 | 405 | */ |
381 | 406 | public function getTitle() { |
382 | | - if ( $this->mTitle !== false ) |
| 407 | + if ( $this->mTitle !== false ) { |
383 | 408 | return $this->mTitle; |
| 409 | + } |
384 | 410 | |
385 | 411 | /** |
386 | 412 | * Chop off any directories in the given filename. Then |
— | — | @@ -425,8 +451,9 @@ |
426 | 452 | # If there was more than one "extension", reassemble the base |
427 | 453 | # filename to prevent bogus complaints about length |
428 | 454 | if( count( $ext ) > 1 ) { |
429 | | - for( $i = 0; $i < count( $ext ) - 1; $i++ ) |
| 455 | + for( $i = 0; $i < count( $ext ) - 1; $i++ ) { |
430 | 456 | $partname .= '.' . $ext[$i]; |
| 457 | + } |
431 | 458 | } |
432 | 459 | |
433 | 460 | if( strlen( $partname ) < 1 ) { |
— | — | @@ -463,7 +490,6 @@ |
464 | 491 | * @param string $saveName - the destination filename |
465 | 492 | * @param string $tempSrc - the source temporary file to save |
466 | 493 | * @return string - full path the stashed file, or false on failure |
467 | | - * @access private |
468 | 494 | */ |
469 | 495 | protected function saveTempUploadedFile( $saveName, $tempSrc ) { |
470 | 496 | $repo = RepoGroup::singleton()->getLocalRepo(); |
— | — | @@ -485,8 +511,9 @@ |
486 | 512 | # Couldn't save the file. |
487 | 513 | return false; |
488 | 514 | } |
489 | | - if(!isset($_SESSION)) |
| 515 | + if( !isset( $_SESSION ) ) { |
490 | 516 | session_start(); // start up the session (might have been previously closed to prevent php session locking) |
| 517 | + } |
491 | 518 | $key = $this->getSessionKey(); |
492 | 519 | $_SESSION['wsUploadData'][$key] = array( |
493 | 520 | 'mTempPath' => $status->value, |
— | — | @@ -500,17 +527,15 @@ |
501 | 528 | /** |
502 | 529 | * Generate a random session key from stash in cases where we want to start an upload without much information |
503 | 530 | */ |
504 | | - protected function getSessionKey(){ |
| 531 | + protected function getSessionKey() { |
505 | 532 | $key = mt_rand( 0, 0x7fffffff ); |
506 | 533 | $_SESSION['wsUploadData'][$key] = array(); |
507 | 534 | return $key; |
508 | 535 | } |
509 | 536 | |
510 | | - |
511 | 537 | /** |
512 | 538 | * If we've modified the upload file we need to manually remove it |
513 | 539 | * on exit to clean up. |
514 | | - * @access private |
515 | 540 | */ |
516 | 541 | public function cleanupTempFile() { |
517 | 542 | if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) { |
— | — | @@ -607,7 +632,8 @@ |
608 | 633 | /** |
609 | 634 | * Heuristic for detecting files that *could* contain JavaScript instructions or |
610 | 635 | * things that may look like HTML to a browser and are thus |
611 | | - * potentially harmful. The present implementation will produce false positives in some situations. |
| 636 | + * potentially harmful. The present implementation will produce false |
| 637 | + * positives in some situations. |
612 | 638 | * |
613 | 639 | * @param string $file Pathname to the temporary upload file |
614 | 640 | * @param string $mime The mime type of the file |
— | — | @@ -617,12 +643,12 @@ |
618 | 644 | public static function detectScript( $file, $mime, $extension ) { |
619 | 645 | global $wgAllowTitlesInSVG; |
620 | 646 | |
621 | | - #ugly hack: for text files, always look at the entire file. |
622 | | - #For binary field, just check the first K. |
| 647 | + # ugly hack: for text files, always look at the entire file. |
| 648 | + # For binary field, just check the first K. |
623 | 649 | |
624 | | - if( strpos( $mime,'text/' ) === 0 ) |
| 650 | + if( strpos( $mime,'text/' ) === 0 ) { |
625 | 651 | $chunk = file_get_contents( $file ); |
626 | | - else { |
| 652 | + } else { |
627 | 653 | $fp = fopen( $file, 'rb' ); |
628 | 654 | $chunk = fread( $fp, 1024 ); |
629 | 655 | fclose( $fp ); |
— | — | @@ -630,44 +656,48 @@ |
631 | 657 | |
632 | 658 | $chunk = strtolower( $chunk ); |
633 | 659 | |
634 | | - if( !$chunk ) |
| 660 | + if( !$chunk ) { |
635 | 661 | return false; |
| 662 | + } |
636 | 663 | |
637 | | - #decode from UTF-16 if needed (could be used for obfuscation). |
638 | | - if( substr( $chunk, 0, 2 ) == "\xfe\xff" ) |
639 | | - $enc = "UTF-16BE"; |
640 | | - elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) |
641 | | - $enc = "UTF-16LE"; |
642 | | - else |
| 664 | + # decode from UTF-16 if needed (could be used for obfuscation). |
| 665 | + if( substr( $chunk, 0, 2 ) == "\xfe\xff" ) { |
| 666 | + $enc = 'UTF-16BE'; |
| 667 | + } elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) { |
| 668 | + $enc = 'UTF-16LE'; |
| 669 | + } else { |
643 | 670 | $enc = null; |
| 671 | + } |
644 | 672 | |
645 | | - if( $enc ) |
| 673 | + if( $enc ) { |
646 | 674 | $chunk = iconv( $enc, "ASCII//IGNORE", $chunk ); |
| 675 | + } |
647 | 676 | |
648 | 677 | $chunk = trim( $chunk ); |
649 | 678 | |
650 | | - #FIXME: convert from UTF-16 if necessarry! |
| 679 | + # FIXME: convert from UTF-16 if necessarry! |
651 | 680 | wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n" ); |
652 | 681 | |
653 | | - #check for HTML doctype |
654 | | - if ( preg_match( "/<!DOCTYPE *X?HTML/i", $chunk ) ) |
| 682 | + # check for HTML doctype |
| 683 | + if ( preg_match( "/<!DOCTYPE *X?HTML/i", $chunk ) ) { |
655 | 684 | return true; |
| 685 | + } |
656 | 686 | |
657 | 687 | /** |
658 | | - * Internet Explorer for Windows performs some really stupid file type |
659 | | - * autodetection which can cause it to interpret valid image files as HTML |
660 | | - * and potentially execute JavaScript, creating a cross-site scripting |
661 | | - * attack vectors. |
662 | | - * |
663 | | - * Apple's Safari browser also performs some unsafe file type autodetection |
664 | | - * which can cause legitimate files to be interpreted as HTML if the |
665 | | - * web server is not correctly configured to send the right content-type |
666 | | - * (or if you're really uploading plain text and octet streams!) |
667 | | - * |
668 | | - * Returns true if IE is likely to mistake the given file for HTML. |
669 | | - * Also returns true if Safari would mistake the given file for HTML |
670 | | - * when served with a generic content-type. |
671 | | - */ |
| 688 | + * Internet Explorer for Windows performs some really stupid file type |
| 689 | + * autodetection which can cause it to interpret valid image files as HTML |
| 690 | + * and potentially execute JavaScript, creating a cross-site scripting |
| 691 | + * attack vectors. |
| 692 | + * |
| 693 | + * Apple's Safari browser also performs some unsafe file type autodetection |
| 694 | + * which can cause legitimate files to be interpreted as HTML if the |
| 695 | + * web server is not correctly configured to send the right content-type |
| 696 | + * (or if you're really uploading plain text and octet streams!) |
| 697 | + * |
| 698 | + * Returns true if IE is likely to mistake the given file for HTML. |
| 699 | + * Also returns true if Safari would mistake the given file for HTML |
| 700 | + * when served with a generic content-type. |
| 701 | + */ |
672 | 702 | $tags = array( |
673 | 703 | '<a href', |
674 | 704 | '<body', |
— | — | @@ -693,20 +723,23 @@ |
694 | 724 | * look for JavaScript |
695 | 725 | */ |
696 | 726 | |
697 | | - #resolve entity-refs to look at attributes. may be harsh on big files... cache result? |
| 727 | + # resolve entity-refs to look at attributes. may be harsh on big files... cache result? |
698 | 728 | $chunk = Sanitizer::decodeCharReferences( $chunk ); |
699 | 729 | |
700 | | - #look for script-types |
701 | | - if( preg_match( '!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) ) |
| 730 | + # look for script-types |
| 731 | + if( preg_match( '!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) ) { |
702 | 732 | return true; |
| 733 | + } |
703 | 734 | |
704 | | - #look for html-style script-urls |
705 | | - if( preg_match( '!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) |
| 735 | + # look for html-style script-urls |
| 736 | + if( preg_match( '!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) { |
706 | 737 | return true; |
| 738 | + } |
707 | 739 | |
708 | | - #look for css-style script-urls |
709 | | - if( preg_match( '!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) |
| 740 | + # look for css-style script-urls |
| 741 | + if( preg_match( '!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) { |
710 | 742 | return true; |
| 743 | + } |
711 | 744 | |
712 | 745 | wfDebug( __METHOD__ . ": no scripts found\n" ); |
713 | 746 | return false; |
— | — | @@ -772,12 +805,12 @@ |
773 | 806 | } |
774 | 807 | |
775 | 808 | # look up scanner configuration |
776 | | - $command = $wgAntivirusSetup[$wgAntivirus]["command"]; |
777 | | - $exitCodeMap = $wgAntivirusSetup[$wgAntivirus]["codemap"]; |
778 | | - $msgPattern = isset( $wgAntivirusSetup[$wgAntivirus]["messagepattern"] ) ? |
779 | | - $wgAntivirusSetup[$wgAntivirus]["messagepattern"] : null; |
| 809 | + $command = $wgAntivirusSetup[$wgAntivirus]['command']; |
| 810 | + $exitCodeMap = $wgAntivirusSetup[$wgAntivirus]['codemap']; |
| 811 | + $msgPattern = isset( $wgAntivirusSetup[$wgAntivirus]['messagepattern'] ) ? |
| 812 | + $wgAntivirusSetup[$wgAntivirus]['messagepattern'] : null; |
780 | 813 | |
781 | | - if ( strpos( $command,"%f" ) === false ) { |
| 814 | + if ( strpos( $command, "%f" ) === false ) { |
782 | 815 | # simple pattern: append file to scan |
783 | 816 | $command .= " " . wfEscapeShellArg( $file ); |
784 | 817 | } else { |
— | — | @@ -790,7 +823,7 @@ |
791 | 824 | # execute virus scanner |
792 | 825 | $exitCode = false; |
793 | 826 | |
794 | | - #NOTE: there's a 50 line workaround to make stderr redirection work on windows, too. |
| 827 | + # NOTE: there's a 50 line workaround to make stderr redirection work on windows, too. |
795 | 828 | # that does not seem to be worth the pain. |
796 | 829 | # Ask me (Duesentrieb) about it if it's ever needed. |
797 | 830 | $output = wfShellExec( "$command 2>&1", $exitCode ); |
— | — | @@ -814,11 +847,11 @@ |
815 | 848 | } else { |
816 | 849 | return null; |
817 | 850 | } |
818 | | - } else if ( $mappedCode === AV_SCAN_ABORTED ) { |
| 851 | + } elseif ( $mappedCode === AV_SCAN_ABORTED ) { |
819 | 852 | # scan failed because filetype is unknown (probably imune) |
820 | 853 | wfDebug( __METHOD__ . ": unsupported file type $file (code $exitCode).\n" ); |
821 | 854 | return null; |
822 | | - } else if ( $mappedCode === AV_NO_VIRUS ) { |
| 855 | + } elseif ( $mappedCode === AV_NO_VIRUS ) { |
823 | 856 | # no virus found |
824 | 857 | wfDebug( __METHOD__ . ": file passed virus scan.\n" ); |
825 | 858 | return false; |
— | — | @@ -846,8 +879,6 @@ |
847 | 880 | * from Internet Explorer on Mac OS Classic and Mac OS X will be. |
848 | 881 | * If so, the data fork will be extracted to a second temporary file, |
849 | 882 | * which will then be checked for validity and either kept or discarded. |
850 | | - * |
851 | | - * @access private |
852 | 883 | */ |
853 | 884 | private function checkMacBinary() { |
854 | 885 | $macbin = new MacBinary( $this->mTempPath ); |
— | — | @@ -872,25 +903,26 @@ |
873 | 904 | * forbid this user from performing the upload. |
874 | 905 | * |
875 | 906 | * @return mixed true on success, error string on failure |
876 | | - * @access private |
877 | 907 | */ |
878 | 908 | private function checkOverwrite() { |
879 | 909 | global $wgUser; |
880 | 910 | // First check whether the local file can be overwritten |
881 | 911 | $file = $this->getLocalFile(); |
882 | 912 | if( $file->exists() ) { |
883 | | - if( !self::userCanReUpload( $wgUser, $file ) ) |
| 913 | + if( !self::userCanReUpload( $wgUser, $file ) ) { |
884 | 914 | return 'fileexists-forbidden'; |
885 | | - else |
| 915 | + } else { |
886 | 916 | return true; |
| 917 | + } |
887 | 918 | } |
888 | 919 | |
889 | 920 | /* Check shared conflicts: if the local file does not exist, but |
890 | 921 | * wfFindFile finds a file, it exists in a shared repository. |
891 | 922 | */ |
892 | 923 | $file = wfFindFile( $this->getTitle() ); |
893 | | - if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) ) |
| 924 | + if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) ) { |
894 | 925 | return 'fileexists-shared-forbidden'; |
| 926 | + } |
895 | 927 | |
896 | 928 | return true; |
897 | 929 | } |
— | — | @@ -903,14 +935,18 @@ |
904 | 936 | * @return bool |
905 | 937 | */ |
906 | 938 | public static function userCanReUpload( User $user, $img ) { |
907 | | - if( $user->isAllowed( 'reupload' ) ) |
| 939 | + if( $user->isAllowed( 'reupload' ) ) { |
908 | 940 | return true; // non-conditional |
909 | | - if( !$user->isAllowed( 'reupload-own' ) ) |
| 941 | + } |
| 942 | + if( !$user->isAllowed( 'reupload-own' ) ) { |
910 | 943 | return false; |
911 | | - if( is_string( $img ) ) |
| 944 | + } |
| 945 | + if( is_string( $img ) ) { |
912 | 946 | $img = wfLocalFile( $img ); |
913 | | - if ( !( $img instanceof LocalFile ) ) |
| 947 | + } |
| 948 | + if ( !( $img instanceof LocalFile ) ) { |
914 | 949 | return false; |
| 950 | + } |
915 | 951 | |
916 | 952 | return $user->getId() == $img->getUser( 'id' ); |
917 | 953 | } |
— | — | @@ -927,14 +963,17 @@ |
928 | 964 | * @return mixed False if the file does not exists, else an array |
929 | 965 | */ |
930 | 966 | public static function getExistsWarning( $file ) { |
931 | | - if( $file->exists() ) |
| 967 | + if( $file->exists() ) { |
932 | 968 | return array( 'warning' => 'exists', 'file' => $file ); |
| 969 | + } |
933 | 970 | |
934 | | - if( $file->getTitle()->getArticleID() ) |
| 971 | + if( $file->getTitle()->getArticleID() ) { |
935 | 972 | return array( 'warning' => 'page-exists', 'file' => $file ); |
| 973 | + } |
936 | 974 | |
937 | | - if ( $file->wasDeleted() && !$file->exists() ) |
| 975 | + if ( $file->wasDeleted() && !$file->exists() ) { |
938 | 976 | return array( 'warning' => 'was-deleted', 'file' => $file ); |
| 977 | + } |
939 | 978 | |
940 | 979 | if( strpos( $file->getName(), '.' ) == false ) { |
941 | 980 | $partname = $file->getName(); |
— | — | @@ -955,29 +994,46 @@ |
956 | 995 | $nt_lc = Title::makeTitle( NS_FILE, "{$partname}.{$normalizedExtension}" ); |
957 | 996 | $file_lc = wfLocalFile( $nt_lc ); |
958 | 997 | |
959 | | - if( $file_lc->exists() ) |
960 | | - return array( 'warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $file_lc ); |
| 998 | + if( $file_lc->exists() ) { |
| 999 | + return array( |
| 1000 | + 'warning' => 'exists-normalized', |
| 1001 | + 'file' => $file, |
| 1002 | + 'normalizedFile' => $file_lc |
| 1003 | + ); |
| 1004 | + } |
961 | 1005 | } |
962 | 1006 | |
963 | 1007 | if ( self::isThumbName( $file->getName() ) ) { |
964 | 1008 | # Check for filenames like 50px- or 180px-, these are mostly thumbnails |
965 | 1009 | $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $extension, NS_FILE ); |
966 | 1010 | $file_thb = wfLocalFile( $nt_thb ); |
967 | | - if( $file_thb->exists() ) |
968 | | - return array( 'warning' => 'thumb', 'file' => $file, 'thumbFile' => $file_thb ); |
969 | | - else |
| 1011 | + if( $file_thb->exists() ) { |
| 1012 | + return array( |
| 1013 | + 'warning' => 'thumb', |
| 1014 | + 'file' => $file, |
| 1015 | + 'thumbFile' => $file_thb |
| 1016 | + ); |
| 1017 | + } else { |
970 | 1018 | // File does not exist, but we just don't like the name |
971 | | - return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb ); |
| 1019 | + return array( |
| 1020 | + 'warning' => 'thumb-name', |
| 1021 | + 'file' => $file, |
| 1022 | + 'thumbFile' => $file_thb |
| 1023 | + ); |
| 1024 | + } |
972 | 1025 | } |
973 | 1026 | |
974 | 1027 | |
975 | 1028 | foreach( self::getFilenamePrefixBlacklist() as $prefix ) { |
976 | | - if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) |
977 | | - return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix ); |
| 1029 | + if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) { |
| 1030 | + return array( |
| 1031 | + 'warning' => 'bad-prefix', |
| 1032 | + 'file' => $file, |
| 1033 | + 'prefix' => $prefix |
| 1034 | + ); |
| 1035 | + } |
978 | 1036 | } |
979 | 1037 | |
980 | | - |
981 | | - |
982 | 1038 | return false; |
983 | 1039 | } |
984 | 1040 | |
— | — | @@ -995,7 +1051,7 @@ |
996 | 1052 | } |
997 | 1053 | |
998 | 1054 | /** |
999 | | - * Get a list of blacklisted filename prefixes from [[MediaWiki:filename-prefix-blacklist]] |
| 1055 | + * Get a list of blacklisted filename prefixes from [[MediaWiki:Filename-prefix-blacklist]] |
1000 | 1056 | * |
1001 | 1057 | * @return array list of prefixes |
1002 | 1058 | */ |
— | — | @@ -1021,7 +1077,7 @@ |
1022 | 1078 | return $blacklist; |
1023 | 1079 | } |
1024 | 1080 | |
1025 | | - public function getImageInfo($result) { |
| 1081 | + public function getImageInfo( $result ) { |
1026 | 1082 | $file = $this->getLocalFile(); |
1027 | 1083 | $imParam = ApiQueryImageInfo::getPropertyNames(); |
1028 | 1084 | return ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result ); |