@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Show image dimensions and some other metadata in Differential

Summary: Fixes T2101. When viewing an image change, show image dimensions, MIME type, and filesize.

Test Plan:
{F190189}

{F190190}

very utility

such wow

Reviewers: mailson, btrahan, chad

Reviewed By: chad

Subscribers: epriestley, Korvin, aran

Maniphest Tasks: T2101

Differential Revision: https://secure.phabricator.com/D5206

+95 -23
+3 -16
src/applications/differential/parser/DifferentialChangesetParser.php
··· 690 690 return false; 691 691 } 692 692 693 - $old = $changeset->getOldProperties(); 694 - $new = $changeset->getNewProperties(); 695 - 696 - if ($old === $new) { 697 - return false; 698 - } 699 - 700 - if ($changeset->getChangeType() == DifferentialChangeType::TYPE_ADD && 701 - $new == array('unix:filemode' => '100644')) { 702 - return false; 703 - } 704 - 705 - if ($changeset->getChangeType() == DifferentialChangeType::TYPE_DELETE && 706 - $old == array('unix:filemode' => '100644')) { 707 - return false; 708 - } 709 693 return true; 710 694 } 711 695 ··· 926 910 } 927 911 } 928 912 } 913 + 914 + $renderer->attachOldFile($old); 915 + $renderer->attachNewFile($new); 929 916 930 917 return $renderer->renderFileChange($old, $new, $id, $vs); 931 918 case DifferentialChangeType::FILE_DIRECTORY:
+15 -3
src/applications/differential/render/DifferentialChangesetHTMLRenderer.php
··· 289 289 290 290 protected function renderPropertyChangeHeader() { 291 291 $changeset = $this->getChangeset(); 292 + list($old, $new) = $this->getChangesetProperties($changeset); 292 293 293 - $old = $changeset->getOldProperties(); 294 - $new = $changeset->getNewProperties(); 294 + // If we don't have any property changes, don't render this table. 295 + if ($old === $new) { 296 + return null; 297 + } 295 298 296 299 $keys = array_keys($old + $new); 297 300 sort($keys); 298 301 302 + $key_map = array( 303 + 'unix:filemode' => pht('File Mode'), 304 + 'file:dimensions' => pht('Image Dimensions'), 305 + 'file:mimetype' => pht('MIME Type'), 306 + 'file:size' => pht('File Size'), 307 + ); 308 + 299 309 $rows = array(); 300 310 foreach ($keys as $key) { 301 311 $oval = idx($old, $key); ··· 313 323 $nval = phutil_escape_html_newlines($nval); 314 324 } 315 325 326 + $readable_key = idx($key_map, $key, $key); 327 + 316 328 $rows[] = phutil_tag('tr', array(), array( 317 - phutil_tag('th', array(), $key), 329 + phutil_tag('th', array(), $readable_key), 318 330 phutil_tag('td', array('class' => 'oval'), $oval), 319 331 phutil_tag('td', array('class' => 'nval'), $nval), 320 332 ));
+74
src/applications/differential/render/DifferentialChangesetRenderer.php
··· 30 30 private $depths; 31 31 private $originalCharacterEncoding; 32 32 33 + private $oldFile = false; 34 + private $newFile = false; 35 + 33 36 public function setOriginalCharacterEncoding($original_character_encoding) { 34 37 $this->originalCharacterEncoding = $original_character_encoding; 35 38 return $this; ··· 61 64 } 62 65 protected function getGaps() { 63 66 return $this->gaps; 67 + } 68 + 69 + public function attachOldFile(PhabricatorFile $old = null) { 70 + $this->oldFile = $old; 71 + return $this; 72 + } 73 + 74 + public function getOldFile() { 75 + if ($this->oldFile === false) { 76 + throw new PhabricatorDataNotAttachedException($this); 77 + } 78 + return $this->oldFile; 79 + } 80 + 81 + public function hasOldFile() { 82 + return (bool)$this->oldFile; 83 + } 84 + 85 + public function attachNewFile(PhabricatorFile $new = null) { 86 + $this->newFile = $new; 87 + return $this; 88 + } 89 + 90 + public function getNewFile() { 91 + if ($this->newFile === false) { 92 + throw new PhabricatorDataNotAttachedException($this); 93 + } 94 + return $this->newFile; 95 + } 96 + 97 + public function hasNewFile() { 98 + return (bool)$this->newFile; 64 99 } 65 100 66 101 public function setOriginalNew($original_new) { ··· 496 531 $out = array_mergev($out); 497 532 498 533 return $out; 534 + } 535 + 536 + protected function getChangesetProperties($changeset) { 537 + $old = $changeset->getOldProperties(); 538 + $new = $changeset->getNewProperties(); 539 + 540 + // When adding files, don't show the uninteresting 644 filemode change. 541 + if ($changeset->getChangeType() == DifferentialChangeType::TYPE_ADD && 542 + $new == array('unix:filemode' => '100644')) { 543 + unset($new['unix:filemode']); 544 + } 545 + 546 + // Likewise when removing files. 547 + if ($changeset->getChangeType() == DifferentialChangeType::TYPE_DELETE && 548 + $old == array('unix:filemode' => '100644')) { 549 + unset($old['unix:filemode']); 550 + } 551 + 552 + if ($this->hasOldFile()) { 553 + $file = $this->getOldFile(); 554 + if ($file->getImageWidth()) { 555 + $dimensions = $file->getImageWidth().'x'.$file->getImageHeight(); 556 + $old['file:dimensions'] = $dimensions; 557 + } 558 + $old['file:mimetype'] = $file->getMimeType(); 559 + $old['file:size'] = phutil_format_bytes($file->getByteSize()); 560 + } 561 + 562 + if ($this->hasNewFile()) { 563 + $file = $this->getNewFile(); 564 + if ($file->getImageWidth()) { 565 + $dimensions = $file->getImageWidth().'x'.$file->getImageHeight(); 566 + $new['file:dimensions'] = $dimensions; 567 + } 568 + $new['file:mimetype'] = $file->getMimeType(); 569 + $new['file:size'] = phutil_format_bytes($file->getByteSize()); 570 + } 571 + 572 + return array($old, $new); 499 573 } 500 574 501 575 }
+1 -2
src/applications/differential/render/DifferentialChangesetTestRenderer.php
··· 23 23 24 24 protected function renderPropertyChangeHeader() { 25 25 $changeset = $this->getChangeset(); 26 - $old = $changeset->getOldProperties(); 27 - $new = $changeset->getNewProperties(); 26 + list($old, $new) = $this->getChangesetProperties($changeset); 28 27 29 28 if (!$old && !$new) { 30 29 return null;
+2 -2
src/infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php
··· 2 2 3 3 final class PhabricatorDataNotAttachedException extends Exception { 4 4 5 - public function __construct(PhabricatorLiskDAO $dao) { 5 + public function __construct($object) { 6 6 $stack = debug_backtrace(); 7 7 8 8 // Shift off `PhabricatorDataNotAttachedException::__construct()`. ··· 19 19 } 20 20 } 21 21 22 - $class = get_class($dao); 22 + $class = get_class($object); 23 23 24 24 $message = 25 25 "Attempting to access attached data on {$class}{$via}, but the data is ".