mw.ForeignRest

Interact with the REST API of another MediaWiki site. mw.ForeignRest creates an object like mw.Rest, but automatically handles everything required to communicate with another MediaWiki wiki via cross-origin requests (CORS).

The foreign wiki must be configured to accept requests from the current wiki. See https://www.mediawiki.org/wiki/Manual:$wgCrossSiteAJAXdomains for details.

var api = new mw.ForeignRest( 'https://commons.wikimedia.org/w/rest.php' );
api.get( '/page/Main_Page/html' )
.done( function ( data ) {
    console.log( data );
} );

Authentication-related MediaWiki extensions may extend this class to ensure that the user authenticated on the current wiki will be automatically authenticated on the foreign one. These extension modules should be registered using the ResourceLoaderForeignApiModules hook. See CentralAuth for a practical example. The general pattern to extend and override the name is:

function MyForeignRest() {};
OO.inheritClass( MyForeignRest, mw.ForeignRest );
mw.ForeignRest = MyForeignRest;

Extends

Constructor

new mw.ForeignRest(url, foreignActionApi, options) #

Create an instance of mw.ForeignRest.

Parameters:

Name Type Attributes Description
url string

URL pointing to another wiki's rest.php endpoint.

foreignActionApi mw.ForeignApi
options Object optional

See mw.Rest.

Properties:
Name Type Attributes Default Description
anonymous boolean optional
false

Perform all requests anonymously. Use this option if the target wiki may otherwise not accept cross-origin requests, or if you don't need to perform write actions or read restricted information and want to avoid the overhead.

Since:
  • 1.36
Author:
  • Petr Pchelko
Source:

Methods

abort() #

Abort all unfinished requests issued by this Api object.

Inherited from:
Source:
Abort all unfinished requests issued by this Api object.

ajax(path, ajaxOptions) → {jQuery.Promise} #

Perform the API call.

Parameters:

Name Type Attributes Description
path string
ajaxOptions Object optional
Inherited from:
Source:

Returns:

Done: API response data and the jqXHR object. Fail: Error code

Type
jQuery.Promise
Perform the API call.

delete(path, body, headers) → {jQuery.Promise} #

Perform REST API DELETE request.

Note: only sending application/json is currently supported.

Parameters:

Name Type Attributes Description
path string
body Object
headers Object optional
Inherited from:
Source:

Returns:

Type
jQuery.Promise
Perform REST API DELETE request.

get(path, query, headers) → {jQuery.Promise} #

Perform REST API get request.

Parameters:

Name Type Attributes Description
path string
query Object
headers Object optional
Inherited from:
Source:

Returns:

Type
jQuery.Promise
Perform REST API get request.

post(path, body, headers) → {jQuery.Promise} #

Perform REST API post request.

Note: only sending application/json is currently supported.

Parameters:

Name Type Attributes Description
path string
body Object optional
headers Object optional
Inherited from:
Source:

Returns:

Type
jQuery.Promise
Perform REST API post request.

put(path, body, headers) → {jQuery.Promise} #

Perform REST API PUT request.

Note: only sending application/json is currently supported.

Parameters:

Name Type Attributes Description
path string
body Object
headers Object optional
Inherited from:
Source:

Returns:

Type
jQuery.Promise
Perform REST API PUT request.