/**
  * Return a HTML representation of the image slider
  *
  * @author Jakub Kurcek
  */
 private function renderSlider()
 {
     wfProfileIn(__METHOD__);
     // do not render empty sliders
     if (empty($this->mFiles)) {
         wfProfileOut(__METHOD__);
         return '';
     }
     $orientation = $this->getParam('orientation');
     // setup image serving for main images and navigation thumbnails
     if ($orientation == 'mosaic') {
         $imagesDimensions = array('w' => WikiaPhotoGalleryHelper::WIKIA_GRID_SLIDER_MOSAIC_MIN_IMG_WIDTH, 'h' => WikiaPhotoGalleryHelper::SLIDER_MOSAIC_MIN_IMG_HEIGHT);
         $sliderClass = 'mosaic';
         $thumbDimensions = array("w" => WikiaPhotoGalleryHelper::WIKIA_GRID_THUMBNAIL_MAX_WIDTH, "h" => 100);
     } else {
         $imagesDimensions = array('w' => WikiaPhotoGalleryHelper::SLIDER_MIN_IMG_WIDTH, 'h' => WikiaPhotoGalleryHelper::SLIDER_MIN_IMG_HEIGHT);
         if ($orientation == 'right') {
             $sliderClass = 'vertical';
             $thumbDimensions = array("w" => 110, "h" => 50);
         } else {
             $sliderClass = 'horizontal';
             $thumbDimensions = array("w" => 90, "h" => 70);
         }
     }
     $out = array();
     $sliderImageLimit = $orientation == 'mosaic' ? 5 : 4;
     foreach ($this->mFiles as $p => $pair) {
         /**
          * @var $nt Title
          * @var $text String
          * @var $link String
          */
         $nt = $pair[0];
         $text = $pair[1];
         $link = $pair[2];
         $linkText = $this->mData['images'][$p]['linktext'];
         $shortText = $this->mData['images'][$p]['shorttext'];
         $time = $descQuery = false;
         // parse link (RT #142515)
         $linkAttribs = $this->parseLink($nt->getLocalUrl(), $nt->getText(), $link);
         wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery));
         $file = wfFindFile($nt, $time);
         if (is_object($file) && $nt->getNamespace() == NS_FILE) {
             list($adjWidth, $adjHeight) = $this->fitWithin($file, $imagesDimensions);
             if (F::app()->checkSkin('wikiamobile')) {
                 $imageUrl = wfReplaceImageServer($file->getUrl(), $file->getTimestamp());
             } else {
                 $imageUrl = $this->resizeURL($file, $imagesDimensions);
             }
             // generate navigation thumbnails
             $thumbUrl = $this->cropURL($file, $thumbDimensions);
             // Handle videos
             $videoHtml = false;
             $videoPlayButton = false;
             $navClass = '';
             if (WikiaFileHelper::isFileTypeVideo($file)) {
                 // Get HTML for main video image
                 $htmlParams = array('file-link' => true, 'linkAttribs' => array('class' => 'wikiaPhotoGallery-slider force-lightbox'));
                 $videoHtml = $file->transform(array('width' => $imagesDimensions['w']))->toHtml($htmlParams);
                 // Get play button overlay for little video thumb
                 $videoPlayButton = $this->videoPlayButton;
                 $navClass = 'xxsmall video-thumbnail';
             }
             $data = array('imageUrl' => $imageUrl, 'imageTitle' => Sanitizer::removeHTMLtags($text), 'imageName' => $file->getTitle()->getText(), 'imageKey' => $file->getTitle()->getDBKey(), 'imageShortTitle' => Sanitizer::removeHTMLtags($shortText), 'imageLink' => !empty($link) ? $linkAttribs['href'] : '', 'imageDescription' => Sanitizer::removeHTMLtags($linkText), 'imageThumbnail' => $thumbUrl, 'adjWidth' => $adjWidth, 'adjHeight' => $adjHeight, 'centerTop' => $imagesDimensions['h'] > $adjHeight ? intval(($imagesDimensions['h'] - $adjHeight) / 2) : 0, 'centerLeft' => $imagesDimensions['w'] > $adjWidth ? intval(($imagesDimensions['w'] - $adjWidth) / 2) : 0, 'videoHtml' => $videoHtml, 'videoPlayButton' => $videoPlayButton, 'navClass' => $navClass);
             if (F::app()->checkSkin('wikiamobile')) {
                 $origWidth = $file->getWidth();
                 $origHeight = $file->getHeight();
                 $size = WikiaMobileMediaService::calculateMediaSize($origWidth, $origHeight);
                 $thumb = $file->transform($size);
                 $imageAttribs = array('src' => wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp()), 'width' => $size['width'], 'height' => $size['height']);
                 $imageParams = array('full' => $imageUrl);
                 if ($this->mParser) {
                     $this->mParser->replaceLinkHolders($text);
                 }
                 $data['mediaInfo'] = array('attributes' => $imageAttribs, 'parameters' => $imageParams, 'caption' => $text, 'noscript' => Xml::element('img', $imageAttribs, '', true));
             }
             $out[] = $data;
         }
         if (count($out) >= $sliderImageLimit) {
             break;
         }
     }
     $html = '';
     //check if we have something to show (images might not match required sizes)
     if (count($out)) {
         $template = new EasyTemplate(dirname(__FILE__) . '/templates');
         $template->set_vars(array('sliderClass' => $sliderClass, 'files' => $out, 'thumbDimensions' => $thumbDimensions, 'sliderId' => $this->mData['id'], 'imagesDimensions' => $imagesDimensions));
         if (F::app()->checkSkin('wikiamobile')) {
             $html = $template->render('renderWikiaMobileSlider');
         } else {
             if ($orientation == 'mosaic') {
                 $html = $template->render('renderMosaicSlider');
             } else {
                 $html = $template->render('renderSlider');
             }
         }
         if ($orientation == 'mosaic') {
             $sliderResources = array('wikia_photo_gallery_mosaic_js', 'wikia_photo_gallery_mosaic_scss');
             $javascriptInitializationFunction = 'WikiaMosaicSliderMasterControl.init';
         } else {
             $sliderResources = array('wikia_photo_gallery_slider_js', 'wikia_photo_gallery_slider_scss');
             $javascriptInitializationFunction = 'WikiaPhotoGallerySlider.init';
         }
         $html .= JSSnippets::addToStack($sliderResources, array(), $javascriptInitializationFunction, array($this->mData['id']));
         //load WikiaMobile resources if needed using JSSnippets filtering mechanism
         $html .= JSSnippets::addToStack(array('wikiaphotogallery_slider_scss_wikiamobile', 'wikiaphotogallery_slider_js_wikiamobile'));
     }
     wfProfileOut(__METHOD__);
     return $html;
 }
 /**
  * Return a HTML representation of the image slider
  *
  * @author Jakub Kurcek
  */
 private function renderSlider()
 {
     wfProfileIn(__METHOD__);
     // do not render empty sliders
     if (empty($this->mImages)) {
         wfProfileOut(__METHOD__);
         return '';
     }
     $orientation = $this->getParam('orientation');
     // setup image serving for "big" images
     if ($orientation == 'mosaic') {
         $imagesDimensions = array('w' => WikiaPhotoGalleryHelper::SLIDER_MOSAIC_MIN_IMG_WIDTH, 'h' => WikiaPhotoGalleryHelper::SLIDER_MOSAIC_MIN_IMG_HEIGHT);
     } else {
         $imagesDimensions = array('w' => WikiaPhotoGalleryHelper::SLIDER_MIN_IMG_WIDTH, 'h' => WikiaPhotoGalleryHelper::SLIDER_MIN_IMG_HEIGHT);
     }
     /* temp transition code until grid is fully rolled out, remove and integrate after transition */
     global $wgOasisGrid;
     if ($orientation == 'mosaic' && !empty($wgOasisGrid)) {
         $imagesDimensions['w'] = WikiaPhotoGalleryHelper::WIKIA_GRID_SLIDER_MOSAIC_MIN_IMG_WIDTH;
     }
     /* end temp transistion code */
     $imageServingForImages = new ImageServing(null, $imagesDimensions['w'], $imagesDimensions);
     // setup image serving for navigation thumbnails
     if ($orientation == 'mosaic') {
         $sliderClass = 'mosaic';
         $thumbDimensions = array("w" => 155, "h" => 100);
     } else {
         if ($orientation == 'right') {
             $sliderClass = 'vertical';
             $thumbDimensions = array("w" => 110, "h" => 50);
         } else {
             $sliderClass = 'horizontal';
             $thumbDimensions = array("w" => 90, "h" => 70);
         }
     }
     /* temp transition code until grid is fully rolled out, remove and integrate after transition */
     if ($orientation == 'mosaic' && !empty($wgOasisGrid)) {
         $thumbDimensions['w'] = WikiaPhotoGalleryHelper::WIKIA_GRID_THUMBNAIL_MAX_WIDTH;
     }
     /* end temp transistion code */
     $imageServingForThumbs = new ImageServing(null, $thumbDimensions['w'], $thumbDimensions);
     $out = array();
     $sliderImageLimit = $orientation == 'mosaic' ? 5 : 4;
     foreach ($this->mImages as $p => $pair) {
         /**
          * @var $nt Title
          * @var $text String
          * @var $link String
          */
         $nt = $pair[0];
         $text = $pair[1];
         $link = $pair[2];
         $linkText = $this->mData['images'][$p]['linktext'];
         $shortText = $this->mData['images'][$p]['shorttext'];
         $time = $descQuery = false;
         // parse link (RT #142515)
         $linkAttribs = $this->parseLink($nt->getLocalUrl(), $nt->getText(), $link);
         wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery));
         $img = wfFindFile($nt, $time);
         if (!WikiaFileHelper::isFileTypeVideo($img) && is_object($img) && $nt->getNamespace() == NS_FILE) {
             if (F::app()->checkSkin('wikiamobile')) {
                 $imageUrl = wfReplaceImageServer($img->getUrl(), $img->getTimestamp());
             } else {
                 // generate cropped version of big image (fit within 660x360 box)
                 // BugId:9678 image thumbnailer does not always land on 360px height since we scale on width
                 // so this also scales image UP if it is too small (stretched is better than blank)
                 // max() added due to BugId:20644
                 $imageUrl = $imageServingForImages->getUrl($img, max($imagesDimensions['w'], $img->getWidth()), max($imagesDimensions['h'], $img->getHeight()));
             }
             // generate navigation thumbnails
             $thumbUrl = $imageServingForThumbs->getUrl($img, $img->getWidth(), $img->getHeight());
             $data = array('imageUrl' => $imageUrl, 'imageTitle' => $text, 'imageShortTitle' => $shortText, 'imageLink' => !empty($link) ? $linkAttribs['href'] : '', 'imageDescription' => $linkText, 'imageThumbnail' => $thumbUrl);
             if (F::app()->checkSkin('wikiamobile')) {
                 $origWidth = $img->getWidth();
                 $origHeight = $img->getHeight();
                 $size = WikiaMobileMediaService::calculateMediaSize($origWidth, $origHeight);
                 $thumb = $img->transform($size);
                 $imageAttribs = array('src' => wfReplaceImageServer($thumb->getUrl(), $img->getTimestamp()), 'width' => $size['width'], 'height' => $size['height']);
                 $imageParams = array('full' => $imageUrl);
                 $data['mediaInfo'] = array('attributes' => $imageAttribs, 'parameters' => $imageParams, 'caption' => $text, 'noscript' => Xml::element('img', $imageAttribs, '', true));
             }
             $out[] = $data;
         }
         if (count($out) >= $sliderImageLimit) {
             break;
         }
     }
     $html = '';
     //check if we have something to show (images might not match required sizes)
     if (count($out)) {
         $template = new EasyTemplate(dirname(__FILE__) . '/templates');
         $template->set_vars(array('sliderClass' => $sliderClass, 'images' => $out, 'thumbDimensions' => $thumbDimensions, 'sliderId' => $this->mData['id'], 'imagesDimensions' => $imagesDimensions));
         if (F::app()->checkSkin('wikiamobile')) {
             $html = $template->render('renderWikiaMobileSlider');
         } else {
             if ($orientation == 'mosaic') {
                 $html = $template->render('renderMosaicSlider');
             } else {
                 $html = $template->render('renderSlider');
             }
         }
         if ($orientation == 'mosaic') {
             $sliderResources = array('/resources/wikia/libraries/modernizr/modernizr-2.0.6.js', '/extensions/wikia/WikiaPhotoGallery/css/WikiaPhotoGallery.slidertag.mosaic.scss', '/extensions/wikia/WikiaPhotoGallery/js/WikiaPhotoGallery.slider.mosaic.js');
             $javascriptInitializationFunction = 'WikiaMosaicSliderMasterControl.init';
         } else {
             $sliderResources = array('/extensions/wikia/WikiaPhotoGallery/css/WikiaPhotoGallery.slidertag.css', '/extensions/wikia/WikiaPhotoGallery/js/WikiaPhotoGallery.slider.js');
             $javascriptInitializationFunction = 'WikiaPhotoGallerySlider.init';
         }
         $html .= F::build('JSSnippets')->addToStack($sliderResources, array(), $javascriptInitializationFunction, array($this->mData['id']));
         //load WikiaMobile resources if needed using JSSnippets filtering mechanism
         $html .= F::build('JSSnippets')->addToStack(array('wikiaphotogallery_slider_scss_wikiamobile', 'wikiaphotogallery_slider_js_wikiamobile'));
     }
     wfProfileOut(__METHOD__);
     return $html;
 }
 public static function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
 {
     global $wgRTEParserEnabled;
     if (!empty($wgRTEParserEnabled)) {
         return true;
     }
     if (is_null(self::$isWikiaMobile)) {
         self::init();
     }
     if (self::$isWikiaMobile) {
         wfProfileIn(__METHOD__);
         /**
          * WikiaMobile: lazy loading images in a SEO-friendly manner
          * @author Federico "Lox" Lucignano <federico@wikia-inc.com
          * @author Artur Klajnerok <*****@*****.**>
          */
         $origImg = Xml::element('img', $imageAttribs, '', true);
         if (empty($imageAttribs['alt'])) {
             unset($imageAttribs['alt']);
         }
         //Not all 'files' have getProviderName defined
         if (is_callable([$file, 'getProviderName'])) {
             $provider = $file->getProviderName();
         } else {
             $provider = '';
         }
         $imageParams = array('type' => 'video', 'provider' => $provider, 'full' => $imageAttribs['src']);
         if (!empty($imageAttribs['data-video-key'])) {
             $imageParams['name'] = htmlspecialchars($imageAttribs['data-video-key']);
         }
         if (!empty($options['caption'])) {
             $imageParams['capt'] = 1;
         }
         // TODO: this resizes every video thumbnail with a width over 64px regardless of where it appears.
         // We may want to add the ability to allow custom image widths (like on the file page history table for example)
         $size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
         $thumb = $file->transform($size);
         $imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
         $imageAttribs['width'] = $size['width'];
         $imageAttribs['height'] = $size['height'];
         $data = ['attributes' => $imageAttribs, 'parameters' => [$imageParams], 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg, 'isSmall' => WikiaMobileMediaService::isSmallImage($imageAttribs['width'], $imageAttribs['height'])];
         $title = $file->getTitle()->getDBKey();
         $titleText = $file->getTitle()->getText();
         $views = MediaQueryService::getTotalVideoViewsByTitle($title);
         $data['content'] = Xml::element('span', ['class' => 'videoInfo'], "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . wfMessage('wikiamobile-video-views-counter', $views)->inContentLanguage()->text() . ')');
         $html = F::app()->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
         wfProfileOut(__METHOD__);
     }
     return true;
 }
 public function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
 {
     $this->wf->profileIn(__METHOD__);
     if (self::$isWikiaMobile) {
         /**
          * WikiaMobile: lazy loading images in a SEO-friendly manner
          * @author Federico "Lox" Lucignano <federico@wikia-inc.com
          * @author Artur Klajnerok <*****@*****.**>
          */
         $origImg = Xml::element('img', $imageAttribs, '', true);
         if (empty($imageAttribs['alt'])) {
             unset($imageAttribs['alt']);
         }
         $imageParams = array('type' => 'video', 'full' => $imageAttribs['src']);
         if (!empty($linkAttribs['data-video-name'])) {
             $imageParams['name'] = $linkAttribs['data-video-name'];
         }
         if (!empty($options['caption'])) {
             $imageParams['capt'] = true;
         }
         if ($file instanceof File) {
             $size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
             $thumb = $file->transform($size);
             $imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
             $imageAttribs['width'] = $size['width'];
             $imageAttribs['height'] = $size['height'];
         }
         $data = array('attributes' => $imageAttribs, 'parameters' => array($imageParams), 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg);
         if ($file instanceof File) {
             $title = $file->getTitle()->getDBKey();
             $titleText = $file->getTitle()->getText();
             $data['content'] = Xml::element('span', array('class' => 'videoInfo'), "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . $this->wf->MsgForContent('wikiamobile-video-views-counter', MediaQueryService::getTotalVideoViewsByTitle($title)) . ')');
         }
         $html = $this->app->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
     }
     $this->wf->profileOut(__METHOD__);
     return true;
 }