Phuedx has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232275
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
A resources/ext.quicksurveys.views/utils.js
5 files changed, 97 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys
refs/changes/75/232275/1
diff --git a/extension.json b/extension.json
index 1cd4b50..37e2224 100644
--- a/extension.json
+++ b/extension.json
@@ -48,6 +48,7 @@
"resources/ext.quicksurveys.views/styles.less"
],
"scripts": [
+ "resources/ext.quicksurveys.views/utils.js",
"resources/ext.quicksurveys.views/QuickSurvey.js"
]
},
@@ -79,6 +80,9 @@
],
"BeforePageDisplay": [
"QuickSurveys\\Hooks::onBeforePageDisplay"
+ ],
+ "EventLoggingRegisterSchemas": [
+ "QuickSurveys\\Hooks::onEventLoggingRegisterSchemas"
]
},
"config": {
diff --git a/includes/QuickSurveys.hooks.php b/includes/QuickSurveys.hooks.php
index 4e172b3..3cd96d9 100644
--- a/includes/QuickSurveys.hooks.php
+++ b/includes/QuickSurveys.hooks.php
@@ -47,4 +47,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 aa0e168..6620cc3 100644
--- a/resources/ext.quicksurveys.init/init.js
+++ b/resources/ext.quicksurveys.init/init.js
@@ -8,7 +8,8 @@
isArticle = mw.config.get( 'wgIsArticle' );
mw.extQuickSurveys = {
- views: {}
+ views: {},
+ utils: {}
};
if ( availableSurveys.length ) {
@@ -37,12 +38,13 @@
mw.loader.using( 'ext.quicksurveys.views'
).done( function () {
var panel;
panel = new
mw.extQuickSurveys.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.on( 'dismiss', function () {
mw.storage.set( storageId, '~'
);
diff --git a/resources/ext.quicksurveys.views/QuickSurvey.js
b/resources/ext.quicksurveys.views/QuickSurvey.js
index 1a93fba..84d29fe 100644
--- a/resources/ext.quicksurveys.views/QuickSurvey.js
+++ b/resources/ext.quicksurveys.views/QuickSurvey.js
@@ -1,4 +1,6 @@
( function ( $ ) {
+ var utils = mw.extQuickSurveys.utils;
+
/**
* Extends a class with new methods and member properties.
*
@@ -44,19 +46,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'
}
}
],
@@ -132,10 +134,24 @@
return new OO.ui[widgetName]( config );
},
/**
- * @param {Number} answer
+ * Log the answer to Schema:QuickSurveysResponses
+ * @see
https://meta.wikimedia.org/wiki/Schema:QuickSurveysResponses
+ * @param {String} answer
*/
- log: function () {
- // Todo: T109009
+ log: function ( answer ) {
+ var survey = this.config.survey;
+
+ if ( mw.eventLog ) {
+ 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: utils.getEditCountBucket(
mw.config.get( 'wgUserEditCount' ) ),
+ countryCode: utils.getCountryCode()
+ } );
+ }
},
/**
* Fired when one of the options are clicked.
diff --git a/resources/ext.quicksurveys.views/utils.js
b/resources/ext.quicksurveys.views/utils.js
new file mode 100644
index 0000000..0cdf609
--- /dev/null
+++ b/resources/ext.quicksurveys.views/utils.js
@@ -0,0 +1,42 @@
+( function ( $ ) {
+ /**
+ * Return edit count bucket based on the number of edits
+ * @param {Number} editCount
+ * @returns {String}
+ */
+ 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;
+ }
+
+ /**
+ * Return two letter country code from the GeoIP cookie.
+ * Return 'Unknown' if the cookie is not set.
+ * @returns {String}
+ */
+ function getCountryCode() {
+ var GeoIP = $.cookie( 'GeoIP' );
+
+ if ( GeoIP ) {
+ return GeoIP.split( ':' )[0];
+ }
+ return 'Unknown';
+ }
+
+ mw.extQuickSurveys.utils.getEditCountBucket = getEditCountBucket;
+ mw.extQuickSurveys.utils.getCountryCode = getCountryCode;
+}( jQuery ) );
+
--
To view, visit https://gerrit.wikimedia.org/r/232275
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: dev
Gerrit-Owner: Phuedx <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits