jenkins-bot has submitted this change and it was merged.

Change subject: resourceloader: Add context param to 
ResourceLoaderModule::getDependencies
......................................................................


resourceloader: Add context param to ResourceLoaderModule::getDependencies

By providing context as a parameter in getDependencies, we allow
modules to dyanamically determine dependencies based on context.
Note: To ease rollout, the parameter is optional in this patch. It is expected
that it will be made non-optional in the near future.

The use case is for CentralNotice campaigns to be able to add special
modules ahead of deciding which banner to show a user. The dynamically
chosen RL modules would replace ad-hoc JS currently sent with some banners.
A list of possible campaigns and banners is already sent as a PHP-
implemented RL module; that's the module that will dynamically choose other
modules as dependencies when appropriate. This approach will save a round
trip as compared to dynamically loading the modules client-side.

For compatibility, extensions that override
ResourceLoaderModule::getDependencies() should be updated with the new
method signature. Here are changes for extensions currently deployed on
Wikimedia wikis:

* CentralNotice: I816bffa3815e2eab7e88cb04d1b345070e6aa15f
* Gadgets: I0a10fb0cbf17d095ece493e744296caf13dcee02
* EventLogging: I67e957f74d6ca48cfb9a41fb5144bcc78f885e50
* PageTriage: Ica3ba32aa2fc76d11a44f391b6edfc871e7fbe0d
* UniversalLanguageSelector: Ic63e617f51702c27104e123d4bed91983a726b7f
* VisualEditor: I0ac775ca286e64825e31a9213b94648e41a5bc30

For more on the CentralNotice use case, please see I9f80edcbcacca2.

Bug: T98924
Change-Id: Iee61e5b527321d01287baa03ad9b4d4f526ff3ef
---
M RELEASE-NOTES-1.26
M includes/resourceloader/ResourceLoaderFileModule.php
M includes/resourceloader/ResourceLoaderLanguageDataModule.php
M includes/resourceloader/ResourceLoaderLanguageNamesModule.php
M includes/resourceloader/ResourceLoaderModule.php
M includes/resourceloader/ResourceLoaderSpecialCharacterDataModule.php
M includes/resourceloader/ResourceLoaderStartUpModule.php
M includes/resourceloader/ResourceLoaderUserOptionsModule.php
M tests/phpunit/ResourceLoaderTestCase.php
9 files changed, 26 insertions(+), 9 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26
index b55e23b..c862bf3 100644
--- a/RELEASE-NOTES-1.26
+++ b/RELEASE-NOTES-1.26
@@ -59,6 +59,11 @@
 * mediaWiki.confirmCloseWindow now returns an object of functions, instead of
   one function. The callback can't be called directly any more. The callback
   function is replaced with confirmCloseWindow.release().
+* BREAKING CHANGE: Added an optional ResouceLoaderContext parameter to
+  ResourceLoaderModule::getDependencies(). Extension classes that override that
+  method should be updated. If they aren't updated, PHP Strict standards
+  warnings will appear when E_STRICT error reporting is enabled. Note: in the
+  near future, this parameter will probably become non-optional.
 * Removed maintenance script deleteImageMemcached.php.
 * MWFunction::newObj() was removed (deprecated in 1.25).
   ObjectFactory::getObjectFromSpec() should be used instead.
diff --git a/includes/resourceloader/ResourceLoaderFileModule.php 
b/includes/resourceloader/ResourceLoaderFileModule.php
index 0ee2e7d..e6c9bd0 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -478,10 +478,10 @@
 
        /**
         * Gets list of names of modules this module depends on.
-        *
+        * @param ResourceLoaderContext context
         * @return array List of module names
         */
-       public function getDependencies() {
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                return $this->dependencies;
        }
 
diff --git a/includes/resourceloader/ResourceLoaderLanguageDataModule.php 
b/includes/resourceloader/ResourceLoaderLanguageDataModule.php
index ebaf366..be15008 100644
--- a/includes/resourceloader/ResourceLoaderLanguageDataModule.php
+++ b/includes/resourceloader/ResourceLoaderLanguageDataModule.php
@@ -71,9 +71,10 @@
        }
 
        /**
+        * @param ResourceLoaderContext $context
         * @return array
         */
-       public function getDependencies() {
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                return array( 'mediawiki.language.init' );
        }
 }
diff --git a/includes/resourceloader/ResourceLoaderLanguageNamesModule.php 
b/includes/resourceloader/ResourceLoaderLanguageNamesModule.php
index 3111050..827a573 100644
--- a/includes/resourceloader/ResourceLoaderLanguageNamesModule.php
+++ b/includes/resourceloader/ResourceLoaderLanguageNamesModule.php
@@ -60,7 +60,11 @@
                );
        }
 
-       public function getDependencies() {
+       /**
+        * @param ResourceLoaderContext $context
+        * @return array
+        */
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                return array( 'mediawiki.language.init' );
        }
 
diff --git a/includes/resourceloader/ResourceLoaderModule.php 
b/includes/resourceloader/ResourceLoaderModule.php
index 958990c..741701c 100644
--- a/includes/resourceloader/ResourceLoaderModule.php
+++ b/includes/resourceloader/ResourceLoaderModule.php
@@ -331,9 +331,14 @@
         *
         * To add dependencies dynamically on the client side, use a custom
         * loader script, see getLoaderScript()
+        *
+        * Note: It is expected that $context will be made non-optional in the 
near
+        * future.
+        *
+        * @param ResourceLoaderContext $context
         * @return array List of module names as strings
         */
-       public function getDependencies() {
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                // Stub, override expected
                return array();
        }
diff --git 
a/includes/resourceloader/ResourceLoaderSpecialCharacterDataModule.php 
b/includes/resourceloader/ResourceLoaderSpecialCharacterDataModule.php
index 5eb4e3a..03f2124 100644
--- a/includes/resourceloader/ResourceLoaderSpecialCharacterDataModule.php
+++ b/includes/resourceloader/ResourceLoaderSpecialCharacterDataModule.php
@@ -62,9 +62,10 @@
        }
 
        /**
+        * @param ResourceLoaderContext $context
         * @return array
         */
-       public function getDependencies() {
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                return array( 'mediawiki.language' );
        }
 
diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php 
b/includes/resourceloader/ResourceLoaderStartUpModule.php
index 6c078b0..8dbed8e 100644
--- a/includes/resourceloader/ResourceLoaderStartUpModule.php
+++ b/includes/resourceloader/ResourceLoaderStartUpModule.php
@@ -226,7 +226,7 @@
 
                        $registryData[$name] = array(
                                'version' => $versionHash,
-                               'dependencies' => $module->getDependencies(),
+                               'dependencies' => $module->getDependencies( 
$context ),
                                'group' => $module->getGroup(),
                                'source' => $module->getSource(),
                                'loader' => $module->getLoaderScript(),
diff --git a/includes/resourceloader/ResourceLoaderUserOptionsModule.php 
b/includes/resourceloader/ResourceLoaderUserOptionsModule.php
index 4ed1b87..aba0fa6 100644
--- a/includes/resourceloader/ResourceLoaderUserOptionsModule.php
+++ b/includes/resourceloader/ResourceLoaderUserOptionsModule.php
@@ -32,9 +32,10 @@
        protected $targets = array( 'desktop', 'mobile' );
 
        /**
+        * @param ResourceLoaderContext $context
         * @return array List of module names as strings
         */
-       public function getDependencies() {
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                return array( 'user.defaults' );
        }
 
diff --git a/tests/phpunit/ResourceLoaderTestCase.php 
b/tests/phpunit/ResourceLoaderTestCase.php
index 6346bb9..223019c 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -83,7 +83,7 @@
                return array( '' => $this->styles );
        }
 
-       public function getDependencies() {
+       public function getDependencies( ResourceLoaderContext $context = null 
) {
                return $this->dependencies;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/202925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iee61e5b527321d01287baa03ad9b4d4f526ff3ef
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: Katie Horn <kh...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to