diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0d750ba6f3..a67662ba3c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2605,7 +2605,6 @@ phutil_register_library_map(array( 'PhabricatorPasswordSettingsPanel' => 'applications/settings/panel/PhabricatorPasswordSettingsPanel.php', 'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php', 'PhabricatorPasteApplication' => 'applications/paste/application/PhabricatorPasteApplication.php', - 'PhabricatorPasteCommentController' => 'applications/paste/controller/PhabricatorPasteCommentController.php', 'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php', 'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php', 'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php', @@ -6800,7 +6799,6 @@ phutil_register_library_map(array( 'PhabricatorSpacesInterface', ), 'PhabricatorPasteApplication' => 'PhabricatorApplication', - 'PhabricatorPasteCommentController' => 'PhabricatorPasteController', 'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorPasteController' => 'PhabricatorController', 'PhabricatorPasteDAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/base/PhabricatorApplication.php b/src/applications/base/PhabricatorApplication.php index f4e5931002..dff4106324 100644 --- a/src/applications/base/PhabricatorApplication.php +++ b/src/applications/base/PhabricatorApplication.php @@ -640,7 +640,7 @@ abstract class PhabricatorApplication '(?P[0-9]\d*)/)?'. '(?:'. '(?:'. - '(?Pparameters|nodefault)'. + '(?Pparameters|nodefault|comment)'. '|'. '(?:form/(?P[^/]+))'. ')'. diff --git a/src/applications/paste/application/PhabricatorPasteApplication.php b/src/applications/paste/application/PhabricatorPasteApplication.php index e066d4cd9d..4ffc18ccc6 100644 --- a/src/applications/paste/application/PhabricatorPasteApplication.php +++ b/src/applications/paste/application/PhabricatorPasteApplication.php @@ -41,7 +41,6 @@ final class PhabricatorPasteApplication extends PhabricatorApplication { 'create/' => 'PhabricatorPasteEditController', $this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController', 'raw/(?P[1-9]\d*)/' => 'PhabricatorPasteRawController', - 'comment/(?P[1-9]\d*)/' => 'PhabricatorPasteCommentController', ), ); } diff --git a/src/applications/paste/controller/PhabricatorPasteCommentController.php b/src/applications/paste/controller/PhabricatorPasteCommentController.php deleted file mode 100644 index 06596e5be7..0000000000 --- a/src/applications/paste/controller/PhabricatorPasteCommentController.php +++ /dev/null @@ -1,63 +0,0 @@ -getViewer(); - $id = $request->getURIData('id'); - - if (!$request->isFormPost()) { - return new Aphront400Response(); - } - - $paste = id(new PhabricatorPasteQuery()) - ->setViewer($viewer) - ->withIDs(array($id)) - ->executeOne(); - if (!$paste) { - return new Aphront404Response(); - } - - $is_preview = $request->isPreviewRequest(); - $draft = PhabricatorDraft::buildFromRequest($request); - - $view_uri = $paste->getURI(); - - $xactions = array(); - $xactions[] = id(new PhabricatorPasteTransaction()) - ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) - ->attachComment( - id(new PhabricatorPasteTransactionComment()) - ->setContent($request->getStr('comment'))); - - $editor = id(new PhabricatorPasteEditor()) - ->setActor($viewer) - ->setContinueOnNoEffect($request->isContinueRequest()) - ->setContentSourceFromRequest($request) - ->setIsPreview($is_preview); - - try { - $xactions = $editor->applyTransactions($paste, $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/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php index 43a7058f59..4302e33d95 100644 --- a/src/applications/paste/controller/PhabricatorPasteViewController.php +++ b/src/applications/paste/controller/PhabricatorPasteViewController.php @@ -1,8 +1,5 @@ getPHID()); - - $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) - ->setUser($viewer) - ->setObjectPHID($paste->getPHID()) - ->setDraft($draft) - ->setHeaderText($add_comment_header) - ->setAction($this->getApplicationURI('/comment/'.$paste->getID().'/')) - ->setSubmitButtonName(pht('Add Comment')); + $comment_view = id(new PhabricatorPasteEditEngine()) + ->setViewer($viewer) + ->buildEditEngineCommentView($paste); return $this->newPage() ->setTitle($paste->getFullName()) @@ -101,7 +86,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController { $object_box, $source_code, $timeline, - $add_comment_form, + $comment_view, )); } diff --git a/src/applications/paste/editor/PhabricatorPasteEditEngine.php b/src/applications/paste/editor/PhabricatorPasteEditEngine.php index ce03a7ff06..2a8ebb4798 100644 --- a/src/applications/paste/editor/PhabricatorPasteEditEngine.php +++ b/src/applications/paste/editor/PhabricatorPasteEditEngine.php @@ -38,6 +38,15 @@ final class PhabricatorPasteEditEngine return pht('Create Paste'); } + protected function getCommentViewHeaderText($object) { + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); + if (!$is_serious) { + return pht('Eat Paste'); + } + + return parent::getCommentViewHeaderText($object); + } + protected function getObjectViewURI($object) { return '/P'.$object->getID(); } diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php index 94284b2caa..fb766317a0 100644 --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -163,6 +163,22 @@ abstract class PhabricatorEditEngine } + /** + * @task text + */ + protected function getCommentViewHeaderText($object) { + return pht('Add Comment'); + } + + + /** + * @task text + */ + protected function getCommentViewButtonText($object) { + return pht('Add Comment'); + } + + /* -( Edit Engine Configuration )------------------------------------------ */ @@ -574,6 +590,8 @@ abstract class PhabricatorEditEngine return $this->buildParametersResponse($object); case 'nodefault': return $this->buildNoDefaultResponse($object); + case 'comment': + return $this->buildCommentResponse($object); default: return $this->buildEditResponse($object); } @@ -854,6 +872,27 @@ abstract class PhabricatorEditEngine $crumbs->addAction($action); } + final public function buildEditEngineCommentView($object) { + $viewer = $this->getViewer(); + $object_phid = $object->getPHID(); + + $header_text = $this->getCommentViewHeaderText($object); + $button_text = $this->getCommentViewButtonText($object); + + // TODO: Drafts. + // $draft = PhabricatorDraft::newFromUserAndKey( + // $viewer, + // $object_phid); + + $comment_uri = $this->getEditURI($object, 'comment/'); + + return id(new PhabricatorApplicationTransactionCommentView()) + ->setUser($viewer) + ->setObjectPHID($object_phid) + ->setHeaderText($header_text) + ->setAction($comment_uri) + ->setSubmitButtonName($button_text); + } /* -( Responding to HTTP Parameter Requests )------------------------------ */ @@ -911,6 +950,60 @@ abstract class PhabricatorEditEngine ->addCancelButton($cancel_uri); } + private function buildCommentResponse($object) { + $viewer = $this->getViewer(); + + if ($this->getIsCreate()) { + return new Aphront404Response(); + } + + $controller = $this->getController(); + $request = $controller->getRequest(); + + if (!$request->isFormPost()) { + return new Aphront400Response(); + } + + $is_preview = $request->isPreviewRequest(); + $view_uri = $this->getObjectViewURI($object); + + $template = $object->getApplicationTransactionTemplate(); + $comment_template = $template->getApplicationTransactionCommentObject(); + + $xactions = array(); + + $xactions[] = id(clone $template) + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) + ->attachComment( + id(clone $comment_template) + ->setContent($request->getStr('comment'))); + + $editor = $object->getApplicationTransactionEditor() + ->setActor($viewer) + ->setContinueOnNoEffect($request->isContinueRequest()) + ->setContentSourceFromRequest($request) + ->setIsPreview($is_preview); + + try { + $xactions = $editor->applyTransactions($object, $xactions); + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { + return id(new PhabricatorApplicationTransactionNoEffectResponse()) + ->setCancelURI($view_uri) + ->setException($ex); + } + + if ($request->isAjax() && $is_preview) { + return id(new PhabricatorApplicationTransactionResponse()) + ->setViewer($viewer) + ->setTransactions($xactions) + ->setIsPreview($is_preview); + } else { + return id(new AphrontRedirectResponse()) + ->setURI($view_uri); + } + } + + /* -( Conduit )------------------------------------------------------------ */