mediawiki-extensions-Visual.../VisualEditorDataModule.php
James D. Forrester 9a27f80b3e build: Enable MediaWiki.Commenting.FunctionComment.MissingReturn
Change-Id: I714220880e91583a6e3cc575810fe02e3e822538
2017-05-11 08:19:44 -07:00

94 lines
2.5 KiB
PHP

<?php
/**
* Resource loader module providing extra data from the server to VisualEditor.
*
* @file
* @ingroup Extensions
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
class VisualEditorDataModule extends ResourceLoaderModule {
/* Protected Members */
protected $origin = self::ORIGIN_USER_SITEWIDE;
protected $targets = [ 'desktop', 'mobile' ];
/* Methods */
/**
* @return string JavaScipt code
*/
public function getScript( ResourceLoaderContext $context ) {
$msgInfo = $this->getMessageInfo( $context );
$parsedMessages = $msgInfo['parsed'];
$textMessages = [];
foreach ( $msgInfo['parse'] as $msgKey => $msgObj ) {
$parsedMessages[ $msgKey ] = $msgObj->parse();
}
foreach ( $msgInfo['text'] as $msgKey => $msgObj ) {
$textMessages[ $msgKey ] = $msgObj->text();
}
return 've.init.platform.addParsedMessages(' . FormatJson::encode(
$parsedMessages,
ResourceLoader::inDebugMode()
) . ');'.
've.init.platform.addMessages(' . FormatJson::encode(
$textMessages,
ResourceLoader::inDebugMode()
) . ');';
}
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' ),
];
// Copyright warning (already parsed)
$parsedMsgs = [
'copyrightwarning' => EditPage::getCopyrightWarning(
// Use a dummy title
Title::newFromText( 'Dwimmerlaik' ),
'parse',
$context->getLanguage()
),
];
// Messages to be exported as text
$textMsgs = [
'visualeditor-feedback-link' =>
$context->msg( 'visualeditor-feedback-link' )
->inContentLanguage(),
'visualeditor-quick-access-characters.json' =>
$context->msg( 'visualeditor-quick-access-characters.json' )
->inContentLanguage(),
];
return [
'parse' => $parseMsgs,
// Already parsed
'parsed' => $parsedMsgs,
'text' => $textMsgs,
];
}
public function enableModuleContentVersion() {
return true;
}
public function getDependencies( ResourceLoaderContext $context = null ) {
return [
'ext.visualEditor.base',
'ext.visualEditor.mediawiki',
];
}
}