Bmansurov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/175639
Change subject: WIP: Don't show WikiGrok twice on the same article after a user
has answered once
......................................................................
WIP: Don't show WikiGrok twice on the same article after a user has answered
once
working on tests....
Change-Id: Iad5c6554c1d06cb53bfaefbcacd747c33b50ff86
---
M javascripts/modules/wikigrok/WikiGrokDialog.js
M javascripts/modules/wikigrok/WikiGrokDialogB.js
M javascripts/modules/wikigrok/init.js
M tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
4 files changed, 60 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/39/175639/1
diff --git a/javascripts/modules/wikigrok/WikiGrokDialog.js
b/javascripts/modules/wikigrok/WikiGrokDialog.js
index c12a29b..7e0e553 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialog.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialog.js
@@ -2,6 +2,7 @@
M.assertMode( [ 'beta', 'alpha' ] );
var Panel = M.require( 'Panel' ),
+ settings = M.require( 'settings' ),
WikiGrokSuggestionApi = M.require(
'modules/wikigrok/WikiGrokSuggestionApi' ),
WikiGrokResponseApi = M.require(
'modules/wikigrok/WikiGrokResponseApi' ),
WikiDataApi = M.require( 'modules/wikigrok/WikiDataApi' ),
@@ -261,7 +262,20 @@
} );
},
+ /**
+ * Save the page title in localStorage so that we don't show
WikiGrok on this page
+ * the next time the user sees the page.
+ */
+ rememberWikiGrokContribution: function () {
+ var pages = $.parseJSON(
+ settings.get( 'pagesWithWikiGrokContributions',
false ) || '{}'
+ );
+ pages[M.getCurrentPage().title] = true;
+ settings.save( 'pagesWithWikiGrokContributions',
JSON.stringify( pages ), false );
+ },
+
thankUser: function ( options, claimAttempted ) {
+ this.rememberWikiGrokContribution();
options.thankUser = true;
if ( claimAttempted ) {
options.contentMsg = 'You just made Wikipedia a
little better, thanks!';
diff --git a/javascripts/modules/wikigrok/WikiGrokDialogB.js
b/javascripts/modules/wikigrok/WikiGrokDialogB.js
index 1638718..9692ab8 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialogB.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialogB.js
@@ -148,6 +148,7 @@
self.logError(
'no-response-cannot-record-user-input' );
} );
self.log( 'widget-click-submit' );
+ self.rememberWikiGrokContribution();
} );
// hide this Dialog when the user reads more about
Wikigrok
diff --git a/javascripts/modules/wikigrok/init.js
b/javascripts/modules/wikigrok/init.js
index f0af48b..7bcf093 100644
--- a/javascripts/modules/wikigrok/init.js
+++ b/javascripts/modules/wikigrok/init.js
@@ -5,6 +5,7 @@
var wikidataID = mw.config.get( 'wgWikibaseItemId' ),
errorSchema = M.require(
'loggingSchemas/mobileWebWikiGrokError' ),
+ settings = M.require( 'settings' ),
permittedOnThisDevice = mw.config.get(
'wgMFEnableWikiGrokOnAllDevices' ) || !M.isWideScreen(),
idOverride,
versionConfigs = {
@@ -22,6 +23,21 @@
versionConfig,
WikiGrokAbTest = M.require( 'WikiGrokAbTest' ),
wikiGrokUser = M.require( 'wikiGrokUser' );
+
+ /*
+ * Checks whether the user has already seen and responded to a WikiGrok
question
+ * before on this device.
+ */
+ function hasUserAlreadyContributedToWikiGrok () {
+ var pages = $.parseJSON(
+ settings.get( 'pagesWithWikiGrokContributions',
false ) || '{}'
+ ),
+ result = false;
+ if ( M.getCurrentPage().title in pages ) {
+ result = true;
+ }
+ return result;
+ }
/*
* Gets the configuration for the version of WikiGrok to use.
@@ -67,6 +83,8 @@
}
if (
+ // show WikiGrok if the user hasn't already contributed to it
on this page before
+ !hasUserAlreadyContributedToWikiGrok() &&
// WikiGrok is enabled
mw.config.get( 'wgMFEnableWikiGrok' ) &&
// We're not on the Main Page
diff --git a/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
b/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
index f3d605c..d4cd527 100644
--- a/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
+++ b/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
@@ -3,6 +3,7 @@
var WikiGrokDialog = M.require( 'modules/wikigrok/WikiGrokDialog' ),
WikiDataApi = M.require( 'modules/wikigrok/WikiDataApi' ),
WikiGrokResponseApi = M.require(
'modules/wikigrok/WikiGrokResponseApi' ),
+ settings = M.require( 'settings'),
suggestions = [ {
"id": "P106",
"name": "occupations",
@@ -12,6 +13,12 @@
Q285759: "insurance broker"
},
pageTitle = 'Some guy';
+
+ function getPagesWithWikiGrokContributions () {
+ return $.parseJSON(
+ settings.get( 'pagesWithWikiGrokContributions', false )
|| '{}'
+ );
+ }
QUnit.module( 'MobileFrontend: WikiGrokDialog', {
teardown: function () {
@@ -124,7 +131,7 @@
this.$el.find( sel ).click();
}
- QUnit.test( '#UI - Question - Click Yes', 2, function ( assert ) {
+ QUnit.test( '#UI - Question - Click Yes', 3, function ( assert ) {
getToQuestion.apply( this );
answerQuestion.call( this, '.yes' );
@@ -132,9 +139,15 @@
// I'm in thanks page now!
assert.equal( this.$el.find( '.wg-link' ).length, 1 );
assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions[pageTitle],
+ true,
+ "User's contribution to WikiGrok has been saved locally
correctly."
+ );
} );
- QUnit.test( '#UI - Question - Click No', 2, function ( assert ) {
+ QUnit.test( '#UI - Question - Click No', 3, function ( assert ) {
getToQuestion.apply( this );
answerQuestion.call( this, '.no' );
@@ -142,9 +155,15 @@
// I'm in thanks page now!
assert.equal( this.$el.find( '.wg-link' ).length, 1 );
assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions[pageTitle],
+ true,
+ "User's contribution to WikiGrok has been saved locally
correctly."
+ );
} );
- QUnit.test( '#UI - Question - Click Not sure', 2, function ( assert ) {
+ QUnit.test( '#UI - Question - Click Not sure', 3, function ( assert ) {
getToQuestion.apply( this );
answerQuestion.call( this, '.not-sure' );
@@ -152,6 +171,11 @@
// I'm in thanks page now!
assert.equal( this.$el.find( '.wg-link' ).length, 1 );
assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+ assert.equal(
+ getPagesWithWikiGrokContributions[pageTitle],
+ true,
+ "User's contribution to WikiGrok has been saved locally
correctly."
+ );
} );
}( jQuery, mw.mobileFrontend ) );
--
To view, visit https://gerrit.wikimedia.org/r/175639
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad5c6554c1d06cb53bfaefbcacd747c33b50ff86
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits