Merge "resourceloader: Replace some Xml::encodeJs calls with RL's own encodeJson"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 16 Jul 2019 06:26:42 +0000 (06:26 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 16 Jul 2019 06:26:42 +0000 (06:26 +0000)
RELEASE-NOTES-1.34
docs/hooks.txt
includes/DummyLinker.php
includes/Linker.php
includes/cache/localisation/LocalisationCache.php
includes/resourceloader/ResourceLoader.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 6da7962..1bd4980 100644 (file)
@@ -285,6 +285,12 @@ because of Phabricator reports.
   which were deprecated and ignored by core since 1.22, are no longer set to any
   value, and SkinTemplate no longer emits a 'jsmimetype' key. Any extensions not
   updated since 2013 to cope with this deprecation may now break.
+* (T222637) Passing ResourceLoaderModule objects to ResourceLoader::register()
+  or $wgResourceModules is no longer supported.
+  Use the 'class' or 'factory' option of the array format instead.
+* The parameter $lang of the functions generateTOC and tocList in Linker and
+  DummyLinker must be in type Language when present. Other types are
+  deprecated since 1.33.
 * …
 
 === Deprecations in 1.34 ===
@@ -364,6 +370,8 @@ because of Phabricator reports.
   been deprecated.
 * User::getRights() and User::$mRights have been deprecated. Use
   PermissionManager::getUserPermissions() instead.
+* The LocalisationCacheRecache hook no longer allows purging of message blobs
+  to be prevented. Modifying the $purgeBlobs parameter now has no effect.
 
 === Other changes in 1.34 ===
 * …
index 8f3c67e..36e0891 100644 (file)
@@ -2095,8 +2095,6 @@ cache.
 $cache: The LocalisationCache object
 $code: language code
 &$alldata: The localisation data from core and extensions
-&$purgeBlobs: whether to purge/update the message blobs via
-  MessageBlobStore::clear()
 
 'LocalisationCacheRecacheFallback': Called for each language when merging
 fallback data into the cache.
index e46c45e..00d66bf 100644 (file)
@@ -345,11 +345,11 @@ class DummyLinker {
                return Linker::tocLineEnd();
        }
 
-       public function tocList( $toc, $lang = null ) {
+       public function tocList( $toc, Language $lang = null ) {
                return Linker::tocList( $toc, $lang );
        }
 
-       public function generateTOC( $tree, $lang = null ) {
+       public function generateTOC( $tree, Language $lang = null ) {
                return Linker::generateTOC( $tree, $lang );
        }
 
index 2e0011c..f20795d 100644 (file)
@@ -1667,16 +1667,11 @@ class Linker {
         *
         * @since 1.16.3
         * @param string $toc Html of the Table Of Contents
-        * @param string|Language|bool|null $lang Language for the toc title, defaults to user language.
-        *  The types string and bool are deprecated.
+        * @param Language|null $lang Language for the toc title, defaults to user language
         * @return string Full html of the TOC
         */
-       public static function tocList( $toc, $lang = null ) {
+       public static function tocList( $toc, Language $lang = null ) {
                $lang = $lang ?? RequestContext::getMain()->getLanguage();
-               if ( !$lang instanceof Language ) {
-                       wfDeprecated( __METHOD__ . ' with type other than Language for $lang', '1.33' );
-                       $lang = wfGetLangObj( $lang );
-               }
 
                $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
 
@@ -1709,11 +1704,10 @@ class Linker {
         *
         * @since 1.16.3. $lang added in 1.17
         * @param array $tree Return value of ParserOutput::getSections()
-        * @param string|Language|bool|null $lang Language for the toc title, defaults to user language.
-        *  The types string and bool are deprecated.
+        * @param Language|null $lang Language for the toc title, defaults to user language
         * @return string HTML fragment
         */
-       public static function generateTOC( $tree, $lang = null ) {
+       public static function generateTOC( $tree, Language $lang = null ) {
                $toc = '';
                $lastLevel = 0;
                foreach ( $tree as $section ) {
index c4a7e89..a0f3d8e 100644 (file)
@@ -1004,8 +1004,8 @@ class LocalisationCache {
                        $allData['list'][$key] = array_keys( $allData[$key] );
                }
                # Run hooks
-               $purgeBlobs = true;
-               Hooks::run( 'LocalisationCacheRecache', [ $this, $code, &$allData, &$purgeBlobs ] );
+               $unused = true; // Used to be $purgeBlobs, removed in 1.34
+               Hooks::run( 'LocalisationCacheRecache', [ $this, $code, &$allData, &$unused ] );
 
                if ( is_null( $allData['namespaceNames'] ) ) {
                        throw new MWException( __METHOD__ . ': Localisation data failed sanity check! ' .
@@ -1037,7 +1037,7 @@ class LocalisationCache {
                # Clear out the MessageBlobStore
                # HACK: If using a null (i.e. disabled) storage backend, we
                # can't write to the MessageBlobStore either
-               if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) {
+               if ( !$this->store instanceof LCStoreNull ) {
                        $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
                        $blobStore->clear();
                }
index f8e76ac..671fe86 100644 (file)
@@ -297,13 +297,13 @@ class ResourceLoader implements LoggerAwareInterface {
        /**
         * Register a module with the ResourceLoader system.
         *
-        * @param mixed $name Name of module as a string or List of name/object pairs as an array
-        * @param array|null $info Module info array. For backwards compatibility with 1.17alpha,
-        *   this may also be a ResourceLoaderModule object. Optional when using
-        *   multiple-registration calling style.
+        * @param string|array[] $name Module name as a string or, array of module info arrays
+        *  keyed by name.
+        * @param array|null $info Module info array. When using the first parameter to register
+        *  multiple modules at once, this parameter is optional.
         * @throws MWException If a duplicate module registration is attempted
         * @throws MWException If a module name contains illegal characters (pipes or commas)
-        * @throws MWException If something other than a ResourceLoaderModule is being registered
+        * @throws InvalidArgumentException If the module info is not an array
         */
        public function register( $name, $info = null ) {
                $moduleSkinStyles = $this->config->get( 'ResourceModuleSkinStyles' );
@@ -320,29 +320,21 @@ class ResourceLoader implements LoggerAwareInterface {
                                );
                        }
 
-                       // Check $name for validity
+                       // Check validity
                        if ( !self::isValidModuleName( $name ) ) {
                                throw new MWException( "ResourceLoader module name '$name' is invalid, "
                                        . "see ResourceLoader::isValidModuleName()" );
                        }
-
-                       // Attach module
-                       if ( $info instanceof ResourceLoaderModule ) {
-                               $this->moduleInfos[$name] = [ 'object' => $info ];
-                               $info->setName( $name );
-                               $this->modules[$name] = $info;
-                       } elseif ( is_array( $info ) ) {
-                               // New calling convention
-                               $this->moduleInfos[$name] = $info;
-                       } else {
-                               throw new MWException(
-                                       'ResourceLoader module info type error for module \'' . $name .
-                                       '\': expected ResourceLoaderModule or array (got: ' . gettype( $info ) . ')'
+                       if ( !is_array( $info ) ) {
+                               throw new InvalidArgumentException(
+                                       'Invalid module info for "' . $name . '": expected array, got ' . gettype( $info )
                                );
                        }
 
-                       // Last-minute changes
+                       // Attach module
+                       $this->moduleInfos[$name] = $info;
 
+                       // Last-minute changes
                        // Apply custom skin-defined styles to existing modules.
                        if ( $this->isFileModule( $name ) ) {
                                foreach ( $moduleSkinStyles as $skinName => $skinStyles ) {
@@ -528,23 +520,18 @@ class ResourceLoader implements LoggerAwareInterface {
                                // No such module
                                return null;
                        }
-                       // Construct the requested object
+                       // Construct the requested module object
                        $info = $this->moduleInfos[$name];
-                       /** @var ResourceLoaderModule $object */
-                       if ( isset( $info['object'] ) ) {
-                               // Object given in info array
-                               $object = $info['object'];
-                       } elseif ( isset( $info['factory'] ) ) {
+                       if ( isset( $info['factory'] ) ) {
+                               /** @var ResourceLoaderModule $object */
                                $object = call_user_func( $info['factory'], $info );
-                               $object->setConfig( $this->getConfig() );
-                               $object->setLogger( $this->logger );
                        } else {
                                $class = $info['class'] ?? ResourceLoaderFileModule::class;
                                /** @var ResourceLoaderModule $object */
                                $object = new $class( $info );
-                               $object->setConfig( $this->getConfig() );
-                               $object->setLogger( $this->logger );
                        }
+                       $object->setConfig( $this->getConfig() );
+                       $object->setLogger( $this->logger );
                        $object->setName( $name );
                        $this->modules[$name] = $object;
                }
@@ -563,9 +550,6 @@ class ResourceLoader implements LoggerAwareInterface {
                        return false;
                }
                $info = $this->moduleInfos[$name];
-               if ( isset( $info['object'] ) ) {
-                       return false;
-               }
                return !isset( $info['factory'] ) && (
                        // The implied default for 'class' is ResourceLoaderFileModule
                        !isset( $info['class'] ) ||
index 412272d..86c2e9f 100644 (file)
@@ -113,7 +113,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         */
        public function testRegisterInvalidType() {
                $resourceLoader = new EmptyResourceLoader();
-               $this->setExpectedException( MWException::class, 'ResourceLoader module info type error' );
+               $this->setExpectedException( InvalidArgumentException::class, 'Invalid module info' );
                $resourceLoader->register( 'test', new stdClass() );
        }