summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki/api/user.js
blob: e7b4b6d54fca752e49615df045b5af5ca3b1d97b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * @class mw.Api.plugin.user
 * @since 1.27
 */
( function ( mw, $ ) {

	$.extend( mw.Api.prototype, {

		/**
		 * Get the current user's groups and rights.
		 *
		 * @return {jQuery.Promise}
		 * @return {Function} return.done
		 * @return {Object} return.done.userInfo
		 * @return {string[]} return.done.userInfo.groups User groups that the current user belongs to
		 * @return {string[]} return.done.userInfo.rights Current user's rights
		 */
		getUserInfo: function () {
			return this.get( {
				action: 'query',
				meta: 'userinfo',
				uiprop: [ 'groups', 'rights' ]
			} ).then( function ( data ) {
				if ( data.query && data.query.userinfo ) {
					return data.query.userinfo;
				}
				return $.Deferred().reject().promise();
			} );
		}
	} );

	/**
	 * @class mw.Api
	 * @mixins mw.Api.plugin.user
	 */

}( mediaWiki, jQuery ) );