Allow passing in an external api.php URL to post a message on a remote
wiki. Note that the remote content model must have its messagePoster
implementation registered on the local wiki for this to work.
Bug: T111590
Change-Id: Id52b7d3a12ed5e57e29d3f22fb7f4f36b8a908b1
'dependencies' => array(
'oojs',
'mediawiki.api',
'dependencies' => array(
'oojs',
'mediawiki.api',
+ 'mediawiki.ForeignApi',
),
'targets' => array( 'desktop', 'mobile' ),
),
),
'targets' => array( 'desktop', 'mobile' ),
),
*
* @constructor
* @param {mw.Title} title Wikitext page in a talk namespace, to post to
*
* @constructor
* @param {mw.Title} title Wikitext page in a talk namespace, to post to
+ * @param {mw.Api} api mw.Api object to use
- function WikitextMessagePoster( title ) {
- this.api = new mw.Api();
+ function WikitextMessagePoster( title, api ) {
+ this.api = api;
* @singleton
*/
function MwMessagePosterFactory() {
* @singleton
*/
function MwMessagePosterFactory() {
- this.api = new mw.Api();
this.contentModelToClass = {};
}
this.contentModelToClass = {};
}
* API and ResourceLoader requests in the background.
*
* @param {mw.Title} title Title that will be posted to
* API and ResourceLoader requests in the background.
*
* @param {mw.Title} title Title that will be posted to
+ * @param {string} [apiUrl] api.php URL if the title is on another wiki
* @return {jQuery.Promise} Promise resolving to a mw.messagePoster.MessagePoster.
* For failure, rejected with up to three arguments:
*
* @return {jQuery.Promise} Promise resolving to a mw.messagePoster.MessagePoster.
* For failure, rejected with up to three arguments:
*
* - error Error explanation
* - details Further error details
*/
* - error Error explanation
* - details Further error details
*/
- MwMessagePosterFactory.prototype.create = function ( title ) {
- var pageId, page, contentModel, moduleName,
+ MwMessagePosterFactory.prototype.create = function ( title, apiUrl ) {
+ var pageId, page, contentModel, moduleName, api,
+ if ( apiUrl ) {
+ api = new mw.ForeignApi( apiUrl );
+ } else {
+ api = mw.Api();
+ }
+
+ return api.get( {
action: 'query',
prop: 'info',
indexpageids: true,
action: 'query',
prop: 'info',
indexpageids: true,
return mw.loader.using( moduleName ).then( function () {
return factory.createForContentModel(
contentModel,
return mw.loader.using( moduleName ).then( function () {
return factory.createForContentModel(
contentModel,
);
}, function () {
return $.Deferred().reject( 'failed-to-load-module', 'Failed to load the \'' + moduleName + '\' module' );
);
}, function () {
return $.Deferred().reject( 'failed-to-load-module', 'Failed to load the \'' + moduleName + '\' module' );
*
* @param {string} contentModel Content model of title
* @param {mw.Title} title Title being posted to
*
* @param {string} contentModel Content model of title
* @param {mw.Title} title Title being posted to
+ * @param {mw.Api} api mw.Api instance that the instance should use
* @return {mw.messagePoster.MessagePoster}
*
*/
* @return {mw.messagePoster.MessagePoster}
*
*/
- MwMessagePosterFactory.prototype.createForContentModel = function ( contentModel, title ) {
- return new this.contentModelToClass[ contentModel ]( title );
+ MwMessagePosterFactory.prototype.createForContentModel = function ( contentModel, title, api ) {
+ return new this.contentModelToClass[ contentModel ]( title, api );