Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6057928
mediawiki.ForeignRest.core.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
mediawiki.ForeignRest.core.js
View Options
module
.
exports
=
(
function
()
{
/**
* @classdesc Interact with the REST API of another MediaWiki site. mw.ForeignRest creates
* an object like {@link 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.
* ```
* const 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;
* ```
*
* @class mw.ForeignRest
* @extends mw.Rest
* @since 1.36
*
* @constructor
* @description Create an instance of `mw.ForeignRest`.
* @param {string} url URL pointing to another wiki's `rest.php` endpoint.
* @param {mw.ForeignApi} foreignActionApi
* @param {Object} [options] See {@link mw.Rest}.
* @param {boolean} [options.anonymous=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.
*
* @author Petr Pchelko
*/
function
CoreForeignRest
(
url
,
foreignActionApi
,
options
)
{
this
.
apiUrl
=
url
;
this
.
anonymous
=
options
&&
options
.
anonymous
;
this
.
foreignActionApi
=
foreignActionApi
;
options
=
$
.
extend
(
/* deep= */
true
,
{
ajax
:
{
url
:
this
.
apiUrl
,
xhrFields
:
{
withCredentials
:
!
this
.
anonymous
}
}
},
options
);
// Call parent constructor
CoreForeignRest
.
super
.
call
(
this
,
options
);
}
OO
.
inheritClass
(
CoreForeignRest
,
mw
.
Rest
);
return
CoreForeignRest
;
}()
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 5 2026, 01:32 (5 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
93/0e/a331497ff73a03acfc68ce116d07
Default Alt Text
mediawiki.ForeignRest.core.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment