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
|
|
|
*/
|
|
|
|
|
2013-08-30 00:55:31 +00:00
|
|
|
class VisualEditorDataModule extends ResourceLoaderModule {
|
2012-06-21 20:39:27 +00:00
|
|
|
|
|
|
|
/* Protected Members */
|
|
|
|
|
2016-02-17 16:18:02 +00:00
|
|
|
protected $targets = [ 'desktop', 'mobile' ];
|
2012-06-21 20:39:27 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
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 );
|
2016-09-22 02:07:57 +00:00
|
|
|
$parsedMessages = $msgInfo['parsed'];
|
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
|
|
|
|
2016-03-11 21:36:16 +00:00
|
|
|
return 've.init.platform.addParsedMessages(' . FormatJson::encode(
|
2013-12-09 23:00:43 +00:00
|
|
|
$parsedMessages,
|
2013-08-30 00:55:31 +00:00
|
|
|
ResourceLoader::inDebugMode()
|
2018-09-02 21:52:54 +00:00
|
|
|
) . ');' .
|
2013-08-30 00:55:31 +00:00
|
|
|
've.init.platform.addMessages(' . FormatJson::encode(
|
2017-08-23 18:08:36 +00:00
|
|
|
$plainMessages,
|
2013-08-30 00:55:31 +00:00
|
|
|
ResourceLoader::inDebugMode()
|
2015-11-28 05:38:27 +00:00
|
|
|
) . ');';
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
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' );
|
|
|
|
$saveButtonLabelKey = $editSubmitButtonLabelPublish ? 'publishpage' : 'savearticle';
|
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
|
|
|
|
2016-09-22 02:07:57 +00:00
|
|
|
// Copyright warning (already parsed)
|
|
|
|
$parsedMsgs = [
|
|
|
|
'copyrightwarning' => EditPage::getCopyrightWarning(
|
|
|
|
// Use a dummy title
|
2016-09-27 00:24:37 +00:00
|
|
|
Title::newFromText( 'Dwimmerlaik' ),
|
|
|
|
'parse',
|
|
|
|
$context->getLanguage()
|
2016-09-22 02:07:57 +00:00
|
|
|
),
|
|
|
|
];
|
2012-12-06 05:27:44 +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,
|
2016-09-22 02:07:57 +00:00
|
|
|
// Already parsed
|
|
|
|
'parsed' => $parsedMsgs,
|
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
|
|
|
}
|