/**
  * Return a HTML representation of the image slideshow
  */
 private function renderSlideshow()
 {
     global $wgStylePath;
     wfProfileIn(__METHOD__);
     // don't render empty slideshows
     if (empty($this->mFiles)) {
         wfProfileOut(__METHOD__);
         return '';
     }
     // If we can, render this as a media gallery
     if ($this->canRenderMediaGallery()) {
         $html = $this->renderMediaGallery();
         wfProfileOut(__METHOD__);
         return trim(preg_replace('/\\n+/', ' ', $html));
     }
     /** @var Skin|Linker $sk The Skin object falls back to Linker methods */
     $sk = RequestContext::getMain()->getSkin();
     // slideshow wrapper CSS class
     $class = 'wikia-slideshow clearfix';
     $id = "slideshow-{$this->mData['id']}";
     // do not add button for galleries from templates
     if (isset($this->mData['params']['source']) && $this->mData['params']['source'] == "template") {
         $class .= ' template';
     }
     // support "position" attribute (slideshow alignment)
     switch ($this->getParam('position')) {
         case 'left':
             $class .= ' floatleft';
             break;
         case 'center':
             $class .= ' slideshow-center';
             break;
         case 'right':
             $class .= ' floatright';
             break;
     }
     // wrap image slideshow inside div.slideshow
     $attribs = Sanitizer::mergeAttributes(array('class' => $class, 'data-hash' => $this->mData['hash'], 'data-crop' => $this->mCrop, 'id' => $id), $this->mAttribs);
     //renderSlideshow for WikiaMobile
     if (F::app()->checkSkin('wikiamobile')) {
         $slideshowHtml = $this->renderWikiaMobileMediaGroup();
     } else {
         $slideshowHtml = Xml::openElement('div', $attribs);
         // render slideshow caption
         if ($this->mCaption) {
             $slideshowHtml .= '<div class="wikia-slideshow-caption">' . $this->mCaption . '</div>';
         }
         // fit images inside width:height = 4:3 box
         $this->mHeights = round($this->mWidths * 3 / 4);
         $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
         wfDebug(__METHOD__ . ": slideshow {$params['width']}x{$params['height']}\n");
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-wrapper', 'style' => 'width: ' . ($this->mWidths + 10) . 'px'));
         // wrap images inside <div> and <ul>
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-images-wrapper accent'));
         $slideshowHtml .= Xml::openElement('ul', array('class' => 'wikia-slideshow-images neutral', 'style' => "height: {$params['height']}px; width: {$params['width']}px"));
         $index = 0;
         foreach ($this->mFiles as $p => $pair) {
             /**
              * @var $nt Title
              */
             $nt = $pair[0];
             $text = $pair[1];
             $link = $pair[2];
             # Give extensions a chance to select the file revision for us
             $time = $descQuery = false;
             wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery));
             $img = wfFindFile($nt, $time);
             if (WikiaFileHelper::isFileTypeVideo($img)) {
                 continue;
             }
             $thumb = null;
             // let's properly scale image (don't make it bigger than original size) and handle "crop" attribute
             if (is_object($img) && $nt->getNamespace() == NS_FILE) {
                 $thumbParams = WikiaPhotoGalleryHelper::getThumbnailDimensions($img, $params['width'], $params['height'], $this->mCrop);
             }
             $caption = $linkOverlay = '';
             // render caption overlay
             if ($text != '') {
                 $caption = Xml::openElement('span', array('class' => 'wikia-slideshow-image-caption')) . Xml::openElement('span', array('class' => 'wikia-slideshow-image-caption-inner')) . $text . Xml::closeElement('span') . Xml::closeElement('span');
             }
             // parse link
             $linkAttribs = $this->parseLink($nt->getLocalUrl(), $nt->getText(), $link);
             // extra link tag attributes
             $linkAttribs['id'] = "{$id}-{$index}";
             $linkAttribs['style'] = 'width: ' . ($params['width'] - 80) . 'px';
             if ($link == '') {
                 // tooltip to be used for not-linked images
                 $linkAttribs['title'] = wfMessage('wikiaPhotoGallery-slideshow-view-popout-tooltip')->text();
                 $linkAttribs['class'] = 'wikia-slideshow-image';
                 unset($linkAttribs['href']);
             } else {
                 // linked images
                 $linkAttribs['class'] .= ' wikia-slideshow-image';
                 // support |linktext= syntax
                 if ($this->mData['images'][$p]['linktext'] != '') {
                     $linkText = $this->mData['images'][$p]['linktext'];
                 } else {
                     $linkText = $link;
                 }
                 // add link overlay
                 $linkOverlay = Xml::openElement('span', array('class' => 'wikia-slideshow-link-overlay')) . wfMessage('wikiaPhotoGallery-slideshow-view-link-overlay', Sanitizer::removeHTMLtags($linkText))->text() . Xml::closeElement('span');
             }
             // generate HTML for a single slideshow image
             $thumbHtml = null;
             $liAttribs = array('title' => null);
             if ($nt->getNamespace() != NS_FILE || !$img) {
                 # We're dealing with a non-image, spit out the name and be done with it.
                 $thumbHtml = '<a class="image broken-image new" style="line-height: ' . $this->mHeights . 'px;">' . $nt->getText() . '</a>';
             } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
                 # The image is blacklisted, just show it as a text link.
                 $thumbHtml = '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . $sk->makeKnownLinkObj($nt, $nt->getText()) . '</div>';
             } elseif (!($thumb = $img->transform($thumbParams))) {
                 # Error generating thumbnail.
                 $thumbHtml = '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
             } else {
                 $thumbAttribs = array('data-src' => $thumb->url, 'class' => 'thumbimage', 'width' => $thumb->width, 'height' => $thumb->height, 'style' => 'border: 0px;', 'data-image-name' => $img->getTitle()->getText(), 'data-image-key' => $img->getTitle()->getDBKey());
                 if (!empty($this->mData['images'][$p]['data-caption'])) {
                     $thumbAttribs['data-caption'] = $this->mData['images'][$p]['data-caption'];
                 }
                 $thumbHtml = Xml::element('img', $thumbAttribs);
             }
             // add CSS class so we can show first slideshow image before JS is loaded
             if ($index == 0) {
                 $liAttribs['class'] = 'wikia-slideshow-first-image';
             }
             $slideshowHtml .= Xml::openElement('li', $liAttribs) . $thumbHtml . Xml::element('a', $linkAttribs, ' ') . $caption . $linkOverlay . '</li>';
             $index++;
             // Call parser transform hook
             if ($this->mParser && is_object($img) && $img->getHandler()) {
                 $img->getHandler()->parserTransformHook($this->mParser, $img);
             }
             if (is_object($thumb)) {
                 wfDebug(__METHOD__ . ": image '" . $nt->getText() . "' {$thumb->width}x{$thumb->height}\n");
             }
         }
         $slideshowHtml .= Xml::closeElement('ul');
         $slideshowHtml .= Xml::closeElement('div');
         // render prev/next buttons
         global $wgBlankImgUrl;
         $top = ($params['height'] >> 1) - 30 + 5;
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-prev-next'));
         // prev
         $slideshowHtml .= Xml::openElement('a', array('class' => 'wikia-slideshow-sprite wikia-slideshow-prev', 'style' => "top: {$top}px", 'title' => wfMessage('wikiaPhotoGallery-slideshow-view-prev-tooltip')->text()));
         $slideshowHtml .= Xml::openElement('span');
         $slideshowHtml .= Xml::element('img', array('class' => 'chevron', 'src' => $wgBlankImgUrl));
         $slideshowHtml .= Xml::closeElement('span');
         $slideshowHtml .= Xml::closeElement('a');
         // next
         $slideshowHtml .= Xml::openElement('a', array('class' => 'wikia-slideshow-sprite wikia-slideshow-next', 'style' => "top: {$top}px", 'title' => wfMessage('wikiaPhotoGallery-slideshow-view-next-tooltip')->text()));
         $slideshowHtml .= Xml::openElement('span');
         $slideshowHtml .= Xml::element('img', array('class' => 'chevron', 'src' => $wgBlankImgUrl));
         $slideshowHtml .= Xml::closeElement('span');
         $slideshowHtml .= Xml::closeElement('a');
         $slideshowHtml .= Xml::closeElement('div');
         // render slideshow toolbar
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-toolbar clearfix', 'style' => 'display: none'));
         // Pop-out icon, "X of X" counter
         $counterValue = wfMessage('wikiaPhotoGallery-slideshow-view-number', '$1', $index)->text();
         $slideshowHtml .= Xml::openElement('div', array('style' => 'float: left'));
         $slideshowHtml .= Xml::element('img', array('class' => 'wikia-slideshow-popout lightbox', 'height' => 11, 'src' => "{$wgStylePath}/common/images/magnify-clip.png", 'title' => wfMessage('wikiaPhotoGallery-slideshow-view-popout-tooltip')->text(), 'width' => 15));
         $slideshowHtml .= Xml::element('span', array('class' => 'wikia-slideshow-toolbar-counter', 'data-counter' => $counterValue), str_replace('$1', '1', $counterValue));
         $slideshowHtml .= Xml::closeElement('div');
         // "Add Image"
         if (!empty($this->mShowAddButton)) {
             $slideshowHtml .= Xml::element('a', array('class' => 'wikia-slideshow-addimage wikia-button secondary', 'style' => 'float: right'), wfMessage('wikiaPhotoGallery-slideshow-view-addphoto')->inContentLanguage()->text());
         }
         $slideshowHtml .= Xml::closeElement('div');
         // close slideshow wrapper
         $slideshowHtml .= Xml::closeElement('div');
         $slideshowHtml .= Xml::closeElement('div');
         // output JS to init slideshow
         $width = "{$params['width']}px";
         $height = "{$params['height']}px";
         $slideshowHtml .= JSSnippets::addToStack(array('wikia_photo_gallery_slideshow_js', 'wikia_photo_gallery_slideshow_scss'), array(), 'WikiaPhotoGallerySlideshow.init', array('id' => $id, 'width' => $width, 'height' => $height));
     }
     wfProfileOut(__METHOD__);
     return $slideshowHtml;
 }