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;
|
2013-10-11 18:42:46 +00:00
|
|
|
protected $targets = array( 'desktop', 'mobile' );
|
2012-06-21 20:39:27 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2015-06-19 21:32:37 +00:00
|
|
|
public function __construct() {
|
2013-08-29 22:53:33 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 20:39:27 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2013-08-29 22:53:33 +00:00
|
|
|
// Messages
|
2012-12-06 05:27:44 +00:00
|
|
|
$msgInfo = $this->getMessageInfo();
|
2013-12-09 23:00:43 +00:00
|
|
|
$parsedMessages = array();
|
2013-05-18 17:34:25 +00:00
|
|
|
$messages = array();
|
2012-12-06 05:27:44 +00:00
|
|
|
foreach ( $msgInfo['args'] as $msgKey => $msgArgs ) {
|
2013-12-09 23:00:43 +00:00
|
|
|
$parsedMessages[ $msgKey ] = call_user_func_array( 'wfMessage', $msgArgs )
|
2012-12-06 05:27:44 +00:00
|
|
|
->inLanguage( $context->getLanguage() )
|
|
|
|
->parse();
|
2012-12-04 06:56:41 +00:00
|
|
|
}
|
2013-05-18 17:34:25 +00:00
|
|
|
foreach ( $msgInfo['vals'] as $msgKey => $msgVal ) {
|
|
|
|
$messages[ $msgKey ] = $msgVal;
|
|
|
|
}
|
2013-08-30 00:55:31 +00:00
|
|
|
|
2013-05-18 17:34:25 +00:00
|
|
|
return
|
2013-08-30 00:55:31 +00:00
|
|
|
'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(
|
|
|
|
$messages,
|
|
|
|
ResourceLoader::inDebugMode()
|
2015-11-28 05:38:27 +00:00
|
|
|
) . ');';
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 05:27:44 +00:00
|
|
|
protected function getMessageInfo() {
|
2013-05-17 14:27:33 +00:00
|
|
|
// Messages that just require simple parsing
|
2012-12-06 05:27:44 +00:00
|
|
|
$msgArgs = array(
|
|
|
|
'minoredit' => array( 'minoredit' ),
|
2013-07-13 11:44:25 +00:00
|
|
|
'missingsummary' => array( 'missingsummary' ),
|
2013-07-18 22:34:16 +00:00
|
|
|
'summary' => array( 'summary' ),
|
2012-12-06 05:27:44 +00:00
|
|
|
'watchthis' => array( 'watchthis' ),
|
2013-05-26 15:23:03 +00:00
|
|
|
'visualeditor-browserwarning' => array( 'visualeditor-browserwarning' ),
|
2013-07-13 11:44:25 +00:00
|
|
|
'visualeditor-wikitext-warning' => array( 'visualeditor-wikitext-warning' ),
|
2012-12-06 05:27:44 +00:00
|
|
|
);
|
|
|
|
|
2013-05-18 17:34:25 +00:00
|
|
|
// Override message value
|
|
|
|
$msgVals = array(
|
2013-05-30 11:00:36 +00:00
|
|
|
'visualeditor-feedback-link' => wfMessage( 'visualeditor-feedback-link' )
|
|
|
|
->inContentLanguage()
|
|
|
|
->text(),
|
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 ) {
|
2012-12-06 05:27:44 +00:00
|
|
|
$copywarnMsg = array( 'copyrightwarning',
|
|
|
|
'[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]',
|
2014-08-13 08:15:42 +00:00
|
|
|
$rightsText );
|
2012-12-06 05:27:44 +00:00
|
|
|
} else {
|
|
|
|
$copywarnMsg = array( 'copyrightwarning2',
|
|
|
|
'[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' );
|
|
|
|
}
|
|
|
|
// EditPage supports customisation based on title, we can't support that here
|
|
|
|
// since these messages are cached on a site-level. $wgTitle is likely set to null.
|
|
|
|
$title = Title::newFromText( 'Dwimmerlaik' );
|
2015-08-06 18:09:19 +00:00
|
|
|
Hooks::run( 'EditPageCopyrightWarning', array( $title, &$copywarnMsg ) );
|
2012-12-06 05:27:44 +00:00
|
|
|
|
|
|
|
// Normalise to 'copyrightwarning' so we have a consistent key in the front-end.
|
|
|
|
$msgArgs[ 'copyrightwarning' ] = $copywarnMsg;
|
|
|
|
|
2014-05-08 21:56:35 +00:00
|
|
|
return array(
|
|
|
|
'args' => $msgArgs,
|
|
|
|
'vals' => $msgVals,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-11-10 00:23:14 +00:00
|
|
|
public function enableModuleContentVersion() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
|
|
|
return array(
|
|
|
|
'ext.visualEditor.base',
|
|
|
|
'ext.visualEditor.mediawiki',
|
|
|
|
);
|
|
|
|
}
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|