Index: branches/uploadwizard-deployment/includes/WebRequest.php |
— | — | @@ -561,22 +561,19 @@ |
562 | 562 | * @return string or NULL if no such file. |
563 | 563 | */ |
564 | 564 | public function getFileTempname( $key ) { |
565 | | - if( !isset( $_FILES[$key] ) ) { |
566 | | - return null; |
567 | | - } |
568 | | - return $_FILES[$key]['tmp_name']; |
| 565 | + $file = new WebRequestUpload( $key ); |
| 566 | + return $file->getTempName(); |
569 | 567 | } |
570 | 568 | |
571 | 569 | /** |
572 | 570 | * Return the size of the upload, or 0. |
| 571 | + * @deprecated |
573 | 572 | * @param $key String: |
574 | 573 | * @return integer |
575 | 574 | */ |
576 | 575 | public function getFileSize( $key ) { |
577 | | - if( !isset( $_FILES[$key] ) ) { |
578 | | - return 0; |
579 | | - } |
580 | | - return $_FILES[$key]['size']; |
| 576 | + $file = new WebRequestUpload( $key ); |
| 577 | + return $file->getSize(); |
581 | 578 | } |
582 | 579 | |
583 | 580 | /** |
— | — | @@ -585,10 +582,8 @@ |
586 | 583 | * @return integer |
587 | 584 | */ |
588 | 585 | public function getUploadError( $key ) { |
589 | | - if( !isset( $_FILES[$key] ) || !isset( $_FILES[$key]['error'] ) ) { |
590 | | - return 0/*UPLOAD_ERR_OK*/; |
591 | | - } |
592 | | - return $_FILES[$key]['error']; |
| 586 | + $file = new WebRequestUpload( $key ); |
| 587 | + return $file->getError(); |
593 | 588 | } |
594 | 589 | |
595 | 590 | /** |
— | — | @@ -603,19 +598,19 @@ |
604 | 599 | * @return string or NULL if no such file. |
605 | 600 | */ |
606 | 601 | public function getFileName( $key ) { |
607 | | - global $wgContLang; |
608 | | - if( !isset( $_FILES[$key] ) ) { |
609 | | - return null; |
610 | | - } |
611 | | - $name = $_FILES[$key]['name']; |
612 | | - |
613 | | - # Safari sends filenames in HTML-encoded Unicode form D... |
614 | | - # Horrid and evil! Let's try to make some kind of sense of it. |
615 | | - $name = Sanitizer::decodeCharReferences( $name ); |
616 | | - $name = $wgContLang->normalize( $name ); |
617 | | - wfDebug( "WebRequest::getFileName() '" . $_FILES[$key]['name'] . "' normalized to '$name'\n" ); |
618 | | - return $name; |
| 602 | + $file = new WebRequestUpload( $key ); |
| 603 | + return $file->getName(); |
619 | 604 | } |
| 605 | + |
| 606 | + /** |
| 607 | + * Return a WebRequestUpload object corresponding to the key |
| 608 | + * |
| 609 | + * @param @key string |
| 610 | + * @return WebRequestUpload |
| 611 | + */ |
| 612 | + public function getUpload( $key ) { |
| 613 | + return new WebRequestUpload( $key ); |
| 614 | + } |
620 | 615 | |
621 | 616 | /** |
622 | 617 | * Return a handle to WebResponse style object, for setting cookies, |
— | — | @@ -706,6 +701,96 @@ |
707 | 702 | } |
708 | 703 | |
709 | 704 | /** |
| 705 | + * Object to access the $_FILES array |
| 706 | + */ |
| 707 | +class WebRequestUpload { |
| 708 | + protected $doesExist; |
| 709 | + protected $fileInfo; |
| 710 | + |
| 711 | + /** |
| 712 | + * Constructor. Should only be called by WebRequest |
| 713 | + * |
| 714 | + * @param $key string Key in $_FILES array (name of form field) |
| 715 | + */ |
| 716 | + public function __construct( $key ) { |
| 717 | + $this->doesExist = isset( $_FILES[$key] ); |
| 718 | + if ( $this->doesExist ) { |
| 719 | + $this->fileInfo = $_FILES[$key]; |
| 720 | + } |
| 721 | + } |
| 722 | + |
| 723 | + /** |
| 724 | + * Return whether a file with this name was uploaded. |
| 725 | + * |
| 726 | + * @return bool |
| 727 | + */ |
| 728 | + public function exists() { |
| 729 | + return $this->doesExist; |
| 730 | + } |
| 731 | + |
| 732 | + /** |
| 733 | + * Return the original filename of the uploaded file |
| 734 | + * |
| 735 | + * @return mixed Filename or null if non-existent |
| 736 | + */ |
| 737 | + public function getName() { |
| 738 | + if ( !$this->exists() ) { |
| 739 | + return null; |
| 740 | + } |
| 741 | + |
| 742 | + global $wgContLang; |
| 743 | + $name = $this->fileInfo['name']; |
| 744 | + |
| 745 | + # Safari sends filenames in HTML-encoded Unicode form D... |
| 746 | + # Horrid and evil! Let's try to make some kind of sense of it. |
| 747 | + $name = Sanitizer::decodeCharReferences( $name ); |
| 748 | + $name = $wgContLang->normalize( $name ); |
| 749 | + wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" ); |
| 750 | + return $name; |
| 751 | + } |
| 752 | + |
| 753 | + /** |
| 754 | + * Return the file size of the uploaded file |
| 755 | + * |
| 756 | + * @return int File size or zero if non-existent |
| 757 | + */ |
| 758 | + public function getSize() { |
| 759 | + if ( !$this->exists() ) { |
| 760 | + return 0; |
| 761 | + } |
| 762 | + |
| 763 | + return $this->fileInfo['size']; |
| 764 | + } |
| 765 | + |
| 766 | + /** |
| 767 | + * Return the path to the temporary file |
| 768 | + * |
| 769 | + * @return mixed Path or null if non-existent |
| 770 | + */ |
| 771 | + public function getTempName() { |
| 772 | + if ( !$this->exists() ) { |
| 773 | + return null; |
| 774 | + } |
| 775 | + |
| 776 | + return $this->fileInfo['tmp_name']; |
| 777 | + } |
| 778 | + |
| 779 | + /** |
| 780 | + * Return the upload error. See link for explanation |
| 781 | + * http://www.php.net/manual/en/features.file-upload.errors.php |
| 782 | + * |
| 783 | + * @return int One of the UPLOAD_ constants, 0 if non-existent |
| 784 | + */ |
| 785 | + public function getError() { |
| 786 | + if ( !$this->exists() ) { |
| 787 | + return 0; # UPLOAD_ERR_OK |
| 788 | + } |
| 789 | + |
| 790 | + return $this->fileInfo['error']; |
| 791 | + } |
| 792 | +} |
| 793 | + |
| 794 | +/** |
710 | 795 | * WebRequest clone which takes values from a provided array. |
711 | 796 | * |
712 | 797 | * @ingroup HTTP |
Property changes on: branches/uploadwizard-deployment/includes/WebRequest.php |
___________________________________________________________________ |
Added: svn:mergeinfo |
713 | 798 | Merged /branches/REL1_15/phase3/includes/WebRequest.php:r51646 |
714 | 799 | Merged /branches/sqlite/includes/WebRequest.php:r58211-58321 |
715 | 800 | Merged /trunk/phase3/includes/WebRequest.php:r63549,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,70037,71059,71098,71942,72024,72120,72525 |
716 | 801 | Merged /branches/wmf-deployment/includes/WebRequest.php:r53381,60970 |
Index: branches/uploadwizard-deployment/includes/AutoLoader.php |
— | — | @@ -241,6 +241,7 @@ |
242 | 242 | 'WatchedItem' => 'includes/WatchedItem.php', |
243 | 243 | 'WatchlistEditor' => 'includes/WatchlistEditor.php', |
244 | 244 | 'WebRequest' => 'includes/WebRequest.php', |
| 245 | + 'WebRequestUpload' => 'includes/WebRequest.php', |
245 | 246 | 'WebResponse' => 'includes/WebResponse.php', |
246 | 247 | 'WikiError' => 'includes/WikiError.php', |
247 | 248 | 'WikiErrorMsg' => 'includes/WikiError.php', |
Property changes on: branches/uploadwizard-deployment/includes/AutoLoader.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
248 | 249 | Merged /trunk/phase3/includes/AutoLoader.php:r70037 |