diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 26ca311dbb..b4dd3cea66 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1147,7 +1147,6 @@ phutil_register_library_map(array( 'PhabricatorXHProfSample' => 'applications/xhprof/storage/PhabricatorXHProfSample.php', 'PhabricatorXHProfSampleListController' => 'applications/xhprof/controller/PhabricatorXHProfSampleListController.php', 'PhabricatorXHProfSampleListView' => 'applications/xhprof/view/PhabricatorXHProfSampleListView.php', - 'PhameAllPostListController' => 'applications/phame/controller/post/list/PhameAllPostListController.php', 'PhameBlog' => 'applications/phame/storage/PhameBlog.php', 'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php', 'PhameBlogDetailView' => 'applications/phame/view/PhameBlogDetailView.php', @@ -1157,20 +1156,17 @@ phutil_register_library_map(array( 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 'PhameBlogSkin' => 'applications/phame/view/skins/PhameBlogSkin.php', 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', - 'PhameBloggerPostListController' => 'applications/phame/controller/post/list/PhameBloggerPostListController.php', 'PhameController' => 'applications/phame/controller/PhameController.php', 'PhameDAO' => 'applications/phame/storage/PhameDAO.php', - 'PhameDraftListController' => 'applications/phame/controller/post/list/PhameDraftListController.php', 'PhamePost' => 'applications/phame/storage/PhamePost.php', 'PhamePostDeleteController' => 'applications/phame/controller/post/PhamePostDeleteController.php', 'PhamePostDetailView' => 'applications/phame/view/PhamePostDetailView.php', 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', - 'PhamePostListBaseController' => 'applications/phame/controller/post/list/PhamePostListBaseController.php', + 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', 'PhamePostListView' => 'applications/phame/view/PhamePostListView.php', 'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php', 'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php', 'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php', - 'PhameUserPostListController' => 'applications/phame/controller/post/list/PhameUserPostListController.php', 'PhortuneMonthYearExpiryControl' => 'applications/phortune/control/PhortuneMonthYearExpiryControl.php', 'PhortuneStripeBaseController' => 'applications/phortune/stripe/controller/PhortuneStripeBaseController.php', 'PhortuneStripePaymentFormView' => 'applications/phortune/stripe/view/PhortuneStripePaymentFormView.php', @@ -2272,7 +2268,6 @@ phutil_register_library_map(array( 'PhabricatorXHProfSample' => 'PhabricatorXHProfDAO', 'PhabricatorXHProfSampleListController' => 'PhabricatorXHProfController', 'PhabricatorXHProfSampleListView' => 'AphrontView', - 'PhameAllPostListController' => 'PhamePostListBaseController', 'PhameBlog' => array( 0 => 'PhameDAO', @@ -2286,10 +2281,8 @@ phutil_register_library_map(array( 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhameBlogSkin' => 'AphrontView', 'PhameBlogViewController' => 'PhameController', - 'PhameBloggerPostListController' => 'PhamePostListBaseController', 'PhameController' => 'PhabricatorController', 'PhameDAO' => 'PhabricatorLiskDAO', - 'PhameDraftListController' => 'PhamePostListBaseController', 'PhamePost' => array( 0 => 'PhameDAO', @@ -2298,12 +2291,11 @@ phutil_register_library_map(array( 'PhamePostDeleteController' => 'PhameController', 'PhamePostDetailView' => 'AphrontView', 'PhamePostEditController' => 'PhameController', - 'PhamePostListBaseController' => 'PhameController', + 'PhamePostListController' => 'PhameController', 'PhamePostListView' => 'AphrontView', 'PhamePostPreviewController' => 'PhameController', 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhamePostViewController' => 'PhameController', - 'PhameUserPostListController' => 'PhamePostListBaseController', 'PhortuneMonthYearExpiryControl' => 'AphrontFormControl', 'PhortuneStripeBaseController' => 'PhabricatorController', 'PhortuneStripePaymentFormView' => 'AphrontView', diff --git a/src/applications/phame/application/PhabricatorApplicationPhame.php b/src/applications/phame/application/PhabricatorApplicationPhame.php index 3ceb07f00c..b588365c99 100644 --- a/src/applications/phame/application/PhabricatorApplicationPhame.php +++ b/src/applications/phame/application/PhabricatorApplicationPhame.php @@ -45,21 +45,18 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication { public function getRoutes() { return array( '/phame/' => array( - '' => 'PhameAllPostListController', + '' => 'PhamePostListController', 'post/' => array( - '' => 'PhameUserPostListController', - 'delete/(?P[^/]+)/' => 'PhamePostDeleteController', - 'edit/(?P[^/]+)/' => 'PhamePostEditController', - 'new/' => 'PhamePostEditController', - 'preview/' => 'PhamePostPreviewController', - 'view/(?P[^/]+)/' => 'PhamePostViewController', + '(?:(?Pdraft|all)/)?' => 'PhamePostListController', + 'blogger/(?P[\w\.-_]+)/' => 'PhamePostListController', + 'delete/(?P[^/]+)/' => 'PhamePostDeleteController', + 'edit/(?P[^/]+)/' => 'PhamePostEditController', + 'new/' => 'PhamePostEditController', + 'preview/' => 'PhamePostPreviewController', + 'view/(?P[^/]+)/' => 'PhamePostViewController', ), - 'draft/' => array( - '' => 'PhameDraftListController', - 'new/' => 'PhamePostEditController', - ), - 'blog/(?:(?Puser|all)/)?' => 'PhameBlogListController', 'blog/' => array( + '(?:(?Puser|all)/)?' => 'PhameBlogListController', 'delete/(?P[^/]+)/' => 'PhameBlogDeleteController', 'edit/(?P[^/]+)/' => 'PhameBlogEditController', 'view/(?P[^/]+)/' => 'PhameBlogViewController', @@ -67,8 +64,6 @@ final class PhabricatorApplicationPhame extends PhabricatorApplication { 'new/' => 'PhameBlogEditController', ), 'posts/' => array( - '' => 'PhameUserPostListController', - '(?P\w+)/' => 'PhameBloggerPostListController', '(?P\w+)/(?P.+/)' => 'PhamePostViewController', ), diff --git a/src/applications/phame/controller/PhameController.php b/src/applications/phame/controller/PhameController.php index 2b571f98cc..034b8092c3 100644 --- a/src/applications/phame/controller/PhameController.php +++ b/src/applications/phame/controller/PhameController.php @@ -81,18 +81,15 @@ abstract class PhameController extends PhabricatorController { $nav->addSpacer(); $nav->addLabel('Posts'); - $nav->addFilter('draft', + $nav->addFilter('post/draft', 'My Drafts'); foreach ($this->getSideNavExtraDraftFilters() as $draft_filter) { $nav->addFilter($draft_filter['key'], $draft_filter['name'], idx($draft_filter, 'uri')); } - $nav->addFilter('post', - 'My Posts'); - $nav->addFilter('post/all', - 'All Posts', - $base_uri); + $nav->addFilter('post/', 'My Posts'); + $nav->addFilter('post/all', 'All Posts'); foreach ($this->getSideNavExtraPostFilters() as $post_filter) { $nav->addFilter($post_filter['key'], $post_filter['name'], @@ -167,7 +164,24 @@ abstract class PhameController extends PhabricatorController { foreach ($posts as $post) { $item = id(new PhabricatorObjectItemView()) ->setHeader($post->getTitle()) - ->setHref($this->getApplicationURI('post/view/'.$post->getPHID())); + ->setHref($this->getApplicationURI('post/view/'.$post->getPHID())) + ->addDetail( + pht('Blogger'), + $this->getHandle($post->getBloggerPHID())->renderLink()) + ->addDetail( + pht('Blog'), + $post->getBlog() + ? $this->getHandle($post->getBlog()->getPHID())->renderLink() + : '-'); + + if ($post->isDraft()) { + $item->addAttribute(pht('Draft')); + } else { + $date_published = phabricator_datetime( + $post->getDatePublished(), + $user); + $item->addAttribute(pht('Published on %s', $date_published)); + } $list->addItem($item); } diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php index 68bf5f6f98..4bc1b38275 100644 --- a/src/applications/phame/controller/blog/PhameBlogViewController.php +++ b/src/applications/phame/controller/blog/PhameBlogViewController.php @@ -65,6 +65,11 @@ final class PhameBlogViewController extends PhameController { $header = id(new PhabricatorHeaderView()) ->setHeader($blog->getName()); + $handle_phids = array_merge( + mpull($posts, 'getBloggerPHID'), + mpull($posts, 'getBlogPHID')); + $this->loadHandles($handle_phids); + $actions = $this->renderActions($blog, $user); $properties = $this->renderProperties($blog, $user); $post_list = $this->renderPostList( diff --git a/src/applications/phame/controller/post/PhamePostListController.php b/src/applications/phame/controller/post/PhamePostListController.php new file mode 100644 index 0000000000..3f926c9e98 --- /dev/null +++ b/src/applications/phame/controller/post/PhamePostListController.php @@ -0,0 +1,105 @@ +filter = idx($data, 'filter', 'blogger'); + $this->bloggername = idx($data, 'bloggername'); + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $query = id(new PhamePostQuery()) + ->setViewer($user); + + switch ($this->filter) { + case 'draft': + $query->withBloggerPHIDs(array($user->getPHID())); + $query->withVisibility(PhamePost::VISIBILITY_DRAFT); + $nodata = pht('You have no unpublished drafts.'); + $title = pht('Unpublished Drafts'); + break; + case 'blogger': + if ($this->bloggername) { + $blogger = id(new PhabricatorUser())->loadOneWhere( + 'username = %s', + $this->bloggername); + if (!$blogger) { + return new Aphront404Response(); + } + } else { + $blogger = $user; + } + + $query->withBloggerPHIDs(array($blogger->getPHID())); + if ($blogger->getPHID() == $user->getPHID()) { + $nodata = pht('You have not written any posts.'); + } else { + $nodata = pht('%s has not written any posts.', $blogger); + } + $title = pht('Posts By %s', $blogger); + break; + case 'all': + $nodata = pht('There are no visible posts.'); + $title = pht('Posts'); + break; + default: + throw new Exception("Unknown filter '{$this->filter}'!"); + } + + $pager = id(new AphrontCursorPagerView()) + ->readFromRequest($request); + + $posts = $query->executeWithCursorPager($pager); + + $handle_phids = array_merge( + mpull($posts, 'getBloggerPHID'), + mpull($posts, 'getBlogPHID')); + $this->loadHandles($handle_phids); + + + $header = id(new PhabricatorHeaderView()) + ->setHeader($title); + $post_list = $this->renderPostList($posts, $user, $nodata); + + $nav = $this->renderSideNavFilterView(null); + $nav->appendChild( + array( + $header, + $post_list, + )); + + return $this->buildApplicationPage( + $nav, + array( + 'title' => $title, + 'device' => true, + )); + } + + +} diff --git a/src/applications/phame/controller/post/list/PhameAllPostListController.php b/src/applications/phame/controller/post/list/PhameAllPostListController.php deleted file mode 100644 index 0d6ce42284..0000000000 --- a/src/applications/phame/controller/post/list/PhameAllPostListController.php +++ /dev/null @@ -1,93 +0,0 @@ -getRequest()->getUser(); - - $new_link = phutil_render_tag( - 'a', - array( - 'href' => '/phame/post/new/', - 'class' => 'button green', - ), - 'write a blog post' - ); - - $remarkup_link = phutil_render_tag( - 'a', - array( - 'href' => - PhabricatorEnv::getDoclink('article/Remarkup_Reference.html'), - ), - 'remarkup' - ); - - $guide_link = phutil_render_tag( - 'a', - array( - 'href' => PhabricatorEnv::getDoclink('article/Phame_User_Guide.html'), - ), - 'Phame user guide' - ); - - $notices = array( - 'Seek phame and '.$new_link, - 'Use '.$remarkup_link.' for maximal elegance, grace, and style. ', - 'If you need more help try the '.$guide_link.'.', - ); - - $notice_view = $this->buildNoticeView(); - foreach ($notices as $notice) { - $notice_view->appendChild('

'.$notice.'

'); - } - - return $notice_view; - } - - public function processRequest() { - $user = $this->getRequest()->getUser(); - - $query = id(new PhamePostQuery()) - ->setViewer($user); - $this->setPhamePostQuery($query); - - $this->setActions(array()); - - $page_title = 'All Posts'; - $this->setPageTitle($page_title); - - $this->setShowSideNav(true); - - return $this->buildPostListPageResponse(); - } - -} diff --git a/src/applications/phame/controller/post/list/PhameBloggerPostListController.php b/src/applications/phame/controller/post/list/PhameBloggerPostListController.php deleted file mode 100644 index 2914de89ce..0000000000 --- a/src/applications/phame/controller/post/list/PhameBloggerPostListController.php +++ /dev/null @@ -1,75 +0,0 @@ -bloggerName = $blogger_name; - return $this; - } - private function getBloggerName() { - return $this->bloggerName; - } - - public function shouldRequireLogin() { - // TODO -- get policy logic going - // return PhabricatorEnv::getEnvConfig('policy.allow-public'); - return true; - } - - public function willProcessRequest(array $data) { - $this->setBloggerName(idx($data, 'bloggername')); - } - - public function processRequest() { - $user = $this->getRequest()->getUser(); - - $blogger = id(new PhabricatorUser())->loadOneWhere( - 'username = %s', - $this->getBloggerName()); - if (!$blogger) { - return new Aphront404Response(); - } - $blogger_phid = $blogger->getPHID(); - if ($blogger_phid == $user->getPHID()) { - $actions = array('view', 'edit'); - } else { - $actions = array('view'); - } - $this->setActions($actions); - - $query = id(new PhamePostQuery()) - ->setViewer($user) - ->withBloggerPHIDs(array($blogger_phid)); - - $this->setPhamePostQuery($query); - - $page_title = 'Posts by '.$this->getBloggerName(); - $this->setPageTitle($page_title); - - $this->setShowSideNav(false); - - return $this->buildPostListPageResponse(); - } -} diff --git a/src/applications/phame/controller/post/list/PhameDraftListController.php b/src/applications/phame/controller/post/list/PhameDraftListController.php deleted file mode 100644 index 0dd1d1fb56..0000000000 --- a/src/applications/phame/controller/post/list/PhameDraftListController.php +++ /dev/null @@ -1,70 +0,0 @@ -getRequest(); - - if ($request->getExists('deleted')) { - $notice_view = $this->buildNoticeView() - ->appendChild('Deleted draft successfully.'); - } else { - $notice_view = null; - } - - return $notice_view; - } - - public function processRequest() { - $user = $this->getRequest()->getUser(); - $phid = $user->getPHID(); - - $query = id(new PhamePostQuery()) - ->setViewer($user) - ->withBloggerPHIDs(array($phid)) - ->withVisibility(PhamePost::VISIBILITY_DRAFT); - - $this->setPhamePostQuery($query); - - $actions = array('view', 'edit'); - $this->setActions($actions); - - $this->setPageTitle('My Drafts'); - - $this->setShowSideNav(true); - - return $this->buildPostListPageResponse(); - } -} diff --git a/src/applications/phame/controller/post/list/PhamePostListBaseController.php b/src/applications/phame/controller/post/list/PhamePostListBaseController.php deleted file mode 100644 index 7c17fae691..0000000000 --- a/src/applications/phame/controller/post/list/PhamePostListBaseController.php +++ /dev/null @@ -1,99 +0,0 @@ -pageTitle = $page_title; - return $this; - } - private function getPageTitle() { - return $this->pageTitle; - } - - protected function setActions($actions) { - $this->actions = $actions; - return $this; - } - private function getActions() { - return $this->actions; - } - - protected function setPhamePostQuery(PhamePostQuery $query) { - $this->phamePostQuery = $query; - return $this; - } - private function getPhamePostQuery() { - return $this->phamePostQuery; - } - - protected function isDraft() { - return false; - } - - protected function getNoticeView() { - return null; - } - - private function loadBloggersFromPosts(array $posts) { - assert_instances_of($posts, 'PhamePost'); - if (empty($posts)) { - return array(); - } - - $blogger_phids = mpull($posts, 'getBloggerPHID', 'getBloggerPHID'); - - return - $this->loadViewerHandles($blogger_phids); - } - - protected function buildPostListPageResponse() { - $request = $this->getRequest(); - $pager = $this->getPager(); - $query = $this->getPhamePostQuery(); - $posts = $query->executeWithOffsetPager($pager); - - $bloggers = $this->loadBloggersFromPosts($posts); - - $panel = id(new PhamePostListView()) - ->setUser($this->getRequest()->getUser()) - ->setBloggers($bloggers) - ->setPosts($posts) - ->setActions($this->getActions()) - ->setRequestURI($request->getRequestURI()) - ->setDraftList($this->isDraft()); - - return $this->buildStandardPageResponse( - array( - $this->getNoticeView(), - $panel, - $pager - ), - array( - 'title' => $this->getPageTitle(), - )); - } -} diff --git a/src/applications/phame/controller/post/list/PhameUserPostListController.php b/src/applications/phame/controller/post/list/PhameUserPostListController.php deleted file mode 100644 index 35595f265e..0000000000 --- a/src/applications/phame/controller/post/list/PhameUserPostListController.php +++ /dev/null @@ -1,65 +0,0 @@ -getRequest(); - - if ($request->getExists('deleted')) { - $notice_view = $this->buildNoticeView() - ->appendChild('Deleted post successfully.'); - } else { - $notice_view = null; - } - - return $notice_view; - } - - public function processRequest() { - $user = $this->getRequest()->getUser(); - $phid = $user->getPHID(); - - $query = id(new PhamePostQuery()) - ->setViewer($user) - ->withBloggerPHIDs(array($phid)); - - $this->setPhamePostQuery($query); - - $actions = array('view', 'edit'); - $this->setActions($actions); - - $this->setPageTitle('My Posts'); - - $this->setShowSideNav(true); - - return $this->buildPostListPageResponse(); - } -} diff --git a/src/applications/phame/query/PhamePostQuery.php b/src/applications/phame/query/PhamePostQuery.php index c07a3882e2..85e6676e1a 100644 --- a/src/applications/phame/query/PhamePostQuery.php +++ b/src/applications/phame/query/PhamePostQuery.php @@ -77,7 +77,7 @@ final class PhamePostQuery extends PhabricatorCursorPagedPolicyAwareQuery { ->setViewer($this->getViewer()) ->withPHIDs($blog_phids) ->execute(); - $blogs = mpull($blogs, 'getPHID'); + $blogs = mpull($blogs, null, 'getPHID'); foreach ($posts as $post) { if (isset($blogs[$post->getBlogPHID()])) { $post->setBlog($blogs[$post->getBlogPHID()]);