Follow-up I0bb4ed7f7: Use correct 'this'
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.ForeignStructuredUpload.js
index 3a0a94b..177861e 100644 (file)
@@ -1,8 +1,5 @@
 ( function ( mw, $, OO ) {
        /**
-        * @class mw.ForeignStructuredUpload
-        * @extends mw.ForeignUpload
-        *
         * Used to represent an upload in progress on the frontend.
         *
         * This subclass will upload to a wiki using a structured metadata
         * **TODO: This currently only supports uploads under CC-BY-SA 4.0,
         * and should really have support for more licenses.**
         *
-        * @inheritdoc
+        * @class mw.ForeignStructuredUpload
+        * @extends mw.ForeignUpload
+        *
+        * @constructor
+        * @param {string} [target]
+        * @param {Object} [apiconfig]
         */
        function ForeignStructuredUpload( target, apiconfig ) {
                this.date = undefined;
         * @param {string[]} categories Array of categories to which this upload will be added.
         */
        ForeignStructuredUpload.prototype.addCategories = function ( categories ) {
-               var i, category;
-
-               for ( i = 0; i < categories.length; i++ ) {
-                       category = categories[ i ];
-                       this.categories.push( category );
-               }
+               // The length of the array must be less than 10000.
+               // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push#Merging_two_arrays
+               Array.prototype.push.apply( this.categories, categories );
        };
 
        /**
         * @return {string}
         */
        ForeignStructuredUpload.prototype.getDescriptions = function () {
-               var i, desc, templateCalls = [];
-
-               for ( i = 0; i < this.descriptions.length; i++ ) {
-                       desc = this.descriptions[ i ];
-                       templateCalls.push(
-                               this.config.format.description
-                                       .replace( '$LANGUAGE', desc.language )
-                                       .replace( '$TEXT', desc.text )
-                       );
-               }
-
-               return templateCalls.join( '\n' );
+               var upload = this;
+               return this.descriptions.map( function ( desc ) {
+                       return upload.config.format.description
+                               .replace( '$LANGUAGE', desc.language )
+                               .replace( '$TEXT', desc.text );
+               } ).join( '\n' );
        };
 
        /**
         * @return {string}
         */
        ForeignStructuredUpload.prototype.getCategories = function () {
-               var i, cat, categoryLinks = [];
-
                if ( this.categories.length === 0 ) {
                        return this.config.format.uncategorized;
                }
 
-               for ( i = 0; i < this.categories.length; i++ ) {
-                       cat = this.categories[ i ];
-                       categoryLinks.push( '[[Category:' + cat + ']]' );
-               }
-
-               return categoryLinks.join( '\n' );
+               return this.categories.map( function ( cat ) {
+                       return '[[Category:' + cat + ']]';
+               } ).join( '\n' );
        };
 
        /**