Bmansurov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/231609
Change subject: Add support for logging events to Schema:QuickSurveysResponses
......................................................................
Add support for logging events to Schema:QuickSurveysResponses
Bug: T109009
Change-Id: Ib135fe9a62053af75842946e9e9cf88f75987c25
---
M extension.json
M includes/QuickSurveys.hooks.php
M resources/ext.quicksurveys.init/init.js
M resources/ext.quicksurveys.views/QuickSurvey.js
4 files changed, 79 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys
refs/changes/09/231609/1
diff --git a/extension.json b/extension.json
index 9d5ae8f..dd696a8 100644
--- a/extension.json
+++ b/extension.json
@@ -79,6 +79,9 @@
],
"BeforePageDisplay": [
"QuickSurveys\\Hooks::onBeforePageDisplay"
+ ],
+ "EventLoggingRegisterSchemas": [
+ "QuickSurveys\\Hooks::onEventLoggingRegisterSchemas"
]
},
"config": {
diff --git a/includes/QuickSurveys.hooks.php b/includes/QuickSurveys.hooks.php
index 4e172b3..f8dd797 100644
--- a/includes/QuickSurveys.hooks.php
+++ b/includes/QuickSurveys.hooks.php
@@ -21,9 +21,7 @@
public static function onResourceLoaderGetConfigVars( &$vars ) {
$config = ConfigFactory::getDefaultInstance()->makeConfig(
'quicksurveys' );
// Get configured surveys
- $configuredSurveys = $config->has( 'QuickSurveysConfig' )
- ? $config->get( 'QuickSurveysConfig' )
- : array();
+ $configuredSurveys = $config->get( 'QuickSurveysConfig' );
$enabledQuickSurveys = array();
// Make enabled surveys available to the browser
foreach ( $configuredSurveys as $survey ) {
@@ -47,4 +45,24 @@
$out->addModules( 'ext.quicksurveys.init' );
return true;
}
+
+ /**
+ * EventLoggingRegisterSchemas hook handler.
+ *
+ * Registers our EventLogging schemas so that they can be converted to
+ * ResourceLoaderSchemaModules by the EventLogging extension.
+ *
+ * If the module has already been registered in
+ * onResourceLoaderRegisterModules, then it is overwritten.
+ *
+ * @param array $schemas The schemas currently registered with the
EventLogging
+ * extension
+ * @return bool Always true
+ */
+ public static function onEventLoggingRegisterSchemas( &$schemas ) {
+ // @see
https://meta.wikimedia.org/wiki/Schema:QuickSurveysResponses
+ $schemas['QuickSurveysResponses'] = 13003413;
+
+ return true;
+ }
}
diff --git a/resources/ext.quicksurveys.init/init.js
b/resources/ext.quicksurveys.init/init.js
index be3dd3e..3dc3a0a 100644
--- a/resources/ext.quicksurveys.init/init.js
+++ b/resources/ext.quicksurveys.init/init.js
@@ -37,12 +37,13 @@
mw.loader.using( 'ext.quicksurveys.views'
).done( function () {
var panel;
panel = new
mw.extQuickSurvey.views.QuickSurvey( {
- type: survey.type,
- templateData: {
- question:
survey.question,
- description:
survey.description
- }
- } );
+ survey: survey,
+ type: survey.type,
+ templateData: {
+ question:
survey.question,
+ description:
survey.description
+ }
+ } );
$panel.replaceWith( panel.$element );
panel.stack.on( 'dismiss', function () {
mw.settings.set( storageId, '~'
);
diff --git a/resources/ext.quicksurveys.views/QuickSurvey.js
b/resources/ext.quicksurveys.views/QuickSurvey.js
index 6fe117b..ab26ffa 100644
--- a/resources/ext.quicksurveys.views/QuickSurvey.js
+++ b/resources/ext.quicksurveys.views/QuickSurvey.js
@@ -1,6 +1,33 @@
( function ( $ ) {
+ function getEditCountBucket( editCount ) {
+ var bucket;
+
+ if ( editCount === 0 || editCount === null ) {
+ bucket = '0'
+ } else if ( editCount >= 1 && editCount <= 4 ) {
+ bucket = '1-4';
+ } else if ( editCount >= 5 && editCount <= 99 ) {
+ bucket = '5-99';
+ } else if ( editCount >= 100 && editCount <= 999 ) {
+ bucket = '100-999';
+ } else if ( editCount >= 1000 ) {
+ bucket = '1000+';
+ }
+ bucket += ' edits';
+ return bucket;
+ }
+
+ function getCountryCode() {
+ var GeoIP = $.cookie( 'GeoIP' );
+
+ if ( GeoIP ) {
+ return GeoIP.split( ':' )[0];
+ }
+ return 'Unknown';
+ }
+
function QuickSurvey( config ) {
- this.initialise();
+ this.initialise( config );
}
/**
@@ -17,19 +44,19 @@
{
label: mw.msg(
'ext-quicksurveys-survey-positive' ),
data: {
- answer: 1
+ answer:
'ext-quicksurveys-survey-positive'
}
},
{
label: mw.msg(
'ext-quicksurveys-survey-neutral' ),
data: {
- answer: 0
+ answer:
'ext-quicksurveys-survey-neutral'
}
},
{
label: mw.msg(
'ext-quicksurveys-survey-negative' ),
data: {
- answer: -1
+ answer:
'ext-quicksurveys-survey-negative'
}
}
],
@@ -49,7 +76,7 @@
classes: [ 'message content' ]
}
},
- initialise: function () {
+ initialise: function ( config ) {
var buttonSelect, $btnContainer,
btns = [];
@@ -84,7 +111,7 @@
} );
buttonSelect.$element.appendTo( $btnContainer );
this.$element = this.stack.$element;
- }
+ },
/**
* Make a brand spanking new oojs ui widget from a template
partial
* @param {String} widgetName a valid OOJS UI widget
@@ -106,8 +133,21 @@
/**
* @param {Number} answer
*/
- log: function () {
- // Todo: T109009
+ log: function ( answer ) {
+ var survey = this.config.survey;
+
+ if ( mw.eventLog ) {
+ // TODO: sample?
+ return mw.eventLog.logEvent(
'QuickSurveysResponses', {
+ surveyCodeName: survey.name,
+ surveyResponseValue: answer,
+ platform: mw.config.get('wgMFMode') !==
null ? 'mobile' : 'desktop',
+ platformVersion:
mw.config.get('wgMFMode') || 'stable',
+ isLoggedIn: !mw.user.isAnon(),
+ editCount: getEditCountBucket(
mw.config.get('wgUserEditCount') ),
+ countryCode: getCountryCode()
+ } );
+ }
},
onChoose: function ( btn ) {
this.log( btn.data.answer );
--
To view, visit https://gerrit.wikimedia.org/r/231609
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib135fe9a62053af75842946e9e9cf88f75987c25
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits