2023-08-17 04:58:59 +00:00
|
|
|
require( './ext.CodeMirror.data.js' );
|
|
|
|
|
2024-08-30 21:47:19 +00:00
|
|
|
if ( mw.config.get( 'extCodeMirrorConfig' ).useV6 ) {
|
|
|
|
const deprecationFn = mw.log.makeDeprecated(
|
|
|
|
'CodeMirror5-deprecation',
|
|
|
|
'CodeMirror 5 has been deprecated in MediaWiki 1.43 and will be removed in 1.44. ' +
|
|
|
|
'Please migrate to CodeMirror 6. See https://w.wiki/B3pr for more information.'
|
|
|
|
);
|
|
|
|
deprecationFn();
|
|
|
|
}
|
|
|
|
|
2023-08-17 04:58:59 +00:00
|
|
|
/**
|
|
|
|
* Log usage of CodeMirror.
|
|
|
|
*
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
function logUsage( data ) {
|
|
|
|
/* eslint-disable camelcase */
|
2024-06-14 11:57:43 +00:00
|
|
|
const event = Object.assign( {
|
2023-08-17 04:58:59 +00:00
|
|
|
session_token: mw.user.sessionId(),
|
|
|
|
user_id: mw.user.getId()
|
|
|
|
}, data );
|
2024-06-14 11:57:43 +00:00
|
|
|
const editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
2023-08-17 04:58:59 +00:00
|
|
|
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
|
2018-01-04 12:35:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-08-17 04:58:59 +00:00
|
|
|
new mw.Api().saveOption( 'usecodemirror', prefValue ? 1 : 0 );
|
|
|
|
mw.user.options.set( 'usecodemirror', prefValue ? 1 : 0 );
|
|
|
|
}
|
2018-01-04 12:35:36 +00:00
|
|
|
|
2023-08-17 04:58:59 +00:00
|
|
|
module.exports = {
|
|
|
|
logUsage: logUsage,
|
|
|
|
setCodeEditorPreference: setCodeEditorPreference
|
|
|
|
};
|