Last modified: 2012-08-01 04:15:47 UTC
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().
We could probably use the server side User class as a loose inspiration (at least in terms of method names). Currently we have: mw.user: - 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 | https://gerrit.wikimedia.org/r/14333