| 1 |
require( './ext.CodeMirror.data.js' ); |
| 2 |
|
| 3 |
if ( mw.config.get( 'extCodeMirrorConfig' ).useV6 ) { |
| 4 |
const deprecationFn = mw.log.makeDeprecated( |
| 5 |
'CodeMirror5-deprecation', |
| 6 |
'CodeMirror 5 has been deprecated in MediaWiki 1.43 and will be removed in 1.44. ' + |
| 7 |
'Please migrate to CodeMirror 6. See https://w.wiki/B3pr for more information.' |
| 8 |
); |
| 9 |
deprecationFn(); |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Log usage of CodeMirror. |
| 14 |
* |
| 15 |
* @param {Object} data |
| 16 |
*/ |
| 17 |
function logUsage( data ) { |
| 18 |
/* eslint-disable camelcase */ |
| 19 |
const event = Object.assign( { |
| 20 |
session_token: mw.user.sessionId(), |
| 21 |
user_id: mw.user.getId() |
| 22 |
}, data ); |
| 23 |
const editCountBucket = mw.config.get( 'wgUserEditCountBucket' ); |
| 24 |
if ( editCountBucket !== null ) { |
| 25 |
event.user_edit_count_bucket = editCountBucket; |
| 26 |
} |
| 27 |
/* eslint-enable camelcase */ |
| 28 |
mw.track( 'event.CodeMirrorUsage', event ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Save CodeMirror enabled preference. |
| 33 |
* |
| 34 |
* @param {boolean} prefValue True, if CodeMirror should be enabled by default, otherwise false. |
| 35 |
*/ |
| 36 |
function setCodeEditorPreference( prefValue ) { |
| 37 |
if ( !mw.user.isNamed() ) { // Skip it for unnamed users |
| 38 |
return; |
| 39 |
} |
| 40 |
new mw.Api().saveOption( 'usecodemirror', prefValue ? 1 : 0 ); |
| 41 |
mw.user.options.set( 'usecodemirror', prefValue ? 1 : 0 ); |
| 42 |
} |
| 43 |
|
| 44 |
module.exports = { |
| 45 |
logUsage: logUsage, |
| 46 |
setCodeEditorPreference: setCodeEditorPreference |
| 47 |
}; |