http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70043
Revision: 70043
Author: btongminh
Date: 2010-07-27 20:54:34 +0000 (Tue, 27 Jul 2010)
Log Message:
-----------
Follow-up r70037: Move isIniSizeOverflow magic to WebRequestUpload
Modified Paths:
--------------
trunk/phase3/includes/WebRequest.php
trunk/phase3/includes/upload/UploadFromFile.php
Modified: trunk/phase3/includes/WebRequest.php
===================================================================
--- trunk/phase3/includes/WebRequest.php 2010-07-27 20:47:16 UTC (rev
70042)
+++ trunk/phase3/includes/WebRequest.php 2010-07-27 20:54:34 UTC (rev
70043)
@@ -590,7 +590,7 @@
* @return string or NULL if no such file.
*/
public function getFileTempname( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getTempName();
}
@@ -602,7 +602,7 @@
* @return integer
*/
public function getFileSize( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getSize();
}
@@ -613,7 +613,7 @@
* @return integer
*/
public function getUploadError( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getError();
}
@@ -629,7 +629,7 @@
* @return string or NULL if no such file.
*/
public function getFileName( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getName();
}
@@ -640,7 +640,7 @@
* @return WebRequestUpload
*/
public function getUpload( $key ) {
- return new WebRequestUpload( $key );
+ return new WebRequestUpload( $this, $key );
}
/**
@@ -675,6 +675,9 @@
}
} else {
$name = 'HTTP_' . str_replace( '-', '_', $name );
+ if ( $name === 'HTTP_CONTENT_LENGTH' && !isset(
$_SERVER[$name] ) ) {
+ $name = 'CONTENT_LENGTH';
+ }
if ( isset( $_SERVER[$name] ) ) {
return $_SERVER[$name];
} else {
@@ -768,15 +771,18 @@
* Object to access the $_FILES array
*/
class WebRequestUpload {
+ protected $request;
protected $doesExist;
protected $fileInfo;
/**
* Constructor. Should only be called by WebRequest
*
+ * @param $request WebRequest The associated request
* @param $key string Key in $_FILES array (name of form field)
*/
- public function __construct( $key ) {
+ public function __construct( $request, $key ) {
+ $this->request = $request;
$this->doesExist = isset( $_FILES[$key] );
if ( $this->doesExist ) {
$this->fileInfo = $_FILES[$key];
@@ -852,6 +858,27 @@
return $this->fileInfo['error'];
}
+
+ /**
+ * Returns whether this upload failed because of overflow of a maximum
set
+ * in php.ini
+ *
+ * @return bool
+ */
+ public function isIniSizeOverflow() {
+ if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
+ # PHP indicated that upload_max_filesize is exceeded
+ return true;
+ }
+
+ $contentLength = $this->request->getHeader( 'CONTENT_LENGTH' );
+ if ( $contentLength > wfShorthandToInteger( ini_get(
'post_max_size' ) ) ) {
+ # post_max_size is exceeded
+ return true;
+ }
+
+ return false;
+ }
}
/**
Modified: trunk/phase3/includes/upload/UploadFromFile.php
===================================================================
--- trunk/phase3/includes/upload/UploadFromFile.php 2010-07-27 20:47:16 UTC
(rev 70042)
+++ trunk/phase3/includes/upload/UploadFromFile.php 2010-07-27 20:54:34 UTC
(rev 70043)
@@ -38,21 +38,14 @@
# Check for a post_max_size or upload_max_size overflow, so
that a
# proper error can be shown to the user
if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
- # Using the Content-length header is not an absolutely
fail-safe
- # method, but the only available option. Otherwise
broken uploads
- # will be handled by the parent method and return
empty-file
- $contentLength = intval( $_SERVER['CONTENT_LENGTH'] );
- $maxPostSize = wfShorthandToInteger( ini_get(
'post_max_size' ) );
- if ( $this->mWebUpload->getError() ==
UPLOAD_ERR_INI_SIZE
- || $contentLength > $maxPostSize ) {
-
+ if ( $this->mWebUpload->isIniSizeOverflow() ) {
global $wgMaxUploadSize;
return array(
'status' => self::FILE_TOO_LARGE,
'max' => min(
$wgMaxUploadSize,
wfShorthandToInteger( ini_get(
'upload_max_filesize' ) ),
- $maxPostSize
+ wfShorthandToInteger( ini_get(
'post_max_size' ) )
),
);
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs