r79749 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79748‎ | r79749 | r79750 >
Date:19:42, 6 January 2011
Author:btongminh
Status:ok
Tags:
Comment:
$wgMaxUploadSize may now be set to an array to specify the upload size limit per upload type.

Backwards compatible, if not set to an array, applies to all uploads. If set to an array, per upload type maximums can be set, using the file and url keys. If the * key is set this value will be used as maximum for non-specified types.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromFile.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromStash.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromUrl.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadFromStash.php
@@ -41,6 +41,8 @@
4242 $this->mSessionKey = $sessionKey;
4343 $this->mVirtualTempPath = $sessionData['mTempPath'];
4444 $this->mFileProps = $sessionData['mFileProps'];
 45+ $this->mSourceType = isset( $sessionData['mSourceType'] ) ?
 46+ $sessionData['mSourceType'] : null;
4547 }
4648
4749 public function initializeFromRequest( &$request ) {
@@ -53,6 +55,10 @@
5456 return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] );
5557 }
5658
 59+ public function getSourceType() {
 60+ return $this->mSourceType;
 61+ }
 62+
5763 /**
5864 * File has been previously verified so no need to do so again.
5965 */
Index: trunk/phase3/includes/upload/UploadFromUrl.php
@@ -78,6 +78,7 @@
7979 && $wgUser->isAllowed( 'upload_by_url' );
8080 }
8181
 82+ public function getSourceType() { return 'url'; }
8283
8384 public function fetchFile() {
8485 if ( !Http::isValidURI( $this->mUrl ) ) {
Index: trunk/phase3/includes/upload/UploadBase.php
@@ -142,6 +142,14 @@
143143 }
144144
145145 public function __construct() {}
 146+
 147+ /**
 148+ * Returns the upload type. Should be overridden by child classes
 149+ *
 150+ * @since 1.18
 151+ * @return string
 152+ */
 153+ public function getSourceType() { return null; }
146154
147155 /**
148156 * Initialize the path information
@@ -226,11 +234,11 @@
227235 /**
228236 * Honor $wgMaxUploadSize
229237 */
230 - global $wgMaxUploadSize;
231 - if( $this->mFileSize > $wgMaxUploadSize ) {
 238+ $maxSize = self::getMaxUploadSize( $this->getSourceType() );
 239+ if( $this->mFileSize > $maxSize ) {
232240 return array(
233241 'status' => self::FILE_TOO_LARGE,
234 - 'max' => $wgMaxUploadSize,
 242+ 'max' => $maxSize,
235243 );
236244 }
237245
@@ -629,7 +637,8 @@
630638 public function stashSessionFile( $key = null ) {
631639 $stash = new UploadStash();
632640 $data = array(
633 - 'mFileProps' => $this->mFileProps
 641+ 'mFileProps' => $this->mFileProps,
 642+ 'mSourceType' => $this->getSourceType(),
634643 );
635644 $file = $stash->stashFile( $this->mTempPath, $data, $key );
636645 $this->mLocalFile = $file;
@@ -1220,4 +1229,19 @@
12211230 unset( $code['status'] );
12221231 return Status::newFatal( $this->getVerificationErrorCode( $code ), $error );
12231232 }
 1233+
 1234+ public static function getMaxUploadSize( $forType = null ) {
 1235+ global $wgMaxUploadSize;
 1236+
 1237+ if ( is_array( $wgMaxUploadSize ) ) {
 1238+ if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) {
 1239+ return $wgMaxUploadSize[$forType];
 1240+ } else {
 1241+ return $wgMaxUploadSize['*'];
 1242+ }
 1243+ } else {
 1244+ return intval( $wgMaxUploadSize );
 1245+ }
 1246+
 1247+ }
12241248 }
Index: trunk/phase3/includes/upload/UploadFromFile.php
@@ -33,16 +33,17 @@
3434 return true;
3535 }
3636
 37+ public function getSourceType() { return 'file'; }
 38+
3739 public function verifyUpload() {
3840 # Check for a post_max_size or upload_max_size overflow, so that a
3941 # proper error can be shown to the user
4042 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
4143 if ( $this->mUpload->isIniSizeOverflow() ) {
42 - global $wgMaxUploadSize;
4344 return array(
4445 'status' => UploadBase::FILE_TOO_LARGE,
4546 'max' => min(
46 - $wgMaxUploadSize,
 47+ self::getMaxUploadSize( $this->getSourceType() ),
4748 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
4849 wfShorthandToInteger( ini_get( 'post_max_size' ) )
4950 ),
Index: trunk/phase3/includes/DefaultSettings.php
@@ -439,7 +439,19 @@
440440 $wgAllowAsyncCopyUploads = false;
441441
442442 /**
443 - * Max size for uploads, in bytes. Applies to all uploads.
 443+ * Max size for uploads, in bytes. If not set to an array, applies to all
 444+ * uploads. If set to an array, per upload type maximums can be set, using the
 445+ * file and url keys. If the * key is set this value will be used as maximum
 446+ * for non-specified types.
 447+ *
 448+ * For example:
 449+ * $wgUploadSize = array(
 450+ * '*' => 250 * 1024,
 451+ * 'url' => 500 * 1024,
 452+ * );
 453+ * Sets the maximum for all uploads to 250 kB except for upload-by-url, which
 454+ * will have a maximum of 500 kB.
 455+ *
444456 */
445457 $wgMaxUploadSize = 1024*1024*100; # 100MB
446458
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -812,7 +812,6 @@
813813 */
814814 protected function getSourceSection() {
815815 global $wgLang, $wgUser, $wgRequest;
816 - global $wgMaxUploadSize;
817816
818817 if ( $this->mSessionKey ) {
819818 return array(
@@ -855,7 +854,7 @@
856855 wfShorthandToInteger( min(
857856 wfShorthandToInteger(
858857 ini_get( 'upload_max_filesize' )
859 - ), $wgMaxUploadSize
 858+ ), UploadBase::getMaxUploadSize( 'file' )
860859 ) )
861860 )
862861 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
@@ -871,7 +870,7 @@
872871 'radio' => &$radio,
873872 'help' => wfMsgExt( 'upload-maxfilesize',
874873 array( 'parseinline', 'escapenoentities' ),
875 - $wgLang->formatSize( $wgMaxUploadSize )
 874+ $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
876875 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
877876 'checked' => $selectedSourceType == 'url',
878877 );
Index: trunk/phase3/RELEASE-NOTES
@@ -31,6 +31,8 @@
3232 note that this changes the cache key making all old entries in the parser cache invalid you
3333 can set $wgUseEditSectionTokens to false to disable this and keep your old parser cache entries.
3434 Note that this feature should reduce parser cache fragmentation when enabled.
 35+* $wgMaxUploadSize may now be set to an array to specify the upload size limit
 36+ per upload type.
3537
3638 === New features in 1.18 ===
3739 * Added a special page, disabled by default, that allows users with the

Follow-up revisions

RevisionCommit summaryAuthorDate
r95681MFT of r79749 - needed to make other fixes for fatals in UploadStash workneilk17:56, 29 August 2011

Status & tagging log