Page MenuHomePhabricator

Use MediaWiki JavaScript API instead of custom code
Closed, ResolvedPublic


In PageTriage, we can remove a lot of custom code that uses $.ajax() (15 matches in 8 files) and make use of API functions provided by the mw JavaScript object (mw.Api().saveOption(), mw.user.options.get(), and mw.Api().postWithToken() , etc. For example, the apiSetFilterParams(), saveFilterParams(), setToolbarPreference(), finishSetToolbarPreference() contain code that request a token, then make a request. For example saveFilterParams() has:

if ( this.optionsToken ) {
} else {
	tokenRequest = {
		action: 'tokens',
		type: 'options',
		format: 'json'
	$.ajax( {
		type: 'get',
		url: mw.util.wikiScript( 'api' ),
		data: tokenRequest,
		dataType: 'json',
		success: function ( data ) {
			try {
				that.optionsToken = data.tokens.optionstoken;
			} catch ( e ) {
				throw new Error( 'Could not get token (requires MediaWiki 1.20).' );
	} );

which can be simplified with mw.Api().postWithToken().

There are other sections of code, for example submit() in ext.pageTriage.delete.js which could be rewritten in a more concise way to use mw.Api().postWithToken().

Event Timeline

Doing this should also fix this warning which appears in the console: "\"action=tokens\" has been deprecated. Please use \"action=query&meta=tokens\" instead."}},

Catrope claimed this task.
Catrope moved this task from Code Review to In Progress on the Growth-Team (Current Sprint) board.
Catrope added a subscriber: Catrope.

So it looks like @kostajh did part of this in , but not all of it. I'll do the rest now.

Change 453548 had a related patch set uploaded (by Catrope; owner: Catrope):
[mediawiki/extensions/PageTriage@master] Port all uses of $.ajax() to mw.Api

kostajh added a subscriber: Etonkovidova.

For QA – in my local environment I tested out the various methods that were worked on (i.e. setting tags, adding a note with a tag, marking an article as reviewed, etc). @Etonkovidova let me know if you have any questions about it!

Change 446517 had a related patch set uploaded (by Kosta Harlan; owner: Kosta Harlan):
[mediawiki/extensions/PageTriage@master] DBPerformance: Master connections and writes via POST not GET

Change 446517 merged by jenkins-bot:
[mediawiki/extensions/PageTriage@master] DBPerformance: Master connections and writes via POST not GET

Change 453548 merged by jenkins-bot:
[mediawiki/extensions/PageTriage@master] Port all uses of $.ajax() to mw.Api