Jdlrobson has uploaded a new change for review.

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

Change subject: Hygiene: Move getOrigin method from mw.mobileFrontend to Api
......................................................................

Hygiene: Move getOrigin method from mw.mobileFrontend to Api

* Update usage
* Styling fixes whilst there.

Change-Id: Ief1e6af11301638cae6dc142afab5d904d5b799a
---
M javascripts/api.js
M javascripts/application.js
M javascripts/modules/uploads/PhotoApi.js
M javascripts/specials/uploads.js
M tests/qunit/test_api.js
5 files changed, 18 insertions(+), 19 deletions(-)


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

diff --git a/javascripts/api.js b/javascripts/api.js
index 33978e0..83504f9 100644
--- a/javascripts/api.js
+++ b/javascripts/api.js
@@ -100,6 +100,16 @@
                },
 
                /**
+                * Returns the current URL including protocol
+                *
+                * @method
+                * @return {String}
+                */
+               getOrigin: function () {
+                       return window.location.protocol + '//' + 
window.location.hostname;
+               },
+
+               /**
                 * Retrieves a token for a given endpoint
                 * FIXME: consolidate with mw.Api.getToken
                 * use postWithToken / getToken where possible
@@ -149,7 +159,7 @@
                                        type: tokenType
                                };
                                if ( endpoint ) {
-                                       data.origin = M.getOrigin();
+                                       data.origin = this.getOrigin();
                                        if ( caToken ) {
                                                data.centralauthtoken = caToken;
                                        }
diff --git a/javascripts/application.js b/javascripts/application.js
index 2e92c19..b2293f5 100644
--- a/javascripts/application.js
+++ b/javascripts/application.js
@@ -249,16 +249,6 @@
        }
 
        /**
-        * Returns the current URL including protocol
-        *
-        * @method
-        * @return {String}
-        */
-       function getOrigin() {
-               return window.location.protocol + '//' + 
window.location.hostname;
-       }
-
-       /**
         * FIXME: sandbox from mf-application.js
         *
         * @method
@@ -380,7 +370,6 @@
                escapeHash: escapeHash,
                inNamespace: inNamespace,
                getCurrentPage: getCurrentPage,
-               getOrigin: getOrigin,
                getSessionId: getSessionId,
                isWideScreen: isWideScreen,
                lockViewport: lockViewport,
diff --git a/javascripts/modules/uploads/PhotoApi.js 
b/javascripts/modules/uploads/PhotoApi.js
index ea0b191..08fd16f 100644
--- a/javascripts/modules/uploads/PhotoApi.js
+++ b/javascripts/modules/uploads/PhotoApi.js
@@ -133,10 +133,10 @@
                 */
                save: function ( options ) {
                        var isNewPage = mw.config.get( 'wgArticleId' ) === 0,
-                       isNewFile = M.inNamespace( 'file' ) && isNewPage,
-                       self = this,
-                       result = $.Deferred(),
-                       apiUrl = endpoint || this.apiUrl;
+                               isNewFile = M.inNamespace( 'file' ) && 
isNewPage,
+                               self = this,
+                               result = $.Deferred(),
+                               apiUrl = endpoint || this.apiUrl;
 
                        options.editSummaryMessage = options.insertInPage ?
                                'mobile-frontend-photo-article-edit-comment' :
@@ -170,7 +170,7 @@
 
                                // add origin only when doing CORS
                                if ( endpoint ) {
-                                       uploadUrl += '&origin=' + M.getOrigin();
+                                       uploadUrl += '&origin=' + 
self.getOrigin();
                                        if ( caToken ) {
                                                data.centralauthtoken = caToken;
                                        }
diff --git a/javascripts/specials/uploads.js b/javascripts/specials/uploads.js
index 2fa36e0..40ef3ea 100644
--- a/javascripts/specials/uploads.js
+++ b/javascripts/specials/uploads.js
@@ -35,7 +35,7 @@
                                        gailimit: this.limit,
                                        gaicontinue: this.endTimestamp,
                                        prop: 'imageinfo',
-                                       origin: corsUrl ? M.getOrigin() : 
undefined,
+                                       origin: corsUrl ? this.getOrigin() : 
undefined,
                                        // FIXME: [API] have to request 
timestamp since api returns an object
                                        // rather than an array thus we need a 
way to sort
                                        iiprop: 'url|timestamp',
diff --git a/tests/qunit/test_api.js b/tests/qunit/test_api.js
index 519220e..eb4bed7 100644
--- a/tests/qunit/test_api.js
+++ b/tests/qunit/test_api.js
@@ -83,7 +83,7 @@
                        xhrFields: { withCredentials: true }
                };
                corsData = { action: 'tokens', type: 'watch',
-                       origin: M.getOrigin()
+                       origin: this.api.getOrigin()
                };
                corsParams = {
                        url: 'http://commons.wikimedia.org/w/api.php',

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

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

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

Reply via email to