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
This commit is contained in:
@@ -37,7 +37,8 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/phame/' => array(
|
||||
'/J(?P<id>[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<queryKey>[^/]+)/)?' => 'PhamePostListController',
|
||||
'blogger/(?P<bloggername>[\w\.-_]+)/' => 'PhamePostListController',
|
||||
'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController',
|
||||
$this->getEditRoutePattern('edit/')
|
||||
=> 'PhamePostEditController',
|
||||
'history/(?P<id>\d+)/' => 'PhamePostHistoryController',
|
||||
'view/(?P<id>\d+)/(?:(?P<slug>[^/]+)/)?' => 'PhamePostViewController',
|
||||
'(?P<action>publish|unpublish)/(?P<id>\d+)/'
|
||||
=> 'PhamePostPublishController',
|
||||
'preview/(?P<id>\d+)/' => 'PhamePostPreviewController',
|
||||
'preview/' => 'PhabricatorMarkupPreviewController',
|
||||
'framed/(?P<id>\d+)/' => 'PhamePostFramedController',
|
||||
'move/(?P<id>\d+)/' => 'PhamePostMoveController',
|
||||
'archive/(?P<id>\d+)/' => 'PhamePostArchiveController',
|
||||
'comment/(?P<id>[1-9]\d*)/' => 'PhamePostCommentController',
|
||||
),
|
||||
'blog/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?' => '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(
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class PhamePostCommentController
|
||||
extends PhamePostController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
19
src/applications/phame/remarkup/PhamePostRemarkupRule.php
Normal file
19
src/applications/phame/remarkup/PhamePostRemarkupRule.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
final class PhamePostRemarkupRule
|
||||
extends PhabricatorObjectRemarkupRule {
|
||||
|
||||
protected function getObjectNamePrefix() {
|
||||
return 'J';
|
||||
}
|
||||
|
||||
protected function loadObjects(array $ids) {
|
||||
$viewer = $this->getEngine()->getConfig('viewer');
|
||||
|
||||
return id(new PhamePostQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs($ids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user