Migrate ResourceLoaderSyntaxHighlightVisualEditorModule to a virtual file callback

Depends-On: I97d61b5793159cea365740e0563f7b733e0f16de
Bug: T47514
Change-Id: I10fceeee808e4d08f7ed63afb13b4d87129365c7
This commit is contained in:
Tim Starling 2023-05-08 17:15:48 +10:00
parent 13c7d46076
commit 54b02b02e1
2 changed files with 10 additions and 25 deletions

View file

@ -55,7 +55,6 @@
]
},
"ext.geshi.visualEditor": {
"class": "MediaWiki\\SyntaxHighlight\\ResourceLoaderSyntaxHighlightVisualEditorModule",
"scripts": [
"ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js",
"ve-syntaxhighlight/ve.dm.MWBlockSyntaxHighlightNode.js",
@ -67,7 +66,11 @@
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightDialogTool.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.js",
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js"
"ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js",
{
"name": "ve-syntaxhighlight/ve.MWSyntaxHighlightConfig.js",
"callback": "MediaWiki\\SyntaxHighlight\\VisualEditorConfig::makeScript"
}
],
"styles": [
"ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.css",

View file

@ -20,19 +20,15 @@ namespace MediaWiki\SyntaxHighlight;
use MediaWiki\ResourceLoader as RL;
class ResourceLoaderSyntaxHighlightVisualEditorModule extends RL\FileModule {
protected $targets = [ 'desktop', 'mobile' ];
class VisualEditorConfig {
/**
* @param RL\Context $context
* @return string JavaScript code
*/
public function getScript( RL\Context $context ) {
$scripts = parent::getScript( $context );
return $scripts
. 've.dm.MWSyntaxHighlightNode.static.addPygmentsLanguages('
. $context->encodeJson( $this->getPygmentsLanguages() )
public static function makeScript( RL\Context $context ) {
return 've.dm.MWSyntaxHighlightNode.static.addPygmentsLanguages('
. $context->encodeJson( self::getPygmentsLanguages() )
. ');'
. 've.dm.MWSyntaxHighlightNode.static.addGeshiToPygmentsMap('
. $context->encodeJson( SyntaxHighlightGeSHiCompat::getGeSHiToPygmentsMap() )
@ -46,21 +42,7 @@ class ResourceLoaderSyntaxHighlightVisualEditorModule extends RL\FileModule {
* Get a full list of available languages
* @return array
*/
private function getPygmentsLanguages() {
private static function getPygmentsLanguages() {
return array_keys( require __DIR__ . '/../SyntaxHighlight.lexers.php' );
}
/**
* @return bool
*/
public function enableModuleContentVersion() {
return true;
}
/**
* @return bool
*/
public function supportsURLLoading() {
return false;
}
}