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

Generate slightly shorter summaries in the typeahead browse dialog

Summary: Ref T11034. Try to produce a roughly-one-sentence summary instead of a roughly-one-paragraph summary for the browse dialog.

Test Plan:
- Added unit tests, ran unit tests.
- Wrote a longer summary for a project, browsed to it, saw a shorter summary.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11034

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

+68 -1
+2
src/__phutil_library_map__.php
··· 2896 2896 'PhabricatorManiphestTaskTestDataGenerator' => 'applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php', 2897 2897 'PhabricatorMarkupCache' => 'applications/cache/storage/PhabricatorMarkupCache.php', 2898 2898 'PhabricatorMarkupEngine' => 'infrastructure/markup/PhabricatorMarkupEngine.php', 2899 + 'PhabricatorMarkupEngineTestCase' => 'infrastructure/markup/__tests__/PhabricatorMarkupEngineTestCase.php', 2899 2900 'PhabricatorMarkupInterface' => 'infrastructure/markup/PhabricatorMarkupInterface.php', 2900 2901 'PhabricatorMarkupOneOff' => 'infrastructure/markup/PhabricatorMarkupOneOff.php', 2901 2902 'PhabricatorMarkupPreviewController' => 'infrastructure/markup/PhabricatorMarkupPreviewController.php', ··· 7871 7872 'PhabricatorManiphestTaskTestDataGenerator' => 'PhabricatorTestDataGenerator', 7872 7873 'PhabricatorMarkupCache' => 'PhabricatorCacheDAO', 7873 7874 'PhabricatorMarkupEngine' => 'Phobject', 7875 + 'PhabricatorMarkupEngineTestCase' => 'PhabricatorTestCase', 7874 7876 'PhabricatorMarkupOneOff' => array( 7875 7877 'Phobject', 7876 7878 'PhabricatorMarkupInterface',
+1 -1
src/applications/project/typeahead/PhabricatorProjectDatasource.php
··· 130 130 131 131 $description = idx($descriptions, $phid); 132 132 if (strlen($description)) { 133 - $summary = PhabricatorMarkupEngine::summarize($description); 133 + $summary = PhabricatorMarkupEngine::summarizeSentence($description); 134 134 $proj_result->addAttribute($summary); 135 135 } 136 136 }
+22
src/infrastructure/markup/PhabricatorMarkupEngine.php
··· 607 607 return array_values($files); 608 608 } 609 609 610 + public static function summarizeSentence($corpus) { 611 + $corpus = trim($corpus); 612 + $blocks = preg_split('/\n+/', $corpus, 2); 613 + $block = head($blocks); 614 + 615 + $sentences = preg_split( 616 + '/\b([.?!]+)\B/u', 617 + $block, 618 + 2, 619 + PREG_SPLIT_DELIM_CAPTURE); 620 + 621 + if (count($sentences) > 1) { 622 + $result = $sentences[0].$sentences[1]; 623 + } else { 624 + $result = head($sentences); 625 + } 626 + 627 + return id(new PhutilUTF8StringTruncator()) 628 + ->setMaximumGlyphs(128) 629 + ->truncateString($result); 630 + } 631 + 610 632 /** 611 633 * Produce a corpus summary, in a way that shortens the underlying text 612 634 * without truncating it somewhere awkward.
+43
src/infrastructure/markup/__tests__/PhabricatorMarkupEngineTestCase.php
··· 1 + <?php 2 + 3 + final class PhabricatorMarkupEngineTestCase 4 + extends PhabricatorTestCase { 5 + 6 + public function testRemarkupSentenceSummmaries() { 7 + $this->assertSentenceSummary( 8 + 'The quick brown fox. Jumped over the lazy dog.', 9 + 'The quick brown fox.'); 10 + 11 + $this->assertSentenceSummary( 12 + 'Go to www.help.com for details. Good day.', 13 + 'Go to www.help.com for details.'); 14 + 15 + $this->assertSentenceSummary( 16 + 'Coxy lummox gives squid who asks for job pen.', 17 + 'Coxy lummox gives squid who asks for job pen.'); 18 + 19 + $this->assertSentenceSummary( 20 + 'DEPRECATED', 21 + 'DEPRECATED'); 22 + 23 + $this->assertSentenceSummary( 24 + 'Never use this! It is deadly poison.', 25 + 'Never use this!'); 26 + 27 + $this->assertSentenceSummary( 28 + "a short poem\nmeow meow meow\nmeow meow meow\n\n- cat", 29 + 'a short poem'); 30 + 31 + $this->assertSentenceSummary( 32 + 'WOW!! GREAT PROJECT!', 33 + 'WOW!!'); 34 + } 35 + 36 + private function assertSentenceSummary($corpus, $summary) { 37 + $this->assertEqual( 38 + $summary, 39 + PhabricatorMarkupEngine::summarizeSentence($corpus), 40 + pht('Summary of: %s', $corpus)); 41 + } 42 + 43 + }