diff --git a/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php b/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php index 7e21fd2054..3bb11ae242 100644 --- a/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php +++ b/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php @@ -1,578 +1,591 @@ getChangeset(); $change = $changeset->getChangeType(); $file = $changeset->getFileType(); $messages = array(); switch ($change) { case DifferentialChangeType::TYPE_ADD: switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht('This file was added.'); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This image was added.'); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This directory was added.'); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This binary file was added.'); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This symlink was added.'); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This submodule was added.'); break; } break; case DifferentialChangeType::TYPE_DELETE: switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht('This file was deleted.'); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This image was deleted.'); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This directory was deleted.'); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This binary file was deleted.'); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This symlink was deleted.'); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This submodule was deleted.'); break; } break; case DifferentialChangeType::TYPE_MOVE_HERE: $from = phutil_tag('strong', array(), $changeset->getOldFile()); switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht('This file was moved from %s.', $from); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This image was moved from %s.', $from); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This directory was moved from %s.', $from); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This binary file was moved from %s.', $from); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This symlink was moved from %s.', $from); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This submodule was moved from %s.', $from); break; } break; case DifferentialChangeType::TYPE_COPY_HERE: $from = phutil_tag('strong', array(), $changeset->getOldFile()); switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht('This file was copied from %s.', $from); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This image was copied from %s.', $from); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This directory was copied from %s.', $from); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This binary file was copied from %s.', $from); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This symlink was copied from %s.', $from); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This submodule was copied from %s.', $from); break; } break; case DifferentialChangeType::TYPE_MOVE_AWAY: $paths = phutil_tag( 'strong', array(), implode(', ', $changeset->getAwayPaths())); switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht('This file was moved to %s.', $paths); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This image was moved to %s.', $paths); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This directory was moved to %s.', $paths); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This binary file was moved to %s.', $paths); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This symlink was moved to %s.', $paths); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This submodule was moved to %s.', $paths); break; } break; case DifferentialChangeType::TYPE_COPY_AWAY: $paths = phutil_tag( 'strong', array(), implode(', ', $changeset->getAwayPaths())); switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht('This file was copied to %s.', $paths); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This image was copied to %s.', $paths); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This directory was copied to %s.', $paths); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This binary file was copied to %s.', $paths); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This symlink was copied to %s.', $paths); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This submodule was copied to %s.', $paths); break; } break; case DifferentialChangeType::TYPE_MULTICOPY: $paths = phutil_tag( 'strong', array(), implode(', ', $changeset->getAwayPaths())); switch ($file) { case DifferentialChangeType::FILE_TEXT: $messages[] = pht( 'This file was deleted after being copied to %s.', $paths); break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht( 'This image was deleted after being copied to %s.', $paths); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht( 'This directory was deleted after being copied to %s.', $paths); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht( 'This binary file was deleted after being copied to %s.', $paths); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht( 'This symlink was deleted after being copied to %s.', $paths); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht( 'This submodule was deleted after being copied to %s.', $paths); break; } break; default: switch ($file) { case DifferentialChangeType::FILE_TEXT: // This is the default case, so we only render this header if // forced to since it's not very useful. if ($force) { $messages[] = pht('This file was not modified.'); } break; case DifferentialChangeType::FILE_IMAGE: $messages[] = pht('This is an image.'); break; case DifferentialChangeType::FILE_DIRECTORY: $messages[] = pht('This is a directory.'); break; case DifferentialChangeType::FILE_BINARY: $messages[] = pht('This is a binary file.'); break; case DifferentialChangeType::FILE_SYMLINK: $messages[] = pht('This is a symlink.'); break; case DifferentialChangeType::FILE_SUBMODULE: $messages[] = pht('This is a submodule.'); break; } break; } // If this is a text file with at least one hunk, we may have converted // the text encoding. In this case, show a note. $show_encoding = ($file == DifferentialChangeType::FILE_TEXT) && ($changeset->getHunks()); if ($show_encoding) { $encoding = $this->getOriginalCharacterEncoding(); if ($encoding != 'utf8') { if ($encoding) { $messages[] = pht( 'This file was converted from %s for display.', phutil_tag('strong', array(), $encoding)); } else { $messages[] = pht( 'This file uses an unknown character encoding.'); } } } if (!$messages) { return null; } foreach ($messages as $key => $message) { $messages[$key] = phutil_tag('li', array(), $message); } return phutil_tag( 'ul', array( 'class' => 'differential-meta-notice', ), $messages); } protected function renderPropertyChangeHeader() { $changeset = $this->getChangeset(); list($old, $new) = $this->getChangesetProperties($changeset); // If we don't have any property changes, don't render this table. if ($old === $new) { return null; } $keys = array_keys($old + $new); sort($keys); $key_map = array( 'unix:filemode' => pht('File Mode'), 'file:dimensions' => pht('Image Dimensions'), 'file:mimetype' => pht('MIME Type'), 'file:size' => pht('File Size'), ); $rows = array(); foreach ($keys as $key) { $oval = idx($old, $key); $nval = idx($new, $key); if ($oval !== $nval) { if ($oval === null) { $oval = phutil_tag('em', array(), 'null'); } else { $oval = phutil_escape_html_newlines($oval); } if ($nval === null) { $nval = phutil_tag('em', array(), 'null'); } else { $nval = phutil_escape_html_newlines($nval); } $readable_key = idx($key_map, $key, $key); $row = array( $readable_key, $oval, $nval, ); $rows[] = $row; } } $classes = array('', 'oval', 'nval'); $headers = array( pht('Property'), pht('Old Value'), pht('New Value'), ); $table = id(new AphrontTableView($rows)) ->setHeaders($headers) ->setColumnClasses($classes); return phutil_tag( 'div', array( 'class' => 'differential-property-table', ), $table); } public function renderShield($message, $force = 'default') { $end = count($this->getOldLines()); $reference = $this->getRenderingReference(); if ($force !== 'text' && $force !== 'whitespace' && $force !== 'none' && $force !== 'default') { throw new Exception("Invalid 'force' parameter '{$force}'!"); } $range = "0-{$end}"; if ($force == 'text') { // If we're forcing text, force the whole file to be rendered. $range = "{$range}/0-{$end}"; } $meta = array( 'ref' => $reference, 'range' => $range, ); if ($force == 'whitespace') { $meta['whitespace'] = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; } $content = array(); $content[] = $message; if ($force !== 'none') { $content[] = ' '; $content[] = javelin_tag( 'a', array( 'mustcapture' => true, 'sigil' => 'show-more', 'class' => 'complete', 'href' => '#', 'meta' => $meta, ), pht('Show File Contents')); } return $this->wrapChangeInTable( javelin_tag( 'tr', array( 'sigil' => 'context-target', ), phutil_tag( 'td', array( 'class' => 'differential-shield', 'colspan' => 6, ), $content))); } abstract protected function renderColgroup(); protected function wrapChangeInTable($content) { if (!$content) { return null; } $classes = array(); $classes[] = 'differential-diff'; $classes[] = 'remarkup-code'; $classes[] = 'PhabricatorMonospaced'; $classes[] = $this->getRendererTableClass(); return javelin_tag( 'table', array( 'class' => implode(' ', $classes), 'sigil' => 'differential-diff', ), array( $this->renderColgroup(), $content, )); } protected function buildInlineComment( PhabricatorInlineCommentInterface $comment, $on_right = false) { $user = $this->getUser(); $edit = $user && ($comment->getAuthorPHID() == $user->getPHID()) && ($comment->isDraft()) && $this->getShowEditAndReplyLinks(); $allow_reply = (bool)$user && $this->getShowEditAndReplyLinks(); return id(new PHUIDiffInlineCommentDetailView()) ->setInlineComment($comment) ->setOnRight($on_right) ->setHandles($this->getHandles()) ->setMarkupEngine($this->getMarkupEngine()) ->setEditable($edit) ->setAllowReply($allow_reply); } /** * Build links which users can click to show more context in a changeset. * * @param int Beginning of the line range to build links for. * @param int Length of the line range to build links for. * @param int Total number of lines in the changeset. * @return markup Rendered links. */ protected function renderShowContextLinks($top, $len, $changeset_length) { $block_size = 20; $end = ($top + $len) - $block_size; // If this is a large block, such that the "top" and "bottom" ranges are // non-overlapping, we'll provide options to show the top, bottom or entire // block. For smaller blocks, we only provide an option to show the entire // block, since it would be silly to show the bottom 20 lines of a 25-line // block. $is_large_block = ($len > ($block_size * 2)); $links = array(); if ($is_large_block) { $is_first_block = ($top == 0); if ($is_first_block) { $text = pht('Show First %d Line(s)', $block_size); } else { $text = pht("\xE2\x96\xB2 Show %d Line(s)", $block_size); } $links[] = $this->renderShowContextLink( false, "{$top}-{$len}/{$top}-20", $text); } $links[] = $this->renderShowContextLink( true, "{$top}-{$len}/{$top}-{$len}", pht('Show All %d Line(s)', $len)); if ($is_large_block) { $is_last_block = (($top + $len) >= $changeset_length); if ($is_last_block) { $text = pht('Show Last %d Line(s)', $block_size); } else { $text = pht("\xE2\x96\xBC Show %d Line(s)", $block_size); } $links[] = $this->renderShowContextLink( false, "{$top}-{$len}/{$end}-20", $text); } return phutil_implode_html(" \xE2\x80\xA2 ", $links); } /** * Build a link that shows more context in a changeset. * * See @{method:renderShowContextLinks}. * * @param bool Does this link show all context when clicked? * @param string Range specification for lines to show. * @param string Text of the link. * @return markup Rendered link. */ private function renderShowContextLink($is_all, $range, $text) { $reference = $this->getRenderingReference(); return javelin_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', 'meta' => array( 'type' => ($is_all ? 'all' : null), 'range' => $range, ), ), $text); } /** * Build the prefixes for line IDs used to track inline comments. * * @return pair Left and right prefixes. */ protected function getLineIDPrefixes() { // These look like "C123NL45", which means the line is line 45 on the // "new" side of the file in changeset 123. // The "C" stands for "changeset", and is followed by a changeset ID. // "N" stands for "new" and means the comment should attach to the new file // when stored. "O" stands for "old" and means the comment should attach to // the old file. These are important because either the old or new part // of a file may appear on the left or right side of the diff in the // diff-of-diffs view. // The "L" stands for "line" and is followed by the line number. if ($this->getOldChangesetID()) { $left_prefix = array(); $left_prefix[] = 'C'; $left_prefix[] = $this->getOldChangesetID(); $left_prefix[] = $this->getOldAttachesToNewFile() ? 'N' : 'O'; $left_prefix[] = 'L'; $left_prefix = implode('', $left_prefix); } else { $left_prefix = null; } if ($this->getNewChangesetID()) { $right_prefix = array(); $right_prefix[] = 'C'; $right_prefix[] = $this->getNewChangesetID(); $right_prefix[] = $this->getNewAttachesToNewFile() ? 'N' : 'O'; $right_prefix[] = 'L'; $right_prefix = implode('', $right_prefix); } else { $right_prefix = null; } return array($left_prefix, $right_prefix); } + protected function renderImageStage(PhabricatorFile $file) { + return phutil_tag( + 'div', + array( + 'class' => 'differential-image-stage', + ), + phutil_tag( + 'img', + array( + 'src' => $file->getBestURI(), + ))); + } + } diff --git a/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php b/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php index 0ca028d42d..2634d037d7 100644 --- a/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php +++ b/src/applications/differential/render/DifferentialChangesetOneUpRenderer.php @@ -1,157 +1,223 @@ 'num')), phutil_tag('col', array('class' => 'num')), phutil_tag('col', array('class' => 'copy')), phutil_tag('col', array('class' => 'unified')), )); } public function renderTextChange( $range_start, $range_len, $rows) { $primitives = $this->buildPrimitives($range_start, $range_len); + return $this->renderPrimitives($primitives, $rows); + } + protected function renderPrimitives(array $primitives, $rows) { list($left_prefix, $right_prefix) = $this->getLineIDPrefixes(); $no_copy = phutil_tag('td', array('class' => 'copy')); $no_coverage = null; $column_width = 4; $out = array(); foreach ($primitives as $p) { $type = $p['type']; switch ($type) { case 'old': case 'new': - $out[] = hsprintf(''); - if ($type == 'old') { + case 'old-file': + case 'new-file': + $is_old = ($type == 'old' || $type == 'old-file'); + + $cells = array(); + if ($is_old) { if ($p['htype']) { $class = 'left old'; } else { $class = 'left'; } + if ($type == 'old-file') { + $class = "{$class} differential-old-image"; + } + if ($left_prefix) { $left_id = $left_prefix.$p['line']; } else { $left_id = null; } - $out[] = phutil_tag('th', array('id' => $left_id), $p['line']); + $cells[] = phutil_tag('th', array('id' => $left_id), $p['line']); - $out[] = phutil_tag('th', array()); - $out[] = $no_copy; - $out[] = phutil_tag('td', array('class' => $class), $p['render']); - $out[] = $no_coverage; + $cells[] = phutil_tag('th', array()); + $cells[] = $no_copy; + $cells[] = phutil_tag('td', array('class' => $class), $p['render']); + $cells[] = $no_coverage; } else { if ($p['htype']) { $class = 'right new'; - $out[] = phutil_tag('th', array()); + $cells[] = phutil_tag('th', array()); } else { $class = 'right'; if ($left_prefix) { $left_id = $left_prefix.$p['oline']; } else { $left_id = null; } - $out[] = phutil_tag('th', array('id' => $left_id), $p['oline']); + $cells[] = phutil_tag('th', array('id' => $left_id), $p['oline']); + } + + if ($type == 'new-file') { + $class = "{$class} differential-new-image"; } if ($right_prefix) { $right_id = $right_prefix.$p['line']; } else { $right_id = null; } - $out[] = phutil_tag('th', array('id' => $right_id), $p['line']); + $cells[] = phutil_tag('th', array('id' => $right_id), $p['line']); - $out[] = $no_copy; - $out[] = phutil_tag('td', array('class' => $class), $p['render']); - $out[] = $no_coverage; + $cells[] = $no_copy; + $cells[] = phutil_tag('td', array('class' => $class), $p['render']); + $cells[] = $no_coverage; } - $out[] = hsprintf(''); + + $out[] = phutil_tag('tr', array(), $cells); + break; case 'inline': $inline = $this->buildInlineComment( $p['comment'], $p['right']); $out[] = $this->getRowScaffoldForInline($inline); break; case 'no-context': $out[] = phutil_tag( 'tr', array(), phutil_tag( 'td', array( 'class' => 'show-more', 'colspan' => $column_width, ), pht('Context not available.'))); break; case 'context': $top = $p['top']; $len = $p['len']; $links = $this->renderShowContextLinks($top, $len, $rows); $out[] = javelin_tag( 'tr', array( 'sigil' => 'context-target', ), phutil_tag( 'td', array( 'class' => 'show-more', 'colspan' => $column_width, ), $links)); break; default: $out[] = hsprintf('%s', $type); break; } } if ($out) { return $this->wrapChangeInTable(phutil_implode_html('', $out)); } + return null; } public function renderFileChange( $old_file = null, $new_file = null, $id = 0, $vs = 0) { - throw new PhutilMethodNotImplementedException(); + // TODO: This should eventually merge into the normal primitives pathway, + // but fake it for now and just share as much code as possible. + + $primitives = array(); + if ($old_file) { + $primitives[] = array( + 'type' => 'old-file', + 'htype' => ($new_file ? 'new-file' : null), + 'file' => $old_file, + 'line' => 1, + 'render' => $this->renderImageStage($old_file), + ); + } + + if ($new_file) { + $primitives[] = array( + 'type' => 'new-file', + 'htype' => ($old_file ? 'old-file' : null), + 'file' => $new_file, + 'line' => 1, + 'oline' => ($old_file ? 1 : null), + 'render' => $this->renderImageStage($old_file), + ); + } + + // TODO: We'd like to share primitive code here, but buildPrimitives() + // currently chokes on changesets with no textual data. + foreach ($this->getOldComments() as $line => $group) { + foreach ($group as $comment) { + $primitives[] = array( + 'type' => 'inline', + 'comment' => $comment, + 'right' => false, + ); + } + } + + foreach ($this->getNewComments() as $line => $group) { + foreach ($group as $comment) { + $primitives[] = array( + 'type' => 'inline', + 'comment' => $comment, + 'right' => true, + ); + } + } + + $output = $this->renderPrimitives($primitives, 1); + return $this->renderChangesetTable($output); } public function getRowScaffoldForInline(PHUIDiffInlineCommentView $view) { return id(new PHUIDiffOneUpInlineCommentRowScaffold()) ->addInlineView($view); } } diff --git a/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php b/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php index 01084087c1..a9eef41ac8 100644 --- a/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php +++ b/src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php @@ -1,390 +1,372 @@ 'num')), phutil_tag('col', array('class' => 'left')), phutil_tag('col', array('class' => 'num')), phutil_tag('col', array('class' => 'copy')), phutil_tag('col', array('class' => 'right')), phutil_tag('col', array('class' => 'cov')), )); } public function renderTextChange( $range_start, $range_len, $rows) { $hunk_starts = $this->getHunkStartLines(); $context_not_available = null; if ($hunk_starts) { $context_not_available = javelin_tag( 'tr', array( 'sigil' => 'context-target', ), phutil_tag( 'td', array( 'colspan' => 6, 'class' => 'show-more', ), pht('Context not available.'))); } $html = array(); $old_lines = $this->getOldLines(); $new_lines = $this->getNewLines(); $gaps = $this->getGaps(); $reference = $this->getRenderingReference(); list($left_prefix, $right_prefix) = $this->getLineIDPrefixes(); $changeset = $this->getChangeset(); $copy_lines = idx($changeset->getMetadata(), 'copy:lines', array()); $highlight_old = $this->getHighlightOld(); $highlight_new = $this->getHighlightNew(); $old_render = $this->getOldRender(); $new_render = $this->getNewRender(); $original_left = $this->getOriginalOld(); $original_right = $this->getOriginalNew(); $depths = $this->getDepths(); $mask = $this->getMask(); for ($ii = $range_start; $ii < $range_start + $range_len; $ii++) { if (empty($mask[$ii])) { // If we aren't going to show this line, we've just entered a gap. // Pop information about the next gap off the $gaps stack and render // an appropriate "Show more context" element. This branch eventually // increments $ii by the entire size of the gap and then continues // the loop. $gap = array_pop($gaps); $top = $gap[0]; $len = $gap[1]; $contents = $this->renderShowContextLinks($top, $len, $rows); $is_last_block = false; if ($ii + $len >= $rows) { $is_last_block = true; } $context = null; $context_line = null; if (!$is_last_block && $depths[$ii + $len]) { for ($l = $ii + $len - 1; $l >= $ii; $l--) { $line = $new_lines[$l]['text']; if ($depths[$l] < $depths[$ii + $len] && trim($line) != '') { $context = $new_render[$l]; $context_line = $new_lines[$l]['line']; break; } } } $container = javelin_tag( 'tr', array( 'sigil' => 'context-target', ), array( phutil_tag( 'td', array( 'colspan' => 2, 'class' => 'show-more', ), $contents), phutil_tag( 'th', array( 'class' => 'show-context-line', ), $context_line ? (int)$context_line : null), phutil_tag( 'td', array( 'colspan' => 3, 'class' => 'show-context', ), // TODO: [HTML] Escaping model here isn't ideal. phutil_safe_html($context)), )); $html[] = $container; $ii += ($len - 1); continue; } $o_num = null; $o_classes = ''; $o_text = null; if (isset($old_lines[$ii])) { $o_num = $old_lines[$ii]['line']; $o_text = isset($old_render[$ii]) ? $old_render[$ii] : null; if ($old_lines[$ii]['type']) { if ($old_lines[$ii]['type'] == '\\') { $o_text = $old_lines[$ii]['text']; $o_class = 'comment'; } else if ($original_left && !isset($highlight_old[$o_num])) { $o_class = 'old-rebase'; } else if (empty($new_lines[$ii])) { $o_class = 'old old-full'; } else { $o_class = 'old'; } $o_classes = $o_class; } } $n_copy = hsprintf(''); $n_cov = null; $n_colspan = 2; $n_classes = ''; $n_num = null; $n_text = null; if (isset($new_lines[$ii])) { $n_num = $new_lines[$ii]['line']; $n_text = isset($new_render[$ii]) ? $new_render[$ii] : null; $coverage = $this->getCodeCoverage(); if ($coverage !== null) { if (empty($coverage[$n_num - 1])) { $cov_class = 'N'; } else { $cov_class = $coverage[$n_num - 1]; } $cov_class = 'cov-'.$cov_class; $n_cov = phutil_tag('td', array('class' => "cov {$cov_class}")); $n_colspan--; } if ($new_lines[$ii]['type']) { if ($new_lines[$ii]['type'] == '\\') { $n_text = $new_lines[$ii]['text']; $n_class = 'comment'; } else if ($original_right && !isset($highlight_new[$n_num])) { $n_class = 'new-rebase'; } else if (empty($old_lines[$ii])) { $n_class = 'new new-full'; } else { $n_class = 'new'; } $n_classes = $n_class; if ($new_lines[$ii]['type'] == '\\' || !isset($copy_lines[$n_num])) { $n_copy = phutil_tag('td', array('class' => "copy {$n_class}")); } else { list($orig_file, $orig_line, $orig_type) = $copy_lines[$n_num]; $title = ($orig_type == '-' ? 'Moved' : 'Copied').' from '; if ($orig_file == '') { $title .= "line {$orig_line}"; } else { $title .= basename($orig_file). ":{$orig_line} in dir ". dirname('/'.$orig_file); } $class = ($orig_type == '-' ? 'new-move' : 'new-copy'); $n_copy = javelin_tag( 'td', array( 'meta' => array( 'msg' => $title, ), 'class' => 'copy '.$class, ), ''); } } } if (isset($hunk_starts[$o_num])) { $html[] = $context_not_available; } if ($o_num && $left_prefix) { $o_id = $left_prefix.$o_num; } else { $o_id = null; } if ($n_num && $right_prefix) { $n_id = $right_prefix.$n_num; } else { $n_id = null; } // NOTE: This is a unicode zero-width space, which we use as a hint when // intercepting 'copy' events to make sure sensible text ends up on the // clipboard. See the 'phabricator-oncopy' behavior. $zero_space = "\xE2\x80\x8B"; $html[] = phutil_tag('tr', array(), array( phutil_tag('th', array('id' => $o_id), $o_num), phutil_tag('td', array('class' => $o_classes), $o_text), phutil_tag('th', array('id' => $n_id), $n_num), $n_copy, phutil_tag( 'td', array('class' => $n_classes, 'colspan' => $n_colspan), array( phutil_tag('span', array('class' => 'zwsp'), $zero_space), $n_text, )), $n_cov, )); if ($context_not_available && ($ii == $rows - 1)) { $html[] = $context_not_available; } $old_comments = $this->getOldComments(); $new_comments = $this->getNewComments(); if ($o_num && isset($old_comments[$o_num])) { foreach ($old_comments[$o_num] as $comment) { $inline = $this->buildInlineComment( $comment, $on_right = false); $scaffold = $this->getRowScaffoldForInline($inline); if ($n_num && isset($new_comments[$n_num])) { foreach ($new_comments[$n_num] as $key => $new_comment) { if ($comment->isCompatible($new_comment)) { $companion = $this->buildInlineComment( $new_comment, $on_right = true); $scaffold->addInlineView($companion); unset($new_comments[$n_num][$key]); } } } $html[] = $scaffold; } } if ($n_num && isset($new_comments[$n_num])) { foreach ($new_comments[$n_num] as $comment) { $inline = $this->buildInlineComment( $comment, $on_right = true); $html[] = $this->getRowScaffoldForInline($inline); } } } return $this->wrapChangeInTable(phutil_implode_html('', $html)); } public function renderFileChange($old_file = null, $new_file = null, $id = 0, $vs = 0) { $old = null; if ($old_file) { - $old = phutil_tag( - 'div', - array( - 'class' => 'differential-image-stage', - ), - phutil_tag( - 'img', - array( - 'src' => $old_file->getBestURI(), - ))); + $old = $this->renderImageStage($old_file); } $new = null; if ($new_file) { - $new = phutil_tag( - 'div', - array( - 'class' => 'differential-image-stage', - ), - phutil_tag( - 'img', - array( - 'src' => $new_file->getBestURI(), - ))); + $new = $this->renderImageStage($new_file); } $html_old = array(); $html_new = array(); foreach ($this->getOldComments() as $on_line => $comment_group) { foreach ($comment_group as $comment) { $inline = $this->buildInlineComment( $comment, $on_right = false); $html_old[] = $this->getRowScaffoldForInline($inline); } } foreach ($this->getNewComments() as $lin_line => $comment_group) { foreach ($comment_group as $comment) { $inline = $this->buildInlineComment( $comment, $on_right = true); $html_new[] = $this->getRowScaffoldForInline($inline); } } if (!$old) { $th_old = phutil_tag('th', array()); } else { $th_old = phutil_tag('th', array('id' => "C{$vs}OL1"), 1); } if (!$new) { $th_new = phutil_tag('th', array()); } else { $th_new = phutil_tag('th', array('id' => "C{$id}OL1"), 1); } $output = hsprintf( ''. '%s'. '%s'. '%s'. '%s'. ''. '%s'. '%s', $th_old, $old, $th_new, $new, phutil_implode_html('', $html_old), phutil_implode_html('', $html_new)); $output = $this->wrapChangeInTable($output); return $this->renderChangesetTable($output); } public function getRowScaffoldForInline(PHUIDiffInlineCommentView $view) { return id(new PHUIDiffTwoUpInlineCommentRowScaffold()) ->addInlineView($view); } }