From: Fomafix Date: Thu, 27 Jun 2019 12:28:17 +0000 (+0200) Subject: resourceloader: Omit parameter 'lang' from image URLs when not vary X-Git-Tag: 1.34.0-rc.0~1067^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=01a4a58982802055b231ca82fcbab092125112ef;p=lhc%2Fweb%2Fwiklou.git resourceloader: Omit parameter 'lang' from image URLs when not vary The parameter 'lang' is only added to the URL when the image vary on the language or on the direction. Also omit the parameter 'lang' when the value is equal to ResourceLoaderContext::DEFAULT_LANG. This change makes the URLs shorter and reduces the size of the stylesheets. This change also improves caching because the URLs do not vary on the language for the same image. Change-Id: Id7d8ecc7d95747f3c157f9abc12e8489e5085aff --- diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php index c1b3dc34ca..7829b71ea1 100644 --- a/includes/resourceloader/ResourceLoaderImage.php +++ b/includes/resourceloader/ResourceLoaderImage.php @@ -214,10 +214,13 @@ class ResourceLoaderImage { 'image' => $this->getName(), 'variant' => $variant, 'format' => $format, - 'lang' => $context->getLanguage(), - 'skin' => $context->getSkin(), - 'version' => $context->getVersion(), ]; + if ( $this->varyOnLanguage() ) { + $query['lang'] = $context->getLanguage(); + } + // The following parameters are at the end to keep the original order of the parameters. + $query['skin'] = $context->getSkin(); + $query['version'] = $context->getVersion(); return wfAppendQuery( $script, $query ); } @@ -446,4 +449,16 @@ class ResourceLoaderImage { return $png ?: false; } } + + /** + * Check if the image depends on the language. + * + * @return bool + */ + private function varyOnLanguage() { + return is_array( $this->descriptor ) && ( + isset( $this->descriptor['ltr'] ) || + isset( $this->descriptor['rtl'] ) || + isset( $this->descriptor['lang'] ) ); + } }