From 204d582a3a71999f23d29923f35964cf18efbf6a Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Tue, 8 Apr 2014 11:37:24 +0200 Subject: [PATCH] Add site/language conditions for feedback button Only show the survey button if the user's language matches and the site is enabled, and log which site we are on. The corresponding site configuration commit is Ic07432649906890785769ce5127761e2c84316e2 Change-Id: I575bb286f4289489b80505c901f5a9e7aeecec8b Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/261 --- MultimediaViewer.php | 5 +++ MultimediaViewerHooks.php | 4 +- resources/mmv/ui/mmv.ui.stripeButtons.js | 14 ++++++- .../qunit/mmv/ui/mmv.ui.stripeButtons.test.js | 41 +++++++++++++++++-- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 43575f470..48a96c110 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -30,6 +30,11 @@ if ( !isset( $wgMediaViewerIsInBeta ) ) { $wgMediaViewerIsInBeta = false; } +if ( !isset( $wgMediaViewerShowSurvey ) ) { + /** @var bool: If set, MediaViewer might direct the user to a survey. **/ + $wgMediaViewerShowSurvey = false; +} + if ( !isset( $wgEnableMediaViewerForLoggedInUsersOnly ) ) { /** * @var bool: If set, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on for diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index 2cda482d5..82daf9dc7 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -144,12 +144,14 @@ class MultimediaViewerHooks { * @return bool */ public static function resourceLoaderGetConfigVars( &$vars ) { - global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor; + global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor, + $wgMediaViewerShowSurvey; $vars['wgMultimediaViewer'] = array( 'infoLink' => self::$infoLink, 'discussionLink' => self::$discussionLink, 'helpLink' => self::$helpLink, 'globalUsageAvailable' => isset( $wgAPIPropModules['globalusage'] ), + 'showSurvey' => (bool)$wgMediaViewerShowSurvey, ); $vars['wgNetworkPerformanceSamplingFactor'] = $wgNetworkPerformanceSamplingFactor; $vars['wgMediaViewer'] = true; diff --git a/resources/mmv/ui/mmv.ui.stripeButtons.js b/resources/mmv/ui/mmv.ui.stripeButtons.js index b0329284c..dc82bfc45 100644 --- a/resources/mmv/ui/mmv.ui.stripeButtons.js +++ b/resources/mmv/ui/mmv.ui.stripeButtons.js @@ -39,7 +39,9 @@ */ this.buttons = {}; - this.initFeedbackButton(); + if ( this.shouldShowFeedbackSurvey() ) { + this.initFeedbackButton(); + } this.initReuseButton(); if ( !mw.user.isAnon() ) { this.initDescriptionPageButton(); @@ -108,13 +110,21 @@ } ); }; + /** + * Checks if it is suitable to show a survey to the current user. + */ + SBP.shouldShowFeedbackSurvey = function () { + return mw.config.get( 'wgMultimediaViewer' ).showSurvey && + mw.config.get( 'wgUserLanguage' ) === 'en'; + }; + /** * Generates a survey URL (currently constant but the possibility of splitting by * editor cohort was mentioned). * @return {string} */ SBP.getFeedbackSurveyUrl = function () { - return 'https://www.surveymonkey.com/s/media-viewer-1?c=mediaviewer'; + return 'https://www.surveymonkey.com/s/media-viewer-1?c=' + mw.config.get( 'wgDBname' ); }; /** diff --git a/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js b/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js index 0105907b7..ed1280bc9 100644 --- a/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.stripeButtons.test.js @@ -16,14 +16,25 @@ */ ( function( mw, $ ) { - QUnit.module( 'mmv.ui.StripeButtons', QUnit.newMwEnvironment() ); + var oldShowSurvey; + + QUnit.module( 'mmv.ui.StripeButtons', QUnit.newMwEnvironment( { + setup: function () { + // pretend surveys are enabled for this site + oldShowSurvey = mw.config.get( 'wgMultimediaViewer' ).showSurvey; + mw.config.get( 'wgMultimediaViewer' ).showSurvey = true; + }, + teardown: function () { + mw.config.get( 'wgMultimediaViewer' ).showSurvey = oldShowSurvey; + } + } ) ); function createStripeButtons() { var fixture = $( '#qunit-fixture' ); - return new mw.mmv.ui.StripeButtons( fixture, $( '
' ).appendTo( fixture ) ); + return new mw.mmv.ui.StripeButtons( fixture ); } - QUnit.test( 'Sanity test, object creation and UI construction', 5, function ( assert ) { + QUnit.test( 'Sanity test, object creation and UI construction', 4, function ( assert ) { var buttons, oldMwUserIsAnon = mw.user.isAnon; @@ -33,7 +44,6 @@ assert.ok( buttons, 'UI element is created.' ); assert.strictEqual( buttons.buttons.$reuse.length, 1, 'Reuse button created.' ); - assert.strictEqual( buttons.buttons.$feedback.length, 1, 'Feedback button created.' ); assert.ok( !buttons.buttons.$descriptionPage, 'File page button not created for anon.' ); // now pretend we are logged in @@ -45,6 +55,29 @@ mw.user.isAnon = oldMwUserIsAnon; } ); + QUnit.test( 'Survey conditions', 3, function ( assert ) { + var buttons, + oldLanguage = mw.config.get( 'wgUserLanguage' ); + + // pretend surveys are disabled for this site + mw.config.get( 'wgMultimediaViewer' ).showSurvey = false; + mw.config.set( 'wgUserLanguage', 'en' ); + buttons = createStripeButtons(); + assert.ok( !buttons.buttons.$feedback, 'No survey button by default.' ); + + // pretend surveys are enabled for this site + mw.config.get( 'wgMultimediaViewer' ).showSurvey = true; + buttons = createStripeButtons(); + assert.ok( buttons.buttons.$feedback, 'Survey button shown when enabled.' ); + + // now pretend we don't speak English + mw.config.set( 'wgUserLanguage', 'el' ); + buttons = createStripeButtons(); + assert.ok( !buttons.buttons.$feedback, 'No survey for non-english speakers.' ); + + mw.config.set( 'wgUserLanguage', oldLanguage ); + } ); + QUnit.test( 'set()/empty() sanity test:', 1, function ( assert ) { var buttons = createStripeButtons(), fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' },