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
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 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 */
|
|
|
|
|
|
|
|
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'];
|
2016-03-11 21:36:16 +00:00
|
|
|
$textMessages = [];
|
|
|
|
foreach ( $msgInfo['parse'] as $msgKey => $msgObj ) {
|
|
|
|
$parsedMessages[ $msgKey ] = $msgObj->parse();
|
2012-12-04 06:56:41 +00:00
|
|
|
}
|
2016-03-11 21:36:16 +00:00
|
|
|
foreach ( $msgInfo['text'] as $msgKey => $msgObj ) {
|
|
|
|
$textMessages[ $msgKey ] = $msgObj->text();
|
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(
|
2016-03-11 21:36:16 +00:00
|
|
|
$textMessages,
|
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 ) {
|
|
|
|
// Messages to be exported as parsed html
|
|
|
|
$parseMsgs = [
|
|
|
|
'minoredit' => $context->msg( 'minoredit' ),
|
|
|
|
'missingsummary' => $context->msg( 'missingsummary' ),
|
|
|
|
'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
|
|
|
|
2016-03-11 21:36:16 +00:00
|
|
|
// Messages to be exported as text
|
|
|
|
$textMsgs = [
|
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,
|
2016-03-11 21:36:16 +00:00
|
|
|
'text' => $textMsgs,
|
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
|
|
|
}
|