mediawiki-extensions-CodeMi.../resources/ext.CodeMirror.js
Ed Sanders f0fb93d3e1 ESLint: Enforce prefer-const
Change-Id: I7f45137a47dddcd2fc70201f28680edce907b522
2024-06-22 10:26:58 +01:00

39 lines
992 B
JavaScript

require( './ext.CodeMirror.data.js' );
/**
* Log usage of CodeMirror.
*
* @param {Object} data
*/
function logUsage( data ) {
/* eslint-disable camelcase */
const event = Object.assign( {
session_token: mw.user.sessionId(),
user_id: mw.user.getId()
}, data );
const editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
if ( editCountBucket !== null ) {
event.user_edit_count_bucket = editCountBucket;
}
/* eslint-enable camelcase */
mw.track( 'event.CodeMirrorUsage', event );
}
/**
* Save CodeMirror enabled preference.
*
* @param {boolean} prefValue True, if CodeMirror should be enabled by default, otherwise false.
*/
function setCodeEditorPreference( prefValue ) {
if ( !mw.user.isNamed() ) { // Skip it for unnamed users
return;
}
new mw.Api().saveOption( 'usecodemirror', prefValue ? 1 : 0 );
mw.user.options.set( 'usecodemirror', prefValue ? 1 : 0 );
}
module.exports = {
logUsage: logUsage,
setCodeEditorPreference: setCodeEditorPreference
};