1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

adding comments to ponder

Summary: This is pretty spartan, but it does the job.

Test Plan:
Patch, update storage, add some comment
to your favorite question or answer.

Reviewers: nh, vrana, epriestley

Reviewed By: epriestley

CC: aran, Korvin, starruler, syrneus, me.here, victorzarate7

Maniphest Tasks: T1645

Differential Revision: https://secure.phabricator.com/D3471
This commit is contained in:
Pieter Hooimeijer 2012-09-11 12:13:20 -07:00
parent 903f985983
commit 5883b4f50c
23 changed files with 631 additions and 21 deletions

View file

@ -0,0 +1,11 @@
CREATE TABLE `{$NAMESPACE}_ponder`.`ponder_comment` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`authorPHID` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`targetPHID` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`content` longtext CHARACTER SET utf8 NOT NULL,
`dateCreated` int(10) unsigned NOT NULL,
`dateModified` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `authorPHID` (`authorPHID`),
KEY `targetPHID` (`targetPHID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View file

@ -2851,9 +2851,18 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/css/application/phriction/phriction-document-css.css',
),
'ponder-comment-table-css' =>
array(
'uri' => '/res/a1bb9056/rsrc/css/application/ponder/comments.css',
'type' => 'css',
'requires' =>
array(
),
'disk' => '/rsrc/css/application/ponder/comments.css',
),
'ponder-core-view-css' =>
array(
'uri' => '/res/4a6e2fc7/rsrc/css/application/ponder/core.css',
'uri' => '/res/3a2d5e18/rsrc/css/application/ponder/core.css',
'type' => 'css',
'requires' =>
array(
@ -2871,7 +2880,7 @@ celerity_register_resource_map(array(
),
'ponder-post-css' =>
array(
'uri' => '/res/32c960df/rsrc/css/application/ponder/post.css',
'uri' => '/res/013b9e2c/rsrc/css/application/ponder/post.css',
'type' => 'css',
'requires' =>
array(
@ -2880,7 +2889,7 @@ celerity_register_resource_map(array(
),
'ponder-vote-css' =>
array(
'uri' => '/res/923bcf97/rsrc/css/application/ponder/vote.css',
'uri' => '/res/d4dff9ba/rsrc/css/application/ponder/vote.css',
'type' => 'css',
'requires' =>
array(

View file

@ -1164,6 +1164,7 @@ phutil_register_library_map(array(
'PhrictionHistoryController' => 'applications/phriction/controller/PhrictionHistoryController.php',
'PhrictionListController' => 'applications/phriction/controller/PhrictionListController.php',
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
'PonderAddCommentView' => 'applications/ponder/view/PonderAddCommentView.php',
'PonderAnswer' => 'applications/ponder/storage/PonderAnswer.php',
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php',
@ -1172,11 +1173,15 @@ phutil_register_library_map(array(
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
'PonderAnswerSummaryView' => 'applications/ponder/view/PonderAnswerSummaryView.php',
'PonderAnswerViewController' => 'applications/ponder/controller/PonderAnswerViewController.php',
'PonderCommentBodyView' => 'applications/ponder/view/PonderCommentBodyView.php',
'PonderComment' => 'applications/ponder/storage/PonderComment.php',
'PonderCommentListView' => 'applications/ponder/view/PonderCommentListView.php',
'PonderCommentQuery' => 'applications/ponder/query/PonderCommentQuery.php',
'PonderCommentSaveController' => 'applications/ponder/controller/PonderCommentSaveController.php',
'PonderConstants' => 'applications/ponder/PonderConstants.php',
'PonderController' => 'applications/ponder/controller/PonderController.php',
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
'PonderFeedController' => 'applications/ponder/controller/PonderFeedController.php',
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
'PonderQuestionAskController' => 'applications/ponder/controller/PonderQuestionAskController.php',
'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php',
@ -2248,6 +2253,7 @@ phutil_register_library_map(array(
'PhrictionHistoryController' => 'PhrictionController',
'PhrictionListController' => 'PhrictionController',
'PonderAddAnswerView' => 'AphrontView',
'PonderAddCommentView' => 'AphrontView',
'PonderAnswer' =>
array(
0 => 'PonderDAO',
@ -2260,10 +2266,18 @@ phutil_register_library_map(array(
'PonderAnswerSaveController' => 'PonderController',
'PonderAnswerSummaryView' => 'AphrontView',
'PonderAnswerViewController' => 'PonderController',
'PonderCommentBodyView' => 'AphrontView',
'PonderComment' =>
array(
0 => 'PonderDAO',
1 => 'PhabricatorMarkupInterface',
),
'PonderCommentListView' => 'AphrontView',
'PonderCommentQuery' => 'PhabricatorQuery',
'PonderCommentSaveController' => 'PonderController',
'PonderController' => 'PhabricatorController',
'PonderDAO' => 'PhabricatorLiskDAO',
'PonderFeedController' => 'PonderController',
'PonderPostBodyView' => 'AphrontView',
'PonderQuestion' =>
array(
0 => 'PonderDAO',

View file

@ -53,6 +53,7 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication {
'answer/preview/' => 'PonderAnswerPreviewController',
'question/ask/' => 'PonderQuestionAskController',
'question/preview/' => 'PonderQuestionPreviewController',
'comment/add/' => 'PonderCommentSaveController',
'(?P<kind>question)/vote/' => 'PonderVoteSaveController',
'(?P<kind>answer)/vote/' => 'PonderVoteSaveController'
));

View file

@ -38,7 +38,7 @@ final class PonderAnswerPreviewController
$answer->setContent($request->getStr('content'));
$answer->setAuthorPHID($author_phid);
$view = new PonderCommentBodyView();
$view = new PonderPostBodyView();
$view
->setQuestion($question)
->setTarget($answer)

View file

@ -0,0 +1,58 @@
<?php
/*
* Copyright 2012 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.
*/
final class PonderCommentSaveController extends PonderController {
public function processRequest() {
$request = $this->getRequest();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$user = $request->getUser();
$question_id = $request->getInt('question_id');
$question = PonderQuestionQuery::loadSingle($user, $question_id);
if (!$question) {
return new Aphront404Response();
}
$target = $request->getStr('target');
$objects = id(new PhabricatorObjectHandleData(array($target)))
->loadHandles();
if (!$objects) {
return new Aphront404Response();
}
$content = $request->getStr('content');
$res = new PonderComment();
$res
->setContent($content)
->setAuthorPHID($user->getPHID())
->setTargetPHID($target)
->save();
PhabricatorSearchPonderIndexer::indexQuestion($question);
return id(new AphrontRedirectResponse())
->setURI(
id(new PhutilURI('/Q'. $question->getID()))
->setFragment('comment-' . $res->getID()));
}
}

View file

@ -35,7 +35,7 @@ final class PonderQuestionPreviewController
$question->setContent($request->getStr('content'));
$question->setAuthorPHID($author_phid);
$view = new PonderCommentBodyView();
$view = new PonderPostBodyView();
$view
->setQuestion($question)
->setTarget($question)

View file

@ -34,11 +34,21 @@ final class PonderQuestionViewController extends PonderController {
return new Aphront404Response();
}
$question->attachRelated($user->getPHID());
$answers = $question->getAnswers();
$object_phids = array($user->getPHID(), $question->getAuthorPHID());
$answers = $question->getAnswers();
$comments = $question->getComments();
foreach ($comments as $comment) {
$object_phids[] = $comment->getAuthorPHID();
}
foreach ($answers as $answer) {
$object_phids[] = $answer->getAuthorPHID();
$comments = $answer->getComments();
foreach ($comments as $comment) {
$object_phids[] = $comment->getAuthorPHID();
}
}
$handles = $this->loadViewerHandles($object_phids);

View file

@ -0,0 +1,81 @@
<?php
/*
* Copyright 2012 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.
*/
final class PonderCommentQuery extends PhabricatorQuery {
private $ids;
private $authorPHID;
private $targetPHIDs;
public function withIDs($qids) {
$this->ids = $qids;
return $this;
}
public function withTargetPHIDs($phids) {
$this->targetPHIDs = $phids;
return $this;
}
public function withAuthorPHID($phid) {
$this->authorPHID = $phid;
return $this;
}
private function buildWhereClause($conn_r) {
$where = array();
if ($this->ids) {
$where[] = qsprintf($conn_r, 'id in (%Ls)', $this->ids);
}
if ($this->authorPHID) {
$where[] = qsprintf($conn_r, 'authorPHID = %s', $this->authorPHID);
}
if ($this->targetPHIDs) {
$where[] = qsprintf($conn_r, 'targetPHID in (%Ls)', $this->targetPHIDs);
}
return $this->formatWhereClause($where);
}
private function buildOrderByClause($conn_r) {
return 'ORDER BY id';
}
public function execute() {
$comment = new PonderComment();
$conn_r = $comment->establishConnection('r');
$select = qsprintf(
$conn_r,
'SELECT r.* FROM %T r',
$comment->getTableName());
$where = $this->buildWhereClause($conn_r);
$order_by = $this->buildOrderByClause($conn_r);
return $comment->loadAllFromArray(
queryfx_all(
$conn_r,
'%Q %Q %Q',
$select,
$where,
$order_by));
}
}

View file

@ -31,6 +31,7 @@ final class PonderAnswer extends PonderDAO
protected $voteCount;
private $vote;
private $question = null;
private $comments;
public function setQuestion($question) {
$this->question = $question;
@ -53,6 +54,15 @@ final class PonderAnswer extends PonderDAO
return $this->vote;
}
public function setComments($comments) {
$this->comments = $comments;
return $this;
}
public function getComments() {
return $this->comments;
}
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,

View file

@ -0,0 +1,57 @@
<?php
/*
* Copyright 2012 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.
*/
final class PonderComment extends PonderDAO
implements PhabricatorMarkupInterface {
const MARKUP_FIELD_CONTENT = 'markup:content';
protected $targetPHID;
protected $authorPHID;
protected $content;
public function getMarkupFieldKey($field) {
$hash = PhabricatorHash::digest($this->getMarkupText($field));
$id = $this->getID();
return "ponder:c{$id}:{$field}:{$hash}";
}
public function getMarkupText($field) {
return $this->getContent();
}
public function newMarkupEngine($field) {
return PhabricatorMarkupEngine::newPonderMarkupEngine();
}
public function didMarkupText(
$field,
$output,
PhutilMarkupEngine $engine) {
return $output;
}
public function shouldUseMarkupCache($field) {
return (bool)$this->getID();
}
public function getMarkupField() {
return self::MARKUP_FIELD_CONTENT;
}
}

View file

@ -34,6 +34,7 @@ final class PonderQuestion extends PonderDAO
private $answers;
private $vote;
private $comments;
public function getConfiguration() {
return array(
@ -76,10 +77,23 @@ final class PonderQuestion extends PonderDAO
$edges[$user_phid][PhabricatorEdgeConfig::TYPE_VOTING_USER_HAS_ANSWER];
$edges = null;
if ($qa_phids) {
$comments = id(new PonderCommentQuery())
->withTargetPHIDs($qa_phids)
->execute();
$comments = mgroup($comments, 'getTargetPHID');
}
else {
$comments = array();
}
$this->setUserVote(idx($question_edge, $this->getPHID()));
$this->setComments(idx($comments, $this->getPHID(), array()));
foreach ($this->answers as $answer) {
$answer->setQuestion($this);
$answer->setUserVote(idx($answer_edges, $answer->getPHID()));
$answer->setComments(idx($comments, $answer->getPHID(), array()));
}
}
@ -95,6 +109,15 @@ final class PonderQuestion extends PonderDAO
return $this->vote;
}
public function setComments($comments) {
$this->comments = $comments;
return $this;
}
public function getComments() {
return $this->comments;
}
public function getAnswers() {
return $this->answers;
}

View file

@ -0,0 +1,70 @@
<?php
/*
* Copyright 2012 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.
*/
final class PonderAddCommentView extends AphrontView {
private $target;
private $user;
private $actionURI;
private $questionID;
public function setTarget($target) {
$this->target = $target;
return $this;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function setQuestionID($id) {
$this->questionID = $id;
return $this;
}
public function setActionURI($uri) {
$this->actionURI = $uri;
return $this;
}
public function render() {
require_celerity_resource('ponder-comment-table-css');
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$questionID = $this->questionID;
$target = $this->target;
$form = new AphrontFormView();
$form
->setUser($this->user)
->setAction($this->actionURI)
->addHiddenInput('target', $target)
->addHiddenInput('question_id', $questionID)
->appendChild(
id(new AphrontFormTextAreaControl())
->setName('content')
->setEnableDragAndDropFileUploads(false))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue($is_serious ? 'Submit' : 'Editorialize'));
return $form->render();
}
}

View file

@ -73,7 +73,7 @@ final class PonderAnswerListView extends AphrontView {
->setHeader("Responses:");
foreach ($this->answers as $cur_answer) {
$view = new PonderCommentBodyView();
$view = new PonderPostBodyView();
$view
->setQuestion($question)
->setTarget($cur_answer)
@ -81,7 +81,19 @@ final class PonderAnswerListView extends AphrontView {
->setHandles($handles)
->setUser($user);
$commentview = new PonderCommentListView();
$commentview
->setUser($user)
->setHandles($handles)
->setComments($cur_answer->getComments())
->setTarget($cur_answer->getPHID())
->setQuestionID($question->getID())
->setActionURI(new PhutilURI('/ponder/comment/add/'));
$panel->appendChild($view);
$panel->appendChild($commentview);
$panel->appendChild('<div style="height: 40px; clear : both"></div>');
}
return $panel->render();

View file

@ -0,0 +1,120 @@
<?php
/*
* Copyright 2012 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.
*/
final class PonderCommentListView extends AphrontView {
private $user;
private $handles;
private $comments;
private $target;
private $actionURI;
private $questionID;
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles;
return $this;
}
public function setComments(array $comments) {
assert_instances_of($comments, 'PonderComment');
$this->comments = $comments;
return $this;
}
public function setQuestionID($id) {
$this->questionID = $id;
return $this;
}
public function setActionURI($uri) {
$this->actionURI = $uri;
return $this;
}
public function setTarget($target) {
$this->target = $target;
return $this;
}
public function render() {
require_celerity_resource('phabricator-remarkup-css');
require_celerity_resource('ponder-comment-table-css');
$user = $this->user;
$handles = $this->handles;
$comments = $this->comments;
$comment_markup = array();
foreach ($comments as $comment) {
$handle = $handles[$comment->getAuthorPHID()];
$body = PhabricatorMarkupEngine::renderOneObject(
$comment,
$comment->getMarkupField(),
$this->user);
$comment_anchor = '<a name="comment-' . $comment->getID() . '" />';
$comment_markup[] =
'<tr>'.
'<th>'.
$comment_anchor.
'</th>'.
'<td>'.
'<div class="phabricator-remarkup ponder-comment-markup">'.
$body.
'&nbsp;&mdash;'.
$handle->renderLink().
'&nbsp;'.
'<span class="ponder-datestamp">'.
phabricator_datetime($comment->getDateCreated(), $user).
'</span>'.
'</div>'.
'</td>'.
'</tr>';
}
$addview = id(new PonderAddCommentView)
->setTarget($this->target)
->setUser($user)
->setQuestionID($this->questionID)
->setActionURI($this->actionURI);
$comment_markup[] =
'<tr>'.
'<th>&nbsp;</th>'.
'<td>'.$addview->render().'</td>'.
'</tr>';
$comment_markup = phutil_render_tag(
'table',
array(
'class' => 'ponder-comments',
),
implode("\n", $comment_markup)
);
return $comment_markup;
}
}

View file

@ -16,7 +16,7 @@
* limitations under the License.
*/
final class PonderCommentBodyView extends AphrontView {
final class PonderPostBodyView extends AphrontView {
private $target;
private $question;

View file

@ -48,7 +48,7 @@ final class PonderQuestionDetailView extends AphrontView {
->addClass("ponder-panel")
->setHeader($this->renderObjectLink().' '.$question->getTitle());
$contentview = new PonderCommentBodyView();
$contentview = new PonderPostBodyView();
$contentview
->setTarget($question)
->setQuestion($question)
@ -56,7 +56,17 @@ final class PonderQuestionDetailView extends AphrontView {
->setHandles($handles)
->setAction(PonderConstants::ASKED_LITERAL);
$commentview = new PonderCommentListView();
$commentview
->setUser($user)
->setHandles($handles)
->setComments($question->getComments())
->setTarget($question->getPHID())
->setQuestionID($question->getID())
->setActionURI(new PhutilURI('/ponder/comment/add/'));
$panel->appendChild($contentview);
$panel->appendChild($commentview);
return $panel->render();
}

View file

@ -61,7 +61,6 @@ final class PonderVotableView extends AphrontView {
'<div id="'.phutil_escape_html($this->phid).'" class="ponder-votebox">
</div>'.
$this->renderChildren().
'<div class="ponder-votable-bottom"></div>'.
'</div>';
return $content;

View file

@ -972,6 +972,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'sql',
'name' => $this->getPatchPath('edgetype.sql'),
),
'ponder-comments.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('ponder-comments.sql'),
),
);
}

View file

@ -0,0 +1,104 @@
/**
* @provides ponder-comment-table-css
*/
.ponder-comments {
width: 600px;
margin : 0;
margin-left : 120px;
}
.ponder-comments th {
width : 0px;
height : 0px;
}
.ponder-comments td {
vertical-align: top;
padding: 6px 2px;
border-bottom: 1px dotted #d0d0d0;
background : #FFF;
}
.ponder-datestamp {
font-size: 9px;
font-family: "Verdana";
color: #666666;
}
.ponder-label {
display: block;
width: 100%;
font-size: 14px;
font-weight: bold;
color: #222222;
text-align: left;
margin: 0px 0px 6px;
padding: 6px 4px;
background: #cccccc;
border-bottom: 1px solid #aaaaaa;
cursor: pointer;
}
td .aphront-form-control {
padding : 0;
}
td .aphront-form-control-submit {
float : right;
margin : 0;
padding : 0;
}
.aphront-form-control-submit button {
margin : 0;
}
td .aphront-form-input {
margin : 0;
width : 100%;
}
td .aphront-form-control textarea {
height : 40px;
width : 560px;
padding : 0;
margin : 0;
background : #EEE;
border : 1px solid #CCC;
}
div.ponder-comment-markup {
padding-left : 5px;
}
.ponder-comment-markup p {
margin : 0;
}
.ponder-comment-markup h2 {
margin : 0;
font-size : inherit;
font-weight : normal;
}
.ponder-comment-markup h3 {
margin : 0;
font-size : inherit;
font-weight : normal;
}
.ponder-comment-markup h4 {
margin : 0;
font-size : inherit;
font-weight : normal;
}
.ponder-comment-markup h5 {
margin : 0;
font-size : inherit;
font-weight : normal;
}

View file

@ -10,13 +10,18 @@
.ponder-panel {
max-width: 800px;
font-family : antiqua, verdana, arial;
padding-left : 30px;
border : none;
background : white;
}
.ponder-panel h1 {
padding-bottom: 8px;
margin-bottom: 8px;
margin-left : -30px;
margin-right : -50px;
margin-bottom: 0px;
padding-bottom : 4px;
font-size : 1.5em;
border-bottom : 1px solid #AAA;
}
.ponder-panel .aphront-form-view {

View file

@ -20,15 +20,24 @@
width: 81ch;
}
.ponder-question {
background : white;
}
.phabricator-transaction-view .ponder-question {
border-color: #777;
background : white;
}
.phabricator-transaction-detail .ponder-question {
border-color: #777;
border : none;
}
.phabricator-transaction-view .ponder-answer {
/* border-color: #203791; */
background : white;
margin-bottom : 0;
}
.phabricator-transaction-content {
background : white;
}

View file

@ -2,8 +2,11 @@
* @provides ponder-vote-css
*/
.ponder-votable {
min-height : 120px;
.ponder-votable .phabricator-transaction-view {
margin : 0;
padding : 0;
}
.ponder-votable .phabricator-transaction-detail {