Log user edit count bucket

Bug: T269986
Change-Id: Iff3c983a59738312bc39bf65e2428526724fe139
This commit is contained in:
Adam Wight 2021-01-14 14:10:57 +01:00 committed by WMDE-Fisch
parent 26f41000a8
commit 36212a7877
3 changed files with 44 additions and 23 deletions

View file

@ -187,7 +187,7 @@
},
"EventLogging": {
"Schemas": {
"CodeMirrorUsage": 20713609
"CodeMirrorUsage": 20981443
}
}
},

View file

@ -175,6 +175,23 @@
} );
}
function logUsage( data ) {
var event, editCountBucket;
/* eslint-disable camelcase */
event = {
session_token: mw.user.sessionId(),
user_id: mw.user.getId()
};
$.extend( event, data );
editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
if ( editCountBucket !== null ) {
event.user_edit_count_bucket = editCountBucket;
}
/* eslint-enable camelcase */
mw.track( 'event.CodeMirrorUsage', event );
}
/**
* Updates CodeMirror button on the toolbar according to the current state (on/off)
*/
@ -220,17 +237,13 @@
}
updateToolbarButton();
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
logUsage( {
editor: 'wikitext',
enabled: codeMirror !== null,
toggled: true,
session_token: mw.user.sessionId(),
user_id: mw.user.getId(),
// eslint-disable-next-line no-jquery/no-global-selector
// eslint-disable-next-line no-jquery/no-global-selector,camelcase
edit_start_ts_ms: parseInt( $( 'input[name="wpStarttime"]' ).val() ) * 1000 || 0
} );
/* eslint-enable camelcase */
}
/**
@ -279,17 +292,13 @@
}
updateToolbarButton();
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
logUsage( {
editor: 'wikitext',
enabled: useCodeMirror,
toggled: false,
session_token: mw.user.sessionId(),
user_id: mw.user.getId(),
// eslint-disable-next-line no-jquery/no-global-selector
// eslint-disable-next-line no-jquery/no-global-selector,camelcase
edit_start_ts_ms: parseInt( $( 'input[name="wpStarttime"]' ).val() ) * 1000 || 0
} );
/* eslint-enable camelcase */
}
$( function () {

View file

@ -30,6 +30,24 @@ ve.ui.CodeMirrorTool.static.group = 'codeMirror';
ve.ui.CodeMirrorTool.static.commandName = 'codeMirror';
ve.ui.CodeMirrorTool.static.deactivateOnSelect = false;
// TODO: consolidate with code in ext.CodeMirror.js, see T272035
ve.ui.CodeMirrorTool.prototype.logUsage = function ( data ) {
var event, editCountBucket;
/* eslint-disable camelcase */
event = {
session_token: mw.user.sessionId(),
user_id: mw.user.getId()
};
$.extend( event, data );
editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
if ( editCountBucket !== null ) {
event.user_edit_count_bucket = editCountBucket;
}
/* eslint-enable camelcase */
mw.track( 'event.CodeMirrorUsage', event );
};
/**
* @inheritdoc
*/
@ -45,16 +63,13 @@ ve.ui.CodeMirrorTool.prototype.onSelect = function () {
new mw.Api().saveOption( 'usecodemirror', useCodeMirror ? 1 : 0 );
mw.user.options.set( 'usecodemirror', useCodeMirror ? 1 : 0 );
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
this.logUsage( {
editor: 'wikitext-2017',
enabled: useCodeMirror,
toggled: true,
session_token: mw.user.sessionId(),
user_id: mw.user.getId(),
// eslint-disable-next-line camelcase
edit_start_ts_ms: ( this.toolbar.target.startTimeStamp * 1000 ) || 0
} );
/* eslint-enable camelcase */
};
/**
@ -73,16 +88,13 @@ ve.ui.CodeMirrorTool.prototype.onSurfaceChange = function ( oldSurface, newSurfa
this.setActive( useCodeMirror );
if ( this.toolbar.target.startTimeStamp ) {
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
this.logUsage( {
editor: 'wikitext-2017',
enabled: useCodeMirror,
toggled: false,
session_token: mw.user.sessionId(),
user_id: mw.user.getId(),
// eslint-disable-next-line camelcase
edit_start_ts_ms: ( this.toolbar.target.startTimeStamp * 1000 ) || 0
} );
/* eslint-enable camelcase */
}
}
};