2020-12-18 16:32:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2023-06-29 12:27:57 +00:00
|
|
|
const Api = require( 'wdio-mediawiki/Api' ),
|
|
|
|
BlankPage = require( 'wdio-mediawiki/BlankPage' ),
|
|
|
|
LoginPage = require( 'wdio-mediawiki/LoginPage' ),
|
2023-04-03 17:14:23 +00:00
|
|
|
Util = require( 'wdio-mediawiki/Util' );
|
2020-12-18 16:32:22 +00:00
|
|
|
|
|
|
|
class UserPreferences {
|
2023-06-29 12:27:57 +00:00
|
|
|
async loginAsOther() {
|
|
|
|
const username = Util.getTestString( 'User-' );
|
|
|
|
const password = Util.getTestString();
|
|
|
|
await Api.createAccount( await Api.bot(), username, password );
|
|
|
|
await LoginPage.login( username, password );
|
|
|
|
}
|
|
|
|
|
2023-04-03 17:14:23 +00:00
|
|
|
async setPreferences( preferences ) {
|
|
|
|
await BlankPage.open();
|
2020-12-18 16:32:22 +00:00
|
|
|
Util.waitForModuleState( 'mediawiki.base' );
|
|
|
|
|
2024-06-14 11:51:53 +00:00
|
|
|
return await browser.execute( ( prefs ) => mw.loader.using( 'mediawiki.api' ).then( () => new mw.Api().saveOptions( prefs ) ), preferences );
|
2020-12-18 16:32:22 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 17:14:23 +00:00
|
|
|
async enableWikitext2010EditorWithCodeMirror() {
|
|
|
|
await this.setPreferences( {
|
2020-12-18 16:32:22 +00:00
|
|
|
usebetatoolbar: '1',
|
|
|
|
usecodemirror: '1',
|
CodeMirrorPreferences: add panel to tweak prefs with the editor open
This is toggled by pressing Mod-Shift-, (or Command-Shift-, on MacOS),
which then puts focus on the preferences panel. It can be closed with
the Escape key, just like other CM panels.
The CodeMirror class comes with these extension which can be toggled in
preferences:
* Bracket matching
* Line numbering
* Line wrapping
* Highlight the active line
* Show special characters
Only bracket matching, line numbering, and line wrapping are available
in the 2017 editor.
The bidi isolation and template folding extensions are registered in
CodeMirrorModeMediaWiki as they are MW-specific. CodeMirrorPreferences'
new registerExtension() method allows any consumer of CodeMirror to add
any arbitrary extensions to the preferences panel. This is expected to
be called *after* CodeMirror has finished initializing. The
'ext.CodeMirror.ready' hook now passes the CodeMirror instance to
accommodate this.
The preferences are stored as a single user option in the database,
called 'codemirror-preferences'. The defaults can be configured with the
$wgCodeMirrorDefaultPreferences configuration setting. The
sysadmin-facing values are the familiar boolean, but since CodeMirror is
widely used, we make extra efforts to reduce the storage footprint (see
T54777). This includes only storing preferences that differ from the
defaults, and using binary representation instead of boolean values,
since the user option is stored as a string.
For now, all preferences are ignored in the 2017 editor. In a future
patch, we may add some as toggleable Tools in the VE toolbar.
Other changes:
* Refactor CSS to use a .darkmode() mixin
* Add a method to create a CSS-only fieldset in CodeMirrorPanel
* Fix Jest tests now that there are more calls to mw.user.options.get()
* Adjust Selenium tests to always use CM6
* Adjust Selenium tests to delete test pages (useful for local dev)
* Remove unused code
Bug: T359498
Change-Id: I70dcf2f49418cea632c452c1266440effad634f3
2024-08-16 01:52:13 +00:00
|
|
|
'codemirror-preferences': '{"bracketMatching":1,"lineWrapping":1,"activeLine":0,"specialChars":1,"bidiIsolation":0}',
|
2020-12-18 16:32:22 +00:00
|
|
|
'visualeditor-enable': '0',
|
|
|
|
'visualeditor-newwikitext': '0'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new UserPreferences();
|