From 2dd9ec21dc5d5f2c25658b58a2dc9f564331e6e2 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 8 Jun 2015 15:47:21 +0100 Subject: [PATCH] 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 --- autoload.php | 2 +- ....php => ResourceLoaderJqueryMsgModule.php} | 28 +++++++-------- resources/Resources.php | 6 ++-- .../src/mediawiki/mediawiki.jqueryMsg.js | 34 +++++++++++-------- 4 files changed, 36 insertions(+), 34 deletions(-) rename includes/resourceloader/{ResourceLoaderJqueryMsgDataModule.php => ResourceLoaderJqueryMsgModule.php} (67%) diff --git a/autoload.php b/autoload.php index 74c7efda69..d543fe0fce 100644 --- a/autoload.php +++ b/autoload.php @@ -993,7 +993,7 @@ $wgAutoloadLocalClasses = array( 'ResourceLoaderFilePath' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePath.php', 'ResourceLoaderImage' => __DIR__ . '/includes/resourceloader/ResourceLoaderImage.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', 'ResourceLoaderLanguageNamesModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageNamesModule.php', 'ResourceLoaderModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderModule.php', diff --git a/includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php b/includes/resourceloader/ResourceLoaderJqueryMsgModule.php similarity index 67% rename from includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php rename to includes/resourceloader/ResourceLoaderJqueryMsgModule.php index fda3faaa4f..b90578120f 100644 --- a/includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php +++ b/includes/resourceloader/ResourceLoaderJqueryMsgModule.php @@ -1,6 +1,6 @@ getScript( $context ) ); - return $ret; + $summary = parent::getDefinitionSummary( $context ); + $summary[] = array( + 'sanitizerData' => Sanitizer::getRecognizedTagData() + ); + return $summary; } } diff --git a/resources/Resources.php b/resources/Resources.php index 644ff9ca50..7ba1b2d80e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -59,9 +59,6 @@ return array( // Scripts for the dynamic language specific data, like grammar forms. '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 */ /** @@ -1297,9 +1294,10 @@ return array( ), 'mediawiki.jqueryMsg' => array( + // Add data for mediawiki.jqueryMsg, such as allowed tags + 'class' => 'ResourceLoaderJqueryMsgModule', 'scripts' => 'resources/src/mediawiki/mediawiki.jqueryMsg.js', 'dependencies' => array( - 'mediawiki.jqueryMsg.data', 'mediawiki.util', 'mediawiki.language', 'dom-level2-shim', diff --git a/resources/src/mediawiki/mediawiki.jqueryMsg.js b/resources/src/mediawiki/mediawiki.jqueryMsg.js index 98148d58ea..66d560e5b0 100644 --- a/resources/src/mediawiki/mediawiki.jqueryMsg.js +++ b/resources/src/mediawiki/mediawiki.jqueryMsg.js @@ -17,14 +17,10 @@ magic: { '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. - // The simplified default here is overridden below by data supplied - // by the mediawiki.jqueryMsg.data module. - allowedHtmlElements: [ - 'b', - 'i' - ], + // Can be populated via setPrivateData(). + allowedHtmlElements: [], // Key tag name, value allowed attributes for that tag. // See Sanitizer::setupAttributeWhitelist 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 = {}; + /** + * 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). * e.g. -- 2.20.1