Commit graph

33 commits

Author SHA1 Message Date
MusikAnimal 13c9eae26e 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-11-18 22:23:22 -05:00
Umherirrender 75428fa046 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Ic474721ccdb77614f46b0237251927e04b2f183d
2024-10-19 23:29:39 +02:00
jenkins-bot a32d8005ea Merge "Remove $wgCodeMirrorRTL as redundant config setting" 2024-09-19 17:09:17 +00:00
thiemowmde f5a5598ba4 Make use of upstream markTestSkippedIfExtensionNotLoaded
This does the same as before.

Also:
* Make use of more fitting ??= operator.
* We can use & for union types, I believe.

Change-Id: I359408473882a9337b40ec464562a4358f8d3241
2024-09-13 12:38:53 +02:00
MusikAnimal b27c9843b5 Remove $wgCodeMirrorRTL as redundant config setting
This was introduced in Iac30ffe274 to control the rollout of CM6 to RTL
wikis separately from LTR wikis because of various bugs. While RTL still
isn't perfect, it is stable enough now (hewiki has not complained) and
the 2017 editor is also fully supported. Thus, we no longer need this
feature flag.

Bug: T170001
Change-Id: Ia439527aaab07644b358cedf9603cd9d148b6608
2024-08-30 22:03:07 +00:00
MusikAnimal 1413e288c6 Hooks: use CM6 wording for colorblind preference
The message existed since I4bc069e0d3 but accidentally went unused.

Change-Id: Ic03ec526d7f807e6031e495f033c6fce1b6bb51a
2024-08-15 01:33:43 -04:00
Fomafix e0dc1c0c32 Use service 'GadgetsRepo' instead of deprecated GadgetRepo::singleton()
The service 'GadgetsRepo' gets injected as optional service.

This change requires a phan dependency on extension Gadgets in
project integration/config in file zuul/parameter_functions.py:
I5052e0c666b7dc7af6061e57001f9feac666e029

Change-Id: Ib405ad79b3c348bed51a8938a6a8f73bd35267d2
2024-07-01 09:32:50 +00:00
MusikAnimal c853e9587d CM6: Rework ResourceLoader modules
Documentation is at https://w.wiki/9kxt

The idea is that modules ending in `.init` imply they initialize
CodeMirror and maniuplate the DOM. The others only export classes for
use in integreations.

In doing so, 'ext.CodeMirror.v6.WikiEditor' now only exports the
CodeMirrorWikiEditor class, while 'ext.CodeMirror.v6.WikiEditor.init'
is added for use on #wpTextbox1 through action=edit.

Bug: T174811
Change-Id: Iec62ac9dc77918904bed886d2d46ccc03e0927f7
2024-04-15 12:40:16 -04:00
MusikAnimal 3dcbb6590d Add $wgCodeMirrorRTL to control rollout to RTL wikis
We want to get moving on rolling out CodeMirror 6 to LTR wikis, but want
to slow rollout to RTL wikis since we are still ironing out some issues
there, specifically T358804.

Bug: T170001
Bug: T358804
Change-Id: Iac30ffe2746139326159fd406fab3b097b3187f5
2024-04-15 00:03:03 +00:00
MusikAnimal f3f46d8e05 CM6: Add syntax highlighting preference for users without WikiEditor
This adds the `ext.CodeMirror.v6.init` ResourceLoader module which
allows use of CodeMirror on `#wpTextbox1` without the use of WikiEditor
(the 'usebetatoolbar' preference). In order for users to opt-in to using
CodeMirror, we make the existing 'usecodemirror' option into a visible
preference. In addition, with two preferences related to CodeMirror, we
group them under a new heading 'Syntax highlighting'. More preferences
may be added later to this section following T359498.

When WikiEditor is not enabled, the layout of the action=edit page has
the textarea as a sibling to other visible content, like `.editOptions`.
Because of this, we can't simply append the CodeMirror DOM to the parent
like we were before, as that would put the visible editor beneath the
edit summary, Publish button, etc. Instead we rework the CodeMirror to
first add a wrapper around the textarea and use that as the parent. This
way, `.cm-editor` is always in the same place in the DOM as the native
textarea.

Line wrapping and focus/blur events are also moved to CodeMirror, as
these are needed when not using WikiEditor.

Bug: T190108
Change-Id: I4bc069e0d398aa7088e4f50bbd0ddda458b289c3
2024-04-09 22:05:20 -04:00
MusikAnimal 60013b1f1f Hooks: restore respect of $wgCodeMirrorLineNumberingNamespaces in CM5
Restore the ResourceLoaderGetConfigVars hook which CodeMirror 5 still
relies on when it checks $wgCodeMirrorLineNumberingNamespaces.
In CM6, this is set in the config provided by DataScript.php.

