mediawiki.Upload: Consistently use getters rather than direct property access
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 2 Sep 2015 11:15:31 +0000 (13:15 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 2 Sep 2015 12:03:18 +0000 (12:03 +0000)
Using this.text instead of this.getText() in this.upload() resulted in the
text of mw.ForeignStructuredUpload being entirely ignored. Fix this
and other properties too for consistency.

Change-Id: I8282260474f4e7d010766be3f2a7ba8641313571

resources/src/mediawiki/mediawiki.Upload.js

index 58c66c1..07a0b75 100644 (file)
         * Sets the filename based on the filename as it was on the upload.
         */
        UP.setFilenameFromFile = function () {
-               if ( this.file.nodeType && this.file.nodeType === Node.ELEMENT_NODE ) {
+               var file = this.getFile();
+               if ( file.nodeType && file.nodeType === Node.ELEMENT_NODE ) {
                        // File input element, use getBasename to cut out the path
-                       this.setFilename( this.getBasename( this.file.value ) );
-               } else if ( this.file.name && this.file.lastModified ) {
+                       this.setFilename( this.getBasename( file.value ) );
+               } else if ( file.name && file.lastModified ) {
                        // HTML5 FileAPI File object, but use getBasename to be safe
-                       this.setFilename( this.getBasename( this.file.name ) );
+                       this.setFilename( this.getBasename( file.name ) );
                }
        };
 
        UP.upload = function () {
                var upload = this;
 
-               if ( !this.file ) {
+               if ( !this.getFile() ) {
                        return $.Deferred().reject( 'No file to upload. Call setFile to add one.' );
                }
 
-               if ( !this.filename ) {
+               if ( !this.getFilename() ) {
                        return $.Deferred().reject( 'No filename set. Call setFilename to add one.' );
                }
 
                this.state = Upload.State.UPLOADING;
 
-               return this.api.upload( this.file, {
-                       watchlist: ( this.watchlist === true ) ? 1 : undefined,
-                       comment: this.comment,
-                       filename: this.filename,
-                       text: this.text
+               return this.api.upload( this.getFile(), {
+                       watchlist: ( this.getWatchlist() ) ? 1 : undefined,
+                       comment: this.getComment(),
+                       filename: this.getFilename(),
+                       text: this.getText()
                } ).then( function ( result ) {
                        upload.state = Upload.State.UPLOADED;
                        upload.imageinfo = result.upload.imageinfo;
        UP.uploadToStash = function () {
                var upload = this;
 
-               if ( !this.file ) {
+               if ( !this.getFile() ) {
                        return $.Deferred().reject( 'No file to upload. Call setFile to add one.' );
                }
 
-               if ( !this.filename ) {
+               if ( !this.getFilename() ) {
                        this.setFilenameFromFile();
                }
 
                this.state = Upload.State.UPLOADING;
 
-               this.stashPromise = this.api.uploadToStash( this.file, {
-                       filename: this.filename
+               this.stashPromise = this.api.uploadToStash( this.getFile(), {
+                       filename: this.getFilename()
                } ).then( function ( finishStash ) {
                        upload.state = Upload.State.STASHED;
                        return finishStash;
                        upload.state = Upload.State.UPLOADING;
 
                        return finishStash( {
-                               watchlist: ( upload.watchlist === true ) ? 1 : undefined,
+                               watchlist: ( upload.getWatchlist() ) ? 1 : undefined,
                                comment: upload.getComment(),
                                filename: upload.getFilename(),
                                text: upload.getText()