diff --git a/includes/ResourceLoaderULSModule.php b/includes/ResourceLoaderULSModule.php index c0c44395..be839f9a 100644 --- a/includes/ResourceLoaderULSModule.php +++ b/includes/ResourceLoaderULSModule.php @@ -1,6 +1,6 @@ getLanguage(); - $out = ''; - foreach ( $this->getData( $languageCode ) as $key => $value ) { - $out .= Xml::encodeJsCall( 'mw.config.set', [ $key, $value ] ); - } - - return $out; + return Xml::encodeJsCall( 'mw.config.set', [ + $this->getData( $languageCode ) + ] ); } /** - * Gets the last modified time for this module depending on the given - * context. - * - * @param $context ResourceLoaderContext - * @return int Unix timestamp + * @return bool */ - public function getModifiedTime( ResourceLoaderContext $context ) { - $languageCode = $context->getLanguage(); - - $cache = wfGetCache( CACHE_ANYTHING ); - - // Since we are updating the timestamp on hash change, we need to - // cache the hash per language to avoid updating the timestamp when - // different languages are being requested. - $key = wfMemcKey( - 'uls', - 'modulemodifiedhash', - $this->getName(), - $languageCode - ); - - $data = $this->getData( $languageCode ); - $hash = md5( serialize( $data ) ); - - $result = $cache->get( $key ); - if ( is_array( $result ) && $result['hash'] === $hash ) { - return $result['timestamp']; - } - $timestamp = wfTimestamp(); - $cache->set( $key, [ - 'hash' => $hash, - 'timestamp' => $timestamp, - ] ); - - return $timestamp; + public function enableModuleContentVersion() { + return true; } } diff --git a/tests/phpunit/ResourceLoaderULSTest.php b/tests/phpunit/ResourceLoaderULSTest.php deleted file mode 100644 index f567420e..00000000 --- a/tests/phpunit/ResourceLoaderULSTest.php +++ /dev/null @@ -1,49 +0,0 @@ -setVal( 'lang', 'he' ); - $context = new ResourceLoaderContext( - new ResourceLoader(), $request ); - $mtimeHebrew = $module->getModifiedTime( $context ); - // sleep for 1 second - sleep( 1 ); - $request->setVal( 'lang', 'hi' ); - $context = new ResourceLoaderContext( new ResourceLoader(), $request ); - $mtimeHindi = $module->getModifiedTime( $context ); - $this->assertGreaterThan( $mtimeHebrew, $mtimeHindi, 'Hindi has recent timestamp than Hebrew' ); - - // sleep for 1 second - sleep( 1 ); - $request->setVal( 'lang', 'he' ); - $context = new ResourceLoaderContext( new ResourceLoader(), $request ); - $mtimeHebrewNew = $module->getModifiedTime( $context ); - $this->assertEquals( $mtimeHebrewNew, $mtimeHebrew, 'Hebrew timestamp remained same' ); - - // sleep for 1 second - sleep( 1 ); - $request->setVal( 'lang', 'hi' ); - $context = new ResourceLoaderContext( new ResourceLoader(), $request ); - $mtimeHindiNew = $module->getModifiedTime( $context ); - $this->assertEquals( $mtimeHindi, $mtimeHindiNew, 'Hindi timestamp remained same' ); - } -}