Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/PhabricatorInlineCommentController.php
| <?php | <?php | ||||
| abstract class PhabricatorInlineCommentController | abstract class PhabricatorInlineCommentController | ||||
| extends PhabricatorController { | extends PhabricatorController { | ||||
| abstract protected function createComment(); | abstract protected function createComment(); | ||||
| abstract protected function loadComment($id); | abstract protected function loadComment($id); | ||||
| abstract protected function loadCommentForEdit($id); | abstract protected function loadCommentForEdit($id); | ||||
| abstract protected function loadCommentByPHID($phid); | |||||
| abstract protected function deleteComment( | abstract protected function deleteComment( | ||||
| PhabricatorInlineCommentInterface $inline); | PhabricatorInlineCommentInterface $inline); | ||||
| abstract protected function saveComment( | abstract protected function saveComment( | ||||
| PhabricatorInlineCommentInterface $inline); | PhabricatorInlineCommentInterface $inline); | ||||
| private $changesetID; | private $changesetID; | ||||
| private $isNewFile; | private $isNewFile; | ||||
| private $isOnRight; | private $isOnRight; | ||||
| private $lineNumber; | private $lineNumber; | ||||
| private $lineLength; | private $lineLength; | ||||
| private $commentText; | private $commentText; | ||||
| private $operation; | private $operation; | ||||
| private $commentID; | private $commentID; | ||||
| private $renderer; | private $renderer; | ||||
| private $replyToCommentPHID; | |||||
| public function getCommentID() { | public function getCommentID() { | ||||
| return $this->commentID; | return $this->commentID; | ||||
| } | } | ||||
| public function getOperation() { | public function getOperation() { | ||||
| return $this->operation; | return $this->operation; | ||||
| } | } | ||||
| Show All 26 Lines | public function setRenderer($renderer) { | ||||
| $this->renderer = $renderer; | $this->renderer = $renderer; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getRenderer() { | public function getRenderer() { | ||||
| return $this->renderer; | return $this->renderer; | ||||
| } | } | ||||
| public function setReplyToCommentPHID($phid) { | |||||
| $this->replyToCommentPHID = $phid; | |||||
| return $this; | |||||
| } | |||||
| public function getReplyToCommentPHID() { | |||||
| return $this->replyToCommentPHID; | |||||
| } | |||||
| public function processRequest() { | public function processRequest() { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $user = $request->getUser(); | $user = $request->getUser(); | ||||
| $this->readRequestParameters(); | $this->readRequestParameters(); | ||||
| switch ($this->getOperation()) { | switch ($this->getOperation()) { | ||||
| case 'delete': | case 'delete': | ||||
| Show All 36 Lines | switch ($this->getOperation()) { | ||||
| } | } | ||||
| } | } | ||||
| $edit_dialog = $this->buildEditDialog(); | $edit_dialog = $this->buildEditDialog(); | ||||
| $edit_dialog->setTitle(pht('Edit Inline Comment')); | $edit_dialog->setTitle(pht('Edit Inline Comment')); | ||||
| $edit_dialog->addHiddenInput('id', $this->getCommentID()); | $edit_dialog->addHiddenInput('id', $this->getCommentID()); | ||||
| $edit_dialog->addHiddenInput('op', 'edit'); | $edit_dialog->addHiddenInput('op', 'edit'); | ||||
| $edit_dialog->addHiddenInput('renderer', $this->getRenderer()); | |||||
| $edit_dialog->appendChild( | $edit_dialog->appendChild( | ||||
| $this->renderTextArea( | $this->renderTextArea( | ||||
| nonempty($text, $inline->getContent()))); | nonempty($text, $inline->getContent()))); | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent($edit_dialog->render()); | ->setContent($edit_dialog->render()); | ||||
| case 'create': | case 'create': | ||||
| $text = $this->getCommentText(); | $text = $this->getCommentText(); | ||||
| if (!$request->isFormPost() || !strlen($text)) { | if (!$request->isFormPost() || !strlen($text)) { | ||||
| return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
| } | } | ||||
| $inline = $this->createComment() | $inline = $this->createComment() | ||||
| ->setChangesetID($this->getChangesetID()) | ->setChangesetID($this->getChangesetID()) | ||||
| ->setAuthorPHID($user->getPHID()) | ->setAuthorPHID($user->getPHID()) | ||||
| ->setLineNumber($this->getLineNumber()) | ->setLineNumber($this->getLineNumber()) | ||||
| ->setLineLength($this->getLineLength()) | ->setLineLength($this->getLineLength()) | ||||
| ->setIsNewFile($this->getIsNewFile()) | ->setIsNewFile($this->getIsNewFile()) | ||||
| ->setContent($text); | ->setContent($text); | ||||
| if ($this->getReplyToCommentPHID()) { | |||||
| $inline->setReplyToCommentPHID($this->getReplyToCommentPHID()); | |||||
| } | |||||
| $this->saveComment($inline); | $this->saveComment($inline); | ||||
| return $this->buildRenderedCommentResponse( | return $this->buildRenderedCommentResponse( | ||||
| $inline, | $inline, | ||||
| $this->getIsOnRight()); | $this->getIsOnRight()); | ||||
| case 'reply': | case 'reply': | ||||
| default: | default: | ||||
| $edit_dialog = $this->buildEditDialog(); | $edit_dialog = $this->buildEditDialog(); | ||||
| Show All 10 Lines | switch ($this->getOperation()) { | ||||
| $edit_dialog->setTitle(pht('New Inline Comment')); | $edit_dialog->setTitle(pht('New Inline Comment')); | ||||
| $changeset = $this->getChangesetID(); | $changeset = $this->getChangesetID(); | ||||
| $is_new = $this->getIsNewFile(); | $is_new = $this->getIsNewFile(); | ||||
| $number = $this->getLineNumber(); | $number = $this->getLineNumber(); | ||||
| $length = $this->getLineLength(); | $length = $this->getLineLength(); | ||||
| } | } | ||||
| $edit_dialog->addHiddenInput('op', 'create'); | $edit_dialog->addHiddenInput('op', 'create'); | ||||
| $edit_dialog->addHiddenInput('changeset', $changeset); | |||||
| $edit_dialog->addHiddenInput('is_new', $is_new); | $edit_dialog->addHiddenInput('is_new', $is_new); | ||||
| $edit_dialog->addHiddenInput('number', $number); | $edit_dialog->addHiddenInput('number', $number); | ||||
| $edit_dialog->addHiddenInput('length', $length); | $edit_dialog->addHiddenInput('length', $length); | ||||
| $edit_dialog->addHiddenInput('renderer', $this->getRenderer()); | |||||
| $text_area = $this->renderTextArea($this->getCommentText()); | $text_area = $this->renderTextArea($this->getCommentText()); | ||||
| $edit_dialog->appendChild($text_area); | $edit_dialog->appendChild($text_area); | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent($edit_dialog->render()); | ->setContent($edit_dialog->render()); | ||||
| } | } | ||||
| } | } | ||||
| private function readRequestParameters() { | private function readRequestParameters() { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| // NOTE: This isn't necessarily a DifferentialChangeset ID, just an | // NOTE: This isn't necessarily a DifferentialChangeset ID, just an | ||||
| // application identifier for the changeset. In Diffusion, it's a Path ID. | // application identifier for the changeset. In Diffusion, it's a Path ID. | ||||
| $this->changesetID = $request->getInt('changeset'); | $this->changesetID = $request->getInt('changesetID'); | ||||
| $this->isNewFile = (int)$request->getBool('is_new'); | $this->isNewFile = (int)$request->getBool('is_new'); | ||||
| $this->isOnRight = $request->getBool('on_right'); | $this->isOnRight = $request->getBool('on_right'); | ||||
| $this->lineNumber = $request->getInt('number'); | $this->lineNumber = $request->getInt('number'); | ||||
| $this->lineLength = $request->getInt('length'); | $this->lineLength = $request->getInt('length'); | ||||
| $this->commentText = $request->getStr('text'); | $this->commentText = $request->getStr('text'); | ||||
| $this->commentID = $request->getInt('id'); | $this->commentID = $request->getInt('id'); | ||||
| $this->operation = $request->getStr('op'); | $this->operation = $request->getStr('op'); | ||||
| $this->renderer = $request->getStr('renderer'); | $this->renderer = $request->getStr('renderer'); | ||||
| $this->replyToCommentPHID = $request->getStr('replyToCommentPHID'); | |||||
| if ($this->getReplyToCommentPHID()) { | |||||
| $reply_phid = $this->getReplyToCommentPHID(); | |||||
| $reply_comment = $this->loadCommentByPHID($reply_phid); | |||||
| if (!$reply_comment) { | |||||
| throw new Exception( | |||||
| pht('Failed to load comment "%s".', $reply_phid)); | |||||
| } | |||||
| if ($reply_comment->getChangesetID() != $this->getChangesetID()) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Comment "%s" belongs to wrong changeset (%s vs %s).', | |||||
| $reply_phid, | |||||
| $reply_comment->getChangesetID(), | |||||
| $this->getChangesetID())); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| private function buildEditDialog() { | private function buildEditDialog() { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $user = $request->getUser(); | $user = $request->getUser(); | ||||
| $edit_dialog = id(new PHUIDiffInlineCommentEditView()) | $edit_dialog = id(new PHUIDiffInlineCommentEditView()) | ||||
| ->setUser($user) | ->setUser($user) | ||||
| ->setSubmitURI($request->getRequestURI()) | ->setSubmitURI($request->getRequestURI()) | ||||
| ->setOnRight($this->getIsOnRight()) | ->setOnRight($this->getIsOnRight()) | ||||
| ->setIsNewFile($this->getIsNewFile()) | ->setIsNewFile($this->getIsNewFile()) | ||||
| ->setNumber($this->getLineNumber()) | ->setNumber($this->getLineNumber()) | ||||
| ->setLength($this->getLineLength()) | ->setLength($this->getLineLength()) | ||||
| ->setRenderer($this->getRenderer()); | ->setRenderer($this->getRenderer()) | ||||
| ->setReplyToCommentPHID($this->getReplyToCommentPHID()) | |||||
| ->setChangesetID($this->getChangesetID()); | |||||
| return $edit_dialog; | return $edit_dialog; | ||||
| } | } | ||||
| private function buildEmptyResponse() { | private function buildEmptyResponse() { | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent( | ->setContent( | ||||
| array( | array( | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||