Record usage statistics for syntax highlighting

Bug: T260138
Change-Id: Ic9b95d6331bf85704822a69483880faaaa578a0e
This commit is contained in:
Andrew Kostka 2020-11-19 17:20:25 +01:00
parent de62f40fc2
commit 7d01567c4f
3 changed files with 53 additions and 1 deletions

View file

@ -167,6 +167,11 @@
"ext.CodeMirror.visualEditor.init",
"ext.CodeMirror.visualEditor"
]
},
"EventLogging": {
"Schemas": {
"CodeMirrorUsage": 20713609
}
}
},
"manifest_version": 2

View file

@ -210,6 +210,18 @@
setCodeEditorPreference( true );
}
updateToolbarButton();
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
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
edit_start_ts_ms: parseInt( $( 'input[name="wpStarttime"]' ).val() ) * 1000 || 0
} );
/* eslint-enable camelcase */
}
/**
@ -249,8 +261,19 @@
if ( useCodeMirror ) {
enableCodeMirror();
}
updateToolbarButton();
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
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
edit_start_ts_ms: parseInt( $( 'input[name="wpStarttime"]' ).val() ) * 1000 || 0
} );
/* eslint-enable camelcase */
}
$( function () {

View file

@ -44,6 +44,17 @@ 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', {
editor: 'wikitext-2017',
enabled: useCodeMirror,
toggled: true,
session_token: mw.user.sessionId(),
user_id: mw.user.getId(),
edit_start_ts_ms: ( this.toolbar.target.startTimeStamp * 1000 ) || 0
} );
/* eslint-enable camelcase */
};
/**
@ -60,6 +71,19 @@ ve.ui.CodeMirrorTool.prototype.onSurfaceChange = function ( oldSurface, newSurfa
useCodeMirror = mw.user.options.get( 'usecodemirror' ) > 0;
command.execute( surface, [ useCodeMirror ] );
this.setActive( useCodeMirror );
if ( this.toolbar.target.startTimeStamp ) {
/* eslint-disable camelcase */
mw.track( 'event.CodeMirrorUsage', {
editor: 'wikitext-2017',
enabled: useCodeMirror,
toggled: false,
session_token: mw.user.sessionId(),
user_id: mw.user.getId(),
edit_start_ts_ms: ( this.toolbar.target.startTimeStamp * 1000 ) || 0
} );
/* eslint-enable camelcase */
}
}
};