jenkins-bot has submitted this change and it was merged.

Change subject: Send WikiGrok responses to wikidata.org
......................................................................


Send WikiGrok responses to wikidata.org

To test locally:
1. Add '*' to $wgCrossSiteAJAXdomains (includes/DefaultSettings.php)
2. Change $wgMFWikiDataEndpoint to 'http://localhost:8080/w/api.php'
(extensions/MobileFrontend/includes/config/Wikidata.php)
3. Visit 
http://127.0.0.1:8080/wiki/2?mobileaction=alpha&wikidataid=Q209939&wikigrokversion=b
(Make sure the domains in step 2 and 3 are different)

Change-Id: I51a01333ad53b5449f72b51a10b0093e30105d0e
---
M javascripts/modules/wikigrok/WikiGrokResponseApi.js
M tests/qunit/modules/wikigrok/test_WikiGrokResponseApi.js
2 files changed, 41 insertions(+), 18 deletions(-)

Approvals:
  Phuedx: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/javascripts/modules/wikigrok/WikiGrokResponseApi.js 
b/javascripts/modules/wikigrok/WikiGrokResponseApi.js
index 3905736..e616544 100644
--- a/javascripts/modules/wikigrok/WikiGrokResponseApi.js
+++ b/javascripts/modules/wikigrok/WikiGrokResponseApi.js
@@ -2,14 +2,17 @@
 ( function ( M ) {
        var WikiGrokResponseApi,
                context = M.require( 'context' ),
-               Api = M.require( 'api' ).Api;
+               user = M.require( 'user' ),
+               ForeignApi = M.require( 'modules/ForeignApi' ),
+               endpoint = mw.config.get( 'wgMFWikiDataEndpoint' );
 
        /**
         * Record claims to the WikiGrok API
         * @class WikiGrokApi
         * @extends Api
         */
-       WikiGrokResponseApi = Api.extend( {
+       WikiGrokResponseApi = ForeignApi.extend( {
+               apiUrl: endpoint,
                /**
                 * Initialize with default values
                 * @method
@@ -22,7 +25,7 @@
                        this.taskToken = options.taskToken;
                        this.taskType = 'version ' + options.version;
                        this.testing = false;
-                       Api.prototype.initialize.apply( this, arguments );
+                       ForeignApi.prototype.initialize.apply( this, arguments 
);
                },
                /**
                 * Saves claims to the wikigrok API server
@@ -31,7 +34,7 @@
                 * @return {jQuery.Deferred} Object returned by ajax call
                 */
                recordClaims: function ( claims ) {
-                       return this.postWithToken( 'edit', {
+                       var data = {
                                action: 'wikigrokresponse',
                                page_id: mw.config.get( 'wgArticleId' ),
                                user_token: this.userToken,
@@ -41,8 +44,16 @@
                                subject: this.subject,
                                mobile_mode: context.getMode(),
                                testing: this.testing,
-                               claims: JSON.stringify( claims )
-                       } );
+                               claims: JSON.stringify( claims ),
+                               wiki: mw.config.get( 'wgDBname' )
+                       };
+                       // To ensure that logged in users' requests don't get 
recorded as anonymous due to
+                       // CentralAuth problems, responses of users who are 
logged in locally should have
+                       // assert=user.
+                       if ( !user.isAnon() ) {
+                               data.assert = 'user';
+                       }
+                       return this.postWithToken( 'csrf', data );
                }
        } );
        M.define( 'modules/wikigrok/WikiGrokResponseApi', WikiGrokResponseApi );
diff --git a/tests/qunit/modules/wikigrok/test_WikiGrokResponseApi.js 
b/tests/qunit/modules/wikigrok/test_WikiGrokResponseApi.js
index 73829e5..5d00d11 100644
--- a/tests/qunit/modules/wikigrok/test_WikiGrokResponseApi.js
+++ b/tests/qunit/modules/wikigrok/test_WikiGrokResponseApi.js
@@ -1,7 +1,8 @@
 ( function ( $, M ) {
 
        var WikiGrokResponseApi = M.require( 
'modules/wikigrok/WikiGrokResponseApi' ),
-               Api = M.require( 'api' ).Api;
+               ForeignApi = M.require( 'modules/ForeignApi' ),
+               user = M.require( 'user' );
 
        QUnit.module( 'MobileFrontend: WikiGrokResponseApi.js', {
                setup: function () {
@@ -12,32 +13,43 @@
                                userToken: 'token',
                                taskToken: 'taskToken'
                        } );
-
-                       this.spy = this.sandbox.stub( Api.prototype, 
'postWithToken' );
-               }
-       } );
-
-       QUnit.test( 'recordClaims', 8, function ( assert ) {
-               var callArgs,
-                       claims = [ {
+                       this.claims = [ {
                                a: 1,
                                campaign: 'actor'
                        }, {
                                b: 2,
                                campaign: 'author'
                        } ];
-               this.api.recordClaims( claims );
+
+                       this.spy = this.sandbox.stub( ForeignApi.prototype, 
'postWithToken' );
+               }
+       } );
+
+       QUnit.test( 'recordClaims - Anons', 9, function ( assert ) {
+               var callArgs;
+               this.sandbox.stub( user, 'isAnon' ).returns( true );
+               this.api.recordClaims( this.claims );
                assert.ok( this.spy.called );
                callArgs = this.spy.getCall( 0 ).args;
-               assert.strictEqual( callArgs[ 0 ], 'edit' );
+               assert.strictEqual( callArgs[ 0 ], 'csrf' );
                assert.strictEqual( callArgs[ 1 ].action, 'wikigrokresponse' );
-               assert.strictEqual( callArgs[ 1 ].claims, JSON.stringify( 
claims ) );
+               assert.strictEqual( callArgs[ 1 ].claims, JSON.stringify( 
this.claims ) );
                //jscs:disable requireCamelCaseOrUpperCaseIdentifiers
                assert.strictEqual( callArgs[ 1 ].subject_id, 'Q764812' );
                assert.strictEqual( callArgs[ 1 ].subject, 'title' );
                assert.strictEqual( callArgs[ 1 ].user_token, 'token' );
                assert.strictEqual( callArgs[ 1 ].task_token, 'taskToken' );
+               assert.strictEqual( callArgs[ 1 ].assert, undefined );
                //jscs:enable requireCamelCaseOrUpperCaseIdentifiers
        } );
 
+       QUnit.test( 'recordClaims - non-Anons', 2, function ( assert ) {
+               var callArgs;
+               this.sandbox.stub( user, 'isAnon' ).returns( false );
+               this.api.recordClaims( this.claims );
+               assert.ok( this.spy.called );
+               callArgs = this.spy.getCall( 0 ).args;
+               assert.strictEqual( callArgs[ 1 ].assert, 'user' );
+       } );
+
 }( jQuery, mw.mobileFrontend ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I51a01333ad53b5449f72b51a10b0093e30105d0e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org>
Gerrit-Reviewer: Bmansurov <bmansu...@wikimedia.org>
Gerrit-Reviewer: Phuedx <g...@samsmith.io>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to