From: Bryan Tong Minh Date: Fri, 4 Mar 2011 15:38:37 +0000 (+0000) Subject: (bug 26995) File size is now checked before uploading in HTML5 browsers X-Git-Tag: 1.31.0-rc.0~31655 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/supprimer.php?a=commitdiff_plain;h=9fb510f31d9784b315595317e1da7a2fdcb1c8a0;p=lhc%2Fweb%2Fwiklou.git (bug 26995) File size is now checked before uploading in HTML5 browsers * Exposed $wgMaxUploadSize to JS * Exposed message largefileserver to JS --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f6aa977ce2..e39753e879 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -86,6 +86,7 @@ PHP if you have not done so prior to upgrading MediaWiki. potentially dangerous Java applets. This allows applets to be blocked specifically, rather than all ZIP files being blocked. * (bug 2429) Allow selection of associated namespace in recent changes +* (bug 26995) File size is now checked before uploading in HTML5 browsers === Bug fixes in 1.18 === * (bug 23119) WikiError class and subclasses are now marked as deprecated diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 8525e522fd..52bee73ae6 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -771,6 +771,8 @@ class UploadForm extends HTMLForm { protected $mTextAfterSummary; protected $mSourceIds; + + protected $mMaxFileSize = array(); public function __construct( $options = array() ) { $this->mWatch = !empty( $options['watch'] ); @@ -851,6 +853,10 @@ class UploadForm extends HTMLForm { ); } + $this->mMaxUploadSize['file'] = min( + wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), + UploadBase::getMaxUploadSize( 'file' ) ); + $descriptor['UploadFile'] = array( 'class' => 'UploadSourceField', 'section' => 'source', @@ -861,17 +867,12 @@ class UploadForm extends HTMLForm { 'radio' => &$radio, 'help' => wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ), - $wgLang->formatSize( - wfShorthandToInteger( min( - wfShorthandToInteger( - ini_get( 'upload_max_filesize' ) - ), UploadBase::getMaxUploadSize( 'file' ) - ) ) - ) + $wgLang->formatSize( $this->mMaxUploadSize['file'] ) ) . ' ' . wfMsgHtml( 'upload_source_file' ), 'checked' => $selectedSourceType == 'file', ); if ( $canUploadByUrl ) { + $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' ); $descriptor['UploadFileURL'] = array( 'class' => 'UploadSourceField', 'section' => 'source', @@ -881,7 +882,7 @@ class UploadForm extends HTMLForm { 'radio' => &$radio, 'help' => wfMsgExt( 'upload-maxfilesize', array( 'parseinline', 'escapenoentities' ), - $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) ) + $wgLang->formatSize( $this->mMaxUploadSize['url'] ) ) . ' ' . wfMsgHtml( 'upload_source_url' ), 'checked' => $selectedSourceType == 'url', ); @@ -1095,6 +1096,7 @@ class UploadForm extends HTMLForm { $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI; + $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize(); $scriptVars = array( 'wgAjaxUploadDestCheck' => $useAjaxDestCheck, @@ -1106,6 +1108,7 @@ class UploadForm extends HTMLForm { 'wgUploadSourceIds' => $this->mSourceIds, 'wgStrictFileExtensions' => $wgStrictFileExtensions, 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ), + 'wgMaxUploadSize' => $this->mMaxUploadSize, ); $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) ); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index fdbd0fcf81..b485949dcd 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1310,7 +1310,7 @@ abstract class UploadBase { global $wgMaxUploadSize; if ( is_array( $wgMaxUploadSize ) ) { - if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) { + if ( !is_null( $forType ) && isset( $wgMaxUploadSize[$forType] ) ) { return $wgMaxUploadSize[$forType]; } else { return $wgMaxUploadSize['*']; diff --git a/resources/Resources.php b/resources/Resources.php index e8947b9b24..a9b1002600 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -436,6 +436,7 @@ return array( 'size-kilobytes', 'size-megabytes', 'size-gigabytes', + 'largefileserver', ), 'dependencies' => array( 'mediawiki.util.jpegmeta' ), ), diff --git a/resources/mediawiki.special/mediawiki.special.upload.js b/resources/mediawiki.special/mediawiki.special.upload.js index bfb65a081a..ee86ea9380 100644 --- a/resources/mediawiki.special/mediawiki.special.upload.js +++ b/resources/mediawiki.special/mediawiki.special.upload.js @@ -191,7 +191,33 @@ jQuery( function( $ ) { $( '#mw-upload-thumbnail' ).remove(); } - + /** + * Check if the file does not exceed the maximum size + */ + function checkMaxUploadSize( file ) { + function getMaxUploadSize( type ) { + sizes = mw.config.get( 'wgMaxUploadSize' ); + if ( sizes[type] !== undefined ) { + return sizes[type]; + } + return sizes['*']; + } + $( '.mw-upload-source-error' ).remove(); + + maxSize = getMaxUploadSize( 'file' ); + if ( file.size > maxSize ) { + error = $( '

' + + mw.msg( 'largefileserver', file.size, maxSize ) + '

' ); + $( '#wpUploadFile' ).after( error ); + return false; + } + return true; + } + + + /** + * Initialization + */ if ( hasFileAPI() ) { // Update thumbnail when the file selection control is updated. $( '#wpUploadFile' ).change( function() { @@ -199,6 +225,11 @@ jQuery( function( $ ) { if ( this.files && this.files.length ) { // Note: would need to be updated to handle multiple files. var file = this.files[0]; + + if ( !checkMaxUploadSize( file ) ) { + return; + } + if ( fileIsPreviewable( file ) ) { showPreview( file ); } @@ -217,6 +248,7 @@ jQuery( function ( $ ) { $( 'input[name="wpSourceType"]', row ).change( function () { var currentRow = row; // Store current row in our own scope return function () { + $( '.mw-upload-source-error' ).remove(); if ( this.checked ) { // Disable all inputs $( 'input[name!="wpSourceType"]', rows ).attr( 'disabled', true ); @@ -227,3 +259,4 @@ jQuery( function ( $ ) { }() ); } } ); +