2014-08-20 17:03:46 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-06 15:13:05 +00:00
|
|
|
namespace MediaWiki\Extension\CodeMirror;
|
|
|
|
|
2023-10-10 19:23:03 +00:00
|
|
|
use InvalidArgumentException;
|
2023-10-03 09:15:14 +00:00
|
|
|
use MediaWiki\Config\Config;
|
2024-03-01 00:36:39 +00:00
|
|
|
use MediaWiki\EditPage\EditPage;
|
2023-10-10 19:23:03 +00:00
|
|
|
use MediaWiki\Extension\Gadgets\GadgetRepo;
|
2024-03-01 00:36:39 +00:00
|
|
|
use MediaWiki\Hook\EditPage__showEditForm_initialHook;
|
2024-01-10 00:02:44 +00:00
|
|
|
use MediaWiki\Hook\EditPage__showReadOnlyForm_initialHook;
|
2023-10-03 09:15:14 +00:00
|
|
|
use MediaWiki\Output\OutputPage;
|
2022-09-19 19:01:32 +00:00
|
|
|
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
2024-10-19 21:29:39 +00:00
|
|
|
use MediaWiki\Registration\ExtensionRegistry;
|
2024-03-28 02:36:25 +00:00
|
|
|
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
2023-11-29 12:38:30 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
2023-10-03 09:15:14 +00:00
|
|
|
use MediaWiki\User\User;
|
2020-12-11 11:30:44 +00:00
|
|
|
|
2024-03-01 00:36:39 +00:00
|
|
|
/**
|
|
|
|
* @phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
|
|
|
*/
|
2022-09-19 19:01:32 +00:00
|
|
|
class Hooks implements
|
2024-03-01 00:36:39 +00:00
|
|
|
EditPage__showEditForm_initialHook,
|
2024-01-10 00:02:44 +00:00
|
|
|
EditPage__showReadOnlyForm_initialHook,
|
2024-03-28 02:36:25 +00:00
|
|
|
ResourceLoaderGetConfigVarsHook,
|
2022-09-19 19:01:32 +00:00
|
|
|
GetPreferencesHook
|
|
|
|
{
|
|
|
|
|
2023-09-19 17:59:29 +00:00
|
|
|
private UserOptionsLookup $userOptionsLookup;
|
2023-10-10 19:23:03 +00:00
|
|
|
private array $conflictingGadgets;
|
2023-09-19 17:59:29 +00:00
|
|
|
private bool $useV6;
|
2024-06-29 21:36:41 +00:00
|
|
|
private ?GadgetRepo $gadgetRepo;
|
2022-09-19 19:01:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param UserOptionsLookup $userOptionsLookup
|
2023-09-19 17:59:29 +00:00
|
|
|
* @param Config $config
|
2024-06-29 21:36:41 +00:00
|
|
|
* @param GadgetRepo|null $gadgetRepo
|
2022-09-19 19:01:32 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2023-09-19 17:59:29 +00:00
|
|
|
UserOptionsLookup $userOptionsLookup,
|
2024-06-29 21:36:41 +00:00
|
|
|
Config $config,
|
|
|
|
?GadgetRepo $gadgetRepo
|
2022-09-19 19:01:32 +00:00
|
|
|
) {
|
|
|
|
$this->userOptionsLookup = $userOptionsLookup;
|
2023-09-19 17:59:29 +00:00
|
|
|
$this->useV6 = $config->get( 'CodeMirrorV6' );
|
2023-10-10 19:23:03 +00:00
|
|
|
$this->conflictingGadgets = $config->get( 'CodeMirrorConflictingGadgets' );
|
2024-06-29 21:36:41 +00:00
|
|
|
$this->gadgetRepo = $gadgetRepo;
|
2022-09-19 19:01:32 +00:00
|
|
|
}
|
2015-08-07 14:45:17 +00:00
|
|
|
|
2017-08-30 21:53:55 +00:00
|
|
|
/**
|
|
|
|
* Checks if CodeMirror for textarea wikitext editor should be loaded on this page or not.
|
|
|
|
*
|
2019-03-11 06:04:20 +00:00
|
|
|
* @param OutputPage $out
|
2023-10-10 19:23:03 +00:00
|
|
|
* @param ExtensionRegistry|null $extensionRegistry Overridden in tests.
|
2017-08-30 21:53:55 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2023-10-10 19:23:03 +00:00
|
|
|
public function shouldLoadCodeMirror( OutputPage $out, ?ExtensionRegistry $extensionRegistry = null ): bool {
|
2019-03-11 06:04:20 +00:00
|
|
|
// Disable CodeMirror when CodeEditor is active on this page
|
2023-05-06 21:19:32 +00:00
|
|
|
// Depends on ext.codeEditor being added by \MediaWiki\EditPage\EditPage::showEditForm:initial
|
2023-06-06 12:37:54 +00:00
|
|
|
if ( in_array( 'ext.codeEditor', $out->getModules(), true ) ) {
|
2019-03-11 06:04:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
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-03-26 20:40:13 +00:00
|
|
|
|
|
|
|
$shouldUseV6 = $this->shouldUseV6( $out );
|
|
|
|
$useCodeMirror = $this->userOptionsLookup->getBoolOption( $out->getUser(), 'usecodemirror' );
|
|
|
|
$useWikiEditor = $this->userOptionsLookup->getBoolOption( $out->getUser(), 'usebetatoolbar' );
|
|
|
|
// Disable CodeMirror 5 when the WikiEditor toolbar is not enabled in preferences.
|
|
|
|
if ( !$shouldUseV6 && !$useWikiEditor ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// In CodeMirror 6, either WikiEditor or the 'usecodemirror' preference must be enabled.
|
|
|
|
if ( $shouldUseV6 && !$useWikiEditor && !$useCodeMirror ) {
|
2019-03-11 06:17:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
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-03-26 20:40:13 +00:00
|
|
|
|
2024-09-13 10:37:00 +00:00
|
|
|
$extensionRegistry ??= ExtensionRegistry::getInstance();
|
2024-03-01 00:36:39 +00:00
|
|
|
$contentModels = $extensionRegistry->getAttribute( 'CodeMirrorContentModels' );
|
2023-10-11 02:00:08 +00:00
|
|
|
$isRTL = $out->getTitle()->getPageLanguage()->isRTL();
|
2024-03-01 00:36:39 +00:00
|
|
|
// Disable CodeMirror if we're on an edit page with a conflicting gadget. See T178348.
|
|
|
|
return !$this->conflictingGadgetsEnabled( $extensionRegistry, $out->getUser() ) &&
|
2023-10-11 02:00:08 +00:00
|
|
|
// CodeMirror 5 on textarea wikitext editors doesn't support RTL (T170001)
|
2024-08-30 21:59:48 +00:00
|
|
|
( !$isRTL || $this->shouldUseV6( $out ) ) &&
|
2024-03-01 00:36:39 +00:00
|
|
|
// Limit to supported content models that use wikitext.
|
|
|
|
// See https://www.mediawiki.org/wiki/Content_handlers#Extension_content_handlers
|
|
|
|
in_array( $out->getTitle()->getContentModel(), $contentModels );
|
2017-08-30 21:53:55 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 19:23:03 +00:00
|
|
|
/**
|
|
|
|
* @param ExtensionRegistry $extensionRegistry
|
|
|
|
* @param User $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function conflictingGadgetsEnabled( ExtensionRegistry $extensionRegistry, User $user ): bool {
|
2024-06-29 21:36:41 +00:00
|
|
|
if ( !$extensionRegistry->isLoaded( 'Gadgets' ) || !$this->gadgetRepo ) {
|
2023-10-10 19:23:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
2024-06-29 21:36:41 +00:00
|
|
|
$conflictingGadgets = array_intersect( $this->conflictingGadgets, $this->gadgetRepo->getGadgetIds() );
|
2023-10-10 19:23:03 +00:00
|
|
|
foreach ( $conflictingGadgets as $conflictingGadget ) {
|
|
|
|
try {
|
2024-06-29 21:36:41 +00:00
|
|
|
if ( $this->gadgetRepo->getGadget( $conflictingGadget )->isEnabled( $user ) ) {
|
2023-10-10 19:23:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} catch ( InvalidArgumentException $e ) {
|
|
|
|
// Safeguard for an invalid gadget ID; treat as gadget not enabled.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-16 05:00:43 +00:00
|
|
|
/**
|
2024-03-01 00:36:39 +00:00
|
|
|
* Load CodeMirror if necessary.
|
2015-03-16 05:00:43 +00:00
|
|
|
*
|
2024-03-01 00:36:39 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/EditPage::showEditForm:initial
|
2015-03-16 05:00:43 +00:00
|
|
|
*
|
2024-03-01 00:36:39 +00:00
|
|
|
* @param EditPage $editor
|
2019-04-03 23:38:24 +00:00
|
|
|
* @param OutputPage $out
|
2015-03-16 05:00:43 +00:00
|
|
|
*/
|
2024-03-01 00:36:39 +00:00
|
|
|
public function onEditPage__showEditForm_initial( $editor, $out ): void {
|
2023-10-10 19:23:03 +00:00
|
|
|
if ( !$this->shouldLoadCodeMirror( $out ) ) {
|
2023-09-19 17:59:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-03-26 20:40:13 +00:00
|
|
|
$useCodeMirror = $this->userOptionsLookup->getBoolOption( $out->getUser(), 'usecodemirror' );
|
|
|
|
$useWikiEditor = $this->userOptionsLookup->getBoolOption( $out->getUser(), 'usebetatoolbar' );
|
|
|
|
|
2023-10-11 02:00:08 +00:00
|
|
|
if ( $this->shouldUseV6( $out ) ) {
|
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-03-26 20:40:13 +00:00
|
|
|
$out->addModules( $useWikiEditor ?
|
2024-04-15 05:05:07 +00:00
|
|
|
'ext.CodeMirror.v6.WikiEditor.init' :
|
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-03-26 20:40:13 +00:00
|
|
|
'ext.CodeMirror.v6.init'
|
|
|
|
);
|
2023-09-19 17:59:29 +00:00
|
|
|
} else {
|
2023-08-17 04:58:59 +00:00
|
|
|
$out->addModules( 'ext.CodeMirror.WikiEditor' );
|
2019-03-09 15:52:49 +00:00
|
|
|
|
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-03-26 20:40:13 +00:00
|
|
|
if ( $useCodeMirror ) {
|
2019-03-09 15:52:49 +00:00
|
|
|
// These modules are predelivered for performance when needed
|
|
|
|
// keep these modules in sync with ext.CodeMirror.js
|
|
|
|
$out->addModules( [ 'ext.CodeMirror.lib', 'ext.CodeMirror.mode.mediawiki' ] );
|
|
|
|
}
|
2015-03-16 05:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 00:02:44 +00:00
|
|
|
/**
|
|
|
|
* Load CodeMirror 6 on read-only pages.
|
|
|
|
*
|
|
|
|
* @param EditPage $editor
|
|
|
|
* @param OutputPage $out
|
|
|
|
*/
|
|
|
|
public function onEditPage__showReadOnlyForm_initial( $editor, $out ): void {
|
|
|
|
if ( $this->shouldUseV6( $out ) && $this->shouldLoadCodeMirror( $out ) ) {
|
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-03-26 20:40:13 +00:00
|
|
|
$useWikiEditor = $this->userOptionsLookup->getBoolOption( $out->getUser(), 'usebetatoolbar' );
|
|
|
|
$out->addModules( $useWikiEditor ?
|
2024-04-15 05:05:07 +00:00
|
|
|
'ext.CodeMirror.v6.WikiEditor.init' :
|
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-03-26 20:40:13 +00:00
|
|
|
'ext.CodeMirror.v6.init'
|
|
|
|
);
|
2024-01-10 00:02:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-11 02:00:08 +00:00
|
|
|
/**
|
|
|
|
* @param OutputPage $out
|
|
|
|
* @return bool
|
|
|
|
* @todo Remove check for cm6enable flag after migration is complete
|
|
|
|
*/
|
|
|
|
private function shouldUseV6( OutputPage $out ): bool {
|
|
|
|
return $this->useV6 || $out->getRequest()->getRawVal( 'cm6enable' );
|
|
|
|
}
|
|
|
|
|
2024-03-28 02:36:25 +00:00
|
|
|
/**
|
|
|
|
* Hook handler for enabling bracket matching.
|
|
|
|
*
|
|
|
|
* TODO: Remove after migration to CodeMirror 6 is complete.
|
|
|
|
*
|
|
|
|
* @param array &$vars Array of variables to be added into the output of the startup module
|
|
|
|
* @param string $skin
|
|
|
|
* @param Config $config
|
|
|
|
* @return void This hook must not abort, it must return no value
|
|
|
|
*/
|
|
|
|
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
|
|
|
$vars['wgCodeMirrorLineNumberingNamespaces'] = $config->get( 'CodeMirrorLineNumberingNamespaces' );
|
|
|
|
}
|
|
|
|
|
2015-03-16 05:00:43 +00:00
|
|
|
/**
|
|
|
|
* GetPreferences hook handler
|
|
|
|
*
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
|
|
|
|
*
|
2015-08-07 14:45:17 +00:00
|
|
|
* @param User $user
|
2017-09-09 16:52:39 +00:00
|
|
|
* @param array &$defaultPreferences
|
2022-09-19 19:01:32 +00:00
|
|
|
* @return bool|void True or no return value to continue or false to abort
|
2015-03-16 05:00:43 +00:00
|
|
|
*/
|
2022-09-19 19:01:32 +00:00
|
|
|
public function onGetPreferences( $user, &$defaultPreferences ) {
|
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-03-26 20:40:13 +00:00
|
|
|
if ( !$this->useV6 ) {
|
|
|
|
$defaultPreferences['usecodemirror'] = [
|
|
|
|
'type' => 'api',
|
|
|
|
];
|
|
|
|
|
|
|
|
// The following messages are generated upstream by the 'section' value
|
|
|
|
// * prefs-accessibility
|
|
|
|
$defaultPreferences['usecodemirror-colorblind'] = [
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'codemirror-prefs-colorblind',
|
|
|
|
'help-message' => 'codemirror-prefs-colorblind-help',
|
|
|
|
'section' => 'editing/accessibility',
|
|
|
|
];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show message with a link to the Help page under "Syntax highlighting".
|
|
|
|
// The following messages are generated upstream by the 'section' value:
|
|
|
|
// * prefs-syntax-highlighting
|
|
|
|
$defaultPreferences['usecodemirror-summary'] = [
|
|
|
|
'type' => 'info',
|
|
|
|
'default' => wfMessage( 'codemirror-prefs-summary' )->parse(),
|
|
|
|
'raw' => true,
|
|
|
|
'section' => 'editing/syntax-highlighting'
|
|
|
|
];
|
|
|
|
|
2021-07-08 00:57:49 +00:00
|
|
|
// CodeMirror is disabled by default for all users. It can enabled for everyone
|
|
|
|
// by default by adding '$wgDefaultUserOptions['usecodemirror'] = 1;' into LocalSettings.php
|
2017-04-01 15:08:36 +00:00
|
|
|
$defaultPreferences['usecodemirror'] = [
|
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-03-26 20:40:13 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'codemirror-prefs-enable',
|
|
|
|
'section' => 'editing/syntax-highlighting',
|
2017-04-01 15:08:36 +00:00
|
|
|
];
|
2022-04-06 10:06:07 +00:00
|
|
|
|
2022-06-13 11:20:24 +00:00
|
|
|
$defaultPreferences['usecodemirror-colorblind'] = [
|
|
|
|
'type' => 'toggle',
|
2024-08-15 05:31:45 +00:00
|
|
|
'label-message' => 'codemirror-v6-prefs-colorblind',
|
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-03-26 20:40:13 +00:00
|
|
|
'section' => 'editing/syntax-highlighting',
|
|
|
|
'disable-if' => [ '!==', 'usecodemirror', '1' ]
|
2022-06-13 11:20:24 +00:00
|
|
|
];
|
2014-10-23 06:09:10 +00:00
|
|
|
}
|
2014-08-20 17:03:46 +00:00
|
|
|
}
|