Move default CSS/JS model mapping out of extension.json

These are for MediaWiki core models, so it seems reasonable to specify
them in the PHP source.

Change-Id: Iab6f9969d2bf72122b2661e139aa21a3475a92a8
This commit is contained in:
Kunal Mehta 2021-02-10 17:12:03 -08:00
parent adb912bb3a
commit 9bdf728fc1
2 changed files with 9 additions and 7 deletions

View file

@ -102,10 +102,7 @@
}, },
"attributes": { "attributes": {
"SyntaxHighlight": { "SyntaxHighlight": {
"Models": { "Models": {}
"css": "css",
"javascript": "javascript"
}
}, },
"VisualEditor": { "VisualEditor": {
"PluginModules": [ "PluginModules": [

View file

@ -517,9 +517,14 @@ class SyntaxHighlight {
return true; return true;
} }
// Determine the language // Determine the SyntaxHighlight language from the page's
// content model. Extensions can extend the default CSS/JS
// mapping by setting the SyntaxHighlightModels attribute.
$extension = ExtensionRegistry::getInstance(); $extension = ExtensionRegistry::getInstance();
$models = $extension->getAttribute( 'SyntaxHighlightModels' ); $models = $extension->getAttribute( 'SyntaxHighlightModels' ) + [
CONTENT_MODEL_CSS => 'css',
CONTENT_MODEL_JAVASCRIPT => 'javascript',
];
$model = $content->getModel(); $model = $content->getModel();
if ( !isset( $models[$model] ) ) { if ( !isset( $models[$model] ) ) {
// We don't care about this model, carry on. // We don't care about this model, carry on.
@ -527,7 +532,7 @@ class SyntaxHighlight {
} }
$lexer = $models[$model]; $lexer = $models[$model];
// Hope that $wgSyntaxHighlightModels does not contain silly types. // Hope that the "SyntaxHighlightModels" attribute does not contain silly types.
$text = ContentHandler::getContentText( $content ); $text = ContentHandler::getContentText( $content );
if ( !$text ) { if ( !$text ) {
// Oops! Non-text content? Let MediaWiki handle this. // Oops! Non-text content? Let MediaWiki handle this.