Zhuyifei1999 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/222085

Change subject: Added support to ignore file extension
......................................................................

Added support to ignore file extension

* When $wgCheckFileExtensions is false, set 
mw.UploadWizard.config.fileExtensions to null
* Ignore extension checks if mw.UploadWizard.config.fileExtensions is null

Bug: T103224
Change-Id: Ie6399be863df542e513dfe4f8d33c3a1afa67e75
---
M UploadWizard.config.php
M resources/mw.UploadWizardUpload.js
2 files changed, 88 insertions(+), 86 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/85/222085/1

diff --git a/UploadWizard.config.php b/UploadWizard.config.php
index 8943a2a..c608dee 100644
--- a/UploadWizard.config.php
+++ b/UploadWizard.config.php
@@ -83,7 +83,7 @@
        'campaignCTACampaignTemplate' => 'uploadCampaign:$1',
 
        // File extensions acceptable in this wiki
-       'fileExtensions' =>  $wgFileExtensions,
+       'fileExtensions' => $wgCheckFileExtensions ? $wgFileExtensions : null,
 
        // Flickr details
        // Flickr API is SSL-only as of June 27th, 2014: 
http://code.flickr.net/2014/04/30/flickr-api-going-ssl-only-on-june-27th-2014/
diff --git a/resources/mw.UploadWizardUpload.js 
b/resources/mw.UploadWizardUpload.js
index c8bb168..b950606 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -442,108 +442,110 @@
                this.setTitle( basename );
 
                // Check if extension is acceptable
