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:
parent
2e3e078358
commit
bee043b163
3 changed files with 16 additions and 5 deletions
|
@ -185,6 +185,7 @@ final class PhabricatorPasteQuery
|
||||||
$paste->getFilePHID(),
|
$paste->getFilePHID(),
|
||||||
$paste->getLanguage(),
|
$paste->getLanguage(),
|
||||||
'snippet',
|
'snippet',
|
||||||
|
'v2',
|
||||||
PhabricatorHash::digestForIndex($paste->getTitle()),
|
PhabricatorHash::digestForIndex($paste->getTitle()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -294,7 +295,8 @@ final class PhabricatorPasteQuery
|
||||||
$snippet_data = phutil_json_decode($caches[$key], true);
|
$snippet_data = phutil_json_decode($caches[$key], true);
|
||||||
$snippet = new PhabricatorPasteSnippet(
|
$snippet = new PhabricatorPasteSnippet(
|
||||||
phutil_safe_html($snippet_data['content']),
|
phutil_safe_html($snippet_data['content']),
|
||||||
$snippet_data['type']);
|
$snippet_data['type'],
|
||||||
|
$snippet_data['contentLineCount']);
|
||||||
$paste->attachSnippet($snippet);
|
$paste->attachSnippet($snippet);
|
||||||
$have_cache[$paste->getPHID()] = true;
|
$have_cache[$paste->getPHID()] = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -326,6 +328,7 @@ final class PhabricatorPasteQuery
|
||||||
$snippet_data = array(
|
$snippet_data = array(
|
||||||
'content' => (string)$snippet->getContent(),
|
'content' => (string)$snippet->getContent(),
|
||||||
'type' => (string)$snippet->getType(),
|
'type' => (string)$snippet->getType(),
|
||||||
|
'contentLineCount' => $snippet->getContentLineCount(),
|
||||||
);
|
);
|
||||||
$write_data[$this->getSnippetCacheKey($paste)] = phutil_json_encode(
|
$write_data[$this->getSnippetCacheKey($paste)] = phutil_json_encode(
|
||||||
$snippet_data);
|
$snippet_data);
|
||||||
|
@ -358,7 +361,8 @@ final class PhabricatorPasteQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = phutil_split_lines($snippet);
|
$lines = phutil_split_lines($snippet);
|
||||||
if (count($lines) > 5) {
|
$line_count = count($lines);
|
||||||
|
if ($line_count > 5) {
|
||||||
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
|
$snippet_type = PhabricatorPasteSnippet::FIRST_LINES;
|
||||||
$snippet = implode('', array_slice($lines, 0, 5));
|
$snippet = implode('', array_slice($lines, 0, 5));
|
||||||
}
|
}
|
||||||
|
@ -368,7 +372,8 @@ final class PhabricatorPasteQuery
|
||||||
$snippet,
|
$snippet,
|
||||||
$paste->getTitle(),
|
$paste->getTitle(),
|
||||||
$paste->getLanguage()),
|
$paste->getLanguage()),
|
||||||
$snippet_type);
|
$snippet_type,
|
||||||
|
$line_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function highlightSource($source, $title, $language) {
|
private function highlightSource($source, $title, $language) {
|
||||||
|
|
|
@ -166,7 +166,7 @@ final class PhabricatorPasteSearchEngine
|
||||||
$preview);
|
$preview);
|
||||||
|
|
||||||
$created = phabricator_datetime($paste->getDateCreated(), $viewer);
|
$created = phabricator_datetime($paste->getDateCreated(), $viewer);
|
||||||
$line_count = count($lines);
|
$line_count = $paste->getSnippet()->getContentLineCount();
|
||||||
$line_count = pht(
|
$line_count = pht(
|
||||||
'%s Line(s)',
|
'%s Line(s)',
|
||||||
new PhutilNumber($line_count));
|
new PhutilNumber($line_count));
|
||||||
|
|
|
@ -8,10 +8,12 @@ final class PhabricatorPasteSnippet extends Phobject {
|
||||||
|
|
||||||
private $content;
|
private $content;
|
||||||
private $type;
|
private $type;
|
||||||
|
private $contentLineCount;
|
||||||
|
|
||||||
public function __construct($content, $type) {
|
public function __construct($content, $type, $content_line_count) {
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
$this->contentLineCount = $content_line_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent() {
|
public function getContent() {
|
||||||
|
@ -21,4 +23,8 @@ final class PhabricatorPasteSnippet extends Phobject {
|
||||||
public function getType() {
|
public function getType() {
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getContentLineCount() {
|
||||||
|
return $this->contentLineCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue