1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

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
This commit is contained in:
Christopher Wetherill 2017-01-26 18:12:02 -05:00 committed by faulconbridge
parent 2e3e078358
commit bee043b163
3 changed files with 16 additions and 5 deletions

View file

@ -185,6 +185,7 @@ final class PhabricatorPasteQuery
$paste->getFilePHID(),
$paste->getLanguage(),
'snippet',
'v2',
PhabricatorHash::digestForIndex($paste->getTitle()),
));
}
@ -294,7 +295,8 @@ final class PhabricatorPasteQuery
$snippet_data = phutil_json_decode($caches[$key], true);
$snippet = new PhabricatorPasteSnippet(
phutil_safe_html($snippet_data['content']),
$snippet_data['type']);
$snippet_data['type'],
$snippet_data['contentLineCount']);
$paste->attachSnippet($snippet);
$have_cache[$paste->getPHID()] = true;
} else {
@ -326,6 +328,7 @@ final class PhabricatorPasteQuery
$snippet_data = array(
'content' => (string)$snippet->getContent(),
'type' => (string)$snippet->getType(),
'contentLineCount' => $snippet->getContentLineCount(),
);
$write_data[$this->getSnippetCacheKey($paste)] = phutil_json_encode(
$snippet_data);
@ -358,7 +361,8 @@ final class PhabricatorPasteQuery
}
$lines = phutil_split_lines($snippet);
if (count($lines) > 5) {
$line_count = count($lines);
if ($line_count > 5) {
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
$snippet = implode('', array_slice($lines, 0, 5));
}
@ -368,7 +372,8 @@ final class PhabricatorPasteQuery
$snippet,
$paste->getTitle(),
$paste->getLanguage()),
$snippet_type);
$snippet_type,
$line_count);
}
private function highlightSource($source, $title, $language) {

View file

@ -166,7 +166,7 @@ final class PhabricatorPasteSearchEngine
$preview);
$created = phabricator_datetime($paste->getDateCreated(), $viewer);
$line_count = count($lines);
$line_count = $paste->getSnippet()->getContentLineCount();
$line_count = pht(
'%s Line(s)',
new PhutilNumber($line_count));

View file

@ -8,10 +8,12 @@ final class PhabricatorPasteSnippet extends Phobject {
private $content;
private $type;
private $contentLineCount;
public function __construct($content, $type) {
public function __construct($content, $type, $content_line_count) {
$this->content = $content;
$this->type = $type;
$this->contentLineCount = $content_line_count;
}
public function getContent() {
@ -21,4 +23,8 @@ final class PhabricatorPasteSnippet extends Phobject {
public function getType() {
return $this->type;
}
public function getContentLineCount() {
return $this->contentLineCount;
}
}