1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 16:00:59 +01:00

Modernize Phame

Summary: Updates Phame for new modern methods.

Test Plan: New blog, edit blog, new post, edit post, publish post.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14419
This commit is contained in:
Chad Little 2015-11-05 14:53:24 -08:00
parent e4806631a5
commit 5024560de1
22 changed files with 153 additions and 161 deletions

View file

@ -3245,6 +3245,7 @@ phutil_register_library_map(array(
'PhameBasicBlogSkin' => 'applications/phame/skins/PhameBasicBlogSkin.php', 'PhameBasicBlogSkin' => 'applications/phame/skins/PhameBasicBlogSkin.php',
'PhameBasicTemplateBlogSkin' => 'applications/phame/skins/PhameBasicTemplateBlogSkin.php', 'PhameBasicTemplateBlogSkin' => 'applications/phame/skins/PhameBasicTemplateBlogSkin.php',
'PhameBlog' => 'applications/phame/storage/PhameBlog.php', 'PhameBlog' => 'applications/phame/storage/PhameBlog.php',
'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php',
'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php', 'PhameBlogDeleteController' => 'applications/phame/controller/blog/PhameBlogDeleteController.php',
'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php',
'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php', 'PhameBlogEditor' => 'applications/phame/editor/PhameBlogEditor.php',
@ -3263,6 +3264,7 @@ phutil_register_library_map(array(
'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php', 'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php',
'PhameDAO' => 'applications/phame/storage/PhameDAO.php', 'PhameDAO' => 'applications/phame/storage/PhameDAO.php',
'PhamePost' => 'applications/phame/storage/PhamePost.php', 'PhamePost' => 'applications/phame/storage/PhamePost.php',
'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php',
'PhamePostDeleteController' => 'applications/phame/controller/post/PhamePostDeleteController.php', 'PhamePostDeleteController' => 'applications/phame/controller/post/PhamePostDeleteController.php',
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php', 'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
@ -7503,18 +7505,19 @@ phutil_register_library_map(array(
'PhabricatorProjectInterface', 'PhabricatorProjectInterface',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
), ),
'PhameBlogDeleteController' => 'PhameController', 'PhameBlogController' => 'PhameController',
'PhameBlogEditController' => 'PhameController', 'PhameBlogDeleteController' => 'PhameBlogController',
'PhameBlogEditController' => 'PhameBlogController',
'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor', 'PhameBlogEditor' => 'PhabricatorApplicationTransactionEditor',
'PhameBlogFeedController' => 'PhameController', 'PhameBlogFeedController' => 'PhameBlogController',
'PhameBlogListController' => 'PhameController', 'PhameBlogListController' => 'PhameBlogController',
'PhameBlogLiveController' => 'PhameController', 'PhameBlogLiveController' => 'PhameBlogController',
'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhameBlogSite' => 'PhameSite', 'PhameBlogSite' => 'PhameSite',
'PhameBlogSkin' => 'PhabricatorController', 'PhameBlogSkin' => 'PhabricatorController',
'PhameBlogTransaction' => 'PhabricatorApplicationTransaction', 'PhameBlogTransaction' => 'PhabricatorApplicationTransaction',
'PhameBlogViewController' => 'PhameController', 'PhameBlogViewController' => 'PhameBlogController',
'PhameCelerityResources' => 'CelerityResources', 'PhameCelerityResources' => 'CelerityResources',
'PhameConduitAPIMethod' => 'ConduitAPIMethod', 'PhameConduitAPIMethod' => 'ConduitAPIMethod',
'PhameController' => 'PhabricatorController', 'PhameController' => 'PhabricatorController',
@ -7530,22 +7533,23 @@ phutil_register_library_map(array(
'PhabricatorSubscribableInterface', 'PhabricatorSubscribableInterface',
'PhabricatorTokenReceiverInterface', 'PhabricatorTokenReceiverInterface',
), ),
'PhamePostDeleteController' => 'PhameController', 'PhamePostController' => 'PhameController',
'PhamePostEditController' => 'PhameController', 'PhamePostDeleteController' => 'PhamePostController',
'PhamePostEditController' => 'PhamePostController',
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor', 'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
'PhamePostFramedController' => 'PhameController', 'PhamePostFramedController' => 'PhamePostController',
'PhamePostListController' => 'PhameController', 'PhamePostListController' => 'PhamePostController',
'PhamePostNewController' => 'PhameController', 'PhamePostNewController' => 'PhamePostController',
'PhamePostNotLiveController' => 'PhameController', 'PhamePostNotLiveController' => 'PhamePostController',
'PhamePostPreviewController' => 'PhameController', 'PhamePostPreviewController' => 'PhamePostController',
'PhamePostPublishController' => 'PhameController', 'PhamePostPublishController' => 'PhamePostController',
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhamePostTransaction' => 'PhabricatorApplicationTransaction', 'PhamePostTransaction' => 'PhabricatorApplicationTransaction',
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhamePostUnpublishController' => 'PhameController', 'PhamePostUnpublishController' => 'PhamePostController',
'PhamePostView' => 'AphrontView', 'PhamePostView' => 'AphrontView',
'PhamePostViewController' => 'PhameController', 'PhamePostViewController' => 'PhamePostController',
'PhameQueryConduitAPIMethod' => 'PhameConduitAPIMethod', 'PhameQueryConduitAPIMethod' => 'PhameConduitAPIMethod',
'PhameQueryPostsConduitAPIMethod' => 'PhameConduitAPIMethod', 'PhameQueryPostsConduitAPIMethod' => 'PhameConduitAPIMethod',
'PhameResourceController' => 'CelerityResourceController', 'PhameResourceController' => 'CelerityResourceController',

View file

@ -2,27 +2,6 @@
abstract class PhameController extends PhabricatorController { abstract class PhameController extends PhabricatorController {
protected function renderSideNavFilterView() {
$base_uri = new PhutilURI($this->getApplicationURI());
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI($base_uri);
$nav->addLabel(pht('Posts'));
$nav->addFilter('post/all', pht('Latest Posts'));
$nav->addFilter('post/draft', pht('My Drafts'));
$nav->addFilter('post', pht('My Posts'));
$nav->addLabel(pht('Blogs'));
$nav->addFilter('blog/user', pht('Joinable Blogs'));
$nav->addFilter('blog/all', pht('All Blogs'));
$nav->selectFilter(null);
return $nav;
}
protected function renderPostList( protected function renderPostList(
array $posts, array $posts,
PhabricatorUser $viewer, PhabricatorUser $viewer,
@ -111,10 +90,6 @@ abstract class PhameController extends PhabricatorController {
return $stories; return $stories;
} }
public function buildApplicationMenu() {
return $this->renderSideNavFilterView()->getMenu();
}
protected function buildApplicationCrumbs() { protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs(); $crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction( $crumbs->addAction(

View file

@ -0,0 +1,10 @@
<?php
abstract class PhameBlogController extends PhameController {
public function buildApplicationMenu() {
return $this->newApplicationMenu()
->setSearchEngine(new PhameBlogSearchEngine());
}
}

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhameBlogDeleteController extends PhameController { final class PhameBlogDeleteController extends PhameBlogController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -27,7 +27,7 @@ final class PhameBlogDeleteController extends PhameController {
$cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/');
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Delete Blog?')) ->setTitle(pht('Delete Blog?'))
->appendChild( ->appendChild(
pht( pht(

View file

@ -1,15 +1,15 @@
<?php <?php
final class PhameBlogEditController final class PhameBlogEditController
extends PhameController { extends PhameBlogController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
if ($id) { if ($id) {
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -30,7 +30,7 @@ final class PhameBlogEditController
$v_projects = array_reverse($v_projects); $v_projects = array_reverse($v_projects);
} else { } else {
$blog = PhameBlog::initializeNewBlog($user); $blog = PhameBlog::initializeNewBlog($viewer);
$submit_button = pht('Create Blog'); $submit_button = pht('Create Blog');
$page_title = pht('Create Blog'); $page_title = pht('Create Blog');
@ -90,7 +90,7 @@ final class PhameBlogEditController
->setNewValue(array('=' => array_fuse($v_projects))); ->setNewValue(array('=' => array_fuse($v_projects)));
$editor = id(new PhameBlogEditor()) $editor = id(new PhameBlogEditor())
->setActor($user) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true); ->setContinueOnNoEffect(true);
@ -111,7 +111,7 @@ final class PhameBlogEditController
} }
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($user) ->setViewer($viewer)
->setObject($blog) ->setObject($blog)
->execute(); ->execute();
@ -119,7 +119,7 @@ final class PhameBlogEditController
$skins = mpull($skins, 'getName'); $skins = mpull($skins, 'getName');
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel(pht('Name')) ->setLabel(pht('Name'))
@ -129,16 +129,16 @@ final class PhameBlogEditController
->setError($e_name)) ->setError($e_name))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user) ->setUser($viewer)
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setName('description') ->setName('description')
->setValue($description) ->setValue($description)
->setID('blog-description') ->setID('blog-description')
->setUser($user) ->setUser($viewer)
->setDisableMacros(true)) ->setDisableMacros(true))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW) ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($blog) ->setPolicyObject($blog)
->setPolicies($policies) ->setPolicies($policies)
@ -147,7 +147,7 @@ final class PhameBlogEditController
->setName('can_view')) ->setName('can_view'))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($blog) ->setPolicyObject($blog)
->setPolicies($policies) ->setPolicies($policies)
@ -155,7 +155,7 @@ final class PhameBlogEditController
->setName('can_edit')) ->setName('can_edit'))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($viewer)
->setCapability(PhabricatorPolicyCapability::CAN_JOIN) ->setCapability(PhabricatorPolicyCapability::CAN_JOIN)
->setPolicyObject($blog) ->setPolicyObject($blog)
->setPolicies($policies) ->setPolicies($policies)
@ -195,13 +195,12 @@ final class PhameBlogEditController
$crumbs->addTextCrumb(pht('Blogs'), $this->getApplicationURI('blog/')); $crumbs->addTextCrumb(pht('Blogs'), $this->getApplicationURI('blog/'));
$crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new')); $crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new'));
return $this->buildApplicationPage( return $this->newPage()
->setTitle($page_title)
->setCrumbs($crumbs)
->appendChild(
array( array(
$crumbs,
$form_box, $form_box,
),
array(
'title' => $page_title,
)); ));
} }
} }

