2012-06-21 20:39:27 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Resource loader module for certain VisualEditor messages.
|
|
|
|
*
|
|
|
|
* @file
|
2012-07-19 00:11:26 +00:00
|
|
|
* @ingroup Extensions
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-12-04 06:56:41 +00:00
|
|
|
* Module for special messages VisualEditor needs to have parsed server side.
|
2012-06-21 20:39:27 +00:00
|
|
|
*/
|
|
|
|
class VisualEditorMessagesModule extends ResourceLoaderModule {
|
|
|
|
|
|
|
|
/* Protected Members */
|
|
|
|
|
2012-12-04 06:56:41 +00:00
|
|
|
protected $origin = self::ORIGIN_USER_SITEWIDE;
|
2012-06-21 20:39:27 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2012-12-06 05:27:44 +00:00
|
|
|
$msgInfo = $this->getMessageInfo();
|
2012-12-04 06:56:41 +00:00
|
|
|
$parsedMesssages = 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 ) {
|
|
|
|
$parsedMesssages[ $msgKey ] = call_user_func_array( 'wfMessage', $msgArgs )
|
|
|
|
->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;
|
|
|
|
}
|
|
|
|
return
|
|
|
|
've.init.platform.addParsedMessages(' . FormatJson::encode( $parsedMesssages ) . ');'.
|
|
|
|
've.init.platform.addMessages(' . FormatJson::encode( $messages ) . ');'
|
|
|
|
;
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 05:27:44 +00:00
|
|
|
protected function getMessageInfo() {
|
|
|
|
$msgKeys = array();
|
|
|
|
|
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' ),
|
|
|
|
'watchthis' => array( 'watchthis' ),
|
2012-12-11 23:19:21 +00:00
|
|
|
'visualeditor-report-notice' => array( 'visualeditor-report-notice' ),
|
2013-05-17 14:27:33 +00:00
|
|
|
'missingsummary' => array( 'missingsummary' ),
|
2012-12-06 05:27:44 +00:00
|
|
|
);
|
|
|
|
|
2013-05-18 17:34:25 +00:00
|
|
|
// Override message value
|
|
|
|
$msgVals = array(
|
|
|
|
'visualeditor-feedback-link' => wfMessage( 'visualeditor-feedback-link' )->inContentLanguage()->text(),
|
|
|
|
);
|
|
|
|
|
2012-12-06 05:27:44 +00:00
|
|
|
// Copyright warning (based on EditPage::getCopyrightWarning)
|
|
|
|
global $wgRightsText;
|
|
|
|
if ( $wgRightsText ) {
|
|
|
|
$copywarnMsg = array( 'copyrightwarning',
|
|
|
|
'[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]',
|
|
|
|
$wgRightsText );
|
|
|
|
} 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' );
|
|
|
|
wfRunHooks( 'EditPageCopyrightWarning', array( $title, &$copywarnMsg ) );
|
|
|
|
|
|
|
|
// Keys used in copyright warning
|
|
|
|
$msgKeys[] = 'copyrightpage';
|
|
|
|
$msgKeys[] = $copywarnMsg[0];
|
|
|
|
// Normalise to 'copyrightwarning' so we have a consistent key in the front-end.
|
|
|
|
$msgArgs[ 'copyrightwarning' ] = $copywarnMsg;
|
|
|
|
|
2013-05-18 17:34:25 +00:00
|
|
|
$msgKeys = array_values( array_unique( array_merge( $msgKeys, array_keys( $msgArgs ), array_keys( $msgVals ) ) ) );
|
2012-12-06 05:27:44 +00:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'keys' => $msgKeys,
|
|
|
|
'args' => $msgArgs,
|
2013-05-18 17:34:25 +00:00
|
|
|
'vals' => $msgVals,
|
2012-12-06 05:27:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-06-21 20:39:27 +00:00
|
|
|
public function getMessages() {
|
2012-12-06 05:27:44 +00:00
|
|
|
// We don't actually use the client-side message system for these messages.
|
|
|
|
// But we're registering them in this standardised method to make use of the
|
|
|
|
// getMsgBlobMtime utility to make cache invalidation work out-of-the-box.
|
|
|
|
|
|
|
|
$msgInfo = $this->getMessageInfo();
|
|
|
|
return $msgInfo['keys'];
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|
2012-07-20 23:59:59 +00:00
|
|
|
|
2012-06-21 20:39:27 +00:00
|
|
|
public function getDependencies() {
|
|
|
|
return array( 'ext.visualEditor.base' );
|
|
|
|
}
|
2012-12-04 06:56:41 +00:00
|
|
|
|
|
|
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
|
|
|
return max(
|
|
|
|
$this->getMsgBlobMtime( $context->getLanguage() ),
|
|
|
|
// Also invalidate this module if this file changes (i.e. when messages were
|
|
|
|
// added or removed, or when the javascript invocation in getScript is changes).
|
|
|
|
file_exists( __FILE__ ) ? filemtime( __FILE__ ) : 1 // use 1 because 0 = now, would invalidate continously
|
|
|
|
);
|
|
|
|
}
|
2012-06-21 20:39:27 +00:00
|
|
|
}
|