3 final class PhabricatorImageDocumentEngine
4 extends PhabricatorDocumentEngine
{
6 const ENGINEKEY
= 'image';
8 public function getViewAsLabel(PhabricatorDocumentRef
$ref) {
9 return pht('View as Image');
12 protected function getDocumentIconIcon(PhabricatorDocumentRef
$ref) {
13 return 'fa-file-image-o';
16 protected function getByteLengthLimit() {
17 return (1024 * 1024 * 64);
20 public function canDiffDocuments(
21 PhabricatorDocumentRef
$uref = null,
22 PhabricatorDocumentRef
$vref = null) {
24 // For now, we can only render a rich image diff if the documents have
25 // their data stored in Files already.
27 if ($uref && !$uref->getFile()) {
31 if ($vref && !$vref->getFile()) {
38 public function newEngineBlocks(
39 PhabricatorDocumentRef
$uref = null,
40 PhabricatorDocumentRef
$vref = null) {
43 $u_blocks = $this->newDiffBlocks($uref);
49 $v_blocks = $this->newDiffBlocks($vref);
54 return id(new PhabricatorDocumentEngineBlocks())
55 ->addBlockList($uref, $u_blocks)
56 ->addBlockList($vref, $v_blocks);
59 public function newBlockDiffViews(
60 PhabricatorDocumentRef
$uref,
61 PhabricatorDocumentEngineBlock
$ublock,
62 PhabricatorDocumentRef
$vref,
63 PhabricatorDocumentEngineBlock
$vblock) {
65 $u_content = $this->newBlockContentView($uref, $ublock);
66 $v_content = $this->newBlockContentView($vref, $vblock);
68 return id(new PhabricatorDocumentEngineBlockDiff())
69 ->setOldContent($u_content)
70 ->addOldClass('diff-image-cell')
71 ->setNewContent($v_content)
72 ->addNewClass('diff-image-cell');
76 private function newDiffBlocks(PhabricatorDocumentRef
$ref) {
79 $file = $ref->getFile();
81 $image_view = phutil_tag(
84 'class' => 'differential-image-stage',
89 'alt' => $file->getAltText(),
90 'src' => $file->getBestURI(),
93 $hash = $file->getContentHash();
95 $blocks[] = id(new PhabricatorDocumentEngineBlock())
97 ->setDifferenceHash($hash)
98 ->setContent($image_view);
103 protected function canRenderDocumentType(PhabricatorDocumentRef
$ref) {
104 $file = $ref->getFile();
106 return $file->isViewableImage();
109 $viewable_types = PhabricatorEnv
::getEnvConfig('files.viewable-mime-types');
110 $viewable_types = array_keys($viewable_types);
112 $image_types = PhabricatorEnv
::getEnvConfig('files.image-mime-types');
113 $image_types = array_keys($image_types);
116 $ref->hasAnyMimeType($viewable_types) &&
117 $ref->hasAnyMimeType($image_types);
120 protected function newDocumentContent(PhabricatorDocumentRef
$ref) {
121 $file = $ref->getFile();
123 $source_uri = $file->getViewURI();
125 // We could use a "data:" URI here. It's not yet clear if or when we'll
126 // have a ref but no backing file.
127 throw new PhutilMethodNotImplementedException();
133 'alt' => $file->getAltText(),
134 'src' => $source_uri,
137 $linked_image = phutil_tag(
140 'href' => $source_uri,
141 'rel' => 'noreferrer',
145 $container = phutil_tag(
148 'class' => 'document-engine-image',