2012-06-21 20:39:27 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2013-08-30 00:55:31 +00:00
|
|
|
* Resource loader module providing extra data from the server to VisualEditor.
|
2012-06-21 20:39:27 +00:00
|
|
|
*
|
|
|
|
* @file
|
2012-07-19 00:11:26 +00:00
|
|
|
* @ingroup Extensions
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2018-03-28 19:47:04 +00:00
|
|
|
* @license MIT
|
2012-06-21 20:39:27 +00:00
|
|
|
*/
|
|
|
|
|
2022-03-13 01:38:23 +00:00
|
|
|
namespace MediaWiki\Extension\VisualEditor;
|
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
use MediaWiki\ResourceLoader\Context as ResourceLoaderContext;
|
|
|
|
use MediaWiki\ResourceLoader\Module as ResourceLoaderModule;
|
2023-08-19 04:21:24 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-03-13 01:38:23 +00:00
|
|
|
|
2013-08-30 00:55:31 +00:00
|
|
|
class VisualEditorDataModule extends ResourceLoaderModule {
|
2012-06-21 20:39:27 +00:00
|
|
|
|
2021-06-03 13:54:40 +00:00
|
|
|
/** @inheritDoc */
|
2016-02-17 16:18:02 +00:00
|
|
|
protected $targets = [ 'desktop', 'mobile' ];
|
2012-06-21 20:39:27 +00:00
|
|
|
|
2017-05-04 22:07:10 +00:00
|
|
|
/**
|
2017-05-04 22:59:27 +00:00
|
|
|
* @param ResourceLoaderContext $context Object containing information about the state of this
|
|
|
|
* specific loader request.
|
2018-04-15 12:30:31 +00:00
|
|
|
* @return string JavaScript code
|
2017-05-04 22:07:10 +00:00
|
|
|
*/
|
2012-06-21 20:39:27 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2016-03-11 21:36:16 +00:00
|
|
|
$msgInfo = $this->getMessageInfo( $context );
|
2022-01-24 13:06:19 +00:00
|
|
|
$parsedMessages = [];
|
2017-08-23 18:08:36 +00:00
|
|
|
$plainMessages = [];
|
2016-03-11 21:36:16 +00:00
|
|
|
foreach ( $msgInfo['parse'] as $msgKey => $msgObj ) {
|
|
|
|
$parsedMessages[ $msgKey ] = $msgObj->parse();
|
2012-12-04 06:56:41 +00:00
|
|
|
}
|
2017-08-23 18:08:36 +00:00
|
|
|
foreach ( $msgInfo['plain'] as $msgKey => $msgObj ) {
|
|
|
|
$plainMessages[ $msgKey ] = $msgObj->plain();
|
2013-05-18 17:34:25 +00:00
|
|
|
}
|
2013-08-30 00:55:31 +00:00
|
|
|
|
2021-02-18 20:53:24 +00:00
|
|
|
return 've.init.platform.addParsedMessages(' . $context->encodeJson(
|
|
|
|
$parsedMessages
|
2018-09-02 21:52:54 +00:00
|
|
|
) . ');' .
|
2021-02-18 20:53:24 +00:00
|
|
|
've.init.platform.addMessages(' . $context->encodeJson(
|
|
|
|
$plainMessages
|
2015-11-28 05:38:27 +00:00
|
|
|
) . ');';
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 02:09:27 +00:00
|
|
|
/**
|
|
|
|
* Get the definition summary for this module.
|
|
|
|
*
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDefinitionSummary( ResourceLoaderContext $context ) {
|
|
|
|
$summary = parent::getDefinitionSummary( $context );
|
|
|
|
|
|
|
|
$msgVersion = [];
|
|
|
|
$msgInfo = $this->getMessageInfo( $context );
|
|
|
|
$msgInfo = array_merge( $msgInfo['parse'], $msgInfo['plain'] );
|
|
|
|
foreach ( $msgInfo as $msgKey => $msgObj ) {
|
|
|
|
$msgVersion[ $msgKey ] = [
|
|
|
|
// Include the text of the message, in case the canonical translation changes
|
|
|
|
$msgObj->plain(),
|
|
|
|
// Include the page touched time, in case the on-wiki override is invalidated
|
|
|
|
Title::makeTitle( NS_MEDIAWIKI, ucfirst( $msgObj->getKey() ) )->getTouched(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$summary[] = [ 've-messages' => $msgVersion ];
|
|
|
|
return $summary;
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @param ResourceLoaderContext $context Object containing information about the state of this
|
|
|
|
* specific loader request.
|
2019-01-26 13:50:22 +00:00
|
|
|
* @return array[] Messages in various states of parsing
|
2018-03-28 19:47:04 +00:00
|
|
|
*/
|
2016-03-11 21:36:16 +00:00
|
|
|
protected function getMessageInfo( ResourceLoaderContext $context ) {
|
2019-04-17 14:26:42 +00:00
|
|
|
$editSubmitButtonLabelPublish = $this->getConfig()
|
2018-01-17 19:14:39 +00:00
|
|
|
->get( 'EditSubmitButtonLabelPublish' );
|
2022-02-26 10:10:31 +00:00
|
|
|
$saveButtonLabelKey = $editSubmitButtonLabelPublish ? 'publishchanges' : 'savechanges';
|
2017-05-29 19:00:15 +00:00
|
|
|
$saveButtonLabel = $context->msg( $saveButtonLabelKey )->text();
|
|
|
|
|
2016-03-11 21:36:16 +00:00
|
|
|
// Messages to be exported as parsed html
|
|
|
|
$parseMsgs = [
|
2017-05-29 19:00:15 +00:00
|
|
|
'missingsummary' => $context->msg( 'missingsummary', $saveButtonLabel ),
|
2016-03-11 21:36:16 +00:00
|
|
|
'summary' => $context->msg( 'summary' ),
|
|
|
|
'visualeditor-browserwarning' => $context->msg( 'visualeditor-browserwarning' ),
|
|
|
|
'visualeditor-wikitext-warning' => $context->msg( 'visualeditor-wikitext-warning' ),
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2013-05-18 17:34:25 +00:00
|
|
|
|
2017-08-23 18:08:36 +00:00
|
|
|
// Messages to be exported as plain text
|
|
|
|
$plainMsgs = [
|
2016-10-24 22:03:23 +00:00
|
|
|
'visualeditor-feedback-link' =>
|
|
|
|
$context->msg( 'visualeditor-feedback-link' )
|
|
|
|
->inContentLanguage(),
|
2018-02-09 00:31:17 +00:00
|
|
|
'visualeditor-feedback-source-link' =>
|
|
|
|
$context->msg( 'visualeditor-feedback-source-link' )
|
|
|
|
->inContentLanguage(),
|
2016-10-24 22:03:23 +00:00
|
|
|
'visualeditor-quick-access-characters.json' =>
|
|
|
|
$context->msg( 'visualeditor-quick-access-characters.json' )
|
2016-03-11 21:36:16 +00:00
|
|
|
->inContentLanguage(),
|
2018-12-07 19:16:40 +00:00
|
|
|
'visualeditor-template-tools-definition.json' =>
|
|
|
|
$context->msg( 'visualeditor-template-tools-definition.json' )
|
|
|
|
->inContentLanguage(),
|
2016-03-11 21:36:16 +00:00
|
|
|
];
|
2012-12-06 05:27:44 +00:00
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
return [
|
2016-03-11 21:36:16 +00:00
|
|
|
'parse' => $parseMsgs,
|
2017-08-23 18:08:36 +00:00
|
|
|
'plain' => $plainMsgs,
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2014-05-08 21:56:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*
|
|
|
|
* Always true.
|
|
|
|
*/
|
2015-11-10 00:23:14 +00:00
|
|
|
public function enableModuleContentVersion() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:47:04 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2015-11-10 00:23:14 +00:00
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
2016-02-17 16:18:02 +00:00
|
|
|
return [
|
2015-11-10 00:23:14 +00:00
|
|
|
'ext.visualEditor.base',
|
|
|
|
'ext.visualEditor.mediawiki',
|
2016-02-17 16:18:02 +00:00
|
|
|
];
|
2015-11-10 00:23:14 +00:00
|
|
|
}
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|