From dafdd39ba9e85cd305ee5a9b86e5a5c810de3d58 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Tue, 8 Dec 2015 14:51:44 -0800 Subject: [PATCH] Clean up URIs in Phame Summary: Normalize "getViewURI" and "getLiveURI" for PhameBlog and PhamePost. Use pretty URIs in PhamePost Test Plan: View Recent, View posts, edit post, new post, move post, view live. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14713 --- .../application/PhabricatorPhameApplication.php | 1 + .../controller/blog/PhameBlogFeedController.php | 2 +- .../controller/post/PhamePostEditController.php | 15 ++++++++++++--- .../post/PhamePostNotLiveController.php | 11 ++--------- .../controller/post/PhamePostViewController.php | 12 +++--------- .../phame/query/PhamePostSearchEngine.php | 2 +- src/applications/phame/storage/PhamePost.php | 7 ++++++- src/applications/phame/view/PhamePostListView.php | 2 +- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/applications/phame/application/PhabricatorPhameApplication.php b/src/applications/phame/application/PhabricatorPhameApplication.php index 4fb907b929..2c2d749bc1 100644 --- a/src/applications/phame/application/PhabricatorPhameApplication.php +++ b/src/applications/phame/application/PhabricatorPhameApplication.php @@ -47,6 +47,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { 'edit/(?:(?P[^/]+)/)?' => 'PhamePostEditController', 'history/(?P\d+)/' => 'PhamePostHistoryController', 'view/(?P\d+)/' => 'PhamePostViewController', + 'view/(?P\d+)/(?P[^/]+)/' => 'PhamePostViewController', 'publish/(?P\d+)/' => 'PhamePostPublishController', 'preview/(?P\d+)/' => 'PhamePostPreviewController', 'unpublish/(?P\d+)/' => 'PhamePostUnpublishController', diff --git a/src/applications/phame/controller/blog/PhameBlogFeedController.php b/src/applications/phame/controller/blog/PhameBlogFeedController.php index b74465ef5e..b8b47c019f 100644 --- a/src/applications/phame/controller/blog/PhameBlogFeedController.php +++ b/src/applications/phame/controller/blog/PhameBlogFeedController.php @@ -62,7 +62,7 @@ final class PhameBlogFeedController extends PhameBlogController { foreach ($posts as $post) { $content[] = hsprintf(''); $content[] = phutil_tag('title', array(), $post->getTitle()); - $content[] = phutil_tag('link', array('href' => $post->getViewURI())); + $content[] = phutil_tag('link', array('href' => $post->getLiveURI())); $content[] = phutil_tag('id', array(), PhabricatorEnv::getProductionURI( '/phame/post/view/'.$post->getID().'/')); diff --git a/src/applications/phame/controller/post/PhamePostEditController.php b/src/applications/phame/controller/post/PhamePostEditController.php index a6bf1732fb..9672150ab2 100644 --- a/src/applications/phame/controller/post/PhamePostEditController.php +++ b/src/applications/phame/controller/post/PhamePostEditController.php @@ -6,6 +6,10 @@ final class PhamePostEditController extends PhamePostController { $viewer = $request->getViewer(); $id = $request->getURIData('id'); + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb( + pht('Blogs'), + $this->getApplicationURI('blog/')); if ($id) { $post = id(new PhamePostQuery()) ->setViewer($viewer) @@ -29,6 +33,9 @@ final class PhamePostEditController extends PhamePostController { $v_projects = array_reverse($v_projects); $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( $post->getPHID()); + $blog = $post->getBlog(); + + } else { $blog = id(new PhameBlogQuery()) ->setViewer($viewer) @@ -102,7 +109,7 @@ final class PhamePostEditController extends PhamePostController { try { $editor->applyTransactions($post, $xactions); - $uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); + $uri = $post->getViewURI(); return id(new AphrontRedirectResponse())->setURI($uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; @@ -192,10 +199,12 @@ final class PhamePostEditController extends PhamePostController { ->setValidationException($validation_exception) ->setForm($form); - $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb( + $blog->getName(), + $blog->getViewURI()); $crumbs->addTextCrumb( $page_title, - $this->getApplicationURI('/post/view/'.$id.'/')); + $cancel_uri); return $this->newPage() ->setTitle($page_title) diff --git a/src/applications/phame/controller/post/PhamePostNotLiveController.php b/src/applications/phame/controller/post/PhamePostNotLiveController.php index c0f986ffda..f09759e801 100644 --- a/src/applications/phame/controller/post/PhamePostNotLiveController.php +++ b/src/applications/phame/controller/post/PhamePostNotLiveController.php @@ -15,17 +15,10 @@ final class PhamePostNotLiveController extends PhamePostController { } $reasons = array(); - if (!$post->getBlog()) { - $reasons[] = phutil_tag('p', array(), pht( - 'You can not view the live version of this post because it '. - 'is not associated with a blog. Move the post to a blog in order to '. - 'view it live.')); - } - if ($post->isDraft()) { $reasons[] = phutil_tag('p', array(), pht( 'You can not view the live version of this post because it '. - 'is still a draft. Use "Preview/Publish" to publish the post.')); + 'is still a draft. Use "Preview" or "Publish" to publish the post.')); } if ($reasons) { @@ -45,7 +38,7 @@ final class PhamePostNotLiveController extends PhamePostController { // No reason this can't go live, maybe an old link. Kick them live and see // what happens. - $live_uri = $post->getViewURI(); + $live_uri = $post->getLiveURI(); return id(new AphrontRedirectResponse())->setURI($live_uri); } diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index 89541de268..c3a1da5026 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -25,15 +25,9 @@ final class PhamePostViewController extends PhamePostController { $crumbs->addTextCrumb( pht('Blogs'), $this->getApplicationURI('blog/')); - if ($blog) { - $crumbs->addTextCrumb( - $blog->getName(), - $this->getApplicationURI('blog/view/'.$blog->getID().'/')); - } else { - $crumbs->addTextCrumb( - pht('[No Blog]'), - null); - } + $crumbs->addTextCrumb( + $blog->getName(), + $this->getApplicationURI('blog/view/'.$blog->getID().'/')); $crumbs->addTextCrumb( $post->getTitle(), $this->getApplicationURI('post/view/'.$post->getID().'/')); diff --git a/src/applications/phame/query/PhamePostSearchEngine.php b/src/applications/phame/query/PhamePostSearchEngine.php index 68c94552bb..5002c84e0d 100644 --- a/src/applications/phame/query/PhamePostSearchEngine.php +++ b/src/applications/phame/query/PhamePostSearchEngine.php @@ -93,7 +93,7 @@ final class PhamePostSearchEngine ->setObject($post) ->setHeader($post->getTitle()) ->setStatusIcon('fa-star') - ->setHref($this->getApplicationURI("/post/view/{$id}/")) + ->setHref($post->getViewURI()) ->addAttribute($blog_name); if ($post->isDraft()) { $item->setStatusIcon('fa-star-o grey'); diff --git a/src/applications/phame/storage/PhamePost.php b/src/applications/phame/storage/PhamePost.php index 3212f128b2..5fa74857c5 100644 --- a/src/applications/phame/storage/PhamePost.php +++ b/src/applications/phame/storage/PhamePost.php @@ -48,7 +48,7 @@ final class PhamePost extends PhameDAO return $this->blog; } - public function getViewURI() { + public function getLiveURI() { // go for the pretty uri if we can $domain = ($this->blog ? $this->blog->getDomain() : ''); if ($domain) { @@ -59,6 +59,11 @@ final class PhamePost extends PhameDAO return PhabricatorEnv::getProductionURI($uri); } + public function getViewURI() { + $phame_title = PhabricatorSlug::normalize($this->getPhameTitle()); + return '/phame/post/view/'.$this->getID().'/'.$phame_title; + } + public function getEditURI() { return '/phame/post/edit/'.$this->getID().'/'; } diff --git a/src/applications/phame/view/PhamePostListView.php b/src/applications/phame/view/PhamePostListView.php index e8272d81bf..aaa014c9dc 100644 --- a/src/applications/phame/view/PhamePostListView.php +++ b/src/applications/phame/view/PhamePostListView.php @@ -89,7 +89,7 @@ final class PhamePostListView extends AphrontTagView { $item = id(new PHUIDocumentSummaryView()) ->setTitle($post->getTitle()) - ->setHref('/phame/post/view/'.$post->getID().'/') + ->setHref($post->getViewURI()) ->setSubtitle($subtitle) ->setImage($blogger_image) ->setImageHref($blogger_uri)