1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

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
This commit is contained in:
Edward Speyer 2013-02-06 21:43:14 +00:00
parent 361ce491f2
commit fb7d5d17a2

View file

@ -50,37 +50,41 @@ final class PhabricatorRemarkupRuleEmbedFile
$file_name = coalesce($options['name'], $file->getName()); $file_name = coalesce($options['name'], $file->getName());
$options['name'] = $file_name; $options['name'] = $file_name;
$is_viewable_image = $file->isViewableImage();
$attrs = array(); $attrs = array();
switch ((string)$options['size']) { if ($is_viewable_image) {
case 'full': switch ((string)$options['size']) {
$attrs['src'] = $file->getBestURI(); case 'full':
$options['image_class'] = null; $attrs['src'] = $file->getBestURI();
$file_data = $file->getMetadata(); $options['image_class'] = null;
$height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT); $file_data = $file->getMetadata();
if ($height) { $height = idx($file_data, PhabricatorFile::METADATA_IMAGE_HEIGHT);
$attrs['height'] = $height; if ($height) {
} $attrs['height'] = $height;
$width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH); }
if ($width) { $width = idx($file_data, PhabricatorFile::METADATA_IMAGE_WIDTH);
$attrs['width'] = $width; if ($width) {
} $attrs['width'] = $width;
break; }
case 'thumb': break;
default: case 'thumb':
$attrs['src'] = $file->getPreview220URI(); default:
$dimensions = $attrs['src'] = $file->getPreview220URI();
PhabricatorImageTransformer::getPreviewDimensions($file, 220); $dimensions =
$attrs['width'] = $dimensions['sdx']; PhabricatorImageTransformer::getPreviewDimensions($file, 220);
$attrs['height'] = $dimensions['sdy']; $attrs['width'] = $dimensions['sdx'];
$options['image_class'] = 'phabricator-remarkup-embed-image'; $attrs['height'] = $dimensions['sdy'];
break; $options['image_class'] = 'phabricator-remarkup-embed-image';
break;
}
} }
$bundle['attrs'] = $attrs; $bundle['attrs'] = $attrs;
$bundle['options'] = $options; $bundle['options'] = $options;
$bundle['meta'] = array( $bundle['meta'] = array(
'phid' => $file->getPHID(), 'phid' => $file->getPHID(),
'viewable' => $file->isViewableImage(), 'viewable' => $is_viewable_image,
'uri' => $file->getBestURI(), 'uri' => $file->getBestURI(),
'dUri' => $file->getDownloadURI(), 'dUri' => $file->getDownloadURI(),
'name' => $options['name'], 'name' => $options['name'],