/** * Constructs HTML for the tutorial (laboriously), including an imagemap for the clickable "Help desk" button. * * @param MediaTransformOutput $thumb * @param String|null $campaign Upload Wizard campaign for which the tutorial should be displayed. * * @return String HTML representing the image, with clickable helpdesk button */ public static function getImageHtml(MediaTransformOutput $thumb, $campaign = null) { $helpDeskUrl = wfMessage('mwe-upwiz-help-desk-url')->text(); // Per convention, we may be either using an absolute URL or a wiki page title in this UI message if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $helpDeskUrl)) { $helpDeskHref = $helpDeskUrl; } else { $helpDeskTitle = Title::newFromText($helpDeskUrl); $helpDeskHref = $helpDeskTitle ? $helpDeskTitle->getLocalURL() : '#'; } $buttonCoords = UploadWizardConfig::getSetting('tutorialHelpdeskCoords', $campaign); $useMap = $buttonCoords !== false && trim($buttonCoords) != ''; $imgAttributes = array('src' => $thumb->getUrl(), 'width' => $thumb->getWidth(), 'height' => $thumb->getHeight()); if ($useMap) { $imgAttributes['usemap'] = '#' . self::IMAGEMAP_ID; } // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image. // we could do more special effects with hovers and images and such, not to mention SVG scripting, // but we aren't sure what we want yet... $imgHtml = Html::element('img', $imgAttributes); if ($useMap) { $areaAltText = wfMessage('mwe-upwiz-help-desk')->text(); $area = Html::element('area', array('shape' => 'rect', 'coords' => $buttonCoords, 'href' => $helpDeskHref, 'alt' => $areaAltText, 'title' => $areaAltText)); $imgHtml = Html::rawElement('map', array('id' => self::IMAGEMAP_ID, 'name' => self::IMAGEMAP_ID), $area) . $imgHtml; } return $imgHtml; }
/** * Process responsive images: add 1.5x and 2x subimages to the thumbnail, where * applicable. * * @param File $file * @param MediaTransformOutput $thumb * @param array $hp Image parameters */ public static function processResponsiveImages($file, $thumb, $hp) { global $wgResponsiveImages; if ($wgResponsiveImages && $thumb && !$thumb->isError()) { $hp15 = $hp; $hp15['width'] = round($hp['width'] * 1.5); $hp20 = $hp; $hp20['width'] = $hp['width'] * 2; if (isset($hp['height'])) { $hp15['height'] = round($hp['height'] * 1.5); $hp20['height'] = $hp['height'] * 2; } $thumb15 = $file->transform($hp15); $thumb20 = $file->transform($hp20); if ($thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl()) { $thumb->responsiveUrls['1.5'] = $thumb15->getUrl(); } if ($thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl()) { $thumb->responsiveUrls['2'] = $thumb20->getUrl(); } } }
/** * @param Array $videoArr * @param MediaTransformOutput $videoThumbObj * * @return stdClass */ protected function extractDataForCaruselTemplate($videoArr, $videoThumbObj) { /** @var File $videoFile */ $videoFile = $videoThumbObj->getFile(); /** @var Title $videoTitle */ $videoTitle = $videoFile->getTitle(); $wikiUrl = WikiFactory::getVarValueByName('wgServer', $videoArr['wikiId']); $videoItem = new stdClass(); $videoItem->duration = $videoFile->getHandler()->getFormattedDuration(); $videoItem->data = array('wiki' => $wikiUrl, 'video-name' => $videoArr['title'], 'ref' => $videoTitle->getNsText() . ':' . $videoTitle->getDBkey()); $videoItem->href = $videoTitle->getFullUrl(); $videoItem->imgUrl = $videoThumbObj->getUrl(); $videoItem->description = $videoArr['headline']; if (empty($videoArr['profile'])) { $videoItem->info = wfMsgExt('wikiahubs-popular-videos-suggested-by', array('parseinline'), array($videoArr['submitter'])); } else { $videoItem->info = wfMsgExt('wikiahubs-popular-videos-suggested-by-profile', array('parseinline'), array($videoArr['submitter'], $videoArr['profile'])); } return $videoItem; }
/** * @param MediaTransformOutput|bool $thumb the thumbnail, or false if no * thumb (which can happen) * @return float */ protected function getGBWidth($thumb) { $thumbWidth = $thumb ? $thumb->getWidth() : $this->mWidths * self::SCALE_FACTOR; return $this->getThumbDivWidth($thumbWidth) + $this->getGBPadding(); }
/** * 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; }