mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-18 00:30:30 +00:00
46b7208d13
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
41 lines
1,005 B
JavaScript
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
|
|
};
|