@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

Display paste line count alongside snippets

Summary: Fixes T11547. I //think// this mostly gets about addressing @epriestley's comments in D16465 and stores each paste's line count in its snippet so that we can display the actual number of lines in the paste rather than '5 Lines'. Let me know if this is on the right track!

Test Plan: Open /paste and see that each paste's actual line count is reported.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T11547

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

authored by

Christopher Wetherill and committed by
faulconbridge
bee043b1 2e3e0783

+16 -5
+8 -3
src/applications/paste/query/PhabricatorPasteQuery.php
··· 185 185 $paste->getFilePHID(), 186 186 $paste->getLanguage(), 187 187 'snippet', 188 + 'v2', 188 189 PhabricatorHash::digestForIndex($paste->getTitle()), 189 190 )); 190 191 } ··· 294 295 $snippet_data = phutil_json_decode($caches[$key], true); 295 296 $snippet = new PhabricatorPasteSnippet( 296 297 phutil_safe_html($snippet_data['content']), 297 - $snippet_data['type']); 298 + $snippet_data['type'], 299 + $snippet_data['contentLineCount']); 298 300 $paste->attachSnippet($snippet); 299 301 $have_cache[$paste->getPHID()] = true; 300 302 } else { ··· 326 328 $snippet_data = array( 327 329 'content' => (string)$snippet->getContent(), 328 330 'type' => (string)$snippet->getType(), 331 + 'contentLineCount' => $snippet->getContentLineCount(), 329 332 ); 330 333 $write_data[$this->getSnippetCacheKey($paste)] = phutil_json_encode( 331 334 $snippet_data); ··· 358 361 } 359 362 360 363 $lines = phutil_split_lines($snippet); 361 - if (count($lines) > 5) { 364 + $line_count = count($lines); 365 + if ($line_count > 5) { 362 366 $snippet_type = PhabricatorPasteSnippet::FIRST_LINES; 363 367 $snippet = implode('', array_slice($lines, 0, 5)); 364 368 } ··· 368 372 $snippet, 369 373 $paste->getTitle(), 370 374 $paste->getLanguage()), 371 - $snippet_type); 375 + $snippet_type, 376 + $line_count); 372 377 } 373 378 374 379 private function highlightSource($source, $title, $language) {
+1 -1
src/applications/paste/query/PhabricatorPasteSearchEngine.php
··· 166 166 $preview); 167 167 168 168 $created = phabricator_datetime($paste->getDateCreated(), $viewer); 169 - $line_count = count($lines); 169 + $line_count = $paste->getSnippet()->getContentLineCount(); 170 170 $line_count = pht( 171 171 '%s Line(s)', 172 172 new PhutilNumber($line_count));
+7 -1
src/applications/paste/snippet/PhabricatorPasteSnippet.php
··· 8 8 9 9 private $content; 10 10 private $type; 11 + private $contentLineCount; 11 12 12 - public function __construct($content, $type) { 13 + public function __construct($content, $type, $content_line_count) { 13 14 $this->content = $content; 14 15 $this->type = $type; 16 + $this->contentLineCount = $content_line_count; 15 17 } 16 18 17 19 public function getContent() { ··· 20 22 21 23 public function getType() { 22 24 return $this->type; 25 + } 26 + 27 + public function getContentLineCount() { 28 + return $this->contentLineCount; 23 29 } 24 30 }