Index: branches/wmf/1.17wmf1/includes/upload/UploadFromStash.php |
— | — | @@ -70,6 +70,8 @@ |
71 | 71 | $this->mVirtualTempPath = $metadata['us_path']; |
72 | 72 | $this->mFileProps = $this->stash->getFileProps( $key ); |
73 | 73 | $this->mSourceType = $metadata['us_source_type']; |
| 74 | + $this->mSourceType = isset( $sessionData['mSourceType'] ) ? |
| 75 | + $sessionData['mSourceType'] : null; |
74 | 76 | } |
75 | 77 | |
76 | 78 | public function initializeFromRequest( &$request ) { |
— | — | @@ -82,6 +84,10 @@ |
83 | 85 | return $this->initialize( $fileKey, $desiredDestName ); |
84 | 86 | } |
85 | 87 | |
| 88 | + public function getSourceType() { |
| 89 | + return $this->mSourceType; |
| 90 | + } |
| 91 | + |
86 | 92 | /** |
87 | 93 | * File has been previously verified so no need to do so again. |
88 | 94 | */ |
Index: branches/wmf/1.17wmf1/includes/upload/UploadFromUrl.php |
— | — | @@ -81,6 +81,7 @@ |
82 | 82 | && $wgUser->isAllowed( 'upload_by_url' ); |
83 | 83 | } |
84 | 84 | |
| 85 | + public function getSourceType() { return 'url'; } |
85 | 86 | |
86 | 87 | public function fetchFile() { |
87 | 88 | if ( !Http::isValidURI( $this->mUrl ) ) { |
Index: branches/wmf/1.17wmf1/includes/upload/UploadBase.php |
— | — | @@ -135,6 +135,14 @@ |
136 | 136 | } |
137 | 137 | |
138 | 138 | public function __construct() {} |
| 139 | + |
| 140 | + /** |
| 141 | + * Returns the upload type. Should be overridden by child classes |
| 142 | + * |
| 143 | + * @since 1.18 |
| 144 | + * @return string |
| 145 | + */ |
| 146 | + public function getSourceType() { return null; } |
139 | 147 | |
140 | 148 | /** |
141 | 149 | * Initialize the path information |
— | — | @@ -219,11 +227,11 @@ |
220 | 228 | /** |
221 | 229 | * Honor $wgMaxUploadSize |
222 | 230 | */ |
223 | | - global $wgMaxUploadSize; |
224 | | - if( $this->mFileSize > $wgMaxUploadSize ) { |
| 231 | + $maxSize = self::getMaxUploadSize( $this->getSourceType() ); |
| 232 | + if( $this->mFileSize > $maxSize ) { |
225 | 233 | return array( |
226 | 234 | 'status' => self::FILE_TOO_LARGE, |
227 | | - 'max' => $wgMaxUploadSize, |
| 235 | + 'max' => $maxSize, |
228 | 236 | ); |
229 | 237 | } |
230 | 238 | |
— | — | @@ -1230,4 +1238,19 @@ |
1231 | 1239 | unset( $code['status'] ); |
1232 | 1240 | return Status::newFatal( $this->getVerificationErrorCode( $code ), $error ); |
1233 | 1241 | } |
| 1242 | + |
| 1243 | + public static function getMaxUploadSize( $forType = null ) { |
| 1244 | + global $wgMaxUploadSize; |
| 1245 | + |
| 1246 | + if ( is_array( $wgMaxUploadSize ) ) { |
| 1247 | + if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) { |
| 1248 | + return $wgMaxUploadSize[$forType]; |
| 1249 | + } else { |
| 1250 | + return $wgMaxUploadSize['*']; |
| 1251 | + } |
| 1252 | + } else { |
| 1253 | + return intval( $wgMaxUploadSize ); |
| 1254 | + } |
| 1255 | + |
| 1256 | + } |
1234 | 1257 | } |
Property changes on: branches/wmf/1.17wmf1/includes/upload/UploadBase.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
1235 | 1258 | Merged /trunk/phase3/includes/upload/UploadBase.php:r79749 |
Index: branches/wmf/1.17wmf1/includes/upload/UploadFromFile.php |
— | — | @@ -45,11 +45,10 @@ |
46 | 46 | # proper error can be shown to the user |
47 | 47 | if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) { |
48 | 48 | if ( $this->mUpload->isIniSizeOverflow() ) { |
49 | | - global $wgMaxUploadSize; |
50 | 49 | return array( |
51 | 50 | 'status' => self::FILE_TOO_LARGE, |
52 | 51 | 'max' => min( |
53 | | - $wgMaxUploadSize, |
| 52 | + self::getMaxUploadSize( $this->getSourceType() ), |
54 | 53 | wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), |
55 | 54 | wfShorthandToInteger( ini_get( 'post_max_size' ) ) |
56 | 55 | ), |
Property changes on: branches/wmf/1.17wmf1/includes/upload/UploadFromFile.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
57 | 56 | Merged /trunk/phase3/includes/upload/UploadFromFile.php:r79749 |
Index: branches/wmf/1.17wmf1/includes/DefaultSettings.php |
— | — | @@ -454,7 +454,19 @@ |
455 | 455 | $wgAllowAsyncCopyUploads = false; |
456 | 456 | |
457 | 457 | /** |
458 | | - * Max size for uploads, in bytes. Applies to all uploads. |
| 458 | + * Max size for uploads, in bytes. If not set to an array, applies to all |
| 459 | + * uploads. If set to an array, per upload type maximums can be set, using the |
| 460 | + * file and url keys. If the * key is set this value will be used as maximum |
| 461 | + * for non-specified types. |
| 462 | + * |
| 463 | + * For example: |
| 464 | + * $wgUploadSize = array( |
| 465 | + * '*' => 250 * 1024, |
| 466 | + * 'url' => 500 * 1024, |
| 467 | + * ); |
| 468 | + * Sets the maximum for all uploads to 250 kB except for upload-by-url, which |
| 469 | + * will have a maximum of 500 kB. |
| 470 | + * |
459 | 471 | */ |
460 | 472 | $wgMaxUploadSize = 1024*1024*100; # 100MB |
461 | 473 | |
Property changes on: branches/wmf/1.17wmf1/includes/DefaultSettings.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
462 | 474 | Merged /trunk/phase3/includes/DefaultSettings.php:r79749 |
Index: branches/wmf/1.17wmf1/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 | ); |
Property changes on: branches/wmf/1.17wmf1/includes/specials/SpecialUpload.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
879 | 878 | Merged /trunk/phase3/includes/specials/SpecialUpload.php:r79749 |
Index: branches/wmf/1.17wmf1/RELEASE-NOTES |
— | — | @@ -23,6 +23,8 @@ |
24 | 24 | a lot of outstanding bugs, cleanup the code quality, and make it easier to |
25 | 25 | use. Notably, you can now run upgrades from the web without having to move |
26 | 26 | LocalSettings.php. The specific bugs are listed below in the general notes. |
| 27 | +* $wgMaxUploadSize may now be set to an array to specify the upload size limit |
| 28 | + per upload type. |
27 | 29 | |
28 | 30 | === Configuration changes in 1.17 === |
29 | 31 | * DatabaseFunctions.php that was needed for compatibility with pre-1.3 |
Property changes on: branches/wmf/1.17wmf1/RELEASE-NOTES |
___________________________________________________________________ |
Modified: svn:mergeinfo |
30 | 32 | Merged /trunk/phase3/RELEASE-NOTES:r79749 |