View file

@ -1,17 +1,17 @@
<?php <?php
final class PhameBlogFeedController extends PhameController { final class PhameBlogFeedController extends PhameBlogController {
public function shouldRequireLogin() { public function shouldRequireLogin() {
return false; return false;
} }
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$blog) { if (!$blog) {
@ -19,7 +19,7 @@ final class PhameBlogFeedController extends PhameController {
} }
$posts = id(new PhamePostQuery()) $posts = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withBlogPHIDs(array($blog->getPHID())) ->withBlogPHIDs(array($blog->getPHID()))
->withVisibility(PhamePost::VISIBILITY_PUBLISHED) ->withVisibility(PhamePost::VISIBILITY_PUBLISHED)
->execute(); ->execute();
@ -47,7 +47,7 @@ final class PhameBlogFeedController extends PhameController {
$content[] = phutil_tag('subtitle', array(), $description); $content[] = phutil_tag('subtitle', array(), $description);
} }
$engine = id(new PhabricatorMarkupEngine())->setViewer($user); $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer);
foreach ($posts as $post) { foreach ($posts as $post) {
$engine->addObject($post, PhamePost::MARKUP_FIELD_BODY); $engine->addObject($post, PhamePost::MARKUP_FIELD_BODY);
} }
@ -55,7 +55,7 @@ final class PhameBlogFeedController extends PhameController {
$blogger_phids = mpull($posts, 'getBloggerPHID'); $blogger_phids = mpull($posts, 'getBloggerPHID');
$bloggers = id(new PhabricatorHandleQuery()) $bloggers = id(new PhabricatorHandleQuery())
->setViewer($user) ->setViewer($viewer)
->withPHIDs($blogger_phids) ->withPHIDs($blogger_phids)
->execute(); ->execute();

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhameBlogListController extends PhameController { final class PhameBlogListController extends PhameBlogController {
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhameBlogLiveController extends PhameController { final class PhameBlogLiveController extends PhameBlogController {
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$site = $request->getSite(); $site = $request->getSite();
if ($site instanceof PhameBlogSite) { if ($site instanceof PhameBlogSite) {
@ -16,7 +16,7 @@ final class PhameBlogLiveController extends PhameController {
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$blog) { if (!$blog) {
@ -38,7 +38,7 @@ final class PhameBlogLiveController extends PhameController {
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setTitle(pht('Blog Moved')) ->setTitle(pht('Blog Moved'))
->setUser($user) ->setUser($viewer)
->appendParagraph(pht('This blog is now hosted here:')) ->appendParagraph(pht('This blog is now hosted here:'))
->appendParagraph( ->appendParagraph(
phutil_tag( phutil_tag(

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhameBlogViewController extends PhameController { final class PhameBlogViewController extends PhameBlogController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$blog) { if (!$blog) {
@ -18,20 +18,20 @@ final class PhameBlogViewController extends PhameController {
->readFromRequest($request); ->readFromRequest($request);
$posts = id(new PhamePostQuery()) $posts = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withBlogPHIDs(array($blog->getPHID())) ->withBlogPHIDs(array($blog->getPHID()))
->executeWithCursorPager($pager); ->executeWithCursorPager($pager);
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader($blog->getName()) ->setHeader($blog->getName())
->setUser($user) ->setUser($viewer)
->setPolicyObject($blog); ->setPolicyObject($blog);
$actions = $this->renderActions($blog, $user); $actions = $this->renderActions($blog, $viewer);
$properties = $this->renderProperties($blog, $user, $actions); $properties = $this->renderProperties($blog, $viewer, $actions);
$post_list = $this->renderPostList( $post_list = $this->renderPostList(
$posts, $posts,
$user, $viewer,
pht('This blog has no visible posts.')); pht('This blog has no visible posts.'));
$post_list = id(new PHUIObjectBoxView()) $post_list = id(new PHUIObjectBoxView())
@ -46,27 +46,26 @@ final class PhameBlogViewController extends PhameController {
->setHeader($header) ->setHeader($header)
->addPropertyList($properties); ->addPropertyList($properties);
return $this->buildApplicationPage( return $this->newPage()
->setTitle($blog->getName())
->setCrumbs($crumbs)
->appendChild(
array( array(
$crumbs,
$object_box, $object_box,
$post_list, $post_list,
),
array(
'title' => $blog->getName(),
)); ));
} }
private function renderProperties( private function renderProperties(
PhameBlog $blog, PhameBlog $blog,
PhabricatorUser $user, PhabricatorUser $viewer,
PhabricatorActionListView $actions) { PhabricatorActionListView $actions) {
require_celerity_resource('aphront-tooltip-css'); require_celerity_resource('aphront-tooltip-css');
Javelin::initBehavior('phabricator-tooltips'); Javelin::initBehavior('phabricator-tooltips');
$properties = id(new PHUIPropertyListView()) $properties = id(new PHUIPropertyListView())
->setUser($user) ->setUser($viewer)
->setObject($blog) ->setObject($blog)
->setActionList($actions); ->setActionList($actions);
@ -94,7 +93,7 @@ final class PhameBlogViewController extends PhameController {
$feed_uri)); $feed_uri));
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$user, $viewer,
$blog); $blog);
$properties->addProperty( $properties->addProperty(
@ -106,7 +105,7 @@ final class PhameBlogViewController extends PhameController {
$descriptions[PhabricatorPolicyCapability::CAN_JOIN]); $descriptions[PhabricatorPolicyCapability::CAN_JOIN]);
$engine = id(new PhabricatorMarkupEngine()) $engine = id(new PhabricatorMarkupEngine())
->setViewer($user) ->setViewer($viewer)
->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION) ->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)
->process(); ->process();
@ -116,7 +115,7 @@ final class PhameBlogViewController extends PhameController {
$description = PhabricatorMarkupEngine::renderOneObject( $description = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($blog->getDescription()), id(new PhabricatorMarkupOneOff())->setContent($blog->getDescription()),
'default', 'default',
$user); $viewer);
$properties->addSectionHeader( $properties->addSectionHeader(
pht('Description'), pht('Description'),
PHUIPropertyListView::ICON_SUMMARY); PHUIPropertyListView::ICON_SUMMARY);
@ -126,19 +125,19 @@ final class PhameBlogViewController extends PhameController {
return $properties; return $properties;
} }
private function renderActions(PhameBlog $blog, PhabricatorUser $user) { private function renderActions(PhameBlog $blog, PhabricatorUser $viewer) {
$actions = id(new PhabricatorActionListView()) $actions = id(new PhabricatorActionListView())
->setObject($blog) ->setObject($blog)
->setObjectURI($this->getRequest()->getRequestURI()) ->setObjectURI($this->getRequest()->getRequestURI())
->setUser($user); ->setUser($viewer);
$can_edit = PhabricatorPolicyFilter::hasCapability( $can_edit = PhabricatorPolicyFilter::hasCapability(
$user, $viewer,
$blog, $blog,
PhabricatorPolicyCapability::CAN_EDIT); PhabricatorPolicyCapability::CAN_EDIT);
$can_join = PhabricatorPolicyFilter::hasCapability( $can_join = PhabricatorPolicyFilter::hasCapability(
$user, $viewer,
$blog, $blog,
PhabricatorPolicyCapability::CAN_JOIN); PhabricatorPolicyCapability::CAN_JOIN);
@ -152,7 +151,7 @@ final class PhameBlogViewController extends PhameController {
$actions->addAction( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setUser($user) ->setUser($viewer)
->setIcon('fa-globe') ->setIcon('fa-globe')
->setHref($blog->getLiveURI()) ->setHref($blog->getLiveURI())
->setName(pht('View Live'))); ->setName(pht('View Live')));

View file

@ -0,0 +1,10 @@
<?php
abstract class PhamePostController extends PhameController {
public function buildApplicationMenu() {
return $this->newApplicationMenu()
->setSearchEngine(new PhamePostSearchEngine());
}
}

View file

@ -1,12 +1,12 @@
<?php <?php
final class PhamePostDeleteController extends PhameController { final class PhamePostDeleteController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($request->getURIData('id'))) ->withIDs(array($request->getURIData('id')))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -26,7 +26,7 @@ final class PhamePostDeleteController extends PhameController {
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); $cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Delete Post?')) ->setTitle(pht('Delete Post?'))
->appendChild( ->appendChild(
pht( pht(

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhamePostEditController extends PhameController { final class PhamePostEditController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $viewer = $request->getViewer();

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhamePostFramedController extends PhameController { final class PhamePostFramedController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getViewer(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhamePostListController extends PhameController { final class PhamePostListController extends PhamePostController {
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;

View file

@ -1,16 +1,16 @@
<?php <?php
final class PhamePostNewController extends PhameController { final class PhamePostNewController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$post = null; $post = null;
$view_uri = null; $view_uri = null;
if ($id) { if ($id) {
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -26,7 +26,7 @@ final class PhamePostNewController extends PhameController {
if ($request->isFormPost()) { if ($request->isFormPost()) {
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($request->getInt('blog'))) ->withIDs(array($request->getInt('blog')))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -49,7 +49,7 @@ final class PhamePostNewController extends PhameController {
} }
$blogs = id(new PhameBlogQuery()) $blogs = id(new PhameBlogQuery())
->setViewer($user) ->setViewer($viewer)
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_JOIN, PhabricatorPolicyCapability::CAN_JOIN,
@ -58,9 +58,9 @@ final class PhamePostNewController extends PhameController {
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $view_uri); $crumbs->addTextCrumb($title, $view_uri);
$display = array();
$display[] = $crumbs;
$notification = null;
$form_box = null;
if (!$blogs) { if (!$blogs) {
$notification = id(new PHUIInfoView()) $notification = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NODATA) ->setSeverity(PHUIInfoView::SEVERITY_NODATA)
@ -68,7 +68,6 @@ final class PhamePostNewController extends PhameController {
pht('You do not have permission to join any blogs. Create a blog '. pht('You do not have permission to join any blogs. Create a blog '.
'first, then you can post to it.')); 'first, then you can post to it.'));
$display[] = $notification;
} else { } else {
$options = mpull($blogs, 'getName', 'getID'); $options = mpull($blogs, 'getName', 'getID');
asort($options); asort($options);
@ -79,7 +78,7 @@ final class PhamePostNewController extends PhameController {
} }
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel(pht('Blog')) ->setLabel(pht('Blog'))
@ -102,19 +101,20 @@ final class PhamePostNewController extends PhameController {
->setValue(pht('Continue'))); ->setValue(pht('Continue')));
} }
$form_box = id(new PHUIObjectBoxView()) $form_box = id(new PHUIObjectBoxView())
->setHeaderText($title) ->setHeaderText($title)
->setForm($form); ->setForm($form);
$display[] = $form_box;
} }
return $this->buildApplicationPage( return $this->newPage()
$display, ->setTitle($title)
->setCrumbs($crumbs)
->appendChild(
array( array(
'title' => $title, $notification,
$form_box,
)); ));
} }
} }

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhamePostNotLiveController extends PhameController { final class PhamePostNotLiveController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$post) { if (!$post) {
@ -32,7 +32,7 @@ final class PhamePostNotLiveController extends PhameController {
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); $cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Post Not Live')) ->setTitle(pht('Post Not Live'))
->addCancelButton($cancel_uri); ->addCancelButton($cancel_uri);

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhamePostPreviewController extends PhameController { final class PhamePostPreviewController extends PhamePostController {
protected function getSideNavFilter() { protected function getSideNavFilter() {
return null; return null;

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhamePostPublishController extends PhameController { final class PhamePostPublishController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -29,7 +29,7 @@ final class PhamePostPublishController extends PhameController {
} }
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue(pht('Publish Post')) ->setValue(pht('Publish Post'))
@ -44,35 +44,30 @@ final class PhamePostPublishController extends PhameController {
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Preview'), $view_uri); $crumbs->addTextCrumb(pht('Preview'), $view_uri);
$nav = $this->renderSideNavFilterView(null); return $this->newPage()
$nav->appendChild( ->setTitle(pht('Preview Post'))
->setCrumbs($crumbs)
->appendChild(
array( array(
$crumbs,
$form_box, $form_box,
$frame, $frame,
)); ));
return $this->buildApplicationPage(
$nav,
array(
'title' => pht('Preview Post'),
));
} }
private function renderPreviewFrame(PhamePost $post) { private function renderPreviewFrame(PhamePost $post) {
// TODO: Clean up this CSS.
return phutil_tag( return phutil_tag(
'div', 'div',
array( array(
'style' => 'text-align: center; padding: 1em;', 'style' => 'text-align: center; padding: 16px;',
), ),
phutil_tag( phutil_tag(
'iframe', 'iframe',
array( array(
'style' => 'width: 100%; height: 600px; '. 'style' => 'width: 100%; height: 600px; '.
'border: 1px solid #303030;', 'border: 1px solid #BFCFDA; '.
'background-color: #fff; '.
'border-radius: 3px; ',
'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'), 'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'),
), ),
'')); ''));

View file

@ -1,13 +1,13 @@
<?php <?php
final class PhamePostUnpublishController extends PhameController { final class PhamePostUnpublishController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$user = $request->getUser(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
@ -30,7 +30,7 @@ final class PhamePostUnpublishController extends PhameController {
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); $cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
$dialog = id(new AphrontDialogView()) $dialog = id(new AphrontDialogView())
->setUser($user) ->setUser($viewer)
->setTitle(pht('Unpublish Post?')) ->setTitle(pht('Unpublish Post?'))
->appendChild( ->appendChild(
pht( pht(

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhamePostViewController extends PhameController { final class PhamePostViewController extends PhamePostController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $viewer = $request->getViewer();

View file

@ -30,7 +30,7 @@ final class PhameBlogSearchEngine
protected function getBuiltinQueryNames() { protected function getBuiltinQueryNames() {
$names = array( $names = array(
'all' => pht('All'), 'all' => pht('All Blogs'),
); );
return $names; return $names;
} }

View file

@ -44,9 +44,9 @@ final class PhamePostSearchEngine
protected function getBuiltinQueryNames() { protected function getBuiltinQueryNames() {
$names = array( $names = array(
'all' => pht('All'), 'all' => pht('All Posts'),
'live' => pht('Live'), 'live' => pht('Live Posts'),
'draft' => pht('Draft'), 'draft' => pht('Draft Posts'),
); );
return $names; return $names;
} }