Last modified: 2014-04-03 17:43:36 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 T36733, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 34733 - mediawiki.api.edit: Use mw.user.tokens.get( 'editToken' ) instead of fetching from action=tokens API
mediawiki.api.edit: Use mw.user.tokens.get( 'editToken' ) instead of fetching...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.19.0
All All
: Normal enhancement with 1 vote (vote)
: 1.23.0 release
Assigned To: Krinkle
: performance
: 47239 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-26 15:35 UTC by Helder
Modified: 2014-04-03 17:43 UTC (History)
7 users (show)

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


Attachments

Description Helder 2012-02-26 15:35:37 UTC
I believe it is better to replace the current API call by
mw.user.tokens.get('editToken')
on
https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/resources/mediawiki.api/mediawiki.api.edit.js?view=markup
and add "mediawiki.user" as a dependency on
https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/resources/Resources.php?revision=112348&view=markup#l520
Comment 1 Krinkle 2012-02-26 15:43:50 UTC
That would be 'user.tokens', but yet that's a good idea.

I think it was originally not done due to a bug with the user.* modules, but that's been solved by 1.19
Comment 2 Niklas Laxström 2012-02-26 15:48:26 UTC
How about making API calls to some other wiki?
Comment 3 Helder 2012-02-26 15:52:15 UTC
(In reply to comment #1)
> That would be 'user.tokens', but yet that's a good idea.

Ah, ok.

BTW: do the function name "postWithEditToken" need to contain the word "Token"?
Wouldn't be more intuitive if the user didn't have to write that when using the
API to edit a page? E.g. api.edit( params, ok, err )?

One more question: is this module new in MW 1.19? If so, and in the case the
function name will change, could this change be backported to MW 1.19?

(In reply to comment #2)
> How about making API calls to some other wiki?

Maybe it could use the API call only in the case of an external wiki?
Comment 4 Krinkle 2012-02-26 16:01:38 UTC
(In reply to comment #2)
> How about making API calls to some other wiki?

Right now this module only supports API requests to the local wiki as far as I know.

Making API calls in general is trivially easy with with the helper functions we have from jQuery. So all this is only convenience.

Also, mw.api.watch is already using user.tokens directly.
Comment 5 Krinkle 2012-02-26 16:04:04 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > How about making API calls to some other wiki?
> 
> Right now this module only supports API requests to the local wiki as far as I
> know.

Okay, scrap that. When constructing a new API object there is an option for api url, defaults to mw.util.wikiScript('api'), but is publicly overridable (and documented with that intention).

Looks like we do indeed need to keep support for getting them from the API directly inside the request and cache them in context.

> Also, mw.api.watch is already using user.tokens directly.

We need to change that.

However we can optimize mw.Api for local wiki usage (if url == mw.util.wikiScript('api'), cachedToken = mw.user.tokens.get( ... ); ok(); else: get from api, callback: ok.
Comment 6 Krinkle 2012-02-26 19:38:02 UTC
(In reply to comment #3)

> BTW: do the function name "postWithEditToken" need to contain the word "Token"?
> Wouldn't be more intuitive if the user didn't have to write that when using the
> API to edit a page? E.g. api.edit( params, ok, err )?

You're right in that postWithEditToken doesn't sound Iike a function that should be used directly in an application. However the name is good as it is in my opinion.

It doesn't edit a page by default, it's used as a pre-processor basically to either continue or get an edit token first. You still need to set action=edit in the params (or something else). Looks like an mw.Api.prototype.edit function should be created separate from this that'll call it with action=edit. Not related to this bug though, create a new enhancement bug for it and a patch if you like :)
Comment 7 Helder 2012-02-26 19:47:09 UTC
(In reply to comment #6)
> create a new enhancement bug for it and a patch if you like :)

Created bug 34744, but without a patch (for now?)... =P
Comment 8 This, that and the other (TTO) 2013-05-12 07:44:19 UTC
*** Bug 47239 has been marked as a duplicate of this bug. ***
Comment 9 Gerrit Notification Bot 2014-02-05 23:04:41 UTC
Change 111636 had a related patch set uploaded by Krinkle:
[WIP] mediawiki.api: Refactor getToken

https://gerrit.wikimedia.org/r/111636
Comment 10 Gerrit Notification Bot 2014-04-03 17:41:22 UTC
Change 111636 merged by jenkins-bot:
mediawiki.api: Refactor getToken and postWithToken methods

https://gerrit.wikimedia.org/r/111636

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


Navigation
Links