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

Ability to archive Phame Posts

Summary: Ref T9897. Adds ability to Archive a Phame Post (only visible under ApplicationSearch).

Test Plan: Archive a post, re-publish it, search for it, archive it again. View Home, Blog, Live pages.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T9897

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

+153 -20
+2
src/__phutil_library_map__.php
··· 3771 3771 'PhameLiveController' => 'applications/phame/controller/PhameLiveController.php', 3772 3772 'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php', 3773 3773 'PhamePost' => 'applications/phame/storage/PhamePost.php', 3774 + 'PhamePostArchiveController' => 'applications/phame/controller/post/PhamePostArchiveController.php', 3774 3775 'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php', 3775 3776 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', 3776 3777 'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php', ··· 8627 8628 'PhabricatorTokenReceiverInterface', 8628 8629 'PhabricatorConduitResultInterface', 8629 8630 ), 8631 + 'PhamePostArchiveController' => 'PhamePostController', 8630 8632 'PhamePostCommentController' => 'PhamePostController', 8631 8633 'PhamePostController' => 'PhameController', 8632 8634 'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
+1
src/applications/phame/application/PhabricatorPhameApplication.php
··· 55 55 'preview/' => 'PhabricatorMarkupPreviewController', 56 56 'framed/(?P<id>\d+)/' => 'PhamePostFramedController', 57 57 'move/(?P<id>\d+)/' => 'PhamePostMoveController', 58 + 'archive/(?P<id>\d+)/' => 'PhamePostArchiveController', 58 59 'comment/(?P<id>[1-9]\d*)/' => 'PhamePostCommentController', 59 60 ), 60 61 'blog/' => array(
+4 -1
src/applications/phame/constants/PhameConstants.php
··· 2 2 3 3 final class PhameConstants extends Phobject { 4 4 5 - const VISIBILITY_DRAFT = 0; 5 + const VISIBILITY_DRAFT = 0; 6 6 const VISIBILITY_PUBLISHED = 1; 7 + const VISIBILITY_ARCHIVED = 2; 7 8 8 9 public static function getPhamePostStatusMap() { 9 10 return array( 10 11 self::VISIBILITY_PUBLISHED => pht('Published'), 11 12 self::VISIBILITY_DRAFT => pht('Draft'), 13 + self::VISIBILITY_ARCHIVED => pht('Archived'), 12 14 ); 13 15 } 14 16 ··· 16 18 $map = array( 17 19 self::VISIBILITY_PUBLISHED => pht('Published'), 18 20 self::VISIBILITY_DRAFT => pht('Draft'), 21 + self::VISIBILITY_ARCHIVED => pht('Archived'), 19 22 ); 20 23 return idx($map, $status, pht('Unknown')); 21 24 }
+2 -2
src/applications/phame/controller/PhameHomeController.php
··· 35 35 $posts = id(new PhamePostQuery()) 36 36 ->setViewer($viewer) 37 37 ->withBlogPHIDs($blog_phids) 38 - ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) 38 + ->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED)) 39 39 ->executeWithCursorPager($pager); 40 40 41 41 if ($posts) { ··· 97 97 ->setViewer($viewer) 98 98 ->withBloggerPHIDs(array($viewer->getPHID())) 99 99 ->withBlogPHIDs(mpull($blogs, 'getPHID')) 100 - ->withVisibility(PhameConstants::VISIBILITY_DRAFT) 100 + ->withVisibility(array(PhameConstants::VISIBILITY_DRAFT)) 101 101 ->setLimit(5) 102 102 ->execute(); 103 103
+2 -1
src/applications/phame/controller/PhameLiveController.php
··· 97 97 98 98 // Only show published posts on external domains. 99 99 if ($is_external) { 100 - $post_query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED); 100 + $post_query->withVisibility( 101 + array(PhameConstants::VISIBILITY_PUBLISHED)); 101 102 } 102 103 103 104 $post = $post_query->executeOne();
+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(PhameConstants::VISIBILITY_PUBLISHED) 24 + ->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED)) 25 25 ->execute(); 26 26 27 27 $blog_uri = PhabricatorEnv::getProductionURI(
+6 -2
src/applications/phame/controller/blog/PhameBlogViewController.php
··· 19 19 20 20 $post_query = id(new PhamePostQuery()) 21 21 ->setViewer($viewer) 22 - ->withBlogPHIDs(array($blog->getPHID())); 22 + ->withBlogPHIDs(array($blog->getPHID())) 23 + ->withVisibility(array( 24 + PhameConstants::VISIBILITY_PUBLISHED, 25 + PhameConstants::VISIBILITY_DRAFT, 26 + )); 23 27 24 28 if ($is_live) { 25 - $post_query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED); 29 + $post_query->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED)); 26 30 } 27 31 28 32 $posts = $post_query->executeWithCursorPager($pager);
+56
src/applications/phame/controller/post/PhamePostArchiveController.php
··· 1 + <?php 2 + 3 + final class PhamePostArchiveController extends PhamePostController { 4 + 5 + public function handleRequest(AphrontRequest $request) { 6 + $viewer = $request->getViewer(); 7 + 8 + $id = $request->getURIData('id'); 9 + $post = id(new PhamePostQuery()) 10 + ->setViewer($viewer) 11 + ->withIDs(array($id)) 12 + ->requireCapabilities( 13 + array( 14 + PhabricatorPolicyCapability::CAN_VIEW, 15 + PhabricatorPolicyCapability::CAN_EDIT, 16 + )) 17 + ->executeOne(); 18 + if (!$post) { 19 + return new Aphront404Response(); 20 + } 21 + 22 + $cancel_uri = $post->getViewURI(); 23 + 24 + if ($request->isFormPost()) { 25 + $xactions = array(); 26 + 27 + $new_value = PhameConstants::VISIBILITY_ARCHIVED; 28 + $xactions[] = id(new PhamePostTransaction()) 29 + ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) 30 + ->setNewValue($new_value); 31 + 32 + id(new PhamePostEditor()) 33 + ->setActor($viewer) 34 + ->setContentSourceFromRequest($request) 35 + ->setContinueOnNoEffect(true) 36 + ->setContinueOnMissingFields(true) 37 + ->applyTransactions($post, $xactions); 38 + 39 + return id(new AphrontRedirectResponse()) 40 + ->setURI($cancel_uri); 41 + } 42 + 43 + $title = pht('Archive Post'); 44 + $body = pht( 45 + 'This post will revert to archived status and no longer be visible '. 46 + 'to other users or members of this blog.'); 47 + $button = pht('Archive Post'); 48 + 49 + return $this->newDialog() 50 + ->setTitle($title) 51 + ->appendParagraph($body) 52 + ->addSubmitButton($button) 53 + ->addCancelButton($cancel_uri); 54 + } 55 + 56 + }
+43 -7
src/applications/phame/controller/post/PhamePostViewController.php
··· 48 48 'Use "Publish" to publish this post.'))); 49 49 } 50 50 51 + if ($post->isArchived()) { 52 + $document->appendChild( 53 + id(new PHUIInfoView()) 54 + ->setSeverity(PHUIInfoView::SEVERITY_ERROR) 55 + ->setTitle(pht('Archived Post')) 56 + ->appendChild( 57 + pht('Only you can see this archived post until you publish it. '. 58 + 'Use "Publish" to publish this post.'))); 59 + } 60 + 51 61 if (!$post->getBlog()) { 52 62 $document->appendChild( 53 63 id(new PHUIInfoView()) ··· 92 102 $date = phabricator_datetime($post->getDatePublished(), $viewer); 93 103 if ($post->isDraft()) { 94 104 $subtitle = pht('Unpublished draft by %s.', $author); 105 + } else if ($post->isArchived()) { 106 + $subtitle = pht('Archived post by %s.', $author); 95 107 } else { 96 108 $subtitle = pht('Written by %s on %s.', $author, $date); 97 109 } ··· 207 219 ->setName(pht('Publish')) 208 220 ->setDisabled(!$can_edit) 209 221 ->setWorkflow(true)); 222 + $actions->addAction( 223 + id(new PhabricatorActionView()) 224 + ->setIcon('fa-ban') 225 + ->setHref($this->getApplicationURI('post/archive/'.$id.'/')) 226 + ->setName(pht('Archive')) 227 + ->setDisabled(!$can_edit) 228 + ->setWorkflow(true)); 229 + } else if ($post->isArchived()) { 230 + $actions->addAction( 231 + id(new PhabricatorActionView()) 232 + ->setIcon('fa-eye') 233 + ->setHref($this->getApplicationURI('post/publish/'.$id.'/')) 234 + ->setName(pht('Publish')) 235 + ->setDisabled(!$can_edit) 236 + ->setWorkflow(true)); 210 237 } else { 211 238 $actions->addAction( 212 239 id(new PhabricatorActionView()) ··· 215 242 ->setName(pht('Unpublish')) 216 243 ->setDisabled(!$can_edit) 217 244 ->setWorkflow(true)); 245 + $actions->addAction( 246 + id(new PhabricatorActionView()) 247 + ->setIcon('fa-ban') 248 + ->setHref($this->getApplicationURI('post/archive/'.$id.'/')) 249 + ->setName(pht('Archive')) 250 + ->setDisabled(!$can_edit) 251 + ->setWorkflow(true)); 218 252 } 219 253 220 254 if ($post->isDraft()) { ··· 223 257 $live_name = pht('View Live'); 224 258 } 225 259 226 - $actions->addAction( 227 - id(new PhabricatorActionView()) 228 - ->setUser($viewer) 229 - ->setIcon('fa-globe') 230 - ->setHref($post->getLiveURI()) 231 - ->setName($live_name)); 260 + if (!$post->isArchived()) { 261 + $actions->addAction( 262 + id(new PhabricatorActionView()) 263 + ->setUser($viewer) 264 + ->setIcon('fa-globe') 265 + ->setHref($post->getLiveURI()) 266 + ->setName($live_name)); 267 + } 232 268 233 269 return $actions; 234 270 } ··· 255 291 256 292 $query = id(new PhamePostQuery()) 257 293 ->setViewer($viewer) 258 - ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) 294 + ->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED)) 259 295 ->withBlogPHIDs(array($post->getBlog()->getPHID())) 260 296 ->setLimit(1); 261 297
+3
src/applications/phame/editor/PhamePostEditor.php
··· 66 66 case PhamePostTransaction::TYPE_VISIBILITY: 67 67 if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) { 68 68 $object->setDatePublished(0); 69 + } else if ($xaction->getNewValue() == 70 + PhameConstants::VISIBILITY_ARCHIVED) { 71 + $object->setDatePublished(0); 69 72 } else { 70 73 $object->setDatePublished(PhabricatorTime::getNow()); 71 74 }
+3 -3
src/applications/phame/query/PhamePostQuery.php
··· 29 29 return $this; 30 30 } 31 31 32 - public function withVisibility($visibility) { 32 + public function withVisibility(array $visibility) { 33 33 $this->visibility = $visibility; 34 34 return $this; 35 35 } ··· 98 98 $this->bloggerPHIDs); 99 99 } 100 100 101 - if ($this->visibility !== null) { 101 + if ($this->visibility) { 102 102 $where[] = qsprintf( 103 103 $conn, 104 - 'visibility = %d', 104 + 'visibility IN (%Ld)', 105 105 $this->visibility); 106 106 } 107 107
+10 -1
src/applications/phame/query/PhamePostSearchEngine.php
··· 19 19 $query = $this->newQuery(); 20 20 21 21 if (strlen($map['visibility'])) { 22 - $query->withVisibility($map['visibility']); 22 + $query->withVisibility(array($map['visibility'])); 23 23 } 24 24 25 25 return $query; ··· 35 35 '' => pht('All'), 36 36 PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), 37 37 PhameConstants::VISIBILITY_DRAFT => pht('Draft'), 38 + PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'), 38 39 )), 39 40 ); 40 41 } ··· 48 49 'all' => pht('All Posts'), 49 50 'live' => pht('Published Posts'), 50 51 'draft' => pht('Draft Posts'), 52 + 'archived' => pht('Archived Posts'), 51 53 ); 52 54 return $names; 53 55 } ··· 65 67 case 'draft': 66 68 return $query->setParameter( 67 69 'visibility', PhameConstants::VISIBILITY_DRAFT); 70 + case 'archived': 71 + return $query->setParameter( 72 + 'visibility', PhameConstants::VISIBILITY_ARCHIVED); 68 73 } 69 74 70 75 return parent::buildSavedQueryFromBuiltin($query_key); ··· 100 105 $item->setStatusIcon('fa-star-o grey'); 101 106 $item->setDisabled(true); 102 107 $item->addIcon('none', pht('Draft Post')); 108 + } else if ($post->isArchived()) { 109 + $item->setStatusIcon('fa-ban grey'); 110 + $item->setDisabled(true); 111 + $item->addIcon('none', pht('Archived Post')); 103 112 } else { 104 113 $date = $post->getDatePublished(); 105 114 $item->setEpoch($date);
+9 -2
src/applications/phame/storage/PhamePost.php
··· 53 53 public function getLiveURI() { 54 54 $blog = $this->getBlog(); 55 55 $is_draft = $this->isDraft(); 56 - if (strlen($blog->getDomain()) && !$is_draft) { 56 + $is_archived = $this->isArchived(); 57 + if (strlen($blog->getDomain()) && !$is_draft && !$is_archived) { 57 58 return $this->getExternalLiveURI(); 58 59 } else { 59 60 return $this->getInternalLiveURI(); ··· 90 91 91 92 public function isDraft() { 92 93 return ($this->getVisibility() == PhameConstants::VISIBILITY_DRAFT); 94 + } 95 + 96 + public function isArchived() { 97 + return ($this->getVisibility() == PhameConstants::VISIBILITY_ARCHIVED); 93 98 } 94 99 95 100 protected function getConfiguration() { ··· 165 170 166 171 switch ($capability) { 167 172 case PhabricatorPolicyCapability::CAN_VIEW: 168 - if (!$this->isDraft() && $this->getBlog()) { 173 + if (!$this->isDraft() && !$this->isArchived() && $this->getBlog()) { 169 174 return $this->getBlog()->getViewPolicy(); 170 175 } else if ($this->getBlog()) { 171 176 return $this->getBlog()->getEditPolicy(); ··· 318 323 319 324 public function getFieldValuesForConduit() { 320 325 if ($this->isDraft()) { 326 + $date_published = null; 327 + } else if ($this->isArchived()) { 321 328 $date_published = null; 322 329 } else { 323 330 $date_published = (int)$this->getDatePublished();
+11
src/applications/phame/storage/PhamePostTransaction.php
··· 73 73 case self::TYPE_VISIBILITY: 74 74 if ($new == PhameConstants::VISIBILITY_PUBLISHED) { 75 75 return 'fa-globe'; 76 + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 77 + return 'fa-ban'; 76 78 } else { 77 79 return 'fa-eye-slash'; 78 80 } ··· 144 146 return pht( 145 147 '%s marked this post as a draft.', 146 148 $this->renderHandleLink($author_phid)); 149 + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 150 + return pht( 151 + '%s archived this post.', 152 + $this->renderHandleLink($author_phid)); 147 153 } else { 148 154 return pht( 149 155 '%s published this post.', ··· 199 205 if ($new == PhameConstants::VISIBILITY_DRAFT) { 200 206 return pht( 201 207 '%s marked %s as a draft.', 208 + $this->renderHandleLink($author_phid), 209 + $this->renderHandleLink($object_phid)); 210 + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { 211 + return pht( 212 + '%s marked %s as archived.', 202 213 $this->renderHandleLink($author_phid), 203 214 $this->renderHandleLink($object_phid)); 204 215 } else {