r83218 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83217‎ | r83218 | r83219 >
Date:15:38, 4 March 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
(bug 26995) File size is now checked before uploading in HTML5 browsers
* Exposed $wgMaxUploadSize to JS
* Exposed message largefileserver to JS
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -1310,7 +1310,7 @@
13111311 global $wgMaxUploadSize;
13121312
13131313 if ( is_array( $wgMaxUploadSize ) ) {
1314 - if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) {
 1314+ if ( !is_null( $forType ) && isset( $wgMaxUploadSize[$forType] ) ) {
13151315 return $wgMaxUploadSize[$forType];
13161316 } else {
13171317 return $wgMaxUploadSize['*'];
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -771,6 +771,8 @@
772772 protected $mTextAfterSummary;
773773
774774 protected $mSourceIds;
 775+
 776+ protected $mMaxFileSize = array();
775777
776778 public function __construct( $options = array() ) {
777779 $this->mWatch = !empty( $options['watch'] );
@@ -851,6 +853,10 @@
852854 );
853855 }
854856
 857+ $this->mMaxUploadSize['file'] = min(
 858+ wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
 859+ UploadBase::getMaxUploadSize( 'file' ) );
 860+
855861 $descriptor['UploadFile'] = array(
856862 'class' => 'UploadSourceField',
857863 'section' => 'source',
@@ -861,17 +867,12 @@
862868 'radio' => &$radio,
863869 'help' => wfMsgExt( 'upload-maxfilesize',
864870 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'] )
872872 ) . ' ' . wfMsgHtml( 'upload_source_file' ),
873873 'checked' => $selectedSourceType == 'file',
874874 );
875875 if ( $canUploadByUrl ) {
 876+ $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
876877 $descriptor['UploadFileURL'] = array(
877878 'class' => 'UploadSourceField',
878879 'section' => 'source',
@@ -881,7 +882,7 @@
882883 'radio' => &$radio,
883884 'help' => wfMsgExt( 'upload-maxfilesize',
884885 array( 'parseinline', 'escapenoentities' ),
885 - $wgLang->formatSize( UploadBase::getMaxUploadSize( 'url' ) )
 886+ $wgLang->formatSize( $this->mMaxUploadSize['url'] )
886887 ) . ' ' . wfMsgHtml( 'upload_source_url' ),
887888 'checked' => $selectedSourceType == 'url',
888889 );
@@ -1095,6 +1096,7 @@
10961097
10971098 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
10981099 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
 1100+ $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
10991101
11001102 $scriptVars = array(
11011103 'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
@@ -1106,6 +1108,7 @@
11071109 'wgUploadSourceIds' => $this->mSourceIds,
11081110 'wgStrictFileExtensions' => $wgStrictFileExtensions,
11091111 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
 1112+ 'wgMaxUploadSize' => $this->mMaxUploadSize,
11101113 );
11111114
11121115 $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
Index: trunk/phase3/RELEASE-NOTES
@@ -86,6 +86,7 @@
8787 potentially dangerous Java applets. This allows applets to be blocked
8888 specifically, rather than all ZIP files being blocked.
8989 * (bug 2429) Allow selection of associated namespace in recent changes
 90+* (bug 26995) File size is now checked before uploading in HTML5 browsers
9091
9192 === Bug fixes in 1.18 ===
9293 * (bug 23119) WikiError class and subclasses are now marked as deprecated
Index: trunk/phase3/resources/Resources.php
@@ -436,6 +436,7 @@
437437 'size-kilobytes',
438438 'size-megabytes',
439439 'size-gigabytes',
 440+ 'largefileserver',
440441 ),
441442 'dependencies' => array( 'mediawiki.util.jpegmeta' ),
442443 ),
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.upload.js
@@ -191,7 +191,33 @@
192192 $( '#mw-upload-thumbnail' ).remove();
193193 }
194194
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+ */
196222 if ( hasFileAPI() ) {
197223 // Update thumbnail when the file selection control is updated.
198224 $( '#wpUploadFile' ).change( function() {
@@ -199,6 +225,11 @@
200226 if ( this.files && this.files.length ) {
201227 // Note: would need to be updated to handle multiple files.
202228 var file = this.files[0];
 229+
 230+ if ( !checkMaxUploadSize( file ) ) {
 231+ return;
 232+ }
 233+
203234 if ( fileIsPreviewable( file ) ) {
204235 showPreview( file );
205236 }
@@ -217,6 +248,7 @@
218249 $( 'input[name="wpSourceType"]', row ).change( function () {
219250 var currentRow = row; // Store current row in our own scope
220251 return function () {
 252+ $( '.mw-upload-source-error' ).remove();
221253 if ( this.checked ) {
222254 // Disable all inputs
223255 $( 'input[name!="wpSourceType"]', rows ).attr( 'disabled', true );
@@ -227,3 +259,4 @@
228260 }() );
229261 }
230262 } );
 263+

Follow-up revisions

RevisionCommit summaryAuthorDate
r83314Follow-up r83218: Fix bug# per http://www.mediawiki.org/wiki/Special:Code/Med...raymond19:28, 5 March 2011
r83318Follow-up r83218: Added var declarations. Html escape the largefileserver mes...btongminh19:47, 5 March 2011

Comments

#Comment by Bryan (talk | contribs)   15:40, 4 March 2011

Wrong number, correct one is bug 26217.

#Comment by Catrope (talk | contribs)   19:32, 5 March 2011
+			sizes = mw.config.get( 'wgMaxUploadSize' );

Use var sizes = ... , otherwise sizes will be defined as a global variable. Same for maxsize and error further down.

+			error = $( '<p class="error mw-upload-source-error" id="wpSourceTypeFile-error">' + 
+					mw.msg( 'largefileserver', file.size, maxSize ) + '</p>' );

Use $( '

' ).text( mw.msg( .... ) ); so the i18n message isn't interpreted as HTML.

#Comment by Bryan (talk | contribs)   19:47, 5 March 2011

Done in r83318, but differently.

Status & tagging log