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

Use PHUIRemarkupPreviewPanel in Ponder

Summary:
Ref T3578. Ref T3671. Depends on D6673. Use `PHUIRemarkupPreviewPanel` (introduced in D6673) to provide question create/edit and answer edit previews in Ponder.

Then delete a million lines of duplicate code.

Test Plan: Edited a question; edited an answer. Saw live previews.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3578, T3671

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

+17 -219
+1 -14
src/__celerity_resource_map__.php
··· 2268 2268 ), 2269 2269 'disk' => '/rsrc/js/application/phriction/phriction-document-preview.js', 2270 2270 ), 2271 - 'javelin-behavior-ponder-feedback-preview' => 2272 - array( 2273 - 'uri' => '/res/2e802dd9/rsrc/js/application/ponder/behavior-comment-preview.js', 2274 - 'type' => 'js', 2275 - 'requires' => 2276 - array( 2277 - 0 => 'javelin-behavior', 2278 - 1 => 'javelin-dom', 2279 - 2 => 'javelin-util', 2280 - 3 => 'phabricator-shaped-request', 2281 - ), 2282 - 'disk' => '/rsrc/js/application/ponder/behavior-comment-preview.js', 2283 - ), 2284 2271 'javelin-behavior-ponder-votebox' => 2285 2272 array( 2286 2273 'uri' => '/res/c28daa12/rsrc/js/application/ponder/behavior-votebox.js', ··· 3866 3853 ), 3867 3854 'phui-remarkup-preview-css' => 3868 3855 array( 3869 - 'uri' => '/res/702b30c4/rsrc/css/phui/phui-remarkup-preview.css', 3856 + 'uri' => '/res/80d54c8c/rsrc/css/phui/phui-remarkup-preview.css', 3870 3857 'type' => 'css', 3871 3858 'requires' => 3872 3859 array(
-6
src/__phutil_library_map__.php
··· 1899 1899 'PonderConstants' => 'applications/ponder/constants/PonderConstants.php', 1900 1900 'PonderController' => 'applications/ponder/controller/PonderController.php', 1901 1901 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php', 1902 - 'PonderLiterals' => 'applications/ponder/constants/PonderLiterals.php', 1903 1902 'PonderPHIDTypeAnswer' => 'applications/ponder/phid/PonderPHIDTypeAnswer.php', 1904 1903 'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php', 1905 - 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 1906 1904 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 1907 1905 'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php', 1908 1906 'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php', ··· 1910 1908 'PonderQuestionHistoryController' => 'applications/ponder/controller/PonderQuestionHistoryController.php', 1911 1909 'PonderQuestionListController' => 'applications/ponder/controller/PonderQuestionListController.php', 1912 1910 'PonderQuestionMailReceiver' => 'applications/ponder/mail/PonderQuestionMailReceiver.php', 1913 - 'PonderQuestionPreviewController' => 'applications/ponder/controller/PonderQuestionPreviewController.php', 1914 1911 'PonderQuestionQuery' => 'applications/ponder/query/PonderQuestionQuery.php', 1915 1912 'PonderQuestionReplyHandler' => 'applications/ponder/mail/PonderQuestionReplyHandler.php', 1916 1913 'PonderQuestionSearchEngine' => 'applications/ponder/query/PonderQuestionSearchEngine.php', ··· 4034 4031 'PonderCommentQuery' => 'PhabricatorQuery', 4035 4032 'PonderController' => 'PhabricatorController', 4036 4033 'PonderDAO' => 'PhabricatorLiskDAO', 4037 - 'PonderLiterals' => 'PonderConstants', 4038 4034 'PonderPHIDTypeAnswer' => 'PhabricatorPHIDType', 4039 4035 'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType', 4040 - 'PonderPostBodyView' => 'AphrontView', 4041 4036 'PonderQuestion' => 4042 4037 array( 4043 4038 0 => 'PonderDAO', ··· 4057 4052 1 => 'PhabricatorApplicationSearchResultsControllerInterface', 4058 4053 ), 4059 4054 'PonderQuestionMailReceiver' => 'PhabricatorObjectMailReceiver', 4060 - 'PonderQuestionPreviewController' => 'PonderController', 4061 4055 'PonderQuestionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4062 4056 'PonderQuestionReplyHandler' => 'PhabricatorMailReplyHandler', 4063 4057 'PonderQuestionSearchEngine' => 'PhabricatorApplicationSearchEngine',
+1 -1
src/applications/ponder/application/PhabricatorApplicationPonder.php
··· 57 57 'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController', 58 58 'question/comment/(?P<id>\d+)/' => 'PonderQuestionCommentController', 59 59 'question/history/(?P<id>\d+)/' => 'PonderQuestionHistoryController', 60 - 'question/preview/' => 'PonderQuestionPreviewController', 60 + 'preview/' => 'PhabricatorMarkupPreviewController', 61 61 'question/(?P<status>open|close)/(?P<id>[1-9]\d*)/' => 62 62 'PonderQuestionStatusController', 63 63 'vote/' => 'PonderVoteSaveController',
-10
src/applications/ponder/constants/PonderLiterals.php
··· 1 - <?php 2 - /** 3 - * @group ponder 4 - */ 5 - final class PonderLiterals extends PonderConstants { 6 - 7 - const LITERAL_ANSWERED = "answered"; 8 - const LITERAL_ASKED = "asked"; 9 - 10 - }
+9
src/applications/ponder/controller/PonderAnswerEditController.php
··· 66 66 $errors = id(new AphrontErrorView())->setErrors($errors); 67 67 } 68 68 69 + $answer_content_id = celerity_generate_unique_node_id(); 70 + 69 71 $form = id(new AphrontFormView()) 70 72 ->setUser($viewer) 71 73 ->appendChild( ··· 76 78 id(new PhabricatorRemarkupControl()) 77 79 ->setLabel(pht('Answer')) 78 80 ->setName('content') 81 + ->setID($answer_content_id) 79 82 ->setValue($v_content) 80 83 ->setError($e_content)) 81 84 ->appendChild( ··· 92 95 id(new PhabricatorCrumbView()) 93 96 ->setName(pht('Edit Answer'))); 94 97 98 + $preview = id(new PHUIRemarkupPreviewPanel()) 99 + ->setHeader(pht('Answer Preview')) 100 + ->setControlID($answer_content_id) 101 + ->setPreviewURI($this->getApplicationURI('preview/')); 102 + 95 103 return $this->buildApplicationPage( 96 104 array( 97 105 $crumbs, 98 106 $errors, 99 107 $form, 108 + $preview, 100 109 ), 101 110 array( 102 111 'title' => pht('Edit Answer'),
+4 -16
src/applications/ponder/controller/PonderQuestionEditController.php
··· 104 104 ->addCancelButton($this->getApplicationURI()) 105 105 ->setValue(pht('Ask Away!'))); 106 106 107 - $preview = hsprintf( 108 - '<div class="aphront-panel-flush">'. 109 - '<div id="question-preview">'. 110 - '<span class="aphront-panel-preview-loading-text">%s</span>'. 111 - '</div>'. 112 - '</div>', 113 - pht('Loading question preview...')); 114 - 115 - Javelin::initBehavior( 116 - 'ponder-feedback-preview', 117 - array( 118 - 'uri' => '/ponder/question/preview/', 119 - 'content' => 'content', 120 - 'preview' => 'question-preview', 121 - 'question_id' => null 122 - )); 107 + $preview = id(new PHUIRemarkupPreviewPanel()) 108 + ->setHeader(pht('Question Preview')) 109 + ->setControlID('content') 110 + ->setPreviewURI($this->getApplicationURI('preview/')); 123 111 124 112 $crumbs = $this->buildApplicationCrumbs(); 125 113
-35
src/applications/ponder/controller/PonderQuestionPreviewController.php
··· 1 - <?php 2 - 3 - final class PonderQuestionPreviewController 4 - extends PonderController { 5 - 6 - const VERB_ASKED = "asked"; 7 - 8 - public function processRequest() { 9 - 10 - $request = $this->getRequest(); 11 - 12 - $user = $request->getUser(); 13 - $author_phid = $user->getPHID(); 14 - 15 - $object_phids = array($author_phid); 16 - $handles = $this->loadViewerHandles($object_phids); 17 - 18 - $question = new PonderQuestion(); 19 - $question->setContent($request->getStr('content')); 20 - $question->setAuthorPHID($author_phid); 21 - 22 - $view = new PonderPostBodyView(); 23 - $view 24 - ->setQuestion($question) 25 - ->setTarget($question) 26 - ->setPreview(true) 27 - ->setUser($user) 28 - ->setHandles($handles) 29 - ->setAction(self::VERB_ASKED); 30 - 31 - return id(new AphrontAjaxResponse()) 32 - ->setContent($view->render()); 33 - } 34 - 35 - }
+2 -2
src/applications/ponder/view/PonderAddAnswerView.php
··· 41 41 ->appendChild( 42 42 id(new AphrontFormSubmitControl()) 43 43 ->setValue($is_serious ? 44 - pht('Submit') : 45 - pht('Make it so'))); 44 + pht('Add Answer') : 45 + pht('Bequeath Wisdom'))); 46 46 47 47 return id(new AphrontNullView()) 48 48 ->appendChild(
-103
src/applications/ponder/view/PonderPostBodyView.php
··· 1 - <?php 2 - 3 - final class PonderPostBodyView extends AphrontView { 4 - 5 - private $target; 6 - private $question; 7 - private $handles; 8 - private $preview; 9 - private $anchorName; 10 - private $action; 11 - 12 - public function setQuestion($question) { 13 - $this->question = $question; 14 - return $this; 15 - } 16 - 17 - public function setTarget($target) { 18 - $this->target = $target; 19 - return $this; 20 - } 21 - 22 - public function setAction($action) { 23 - $this->action = $action; 24 - return $this; 25 - } 26 - 27 - public function setHandles(array $handles) { 28 - assert_instances_of($handles, 'PhabricatorObjectHandle'); 29 - $this->handles = $handles; 30 - return $this; 31 - } 32 - 33 - public function setPreview($preview) { 34 - $this->preview = $preview; 35 - return $this; 36 - } 37 - 38 - public function render() { 39 - 40 - if (!$this->user) { 41 - throw new Exception("Call setUser() before rendering!"); 42 - } 43 - 44 - require_celerity_resource('phabricator-remarkup-css'); 45 - require_celerity_resource('ponder-post-css'); 46 - 47 - $user = $this->user; 48 - $question = $this->question; 49 - $target = $this->target; 50 - $content = $target->getContent(); 51 - $info = array(); 52 - 53 - 54 - $content = PhabricatorMarkupEngine::renderOneObject( 55 - $target, 56 - $target->getMarkupField(), 57 - $this->user); 58 - 59 - $content = phutil_tag( 60 - 'div', 61 - array( 62 - 'class' => 'phabricator-remarkup', 63 - ), 64 - $content); 65 - 66 - $author = $this->handles[$target->getAuthorPHID()]; 67 - $actions = array(hsprintf('%s %s', $author->renderLink(), $this->action)); 68 - $author_link = $author->renderLink(); 69 - $xaction_view = id(new PhabricatorTransactionView()) 70 - ->setUser($user) 71 - ->setImageURI($author->getImageURI()) 72 - ->setContentSource($target->getContentSource()) 73 - ->setActions($actions); 74 - 75 - if ($this->target instanceof PonderAnswer) { 76 - $xaction_view->addClass("ponder-answer"); 77 - } else { 78 - $xaction_view->addClass("ponder-question"); 79 - } 80 - 81 - if ($this->preview) { 82 - $xaction_view->setIsPreview($this->preview); 83 - } else { 84 - $xaction_view->setEpoch($target->getDateCreated()); 85 - if ($this->target instanceof PonderAnswer) { 86 - $anchor_text = 'Q' . $question->getID(). '#A' . $target->getID(); 87 - $xaction_view->setAnchor('A'.$target->getID(), $anchor_text); 88 - $xaction_view->addClass("ponder-answer"); 89 - } 90 - } 91 - 92 - $xaction_view->appendChild( 93 - phutil_tag( 94 - 'div', 95 - array( 96 - 'class' => 'ponder-post-core', 97 - ), 98 - $content)); 99 - 100 - return $xaction_view; 101 - } 102 - 103 - }
-32
webroot/rsrc/js/application/ponder/behavior-comment-preview.js
··· 1 - /** 2 - * @provides javelin-behavior-ponder-feedback-preview 3 - * @requires javelin-behavior 4 - * javelin-dom 5 - * javelin-util 6 - * phabricator-shaped-request 7 - */ 8 - 9 - JX.behavior('ponder-feedback-preview', function(config) { 10 - 11 - var content = JX.$(config.content); 12 - var question_id = config.question_id; 13 - 14 - var callback = function(r) { 15 - JX.DOM.setContent(JX.$(config.preview), JX.$H(r)); 16 - }; 17 - 18 - var getdata = function() { 19 - var data = { 20 - content : content.value, 21 - question_id : question_id 22 - }; 23 - return data; 24 - }; 25 - 26 - var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata); 27 - var trigger = JX.bind(request, request.trigger); 28 - 29 - JX.DOM.listen(content, 'keydown', null, trigger); 30 - 31 - request.start(); 32 - });