/**
  * Get data for each gallery item
  * @param array $item Data about the media item
  * @param int $index Where the item shows up in the gallery
  * @return array|null
  */
 protected function getMediaData(array $item, $index)
 {
     $file = wfFindFile($item['title']);
     if (!$file instanceof File) {
         WikiaLogger::instance()->error('File with title: ' . $item['title'] . 'doesn\'t exist', ['class' => __CLASS__]);
         return null;
     }
     $dimension = MediaGalleryHelper::getImageWidth($this->itemCount, $index);
     $thumbUrl = WikiaFileHelper::getSquaredThumbnailUrl($file, $dimension);
     $dimensions = ['width' => $dimension, 'height' => $dimension];
     $thumb = $file->transform($dimensions);
     if (!$thumb instanceof ThumbnailImage) {
         WikiaLogger::instance()->error('ThumbnailImage from title: ' . $item['title'] . ' couldn\'t be created.', ['thumbClass' => get_class($thumb)]);
         return null;
     }
     $thumb->setUrl($thumbUrl);
     $thumbnail = $this->app->renderView('ThumbnailController', 'gallery', ['thumb' => $thumb]);
     $caption = '';
     if (!empty($item['caption'])) {
         // parse any wikitext in caption. Logic borrowed from WikiaMobileMediaService::renderMediaGroup.
         $parser = $this->getParser();
         $caption = $parser->internalParse($item['caption']);
         $parser->replaceLinkHolders($caption);
         $caption = $parser->killMarkers($caption);
     }
     $title = $file->getTitle();
     return ['thumbUrl' => $thumbUrl, 'thumbHtml' => $thumbnail, 'caption' => $caption, 'linkHref' => $file->getTitle()->getLinkURL(), 'title' => $title->getText(), 'dbKey' => $title->getDBKey()];
 }
 /**
  * Set urls to be used for <picture> tags. Sets both thumbnails in the original format (jpeg, png, etc),
  * and WebP to be used if the browser supports it.
  * @param WikiaController $controller
  * @param MediaTransformOutput $thumb
  */
 public static function setPictureTagInfo(WikiaController $controller, MediaTransformOutput $thumb)
 {
     $file = $thumb->file;
     $fullSizeDimension = max($thumb->getWidth(), $thumb->getHeight());
     $smallSizeDimension = $fullSizeDimension * self::SMALL_THUMB_SIZE;
     $useWebP = true;
     // get small images (original and WebP)
     $controller->smallUrl = WikiaFileHelper::getSquaredThumbnailUrl($file, $smallSizeDimension);
     $controller->smallUrlWebP = WikiaFileHelper::getSquaredThumbnailUrl($file, $smallSizeDimension, $useWebP);
     // Set the breakpoint used by the <picture> tag to determine which image to load
     $controller->breakPoint = self::MEDIUM_BREAKPOINT;
     // get full size WebP image
     $controller->imgSrcWebP = WikiaFileHelper::getSquaredThumbnailUrl($file, $fullSizeDimension, $useWebP);
     // Let image template know to use <picture> tag instead of <img> tag
     $controller->usePictureTag = true;
 }