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

Add a rough Quick Search datasource for Phriction documents

Summary:
Depends on D19106. Fixes T5941. Ref T13077. Allows you to find Phriction documents as suggestions from global quick search.

Also supports `w` to jump to Phriction and `w query` to query Phriction.

The actual query logic for the datasource may need some tweaking after it collides with reality, but seems to produce fairly reasonable results in local testing against synthetic data.

Test Plan: Searched for "Porcupine Facts", "Travel Companions", and other useful local pages. Searched for `w`. Searched for `w zebra facts`.

Maniphest Tasks: T13077, T5941

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

+167 -14
+14 -14
resources/celerity/map.php
··· 10 10 'conpherence.pkg.css' => 'e68cf1fa', 11 11 'conpherence.pkg.js' => '15191c65', 12 12 'core.pkg.css' => 'e4f098a5', 13 - 'core.pkg.js' => '3ac6e174', 13 + 'core.pkg.js' => 'bd19de1c', 14 14 'darkconsole.pkg.js' => '1f9a31bc', 15 15 'differential.pkg.css' => '113e692c', 16 16 'differential.pkg.js' => 'f6d809c0', ··· 506 506 'rsrc/js/core/behavior-reorder-applications.js' => '76b9fc3e', 507 507 'rsrc/js/core/behavior-reveal-content.js' => '60821bc7', 508 508 'rsrc/js/core/behavior-scrollbar.js' => '834a1173', 509 - 'rsrc/js/core/behavior-search-typeahead.js' => 'd0a99ab4', 509 + 'rsrc/js/core/behavior-search-typeahead.js' => 'c3e917d9', 510 510 'rsrc/js/core/behavior-select-content.js' => 'bf5374ef', 511 511 'rsrc/js/core/behavior-select-on-click.js' => '4e3e79a6', 512 512 'rsrc/js/core/behavior-setup-check-https.js' => '491416b3', ··· 663 663 'javelin-behavior-phabricator-oncopy' => '2926fff2', 664 664 'javelin-behavior-phabricator-remarkup-assist' => 'acd29eee', 665 665 'javelin-behavior-phabricator-reveal-content' => '60821bc7', 666 - 'javelin-behavior-phabricator-search-typeahead' => 'd0a99ab4', 666 + 'javelin-behavior-phabricator-search-typeahead' => 'c3e917d9', 667 667 'javelin-behavior-phabricator-show-older-transactions' => '8f29b364', 668 668 'javelin-behavior-phabricator-tooltips' => 'c420b0b9', 669 669 'javelin-behavior-phabricator-transaction-comment-form' => 'b23b49e6', ··· 1918 1918 'javelin-dom', 1919 1919 'javelin-vector', 1920 1920 ), 1921 + 'c3e917d9' => array( 1922 + 'javelin-behavior', 1923 + 'javelin-typeahead-ondemand-source', 1924 + 'javelin-typeahead', 1925 + 'javelin-dom', 1926 + 'javelin-uri', 1927 + 'javelin-util', 1928 + 'javelin-stratcom', 1929 + 'phabricator-prefab', 1930 + 'phuix-icon-view', 1931 + ), 1921 1932 'c420b0b9' => array( 1922 1933 'javelin-behavior', 1923 1934 'javelin-behavior-device', ··· 1968 1979 'javelin-util', 1969 1980 'phabricator-notification', 1970 1981 'conpherence-thread-manager', 1971 - ), 1972 - 'd0a99ab4' => array( 1973 - 'javelin-behavior', 1974 - 'javelin-typeahead-ondemand-source', 1975 - 'javelin-typeahead', 1976 - 'javelin-dom', 1977 - 'javelin-uri', 1978 - 'javelin-util', 1979 - 'javelin-stratcom', 1980 - 'phabricator-prefab', 1981 - 'phuix-icon-view', 1982 1982 ), 1983 1983 'd0c516d5' => array( 1984 1984 'javelin-behavior',
+4
src/__phutil_library_map__.php
··· 4855 4855 'PhrictionController' => 'applications/phriction/controller/PhrictionController.php', 4856 4856 'PhrictionCreateConduitAPIMethod' => 'applications/phriction/conduit/PhrictionCreateConduitAPIMethod.php', 4857 4857 'PhrictionDAO' => 'applications/phriction/storage/PhrictionDAO.php', 4858 + 'PhrictionDatasourceEngineExtension' => 'applications/phriction/engineextension/PhrictionDatasourceEngineExtension.php', 4858 4859 'PhrictionDeleteController' => 'applications/phriction/controller/PhrictionDeleteController.php', 4859 4860 'PhrictionDiffController' => 'applications/phriction/controller/PhrictionDiffController.php', 4860 4861 'PhrictionDocument' => 'applications/phriction/storage/PhrictionDocument.php', ··· 4862 4863 'PhrictionDocumentContentHeraldField' => 'applications/phriction/herald/PhrictionDocumentContentHeraldField.php', 4863 4864 'PhrictionDocumentContentTransaction' => 'applications/phriction/xaction/PhrictionDocumentContentTransaction.php', 4864 4865 'PhrictionDocumentController' => 'applications/phriction/controller/PhrictionDocumentController.php', 4866 + 'PhrictionDocumentDatasource' => 'applications/phriction/typeahead/PhrictionDocumentDatasource.php', 4865 4867 'PhrictionDocumentDeleteTransaction' => 'applications/phriction/xaction/PhrictionDocumentDeleteTransaction.php', 4866 4868 'PhrictionDocumentFerretEngine' => 'applications/phriction/search/PhrictionDocumentFerretEngine.php', 4867 4869 'PhrictionDocumentFulltextEngine' => 'applications/phriction/search/PhrictionDocumentFulltextEngine.php', ··· 10777 10779 'PhrictionController' => 'PhabricatorController', 10778 10780 'PhrictionCreateConduitAPIMethod' => 'PhrictionConduitAPIMethod', 10779 10781 'PhrictionDAO' => 'PhabricatorLiskDAO', 10782 + 'PhrictionDatasourceEngineExtension' => 'PhabricatorDatasourceEngineExtension', 10780 10783 'PhrictionDeleteController' => 'PhrictionController', 10781 10784 'PhrictionDiffController' => 'PhrictionController', 10782 10785 'PhrictionDocument' => array( ··· 10796 10799 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', 10797 10800 'PhrictionDocumentContentTransaction' => 'PhrictionDocumentTransactionType', 10798 10801 'PhrictionDocumentController' => 'PhrictionController', 10802 + 'PhrictionDocumentDatasource' => 'PhabricatorTypeaheadDatasource', 10799 10803 'PhrictionDocumentDeleteTransaction' => 'PhrictionDocumentTransactionType', 10800 10804 'PhrictionDocumentFerretEngine' => 'PhabricatorFerretEngine', 10801 10805 'PhrictionDocumentFulltextEngine' => 'PhabricatorFulltextEngine',
+56
src/applications/phriction/engineextension/PhrictionDatasourceEngineExtension.php
··· 1 + <?php 2 + 3 + final class PhrictionDatasourceEngineExtension 4 + extends PhabricatorDatasourceEngineExtension { 5 + 6 + public function newQuickSearchDatasources() { 7 + return array( 8 + new PhrictionDocumentDatasource(), 9 + ); 10 + } 11 + 12 + public function newJumpURI($query) { 13 + $viewer = $this->getViewer(); 14 + 15 + // Send "w" to Phriction. 16 + if (preg_match('/^w\z/i', $query)) { 17 + return '/w/'; 18 + } 19 + 20 + // Send "w <string>" to a search for similar wiki documents. 21 + $matches = null; 22 + if (preg_match('/^w\s+(.+)\z/i', $query, $matches)) { 23 + $raw_query = $matches[1]; 24 + 25 + $engine = id(new PhrictionDocument()) 26 + ->newFerretEngine(); 27 + 28 + $compiler = id(new PhutilSearchQueryCompiler()) 29 + ->setEnableFunctions(true); 30 + 31 + $raw_tokens = $compiler->newTokens($raw_query); 32 + 33 + $fulltext_tokens = array(); 34 + foreach ($raw_tokens as $raw_token) { 35 + $fulltext_token = id(new PhabricatorFulltextToken()) 36 + ->setToken($raw_token); 37 + $fulltext_tokens[] = $fulltext_token; 38 + } 39 + 40 + $documents = id(new PhrictionDocumentQuery()) 41 + ->setViewer($viewer) 42 + ->withFerretConstraint($engine, $fulltext_tokens) 43 + ->execute(); 44 + if (count($documents) == 1) { 45 + return head($documents)->getURI(); 46 + } else { 47 + // More than one match, jump to search. 48 + return urisprintf( 49 + '/phriction/?order=relevance&query=%s#R', 50 + $raw_query); 51 + } 52 + } 53 + 54 + return null; 55 + } 56 + }
+4
src/applications/phriction/storage/PhrictionDocument.php
··· 149 149 return $this; 150 150 } 151 151 152 + public function getURI() { 153 + return self::getSlugURI($this->getSlug()); 154 + } 155 + 152 156 /* -( Status )------------------------------------------------------------- */ 153 157 154 158
+88
src/applications/phriction/typeahead/PhrictionDocumentDatasource.php
··· 1 + <?php 2 + 3 + final class PhrictionDocumentDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getBrowseTitle() { 7 + return pht('Browse Documents'); 8 + } 9 + 10 + public function getPlaceholderText() { 11 + return pht('Type a document name...'); 12 + } 13 + 14 + public function getDatasourceApplicationClass() { 15 + return 'PhabricatorPhrictionApplication'; 16 + } 17 + 18 + public function loadResults() { 19 + $viewer = $this->getViewer(); 20 + 21 + $raw_query = $this->getRawQuery(); 22 + 23 + $engine = id(new PhrictionDocument()) 24 + ->newFerretEngine(); 25 + 26 + $compiler = id(new PhutilSearchQueryCompiler()) 27 + ->setEnableFunctions(true); 28 + 29 + $raw_tokens = $compiler->newTokens($raw_query); 30 + 31 + $fulltext_tokens = array(); 32 + foreach ($raw_tokens as $raw_token) { 33 + 34 + // This is a little hacky and could maybe be cleaner. We're treating 35 + // every search term as though the user had entered "title:dog" insead 36 + // of "dog". 37 + 38 + $alternate_token = PhutilSearchQueryToken::newFromDictionary( 39 + array( 40 + 'quoted' => $raw_token->isQuoted(), 41 + 'value' => $raw_token->getValue(), 42 + 'operator' => PhutilSearchQueryCompiler::OPERATOR_SUBSTRING, 43 + 'function' => 'title', 44 + )); 45 + 46 + $fulltext_token = id(new PhabricatorFulltextToken()) 47 + ->setToken($alternate_token); 48 + $fulltext_tokens[] = $fulltext_token; 49 + } 50 + 51 + $documents = id(new PhrictionDocumentQuery()) 52 + ->setViewer($viewer) 53 + ->withFerretConstraint($engine, $fulltext_tokens) 54 + ->needContent(true) 55 + ->execute(); 56 + 57 + $results = array(); 58 + foreach ($documents as $document) { 59 + $content = $document->getContent(); 60 + 61 + if (!$document->isActive()) { 62 + $closed = $document->getStatusDisplayName(); 63 + } else { 64 + $closed = null; 65 + } 66 + 67 + $slug = $document->getSlug(); 68 + $title = $content->getTitle(); 69 + 70 + $sprite = 'phabricator-search-icon phui-font-fa phui-icon-view fa-book'; 71 + 72 + $result = id(new PhabricatorTypeaheadResult()) 73 + ->setName($title) 74 + ->setDisplayName($title) 75 + ->setURI($document->getURI()) 76 + ->setPHID($document->getPHID()) 77 + ->setDisplayType($slug) 78 + ->setPriorityType('wiki') 79 + ->setImageSprite($sprite) 80 + ->setClosed($closed); 81 + 82 + $results[] = $result; 83 + } 84 + 85 + return $results; 86 + } 87 + 88 + }
+1
webroot/rsrc/js/core/behavior-search-typeahead.js
··· 70 70 'proj', 71 71 'user', 72 72 'repo', 73 + 'wiki', 73 74 'symb', 74 75 'misc' 75 76 ];