@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.

Add a transaction for PhamePost visibility

Summary: Adds ability to set visibility when authoring a Post. New default is "Visible". If you write a post and save it as a Draft, and later click publish, a feed story and mail will go out.

Test Plan: Write a new Post, see feed story and get email. Write a new Draft, get nothing. Click Publish, see story and email.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9360

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

+150 -47
+2
src/__phutil_library_map__.php
··· 3262 3262 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', 3263 3263 'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php', 3264 3264 'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php', 3265 + 'PhameConstants' => 'applications/phame/constants/PhameConstants.php', 3265 3266 'PhameController' => 'applications/phame/controller/PhameController.php', 3266 3267 'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php', 3267 3268 'PhameDAO' => 'applications/phame/storage/PhameDAO.php', ··· 7525 7526 'PhameBlogViewController' => 'PhameBlogController', 7526 7527 'PhameCelerityResources' => 'CelerityResources', 7527 7528 'PhameConduitAPIMethod' => 'ConduitAPIMethod', 7529 + 'PhameConstants' => 'Phobject', 7528 7530 'PhameController' => 'PhabricatorController', 7529 7531 'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod', 7530 7532 'PhameDAO' => 'PhabricatorLiskDAO',
+1 -1
src/applications/phame/conduit/PhameCreatePostConduitAPIMethod.php
··· 85 85 $is_draft = $request->getValue('isDraft', false); 86 86 if (!$is_draft) { 87 87 $post->setDatePublished(time()); 88 - $post->setVisibility(PhamePost::VISIBILITY_PUBLISHED); 88 + $post->setVisibility(PhameConstants::VISIBILITY_PUBLISHED); 89 89 } 90 90 $post->setTitle($title); 91 91 $phame_title = $request->getValue(
+2 -2
src/applications/phame/conduit/PhameQueryPostsConduitAPIMethod.php
··· 65 65 66 66 $published = $request->getValue('published', null); 67 67 if ($published === true) { 68 - $query->withVisibility(PhamePost::VISIBILITY_PUBLISHED); 68 + $query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED); 69 69 } else if ($published === false) { 70 - $query->withVisibility(PhamePost::VISIBILITY_DRAFT); 70 + $query->withVisibility(PhameConstants::VISIBILITY_DRAFT); 71 71 } 72 72 73 73 $published_after = $request->getValue('publishedAfter', null);
+23
src/applications/phame/constants/PhameConstants.php
··· 1 + <?php 2 + 3 + final class PhameConstants extends Phobject { 4 + 5 + const VISIBILITY_DRAFT = 0; 6 + const VISIBILITY_PUBLISHED = 1; 7 + 8 + public static function getPhamePostStatusMap() { 9 + return array( 10 + self::VISIBILITY_PUBLISHED => pht('Published'), 11 + self::VISIBILITY_DRAFT => pht('Draft'), 12 + ); 13 + } 14 + 15 + public static function getPhamePostStatusName($status) { 16 + $map = array( 17 + self::VISIBILITY_PUBLISHED => pht('Published'), 18 + self::VISIBILITY_DRAFT => pht('Draft'), 19 + ); 20 + return idx($map, $status, pht('Unknown')); 21 + } 22 + 23 + }
+1 -1
src/applications/phame/controller/blog/PhameBlogFeedController.php
··· 21 21 $posts = id(new PhamePostQuery()) 22 22 ->setViewer($viewer) 23 23 ->withBlogPHIDs(array($blog->getPHID())) 24 - ->withVisibility(PhamePost::VISIBILITY_PUBLISHED) 24 + ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) 25 25 ->execute(); 26 26 27 27 $blog_uri = PhabricatorEnv::getProductionURI(
+21 -10
src/applications/phame/controller/post/PhamePostEditController.php
··· 45 45 $post = PhamePost::initializePost($viewer, $blog); 46 46 $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); 47 47 48 - $submit_button = pht('Save Draft'); 49 - $page_title = pht('Create Post'); 48 + $submit_button = pht('Create Post'); 49 + $page_title = pht('Create Post'); 50 50 } 51 51 52 - $title = $post->getTitle(); 53 - $phame_title = $post->getPhameTitle(); 54 - $body = $post->getBody(); 52 + $title = $post->getTitle(); 53 + $phame_title = $post->getPhameTitle(); 54 + $body = $post->getBody(); 55 55 $comments_widget = $post->getCommentsWidget(); 56 + $visibility = $post->getVisibility(); 56 57 57 58 $e_title = true; 58 59 $e_phame_title = true; 59 60 $validation_exception = null; 60 61 if ($request->isFormPost()) { 61 - $title = $request->getStr('title'); 62 - $phame_title = $request->getStr('phame_title'); 63 - $phame_title = PhabricatorSlug::normalize($phame_title); 64 - $body = $request->getStr('body'); 62 + $title = $request->getStr('title'); 63 + $phame_title = $request->getStr('phame_title'); 64 + $phame_title = PhabricatorSlug::normalize($phame_title); 65 + $body = $request->getStr('body'); 65 66 $comments_widget = $request->getStr('comments_widget'); 66 - $v_projects = $request->getArr('projects'); 67 + $v_projects = $request->getArr('projects'); 68 + $visibility = $request->getInt('visibility'); 67 69 68 70 $xactions = array( 69 71 id(new PhamePostTransaction()) ··· 75 77 id(new PhamePostTransaction()) 76 78 ->setTransactionType(PhamePostTransaction::TYPE_BODY) 77 79 ->setNewValue($body), 80 + id(new PhamePostTransaction()) 81 + ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 82 + ->setNewValue($visibility), 78 83 id(new PhamePostTransaction()) 79 84 ->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET) 80 85 ->setNewValue($comments_widget), ··· 134 139 'with underscores for spaces. '. 135 140 'Formatting is enforced.')) 136 141 ->setError($e_phame_title)) 142 + ->appendChild( 143 + id(new AphrontFormSelectControl()) 144 + ->setLabel(pht('Visibility')) 145 + ->setName('visibility') 146 + ->setvalue($visibility) 147 + ->setOptions(PhameConstants::getPhamePostStatusMap())) 137 148 ->appendChild( 138 149 id(new PhabricatorRemarkupControl()) 139 150 ->setLabel(pht('Body'))
+17 -3
src/applications/phame/controller/post/PhamePostPublishController.php
··· 21 21 $view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); 22 22 23 23 if ($request->isFormPost()) { 24 - $post->setVisibility(PhamePost::VISIBILITY_PUBLISHED); 25 - $post->setDatePublished(time()); 26 - $post->save(); 24 + $xactions = array(); 25 + $xactions[] = id(new PhamePostTransaction()) 26 + ->setTransactionType(PhamePostTransaction::TYPE_TITLE) 27 + ->setNewValue($post->getTitle()); 28 + $xactions[] = id(new PhamePostTransaction()) 29 + ->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE) 30 + ->setNewValue($post->getPhameTitle()); 31 + $xactions[] = id(new PhamePostTransaction()) 32 + ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 33 + ->setNewValue(PhameConstants::VISIBILITY_PUBLISHED); 34 + 35 + id(new PhamePostEditor()) 36 + ->setActor($viewer) 37 + ->setContentSourceFromRequest($request) 38 + ->setContinueOnNoEffect(true) 39 + ->setContinueOnMissingFields(true) 40 + ->applyTransactions($post, $xactions); 27 41 28 42 return id(new AphrontRedirectResponse())->setURI($view_uri); 29 43 }
+17 -3
src/applications/phame/controller/post/PhamePostUnpublishController.php
··· 19 19 } 20 20 21 21 if ($request->isFormPost()) { 22 - $post->setVisibility(PhamePost::VISIBILITY_DRAFT); 23 - $post->setDatePublished(0); 24 - $post->save(); 22 + $xactions = array(); 23 + $xactions[] = id(new PhamePostTransaction()) 24 + ->setTransactionType(PhamePostTransaction::TYPE_TITLE) 25 + ->setNewValue($post->getTitle()); 26 + $xactions[] = id(new PhamePostTransaction()) 27 + ->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE) 28 + ->setNewValue($post->getPhameTitle()); 29 + $xactions[] = id(new PhamePostTransaction()) 30 + ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 31 + ->setNewValue(PhameConstants::VISIBILITY_DRAFT); 32 + 33 + id(new PhamePostEditor()) 34 + ->setActor($viewer) 35 + ->setContentSourceFromRequest($request) 36 + ->setContinueOnNoEffect(true) 37 + ->setContinueOnMissingFields(true) 38 + ->applyTransactions($post, $xactions); 25 39 26 40 return id(new AphrontRedirectResponse()) 27 41 ->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/'));
+12
src/applications/phame/editor/PhamePostEditor.php
··· 17 17 $types[] = PhamePostTransaction::TYPE_TITLE; 18 18 $types[] = PhamePostTransaction::TYPE_PHAME_TITLE; 19 19 $types[] = PhamePostTransaction::TYPE_BODY; 20 + $types[] = PhamePostTransaction::TYPE_VISIBILITY; 20 21 $types[] = PhamePostTransaction::TYPE_COMMENTS_WIDGET; 21 22 22 23 return $types; ··· 33 34 return $object->getPhameTitle(); 34 35 case PhamePostTransaction::TYPE_BODY: 35 36 return $object->getBody(); 37 + case PhamePostTransaction::TYPE_VISIBILITY: 38 + return $object->getVisibility(); 36 39 case PhamePostTransaction::TYPE_COMMENTS_WIDGET: 37 40 return $object->getCommentsWidget(); 38 41 } ··· 46 49 case PhamePostTransaction::TYPE_TITLE: 47 50 case PhamePostTransaction::TYPE_PHAME_TITLE: 48 51 case PhamePostTransaction::TYPE_BODY: 52 + case PhamePostTransaction::TYPE_VISIBILITY: 49 53 case PhamePostTransaction::TYPE_COMMENTS_WIDGET: 50 54 return $xaction->getNewValue(); 51 55 } ··· 62 66 return $object->setPhameTitle($xaction->getNewValue()); 63 67 case PhamePostTransaction::TYPE_BODY: 64 68 return $object->setBody($xaction->getNewValue()); 69 + case PhamePostTransaction::TYPE_VISIBILITY: 70 + if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) { 71 + $object->setDatePublished(time()); 72 + } else { 73 + $object->setDatePublished(0); 74 + } 75 + return $object->setVisibility($xaction->getNewValue()); 65 76 case PhamePostTransaction::TYPE_COMMENTS_WIDGET: 66 77 return $object->setCommentsWidget($xaction->getNewValue()); 67 78 } ··· 77 88 case PhamePostTransaction::TYPE_TITLE: 78 89 case PhamePostTransaction::TYPE_PHAME_TITLE: 79 90 case PhamePostTransaction::TYPE_BODY: 91 + case PhamePostTransaction::TYPE_VISIBILITY: 80 92 case PhamePostTransaction::TYPE_COMMENTS_WIDGET: 81 93 return; 82 94 }
+5 -5
src/applications/phame/query/PhamePostSearchEngine.php
··· 32 32 ->setLabel(pht('Visibility')) 33 33 ->setOptions(array( 34 34 '' => pht('All'), 35 - PhamePost::VISIBILITY_PUBLISHED => pht('Live'), 36 - PhamePost::VISIBILITY_DRAFT => pht('Draft'), 35 + PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), 36 + PhameConstants::VISIBILITY_DRAFT => pht('Draft'), 37 37 )), 38 38 ); 39 39 } ··· 45 45 protected function getBuiltinQueryNames() { 46 46 $names = array( 47 47 'all' => pht('All Posts'), 48 - 'live' => pht('Live Posts'), 48 + 'live' => pht('Published Posts'), 49 49 'draft' => pht('Draft Posts'), 50 50 ); 51 51 return $names; ··· 60 60 return $query; 61 61 case 'live': 62 62 return $query->setParameter( 63 - 'visibility', PhamePost::VISIBILITY_PUBLISHED); 63 + 'visibility', PhameConstants::VISIBILITY_PUBLISHED); 64 64 case 'draft': 65 65 return $query->setParameter( 66 - 'visibility', PhamePost::VISIBILITY_DRAFT); 66 + 'visibility', PhameConstants::VISIBILITY_DRAFT); 67 67 } 68 68 69 69 return parent::buildSavedQueryFromBuiltin($query_key);
+2 -13
src/applications/phame/storage/PhamePost.php
··· 13 13 const MARKUP_FIELD_BODY = 'markup:body'; 14 14 const MARKUP_FIELD_SUMMARY = 'markup:summary'; 15 15 16 - const VISIBILITY_DRAFT = 0; 17 - const VISIBILITY_PUBLISHED = 1; 18 - 19 16 protected $bloggerPHID; 20 17 protected $title; 21 18 protected $phameTitle; ··· 37 34 ->setBlogPHID($blog->getPHID()) 38 35 ->setBlog($blog) 39 36 ->setDatePublished(0) 40 - ->setVisibility(self::VISIBILITY_DRAFT); 37 + ->setVisibility(PhameConstants::VISIBILITY_PUBLISHED); 41 38 return $post; 42 39 } 43 40 ··· 66 63 } 67 64 68 65 public function isDraft() { 69 - return $this->getVisibility() == self::VISIBILITY_DRAFT; 66 + return $this->getVisibility() == PhameConstants::VISIBILITY_DRAFT; 70 67 } 71 68 72 69 public function getHumanName() { ··· 162 159 'summary' => PhabricatorMarkupEngine::summarize($this->getBody()), 163 160 'datePublished' => $this->getDatePublished(), 164 161 'published' => !$this->isDraft(), 165 - ); 166 - } 167 - 168 - public static function getVisibilityOptionsForSelect() { 169 - return array( 170 - self::VISIBILITY_DRAFT => pht('Draft: visible only to me.'), 171 - self::VISIBILITY_PUBLISHED => pht( 172 - 'Published: visible to the whole world.'), 173 162 ); 174 163 } 175 164
+47 -9
src/applications/phame/storage/PhamePostTransaction.php
··· 6 6 const TYPE_TITLE = 'phame.post.title'; 7 7 const TYPE_PHAME_TITLE = 'phame.post.phame.title'; 8 8 const TYPE_BODY = 'phame.post.body'; 9 + const TYPE_VISIBILITY = 'phame.post.visibility'; 9 10 const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget'; 10 11 11 12 const MAILTAG_CONTENT = 'phame-post-content'; ··· 54 55 break; 55 56 case self::TYPE_PHAME_TITLE: 56 57 case self::TYPE_BODY: 58 + case self::TYPE_VISIBILITY: 57 59 case self::TYPE_COMMENTS_WIDGET: 58 60 return 'fa-pencil'; 59 61 break; ··· 108 110 '%s updated the blog post.', 109 111 $this->renderHandleLink($author_phid)); 110 112 break; 113 + case self::TYPE_VISIBILITY: 114 + if ($new == PhameConstants::VISIBILITY_DRAFT) { 115 + return pht( 116 + '%s marked this post as a draft.', 117 + $this->renderHandleLink($author_phid)); 118 + } else { 119 + return pht( 120 + '%s published this post.', 121 + $this->renderHandleLink($author_phid)); 122 + } 123 + break; 111 124 case self::TYPE_PHAME_TITLE: 112 125 return pht( 113 126 '%s updated the post\'s Phame title to "%s".', ··· 153 166 $this->renderHandleLink($author_phid), 154 167 $this->renderHandleLink($object_phid)); 155 168 break; 169 + case self::TYPE_VISIBILITY: 170 + if ($new == PhameConstants::VISIBILITY_DRAFT) { 171 + return pht( 172 + '%s marked %s as a draft.', 173 + $this->renderHandleLink($author_phid), 174 + $this->renderHandleLink($object_phid)); 175 + } else { 176 + return pht( 177 + '%s published %s.', 178 + $this->renderHandleLink($author_phid), 179 + $this->renderHandleLink($object_phid)); 180 + } 181 + break; 156 182 case self::TYPE_PHAME_TITLE: 157 183 return pht( 158 184 '%s updated the Phame title for %s.', ··· 171 197 } 172 198 173 199 public function getBodyForFeed(PhabricatorFeedStory $story) { 174 - $new = $this->getNewValue(); 175 - 176 - $body = null; 177 - 200 + $text = null; 178 201 switch ($this->getTransactionType()) { 179 202 case self::TYPE_TITLE: 203 + if ($this->getOldValue() === null) { 204 + $post = $story->getPrimaryObject(); 205 + $text = $post->getBody(); 206 + } 207 + break; 208 + case self::TYPE_VISIBILITY: 209 + if ($this->getNewValue() == PhameConstants::VISIBILITY_PUBLISHED) { 210 + $post = $story->getPrimaryObject(); 211 + $text = $post->getBody(); 212 + } 213 + break; 180 214 case self::TYPE_BODY: 181 - return phutil_escape_html_newlines( 182 - id(new PhutilUTF8StringTruncator()) 183 - ->setMaximumGlyphs(128) 184 - ->truncateString($new)); 215 + $text = $this->getNewValue(); 185 216 break; 186 217 } 218 + 219 + if (strlen($text)) { 220 + return phutil_escape_html_newlines( 221 + id(new PhutilUTF8StringTruncator()) 222 + ->setMaximumGlyphs(128) 223 + ->truncateString($text)); 224 + } 225 + 187 226 return parent::getBodyForFeed($story); 188 227 } 189 228 ··· 200 239 201 240 return parent::getColor(); 202 241 } 203 - 204 242 205 243 public function hasChangeDetails() { 206 244 switch ($this->getTransactionType()) {