From 15f9e0f6ea2fc55fbcb6f22229c24a3f34e7cf53 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 6 Jul 2016 12:24:36 -0700 Subject: [PATCH] Use CommentEditEngine in PhamePost Summary: Ref T9360. Moves PhamePost to CommentEditEngine. [x] HTTP Parameters dropdown on New Post goes to 404 [x] Implement EditEngine Comments Test Plan: Make Post, Make Comment, Laugh. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9360 Differential Revision: https://secure.phabricator.com/D16222 --- resources/celerity/map.php | 4 +- src/__phutil_library_map__.php | 4 +- .../PhabricatorPhameApplication.php | 15 +++-- .../post/PhamePostCommentController.php | 63 ------------------- .../post/PhamePostViewController.php | 25 ++++---- .../phame/editor/PhamePostEditEngine.php | 4 ++ .../phame/mail/PhamePostMailReceiver.php | 2 +- .../phid/PhabricatorPhamePostPHIDType.php | 4 +- .../phame/remarkup/PhamePostRemarkupRule.php | 19 ++++++ src/applications/phame/storage/PhamePost.php | 4 ++ webroot/rsrc/css/application/phame/phame.css | 4 ++ 11 files changed, 60 insertions(+), 88 deletions(-) delete mode 100644 src/applications/phame/controller/post/PhamePostCommentController.php create mode 100644 src/applications/phame/remarkup/PhamePostRemarkupRule.php diff --git a/resources/celerity/map.php b/resources/celerity/map.php index cd3ef696ae..944dc09de6 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -81,7 +81,7 @@ return array( 'rsrc/css/application/owners/owners-path-editor.css' => '2f00933b', 'rsrc/css/application/paste/paste.css' => '1898e534', 'rsrc/css/application/people/people-profile.css' => '2473d929', - 'rsrc/css/application/phame/phame.css' => 'bf6a743f', + 'rsrc/css/application/phame/phame.css' => '8efb0729', 'rsrc/css/application/pholio/pholio-edit.css' => '07676f51', 'rsrc/css/application/pholio/pholio-inline-comments.css' => '8e545e49', 'rsrc/css/application/pholio/pholio.css' => 'ca89d380', @@ -811,7 +811,7 @@ return array( 'phabricator-uiexample-reactor-sendclass' => '1def2711', 'phabricator-uiexample-reactor-sendproperties' => 'b1f0ccee', 'phabricator-zindex-css' => '5b6fcf3f', - 'phame-css' => 'bf6a743f', + 'phame-css' => '8efb0729', 'pholio-css' => 'ca89d380', 'pholio-edit-css' => '07676f51', 'pholio-inline-comments-css' => '8e545e49', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e8c4ab5e87..791c4f8e5e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3834,7 +3834,6 @@ phutil_register_library_map(array( 'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php', 'PhamePost' => 'applications/phame/storage/PhamePost.php', 'PhamePostArchiveController' => 'applications/phame/controller/post/PhamePostArchiveController.php', - 'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php', 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', 'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php', 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', @@ -3848,6 +3847,7 @@ phutil_register_library_map(array( 'PhamePostMoveController' => 'applications/phame/controller/post/PhamePostMoveController.php', 'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php', 'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php', + 'PhamePostRemarkupRule' => 'applications/phame/remarkup/PhamePostRemarkupRule.php', 'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php', 'PhamePostSearchConduitAPIMethod' => 'applications/phame/conduit/PhamePostSearchConduitAPIMethod.php', 'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php', @@ -8760,7 +8760,6 @@ phutil_register_library_map(array( 'PhabricatorFulltextInterface', ), 'PhamePostArchiveController' => 'PhamePostController', - 'PhamePostCommentController' => 'PhamePostController', 'PhamePostController' => 'PhameController', 'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhamePostEditController' => 'PhamePostController', @@ -8774,6 +8773,7 @@ phutil_register_library_map(array( 'PhamePostMoveController' => 'PhamePostController', 'PhamePostPublishController' => 'PhamePostController', 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhamePostRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhamePostSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/phame/application/PhabricatorPhameApplication.php b/src/applications/phame/application/PhabricatorPhameApplication.php index d385b65215..16fd83f5b0 100644 --- a/src/applications/phame/application/PhabricatorPhameApplication.php +++ b/src/applications/phame/application/PhabricatorPhameApplication.php @@ -37,7 +37,8 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { public function getRoutes() { return array( - '/phame/' => array( + '/J(?P[1-9]\d*)' => 'PhamePostViewController', + '/phame/' => array( '' => 'PhameHomeController', // NOTE: The live routes include an initial "/", so leave it off @@ -46,17 +47,16 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { 'post/' => array( '(?:query/(?P[^/]+)/)?' => 'PhamePostListController', 'blogger/(?P[\w\.-_]+)/' => 'PhamePostListController', - 'edit/(?:(?P[^/]+)/)?' => 'PhamePostEditController', + $this->getEditRoutePattern('edit/') + => 'PhamePostEditController', 'history/(?P\d+)/' => 'PhamePostHistoryController', 'view/(?P\d+)/(?:(?P[^/]+)/)?' => 'PhamePostViewController', '(?Ppublish|unpublish)/(?P\d+)/' => 'PhamePostPublishController', 'preview/(?P\d+)/' => 'PhamePostPreviewController', 'preview/' => 'PhabricatorMarkupPreviewController', - 'framed/(?P\d+)/' => 'PhamePostFramedController', 'move/(?P\d+)/' => 'PhamePostMoveController', 'archive/(?P\d+)/' => 'PhamePostArchiveController', - 'comment/(?P[1-9]\d*)/' => 'PhamePostCommentController', ), 'blog/' => array( '(?:query/(?P[^/]+)/)?' => 'PhameBlogListController', @@ -107,6 +107,13 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { ); } + public function getRemarkupRules() { + return array( + new PhamePostRemarkupRule(), + ); + } + + protected function getCustomCapabilities() { return array( PhameBlogCreateCapability::CAPABILITY => array( diff --git a/src/applications/phame/controller/post/PhamePostCommentController.php b/src/applications/phame/controller/post/PhamePostCommentController.php deleted file mode 100644 index 54c041ef94..0000000000 --- a/src/applications/phame/controller/post/PhamePostCommentController.php +++ /dev/null @@ -1,63 +0,0 @@ -getViewer(); - $id = $request->getURIData('id'); - - if (!$request->isFormPost()) { - return new Aphront400Response(); - } - - $post = id(new PhamePostQuery()) - ->setViewer($viewer) - ->withIDs(array($id)) - ->executeOne(); - if (!$post) { - return new Aphront404Response(); - } - - $is_preview = $request->isPreviewRequest(); - $draft = PhabricatorDraft::buildFromRequest($request); - - $view_uri = $this->getApplicationURI('post/view/'.$post->getID().'/'); - - $xactions = array(); - $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) - ->attachComment( - id(new PhamePostTransactionComment()) - ->setContent($request->getStr('comment'))); - - $editor = id(new PhamePostEditor()) - ->setActor($viewer) - ->setContinueOnNoEffect($request->isContinueRequest()) - ->setContentSourceFromRequest($request) - ->setIsPreview($is_preview); - - try { - $xactions = $editor->applyTransactions($post, $xactions); - } catch (PhabricatorApplicationTransactionNoEffectException $ex) { - return id(new PhabricatorApplicationTransactionNoEffectResponse()) - ->setCancelURI($view_uri) - ->setException($ex); - } - - if ($draft) { - $draft->replaceOrDelete(); - } - - if ($request->isAjax() && $is_preview) { - return id(new PhabricatorApplicationTransactionResponse()) - ->setViewer($viewer) - ->setTransactions($xactions) - ->setIsPreview($is_preview); - } else { - return id(new AphrontRedirectResponse()) - ->setURI($view_uri); - } - } - -} diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index f7dddebe53..a056502349 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -123,19 +123,22 @@ final class PhamePostViewController ->setImage($blogger->getProfileImageURI()) ->setImageHref($author_uri); + $monogram = $post->getMonogram(); $timeline = $this->buildTransactionTimeline( $post, id(new PhamePostTransactionQuery()) ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT))); - $timeline = phutil_tag_div('phui-document-view-pro-box', $timeline); + $timeline->setQuoteRef($monogram); if ($is_external) { $add_comment = null; } else { - $add_comment = $this->buildCommentForm($post); - $add_comment = phutil_tag_div('mlb mlt', $add_comment); + $add_comment = $this->buildCommentForm($post, $timeline); + $add_comment = phutil_tag_div('mlb mlt phame-comment-view', $add_comment); } + $timeline = phutil_tag_div('phui-document-view-pro-box', $timeline); + list($prev, $next) = $this->loadAdjacentPosts($post); $properties = id(new PHUIPropertyListView()) @@ -273,19 +276,13 @@ final class PhamePostViewController return $actions; } - private function buildCommentForm(PhamePost $post) { + private function buildCommentForm(PhamePost $post, $timeline) { $viewer = $this->getViewer(); - $draft = PhabricatorDraft::newFromUserAndKey( - $viewer, $post->getPHID()); - - $box = id(new PhabricatorApplicationTransactionCommentView()) - ->setUser($viewer) - ->setObjectPHID($post->getPHID()) - ->setDraft($draft) - ->setHeaderText(pht('Add Comment')) - ->setAction($this->getApplicationURI('post/comment/'.$post->getID().'/')) - ->setSubmitButtonName(pht('Add Comment')); + $box = id(new PhamePostEditEngine()) + ->setViewer($viewer) + ->buildEditEngineCommentView($post) + ->setTransactionTimeline($timeline); return phutil_tag_div('phui-document-view-pro-box', $box); } diff --git a/src/applications/phame/editor/PhamePostEditEngine.php b/src/applications/phame/editor/PhamePostEditEngine.php index 1c58722e2e..382ef3f8ff 100644 --- a/src/applications/phame/editor/PhamePostEditEngine.php +++ b/src/applications/phame/editor/PhamePostEditEngine.php @@ -68,6 +68,10 @@ final class PhamePostEditEngine return $object->getViewURI(); } + protected function getEditorURI() { + return $this->getApplication()->getApplicationURI('post/edit/'); + } + protected function buildCustomEditFields($object) { $blog_phid = $object->getBlog()->getPHID(); diff --git a/src/applications/phame/mail/PhamePostMailReceiver.php b/src/applications/phame/mail/PhamePostMailReceiver.php index 975d64a668..3655e73906 100644 --- a/src/applications/phame/mail/PhamePostMailReceiver.php +++ b/src/applications/phame/mail/PhamePostMailReceiver.php @@ -9,7 +9,7 @@ final class PhamePostMailReceiver } protected function getObjectPattern() { - return 'POST[1-9]\d*'; + return 'J[1-9]\d*'; } protected function loadObject($pattern, PhabricatorUser $viewer) { diff --git a/src/applications/phame/phid/PhabricatorPhamePostPHIDType.php b/src/applications/phame/phid/PhabricatorPhamePostPHIDType.php index 4250c91949..7c86d89d41 100644 --- a/src/applications/phame/phid/PhabricatorPhamePostPHIDType.php +++ b/src/applications/phame/phid/PhabricatorPhamePostPHIDType.php @@ -32,8 +32,8 @@ final class PhabricatorPhamePostPHIDType extends PhabricatorPHIDType { foreach ($handles as $phid => $handle) { $post = $objects[$phid]; $handle->setName($post->getTitle()); - $handle->setFullName($post->getTitle()); - $handle->setURI('/phame/post/view/'.$post->getID().'/'); + $handle->setFullName(pht('Blog Post: ').$post->getTitle()); + $handle->setURI('/J'.$post->getID()); if ($post->isArchived()) { $handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED); diff --git a/src/applications/phame/remarkup/PhamePostRemarkupRule.php b/src/applications/phame/remarkup/PhamePostRemarkupRule.php new file mode 100644 index 0000000000..92a2f0d350 --- /dev/null +++ b/src/applications/phame/remarkup/PhamePostRemarkupRule.php @@ -0,0 +1,19 @@ +getEngine()->getConfig('viewer'); + + return id(new PhamePostQuery()) + ->setViewer($viewer) + ->withIDs($ids) + ->execute(); + } + +} diff --git a/src/applications/phame/storage/PhamePost.php b/src/applications/phame/storage/PhamePost.php index 4c4acf4dc1..351bcb5dc0 100644 --- a/src/applications/phame/storage/PhamePost.php +++ b/src/applications/phame/storage/PhamePost.php @@ -51,6 +51,10 @@ final class PhamePost extends PhameDAO return $this->assertAttached($this->blog); } + public function getMonogram() { + return 'J'.$this->getID(); + } + public function getLiveURI() { $blog = $this->getBlog(); $is_draft = $this->isDraft(); diff --git a/webroot/rsrc/css/application/phame/phame.css b/webroot/rsrc/css/application/phame/phame.css index eca45b7741..75f1326af7 100644 --- a/webroot/rsrc/css/application/phame/phame.css +++ b/webroot/rsrc/css/application/phame/phame.css @@ -308,3 +308,7 @@ font-family: 'Aleo', {$fontfamily}; padding-top: 8px; } + +.phame-comment-view .aphront-form-control.aphront-form-control-select { + display: none; +}