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
This commit is contained in:
Gilles Dubuc 2014-04-08 11:37:24 +02:00
parent 642b69c3f1
commit 204d582a3a
4 changed files with 57 additions and 7 deletions

View file

@ -30,6 +30,11 @@ if ( !isset( $wgMediaViewerIsInBeta ) ) {
$wgMediaViewerIsInBeta = false; $wgMediaViewerIsInBeta = false;
} }
if ( !isset( $wgMediaViewerShowSurvey ) ) {
/** @var bool: If set, MediaViewer might direct the user to a survey. **/
$wgMediaViewerShowSurvey = false;
}
if ( !isset( $wgEnableMediaViewerForLoggedInUsersOnly ) ) { if ( !isset( $wgEnableMediaViewerForLoggedInUsersOnly ) ) {
/** /**
* @var bool: If set, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on for * @var bool: If set, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on for

View file

@ -144,12 +144,14 @@ class MultimediaViewerHooks {
* @return bool * @return bool
*/ */
public static function resourceLoaderGetConfigVars( &$vars ) { public static function resourceLoaderGetConfigVars( &$vars ) {
global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor; global $wgAPIPropModules, $wgNetworkPerformanceSamplingFactor,
$wgMediaViewerShowSurvey;
$vars['wgMultimediaViewer'] = array( $vars['wgMultimediaViewer'] = array(
'infoLink' => self::$infoLink, 'infoLink' => self::$infoLink,
'discussionLink' => self::$discussionLink, 'discussionLink' => self::$discussionLink,
'helpLink' => self::$helpLink, 'helpLink' => self::$helpLink,
'globalUsageAvailable' => isset( $wgAPIPropModules['globalusage'] ), 'globalUsageAvailable' => isset( $wgAPIPropModules['globalusage'] ),
'showSurvey' => (bool)$wgMediaViewerShowSurvey,
); );
$vars['wgNetworkPerformanceSamplingFactor'] = $wgNetworkPerformanceSamplingFactor; $vars['wgNetworkPerformanceSamplingFactor'] = $wgNetworkPerformanceSamplingFactor;
$vars['wgMediaViewer'] = true; $vars['wgMediaViewer'] = true;

View file

@ -39,7 +39,9 @@
*/ */
this.buttons = {}; this.buttons = {};
this.initFeedbackButton(); if ( this.shouldShowFeedbackSurvey() ) {
this.initFeedbackButton();
}
this.initReuseButton(); this.initReuseButton();
if ( !mw.user.isAnon() ) { if ( !mw.user.isAnon() ) {
this.initDescriptionPageButton(); 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 * Generates a survey URL (currently constant but the possibility of splitting by
* editor cohort was mentioned). * editor cohort was mentioned).
* @return {string} * @return {string}
*/ */
SBP.getFeedbackSurveyUrl = function () { 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' );
}; };
/** /**

View file

@ -16,14 +16,25 @@
*/ */
( function( mw, $ ) { ( 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() { function createStripeButtons() {
var fixture = $( '#qunit-fixture' ); var fixture = $( '#qunit-fixture' );
return new mw.mmv.ui.StripeButtons( fixture, $( '<div>' ).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, var buttons,
oldMwUserIsAnon = mw.user.isAnon; oldMwUserIsAnon = mw.user.isAnon;
@ -33,7 +44,6 @@
assert.ok( buttons, 'UI element is created.' ); assert.ok( buttons, 'UI element is created.' );
assert.strictEqual( buttons.buttons.$reuse.length, 1, 'Reuse button 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.' ); assert.ok( !buttons.buttons.$descriptionPage, 'File page button not created for anon.' );
// now pretend we are logged in // now pretend we are logged in
@ -45,6 +55,29 @@
mw.user.isAnon = oldMwUserIsAnon; 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 ) { QUnit.test( 'set()/empty() sanity test:', 1, function ( assert ) {
var buttons = createStripeButtons(), var buttons = createStripeButtons(),
fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' }, fakeImageInfo = { descriptionUrl: '//commons.wikimedia.org/wiki/File:Foo.jpg' },