2 * Allows to retrieve a specific or a set of
3 * messages to be added to mw.messages and returned
6 * @class mw.Api.plugin.messages
12 $.extend( mw.Api.prototype, {
14 * Get a set of messages.
16 * @param {Array} messages Messages to retrieve
17 * @param {Object} [options] Additional parameters for the API call
18 * @return {jQuery.Promise}
20 getMessages: function ( messages, options ) {
21 options = options || {};
22 return this.get( $.extend( {
26 amlang: mw.config.get( 'wgUserLanguage' ),
28 }, options ) ).then( function ( data ) {
31 $.each( data.query.allmessages, function ( i, obj ) {
33 result[ obj.name ] = obj.content;
42 * Loads a set of messages and add them to mw.messages.
44 * @param {Array} messages Messages to retrieve
45 * @param {Object} [options] Additional parameters for the API call
46 * @return {jQuery.Promise}
48 loadMessages: function ( messages, options ) {
49 return this.getMessages( messages, options ).then( $.proxy( mw.messages, 'set' ) );
53 * Loads a set of messages and add them to mw.messages. Only messages that are not already known
54 * are loaded. If all messages are known, the returned promise is resolved immediately.
56 * @param {Array} messages Messages to retrieve
57 * @param {Object} [options] Additional parameters for the API call
58 * @return {jQuery.Promise}
60 loadMessagesIfMissing: function ( messages, options ) {
61 var missing = messages.filter( function ( msg ) {
62 return !mw.message( msg ).exists();
65 if ( missing.length === 0 ) {
66 return $.Deferred().resolve();
69 return this.getMessages( missing, options ).then( $.proxy( mw.messages, 'set' ) );
75 * @mixins mw.Api.plugin.messages
78 }( mediaWiki, jQuery ) );