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
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
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 */
|
|
|
|
|
2012-12-04 06:56:41 +00:00
|
|
|
protected $origin = self::ORIGIN_USER_SITEWIDE;
|
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.
|
2017-05-04 22:15:55 +00:00
|
|
|
* @return string JavaScipt 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()
|
|
|
|
) . ');'.
|
|
|
|
'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
|
|
|
}
|
|
|
|
|
2016-03-11 21:36:16 +00:00
|
|
|
protected function getMessageInfo( ResourceLoaderContext $context ) {
|
2017-05-29 19:00:15 +00:00
|
|
|
global $wgEditSubmitButtonLabelPublish;
|
|
|
|
$saveButtonLabelKey = $wgEditSubmitButtonLabelPublish ? 'publishpage' : 'savearticle';
|
|
|
|
$saveButtonLabel = $context->msg( $saveButtonLabelKey )->text();
|
|
|
|
|
2016-03-11 21:36:16 +00:00
|
|
|
// Messages to be exported as parsed html
|
|
|
|
$parseMsgs = [
|
|
|
|
'minoredit' => $context->msg( 'minoredit' ),
|
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' ),
|
|
|
|
'watchthis' => $context->msg( 'watchthis' ),
|
|
|
|
'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(),
|
|
|
|
'visualeditor-quick-access-characters.json' =>
|
|
|
|
$context->msg( 'visualeditor-quick-access-characters.json' )
|
2016-03-11 21:36:16 +00:00
|
|
|
->inContentLanguage(),
|
|
|
|
];
|
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
|
|
|
}
|
|
|
|
|
2015-11-10 00:23:14 +00:00
|
|
|
public function enableModuleContentVersion() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|