@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update PhamePost to EditEngine

Summary: Allows create and edit workflows through EditEngine. Not sure I did the 'blog' stuff correct.

Test Plan: Create a new post, edit a post, move a post.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14802

+141 -169
+2
src/__phutil_library_map__.php
··· 3430 3430 'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php', 3431 3431 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', 3432 3432 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', 3433 + 'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php', 3433 3434 'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php', 3434 3435 'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php', 3435 3436 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', ··· 7890 7891 'PhamePostCommentController' => 'PhamePostController', 7891 7892 'PhamePostController' => 'PhameController', 7892 7893 'PhamePostEditController' => 'PhamePostController', 7894 + 'PhamePostEditEngine' => 'PhabricatorEditEngine', 7893 7895 'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor', 7894 7896 'PhamePostHistoryController' => 'PhamePostController', 7895 7897 'PhamePostListController' => 'PhamePostController',
+13 -5
src/applications/phame/controller/PhameHomeController.php
··· 28 28 ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) 29 29 ->executeWithCursorPager($pager); 30 30 31 - $post_list = id(new PhamePostListView()) 32 - ->setPosts($posts) 33 - ->setViewer($viewer) 34 - ->showBlog(true); 31 + if ($posts) { 32 + $post_list = id(new PhamePostListView()) 33 + ->setPosts($posts) 34 + ->setViewer($viewer) 35 + ->showBlog(true); 36 + } else { 37 + $post_list = id(new PHUIBigInfoView()) 38 + ->setIcon('fa-star') 39 + ->setTitle('No Visible Posts') 40 + ->setDescription( 41 + pht('There aren\'t any visible blog posts.')); 42 + } 35 43 } else { 36 44 $create_button = id(new PHUIButtonView()) 37 45 ->setTag('a') ··· 43 51 ->setIcon('fa-star') 44 52 ->setTitle('Welcome to Phame') 45 53 ->setDescription( 46 - pht('There aren\'t any visible Blog Posts.')) 54 + pht('There aren\'t any visible blog posts.')) 47 55 ->addAction($create_button); 48 56 } 49 57
+16 -164
src/applications/phame/controller/post/PhamePostEditController.php
··· 6 6 $viewer = $request->getViewer(); 7 7 $id = $request->getURIData('id'); 8 8 9 - $crumbs = $this->buildApplicationCrumbs(); 10 - $crumbs->addTextCrumb( 11 - pht('Blogs'), 12 - $this->getApplicationURI('blog/')); 13 9 if ($id) { 14 10 $post = id(new PhamePostQuery()) 15 11 ->setViewer($viewer) ··· 22 18 if (!$post) { 23 19 return new Aphront404Response(); 24 20 } 25 - 26 - $cancel_uri = $this->getApplicationURI('/post/view/'.$id.'/'); 27 - $submit_button = pht('Save Changes'); 28 - $page_title = pht('Edit Post'); 29 - 30 - $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( 31 - $post->getPHID(), 32 - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 33 - $v_projects = array_reverse($v_projects); 34 - $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( 35 - $post->getPHID()); 36 - $blog = $post->getBlog(); 37 - 38 - 21 + $blog_id = $post->getBlog()->getID(); 39 22 } else { 40 - $blog = id(new PhameBlogQuery()) 41 - ->setViewer($viewer) 42 - ->withIDs(array($request->getInt('blog'))) 43 - ->requireCapabilities( 44 - array( 45 - PhabricatorPolicyCapability::CAN_VIEW, 46 - PhabricatorPolicyCapability::CAN_EDIT, 47 - )) 48 - ->executeOne(); 49 - if (!$blog) { 50 - return new Aphront404Response(); 51 - } 52 - $v_projects = array(); 53 - $v_cc = array(); 54 - 55 - $post = PhamePost::initializePost($viewer, $blog); 56 - $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); 57 - 58 - $submit_button = pht('Create Post'); 59 - $page_title = pht('Create Post'); 60 - } 61 - 62 - $title = $post->getTitle(); 63 - $body = $post->getBody(); 64 - $visibility = $post->getVisibility(); 65 - 66 - $e_title = true; 67 - $validation_exception = null; 68 - if ($request->isFormPost()) { 69 - $title = $request->getStr('title'); 70 - $body = $request->getStr('body'); 71 - $v_projects = $request->getArr('projects'); 72 - $v_cc = $request->getArr('cc'); 73 - $visibility = $request->getInt('visibility'); 74 - 75 - $xactions = array( 76 - id(new PhamePostTransaction()) 77 - ->setTransactionType(PhamePostTransaction::TYPE_TITLE) 78 - ->setNewValue($title), 79 - id(new PhamePostTransaction()) 80 - ->setTransactionType(PhamePostTransaction::TYPE_BODY) 81 - ->setNewValue($body), 82 - id(new PhamePostTransaction()) 83 - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 84 - ->setNewValue($visibility), 85 - id(new PhamePostTransaction()) 86 - ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 87 - ->setNewValue(array('=' => $v_cc)), 88 - 89 - ); 90 - 91 - $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 92 - $xactions[] = id(new PhamePostTransaction()) 93 - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) 94 - ->setMetadataValue('edge:type', $proj_edge_type) 95 - ->setNewValue(array('=' => array_fuse($v_projects))); 96 - 97 - $editor = id(new PhamePostEditor()) 98 - ->setActor($viewer) 99 - ->setContentSourceFromRequest($request) 100 - ->setContinueOnNoEffect(true); 101 - 102 - try { 103 - $editor->applyTransactions($post, $xactions); 104 - 105 - $uri = $post->getViewURI(); 106 - return id(new AphrontRedirectResponse())->setURI($uri); 107 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 108 - $validation_exception = $ex; 109 - $e_title = $validation_exception->getShortMessage( 110 - PhamePostTransaction::TYPE_TITLE); 111 - } 23 + $blog_id = $request->getInt('blog'); 112 24 } 113 25 114 - $handle = id(new PhabricatorHandleQuery()) 26 + $blog = id(new PhameBlogQuery()) 115 27 ->setViewer($viewer) 116 - ->withPHIDs(array($post->getBlogPHID())) 28 + ->withIDs(array($blog_id)) 29 + ->requireCapabilities( 30 + array( 31 + PhabricatorPolicyCapability::CAN_VIEW, 32 + PhabricatorPolicyCapability::CAN_EDIT, 33 + )) 117 34 ->executeOne(); 118 35 119 - $form = id(new AphrontFormView()) 120 - ->setUser($viewer) 121 - ->addHiddenInput('blog', $request->getInt('blog')) 122 - ->appendChild( 123 - id(new AphrontFormMarkupControl()) 124 - ->setLabel(pht('Blog')) 125 - ->setValue($handle->renderLink())) 126 - ->appendChild( 127 - id(new AphrontFormTextControl()) 128 - ->setLabel(pht('Title')) 129 - ->setName('title') 130 - ->setValue($title) 131 - ->setID('post-title') 132 - ->setError($e_title)) 133 - ->appendChild( 134 - id(new AphrontFormSelectControl()) 135 - ->setLabel(pht('Visibility')) 136 - ->setName('visibility') 137 - ->setValue($visibility) 138 - ->setOptions(PhameConstants::getPhamePostStatusMap())) 139 - ->appendChild( 140 - id(new PhabricatorRemarkupControl()) 141 - ->setLabel(pht('Body')) 142 - ->setName('body') 143 - ->setValue($body) 144 - ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) 145 - ->setID('post-body') 146 - ->setUser($viewer) 147 - ->setDisableMacros(true)) 148 - ->appendControl( 149 - id(new AphrontFormTokenizerControl()) 150 - ->setLabel(pht('Subscribers')) 151 - ->setName('cc') 152 - ->setValue($v_cc) 153 - ->setUser($viewer) 154 - ->setDatasource(new PhabricatorMetaMTAMailableDatasource())) 155 - ->appendControl( 156 - id(new AphrontFormTokenizerControl()) 157 - ->setLabel(pht('Projects')) 158 - ->setName('projects') 159 - ->setValue($v_projects) 160 - ->setDatasource(new PhabricatorProjectDatasource())) 161 - ->appendChild( 162 - id(new AphrontFormSubmitControl()) 163 - ->addCancelButton($cancel_uri) 164 - ->setValue($submit_button)); 36 + if (!$blog) { 37 + return new Aphront404Response(); 38 + } 165 39 166 - $preview = id(new PHUIRemarkupPreviewPanel()) 167 - ->setHeader($post->getTitle()) 168 - ->setPreviewURI($this->getApplicationURI('post/preview/')) 169 - ->setControlID('post-body') 170 - ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT); 171 - 172 - $form_box = id(new PHUIObjectBoxView()) 173 - ->setHeaderText($page_title) 174 - ->setValidationException($validation_exception) 175 - ->setForm($form); 176 - 177 - $crumbs->addTextCrumb( 178 - $blog->getName(), 179 - $blog->getViewURI()); 180 - $crumbs->addTextCrumb( 181 - $page_title, 182 - $cancel_uri); 183 - 184 - return $this->newPage() 185 - ->setTitle($page_title) 186 - ->setCrumbs($crumbs) 187 - ->appendChild( 188 - array( 189 - $form_box, 190 - $preview, 191 - )); 40 + return id(new PhamePostEditEngine()) 41 + ->setController($this) 42 + ->setBlog($blog) 43 + ->buildResponse(); 192 44 } 193 45 194 46 }
+110
src/applications/phame/editor/PhamePostEditEngine.php
··· 1 + <?php 2 + 3 + final class PhamePostEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + private $blog; 7 + 8 + const ENGINECONST = 'phame.post'; 9 + 10 + public function getEngineName() { 11 + return pht('Blog Posts'); 12 + } 13 + 14 + public function getSummaryHeader() { 15 + return pht('Configure Blog Post Forms'); 16 + } 17 + 18 + public function getSummaryText() { 19 + return pht('Configure creation and editing blog posts in Phame.'); 20 + } 21 + 22 + public function setBlog(PhameBlog $blog) { 23 + $this->blog = $blog; 24 + return $this; 25 + } 26 + 27 + public function getEngineApplicationClass() { 28 + return 'PhabricatorPhameApplication'; 29 + } 30 + 31 + protected function newEditableObject() { 32 + $viewer = $this->getViewer(); 33 + 34 + if ($this->blog) { 35 + $blog = $this->blog; 36 + } else { 37 + $blog = PhameBlog::initializeNewBlog($viewer); 38 + } 39 + 40 + return PhamePost::initializePost($viewer, $blog); 41 + } 42 + 43 + protected function newObjectQuery() { 44 + return new PhamePostQuery(); 45 + } 46 + 47 + protected function getObjectCreateTitleText($object) { 48 + return pht('Create New Post'); 49 + } 50 + 51 + protected function getObjectEditTitleText($object) { 52 + return pht('Edit %s', $object->getTitle()); 53 + } 54 + 55 + protected function getObjectEditShortText($object) { 56 + return $object->getTitle(); 57 + } 58 + 59 + protected function getObjectCreateShortText() { 60 + return pht('Create Post'); 61 + } 62 + 63 + protected function getObjectViewURI($object) { 64 + return $object->getViewURI(); 65 + } 66 + 67 + protected function buildCustomEditFields($object) { 68 + 69 + if ($this->blog) { 70 + $blog_title = pht('Blog: %s', $this->blog->getName()); 71 + } else { 72 + $blog_title = pht('Sample Blog Title'); 73 + } 74 + 75 + return array( 76 + id(new PhabricatorInstructionsEditField()) 77 + ->setValue($blog_title), 78 + id(new PhabricatorTextEditField()) 79 + ->setKey('title') 80 + ->setLabel(pht('Title')) 81 + ->setDescription(pht('Post title.')) 82 + ->setConduitDescription(pht('Retitle the post.')) 83 + ->setConduitTypeDescription(pht('New post title.')) 84 + ->setTransactionType(PhamePostTransaction::TYPE_TITLE) 85 + ->setValue($object->getTitle()), 86 + id(new PhabricatorSelectEditField()) 87 + ->setKey('visibility') 88 + ->setLabel(pht('Visibility')) 89 + ->setDescription(pht('Post visibility.')) 90 + ->setConduitDescription(pht('Change post visibility.')) 91 + ->setConduitTypeDescription(pht('New post visibility constant.')) 92 + ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 93 + ->setValue($object->getVisibility()) 94 + ->setOptions(PhameConstants::getPhamePostStatusMap()), 95 + id(new PhabricatorRemarkupEditField()) 96 + ->setKey('body') 97 + ->setLabel(pht('Body')) 98 + ->setDescription(pht('Post body.')) 99 + ->setConduitDescription(pht('Change post body.')) 100 + ->setConduitTypeDescription(pht('New post body.')) 101 + ->setTransactionType(PhamePostTransaction::TYPE_BODY) 102 + ->setValue($object->getBody()) 103 + ->setPreviewPanel( 104 + id(new PHUIRemarkupPreviewPanel()) 105 + ->setHeader(pht('Blog Post')) 106 + ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT)), 107 + ); 108 + } 109 + 110 + }