Page MenuHomePhabricator

Add support for getting and caching user rights in javascript
Closed, ResolvedPublic


Currently to get the user name or group you do mw.config.get('wgUserName') or mw.config.get('wgUserGroups').

In Gerrit change 13628 I tried to add wgUserRights. Krinkle has said that this makes the page too heavy though.

What's suggested is that we make new methods in mw.user which are asynchronous, use the API and cache the data.
E.g. mw.user.getName(), mw.user.getGroups(), mw.user.getRights().

Version: unspecified
Severity: enhancement



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 12:54 AM
bzimport set Reference to bz38151.

We could probably use the server side User class as a loose inspiration (at least in terms of method names).

Currently we have:

  • anonymous(): bool
  • name(): string|null
  • options(): mw.Map from module user.options (Preferences from user_options)
  • tokens(): mw.Map from module user.tokens

Renaming name() to getName() would make sense indeed (similar to how version() and state() have been renamed to getVersion() and getState() in mw.loader).

And getGroups and getRights matches User.php as well :)

Assigned this bug to myself as I plan to have a go at it.

I recall we recently had API trouble because one of the E3 extensions was hitting the API for each page view. Might this cause the same sort of problem if people start using these functions in heavily-used gadgets or in MediaWiki:Common.js? Or was the problem there due to writes rather than reads?

Given that these will be cacheable GET requests, this shouldn't be an issue.

Gerrit change 14333 is up. Obviously I need to write a proper commit message but I also need to work out how to do this asynchronously.

Krinkle, could you give me any tips on how to make this asynchronous please?

(In reply to comment #6)

Krinkle, could you give me any tips on how to make this asynchronous please?

The most correct but useless answer is: Remove "async: false" from the ajax options ;-)

I've added some useful pointers in Gerrit code review:
I5970be9e85935 |