JGonera has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80132


Change subject: Hygiene: get rid of M.getApiUrl()
......................................................................

Hygiene: get rid of M.getApiUrl()

Change-Id: Idaa5bef8c420b18ac3a9c14ada79fb4932061b0c
---
M javascripts/common/api.js
M javascripts/common/application.js
M javascripts/modules/mf-watchstar.js
M javascripts/modules/nearby/NearbyApi.js
M javascripts/modules/uploads/PhotoApi.js
M javascripts/specials/uploads.js
M tests/javascripts/common/test_api.js
7 files changed, 15 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/32/80132/1

diff --git a/javascripts/common/api.js b/javascripts/common/api.js
index 2d885c6..91eb6fc 100644
--- a/javascripts/common/api.js
+++ b/javascripts/common/api.js
@@ -1,12 +1,13 @@
 ( function( M, $ ) {
 
        var EventEmitter = M.require( 'eventemitter' ),
+               apiUrl = mw.config.get( 'wgScriptPath', '' ) + '/api.php',
                Api, api;
 
        // TODO: this might be dangerous and cause conflicts with other code
        // should we move it to Api#ajax?
        $.ajaxSetup( {
-               url: M.getApiUrl(),
+               url: apiUrl,
                dataType: 'json',
                data: {
                        format: 'json'
@@ -14,6 +15,8 @@
        } );
 
        Api = EventEmitter.extend( {
+               apiUrl: apiUrl,
+
                /**
                 * Constructor, if you override it, use _super().
                 *
@@ -155,7 +158,7 @@
                                        }
                                }
                                this.ajax( data, {
-                                       url: endpoint || M.getApiUrl(),
+                                       url: endpoint || this.apiUrl,
                                        xhrFields: { withCredentials: true }
                                } ).then( function( tokenData ) {
                                        var token;
diff --git a/javascripts/common/application.js 
b/javascripts/common/application.js
index 1a427b2..2279cfb 100644
--- a/javascripts/common/application.js
+++ b/javascripts/common/application.js
@@ -207,14 +207,6 @@
                }
        }
 
-       // FIXME: remove when we use api module everywhere
-       /**
-        * @deprecated
-        */
-       function getApiUrl() {
-               return mw.config.get( 'wgScriptPath', '' ) + '/api.php';
-       }
-
        function isLoggedIn() {
                return mw.config.get( 'wgUserName' ) ? true : false;
        }
@@ -279,7 +271,6 @@
                init: init,
                emit: emit,
                jQuery: typeof jQuery  !== 'undefined' ? jQuery : false,
-               getApiUrl: getApiUrl,
                getOrigin: getOrigin,
                getSessionId: getSessionId,
                isLoggedIn: isLoggedIn,
diff --git a/javascripts/modules/mf-watchstar.js 
b/javascripts/modules/mf-watchstar.js
index fbabb6d..55b96fd 100644
--- a/javascripts/modules/mf-watchstar.js
+++ b/javascripts/modules/mf-watchstar.js
@@ -52,12 +52,7 @@
                        popup.show( msg, popupClass );
                }
 
-               $.ajax( {
-                       type: 'post', dataType: 'json',
-                       url:  M.getApiUrl(),
-                       data: data
-               } ).done( callback ).fail( errback ).
-                       done( report );
+               api.post( data ).done( callback ).fail( errback ).done( report 
);
        }
 
        function createButton( container ) {
@@ -126,13 +121,10 @@
         * @param {Function} callback: A callback that is passed a json of 
mappings from title to booleans describing whether page is watched
         */
        function asyncCheckWatchStatus( titles, callback ) {
-               $.ajax( {
-                       url:  M.getApiUrl(), dataType: 'json',
-                       data: {
-                               action: 'query', format: 'json',
-                               titles: titles.join( '|' ),
-                               prop: 'info', inprop: 'watched'
-                       }
+               api.get( {
+                       action: 'query', format: 'json',
+                       titles: titles.join( '|' ),
+                       prop: 'info', inprop: 'watched'
                } ).done( function( data ) {
                                var pages = data.query.pages,
                                        statuses = {}, page, i;
diff --git a/javascripts/modules/nearby/NearbyApi.js 
b/javascripts/modules/nearby/NearbyApi.js
index f5aa728..ed92fa6 100644
--- a/javascripts/modules/nearby/NearbyApi.js
+++ b/javascripts/modules/nearby/NearbyApi.js
@@ -75,7 +75,7 @@
                        },
                        {
                                dataType: endpoint ? 'jsonp' : 'json',
-                               url: endpoint || M.getApiUrl()
+                               url: endpoint || this.apiUrl
                        } ).then( function( resp ) {
                                var pages;
                                // FIXME: API bug 48512
diff --git a/javascripts/modules/uploads/PhotoApi.js 
b/javascripts/modules/uploads/PhotoApi.js
index b76cd4a..52e2fae 100644
--- a/javascripts/modules/uploads/PhotoApi.js
+++ b/javascripts/modules/uploads/PhotoApi.js
@@ -1,7 +1,6 @@
 ( function( M, $ ) {
        var Api = M.require( 'api' ).Api,
                endpoint = mw.config.get( 'wgMFPhotoUploadEndpoint' ),
-               apiUrl = endpoint || M.getApiUrl(),
                PhotoApi;
 
        // Originally written by Brion for WikiLovesMonuments app
@@ -117,7 +116,7 @@
                },
 
                save: function( options ) {
-                       var self = this, result = $.Deferred();
+                       var self = this, result = $.Deferred(), apiUrl = 
endpoint || this.apiUrl;
 
                        options.editSummaryMessage = options.insertInPage ?
                                'mobile-frontend-photo-article-edit-comment' :
diff --git a/javascripts/specials/uploads.js b/javascripts/specials/uploads.js
index dd542ac..8ea63d9 100644
--- a/javascripts/specials/uploads.js
+++ b/javascripts/specials/uploads.js
@@ -36,7 +36,7 @@
                                        iiprop: 'url|timestamp',
                                        iiurlwidth: IMAGE_WIDTH
                                }, {
-                                       url: corsUrl || M.getApiUrl(),
+                                       url: corsUrl || this.apiUrl,
                                        xhrFields: { withCredentials: true }
                                } ).done( function( resp ) {
                                        if ( resp.query && resp.query.pages ) {
diff --git a/tests/javascripts/common/test_api.js 
b/tests/javascripts/common/test_api.js
index 9683d1c..86f5cd1 100644
--- a/tests/javascripts/common/test_api.js
+++ b/tests/javascripts/common/test_api.js
@@ -20,7 +20,7 @@
        $.ajax( {
                data: { test: 'test' }
        } );
-       strictEqual( this.lastXhr.url.indexOf( M.getApiUrl() ), 0, 'set default 
API URL' );
+       strictEqual( this.lastXhr.url.indexOf( Api.prototype.apiUrl ), 0, 'set 
default API URL' );
 } );
 
 QUnit.test( 'default instance', 1, function() {
@@ -111,7 +111,7 @@
                this.api = new Api();
                stub = sinon.stub( this.api , 'ajax' );
                params = {
-                       url: M.getApiUrl(),
+                       url: this.api.apiUrl,
                        xhrFields: { withCredentials: true }
                };
                corsData = { action: 'tokens', type: 'watch',

-- 
To view, visit https://gerrit.wikimedia.org/r/80132
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idaa5bef8c420b18ac3a9c14ada79fb4932061b0c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to