mediawiki.jqueryMsg: Phase out redundant data module and minor clean up
Follows-up 4a3e50a54.
* Merge mediawiki.jqueryMsg.data and mediawiki.jqueryMsg modules.
There's no need for this to be a separate module. The data is not for public consumption,
it's provided to jqueryMsg only.
* Remove unused default-default values for 'allowedHtmlElements'.
* Remove conditionals around data providing at initial run-time. Instead, expose
private method can call that. This way, we don't have two code paths claim
ownership over the namespace. And it makes the module easier to test and re-use
by not requiring the data to exist at first run time.
* Fix getDefinitionSummary() implementation to append data instead of setting
arbitary keys in parent data. ResourceLoader documentation of getDefinitionSummary()
has been updated to reflect this practice.
Change-Id: I40006d39514a997dce4930756a3dac84a0c9bb83
This commit is contained in:
parent
fb406cd28d
commit
2dd9ec21dc
4 changed files with 36 additions and 34 deletions
|
|
@ -993,7 +993,7 @@ $wgAutoloadLocalClasses = array(
|
||||||
'ResourceLoaderFilePath' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePath.php',
|
'ResourceLoaderFilePath' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePath.php',
|
||||||
'ResourceLoaderImage' => __DIR__ . '/includes/resourceloader/ResourceLoaderImage.php',
|
'ResourceLoaderImage' => __DIR__ . '/includes/resourceloader/ResourceLoaderImage.php',
|
||||||
'ResourceLoaderImageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderImageModule.php',
|
'ResourceLoaderImageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderImageModule.php',
|
||||||
'ResourceLoaderJqueryMsgDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php',
|
'ResourceLoaderJqueryMsgModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderJqueryMsgModule.php',
|
||||||
'ResourceLoaderLanguageDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageDataModule.php',
|
'ResourceLoaderLanguageDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageDataModule.php',
|
||||||
'ResourceLoaderLanguageNamesModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageNamesModule.php',
|
'ResourceLoaderLanguageNamesModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageNamesModule.php',
|
||||||
'ResourceLoaderModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderModule.php',
|
'ResourceLoaderModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderModule.php',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Resource loader module for populating mediawiki.jqueryMsg data.
|
* ResourceLoader module for mediawiki.jqueryMsg that provides generated data.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -22,21 +22,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ResourceLoader module for populating mediawiki.jqueryMsg data.
|
* ResourceLoader module for mediawiki.jqueryMsg and its generated data
|
||||||
*/
|
*/
|
||||||
class ResourceLoaderJqueryMsgDataModule extends ResourceLoaderModule {
|
class ResourceLoaderJqueryMsgModule extends ResourceLoaderFileModule {
|
||||||
|
|
||||||
protected $targets = array( 'desktop', 'mobile' );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ResourceLoaderContext $context
|
* @param ResourceLoaderContext $context
|
||||||
* @return string JavaScript code
|
* @return string JavaScript code
|
||||||
*/
|
*/
|
||||||
public function getScript( ResourceLoaderContext $context ) {
|
public function getScript( ResourceLoaderContext $context ) {
|
||||||
$jsData = array();
|
$fileScript = parent::getScript( $context );
|
||||||
|
|
||||||
$tagData = Sanitizer::getRecognizedTagData();
|
$tagData = Sanitizer::getRecognizedTagData();
|
||||||
$jsData['allowedHtmlElements'] = array_merge(
|
$parserDefaults = array();
|
||||||
|
$parserDefaults['allowedHtmlElements'] = array_merge(
|
||||||
array_keys( $tagData['htmlpairs'] ),
|
array_keys( $tagData['htmlpairs'] ),
|
||||||
array_diff(
|
array_diff(
|
||||||
array_keys( $tagData['htmlsingle'] ),
|
array_keys( $tagData['htmlsingle'] ),
|
||||||
|
|
@ -44,10 +43,9 @@ class ResourceLoaderJqueryMsgDataModule extends ResourceLoaderModule {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return "if ( !mw.jqueryMsg ) {\n" .
|
$dataScript = Xml::encodeJsCall( 'mw.jqueryMsg.setParserDefaults', array( $parserDefaults ) );
|
||||||
"\tmw.jqueryMsg = {};\n" .
|
|
||||||
"}\n" .
|
return $fileScript . $dataScript;
|
||||||
"mw.jqueryMsg.data = " . Xml::encodeJsVar( $jsData ) . ";\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -55,8 +53,10 @@ class ResourceLoaderJqueryMsgDataModule extends ResourceLoaderModule {
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public function getDefinitionSummary( ResourceLoaderContext $context ) {
|
public function getDefinitionSummary( ResourceLoaderContext $context ) {
|
||||||
$ret = parent::getDefinitionSummary( $context );
|
$summary = parent::getDefinitionSummary( $context );
|
||||||
$ret['hash'] = md5( $this->getScript( $context ) );
|
$summary[] = array(
|
||||||
return $ret;
|
'sanitizerData' => Sanitizer::getRecognizedTagData()
|
||||||
|
);
|
||||||
|
return $summary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,9 +59,6 @@ return array(
|
||||||
// Scripts for the dynamic language specific data, like grammar forms.
|
// Scripts for the dynamic language specific data, like grammar forms.
|
||||||
'mediawiki.language.data' => array( 'class' => 'ResourceLoaderLanguageDataModule' ),
|
'mediawiki.language.data' => array( 'class' => 'ResourceLoaderLanguageDataModule' ),
|
||||||
|
|
||||||
// Dynamic data for mediawiki.jqueryMsg, such as allowed tags
|
|
||||||
'mediawiki.jqueryMsg.data' => array( 'class' => 'ResourceLoaderJqueryMsgDataModule' ),
|
|
||||||
|
|
||||||
/* MediaWiki base skinning modules */
|
/* MediaWiki base skinning modules */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1297,9 +1294,10 @@ return array(
|
||||||
),
|
),
|
||||||
|
|
||||||
'mediawiki.jqueryMsg' => array(
|
'mediawiki.jqueryMsg' => array(
|
||||||
|
// Add data for mediawiki.jqueryMsg, such as allowed tags
|
||||||
|
'class' => 'ResourceLoaderJqueryMsgModule',
|
||||||
'scripts' => 'resources/src/mediawiki/mediawiki.jqueryMsg.js',
|
'scripts' => 'resources/src/mediawiki/mediawiki.jqueryMsg.js',
|
||||||
'dependencies' => array(
|
'dependencies' => array(
|
||||||
'mediawiki.jqueryMsg.data',
|
|
||||||
'mediawiki.util',
|
'mediawiki.util',
|
||||||
'mediawiki.language',
|
'mediawiki.language',
|
||||||
'dom-level2-shim',
|
'dom-level2-shim',
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,10 @@
|
||||||
magic: {
|
magic: {
|
||||||
'SITENAME': mw.config.get( 'wgSiteName' )
|
'SITENAME': mw.config.get( 'wgSiteName' )
|
||||||
},
|
},
|
||||||
// This is a whitelist like Sanitizer.php.
|
// Whitelist for allowed HTML elements in wikitext.
|
||||||
// Self-closing tags are not currently supported.
|
// Self-closing tags are not currently supported.
|
||||||
// The simplified default here is overridden below by data supplied
|
// Can be populated via setPrivateData().
|
||||||
// by the mediawiki.jqueryMsg.data module.
|
allowedHtmlElements: [],
|
||||||
allowedHtmlElements: [
|
|
||||||
'b',
|
|
||||||
'i'
|
|
||||||
],
|
|
||||||
// Key tag name, value allowed attributes for that tag.
|
// Key tag name, value allowed attributes for that tag.
|
||||||
// See Sanitizer::setupAttributeWhitelist
|
// See Sanitizer::setupAttributeWhitelist
|
||||||
allowedHtmlCommonAttributes: [
|
allowedHtmlCommonAttributes: [
|
||||||
|
|
@ -132,16 +128,24 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use data from mediawiki.jqueryMsg.data to override defaults, if
|
|
||||||
// available
|
|
||||||
if ( mw.jqueryMsg && mw.jqueryMsg.data ) {
|
|
||||||
if ( mw.jqueryMsg.data.allowedHtmlElements ) {
|
|
||||||
parserDefaults.allowedHtmlElements = mw.jqueryMsg.data.allowedHtmlElements;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mw.jqueryMsg = {};
|
mw.jqueryMsg = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize parser defaults.
|
||||||
|
*
|
||||||
|
* ResourceLoaderJqueryMsgModule calls this to provide default values from
|
||||||
|
* Sanitizer.php for allowed HTML elements. To override this data for individual
|
||||||
|
* parsers, pass the relevant options to mw.jqueryMsg.parser.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} data
|
||||||
|
*/
|
||||||
|
mw.jqueryMsg.setParserDefaults = function ( data ) {
|
||||||
|
if ( data.allowedHtmlElements ) {
|
||||||
|
parserDefaults.allowedHtmlElements = data.allowedHtmlElements;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a function suitable for use as a global, to construct strings from the message key (and optional replacements).
|
* Returns a function suitable for use as a global, to construct strings from the message key (and optional replacements).
|
||||||
* e.g.
|
* e.g.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue