r70043 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70042‎ | r70043 | r70044 >
Date:20:54, 27 July 2010
Author:btongminh
Status:ok
Tags:
Comment:
Follow-up r70037: Move isIniSizeOverflow magic to WebRequestUpload
Modified paths:
  • /trunk/phase3/includes/WebRequest.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromFile.php
@@ -38,21 +38,14 @@
3939 # Check for a post_max_size or upload_max_size overflow, so that a
4040 # proper error can be shown to the user
4141 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
42 - # Using the Content-length header is not an absolutely fail-safe
43 - # method, but the only available option. Otherwise broken uploads
44 - # will be handled by the parent method and return empty-file
45 - $contentLength = intval( $_SERVER['CONTENT_LENGTH'] );
46 - $maxPostSize = wfShorthandToInteger( ini_get( 'post_max_size' ) );
47 - if ( $this->mWebUpload->getError() == UPLOAD_ERR_INI_SIZE
48 - || $contentLength > $maxPostSize ) {
49 -
 42+ if ( $this->mWebUpload->isIniSizeOverflow() ) {
5043 global $wgMaxUploadSize;
5144 return array(
5245 'status' => self::FILE_TOO_LARGE,
5346 'max' => min(
5447 $wgMaxUploadSize,
5548 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
56 - $maxPostSize
 49+ wfShorthandToInteger( ini_get( 'post_max_size' ) )
5750 ),
5851 );
5952 }
Index: trunk/phase3/includes/WebRequest.php
@@ -590,7 +590,7 @@
591591 * @return string or NULL if no such file.
592592 */
593593 public function getFileTempname( $key ) {
594 - $file = new WebRequestUpload( $key );
 594+ $file = new WebRequestUpload( $this, $key );
595595 return $file->getTempName();
596596 }
597597
@@ -602,7 +602,7 @@
603603 * @return integer
604604 */
605605 public function getFileSize( $key ) {
606 - $file = new WebRequestUpload( $key );
 606+ $file = new WebRequestUpload( $this, $key );
607607 return $file->getSize();
608608 }
609609
@@ -613,7 +613,7 @@
614614 * @return integer
615615 */
616616 public function getUploadError( $key ) {
617 - $file = new WebRequestUpload( $key );
 617+ $file = new WebRequestUpload( $this, $key );
618618 return $file->getError();
619619 }
620620
@@ -629,7 +629,7 @@
630630 * @return string or NULL if no such file.
631631 */
632632 public function getFileName( $key ) {
633 - $file = new WebRequestUpload( $key );
 633+ $file = new WebRequestUpload( $this, $key );
634634 return $file->getName();
635635 }
636636
@@ -640,7 +640,7 @@
641641 * @return WebRequestUpload
642642 */
643643 public function getUpload( $key ) {
644 - return new WebRequestUpload( $key );
 644+ return new WebRequestUpload( $this, $key );
645645 }
646646
647647 /**
@@ -675,6 +675,9 @@
676676 }
677677 } else {
678678 $name = 'HTTP_' . str_replace( '-', '_', $name );
 679+ if ( $name === 'HTTP_CONTENT_LENGTH' && !isset( $_SERVER[$name] ) ) {
 680+ $name = 'CONTENT_LENGTH';
 681+ }
679682 if ( isset( $_SERVER[$name] ) ) {
680683 return $_SERVER[$name];
681684 } else {
@@ -768,15 +771,18 @@
769772 * Object to access the $_FILES array
770773 */
771774 class WebRequestUpload {
 775+ protected $request;
772776 protected $doesExist;
773777 protected $fileInfo;
774778
775779 /**
776780 * Constructor. Should only be called by WebRequest
777781 *
 782+ * @param $request WebRequest The associated request
778783 * @param $key string Key in $_FILES array (name of form field)
779784 */
780 - public function __construct( $key ) {
 785+ public function __construct( $request, $key ) {
 786+ $this->request = $request;
781787 $this->doesExist = isset( $_FILES[$key] );
782788 if ( $this->doesExist ) {
783789 $this->fileInfo = $_FILES[$key];
@@ -852,6 +858,27 @@
853859
854860 return $this->fileInfo['error'];
855861 }
 862+
 863+ /**
 864+ * Returns whether this upload failed because of overflow of a maximum set
 865+ * in php.ini
 866+ *
 867+ * @return bool
 868+ */
 869+ public function isIniSizeOverflow() {
 870+ if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
 871+ # PHP indicated that upload_max_filesize is exceeded
 872+ return true;
 873+ }
 874+
 875+ $contentLength = $this->request->getHeader( 'CONTENT_LENGTH' );
 876+ if ( $contentLength > wfShorthandToInteger( ini_get( 'post_max_size' ) ) ) {
 877+ # post_max_size is exceeded
 878+ return true;
 879+ }
 880+
 881+ return false;
 882+ }
856883 }
857884
858885 /**

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