mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-28 16:10:55 +00:00
Merge "Remove unnecessary MinervaResourceLoaderParsedMessageModule"
This commit is contained in:
commit
32b15522b1
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* ResourceLoaderModule subclass for Minerva
|
||||
* Allows basic server side parsing of messages without arguments
|
||||
*/
|
||||
class MinervaResourceLoaderParsedMessageModule extends ResourceLoaderFileModule {
|
||||
/** @var array Saves a list of messages which have been marked as needing parsing. */
|
||||
protected $parsedMessages = [];
|
||||
/** @var array Saves a list of message keys used by this module. */
|
||||
protected $messages = [];
|
||||
/** @var array Saves the target for the module (e.g. desktop and mobile). */
|
||||
protected $targets = [ 'mobile', 'desktop' ];
|
||||
/** @var boolean Whether the module abuses getScript. */
|
||||
protected $hasHackedScriptMode = false;
|
||||
|
||||
/**
|
||||
* Registers core modules and runs registration hooks.
|
||||
* @param array $options List of options; if not given or empty,
|
||||
* an empty module will be constructed
|
||||
*/
|
||||
public function __construct( $options ) {
|
||||
foreach ( $options as $member => $option ) {
|
||||
switch ( $member ) {
|
||||
case 'messages':
|
||||
$this->processMessages( $option );
|
||||
$this->hasHackedScriptMode = true;
|
||||
// Prevent them being reinitialised when parent construct is called.
|
||||
unset( $options[$member] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct( $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process messages which have been marked as needing parsing
|
||||
*
|
||||
* @param ResourceLoaderContext $context
|
||||
* @return string JavaScript code
|
||||
*/
|
||||
public function addParsedMessages( ResourceLoaderContext $context ) {
|
||||
if ( !$this->parsedMessages ) {
|
||||
return '';
|
||||
}
|
||||
$messages = [];
|
||||
foreach ( $this->parsedMessages as $key ) {
|
||||
$messages[ $key ] = $context->msg( $key )->parse();
|
||||
}
|
||||
return Xml::encodeJsCall( 'mw.messages.set', [ $messages ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate messages which have been marked as needing parsing from standard messages
|
||||
* @param array $messages Array of messages to process
|
||||
*/
|
||||
private function processMessages( $messages ) {
|
||||
foreach ( $messages as $key => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $directive ) {
|
||||
if ( $directive == 'parse' ) {
|
||||
$this->parsedMessages[] = $key;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->messages[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all scripts for a given context concatenated together including processed messages
|
||||
*
|
||||
* @param ResourceLoaderContext $context Context in which to generate script
|
||||
* @return string JavaScript code for $context
|
||||
*/
|
||||
public function getScript( ResourceLoaderContext $context ) {
|
||||
$script = parent::getScript( $context );
|
||||
return $this->addParsedMessages( $context ) . $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL or URLs to load for this module's JS in debug mode.
|
||||
* @param ResourceLoaderContext $context
|
||||
* @return array list of urls
|
||||
* @see ResourceLoaderModule::getScriptURLsForDebug
|
||||
*/
|
||||
public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
|
||||
if ( $this->hasHackedScriptMode ) {
|
||||
$derivative = new DerivativeResourceLoaderContext( $context );
|
||||
$derivative->setDebug( true );
|
||||
$derivative->setModules( [ $this->getName() ] );
|
||||
// @todo FIXME: Make this templates and update
|
||||
// makeModuleResponse so that it only outputs template code.
|
||||
// When this is done you can merge with parent array and
|
||||
// retain file names.
|
||||
$derivative->setOnly( 'scripts' );
|
||||
$rl = $derivative->getResourceLoader();
|
||||
$urls = [
|
||||
$rl->createLoaderURL( $this->getSource(), $derivative ),
|
||||
];
|
||||
} else {
|
||||
$urls = parent::getScriptURLsForDebug( $context );
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
}
|
39
skin.json
39
skin.json
|
@ -40,7 +40,6 @@
|
|||
"minerva": "MinervaNeue"
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"MinervaResourceLoaderParsedMessageModule": "includes/MinervaResourceLoaderParsedMessageModule.php",
|
||||
"MinervaUI": "includes/MinervaUI.php",
|
||||
"MinervaHooks": "includes/MinervaHooks.php",
|
||||
"MinervaTemplate": "includes/skins/MinervaTemplate.php",
|
||||
|
@ -485,7 +484,10 @@
|
|||
]
|
||||
},
|
||||
"skins.minerva.editor": {
|
||||
"class": "MinervaResourceLoaderParsedMessageModule",
|
||||
"targets": [
|
||||
"mobile",
|
||||
"desktop"
|
||||
],
|
||||
"dependencies": [
|
||||
"mediawiki.util",
|
||||
"mediawiki.router",
|
||||
|
@ -497,22 +499,18 @@
|
|||
"mediawiki.jqueryMsg",
|
||||
"skins.minerva.editor.blockMessage"
|
||||
],
|
||||
"messages": {
|
||||
"0": "mobile-frontend-editor-disabled",
|
||||
"1": "mobile-frontend-editor-unavailable",
|
||||
"2": "mobile-frontend-editor-uploadenable",
|
||||
"mobile-frontend-editor-blocked-info-loggedin": [
|
||||
"parse"
|
||||
],
|
||||
"3": "mobile-frontend-editor-cta",
|
||||
"4": "mobile-frontend-editor-undo-unsupported",
|
||||
"5": "mobile-frontend-editor-edit",
|
||||
"6": "mobile-frontend-editor-redlink-create",
|
||||
"7": "mobile-frontend-editor-redlink-leave",
|
||||
"mobile-frontend-editor-redlink-explain": [
|
||||
"parse"
|
||||
]
|
||||
},
|
||||
"messages": [
|
||||
"mobile-frontend-editor-disabled",
|
||||
"mobile-frontend-editor-unavailable",
|
||||
"mobile-frontend-editor-uploadenable",
|
||||
"mobile-frontend-editor-blocked-info-loggedin",
|
||||
"mobile-frontend-editor-cta",
|
||||
"mobile-frontend-editor-undo-unsupported",
|
||||
"mobile-frontend-editor-edit",
|
||||
"mobile-frontend-editor-redlink-create",
|
||||
"mobile-frontend-editor-redlink-leave",
|
||||
"mobile-frontend-editor-redlink-explain"
|
||||
],
|
||||
"scripts": [
|
||||
"resources/skins.minerva.editor/init.js"
|
||||
]
|
||||
|
@ -567,7 +565,10 @@
|
|||
]
|
||||
},
|
||||
"skins.minerva.toggling": {
|
||||
"class": "MinervaResourceLoaderParsedMessageModule",
|
||||
"targets": [
|
||||
"mobile",
|
||||
"desktop"
|
||||
],
|
||||
"dependencies": [
|
||||
"mobile.toggle",
|
||||
"skins.minerva.icons.images.variants",
|
||||
|
|
Loading…
Reference in a new issue