mediawiki-extensions-CodeMi.../resources/ext.CodeMirror.js
MusikAnimal 46b7208d13 Convert applicable ResourceLoader modules to use packageFiles
Move WikiEditor-specific code to ext.CodeMirror.WikiEditor, leaivng only
CodeMirror-specific things in ext.CodeMirror, including the logUsage
method which was duplicated in the VE plugin and now refactored.

Add .env to .gitignore so that selenium tests can be ran more easily

This patch leaves the other non-mediawiki modes still using the
'scripts' system instead of 'packageFiles'. These are not used in
MediaWiki directly but by some extensions (i.e. PhpTags) and using
packageFiles will break that integration.

Bug: T272035
Change-Id: I3bafef196c1f713443d7b8e9cb7dc2891b379f5d
2023-08-24 11:55:13 -04:00

41 lines
1,005 B
JavaScript

require( './ext.CodeMirror.data.js' );
/**
* Log usage of CodeMirror.
*
* @param {Object} data
*/
function logUsage( data ) {
var event, editCountBucket;
/* eslint-disable camelcase */
event = $.extend( {
session_token: mw.user.sessionId(),
user_id: mw.user.getId()
}, data );
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
};