Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/248357

Change subject: Work around broken HHVM ini_get() for 'upload_max_filesize' and 
'post_max_size'
......................................................................

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().

Bug: T116347
Change-Id: Idf707253eeae1b90792a7e26d2ab66d1317e67ae
---
M RELEASE-NOTES-1.27
M includes/Setup.php
M includes/WebRequestUpload.php
M includes/specials/SpecialUpload.php
M includes/upload/UploadBase.php
M includes/upload/UploadFromFile.php
6 files changed, 42 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/57/248357/1

diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27
index f8293b9..d334338 100644
--- a/RELEASE-NOTES-1.27
+++ b/RELEASE-NOTES-1.27
@@ -67,6 +67,8 @@
 ==== 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 fbfef1f..6877c20 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -377,9 +377,13 @@
 // 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(),
+       // Leave some room for other POST parameters
+       ( wfShorthandToInteger(
+               ini_get( 'post_max_size' ) ?: ini_get( 
'hhvm.server.max_post_size' ),
+               1e100
+       ) ?: 1e100 ) - 1024
 );
 
 /**
diff --git a/includes/WebRequestUpload.php b/includes/WebRequestUpload.php
index e743d9d..c99b0e3 100644
--- a/includes/WebRequestUpload.php
+++ b/includes/WebRequestUpload.php
@@ -127,7 +127,12 @@
                }
 
                $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 6692bb6..c8c4642 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -890,15 +890,10 @@
                        );
                }
 
-               $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 f600e32..e56c0c9 100644
--- a/includes/upload/UploadBase.php
+++ b/includes/upload/UploadBase.php
@@ -1919,6 +1919,9 @@
        }
 
        /**
+        * Get the MediaWiki maximum uploaded file size for given type of 
upload, based on
+        * $wgMaxUploadSize.
+        *
         * @param null|string $forType
         * @return int
         */
@@ -1937,6 +1940,25 @@
        }
 
        /**
+        * 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.
+        *
+        * @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' ),
+                       1e100
+               );
+               $phpMaxPostSize = wfShorthandToInteger(
+                       ini_get( 'post_max_size' ) ?: ini_get( 
'hhvm.server.max_post_size' ),
+                       1e100
+               ) ?: 1e100;
+               return min( $phpMaxFileSize, $phpMaxPostSize );
+       }
+
+       /**
         * Get the current status of a chunked upload (used for polling)
         *
         * The value will be read from cache.
diff --git a/includes/upload/UploadFromFile.php 
b/includes/upload/UploadFromFile.php
index 3a1e8bd..1607cb6 100644
--- a/includes/upload/UploadFromFile.php
+++ b/includes/upload/UploadFromFile.php
@@ -86,8 +86,7 @@
                                        '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()
                                        ),
                                );
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/248357
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf707253eeae1b90792a7e26d2ab66d1317e67ae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to