Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -1310,7 +1310,7 @@ |
1311 | 1311 | global $wgMaxUploadSize; |
1312 | 1312 | |
1313 | 1313 | if ( is_array( $wgMaxUploadSize ) ) { |
1314 | | - if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) { |
| 1314 | + if ( !is_null( $forType ) && isset( $wgMaxUploadSize[$forType] ) ) { |
1315 | 1315 | return $wgMaxUploadSize[$forType]; |
1316 | 1316 | } else { |
1317 | 1317 | return $wgMaxUploadSize['*']; |
Index: trunk/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -771,6 +771,8 @@ |
772 | 772 | protected $mTextAfterSummary; |
773 | 773 | |
774 | 774 | protected $mSourceIds; |
| 775 | + |
| 776 | + protected $mMaxFileSize = array(); |
775 | 777 | |
776 | 778 | public function __construct( $options = array() ) { |
777 | 779 | $this->mWatch = !empty( $options['watch'] ); |
— | — | @@ -851,6 +853,10 @@ |
852 | 854 | ); |
853 | 855 | } |
854 | 856 | |
| 857 | + $this->mMaxUploadSize['file'] = min( |
| 858 | + wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), |
| 859 | + UploadBase::getMaxUploadSize( 'file' ) ); |
| 860 | + |
855 | 861 | $descriptor['UploadFile'] = array( |
856 | 862 | 'class' => 'UploadSourceField', |
857 | 863 | 'section' => 'source', |
— | — | @@ -861,17 +867,12 @@ |
862 | 868 | 'radio' => &$radio, |
863 | 869 | 'help' => wfMsgExt( 'upload-maxfilesize', |
864 | 870 | array( 'parseinline', 'escapenoentities' ), |
865 | | - $wgLang->formatSize( |
866 | | - wfShorthandToInteger( min( |
867 | | - wfShorthandToInteger( |
868 | | - ini_get( 'upload_max_filesize' ) |
869 | | - ), UploadBase::getMaxUploadSize( 'file' ) |
870 | | - ) ) |
871 | | - ) |
| 871 | + $wgLang->formatSize( $this->mMaxUploadSize['file'] ) |
872 | 872 | ) . ' ' . wfMsgHtml( 'upload_source_file' ), |
873 | 873 | 'checked' => $selectedSourceType == 'file', |
874 | 874 | ); |
875 | 875 | if ( $canUploadByUrl ) { |
| 876 | + $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' ); |
876 | 877 | $descriptor['UploadFileURL'] = array( |
877 | 878 | 'class' => 'UploadSourceField', |
878 | 879 | 'section' => 'source', |
— | — | @@ -881,7 +882,7 @@ |
882 | 883 | 'radio' => &$radio, |
883 | 884 | 'help' => wfMsgExt( 'upload-maxfilesize', |
884 | 885 | array( 'parseinline', 'escapenoentities' ), |
885 | | - $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) ) |
| 886 | + $wgLang->formatSize( $this->mMaxUploadSize['url'] ) |
886 | 887 | ) . ' ' . wfMsgHtml( 'upload_source_url' ), |
887 | 888 | 'checked' => $selectedSourceType == 'url', |
888 | 889 | ); |
— | — | @@ -1095,6 +1096,7 @@ |
1096 | 1097 | |
1097 | 1098 | $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; |
1098 | 1099 | $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; |
| 1100 | + $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize(); |
1099 | 1101 | |
1100 | 1102 | $scriptVars = array( |
1101 | 1103 | 'wgAjaxUploadDestCheck' => $useAjaxDestCheck, |
— | — | @@ -1106,6 +1108,7 @@ |
1107 | 1109 | 'wgUploadSourceIds' => $this->mSourceIds, |
1108 | 1110 | 'wgStrictFileExtensions' => $wgStrictFileExtensions, |
1109 | 1111 | 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ), |
| 1112 | + 'wgMaxUploadSize' => $this->mMaxUploadSize, |
1110 | 1113 | ); |
1111 | 1114 | |
1112 | 1115 | $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) ); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -86,6 +86,7 @@ |
87 | 87 | potentially dangerous Java applets. This allows applets to be blocked |
88 | 88 | specifically, rather than all ZIP files being blocked. |
89 | 89 | * (bug 2429) Allow selection of associated namespace in recent changes |
| 90 | +* (bug 26995) File size is now checked before uploading in HTML5 browsers |
90 | 91 | |
91 | 92 | === Bug fixes in 1.18 === |
92 | 93 | * (bug 23119) WikiError class and subclasses are now marked as deprecated |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -436,6 +436,7 @@ |
437 | 437 | 'size-kilobytes', |
438 | 438 | 'size-megabytes', |
439 | 439 | 'size-gigabytes', |
| 440 | + 'largefileserver', |
440 | 441 | ), |
441 | 442 | 'dependencies' => array( 'mediawiki.util.jpegmeta' ), |
442 | 443 | ), |
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js |
— | — | @@ -191,7 +191,33 @@ |
192 | 192 | $( '#mw-upload-thumbnail' ).remove(); |
193 | 193 | } |
194 | 194 | |
195 | | - |
| 195 | + /** |
| 196 | + * Check if the file does not exceed the maximum size |
| 197 | + */ |
| 198 | + function checkMaxUploadSize( file ) { |
| 199 | + function getMaxUploadSize( type ) { |
| 200 | + sizes = mw.config.get( 'wgMaxUploadSize' ); |
| 201 | + if ( sizes[type] !== undefined ) { |
| 202 | + return sizes[type]; |
| 203 | + } |
| 204 | + return sizes['*']; |
| 205 | + } |
| 206 | + $( '.mw-upload-source-error' ).remove(); |
| 207 | + |
| 208 | + maxSize = getMaxUploadSize( 'file' ); |
| 209 | + if ( file.size > maxSize ) { |
| 210 | + error = $( '<p class="error mw-upload-source-error" id="wpSourceTypeFile-error">' + |
| 211 | + mw.msg( 'largefileserver', file.size, maxSize ) + '</p>' ); |
| 212 | + $( '#wpUploadFile' ).after( error ); |
| 213 | + return false; |
| 214 | + } |
| 215 | + return true; |
| 216 | + } |
| 217 | + |
| 218 | + |
| 219 | + /** |
| 220 | + * Initialization |
| 221 | + */ |
196 | 222 | if ( hasFileAPI() ) { |
197 | 223 | // Update thumbnail when the file selection control is updated. |
198 | 224 | $( '#wpUploadFile' ).change( function() { |
— | — | @@ -199,6 +225,11 @@ |
200 | 226 | if ( this.files && this.files.length ) { |
201 | 227 | // Note: would need to be updated to handle multiple files. |
202 | 228 | var file = this.files[0]; |
| 229 | + |
| 230 | + if ( !checkMaxUploadSize( file ) ) { |
| 231 | + return; |
| 232 | + } |
| 233 | + |
203 | 234 | if ( fileIsPreviewable( file ) ) { |
204 | 235 | showPreview( file ); |
205 | 236 | } |
— | — | @@ -217,6 +248,7 @@ |
218 | 249 | $( 'input[name="wpSourceType"]', row ).change( function () { |
219 | 250 | var currentRow = row; // Store current row in our own scope |
220 | 251 | return function () { |
| 252 | + $( '.mw-upload-source-error' ).remove(); |
221 | 253 | if ( this.checked ) { |
222 | 254 | // Disable all inputs |
223 | 255 | $( 'input[name!="wpSourceType"]', rows ).attr( 'disabled', true ); |
— | — | @@ -227,3 +259,4 @@ |
228 | 260 | }() ); |
229 | 261 | } |
230 | 262 | } ); |
| 263 | + |