Merge "Do not show useless form at Special:ChangeContentModel"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.ForeignStructuredUpload.js
index 5e79039..f90071c 100644 (file)
@@ -85,8 +85,7 @@
        ForeignStructuredUpload.prototype.getText = function () {
                return (
                        '== {{int:filedesc}} ==\n' +
-                       '{{' +
-                       this.getTemplateName() +
+                       '{{Information' +
                        '\n|description=' +
                        this.getDescriptions() +
                        '\n|date=' +
                return this.date.toString();
        };
 
-       /**
-        * Gets the name of the template to use for creating the file metadata.
-        * Override in subclasses for other templates.
-        *
-        * @private
-        * @return {string}
-        */
-       ForeignStructuredUpload.prototype.getTemplateName = function () {
-               return 'Information';
-       };
-
        /**
         * Fetches the wikitext for any descriptions that have been added
         * to the upload.
         * @return {string}
         */
        ForeignStructuredUpload.prototype.getDescriptions = function () {
-               var i, desc, hasEquals, templateCalls = [];
+               var i, desc, templateCalls = [];
 
                for ( i = 0; i < this.descriptions.length; i++ ) {
                        desc = this.descriptions[ i ];
-                       hasEquals = desc.text.indexOf( '=' ) !== -1;
-                       templateCalls.push( '{{' + desc.language + ( hasEquals ? '|1=' : '|' ) + desc.text + '}}' );
+                       templateCalls.push( '{{' + desc.language + '|1=' + desc.text + '}}' );
                }
 
                return templateCalls.join( '\n' );
        ForeignStructuredUpload.prototype.getCategories = function () {
                var i, cat, categoryLinks = [];
 
+               if ( this.categories.length === 0 ) {
+                       return '{{subst:unc}}';
+               }
+
                for ( i = 0; i < this.categories.length; i++ ) {
                        cat = this.categories[ i ];
                        categoryLinks.push( '[[Category:' + cat + ']]' );
         * @return {string}
         */
        ForeignStructuredUpload.prototype.getUser = function () {
-               var username = mw.config.get( 'wgUserName' );
-               // Do not localise 'User:', we don't know the language of target wiki
-               return '[[User:' + username + '|' + username + ']]';
+               var username, namespace;
+               // Do not localise, we don't know the language of target wiki
+               namespace = 'User';
+               username = mw.config.get( 'wgUserName' );
+               if ( !username ) {
+                       // The user is not logged in locally. However, they might be logged in on the foreign wiki.
+                       // We should record their username there. (If they're not logged in there either, this will
+                       // record the IP address.) It's also possible that the user opened this dialog, got an error
+                       // about not being logged in, logged in in another browser tab, then continued uploading.
+                       username = '{{subst:REVISIONUSER}}';
+               }
+               return '[[' + namespace + ':' + username + '|' + username + ']]';
        };
 
        mw.ForeignStructuredUpload = ForeignStructuredUpload;