Fix description for $wgGalleryOptions in DefaultSettings.php
[lhc/web/wiklou.git] / includes / media / ThumbnailImage.php
index 0deb89f..7ee6dcb 100644 (file)
@@ -110,9 +110,9 @@ class ThumbnailImage extends MediaTransformOutput {
         * @return string
         */
        function toHtml( $options = [] ) {
-               global $wgPriorityHints, $wgElementTiming;
+               global $wgPriorityHints, $wgPriorityHintsRatio, $wgElementTiming;
 
-               if ( count( func_get_args() ) == 2 ) {
+               if ( func_num_args() == 2 ) {
                        throw new MWException( __METHOD__ . ' called in the old style' );
                }
 
@@ -133,8 +133,16 @@ class ThumbnailImage extends MediaTransformOutput {
                        && $this->width * $this->height > 100 * 100 ) {
                        self::$firstNonIconImageRendered = true;
 
-                       $attribs['importance'] = 'high';
-                       $elementTimingName = 'thumbnail-high';
+                       // Generate a random number between 0.01 and 1.0, included
+                       $random = rand( 1, 100 ) / 100.0;
+
+                       if ( $random <= $wgPriorityHintsRatio ) {
+                               $attribs['importance'] = 'high';
+                               $elementTimingName = 'thumbnail-high';
+                       } else {
+                               // This lets us track that the thumbnail *would* have gotten high priority but didn't.
+                               $elementTimingName = 'thumbnail-top';
+                       }
                }
 
                if ( $wgElementTiming ) {