mw.messagePoster: Support foreign wikis
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 10 Dec 2015 18:51:27 +0000 (10:51 -0800)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 10 Dec 2015 18:51:27 +0000 (10:51 -0800)
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

resources/Resources.php
resources/src/mediawiki.messagePoster/mediawiki.messagePoster.WikitextMessagePoster.js
resources/src/mediawiki.messagePoster/mediawiki.messagePoster.factory.js

index 4657a6a..d7320f5 100644 (file)
@@ -1065,6 +1065,7 @@ return array(
                'dependencies' => array(
                        'oojs',
                        'mediawiki.api',
+                       'mediawiki.ForeignApi',
                ),
                'targets' => array( 'desktop', 'mobile' ),
        ),
index ad01865..862454d 100644 (file)
@@ -8,9 +8,10 @@
         *
         * @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;
                this.title = title;
        }
 
index 4d0231f..b6dc2b4 100644 (file)
@@ -8,7 +8,6 @@
         * @singleton
         */
        function MwMessagePosterFactory() {
-               this.api = new mw.Api();
                this.contentModelToClass = {};
        }
 
@@ -50,6 +49,7 @@
         * 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:
         *
         *   - 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,
                        factory = this;
 
-               return this.api.get( {
+               if ( apiUrl ) {
+                       api = new mw.ForeignApi( apiUrl );
+               } else {
+                       api = mw.Api();
+               }
+
+               return api.get( {
                        action: 'query',
                        prop: 'info',
                        indexpageids: true,
@@ -76,7 +82,8 @@
                                return mw.loader.using( moduleName ).then( function () {
                                        return factory.createForContentModel(
                                                contentModel,
-                                               title
+                                               title,
+                                               api
                                        );
                                }, 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 {mw.Api} api mw.Api instance that the instance should use
         * @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 );
        };
 
        mw.messagePoster = {