Partially reverts I67518c0968

Bug: T347211
Follow-Up: I67518c0968f64c79e290f57b4884d30a161212d3
Change-Id: Id34858da68f7e08d16f8d1312bbbd355ccf8d140
2024-03-27 22:36:27 -04:00
MusikAnimal 7e9d90bb52 CM6: put template folding behind feature flag and rework config settings
Template folding is likely going to be a big 'hit' of a feature, but not
everyone will want it. Until CodeMirror prefs are introduced (T359498),
we need a way to control the rollout of template folding. This commit
adds $wgCodeMirrorTemplateFoldingNamespaces which acts similar to the
existing $wgCodeMirrorLineNumberingNamespaces.

We also move template folding to be part of CodeMirrorModeMediaWiki,
since the feature is unique to MediaWiki wikitext.

Move configuration settings to be part of the DataScript, thus removing
the need for the ResourceLoaderGetConfigVarsHook (which unnecessarily
makes the config settings available on every page load).

Other minor changes like adding missing JSDoc blocks.

Bug: T30684
Change-Id: I67518c0968f64c79e290f57b4884d30a161212d3
2024-03-14 23:54:39 -04:00
MusikAnimal 63cd3e4ff8 CodeMirror 6: show wikitext highlighting on protected pages
It is necessary to have a way to toggle CodeMirror on and off, so we use
WikiEditor and hide all other buttons. This is more costly than loading
just vanilla CodeMirror, but it ensures a consistent experience with
pages that are editable, with the toggle button in the familiar place.
At a later time, WikiEditor may be updated to better support read only
pages in a lightweight fashion (T188817).

Bug: T301615
Change-Id: I8ea7597d07ff60a3f58ba306d2d6d12d3ec08b16
2024-03-11 17:35:20 -04:00
MusikAnimal 894d2c33e9 Hooks: further limit where CodeMirror RL modules are loaded
This fixes a preexisting issue where we were loading CodeMirror on pages
where it would never be used. We use the EditPage__showEditForm_initial
hook so we don't need to check the action.

This commit introduces the CodeMirrorContentModels extension attribute,
used to limit where CodeMirror is loaded automatically. By default,
this includes only CONTENT_MODEL_WIKITEXT ('wikitext'). This extension
attribute serves as a stepping stone to CM being used on content types
other than just wikitext.

Bug: T359206
Change-Id: Ibefc028c5ef6275393202fe773c26162715e1bca
2024-03-11 17:30:10 -04:00
MusikAnimal 15215cb81f Utilize __non_webpack_require__ so we can source virtual files
This removes the need for a separate init module. Using
`__non_webpack_require__` will force Webpack to compile as `require`
instead of `__webpack_require__`, allowing ResourceLoader to inject the
virtual file.

Change-Id: I00203f4665b49cb92ee9db356445fdc2ab17fc5f
2024-02-14 08:47:21 -05:00
MusikAnimal c670344851 Implement core MediaWiki stream parser for CodeMirror 6
This is more or less a exact port of the old stream parser, with the big
notable change being that all configuration-related code lives in a
separate class, CodeMirrorModeMediaWikiConfig. A smaller change is that
closing HTML tags that are marked as errors now have the ending '>'
character highlighted red, when it didn't before.

Integration with other extensions and modes is saved for a future patch
(T348684). This means <nowiki>, <ref> and other extension-supplied
markup is not yet highlighted.

The entry point for WikiEditor integration is now at
ext.CodeMirror.v6.WikiEditor.init.js, which needs to first require the
virtual file set via the DataScript (PHP) class. This can't be
integrated into the CM6 code because it needs to be precompiled before
ResourceLoader can use it (T281781).

Known issues, to be addressed separately:

* No support for TagModes / PluginModes (T348684)
* Identical adjacent tokens produce excess markup (T352917)
* Section headings do not have line-level styling (T351686)

Bug: T348019
Change-Id: I8f8a81f362bed60dea14ecde9487a2b0c89225e8
2024-01-02 23:18:32 -05:00
gerritbot 1ead9c4b79 Update UserOptionsLookup's FQN
User-options related classes are being moved to the MediaWiki\User\Options namespace in MediaWiki Core; reflect that change here.

Bug: T352284
Depends-On: I9822eb1553870b876d0b8a927e4e86c27d83bd52
Change-Id: Ib0022571e750becc87c56adcb2d5bdb203b6254d
2023-11-29 12:38:30 +00:00
Ed Sanders 329235c417 Document generated message keys
Change-Id: Ie6f7dbea0726ec711fa5f23c1779b999107c7612
2023-11-02 18:46:56 +00:00
MusikAnimal 65b864588b Enable support for RTL when using CodeMirror 6
Refactor common contentAttributes Facet into a default Extension

