Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

morebits: api improvements #1038

Merged
merged 4 commits into from Jul 14, 2020

Conversation

siddharthvp
Copy link
Member

#1029 seems rather far-fetched for now, so it might still be worth making some improvements to Morebits.wiki.api.

All action=query requests can be done using GET protocol.
…in JSON

As JSON support is fairly recent, there are unlikely to be any existing clients.
This is the best time we can make this change.
All new API usages in JSON should anyway be done with formatversion=2 (phab:T178734 et al)
Copy link
Collaborator

@Amorymeltzer Amorymeltzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@@ -1774,7 +1777,7 @@ Morebits.wiki.api.prototype = {

var ajaxparams = $.extend({}, {
context: this,
type: 'POST',
type: this.query.action === 'query' ? 'GET' : 'POST',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -1721,6 +1721,8 @@ Morebits.wiki.api = function(currentAction, query, onSuccess, statusElement, onE
}
if (!query.format) {
this.query.format = 'xml';
} else if (query.format === 'json' && !query.formatversion) {
this.query.formatversion = '2';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about this being a good time. I'm already using it locally, so 👍

morebits.js Outdated
@@ -1738,6 +1740,7 @@ Morebits.wiki.api.prototype = {
statusText: null, // result received from the API, normally "success" or "error"
errorCode: null, // short text error code, if any, as documented in the MediaWiki API
errorText: null, // full error description, if any
tokenRetry: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you renamed this to badtokenRetry below (or vice-versa)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. So what messed me up here was the later realisation that all actions don't use a CSRF token. If we want to be fussy about it, we could do something like what I do in my bot framework (querying the type of token needed as well) but IMO not really necessary.

Easier to pretend that everything is CSRF-based (badtoken error on anything which isn't will be failing as before).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's roughly where I ended up thinking. It's few and far between atm, so nbd.

@Amorymeltzer Amorymeltzer added this to the July 2020 update milestone Jul 12, 2020
Some methods of mw.Api does this as well.

Automatically retry (at most once) on badtoken errors for all API calls.
With this, there is no need to separately handle badtoken errors in save(), deletePage() and undeletePage()
Action completed status messages are just like all other status lines at the moment.
They ought to be emphasised.
Copy link
Collaborator

@Amorymeltzer Amorymeltzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it

@Amorymeltzer Amorymeltzer merged commit 6b815fe into wikimedia-gadgets:master Jul 14, 2020
Amorymeltzer added a commit to Amorymeltzer/twinkle that referenced this pull request Oct 5, 2020
Stems from af13dce/wikimedia-gadgets#1038.  Looks like, since `Morebits.wiki.api.getToken` explicitly creates a new construct, `this` in `returnError`'s return ends up going global (`window`).

Reported at WT:TW (https://en.wikipedia.org/w/index.php?oldid=982033312#%22Getting_token%22_and_what?)
Amorymeltzer added a commit to Amorymeltzer/twinkle that referenced this pull request Oct 6, 2020
Stems from af13dce/wikimedia-gadgets#1038.  Looks like, since `Morebits.wiki.api.getToken` explicitly creates a new construct, `this` in `returnError`'s return ends up going global (`window`).

Reported at WT:TW (https://en.wikipedia.org/w/index.php?oldid=982033312#%22Getting_token%22_and_what?)
@siddharthvp siddharthvp deleted the apiimprove branch October 22, 2020 20:26
Amorymeltzer added a commit that referenced this pull request Dec 8, 2020
- `errorformat` defaults to `html`, only accepting `wikitext` and `plaintext` otherwise (#1179)
- `uselang` is set to the wiki's content language (#1179)
- `formatversion` defaults to `2` when `format=json` (#1038)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants