@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.

Render "Show Context" blocks in unified view

Summary:
Ref T2009. This basically copy/pastes them for now. Plans is:

- Make this actually work all the way.
- Add test coverage after D11970.
- Move 2-up here after test coverage.

Clicking the links does not work yet, because they use the 2-up renderer. I'll fix this in the next diff.

Test Plan: Viewed diffs in unified, saw links to show more.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: chad, epriestley

Maniphest Tasks: T2009

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

+137 -1
+88
src/applications/differential/render/DifferentialChangesetHTMLRenderer.php
··· 439 439 ->setAllowReply($allow_reply); 440 440 } 441 441 442 + 443 + /** 444 + * Build links which users can click to show more context in a changeset. 445 + * 446 + * @param int Beginning of the line range to build links for. 447 + * @param int Length of the line range to build links for. 448 + * @param int Total number of lines in the changeset. 449 + * @return markup Rendered links. 450 + */ 451 + protected function renderShowContextLinks($top, $len, $changeset_length) { 452 + $block_size = 20; 453 + $end = ($top + $len) - $block_size; 454 + 455 + // If this is a large block, such that the "top" and "bottom" ranges are 456 + // non-overlapping, we'll provide options to show the top, bottom or entire 457 + // block. For smaller blocks, we only provide an option to show the entire 458 + // block, since it would be silly to show the bottom 20 lines of a 25-line 459 + // block. 460 + $is_large_block = ($len > ($block_size * 2)); 461 + 462 + $links = array(); 463 + 464 + if ($is_large_block) { 465 + $is_first_block = ($top == 0); 466 + if ($is_first_block) { 467 + $text = pht('Show First %d Line(s)', $block_size); 468 + } else { 469 + $text = pht("\xE2\x96\xB2 Show %d Line(s)", $block_size); 470 + } 471 + 472 + $links[] = $this->renderShowContextLink( 473 + false, 474 + "{$top}-{$len}/{$top}-20", 475 + $text); 476 + } 477 + 478 + $links[] = $this->renderShowContextLink( 479 + true, 480 + "{$top}-{$len}/{$top}-{$len}", 481 + pht('Show All %d Line(s)', $len)); 482 + 483 + if ($is_large_block) { 484 + $is_last_block = (($top + $len) >= $changeset_length); 485 + if ($is_last_block) { 486 + $text = pht('Show Last %d Line(s)', $block_size); 487 + } else { 488 + $text = pht("\xE2\x96\xBC Show %d Line(s)", $block_size); 489 + } 490 + 491 + $links[] = $this->renderShowContextLink( 492 + false, 493 + "{$top}-{$len}/{$end}-20", 494 + $text); 495 + } 496 + 497 + return phutil_implode_html(" \xE2\x80\xA2 ", $links); 498 + } 499 + 500 + 501 + /** 502 + * Build a link that shows more context in a changeset. 503 + * 504 + * See @{method:renderShowContextLinks}. 505 + * 506 + * @param bool Does this link show all context when clicked? 507 + * @param string Range specification for lines to show. 508 + * @param string Text of the link. 509 + * @return markup Rendered link. 510 + */ 511 + private function renderShowContextLink($is_all, $range, $text) { 512 + $reference = $this->getRenderingReference(); 513 + 514 + return javelin_tag( 515 + 'a', 516 + array( 517 + 'href' => '#', 518 + 'mustcapture' => true, 519 + 'sigil' => 'show-more', 520 + 'meta' => array( 521 + 'type' => ($is_all ? 'all' : null), 522 + 'ref' => $reference, 523 + 'range' => $range, 524 + ), 525 + ), 526 + $text); 527 + } 528 + 529 + 442 530 }
+20 -1
src/applications/differential/render/DifferentialChangesetOneUpRenderer.php
··· 69 69 break; 70 70 case 'no-context': 71 71 $out[] = hsprintf( 72 - '<tr><td class="show-more" colspan="3">%s</th></tr>', 72 + '<tr><td class="show-more" colspan="3">%s</td></tr>', 73 73 pht('Context not available.')); 74 + break; 75 + case 'context': 76 + $top = $p['top']; 77 + $len = $p['len']; 78 + 79 + $links = $this->renderShowContextLinks($top, $len, $rows); 80 + 81 + $out[] = javelin_tag( 82 + 'tr', 83 + array( 84 + 'sigil' => 'context-target', 85 + ), 86 + phutil_tag( 87 + 'td', 88 + array( 89 + 'class' => 'show-more', 90 + 'colspan' => 3, 91 + ), 92 + $links)); 74 93 break; 75 94 default: 76 95 $out[] = hsprintf('<tr><th /><th /><td>%s</td></tr>', $type);
+3
src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php
··· 84 84 // increments $ii by the entire size of the gap and then continues 85 85 // the loop. 86 86 $gap = array_pop($gaps); 87 + 88 + // TODO: Move this to renderShowContextLinks() once that is stable. 89 + 87 90 $top = $gap[0]; 88 91 $len = $gap[1]; 89 92
+26
src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
··· 941 941 'allowed domains will be able to register an account: %3$s', 942 942 ), 943 943 ), 944 + 945 + 'Show First %d Line(s)' => array( 946 + 'Show First Line', 947 + 'Show First %d Lines', 948 + ), 949 + 950 + "\xE2\x96\xB2 Show %d Line(s)" => array( 951 + "\xE2\x96\xB2 Show %d Line(s)", 952 + "\xE2\x96\xB2 Show %d Line(s)", 953 + ), 954 + 955 + 'Show All %d Line(s)' => array( 956 + 'Show Line', 957 + 'Show All %d Lines', 958 + ), 959 + 960 + "\xE2\x96\xBC Show %d Line(s)" => array( 961 + "\xE2\x96\xBC Show Line", 962 + "\xE2\x96\xBC Show %d Lines", 963 + ), 964 + 965 + 'Show Last %d Line(s)' => array( 966 + 'Show Last Line', 967 + 'Show Last %d Lines', 968 + ), 969 + 944 970 ); 945 971 } 946 972