Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / resources / src / mediawiki.base / mediawiki.base.js
index 04ed5d6..00a74fe 100644 (file)
                 * @return {string} Parsed message
                 */
                parser: function () {
-                       var text;
-                       if ( mw.config.get( 'wgUserLanguage' ) === 'qqx' ) {
+                       var text = this.map.get( this.key );
+                       if (
+                               mw.config.get( 'wgUserLanguage' ) === 'qqx' &&
+                               ( !text || text === '(' + this.key + ')' )
+                       ) {
                                text = '(' + this.key + '$*)';
-                       } else {
-                               text = this.map.get( this.key );
                        }
                        return mw.format.apply( null, [ text ].concat( this.parameters ) );
                },
        /**
         * Replace $* with a list of parameters for &uselang=qqx.
         *
+        * @private
         * @since 1.33
         * @param {string} formatString Format string
         * @param {Array} parameters Values for $N replacements
         * @return {string} Transformed format string
         */
-       mw.transformFormatForQqx = function ( formatString, parameters ) {
+       mw.internalDoTransformFormatForQqx = function ( formatString, parameters ) {
                var parametersString;
                if ( formatString.indexOf( '$*' ) !== -1 ) {
                        parametersString = '';
         */
        mw.format = function ( formatString ) {
                var parameters = slice.call( arguments, 1 );
-               formatString = mw.transformFormatForQqx( formatString, parameters );
+               formatString = mw.internalDoTransformFormatForQqx( formatString, parameters );
                return formatString.replace( /\$(\d+)/g, function ( str, match ) {
                        var index = parseInt( match, 10 ) - 1;
                        return parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;
                var deferred = $.Deferred();
 
                // Allow calling with a single dependency as a string
-               if ( typeof dependencies === 'string' ) {
+               if ( !Array.isArray( dependencies ) ) {
                        dependencies = [ dependencies ];
                }
 
                        return deferred.reject( e ).promise();
                }
 
-               mw.loader.enqueue( dependencies, function () {
-                       deferred.resolve( mw.loader.require );
-               }, deferred.reject );
+               mw.loader.enqueue(
+                       dependencies,
+                       function () { deferred.resolve( mw.loader.require ); },
+                       deferred.reject
+               );
 
                return deferred.promise();
        };
 
+       /**
+        * Load a script by URL.
+        *
+        * Example:
+        *
+        *     mw.loader.getScript(
+        *         'https://example.org/x-1.0.0.js'
+        *     )
+        *         .then( function () {
+        *             // Script succeeded. You can use X now.
+        *         }, function ( e ) {
+        *             // Script failed. X is not avaiable
+        *             mw.log.error( e.message ); // => "Failed to load script"
+        *         } );
+        *     } );
+        *
+        * @member mw.loader
+        * @param {string} url Script URL
+        * @return {jQuery.Promise} Resolved when the script is loaded
+        */
+       mw.loader.getScript = function ( url ) {
+               return $.ajax( url, { dataType: 'script', cache: true } )
+                       .catch( function () {
+                               throw new Error( 'Failed to load script' );
+                       } );
+       };
+
        // Alias $j to jQuery for backwards compatibility
        // @deprecated since 1.23 Use $ or jQuery instead
        mw.log.deprecate( window, '$j', $, 'Use $ or jQuery instead.' );