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-02-17 16:18:02 +00:00
|
|
|
$parsedMessages = [];
|
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
|
|
|
|
2012-12-06 05:27:44 +00:00
|
|
|
// Copyright warning (based on EditPage::getCopyrightWarning)
|
2014-08-13 08:15:42 +00:00
|
|
|
$rightsText = $this->config->get( 'RightsText' );
|
|
|
|
if ( $rightsText ) {
|
2016-03-11 21:36:16 +00:00
|
|
|
$copywarnMsgArgs = [ 'copyrightwarning',
|
|
|
|
'[[' . $context->msg( 'copyrightpage' )->inContentLanguage()->text() . ']]',
|
2016-02-17 16:18:02 +00:00
|
|
|
$rightsText ];
|
2012-12-06 05:27:44 +00:00
|
|
|
} else {
|
2016-03-11 21:36:16 +00:00
|
|
|
$copywarnMsgArgs = [ 'copyrightwarning2',
|
|
|
|
'[[' . $context->msg( 'copyrightpage' )->inContentLanguage()->text() . ']]' ];
|
2012-12-06 05:27:44 +00:00
|
|
|
}
|
2016-03-11 21:36:16 +00:00
|
|
|
// EditPage supports customisation based on title, we can't support that
|
2012-12-06 05:27:44 +00:00
|
|
|
$title = Title::newFromText( 'Dwimmerlaik' );
|
2016-03-11 21:36:16 +00:00
|
|
|
Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsgArgs ] );
|
|
|
|
// Normalise to 'copyrightwarning' so we have a consistent key in the front-end
|
|
|
|
$parseMsgs[ 'copyrightwarning' ] = call_user_func_array(
|
|
|
|
[ $context, 'msg' ],
|
|
|
|
$copywarnMsgArgs
|
|
|
|
);
|
2012-12-06 05:27:44 +00:00
|
|
|
|
2016-03-11 21:36:16 +00:00
|
|
|
// Messages to be exported as text
|
|
|
|
$textMsgs = [
|
|
|
|
'visualeditor-feedback-link' => $context->msg( 'visualeditor-feedback-link' )
|
|
|
|
->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,
|
|
|
|
'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
|
|
|
}
|