Krinkle has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/378748 )
Change subject: resourceloader: Support isKnownEmpty for general modules
......................................................................
resourceloader: Support isKnownEmpty for general modules
It was already supported for only=scripts and only=styles, but
not yet for general modules loaded as 'combined'.
This is especially useful for general modules that are private/embedded,
as this allows us to skip the loader.implement() boilerplate.
Bug: T176159
Change-Id: I83e9f74dad75867c10ebd0a94b87c31e4adbb57f
---
M includes/resourceloader/ResourceLoaderClientHtml.php
M tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
2 files changed, 10 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/48/378748/1
diff --git a/includes/resourceloader/ResourceLoaderClientHtml.php
b/includes/resourceloader/ResourceLoaderClientHtml.php
index 06f9841..c76ed91 100644
--- a/includes/resourceloader/ResourceLoaderClientHtml.php
+++ b/includes/resourceloader/ResourceLoaderClientHtml.php
@@ -149,6 +149,13 @@
continue;
}
+ $context = $this->getContext( $module->getGroup(),
ResourceLoaderModule::TYPE_COMBINED );
+ if ( $module->isKnownEmpty( $context ) ) {
+ // Avoid needless request or embed for empty
module
+ $data['states'][$name] = 'ready';
+ continue;
+ }
+
if ( $module->shouldEmbedModule( $this->context ) ) {
// Embed via mw.loader.implement per T36907.
$data['embed']['general'][] = $name;
diff --git
a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
index 3530d3c..eaae9dc 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
@@ -43,6 +43,7 @@
'test.top' => [ 'position' => 'top' ],
'test.private.top' => [ 'group' => 'private',
'position' => 'top' ],
'test.private.bottom' => [ 'group' => 'private',
'position' => 'bottom' ],
+ 'test.shouldembed.empty' => [ 'shouldEmbed' => true,
'isKnownEmpty' => true ],
'test.shouldembed' => [ 'shouldEmbed' => true ],
'test.styles.pure' => [ 'type' =>
ResourceLoaderModule::LOAD_STYLES ],
@@ -115,6 +116,7 @@
'test.private.bottom',
'test.private.top',
'test.top',
+ 'test.shouldembed.empty',
'test.shouldembed',
'test.unregistered',
] );
@@ -138,6 +140,7 @@
'states' => [
'test.private.top' => 'loading',
'test.private.bottom' => 'loading',
+ 'test.shouldembed.empty' => 'ready',
'test.shouldembed' => 'loading',
'test.styles.pure' => 'ready',
'test.styles.user.empty' => 'ready',
--
To view, visit https://gerrit.wikimedia.org/r/378748
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I83e9f74dad75867c10ebd0a94b87c31e4adbb57f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits