Last modified: 2014-04-03 17:43:36 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
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
How about making API calls to some other wiki?
(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?
(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.
(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.
(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 :)
(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
*** Bug 47239 has been marked as a duplicate of this bug. ***
Change 111636 had a related patch set uploaded by Krinkle: [WIP] mediawiki.api: Refactor getToken https://gerrit.wikimedia.org/r/111636
Change 111636 merged by jenkins-bot: mediawiki.api: Refactor getToken and postWithToken methods https://gerrit.wikimedia.org/r/111636