2016-02-03 21:03:41 +00:00
|
|
|
<?php
|
2017-12-28 14:55:49 +00:00
|
|
|
|
2019-11-19 14:12:11 +00:00
|
|
|
namespace Cite\ResourceLoader;
|
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
use MediaWiki\ResourceLoader as RL;
|
2019-11-19 14:12:11 +00:00
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/**
|
2021-11-10 20:36:35 +00:00
|
|
|
* File module with extra data generated by the server.
|
2016-02-03 21:03:41 +00:00
|
|
|
*
|
2021-11-10 20:36:35 +00:00
|
|
|
* Temporary hack since 2015 for T93800.
|
2016-02-03 21:03:41 +00:00
|
|
|
*
|
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
|
|
|
*/
|
2022-05-20 02:11:31 +00:00
|
|
|
class CiteVisualEditorModule extends RL\FileModule {
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2017-10-06 19:22:30 +00:00
|
|
|
/** @inheritDoc */
|
2022-05-20 02:11:31 +00:00
|
|
|
public function getScript( RL\Context $context ) {
|
2021-11-10 20:36:35 +00:00
|
|
|
return $this->makePrependedScript( $context ) . parent::getScript( $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2022-05-20 02:11:31 +00:00
|
|
|
* @param RL\Context $context
|
2021-11-10 20:36:35 +00:00
|
|
|
* @return string JavaScript code
|
|
|
|
*/
|
2022-05-20 02:11:31 +00:00
|
|
|
public function makePrependedScript( RL\Context $context ) {
|
2016-02-03 21:03:41 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-10 20:56:35 +00:00
|
|
|
// TODO: When this custom module is converted to adopt packageFiles, this data
|
|
|
|
// can be exported via a callback as a virtual "tools.json" file. Then the JS
|
|
|
|
// in MWReference.init.js can do `ve.ui.mwCitationTools = require( "./tools.json" )`
|
|
|
|
|
|
|
|
// Limit and expose
|
|
|
|
$limit = 5;
|
|
|
|
$citationTools = array_slice( $citationTools, 0, $limit );
|
|
|
|
return 've.ui.mwCitationTools = ' . $context->encodeJson( $citationTools ) . ';';
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 19:22:30 +00:00
|
|
|
/** @inheritDoc */
|
2022-05-20 02:11:31 +00:00
|
|
|
public function getDefinitionSummary( RL\Context $context ) {
|
2016-02-03 21:03:41 +00:00
|
|
|
$summary = parent::getDefinitionSummary( $context );
|
2016-05-09 23:36:49 +00:00
|
|
|
$summary[] = [
|
2021-11-10 20:36:35 +00:00
|
|
|
'script' => $this->makePrependedScript( $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
|
|
|
}
|