r76093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76092‎ | r76093 | r76094 >
Date:14:02, 5 November 2010
Author:catrope
Status:deferred
Tags:
Comment:
Merge the WebRequest part of r70037 to unbreak UploadStash
Modified paths:
  • /branches/uploadwizard-deployment/includes/AutoLoader.php (modified) (history)
  • /branches/uploadwizard-deployment/includes/WebRequest.php (modified) (history)

Diff [purge]

Index: branches/uploadwizard-deployment/includes/WebRequest.php
@@ -561,22 +561,19 @@
562562 * @return string or NULL if no such file.
563563 */
564564 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();
569567 }
570568
571569 /**
572570 * Return the size of the upload, or 0.
 571+ * @deprecated
573572 * @param $key String:
574573 * @return integer
575574 */
576575 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();
581578 }
582579
583580 /**
@@ -585,10 +582,8 @@
586583 * @return integer
587584 */
588585 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();
593588 }
594589
595590 /**
@@ -603,19 +598,19 @@
604599 * @return string or NULL if no such file.
605600 */
606601 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();
619604 }
 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+ }
620615
621616 /**
622617 * Return a handle to WebResponse style object, for setting cookies,
@@ -706,6 +701,96 @@
707702 }
708703
709704 /**
 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+/**
710795 * WebRequest clone which takes values from a provided array.
711796 *
712797 * @ingroup HTTP
Property changes on: branches/uploadwizard-deployment/includes/WebRequest.php
___________________________________________________________________
Added: svn:mergeinfo
713798 Merged /branches/REL1_15/phase3/includes/WebRequest.php:r51646
714799 Merged /branches/sqlite/includes/WebRequest.php:r58211-58321
715800 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
716801 Merged /branches/wmf-deployment/includes/WebRequest.php:r53381,60970
Index: branches/uploadwizard-deployment/includes/AutoLoader.php
@@ -241,6 +241,7 @@
242242 'WatchedItem' => 'includes/WatchedItem.php',
243243 'WatchlistEditor' => 'includes/WatchlistEditor.php',
244244 'WebRequest' => 'includes/WebRequest.php',
 245+ 'WebRequestUpload' => 'includes/WebRequest.php',
245246 'WebResponse' => 'includes/WebResponse.php',
246247 'WikiError' => 'includes/WikiError.php',
247248 'WikiErrorMsg' => 'includes/WikiError.php',
Property changes on: branches/uploadwizard-deployment/includes/AutoLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
248249 Merged /trunk/phase3/includes/AutoLoader.php:r70037

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70037(bug 23380) Uploaded files that are larger than allowed by PHP now show a use...btongminh20:38, 27 July 2010

Status & tagging log