Last modified: 2012-08-01 04:15:47 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T40151, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 38151 - Add support for getting and caching user rights in javascript
Add support for getting and caching user rights in javascript
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: 1.20.0 release
Assigned To: Krinkle
:
Depends on:
Blocks: 38055
  Show dependency treegraph
 
Reported: 2012-07-03 18:47 UTC by Alex Monk
Modified: 2012-08-01 04:15 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Alex Monk 2012-07-03 18:47:57 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().
Comment 1 Krinkle 2012-07-03 19:08:49 UTC
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 :)
Comment 2 Alex Monk 2012-07-05 01:05:56 UTC
Assigned this bug to myself as I plan to have a go at it.
Comment 3 Brad Jorsch 2012-07-05 14:38:15 UTC
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?
Comment 4 Krinkle 2012-07-05 14:54:41 UTC
Given that these will be cacheable GET requests, this shouldn't be an issue.
Comment 5 Alex Monk 2012-07-05 16:51:41 UTC
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.
Comment 6 Alex Monk 2012-07-07 19:39:55 UTC
Krinkle, could you give me any tips on how to make this asynchronous please?
Comment 7 Krinkle 2012-07-08 22:59:19 UTC
(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

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links