mediawiki-extensions-Cite/src/ResourceLoader/CiteVisualEditorModule.php
Timo Tijhof fb2c7c37db Combine ext.cite.visualEditor.data into ext.cite.visualEditor
Rather than depending on a separate module with one line of generated
JS code, generate it as a prepended statement to the same module.

Should be a no-op.

Depends-On: I809951d34feb2dbd01b7ae0f4bd98dac7c3f6fe2
Change-Id: I5886bf9f82025048976b7750e8cb751681021fb4
2021-11-19 16:56:51 +00:00

70 lines
1.7 KiB
PHP

<?php
namespace Cite\ResourceLoader;
use ResourceLoaderContext;
/**
* File module with extra data generated by the server.
*
* Temporary hack since 2015 for T93800.
*
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
class CiteVisualEditorModule extends \ResourceLoaderFileModule {
/** @inheritDoc */
public function getScript( ResourceLoaderContext $context ) {
return $this->makePrependedScript( $context ) . parent::getScript( $context );
}
/**
* @internal
* @param ResourceLoaderContext $context
* @return string JavaScript code
*/
public function makePrependedScript( ResourceLoaderContext $context ) {
$citationDefinition = json_decode(
$context->msg( 'cite-tool-definition.json' )
->inContentLanguage()
->plain()
);
if ( $citationDefinition === null ) {
$citationDefinition = json_decode(
$context->msg( 'visualeditor-cite-tool-definition.json' )
->inContentLanguage()
->plain()
);
}
$citationTools = [];
if ( is_array( $citationDefinition ) ) {
foreach ( $citationDefinition as $tool ) {
if ( !isset( $tool->title ) ) {
$tool->title = $context->msg( 'visualeditor-cite-tool-name-' . $tool->name )
->text();
}
$citationTools[] = $tool;
}
}
return 've.init.platform.addMessages(' . $context->encodeJson(
[
'cite-tool-definition.json' => json_encode( $citationTools )
]
) . ');';
}
/** @inheritDoc */
public function getDefinitionSummary( ResourceLoaderContext $context ) {
$summary = parent::getDefinitionSummary( $context );
$summary[] = [
'script' => $this->makePrependedScript( $context ),
];
return $summary;
}
}