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

Converted Paste language selection to a typeahead

Summary: Fixes T11532. The language selection for pastes is now a typeahead that is backed by `pygments.dropdown-choices`. There is still a bit of weirdness around making "auto-detection" the default state. To actually select a different language, you first need to remove the "auto detect" option that is pre-populated in a new paste. Other than that, it works as intended.

Test Plan:
Create a new paste with a file extension that can be auto-detected.
Created a new paste and manually selected the language
Edited a paste and changed the language.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley, yelirekim

Maniphest Tasks: T11532

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

authored by

Josh Cox and committed by
jcox
9422596e 60d1762a

+53 -9
+3
resources/sql/autopatches/20160829.pastebin.01.language.sql
··· 1 + /* Allow this column to be nullable (null means we'll try to autodetect) */ 2 + ALTER TABLE {$NAMESPACE}_pastebin.pastebin_paste MODIFY language VARCHAR(64) 3 + COLLATE {$COLLATE_TEXT};
+2
resources/sql/autopatches/20160829.pastebin.02.language.sql
··· 1 + UPDATE {$NAMESPACE}_pastebin.pastebin_paste SET language = NULL 2 + WHERE language = '';
+2
src/__phutil_library_map__.php
··· 1732 1732 'PasteEditConduitAPIMethod' => 'applications/paste/conduit/PasteEditConduitAPIMethod.php', 1733 1733 'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php', 1734 1734 'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php', 1735 + 'PasteLanguageSelectDatasource' => 'applications/paste/typeahead/PasteLanguageSelectDatasource.php', 1735 1736 'PasteMailReceiver' => 'applications/paste/mail/PasteMailReceiver.php', 1736 1737 'PasteQueryConduitAPIMethod' => 'applications/paste/conduit/PasteQueryConduitAPIMethod.php', 1737 1738 'PasteReplyHandler' => 'applications/paste/mail/PasteReplyHandler.php', ··· 6401 6402 'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 6402 6403 'PasteEmbedView' => 'AphrontView', 6403 6404 'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod', 6405 + 'PasteLanguageSelectDatasource' => 'PhabricatorTypeaheadDatasource', 6404 6406 'PasteMailReceiver' => 'PhabricatorObjectMailReceiver', 6405 6407 'PasteQueryConduitAPIMethod' => 'PasteConduitAPIMethod', 6406 6408 'PasteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
+3 -7
src/applications/paste/editor/PhabricatorPasteEditEngine.php
··· 63 63 } 64 64 65 65 protected function buildCustomEditFields($object) { 66 - $langs = array( 67 - '' => pht('(Detect From Filename in Title)'), 68 - ) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); 69 - 70 66 return array( 71 67 id(new PhabricatorTextEditField()) 72 68 ->setKey('title') ··· 76 72 ->setConduitDescription(pht('Retitle the paste.')) 77 73 ->setConduitTypeDescription(pht('New paste title.')) 78 74 ->setValue($object->getTitle()), 79 - id(new PhabricatorSelectEditField()) 75 + id(new PhabricatorDatasourceEditField()) 80 76 ->setKey('language') 81 77 ->setLabel(pht('Language')) 82 78 ->setTransactionType( 83 79 PhabricatorPasteLanguageTransaction::TRANSACTIONTYPE) 84 80 ->setAliases(array('lang')) 85 81 ->setIsCopyable(true) 86 - ->setOptions($langs) 82 + ->setDatasource(new PasteLanguageSelectDatasource()) 87 83 ->setDescription( 88 84 pht( 89 85 'Language used for syntax highlighting. By default, inferred '. ··· 91 87 ->setConduitDescription( 92 88 pht('Change language used for syntax highlighting.')) 93 89 ->setConduitTypeDescription(pht('New highlighting language.')) 94 - ->setValue($object->getLanguage()), 90 + ->setSingleValue($object->getLanguage()), 95 91 id(new PhabricatorTextAreaEditField()) 96 92 ->setKey('text') 97 93 ->setLabel(pht('Text'))
+1 -2
src/applications/paste/storage/PhabricatorPaste.php
··· 42 42 43 43 return id(new PhabricatorPaste()) 44 44 ->setTitle('') 45 - ->setLanguage('') 46 45 ->setStatus(self::STATUS_ACTIVE) 47 46 ->setAuthorPHID($actor->getPHID()) 48 47 ->setViewPolicy($view_policy) ··· 72 71 self::CONFIG_COLUMN_SCHEMA => array( 73 72 'status' => 'text32', 74 73 'title' => 'text255', 75 - 'language' => 'text64', 74 + 'language' => 'text64?', 76 75 'mailKey' => 'bytes20', 77 76 'parentPHID' => 'phid?', 78 77
+42
src/applications/paste/typeahead/PasteLanguageSelectDatasource.php
··· 1 + <?php 2 + 3 + final class PasteLanguageSelectDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getBrowseTitle() { 7 + return pht('Browse Languages'); 8 + } 9 + 10 + public function getPlaceholderText() { 11 + return pht('Type a language name or leave blank to auto-detect...'); 12 + } 13 + 14 + public function getDatasourceApplicationClass() { 15 + return 'PhabricatorPasteApplication'; 16 + } 17 + 18 + public function loadResults() { 19 + $results = $this->buildResults(); 20 + return $this->filterResultsAgainstTokens($results); 21 + } 22 + 23 + 24 + protected function renderSpecialTokens(array $values) { 25 + return $this->renderTokensFromResults($this->buildResults(), $values); 26 + } 27 + 28 + private function buildResults() { 29 + $results = array(); 30 + $languages = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices'); 31 + 32 + foreach ($languages as $value => $name) { 33 + $result = id(new PhabricatorTypeaheadResult()) 34 + ->setPHID($value) 35 + ->setName($name); 36 + 37 + $results[$value] = $result; 38 + } 39 + return $results; 40 + } 41 + 42 + }