2011-02-02 01:42:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DifferentialInlineCommentEditController extends DifferentialController {
|
|
|
|
|
|
|
|
private $revisionID;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->revisionID = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$changeset = $request->getInt('changeset');
|
Fix "reply" link in Differential
Summary:
Fixes the issue caused by rPa0af5b66437719dba6136579c051982ab275e6a0. Prior to
that patch, isCommentInNewFile() returned $comment->getIsNewFile(). While this
was often the wrong value, it came from the database and was the integer 1 if
true.
After the patch, the function returns 'true' as a boolean, which is passed to JS
and then back to PHP, interpreted as an integer, and evaluates to 0.
To avoid this issue in general, provide an isBool() method on AphrontRequest
which interprets this correctly.
I will also revert the revert of rPa0af5b66437719dba6136579c051982ab275e6a0 when
I land this.
Test Plan:
Clicked "reply" on the right hand side of a diff, got a right-hand-side inline
comment.
Reviewed By: rm
Reviewers: tuomaspelkonen, jungejason, aran, rm
CC: simpkins, aran, epriestley, rm
Differential Revision: 250
2011-05-07 19:42:40 +02:00
|
|
|
$is_new = $request->getBool('is_new');
|
|
|
|
$on_right = $request->getBool('on_right');
|
2011-02-02 01:42:36 +01:00
|
|
|
$number = $request->getInt('number');
|
|
|
|
$length = $request->getInt('length');
|
|
|
|
$text = $request->getStr('text');
|
|
|
|
$op = $request->getStr('op');
|
2011-02-02 19:10:25 +01:00
|
|
|
$inline_id = $request->getInt('id');
|
2011-02-02 01:42:36 +01:00
|
|
|
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$submit_uri = '/differential/comment/inline/edit/'.$this->revisionID.'/';
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog = new AphrontDialogView();
|
|
|
|
$edit_dialog->setUser($user);
|
|
|
|
$edit_dialog->setSubmitURI($submit_uri);
|
|
|
|
|
|
|
|
$edit_dialog->addHiddenInput('on_right', $on_right);
|
|
|
|
|
|
|
|
$edit_dialog->addSubmitButton();
|
|
|
|
$edit_dialog->addCancelButton('#');
|
|
|
|
|
|
|
|
$inline = null;
|
|
|
|
if ($inline_id) {
|
|
|
|
$inline = id(new DifferentialInlineComment())
|
|
|
|
->load($inline_id);
|
|
|
|
|
|
|
|
if (!$inline ||
|
|
|
|
$inline->getAuthorPHID() != $user->getPHID() ||
|
|
|
|
$inline->getCommentID() ||
|
|
|
|
$inline->getRevisionID() != $this->revisionID) {
|
|
|
|
throw new Exception("That comment is not editable!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
switch ($op) {
|
|
|
|
case 'delete':
|
2011-02-02 19:10:25 +01:00
|
|
|
if (!$inline) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
if ($request->isFormPost()) {
|
2011-02-02 19:10:25 +01:00
|
|
|
$inline->delete();
|
2011-04-20 10:58:05 +02:00
|
|
|
return $this->buildEmptyResponse();
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog->setTitle('Really delete this comment?');
|
|
|
|
$edit_dialog->addHiddenInput('id', $inline_id);
|
|
|
|
$edit_dialog->addHiddenInput('op', 'delete');
|
|
|
|
$edit_dialog->appendChild(
|
|
|
|
'<p>Delete this inline comment?</p>');
|
2011-02-02 01:42:36 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
return id(new AphrontDialogResponse())->setDialog($edit_dialog);
|
2011-02-02 01:42:36 +01:00
|
|
|
case 'edit':
|
2011-02-02 19:10:25 +01:00
|
|
|
if (!$inline) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
if (strlen($text)) {
|
|
|
|
$inline->setContent($text);
|
2011-02-03 04:38:43 +01:00
|
|
|
$inline->setCache(null);
|
2011-02-02 19:10:25 +01:00
|
|
|
$inline->save();
|
|
|
|
return $this->buildRenderedCommentResponse(
|
|
|
|
$inline,
|
|
|
|
$on_right);
|
|
|
|
} else {
|
|
|
|
$inline->delete();
|
2011-04-20 10:58:05 +02:00
|
|
|
return $this->buildEmptyResponse();
|
2011-02-02 19:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$edit_dialog->setTitle('Edit Inline Comment');
|
2011-02-02 01:42:36 +01:00
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog->addHiddenInput('id', $inline_id);
|
|
|
|
$edit_dialog->addHiddenInput('op', 'edit');
|
|
|
|
|
|
|
|
$edit_dialog->appendChild(
|
|
|
|
$this->renderTextArea(
|
|
|
|
$inline->getContent()));
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($edit_dialog);
|
2011-02-02 01:42:36 +01:00
|
|
|
case 'create':
|
|
|
|
|
|
|
|
if (!$request->isFormPost() || !strlen($text)) {
|
2011-04-20 10:58:05 +02:00
|
|
|
return $this->buildEmptyResponse();
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$inline = id(new DifferentialInlineComment())
|
|
|
|
->setRevisionID($this->revisionID)
|
|
|
|
->setChangesetID($changeset)
|
|
|
|
->setCommentID(null)
|
|
|
|
->setAuthorPHID($user->getPHID())
|
|
|
|
->setLineNumber($number)
|
|
|
|
->setLineLength($length)
|
2011-04-19 01:10:18 +02:00
|
|
|
->setIsNewFile($on_right)
|
2011-02-02 01:42:36 +01:00
|
|
|
->setContent($text)
|
|
|
|
->save();
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
return $this->buildRenderedCommentResponse($inline, $on_right);
|
2011-02-02 01:42:36 +01:00
|
|
|
default:
|
2011-02-02 19:10:25 +01:00
|
|
|
$edit_dialog->setTitle('New Inline Comment');
|
|
|
|
|
|
|
|
$edit_dialog->addHiddenInput('op', 'create');
|
|
|
|
$edit_dialog->addHiddenInput('changeset', $changeset);
|
|
|
|
$edit_dialog->addHiddenInput('is_new', $is_new);
|
|
|
|
$edit_dialog->addHiddenInput('number', $number);
|
|
|
|
$edit_dialog->addHiddenInput('length', $length);
|
|
|
|
|
|
|
|
$edit_dialog->appendChild($this->renderTextArea(''));
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($edit_dialog);
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-02 19:10:25 +01:00
|
|
|
private function buildRenderedCommentResponse(
|
|
|
|
DifferentialInlineComment $inline,
|
|
|
|
$on_right) {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$factory = new DifferentialMarkupEngineFactory();
|
|
|
|
$engine = $factory->newDifferentialCommentMarkupEngine();
|
|
|
|
|
|
|
|
$phids = array($user->getPHID());
|
|
|
|
|
|
|
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
|
|
|
->loadHandles();
|
|
|
|
|
|
|
|
$view = new DifferentialInlineCommentView();
|
|
|
|
$view->setInlineComment($inline);
|
|
|
|
$view->setOnRight($on_right);
|
|
|
|
$view->setBuildScaffolding(true);
|
|
|
|
$view->setMarkupEngine($engine);
|
|
|
|
$view->setHandles($handles);
|
|
|
|
$view->setEditable(true);
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(
|
|
|
|
array(
|
|
|
|
'inlineCommentID' => $inline->getID(),
|
|
|
|
'markup' => $view->render(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-04-20 10:58:05 +02:00
|
|
|
private function buildEmptyResponse() {
|
2011-02-02 19:10:25 +01:00
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(
|
|
|
|
array(
|
|
|
|
'markup' => '',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderTextArea($text) {
|
|
|
|
return phutil_render_tag(
|
|
|
|
'textarea',
|
|
|
|
array(
|
2011-02-05 02:53:14 +01:00
|
|
|
'class' => 'differential-inline-comment-edit-textarea',
|
2011-02-02 19:10:25 +01:00
|
|
|
'name' => 'text',
|
|
|
|
),
|
2011-04-30 05:18:12 +02:00
|
|
|
phutil_escape_html($text));
|
2011-02-02 19:10:25 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 01:42:36 +01:00
|
|
|
}
|