mediawiki-extensions-Cite/src/ResourceLoader/CiteDataModule.php
Thiemo Kreuz ab3063fee5 Move all code to PSR-4 compatible namespaces
This patch does intentionally not touch any file name. Some of the
file names are a little weird now, e.g. \Cite\Cite. These can more
easily be renamed in later patches.

I used https://codesearch.wmflabs.org/search/?q=new%20Cite%5C( and it
looks like this code is not used anywhere else.

Change-Id: I5f93a224e9cacf45b7a0d68c216a78723364dd96
2019-11-20 17:00:13 +01:00

74 lines
1.7 KiB
PHP

<?php
namespace Cite\ResourceLoader;
use FormatJson;
use ResourceLoader;
use ResourceLoaderContext;
/**
* 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;
}
}