From fb7d5d17a2bec5ba1815cb69c908bac33f831cc2 Mon Sep 17 00:00:00 2001 From: Edward Speyer Date: Wed, 6 Feb 2013 21:43:14 +0000 Subject: [PATCH] Don't do image stuff with unviewable images Summary: If a file isn't a viewable image, don't try to figure out metadata (size, etc.) when rendering a `{F...}` tag in Remarkup. Test Plan: Uploaded a .rtf, added it as `{F1}` in a new Maniphest task, saw no errors in the dark console. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2479 Differential Revision: https://secure.phabricator.com/D4837 --- .../rule/PhabricatorRemarkupRuleEmbedFile.php | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php index 31ec888b21..45df8b9c8b 100644 --- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php +++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleEmbedFile.php @@ -50,37 +50,41 @@ final class PhabricatorRemarkupRuleEmbedFile $file_name = coalesce($options['name'], $file->getName()); $options['name'] = $file_name; + $is_viewable_image = $file->isViewableImage(); + $attrs = array(); - switch ((string)$options['size']) { - case 'full': - $attrs['src'] = $file->getBestURI(); - $options['image_class'] = null; - $file_data = $file->getMetadata(); - $height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT); - if ($height) { - $attrs['height'] = $height; - } - $width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH); - if ($width) { - $attrs['width'] = $width; - } - break; - case 'thumb': - default: - $attrs['src'] = $file->getPreview220URI(); - $dimensions = - PhabricatorImageTransformer::getPreviewDimensions($file, 220); - $attrs['width'] = $dimensions['sdx']; - $attrs['height'] = $dimensions['sdy']; - $options['image_class'] = 'phabricator-remarkup-embed-image'; - break; + if ($is_viewable_image) { + switch ((string)$options['size']) { + case 'full': + $attrs['src'] = $file->getBestURI(); + $options['image_class'] = null; + $file_data = $file->getMetadata(); + $height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT); + if ($height) { + $attrs['height'] = $height; + } + $width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH); + if ($width) { + $attrs['width'] = $width; + } + break; + case 'thumb': + default: + $attrs['src'] = $file->getPreview220URI(); + $dimensions = + PhabricatorImageTransformer::getPreviewDimensions($file, 220); + $attrs['width'] = $dimensions['sdx']; + $attrs['height'] = $dimensions['sdy']; + $options['image_class'] = 'phabricator-remarkup-embed-image'; + break; + } } $bundle['attrs'] = $attrs; $bundle['options'] = $options; $bundle['meta'] = array( 'phid' => $file->getPHID(), - 'viewable' => $file->isViewableImage(), + 'viewable' => $is_viewable_image, 'uri' => $file->getBestURI(), 'dUri' => $file->getDownloadURI(), 'name' => $options['name'],