mediawiki-extensions-Cite/includes/CiteDataModule.php
Bartosz Dziewoński 2e35d29223 CiteDataModule: Remove origin restriction
Without this change it would no longer load in safe mode (T185303)
because the module would be missing.

I think this has been copy-pasted from VisualEditor, see commit
I6d097ccbf1dc2462843219adcf96bf8313e30289 there for explanation.

Bug: T185303
Change-Id: I6f6857ec50e7b8c6e25022024c29b59726c656e3
2018-04-30 22:18:06 +02:00

68 lines
1.6 KiB
PHP

<?php
/**
* Resource loader module providing extra data from the server to Cite.
*
* Temporary hack for T93800
*
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
class CiteDataModule extends ResourceLoaderModule {
protected $targets = [ 'desktop', 'mobile' ];
/** @inheritDoc */
public function getScript( 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(' . FormatJson::encode(
[
'cite-tool-definition.json' => json_encode( $citationTools )
],
ResourceLoader::inDebugMode()
) . ');';
}
/** @inheritDoc */
public function getDependencies( ResourceLoaderContext $context = null ) {
return [
'ext.visualEditor.base',
'ext.visualEditor.mediawiki',
];
}
/** @inheritDoc */
public function getDefinitionSummary( ResourceLoaderContext $context ) {
$summary = parent::getDefinitionSummary( $context );
$summary[] = [
'script' => $this->getScript( $context ),
];
return $summary;
}
}