Index: trunk/phase3/includes/upload/UploadFromStash.php |
— | — | @@ -41,6 +41,8 @@ |
42 | 42 | $this->mSessionKey = $sessionKey; |
43 | 43 | $this->mVirtualTempPath = $sessionData['mTempPath']; |
44 | 44 | $this->mFileProps = $sessionData['mFileProps']; |
| 45 | + $this->mSourceType = isset( $sessionData['mSourceType'] ) ? |
| 46 | + $sessionData['mSourceType'] : null; |
45 | 47 | } |
46 | 48 | |
47 | 49 | public function initializeFromRequest( &$request ) { |
— | — | @@ -53,6 +55,10 @@ |
54 | 56 | return $this->initialize( $desiredDestName, $sessionKey, $sessionData[$sessionKey] ); |
55 | 57 | } |
56 | 58 | |
| 59 | + public function getSourceType() { |
| 60 | + return $this->mSourceType; |
| 61 | + } |
| 62 | + |
57 | 63 | /** |
58 | 64 | * File has been previously verified so no need to do so again. |
59 | 65 | */ |
Index: trunk/phase3/includes/upload/UploadFromUrl.php |
— | — | @@ -78,6 +78,7 @@ |
79 | 79 | && $wgUser->isAllowed( 'upload_by_url' ); |
80 | 80 | } |
81 | 81 | |
| 82 | + public function getSourceType() { return 'url'; } |
82 | 83 | |
83 | 84 | public function fetchFile() { |
84 | 85 | if ( !Http::isValidURI( $this->mUrl ) ) { |
Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -142,6 +142,14 @@ |
143 | 143 | } |
144 | 144 | |
145 | 145 | 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; } |
146 | 154 | |
147 | 155 | /** |
148 | 156 | * Initialize the path information |
— | — | @@ -226,11 +234,11 @@ |
227 | 235 | /** |
228 | 236 | * Honor $wgMaxUploadSize |
229 | 237 | */ |
230 | | - global $wgMaxUploadSize; |
231 | | - if( $this->mFileSize > $wgMaxUploadSize ) { |
| 238 | + $maxSize = self::getMaxUploadSize( $this->getSourceType() ); |
| 239 | + if( $this->mFileSize > $maxSize ) { |
232 | 240 | return array( |
233 | 241 | 'status' => self::FILE_TOO_LARGE, |
234 | | - 'max' => $wgMaxUploadSize, |
| 242 | + 'max' => $maxSize, |
235 | 243 | ); |
236 | 244 | } |
237 | 245 | |
— | — | @@ -629,7 +637,8 @@ |
630 | 638 | public function stashSessionFile( $key = null ) { |
631 | 639 | $stash = new UploadStash(); |
632 | 640 | $data = array( |
633 | | - 'mFileProps' => $this->mFileProps |
| 641 | + 'mFileProps' => $this->mFileProps, |
| 642 | + 'mSourceType' => $this->getSourceType(), |
634 | 643 | ); |
635 | 644 | $file = $stash->stashFile( $this->mTempPath, $data, $key ); |
636 | 645 | $this->mLocalFile = $file; |
— | — | @@ -1220,4 +1229,19 @@ |
1221 | 1230 | unset( $code['status'] ); |
1222 | 1231 | return Status::newFatal( $this->getVerificationErrorCode( $code ), $error ); |
1223 | 1232 | } |
| 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 | + } |
1224 | 1248 | } |
Index: trunk/phase3/includes/upload/UploadFromFile.php |
— | — | @@ -33,16 +33,17 @@ |
34 | 34 | return true; |
35 | 35 | } |
36 | 36 | |
| 37 | + public function getSourceType() { return 'file'; } |
| 38 | + |
37 | 39 | public function verifyUpload() { |
38 | 40 | # Check for a post_max_size or upload_max_size overflow, so that a |
39 | 41 | # proper error can be shown to the user |
40 | 42 | if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) { |
41 | 43 | if ( $this->mUpload->isIniSizeOverflow() ) { |
42 | | - global $wgMaxUploadSize; |
43 | 44 | return array( |
44 | 45 | 'status' => UploadBase::FILE_TOO_LARGE, |
45 | 46 | 'max' => min( |
46 | | - $wgMaxUploadSize, |
| 47 | + self::getMaxUploadSize( $this->getSourceType() ), |
47 | 48 | wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), |
48 | 49 | wfShorthandToInteger( ini_get( 'post_max_size' ) ) |
49 | 50 | ), |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -439,7 +439,19 @@ |
440 | 440 | $wgAllowAsyncCopyUploads = false; |
441 | 441 | |
442 | 442 | /** |
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 | + * |
444 | 456 | */ |
445 | 457 | $wgMaxUploadSize = 1024*1024*100; # 100MB |
446 | 458 | |
Index: trunk/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -812,7 +812,6 @@ |
813 | 813 | */ |
814 | 814 | protected function getSourceSection() { |
815 | 815 | global $wgLang, $wgUser, $wgRequest; |
816 | | - global $wgMaxUploadSize; |
817 | 816 | |
818 | 817 | if ( $this->mSessionKey ) { |
819 | 818 | return array( |
— | — | @@ -855,7 +854,7 @@ |
856 | 855 | wfShorthandToInteger( min( |
857 | 856 | wfShorthandToInteger( |
858 | 857 | ini_get( 'upload_max_filesize' ) |
859 | | - ), $wgMaxUploadSize |
| 858 | + ), UploadBase::getMaxUploadSize( 'file' ) |
860 | 859 | ) ) |
861 | 860 | ) |
862 | 861 | ) . ' ' . wfMsgHtml( 'upload_source_file' ), |
— | — | @@ -871,7 +870,7 @@ |
872 | 871 | 'radio' => &$radio, |
873 | 872 | 'help' => wfMsgExt( 'upload-maxfilesize', |
874 | 873 | array( 'parseinline', 'escapenoentities' ), |
875 | | - $wgLang->formatSize( $wgMaxUploadSize ) |
| 874 | + $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) ) |
876 | 875 | ) . ' ' . wfMsgHtml( 'upload_source_url' ), |
877 | 876 | 'checked' => $selectedSourceType == 'url', |
878 | 877 | ); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -31,6 +31,8 @@ |
32 | 32 | note that this changes the cache key making all old entries in the parser cache invalid you |
33 | 33 | can set $wgUseEditSectionTokens to false to disable this and keep your old parser cache entries. |
34 | 34 | 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. |
35 | 37 | |
36 | 38 | === New features in 1.18 === |
37 | 39 | * Added a special page, disabled by default, that allows users with the |