From 3b4b0c3c899253e102bc75ea720ffb17ea777750 Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Fri, 28 Jun 2013 18:55:36 -0400 Subject: [PATCH] Add GuidedTour survey about user gender Disabled by default, enabled with $wgVisualEditorEnableGenderSurvey. Change-Id: I2b4aba6a95a33474c3e68423d478aa78e57d86ad --- VisualEditor.hooks.php | 28 +++++++++++++- VisualEditor.i18n.php | 10 +++++ VisualEditor.php | 38 ++++++++++++++++++- modules/ve/init/mw/tours/vegendersurvey.js | 31 +++++++++++++++ .../ve/init/mw/ve.init.mw.genderSurvey.css | 3 ++ modules/ve/init/mw/ve.init.mw.genderSurvey.js | 14 +++++++ 6 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 modules/ve/init/mw/tours/vegendersurvey.js create mode 100644 modules/ve/init/mw/ve.init.mw.genderSurvey.css create mode 100644 modules/ve/init/mw/ve.init.mw.genderSurvey.js diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 0e5e0f5301..03461bc5e3 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -13,7 +13,8 @@ class VisualEditorHooks { protected static $supportedSkins = array( 'vector', 'apex', 'monobook' ); public static function onSetup() { - global $wgVisualEditorEnableEventLogging, $wgResourceModules; + global $wgVisualEditorEnableEventLogging, $wgResourceModules, + $wgVisualEditorEnableGenderSurvey; if ( $wgVisualEditorEnableEventLogging ) { if ( class_exists( 'ResourceLoaderSchemaModule' ) ) { @@ -24,6 +25,14 @@ class VisualEditorHooks { 'schema' => 'Edit', 'revision' => 5570274, ); + + if ( $wgVisualEditorEnableGenderSurvey ) { + $wgResourceModules['schema.GenderSurvey'] = array( + 'class' => 'ResourceLoaderSchemaModule', + 'schema' => 'GenderSurvey', + 'revision' => '5607845', + ); + } } else { wfWarn( 'VisualEditor is configured to use EventLogging, but the extension is ' . ' not available. Disabling wgVisualEditorEnableEventLogging.' ); @@ -79,6 +88,23 @@ class VisualEditorHooks { return true; } + // Temporary survey in conjuction with split test (bug 49604) + // To be removed once no longer needed. + // Depends on GuidedTour and EventLogging + public static function onBeforeWelcomeCreation( &$welcomeCreationMsg, &$injectHtml ) { + global $wgOut, $wgVisualEditorEnableGenderSurvey; + + if ( $wgVisualEditorEnableGenderSurvey ) { + $wgOut->addModules( array( + 'ext.guidedTour.lib', + 'ext.guidedTour.tour.vegendersurvey', + 'ext.visualEditor.genderSurvey' + ) ); + } + + return true; + } + public static function onGetPreferences( $user, &$preferences ) { $preferences['visualeditor-enable'] = array( 'type' => 'toggle', diff --git a/VisualEditor.i18n.php b/VisualEditor.i18n.php index 171c980c24..d09172bf33 100644 --- a/VisualEditor.i18n.php +++ b/VisualEditor.i18n.php @@ -147,6 +147,11 @@ $messages['en'] = array( 'visualeditor-usernamespacepagelink' => 'Project:User namespace', 'visualeditor-viewpage-savewarning' => 'Are you sure you want to go back to view mode without saving first?', 'visualeditor-window-title' => 'Inspect', + 'guidedtour-tour-vegendersurvey-title' => 'Please select your gender', + 'guidedtour-tour-vegendersurvey-description' => 'By participating in this survey, you consent to the transfer of the information you submit to the Wikimedia Foundation in the United States and elsewhere. The information collected is for internal research purposes only and will not be publicly associated with your account. However, we may share the results of this survey with the public in anonymized or aggregated forms.', + 'guidedtour-tour-vegendersurvey-male' => 'Male', + 'guidedtour-tour-vegendersurvey-female' => 'Female', + 'guidedtour-tour-vegendersurvey-optout' => 'Prefer not to say', ); /** Message documentation (Message documentation) @@ -396,6 +401,11 @@ Parameters: {{doc-important|Do not translate "Project"; it is automatically converted to the wiki\'s project namespace.}}', 'visualeditor-viewpage-savewarning' => 'Text shown when the user tries to leave the editor without saving their changes', 'visualeditor-window-title' => 'Title of an unnamed inspector', + 'guidedtour-tour-vegendersurvey-title' => 'Title of gender survey guider', + 'guidedtour-tour-vegendersurvey-description' => 'Description of gender survey guider', + 'guidedtour-tour-vegendersurvey-male' => 'Button on gender survey for choosing \'male\'', + 'guidedtour-tour-vegendersurvey-female' => 'Button on gender survey for choosing \'female\'', + 'guidedtour-tour-vegendersurvey-optout' => 'Button on gender survey for those who prefer not to answer', ); /** Arabic (العربية) diff --git a/VisualEditor.php b/VisualEditor.php index 55a0387a61..3052cdac6f 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -30,7 +30,10 @@ $wgVisualEditorEnableExperimentalCode = false; // * add: Adds #ca-ve-edit. // * replace: Re-creates #ca-edit for VisualEditor and adds #ca-editsource. $wgVisualEditorTabLayout = 'replace'; - +// Conduct an optional survey (the user can decline to answer) on the user's gender +// upon signup. +// Depends on GuidedTour and EventLogging extensions. +$wgVisualEditorEnableGenderSurvey = false; /* Setup */ $wgExtensionCredits['other'][] = array( @@ -98,6 +101,37 @@ $wgResourceModules += array( 've/init/mw/ve.init.mw.splitTest.js', ) ), + + 'ext.guidedTour.tour.vegendersurvey' => $wgVisualEditorResourceTemplate + array( + 'scripts' => array( + 've/init/mw/tours/vegendersurvey.js', + ), + 'dependencies' => array( + 'ext.guidedTour.lib', + ), + 'messages' => array( + 'guidedtour-tour-vegendersurvey-title', + 'guidedtour-tour-vegendersurvey-description', + 'guidedtour-tour-vegendersurvey-male', + 'guidedtour-tour-vegendersurvey-female', + 'guidedtour-tour-vegendersurvey-optout' + ), + ), + + 'ext.visualEditor.genderSurvey' => $wgVisualEditorResourceTemplate + array( + 'scripts' => array( + 've/init/mw/ve.init.mw.genderSurvey.js', + ), + 'styles' => array( + 've/init/mw/ve.init.mw.genderSurvey.css', + ), + 'dependencies' => array( + 'ext.guidedTour.lib', + 'ext.guidedTour.tour.vegendersurvey', + 'ext.visualEditor.mediawiki', + ), + ), + // Alias for backwards compat, safe to remove after 'ext.visualEditor.editPageInit' => $wgVisualEditorResourceTemplate + array( 'dependencies' => array( @@ -663,7 +697,9 @@ $wgHooks['ResourceLoaderGetConfigVars'][] = 'VisualEditorHooks::onResourceLoader $wgHooks['ResourceLoaderTestModules'][] = 'VisualEditorHooks::onResourceLoaderTestModules'; // Bug 49604: Running split test in production if $wgVisualEditorEnableSplitTest is true. +// This requires that GuidedTour and EventLogging are also enabled on the wiki. $wgHooks['AddNewAccount'][] = 'VisualEditorHooks::onAddNewAccount'; +$wgHooks['BeforeWelcomeCreation'][] = 'VisualEditorHooks::onBeforeWelcomeCreation'; $wgExtensionFunctions[] = 'VisualEditorHooks::onSetup'; diff --git a/modules/ve/init/mw/tours/vegendersurvey.js b/modules/ve/init/mw/tours/vegendersurvey.js new file mode 100644 index 0000000000..651e32af3f --- /dev/null +++ b/modules/ve/init/mw/tours/vegendersurvey.js @@ -0,0 +1,31 @@ +/*global mw */ +( function ( $, gt ) { + gt.defineTour( { + name: 'vegendersurvey', + isSinglePage: true, + // shouldLog tells GuidedTour to provide additional logging (step impressions, etc.) + shouldLog: true, + steps: [ { + titlemsg: 'guidedtour-tour-vegendersurvey-title', + descriptionmsg: 'guidedtour-tour-vegendersurvey-description', + allowAutomaticOkay: false, + overlay: true, + buttons: [ { + namemsg: 'guidedtour-tour-vegendersurvey-male', + onclick: function () { + ve.init.mw.genderSurvey.logAndEndTour( 'male' ); + } + }, { + namemsg: 'guidedtour-tour-vegendersurvey-female', + onclick: function () { + ve.init.mw.genderSurvey.logAndEndTour( 'female' ); + } + }, { + namemsg: 'guidedtour-tour-vegendersurvey-optout', + onclick: function () { + ve.init.mw.genderSurvey.logAndEndTour( 'opt-out' ); + } + } ] + } ] + } ); +} ( jQuery, mw.guidedTour ) ); \ No newline at end of file diff --git a/modules/ve/init/mw/ve.init.mw.genderSurvey.css b/modules/ve/init/mw/ve.init.mw.genderSurvey.css new file mode 100644 index 0000000000..19851a5360 --- /dev/null +++ b/modules/ve/init/mw/ve.init.mw.genderSurvey.css @@ -0,0 +1,3 @@ +.mw-guidedtour-tour-vegendersurvey .guider_description { + font-size: small; +} diff --git a/modules/ve/init/mw/ve.init.mw.genderSurvey.js b/modules/ve/init/mw/ve.init.mw.genderSurvey.js new file mode 100644 index 0000000000..edb83dff96 --- /dev/null +++ b/modules/ve/init/mw/ve.init.mw.genderSurvey.js @@ -0,0 +1,14 @@ +/*global mw */ +mw.loader.using( 'schema.GenderSurvey', function () { + ve.init.mw.genderSurvey = { + logAndEndTour: function ( buttonType ) { + mw.eventLog.logEvent( 'GenderSurvey', { + userId: mw.config.get( 'wgUserId' ), + buttonType: buttonType + } ); + mw.guidedTour.endTour( 'vegendersurvey' ); + } + }; + + mw.guidedTour.launchTour( 'vegendersurvey' ); +} );