Page MenuHomePhabricator

D14429.diff
No OneTemporary

D14429.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3262,6 +3262,7 @@
'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php',
'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php',
'PhameConduitAPIMethod' => 'applications/phame/conduit/PhameConduitAPIMethod.php',
+ 'PhameConstants' => 'applications/phame/constants/PhameConstants.php',
'PhameController' => 'applications/phame/controller/PhameController.php',
'PhameCreatePostConduitAPIMethod' => 'applications/phame/conduit/PhameCreatePostConduitAPIMethod.php',
'PhameDAO' => 'applications/phame/storage/PhameDAO.php',
@@ -7525,6 +7526,7 @@
'PhameBlogViewController' => 'PhameBlogController',
'PhameCelerityResources' => 'CelerityResources',
'PhameConduitAPIMethod' => 'ConduitAPIMethod',
+ 'PhameConstants' => 'Phobject',
'PhameController' => 'PhabricatorController',
'PhameCreatePostConduitAPIMethod' => 'PhameConduitAPIMethod',
'PhameDAO' => 'PhabricatorLiskDAO',
diff --git a/src/applications/phame/conduit/PhameCreatePostConduitAPIMethod.php b/src/applications/phame/conduit/PhameCreatePostConduitAPIMethod.php
--- a/src/applications/phame/conduit/PhameCreatePostConduitAPIMethod.php
+++ b/src/applications/phame/conduit/PhameCreatePostConduitAPIMethod.php
@@ -85,7 +85,7 @@
$is_draft = $request->getValue('isDraft', false);
if (!$is_draft) {
$post->setDatePublished(time());
- $post->setVisibility(PhamePost::VISIBILITY_PUBLISHED);
+ $post->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
}
$post->setTitle($title);
$phame_title = $request->getValue(
diff --git a/src/applications/phame/conduit/PhameQueryPostsConduitAPIMethod.php b/src/applications/phame/conduit/PhameQueryPostsConduitAPIMethod.php
--- a/src/applications/phame/conduit/PhameQueryPostsConduitAPIMethod.php
+++ b/src/applications/phame/conduit/PhameQueryPostsConduitAPIMethod.php
@@ -65,9 +65,9 @@
$published = $request->getValue('published', null);
if ($published === true) {
- $query->withVisibility(PhamePost::VISIBILITY_PUBLISHED);
+ $query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED);
} else if ($published === false) {
- $query->withVisibility(PhamePost::VISIBILITY_DRAFT);
+ $query->withVisibility(PhameConstants::VISIBILITY_DRAFT);
}
$published_after = $request->getValue('publishedAfter', null);
diff --git a/src/applications/phame/constants/PhameConstants.php b/src/applications/phame/constants/PhameConstants.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/constants/PhameConstants.php
@@ -0,0 +1,23 @@
+<?php
+
+final class PhameConstants extends Phobject {
+
+ const VISIBILITY_DRAFT = 0;
+ const VISIBILITY_PUBLISHED = 1;
+
+ public static function getPhamePostStatusMap() {
+ return array(
+ self::VISIBILITY_PUBLISHED => pht('Published'),
+ self::VISIBILITY_DRAFT => pht('Draft'),
+ );
+ }
+
+ public static function getPhamePostStatusName($status) {
+ $map = array(
+ self::VISIBILITY_PUBLISHED => pht('Published'),
+ self::VISIBILITY_DRAFT => pht('Draft'),
+ );
+ return idx($map, $status, pht('Unknown'));
+ }
+
+}
diff --git a/src/applications/phame/controller/blog/PhameBlogFeedController.php b/src/applications/phame/controller/blog/PhameBlogFeedController.php
--- a/src/applications/phame/controller/blog/PhameBlogFeedController.php
+++ b/src/applications/phame/controller/blog/PhameBlogFeedController.php
@@ -21,7 +21,7 @@
$posts = id(new PhamePostQuery())
->setViewer($viewer)
->withBlogPHIDs(array($blog->getPHID()))
- ->withVisibility(PhamePost::VISIBILITY_PUBLISHED)
+ ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->execute();
$blog_uri = PhabricatorEnv::getProductionURI(
diff --git a/src/applications/phame/controller/post/PhamePostEditController.php b/src/applications/phame/controller/post/PhamePostEditController.php
--- a/src/applications/phame/controller/post/PhamePostEditController.php
+++ b/src/applications/phame/controller/post/PhamePostEditController.php
@@ -45,25 +45,27 @@
$post = PhamePost::initializePost($viewer, $blog);
$cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/');
- $submit_button = pht('Save Draft');
- $page_title = pht('Create Post');
+ $submit_button = pht('Create Post');
+ $page_title = pht('Create Post');
}
- $title = $post->getTitle();
- $phame_title = $post->getPhameTitle();
- $body = $post->getBody();
+ $title = $post->getTitle();
+ $phame_title = $post->getPhameTitle();
+ $body = $post->getBody();
$comments_widget = $post->getCommentsWidget();
+ $visibility = $post->getVisibility();
$e_title = true;
$e_phame_title = true;
$validation_exception = null;
if ($request->isFormPost()) {
- $title = $request->getStr('title');
- $phame_title = $request->getStr('phame_title');
- $phame_title = PhabricatorSlug::normalize($phame_title);
- $body = $request->getStr('body');
+ $title = $request->getStr('title');
+ $phame_title = $request->getStr('phame_title');
+ $phame_title = PhabricatorSlug::normalize($phame_title);
+ $body = $request->getStr('body');
$comments_widget = $request->getStr('comments_widget');
- $v_projects = $request->getArr('projects');
+ $v_projects = $request->getArr('projects');
+ $visibility = $request->getInt('visibility');
$xactions = array(
id(new PhamePostTransaction())
@@ -76,6 +78,9 @@
->setTransactionType(PhamePostTransaction::TYPE_BODY)
->setNewValue($body),
id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setNewValue($visibility),
+ id(new PhamePostTransaction())
->setTransactionType(PhamePostTransaction::TYPE_COMMENTS_WIDGET)
->setNewValue($comments_widget),
);
@@ -135,6 +140,12 @@
'Formatting is enforced.'))
->setError($e_phame_title))
->appendChild(
+ id(new AphrontFormSelectControl())
+ ->setLabel(pht('Visibility'))
+ ->setName('visibility')
+ ->setvalue($visibility)
+ ->setOptions(PhameConstants::getPhamePostStatusMap()))
+ ->appendChild(
id(new PhabricatorRemarkupControl())
->setLabel(pht('Body'))
->setName('body')
diff --git a/src/applications/phame/controller/post/PhamePostPublishController.php b/src/applications/phame/controller/post/PhamePostPublishController.php
--- a/src/applications/phame/controller/post/PhamePostPublishController.php
+++ b/src/applications/phame/controller/post/PhamePostPublishController.php
@@ -21,9 +21,23 @@
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
if ($request->isFormPost()) {
- $post->setVisibility(PhamePost::VISIBILITY_PUBLISHED);
- $post->setDatePublished(time());
- $post->save();
+ $xactions = array();
+ $xactions[] = id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_TITLE)
+ ->setNewValue($post->getTitle());
+ $xactions[] = id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE)
+ ->setNewValue($post->getPhameTitle());
+ $xactions[] = id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setNewValue(PhameConstants::VISIBILITY_PUBLISHED);
+
+ id(new PhamePostEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->applyTransactions($post, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
diff --git a/src/applications/phame/controller/post/PhamePostUnpublishController.php b/src/applications/phame/controller/post/PhamePostUnpublishController.php
--- a/src/applications/phame/controller/post/PhamePostUnpublishController.php
+++ b/src/applications/phame/controller/post/PhamePostUnpublishController.php
@@ -19,9 +19,23 @@
}
if ($request->isFormPost()) {
- $post->setVisibility(PhamePost::VISIBILITY_DRAFT);
- $post->setDatePublished(0);
- $post->save();
+ $xactions = array();
+ $xactions[] = id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_TITLE)
+ ->setNewValue($post->getTitle());
+ $xactions[] = id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_PHAME_TITLE)
+ ->setNewValue($post->getPhameTitle());
+ $xactions[] = id(new PhamePostTransaction())
+ ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setNewValue(PhameConstants::VISIBILITY_DRAFT);
+
+ id(new PhamePostEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->applyTransactions($post, $xactions);
return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/'));
diff --git a/src/applications/phame/editor/PhamePostEditor.php b/src/applications/phame/editor/PhamePostEditor.php
--- a/src/applications/phame/editor/PhamePostEditor.php
+++ b/src/applications/phame/editor/PhamePostEditor.php
@@ -17,6 +17,7 @@
$types[] = PhamePostTransaction::TYPE_TITLE;
$types[] = PhamePostTransaction::TYPE_PHAME_TITLE;
$types[] = PhamePostTransaction::TYPE_BODY;
+ $types[] = PhamePostTransaction::TYPE_VISIBILITY;
$types[] = PhamePostTransaction::TYPE_COMMENTS_WIDGET;
return $types;
@@ -33,6 +34,8 @@
return $object->getPhameTitle();
case PhamePostTransaction::TYPE_BODY:
return $object->getBody();
+ case PhamePostTransaction::TYPE_VISIBILITY:
+ return $object->getVisibility();
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return $object->getCommentsWidget();
}
@@ -46,6 +49,7 @@
case PhamePostTransaction::TYPE_TITLE:
case PhamePostTransaction::TYPE_PHAME_TITLE:
case PhamePostTransaction::TYPE_BODY:
+ case PhamePostTransaction::TYPE_VISIBILITY:
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return $xaction->getNewValue();
}
@@ -62,6 +66,13 @@
return $object->setPhameTitle($xaction->getNewValue());
case PhamePostTransaction::TYPE_BODY:
return $object->setBody($xaction->getNewValue());
+ case PhamePostTransaction::TYPE_VISIBILITY:
+ if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
+ $object->setDatePublished(time());
+ } else {
+ $object->setDatePublished(0);
+ }
+ return $object->setVisibility($xaction->getNewValue());
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return $object->setCommentsWidget($xaction->getNewValue());
}
@@ -77,6 +88,7 @@
case PhamePostTransaction::TYPE_TITLE:
case PhamePostTransaction::TYPE_PHAME_TITLE:
case PhamePostTransaction::TYPE_BODY:
+ case PhamePostTransaction::TYPE_VISIBILITY:
case PhamePostTransaction::TYPE_COMMENTS_WIDGET:
return;
}
diff --git a/src/applications/phame/query/PhamePostSearchEngine.php b/src/applications/phame/query/PhamePostSearchEngine.php
--- a/src/applications/phame/query/PhamePostSearchEngine.php
+++ b/src/applications/phame/query/PhamePostSearchEngine.php
@@ -32,8 +32,8 @@
->setLabel(pht('Visibility'))
->setOptions(array(
'' => pht('All'),
- PhamePost::VISIBILITY_PUBLISHED => pht('Live'),
- PhamePost::VISIBILITY_DRAFT => pht('Draft'),
+ PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
+ PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
)),
);
}
@@ -45,7 +45,7 @@
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Posts'),
- 'live' => pht('Live Posts'),
+ 'live' => pht('Published Posts'),
'draft' => pht('Draft Posts'),
);
return $names;
@@ -60,10 +60,10 @@
return $query;
case 'live':
return $query->setParameter(
- 'visibility', PhamePost::VISIBILITY_PUBLISHED);
+ 'visibility', PhameConstants::VISIBILITY_PUBLISHED);
case 'draft':
return $query->setParameter(
- 'visibility', PhamePost::VISIBILITY_DRAFT);
+ 'visibility', PhameConstants::VISIBILITY_DRAFT);
}
return parent::buildSavedQueryFromBuiltin($query_key);
diff --git a/src/applications/phame/storage/PhamePost.php b/src/applications/phame/storage/PhamePost.php
--- a/src/applications/phame/storage/PhamePost.php
+++ b/src/applications/phame/storage/PhamePost.php
@@ -13,9 +13,6 @@
const MARKUP_FIELD_BODY = 'markup:body';
const MARKUP_FIELD_SUMMARY = 'markup:summary';
- const VISIBILITY_DRAFT = 0;
- const VISIBILITY_PUBLISHED = 1;
-
protected $bloggerPHID;
protected $title;
protected $phameTitle;
@@ -37,7 +34,7 @@
->setBlogPHID($blog->getPHID())
->setBlog($blog)
->setDatePublished(0)
- ->setVisibility(self::VISIBILITY_DRAFT);
+ ->setVisibility(PhameConstants::VISIBILITY_PUBLISHED);
return $post;
}
@@ -66,7 +63,7 @@
}
public function isDraft() {
- return $this->getVisibility() == self::VISIBILITY_DRAFT;
+ return $this->getVisibility() == PhameConstants::VISIBILITY_DRAFT;
}
public function getHumanName() {
@@ -165,14 +162,6 @@
);
}
- public static function getVisibilityOptionsForSelect() {
- return array(
- self::VISIBILITY_DRAFT => pht('Draft: visible only to me.'),
- self::VISIBILITY_PUBLISHED => pht(
- 'Published: visible to the whole world.'),
- );
- }
-
public function getCommentsWidgetOptionsForSelect() {
$current = $this->getCommentsWidget();
$options = array();
diff --git a/src/applications/phame/storage/PhamePostTransaction.php b/src/applications/phame/storage/PhamePostTransaction.php
--- a/src/applications/phame/storage/PhamePostTransaction.php
+++ b/src/applications/phame/storage/PhamePostTransaction.php
@@ -6,6 +6,7 @@
const TYPE_TITLE = 'phame.post.title';
const TYPE_PHAME_TITLE = 'phame.post.phame.title';
const TYPE_BODY = 'phame.post.body';
+ const TYPE_VISIBILITY = 'phame.post.visibility';
const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget';
const MAILTAG_CONTENT = 'phame-post-content';
@@ -54,6 +55,7 @@
break;
case self::TYPE_PHAME_TITLE:
case self::TYPE_BODY:
+ case self::TYPE_VISIBILITY:
case self::TYPE_COMMENTS_WIDGET:
return 'fa-pencil';
break;
@@ -108,6 +110,17 @@
'%s updated the blog post.',
$this->renderHandleLink($author_phid));
break;
+ case self::TYPE_VISIBILITY:
+ if ($new == PhameConstants::VISIBILITY_DRAFT) {
+ return pht(
+ '%s marked this post as a draft.',
+ $this->renderHandleLink($author_phid));
+ } else {
+ return pht(
+ '%s published this post.',
+ $this->renderHandleLink($author_phid));
+ }
+ break;
case self::TYPE_PHAME_TITLE:
return pht(
'%s updated the post\'s Phame title to "%s".',
@@ -153,6 +166,19 @@
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
+ case self::TYPE_VISIBILITY:
+ if ($new == PhameConstants::VISIBILITY_DRAFT) {
+ return pht(
+ '%s marked %s as a draft.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ } else {
+ return pht(
+ '%s published %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ break;
case self::TYPE_PHAME_TITLE:
return pht(
'%s updated the Phame title for %s.',
@@ -171,19 +197,32 @@
}
public function getBodyForFeed(PhabricatorFeedStory $story) {
- $new = $this->getNewValue();
-
- $body = null;
-
+ $text = null;
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
+ if ($this->getOldValue() === null) {
+ $post = $story->getPrimaryObject();
+ $text = $post->getBody();
+ }
+ break;
+ case self::TYPE_VISIBILITY:
+ if ($this->getNewValue() == PhameConstants::VISIBILITY_PUBLISHED) {
+ $post = $story->getPrimaryObject();
+ $text = $post->getBody();
+ }
+ break;
case self::TYPE_BODY:
- return phutil_escape_html_newlines(
- id(new PhutilUTF8StringTruncator())
- ->setMaximumGlyphs(128)
- ->truncateString($new));
+ $text = $this->getNewValue();
break;
}
+
+ if (strlen($text)) {
+ return phutil_escape_html_newlines(
+ id(new PhutilUTF8StringTruncator())
+ ->setMaximumGlyphs(128)
+ ->truncateString($text));
+ }
+
return parent::getBodyForFeed($story);
}
@@ -201,7 +240,6 @@
return parent::getColor();
}
-
public function hasChangeDetails() {
switch ($this->getTransactionType()) {
case self::TYPE_BODY:

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 11, 2:35 PM (2 d, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7228101
Default Alt Text
D14429.diff (17 KB)

Event Timeline