2016-02-03 21:03:41 +00:00
|
|
|
<?php
|
2017-12-28 14:55:49 +00:00
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/**
|
|
|
|
* Resource loader module providing extra data from the server to Cite.
|
|
|
|
*
|
|
|
|
* Temporary hack for T93800
|
|
|
|
*
|
2018-01-03 01:05:45 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
|
2017-12-29 12:12:35 +00:00
|
|
|
* @license MIT
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
class CiteDataModule extends ResourceLoaderModule {
|
|
|
|
|
|
|
|
protected $origin = self::ORIGIN_USER_SITEWIDE;
|
2016-05-09 23:36:49 +00:00
|
|
|
protected $targets = [ 'desktop', 'mobile' ];
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2017-10-06 19:22:30 +00:00
|
|
|
/** @inheritDoc */
|
2016-02-03 21:03:41 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
|
|
|
$citationDefinition = json_decode(
|
2016-06-24 23:37:20 +00:00
|
|
|
$context->msg( 'cite-tool-definition.json' )
|
2016-02-24 00:29:47 +00:00
|
|
|
->inContentLanguage()
|
|
|
|
->plain()
|
2016-02-03 21:03:41 +00:00
|
|
|
);
|
|
|
|
|
2016-06-24 23:37:20 +00:00
|
|
|
if ( $citationDefinition === null ) {
|
|
|
|
$citationDefinition = json_decode(
|
|
|
|
$context->msg( 'visualeditor-cite-tool-definition.json' )
|
|
|
|
->inContentLanguage()
|
|
|
|
->plain()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:36:49 +00:00
|
|
|
$citationTools = [];
|
2016-02-03 21:03:41 +00:00
|
|
|
if ( is_array( $citationDefinition ) ) {
|
|
|
|
foreach ( $citationDefinition as $tool ) {
|
|
|
|
if ( !isset( $tool->title ) ) {
|
2016-03-11 21:48:08 +00:00
|
|
|
$tool->title = $context->msg( 'visualeditor-cite-tool-name-' . $tool->name )
|
|
|
|
->text();
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
$citationTools[] = $tool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-29 23:28:16 +00:00
|
|
|
return 've.init.platform.addMessages(' . FormatJson::encode(
|
2016-05-09 23:36:49 +00:00
|
|
|
[
|
2016-06-28 22:01:20 +00:00
|
|
|
'cite-tool-definition.json' => json_encode( $citationTools )
|
2016-05-09 23:36:49 +00:00
|
|
|
],
|
2016-02-03 21:03:41 +00:00
|
|
|
ResourceLoader::inDebugMode()
|
|
|
|
) . ');';
|
|
|
|
}
|
|
|
|
|
2017-10-06 19:22:30 +00:00
|
|
|
/** @inheritDoc */
|
2016-02-03 21:03:41 +00:00
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
2016-05-09 23:36:49 +00:00
|
|
|
return [
|
2016-02-03 21:03:41 +00:00
|
|
|
'ext.visualEditor.base',
|
|
|
|
'ext.visualEditor.mediawiki',
|
2016-05-09 23:36:49 +00:00
|
|
|
];
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 19:22:30 +00:00
|
|
|
/** @inheritDoc */
|
2016-02-03 21:03:41 +00:00
|
|
|
public function getDefinitionSummary( ResourceLoaderContext $context ) {
|
|
|
|
$summary = parent::getDefinitionSummary( $context );
|
2016-05-09 23:36:49 +00:00
|
|
|
$summary[] = [
|
2016-02-03 21:03:41 +00:00
|
|
|
'script' => $this->getScript( $context ),
|
2016-05-09 23:36:49 +00:00
|
|
|
];
|
2016-02-03 21:03:41 +00:00
|
|
|
return $summary;
|
|
|
|
}
|
2017-12-28 14:55:49 +00:00
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|