mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-12 09:09:25 +00:00
101eda99a2
Changing `->text()` to `->plain()` and some variable names and comments to match that. This is now the same as normal ResourceLoader behavior for messages added via `'messages'` in RL modules. Also remove a duplicate use of the 'visualeditor-quick-access-characters.json' message. Bug: T159529 Change-Id: I63593db445433e7da5c71e6800f96daf63054fcf
100 lines
2.8 KiB
PHP
100 lines
2.8 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 */
|
|
|
|
/**
|
|
* @param ResourceLoaderContext $context Object containing information about the state of this
|
|
* specific loader request.
|
|
* @return string JavaScipt code
|
|
*/
|
|
public function getScript( ResourceLoaderContext $context ) {
|
|
$msgInfo = $this->getMessageInfo( $context );
|
|
$parsedMessages = $msgInfo['parsed'];
|
|
$plainMessages = [];
|
|
foreach ( $msgInfo['parse'] as $msgKey => $msgObj ) {
|
|
$parsedMessages[ $msgKey ] = $msgObj->parse();
|
|
}
|
|
foreach ( $msgInfo['plain'] as $msgKey => $msgObj ) {
|
|
$plainMessages[ $msgKey ] = $msgObj->plain();
|
|
}
|
|
|
|
return 've.init.platform.addParsedMessages(' . FormatJson::encode(
|
|
$parsedMessages,
|
|
ResourceLoader::inDebugMode()
|
|
) . ');'.
|
|
've.init.platform.addMessages(' . FormatJson::encode(
|
|
$plainMessages,
|
|
ResourceLoader::inDebugMode()
|
|
) . ');';
|
|
}
|
|
|
|
protected function getMessageInfo( ResourceLoaderContext $context ) {
|
|
global $wgEditSubmitButtonLabelPublish;
|
|
$saveButtonLabelKey = $wgEditSubmitButtonLabelPublish ? 'publishpage' : 'savearticle';
|
|
$saveButtonLabel = $context->msg( $saveButtonLabelKey )->text();
|
|
|
|
// Messages to be exported as parsed html
|
|
$parseMsgs = [
|
|
'minoredit' => $context->msg( 'minoredit' ),
|
|
'missingsummary' => $context->msg( 'missingsummary', $saveButtonLabel ),
|
|
'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 plain text
|
|
$plainMsgs = [
|
|
'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,
|
|
'plain' => $plainMsgs,
|
|
];
|
|
}
|
|
|
|
public function enableModuleContentVersion() {
|
|
return true;
|
|
}
|
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
|
return [
|
|
'ext.visualEditor.base',
|
|
'ext.visualEditor.mediawiki',
|
|
];
|
|
}
|
|
}
|