Bug: T170001
Change-Id: I648bac617b5939c1fc4e115144e55a5cb77d6d66
2023-10-17 20:33:01 -04:00
MusikAnimal c0b01008a4 Add $wgCodeMirrorConflictingGadgets instead of checking wikEd directly
Since wikEd and DotsSyntaxHighlighter are both popular gadgets in and
outside WMF wikis, they are included in this setting by default.

Change-Id: If6c953858f9cf73024959b5a3b71b33ab7b48b4c
2023-10-11 01:33:35 -04:00
jenkins-bot 39ed5a05fc Merge "CodeMirror6: add new modules, feature flag, and URL query parameter" 2023-10-10 08:49:11 +00:00
MusikAnimal 880c690a10 CodeMirror6: add new modules, feature flag, and URL query parameter
Add a new $wgCodeMirrorV6 temporary feature flag that when enabled,
will load the 'ext.CodeMirror.v6.WikiEditor' module that is built
against CodeMirror 6. You can also pass in the ?cm6enable=1 query
parameter to force use of CodeMirror 6. This is currently only
implemented for the 2010 editor.

Due to packaging constraints with CodeMirror 6, we now use Webpack to
bundle the files, which are then used by ResourceLoader. This is similar
to what is done for Extension:Popups, MobileFrontend, among other
extensions.

A new generic class CodeMirror can be used on other areas where syntax
highlighting is desirable, but not necessarily for editing (i.e. without
WikiEditor).

This commit merely lays the foundation for CodeMirror 6 and updates
WikiEditor to use it. The actual MediaWiki syntax highlighting will come
with a future commit.

With the new Webpack build, the Gruntfile was removed and the tasks
moved to npm commands.

Bug: T317243
Change-Id: I2239d2449b2db3b638551f847eb4eff1aafa6276
2023-10-09 19:51:24 -04:00
Fomafix b6c3eca38b Use namespaced classes
Change-Id: I2d9f6a9a8b7e0812a0a758455219aef826a0ffa5
2023-10-03 09:18:59 +00:00
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
Ed Sanders 5b69b2380c Always use the strict equality flag when using in_array
Change-Id: Ieb7dc53cbd5b45b6064e05fe5df0401918bbb36d
2023-06-06 13:37:54 +01:00
gerritbot b704455012 Update moved class EditPage
See T321882. Moved in Ibefc44eb64aed

Bug: T321681
Change-Id: I2c9bf1c8289f3e45be6f88e685b52371291d66e9
2023-05-06 22:48:02 +00:00
Fomafix 81eb401a75 Use HookHandlers and inject services
Change-Id: Ia72968e53373d136efb75e6f82fb7bd27665f83d
2023-01-02 22:12:20 +00:00
WMDE-Fisch 574ceba9bf Remove $wgCodeMirrorColorblindColors feature flag
Bug: T307188
Change-Id: I7a8f2b02cad160df838ebfb167b63296123b4a08
2022-06-13 13:20:24 +02:00
Adam Wight 9f34c4d220 Remove $wgCodeMirrorEnableBracketMatching feature flag
Bug: T307188
Change-Id: Ibb21dea29c87d8fac898506c19f329273348c190
2022-06-13 10:34:41 +02:00
Adam Wight 396d50cd5d Remove $wgCodeMirrorAccessibilityColors feature flag
Get rid of the flag, without making any substantial changes to the
code.  A follow-up commit will merge the CSS into base rules.

Bug: T307188
Change-Id: I601df5047d0db3cfb9559538487d3d39bb6c7cf4
2022-06-10 16:18:42 +02:00
Umherirrender 0ce9a922dd Replace Action::getActionName by IContextSource::getActionName
Change-Id: Ica106d108f8930b93c9bbd4851d2915b40d7b343
2022-04-15 23:17:08 +02:00
WMDE-Fisch c3cda7edd7 Add colorblind-friendly scheme
Including an user options to enable/disable the scheme. Defaults
to false. Feature is only availible together with the new more
accessibile color scheme as the CSS depends on each other.

Set behind a new temporary feature flag.

Bug: T305027
Change-Id: I46d240a30eda5a1526ada1fe9b724f7b4594b426
2022-04-08 14:12:43 +02:00
Reedy 386bb03b01 Namespace extension
Change-Id: I83913927e86d44726d3a1c3a682cc1f6e2372f07
2022-02-06 15:16:42 +00:00
Renamed from includes/CodeMirrorHooks.php (Browse further)