From: Bartosz DziewoƄski Date: Fri, 23 Oct 2015 16:03:43 +0000 (+0200) Subject: Work around broken HHVM ini_get() for 'upload_max_filesize' and 'post_max_size' X-Git-Tag: 1.31.0-rc.0~9059^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=ed6648427a86d6893deb219081a96e337a1141cb;p=lhc%2Fweb%2Fwiklou.git Work around broken HHVM ini_get() for 'upload_max_filesize' and 'post_max_size' In HHVM, the settings 'upload_max_filesize' and 'post_max_size' are not available via ini_get() due to some long-standing bug (https://github.com/facebook/hhvm/issues/4993). Instead, one can use 'hhvm.server.upload.upload_max_file_size' and 'hhvm.server.max_post_size' (in a typical PHP fashion, their names are subtly different than the originals as to increase the potential for confusion). Added a new method UploadBase::getMaxPhpUploadSize() to handle this. Additionally: * 'post_max_size' can be set to 0, which is equivalent to no limit. Handle this correctly. * $wgMaxUploadSize can be an array structure, instead of just a number. Handle this correctly by using UploadBase::getMaxUploadSize(). * When no maximum is set, use PHP_INT_MAX rather than 1e100. It should be big enough, and the latter is a float, results in 0 when cast to int, and doesn't look as pretty when formatted in GB in the interface. Bug: T116347 Change-Id: Idf707253eeae1b90792a7e26d2ab66d1317e67ae --- diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27 index 76f8ba311d..442e70d624 100644 --- a/RELEASE-NOTES-1.27 +++ b/RELEASE-NOTES-1.27 @@ -77,6 +77,8 @@ production. ==== External libraries ==== === Bug fixes in 1.27 === +* Special:Upload will now display correct maximum allowed file size when running + under HHVM (T116347). === Action API changes in 1.27 === * Added list=allrevisions. diff --git a/includes/Setup.php b/includes/Setup.php index 69a041e000..355b03a71e 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -380,9 +380,12 @@ if ( $wgResourceLoaderMaxQueryLength === false ) { // upload size. $wgMinUploadChunkSize = min( $wgMinUploadChunkSize, - $wgMaxUploadSize, - wfShorthandToInteger( ini_get( 'upload_max_filesize' ), 1e100 ), - wfShorthandToInteger( ini_get( 'post_max_size' ), 1e100 ) - 1024 # Leave room for other parameters + UploadBase::getMaxUploadSize( 'file' ), + UploadBase::getMaxPhpUploadSize(), + ( wfShorthandToInteger( + ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ), + PHP_INT_MAX + ) ?: PHP_INT_MAX ) - 1024 // Leave some room for other POST parameters ); /** diff --git a/includes/WebRequestUpload.php b/includes/WebRequestUpload.php index e743d9de16..c99b0e3256 100644 --- a/includes/WebRequestUpload.php +++ b/includes/WebRequestUpload.php @@ -127,7 +127,12 @@ class WebRequestUpload { } $contentLength = $this->request->getHeader( 'CONTENT_LENGTH' ); - if ( $contentLength > wfShorthandToInteger( ini_get( 'post_max_size' ) ) ) { + $maxPostSize = wfShorthandToInteger( + ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ), + 0 + ); + + if ( $maxPostSize && $contentLength > $maxPostSize ) { # post_max_size is exceeded return true; } diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 6692bb6029..c8c464274b 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -890,15 +890,10 @@ class UploadForm extends HTMLForm { ); } - $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize( 'file' ); - # Limit to upload_max_filesize unless we are running under HipHop and - # that setting doesn't exist - if ( !wfIsHHVM() ) { - $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'], - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), - wfShorthandToInteger( ini_get( 'post_max_size' ) ) - ); - } + $this->mMaxUploadSize['file'] = min( + UploadBase::getMaxUploadSize( 'file' ), + UploadBase::getMaxPhpUploadSize() + ); $help = $this->msg( 'upload-maxfilesize', $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] ) diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 17fcab8b09..f8624d02c5 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1919,6 +1919,9 @@ abstract class UploadBase { } /** + * Get the MediaWiki maximum uploaded file size for given type of upload, based on + * $wgMaxUploadSize. + * * @param null|string $forType * @return int */ @@ -1936,6 +1939,25 @@ abstract class UploadBase { } } + /** + * Get the PHP maximum uploaded file size, based on ini settings. If there is no limit or the + * limit can't be guessed, returns a very large number (PHP_INT_MAX). + * + * @since 1.27 + * @return int + */ + public static function getMaxPhpUploadSize() { + $phpMaxFileSize = wfShorthandToInteger( + ini_get( 'upload_max_filesize' ) ?: ini_get( 'hhvm.server.upload.upload_max_file_size' ), + PHP_INT_MAX + ); + $phpMaxPostSize = wfShorthandToInteger( + ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ), + PHP_INT_MAX + ) ?: PHP_INT_MAX; + return min( $phpMaxFileSize, $phpMaxPostSize ); + } + /** * Get the current status of a chunked upload (used for polling) * diff --git a/includes/upload/UploadFromFile.php b/includes/upload/UploadFromFile.php index 3a1e8bdcea..1607cb6f02 100644 --- a/includes/upload/UploadFromFile.php +++ b/includes/upload/UploadFromFile.php @@ -86,8 +86,7 @@ class UploadFromFile extends UploadBase { 'status' => UploadBase::FILE_TOO_LARGE, 'max' => min( self::getMaxUploadSize( $this->getSourceType() ), - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), - wfShorthandToInteger( ini_get( 'post_max_size' ) ) + self::getMaxPhpUploadSize() ), ); }