Example #1
0
File: Linker.php Project: paladox/2
 /**
  * @param Title $title
  * @param File $file
  * @param array $frameParams
  * @param array $handlerParams
  * @param bool $time
  * @param string $query
  * @return string
  */
 public static function makeThumbLink2(Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "")
 {
     $exists = $file && $file->exists();
     # Shortcuts
     $fp =& $frameParams;
     $hp =& $handlerParams;
     $page = isset($hp['page']) ? $hp['page'] : false;
     if (!isset($fp['align'])) {
         $fp['align'] = 'right';
     }
     if (!isset($fp['alt'])) {
         $fp['alt'] = '';
     }
     if (!isset($fp['title'])) {
         $fp['title'] = '';
     }
     if (!isset($fp['caption'])) {
         $fp['caption'] = '';
     }
     if (empty($hp['width'])) {
         // Reduce width for upright images when parameter 'upright' is used
         $hp['width'] = isset($fp['upright']) ? 130 : 180;
     }
     $thumb = false;
     $noscale = false;
     $manualthumb = false;
     if (!$exists) {
         $outerWidth = $hp['width'] + 2;
     } else {
         if (isset($fp['manualthumb'])) {
             # Use manually specified thumbnail
             $manual_title = Title::makeTitleSafe(NS_FILE, $fp['manualthumb']);
             if ($manual_title) {
                 $manual_img = wfFindFile($manual_title);
                 if ($manual_img) {
                     $thumb = $manual_img->getUnscaledThumb($hp);
                     $manualthumb = true;
                 } else {
                     $exists = false;
                 }
             }
         } elseif (isset($fp['framed'])) {
             // Use image dimensions, don't scale
             $thumb = $file->getUnscaledThumb($hp);
             $noscale = true;
         } else {
             # Do not present an image bigger than the source, for bitmap-style images
             # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
             $srcWidth = $file->getWidth($page);
             if ($srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth) {
                 $hp['width'] = $srcWidth;
             }
             $thumb = $file->transform($hp);
         }
         if ($thumb) {
             $outerWidth = $thumb->getWidth() + 2;
         } else {
             $outerWidth = $hp['width'] + 2;
         }
     }
     # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
     # So we don't need to pass it here in $query. However, the URL for the
     # zoom icon still needs it, so we make a unique query for it. See bug 14771
     $url = $title->getLocalURL($query);
     if ($page) {
         $url = wfAppendQuery($url, array('page' => $page));
     }
     if ($manualthumb && !isset($fp['link-title']) && !isset($fp['link-url']) && !isset($fp['no-link'])) {
         $fp['link-url'] = $url;
     }
     $s = "<div class=\"thumb t{$fp['align']}\">" . "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
     if (!$exists) {
         $s .= self::makeBrokenImageLinkObj($title, $fp['title'], '', '', '', $time == true);
         $zoomIcon = '';
     } elseif (!$thumb) {
         $s .= wfMessage('thumbnail_error', '')->escaped();
         $zoomIcon = '';
     } else {
         if (!$noscale && !$manualthumb) {
             self::processResponsiveImages($file, $thumb, $hp);
         }
         $params = array('alt' => $fp['alt'], 'title' => $fp['title'], 'img-class' => (isset($fp['class']) && $fp['class'] !== '' ? $fp['class'] . ' ' : '') . 'thumbimage');
         $params = self::getImageLinkMTOParams($fp, $query) + $params;
         $s .= $thumb->toHtml($params);
         if (isset($fp['framed'])) {
             $zoomIcon = "";
         } else {
             $zoomIcon = Html::rawElement('div', array('class' => 'magnify'), Html::rawElement('a', array('href' => $url, 'class' => 'internal', 'title' => wfMessage('thumbnail-more')->text()), ""));
         }
     }
     $s .= '  <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
     return str_replace("\n", ' ', $s);
 }