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

Initial support for comments/append-edits in EditEngine

Summary:
Ref T9132. This just replaces the "Add Comment" form in Paste with a generic flow in EditEngine.

No actual field-awareness or action stacking or anything quite yet, but that will come in a bit. This mildly regresses drafts (which don't seem like a big deal for Pastes). I'll hook those up again in the next diff, but I want to build them in a better way that will work with multiple actions in a generic way, and solve T5031.

Big practical advantage here is that applications don't need copy/pasted preview controllers.

Test Plan:
- Saw previews.
- Added comments.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9132

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

+107 -86
-2
src/__phutil_library_map__.php
··· 2605 2605 'PhabricatorPasswordSettingsPanel' => 'applications/settings/panel/PhabricatorPasswordSettingsPanel.php', 2606 2606 'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php', 2607 2607 'PhabricatorPasteApplication' => 'applications/paste/application/PhabricatorPasteApplication.php', 2608 - 'PhabricatorPasteCommentController' => 'applications/paste/controller/PhabricatorPasteCommentController.php', 2609 2608 'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php', 2610 2609 'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php', 2611 2610 'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php', ··· 6800 6799 'PhabricatorSpacesInterface', 6801 6800 ), 6802 6801 'PhabricatorPasteApplication' => 'PhabricatorApplication', 6803 - 'PhabricatorPasteCommentController' => 'PhabricatorPasteController', 6804 6802 'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions', 6805 6803 'PhabricatorPasteController' => 'PhabricatorController', 6806 6804 'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
+1 -1
src/applications/base/PhabricatorApplication.php
··· 640 640 '(?P<id>[0-9]\d*)/)?'. 641 641 '(?:'. 642 642 '(?:'. 643 - '(?P<editAction>parameters|nodefault)'. 643 + '(?P<editAction>parameters|nodefault|comment)'. 644 644 '|'. 645 645 '(?:form/(?P<formKey>[^/]+))'. 646 646 ')'.
-1
src/applications/paste/application/PhabricatorPasteApplication.php
··· 41 41 'create/' => 'PhabricatorPasteEditController', 42 42 $this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController', 43 43 'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController', 44 - 'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController', 45 44 ), 46 45 ); 47 46 }
-63
src/applications/paste/controller/PhabricatorPasteCommentController.php
··· 1 - <?php 2 - 3 - final class PhabricatorPasteCommentController 4 - extends PhabricatorPasteController { 5 - 6 - public function handleRequest(AphrontRequest $request) { 7 - $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 9 - 10 - if (!$request->isFormPost()) { 11 - return new Aphront400Response(); 12 - } 13 - 14 - $paste = id(new PhabricatorPasteQuery()) 15 - ->setViewer($viewer) 16 - ->withIDs(array($id)) 17 - ->executeOne(); 18 - if (!$paste) { 19 - return new Aphront404Response(); 20 - } 21 - 22 - $is_preview = $request->isPreviewRequest(); 23 - $draft = PhabricatorDraft::buildFromRequest($request); 24 - 25 - $view_uri = $paste->getURI(); 26 - 27 - $xactions = array(); 28 - $xactions[] = id(new PhabricatorPasteTransaction()) 29 - ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 30 - ->attachComment( 31 - id(new PhabricatorPasteTransactionComment()) 32 - ->setContent($request->getStr('comment'))); 33 - 34 - $editor = id(new PhabricatorPasteEditor()) 35 - ->setActor($viewer) 36 - ->setContinueOnNoEffect($request->isContinueRequest()) 37 - ->setContentSourceFromRequest($request) 38 - ->setIsPreview($is_preview); 39 - 40 - try { 41 - $xactions = $editor->applyTransactions($paste, $xactions); 42 - } catch (PhabricatorApplicationTransactionNoEffectException $ex) { 43 - return id(new PhabricatorApplicationTransactionNoEffectResponse()) 44 - ->setCancelURI($view_uri) 45 - ->setException($ex); 46 - } 47 - 48 - if ($draft) { 49 - $draft->replaceOrDelete(); 50 - } 51 - 52 - if ($request->isAjax() && $is_preview) { 53 - return id(new PhabricatorApplicationTransactionResponse()) 54 - ->setViewer($viewer) 55 - ->setTransactions($xactions) 56 - ->setIsPreview($is_preview); 57 - } else { 58 - return id(new AphrontRedirectResponse()) 59 - ->setURI($view_uri); 60 - } 61 - } 62 - 63 - }
+4 -19
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 1 1 <?php 2 2 3 - /** 4 - * group paste 5 - */ 6 3 final class PhabricatorPasteViewController extends PhabricatorPasteController { 7 4 8 5 private $highlightMap; ··· 73 70 $paste, 74 71 new PhabricatorPasteTransactionQuery()); 75 72 76 - $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 77 - 78 - $add_comment_header = $is_serious 79 - ? pht('Add Comment') 80 - : pht('Eat Paste'); 81 - 82 - $draft = PhabricatorDraft::newFromUserAndKey($viewer, $paste->getPHID()); 83 - 84 - $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) 85 - ->setUser($viewer) 86 - ->setObjectPHID($paste->getPHID()) 87 - ->setDraft($draft) 88 - ->setHeaderText($add_comment_header) 89 - ->setAction($this->getApplicationURI('/comment/'.$paste->getID().'/')) 90 - ->setSubmitButtonName(pht('Add Comment')); 73 + $comment_view = id(new PhabricatorPasteEditEngine()) 74 + ->setViewer($viewer) 75 + ->buildEditEngineCommentView($paste); 91 76 92 77 return $this->newPage() 93 78 ->setTitle($paste->getFullName()) ··· 101 86 $object_box, 102 87 $source_code, 103 88 $timeline, 104 - $add_comment_form, 89 + $comment_view, 105 90 )); 106 91 } 107 92
+9
src/applications/paste/editor/PhabricatorPasteEditEngine.php
··· 38 38 return pht('Create Paste'); 39 39 } 40 40 41 + protected function getCommentViewHeaderText($object) { 42 + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 43 + if (!$is_serious) { 44 + return pht('Eat Paste'); 45 + } 46 + 47 + return parent::getCommentViewHeaderText($object); 48 + } 49 + 41 50 protected function getObjectViewURI($object) { 42 51 return '/P'.$object->getID(); 43 52 }
+93
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 163 163 } 164 164 165 165 166 + /** 167 + * @task text 168 + */ 169 + protected function getCommentViewHeaderText($object) { 170 + return pht('Add Comment'); 171 + } 172 + 173 + 174 + /** 175 + * @task text 176 + */ 177 + protected function getCommentViewButtonText($object) { 178 + return pht('Add Comment'); 179 + } 180 + 181 + 166 182 /* -( Edit Engine Configuration )------------------------------------------ */ 167 183 168 184 ··· 574 590 return $this->buildParametersResponse($object); 575 591 case 'nodefault': 576 592 return $this->buildNoDefaultResponse($object); 593 + case 'comment': 594 + return $this->buildCommentResponse($object); 577 595 default: 578 596 return $this->buildEditResponse($object); 579 597 } ··· 854 872 $crumbs->addAction($action); 855 873 } 856 874 875 + final public function buildEditEngineCommentView($object) { 876 + $viewer = $this->getViewer(); 877 + $object_phid = $object->getPHID(); 878 + 879 + $header_text = $this->getCommentViewHeaderText($object); 880 + $button_text = $this->getCommentViewButtonText($object); 881 + 882 + // TODO: Drafts. 883 + // $draft = PhabricatorDraft::newFromUserAndKey( 884 + // $viewer, 885 + // $object_phid); 886 + 887 + $comment_uri = $this->getEditURI($object, 'comment/'); 888 + 889 + return id(new PhabricatorApplicationTransactionCommentView()) 890 + ->setUser($viewer) 891 + ->setObjectPHID($object_phid) 892 + ->setHeaderText($header_text) 893 + ->setAction($comment_uri) 894 + ->setSubmitButtonName($button_text); 895 + } 857 896 858 897 /* -( Responding to HTTP Parameter Requests )------------------------------ */ 859 898 ··· 910 949 'forms for creating objects.')) 911 950 ->addCancelButton($cancel_uri); 912 951 } 952 + 953 + private function buildCommentResponse($object) { 954 + $viewer = $this->getViewer(); 955 + 956 + if ($this->getIsCreate()) { 957 + return new Aphront404Response(); 958 + } 959 + 960 + $controller = $this->getController(); 961 + $request = $controller->getRequest(); 962 + 963 + if (!$request->isFormPost()) { 964 + return new Aphront400Response(); 965 + } 966 + 967 + $is_preview = $request->isPreviewRequest(); 968 + $view_uri = $this->getObjectViewURI($object); 969 + 970 + $template = $object->getApplicationTransactionTemplate(); 971 + $comment_template = $template->getApplicationTransactionCommentObject(); 972 + 973 + $xactions = array(); 974 + 975 + $xactions[] = id(clone $template) 976 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 977 + ->attachComment( 978 + id(clone $comment_template) 979 + ->setContent($request->getStr('comment'))); 980 + 981 + $editor = $object->getApplicationTransactionEditor() 982 + ->setActor($viewer) 983 + ->setContinueOnNoEffect($request->isContinueRequest()) 984 + ->setContentSourceFromRequest($request) 985 + ->setIsPreview($is_preview); 986 + 987 + try { 988 + $xactions = $editor->applyTransactions($object, $xactions); 989 + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { 990 + return id(new PhabricatorApplicationTransactionNoEffectResponse()) 991 + ->setCancelURI($view_uri) 992 + ->setException($ex); 993 + } 994 + 995 + if ($request->isAjax() && $is_preview) { 996 + return id(new PhabricatorApplicationTransactionResponse()) 997 + ->setViewer($viewer) 998 + ->setTransactions($xactions) 999 + ->setIsPreview($is_preview); 1000 + } else { 1001 + return id(new AphrontRedirectResponse()) 1002 + ->setURI($view_uri); 1003 + } 1004 + } 1005 + 913 1006 914 1007 /* -( Conduit )------------------------------------------------------------ */ 915 1008