-               extension = this.title.getExtension();
-               if ( mw.isEmpty( extension ) ) {
-                       this.fileNameErr( 'noext', null );
-               } else {
-                       if ( $.inArray( extension.toLowerCase(), 
mw.UploadWizard.config.fileExtensions ) === -1 ) {
+               if (mw.UploadWizard.config.fileExtensions !== null) {
+                       extension = this.title.getExtension();
+                       if ( mw.isEmpty( extension ) ) {
+                               this.fileNameErr( 'noext', null );
+                               return;
+                       } else if ( $.inArray( extension.toLowerCase(), 
mw.UploadWizard.config.fileExtensions ) === -1 ) {
                                this.fileNameErr( 'ext', extension );
-                       } else {
-                               // Split this into a separate case, if the 
error above got ignored,
-                               // we want to still trudge forward.
-                               // if the JavaScript FileReader is available, 
extract more info via fileAPI
-                               if ( mw.fileApi.isAvailable() ) {
+                               return;
+                       }
+               } else {
+                       // Split this into a separate case, if the error above 
got ignored,
+                       // we want to still trudge forward.
+                       // if the JavaScript FileReader is available, extract 
more info via fileAPI
+                       if ( mw.fileApi.isAvailable() ) {
 
-                                       // An UploadWizardUpload object already 
exists (us) when we add a file.
-                                       // So, when multiple files are provided 
(via select multiple), add the first file to this UploadWizardUpload
-                                       // and create new UploadWizardUpload 
objects and corresponding interfaces for the rest.
+                               // An UploadWizardUpload object already exists 
(us) when we add a file.
+                               // So, when multiple files are provided (via 
select multiple), add the first file to this UploadWizardUpload
+                               // and create new UploadWizardUpload objects 
and corresponding interfaces for the rest.
 
-                                       this.file = files[0];
+                               this.file = files[0];
 
-                                       // If chunked uploading is enabled, we 
can transfer any file that MediaWiki
-                                       // will accept. Otherwise we're bound 
by PHP's limits.
-                                       // NOTE: Because we don't know until 
runtime if the browser supports chunked
-                                       // uploading, we can't determine this 
server-side.
-                                       if ( 
mw.UploadWizard.config.enableChunked && mw.fileApi.isFormDataAvailable() ) {
-                                               actualMaxSize = 
mw.UploadWizard.config.maxMwUploadSize;
-                                       } else {
-                                               actualMaxSize = Math.min(
-                                                       
mw.UploadWizard.config.maxMwUploadSize,
-                                                       
mw.UploadWizard.config.maxPhpUploadSize
-                                               );
+                               // If chunked uploading is enabled, we can 
transfer any file that MediaWiki
+                               // will accept. Otherwise we're bound by PHP's 
limits.
+                               // NOTE: Because we don't know until runtime if 
the browser supports chunked
+                               // uploading, we can't determine this 
server-side.
+                               if ( mw.UploadWizard.config.enableChunked && 
mw.fileApi.isFormDataAvailable() ) {
+                                       actualMaxSize = 
mw.UploadWizard.config.maxMwUploadSize;
+                               } else {
+                                       actualMaxSize = Math.min(
+                                               
mw.UploadWizard.config.maxMwUploadSize,
+                                               
mw.UploadWizard.config.maxPhpUploadSize
+                                       );
+                               }
+
+                               // make sure the file isn't too large
+                               // XXX need a way to find the size of the 
Flickr image
+                               if ( !this.fromURL ) {
+                                       this.transportWeight = this.file.size;
+                                       if ( this.transportWeight > 
actualMaxSize ) {
+                                               this.showMaxSizeWarning( 
this.transportWeight, actualMaxSize );
+                                               return;
                                        }
+                               }
+                               if ( this.imageinfo === undefined ) {
+                                       this.imageinfo = {};
+                               }
+                               this.filename = filename;
 
-                                       // make sure the file isn't too large
-                                       // XXX need a way to find the size of 
the Flickr image
-                                       if ( !this.fromURL ) {
-                                               this.transportWeight = 
this.file.size;
-                                               if ( this.transportWeight > 
actualMaxSize ) {
-                                                       
this.showMaxSizeWarning( this.transportWeight, actualMaxSize );
-                                                       return;
-                                               }
-                                       }
-                                       if ( this.imageinfo === undefined ) {
-                                               this.imageinfo = {};
-                                       }
-                                       this.filename = filename;
+                               // For JPEGs, we use the JsJpegMeta library in 
core to extract metadata,
+                               // including EXIF tags. This is done 
asynchronously once each file has been
+                               // read. Only then is the file properly added 
to UploadWizard via fileNameOk().
+                               //
+                               // For all other file types, we don't need or 
want to run this.
+                               //
+                               // TODO: This should be refactored.
 
-                                       // For JPEGs, we use the JsJpegMeta 
library in core to extract metadata,
-                                       // including EXIF tags. This is done 
asynchronously once each file has been
-                                       // read. Only then is the file properly 
added to UploadWizard via fileNameOk().
-                                       //
-                                       // For all other file types, we don't 
need or want to run this.
-                                       //
-                                       // TODO: This should be refactored.
-
-                                       if ( this.file.type === 'image/jpeg' ) {
-                                               binReader = new FileReader();
-                                               binReader.onload = function () {
-                                                       var binStr, arr, i, 
meta;
-                                                       if ( typeof 
binReader.result === 'string' ) {
-                                                               binStr = 
binReader.result;
-                                                       } else {
-                                                               // Array 
buffer; convert to binary string for the library.
-                                                               arr = new 
Uint8Array( binReader.result );
-                                                               binStr = '';
-                                                               for ( i = 0; i 
< arr.byteLength; i++ ) {
-                                                                       binStr 
+= String.fromCharCode( arr[i] );
-                                                               }
-                                                       }
-                                                       try {
-                                                               meta = 
mw.libs.jpegmeta( binStr, upload.file.fileName );
-                                                               
meta._binary_data = null;
-                                                       } catch ( e ) {
-                                                               meta = null;
-                                                       }
-                                                       
upload.extractMetadataFromJpegMeta( meta );
-                                                       upload.filename = 
filename;
-                                                       if ( upload.hasError 
=== false ) {
-                                                               
finishCallback();
-                                                       }
-                                               };
-                                               if ( 'readAsBinaryString' in 
binReader ) {
-                                                       
binReader.readAsBinaryString( upload.file );
-                                               } else if ( 'readAsArrayBuffer' 
in binReader ) {
-                                                       
binReader.readAsArrayBuffer( upload.file );
+                               if ( this.file.type === 'image/jpeg' ) {
+                                       binReader = new FileReader();
+                                       binReader.onload = function () {
+                                               var binStr, arr, i, meta;
+                                               if ( typeof binReader.result 
=== 'string' ) {
+                                                       binStr = 
binReader.result;
                                                } else {
-                                                       // We should never get 
here. :P
-                                                       throw new Error( 
'Cannot read thumbnail as binary string or array buffer.' );
+                                                       // Array buffer; 
convert to binary string for the library.
+                                                       arr = new Uint8Array( 
binReader.result );
+                                                       binStr = '';
+                                                       for ( i = 0; i < 
arr.byteLength; i++ ) {
+                                                               binStr += 
String.fromCharCode( arr[i] );
+                                                       }
                                                }
-                                       } else {
-                                               if ( this.hasError === false ) {
+                                               try {
+                                                       meta = 
mw.libs.jpegmeta( binStr, upload.file.fileName );
+                                                       meta._binary_data = 
null;
+                                               } catch ( e ) {
+                                                       meta = null;
+                                               }
+                                               
upload.extractMetadataFromJpegMeta( meta );
+                                               upload.filename = filename;
+                                               if ( upload.hasError === false 
) {
                                                        finishCallback();
                                                }
+                                       };
+                                       if ( 'readAsBinaryString' in binReader 
) {
+                                               binReader.readAsBinaryString( 
upload.file );
+                                       } else if ( 'readAsArrayBuffer' in 
binReader ) {
+                                               binReader.readAsArrayBuffer( 
upload.file );
+                                       } else {
+                                               // We should never get here. :P
+                                               throw new Error( 'Cannot read 
thumbnail as binary string or array buffer.' );
                                        }
-
-                                       // Now that first file has been 
prepared, process remaining files
-                                       // in case of a multi-file upload.
-                                       this.emit( 'extra-files', files.slice( 
1 ), toobig );
                                } else {
-                                       this.filename = filename;
                                        if ( this.hasError === false ) {
                                                finishCallback();
                                        }
                                }
+
+                               // Now that first file has been prepared, 
process remaining files
+                               // in case of a multi-file upload.
+                               this.emit( 'extra-files', files.slice( 1 ), 
toobig );
+                       } else {
+                               this.filename = filename;
+                               if ( this.hasError === false ) {
+                                       finishCallback();
+                               }
                        }
                }
        };

-- 
To view, visit https://gerrit.wikimedia.org/r/222085
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6399be863df542e513dfe4f8d33c3a1afa67e75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Zhuyifei1999 <zhuyifei1...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to