diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7716a29ce7..70c5ea2cf1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4272,12 +4272,15 @@ phutil_register_library_map(array( 'PhameNextPostView' => 'applications/phame/view/PhameNextPostView.php', 'PhamePost' => 'applications/phame/storage/PhamePost.php', 'PhamePostArchiveController' => 'applications/phame/controller/post/PhamePostArchiveController.php', + 'PhamePostBlogTransaction' => 'applications/phame/xaction/PhamePostBlogTransaction.php', + 'PhamePostBodyTransaction' => 'applications/phame/xaction/PhamePostBodyTransaction.php', 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', 'PhamePostEditConduitAPIMethod' => 'applications/phame/conduit/PhamePostEditConduitAPIMethod.php', 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', 'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php', 'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php', 'PhamePostFulltextEngine' => 'applications/phame/search/PhamePostFulltextEngine.php', + 'PhamePostHeaderImageTransaction' => 'applications/phame/xaction/PhamePostHeaderImageTransaction.php', 'PhamePostHeaderPictureController' => 'applications/phame/controller/post/PhamePostHeaderPictureController.php', 'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php', 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', @@ -4290,10 +4293,14 @@ phutil_register_library_map(array( 'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php', 'PhamePostSearchConduitAPIMethod' => 'applications/phame/conduit/PhamePostSearchConduitAPIMethod.php', 'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php', + 'PhamePostSubtitleTransaction' => 'applications/phame/xaction/PhamePostSubtitleTransaction.php', + 'PhamePostTitleTransaction' => 'applications/phame/xaction/PhamePostTitleTransaction.php', 'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php', 'PhamePostTransactionComment' => 'applications/phame/storage/PhamePostTransactionComment.php', 'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php', + 'PhamePostTransactionType' => 'applications/phame/xaction/PhamePostTransactionType.php', 'PhamePostViewController' => 'applications/phame/controller/post/PhamePostViewController.php', + 'PhamePostVisibilityTransaction' => 'applications/phame/xaction/PhamePostVisibilityTransaction.php', 'PhameSchemaSpec' => 'applications/phame/storage/PhameSchemaSpec.php', 'PhameSite' => 'applications/phame/site/PhameSite.php', 'PhluxController' => 'applications/phlux/controller/PhluxController.php', @@ -9753,12 +9760,15 @@ phutil_register_library_map(array( 'PhabricatorFulltextInterface', ), 'PhamePostArchiveController' => 'PhamePostController', + 'PhamePostBlogTransaction' => 'PhamePostTransactionType', + 'PhamePostBodyTransaction' => 'PhamePostTransactionType', 'PhamePostController' => 'PhameController', 'PhamePostEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhamePostEditController' => 'PhamePostController', 'PhamePostEditEngine' => 'PhabricatorEditEngine', 'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor', 'PhamePostFulltextEngine' => 'PhabricatorFulltextEngine', + 'PhamePostHeaderImageTransaction' => 'PhamePostTransactionType', 'PhamePostHeaderPictureController' => 'PhamePostController', 'PhamePostHistoryController' => 'PhamePostController', 'PhamePostListController' => 'PhamePostController', @@ -9771,10 +9781,14 @@ phutil_register_library_map(array( 'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhamePostSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine', - 'PhamePostTransaction' => 'PhabricatorApplicationTransaction', + 'PhamePostSubtitleTransaction' => 'PhamePostTransactionType', + 'PhamePostTitleTransaction' => 'PhamePostTransactionType', + 'PhamePostTransaction' => 'PhabricatorModularTransaction', 'PhamePostTransactionComment' => 'PhabricatorApplicationTransactionComment', 'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery', + 'PhamePostTransactionType' => 'PhabricatorModularTransactionType', 'PhamePostViewController' => 'PhameLiveController', + 'PhamePostVisibilityTransaction' => 'PhamePostTransactionType', 'PhameSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhameSite' => 'PhabricatorSite', 'PhluxController' => 'PhabricatorController', diff --git a/src/applications/phame/controller/post/PhamePostArchiveController.php b/src/applications/phame/controller/post/PhamePostArchiveController.php index 5a3b32944a..b8647121ef 100644 --- a/src/applications/phame/controller/post/PhamePostArchiveController.php +++ b/src/applications/phame/controller/post/PhamePostArchiveController.php @@ -26,7 +26,7 @@ final class PhamePostArchiveController extends PhamePostController { $new_value = PhameConstants::VISIBILITY_ARCHIVED; $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) + ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE) ->setNewValue($new_value); id(new PhamePostEditor()) diff --git a/src/applications/phame/controller/post/PhamePostHeaderPictureController.php b/src/applications/phame/controller/post/PhamePostHeaderPictureController.php index 2e60c9ba71..60075cc077 100644 --- a/src/applications/phame/controller/post/PhamePostHeaderPictureController.php +++ b/src/applications/phame/controller/post/PhamePostHeaderPictureController.php @@ -61,7 +61,7 @@ final class PhamePostHeaderPictureController $xactions = array(); $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_HEADERIMAGE) + ->setTransactionType(PhamePostHeaderImageTransaction::TRANSACTIONTYPE) ->setNewValue($new_value); $editor = id(new PhamePostEditor()) diff --git a/src/applications/phame/controller/post/PhamePostMoveController.php b/src/applications/phame/controller/post/PhamePostMoveController.php index 3e09a9ba2d..d088b260b5 100644 --- a/src/applications/phame/controller/post/PhamePostMoveController.php +++ b/src/applications/phame/controller/post/PhamePostMoveController.php @@ -28,7 +28,7 @@ final class PhamePostMoveController extends PhamePostController { $xactions = array(); $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_BLOG) + ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE) ->setNewValue($v_blog); $editor = id(new PhamePostEditor()) diff --git a/src/applications/phame/controller/post/PhamePostPublishController.php b/src/applications/phame/controller/post/PhamePostPublishController.php index 567099f0d4..70989082bd 100644 --- a/src/applications/phame/controller/post/PhamePostPublishController.php +++ b/src/applications/phame/controller/post/PhamePostPublishController.php @@ -34,7 +34,7 @@ final class PhamePostPublishController extends PhamePostController { } $xactions[] = id(new PhamePostTransaction()) - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) + ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE) ->setNewValue($new_value); id(new PhamePostEditor()) diff --git a/src/applications/phame/editor/PhamePostEditEngine.php b/src/applications/phame/editor/PhamePostEditEngine.php index e80c1f6d0d..af1b1091d1 100644 --- a/src/applications/phame/editor/PhamePostEditEngine.php +++ b/src/applications/phame/editor/PhamePostEditEngine.php @@ -84,7 +84,7 @@ final class PhamePostEditEngine pht('Choose a blog to create a post on (or move a post to).')) ->setConduitTypeDescription(pht('PHID of the blog.')) ->setAliases(array('blogPHID')) - ->setTransactionType(PhamePostTransaction::TYPE_BLOG) + ->setTransactionType(PhamePostBlogTransaction::TRANSACTIONTYPE) ->setHandleParameterType(new AphrontPHIDListHTTPParameterType()) ->setSingleValue($blog_phid) ->setIsReorderable(false) @@ -97,7 +97,7 @@ final class PhamePostEditEngine ->setDescription(pht('Post title.')) ->setConduitDescription(pht('Retitle the post.')) ->setConduitTypeDescription(pht('New post title.')) - ->setTransactionType(PhamePostTransaction::TYPE_TITLE) + ->setTransactionType(PhamePostTitleTransaction::TRANSACTIONTYPE) ->setValue($object->getTitle()), id(new PhabricatorTextEditField()) ->setKey('subtitle') @@ -105,7 +105,7 @@ final class PhamePostEditEngine ->setDescription(pht('Post subtitle.')) ->setConduitDescription(pht('Change the post subtitle.')) ->setConduitTypeDescription(pht('New post subtitle.')) - ->setTransactionType(PhamePostTransaction::TYPE_SUBTITLE) + ->setTransactionType(PhamePostSubtitleTransaction::TRANSACTIONTYPE) ->setValue($object->getSubtitle()), id(new PhabricatorSelectEditField()) ->setKey('visibility') @@ -113,7 +113,7 @@ final class PhamePostEditEngine ->setDescription(pht('Post visibility.')) ->setConduitDescription(pht('Change post visibility.')) ->setConduitTypeDescription(pht('New post visibility constant.')) - ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY) + ->setTransactionType(PhamePostVisibilityTransaction::TRANSACTIONTYPE) ->setValue($object->getVisibility()) ->setOptions(PhameConstants::getPhamePostStatusMap()), id(new PhabricatorRemarkupEditField()) @@ -122,7 +122,7 @@ final class PhamePostEditEngine ->setDescription(pht('Post body.')) ->setConduitDescription(pht('Change post body.')) ->setConduitTypeDescription(pht('New post body.')) - ->setTransactionType(PhamePostTransaction::TYPE_BODY) + ->setTransactionType(PhamePostBodyTransaction::TRANSACTIONTYPE) ->setValue($object->getBody()) ->setPreviewPanel( id(new PHUIRemarkupPreviewPanel()) diff --git a/src/applications/phame/editor/PhamePostEditor.php b/src/applications/phame/editor/PhamePostEditor.php index 929613fe80..8f0e2b5099 100644 --- a/src/applications/phame/editor/PhamePostEditor.php +++ b/src/applications/phame/editor/PhamePostEditor.php @@ -11,177 +11,21 @@ final class PhamePostEditor return pht('Phame Posts'); } + public function getCreateObjectTitle($author, $object) { + return pht('%s created this post.', $author); + } + + public function getCreateObjectTitleForFeed($author, $object) { + return pht('%s created %s.', $author, $object); + } + public function getTransactionTypes() { $types = parent::getTransactionTypes(); - - $types[] = PhamePostTransaction::TYPE_BLOG; - $types[] = PhamePostTransaction::TYPE_TITLE; - $types[] = PhamePostTransaction::TYPE_SUBTITLE; - $types[] = PhamePostTransaction::TYPE_BODY; - $types[] = PhamePostTransaction::TYPE_VISIBILITY; - $types[] = PhamePostTransaction::TYPE_HEADERIMAGE; $types[] = PhabricatorTransactions::TYPE_COMMENT; return $types; } - protected function getCustomTransactionOldValue( - PhabricatorLiskDAO $object, - PhabricatorApplicationTransaction $xaction) { - - switch ($xaction->getTransactionType()) { - case PhamePostTransaction::TYPE_BLOG: - return $object->getBlogPHID(); - case PhamePostTransaction::TYPE_TITLE: - return $object->getTitle(); - case PhamePostTransaction::TYPE_SUBTITLE: - return $object->getSubtitle(); - case PhamePostTransaction::TYPE_BODY: - return $object->getBody(); - case PhamePostTransaction::TYPE_VISIBILITY: - return $object->getVisibility(); - case PhamePostTransaction::TYPE_HEADERIMAGE: - return $object->getHeaderImagePHID(); - } - } - - protected function getCustomTransactionNewValue( - PhabricatorLiskDAO $object, - PhabricatorApplicationTransaction $xaction) { - - switch ($xaction->getTransactionType()) { - case PhamePostTransaction::TYPE_TITLE: - case PhamePostTransaction::TYPE_SUBTITLE: - case PhamePostTransaction::TYPE_BODY: - case PhamePostTransaction::TYPE_VISIBILITY: - case PhamePostTransaction::TYPE_HEADERIMAGE: - case PhamePostTransaction::TYPE_BLOG: - return $xaction->getNewValue(); - } - } - - protected function applyCustomInternalTransaction( - PhabricatorLiskDAO $object, - PhabricatorApplicationTransaction $xaction) { - - switch ($xaction->getTransactionType()) { - case PhamePostTransaction::TYPE_TITLE: - return $object->setTitle($xaction->getNewValue()); - case PhamePostTransaction::TYPE_SUBTITLE: - return $object->setSubtitle($xaction->getNewValue()); - case PhamePostTransaction::TYPE_BODY: - return $object->setBody($xaction->getNewValue()); - case PhamePostTransaction::TYPE_BLOG: - return $object->setBlogPHID($xaction->getNewValue()); - case PhamePostTransaction::TYPE_HEADERIMAGE: - return $object->setHeaderImagePHID($xaction->getNewValue()); - case PhamePostTransaction::TYPE_VISIBILITY: - if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) { - $object->setDatePublished(0); - } else if ($xaction->getNewValue() == - PhameConstants::VISIBILITY_ARCHIVED) { - $object->setDatePublished(0); - } else { - $object->setDatePublished(PhabricatorTime::getNow()); - } - return $object->setVisibility($xaction->getNewValue()); - } - - return parent::applyCustomInternalTransaction($object, $xaction); - } - - protected function applyCustomExternalTransaction( - PhabricatorLiskDAO $object, - PhabricatorApplicationTransaction $xaction) { - - switch ($xaction->getTransactionType()) { - case PhamePostTransaction::TYPE_TITLE: - case PhamePostTransaction::TYPE_SUBTITLE: - case PhamePostTransaction::TYPE_BODY: - case PhamePostTransaction::TYPE_VISIBILITY: - case PhamePostTransaction::TYPE_HEADERIMAGE: - case PhamePostTransaction::TYPE_BLOG: - return; - } - - return parent::applyCustomExternalTransaction($object, $xaction); - } - - protected function validateTransaction( - PhabricatorLiskDAO $object, - $type, - array $xactions) { - - $errors = parent::validateTransaction($object, $type, $xactions); - - switch ($type) { - case PhamePostTransaction::TYPE_TITLE: - $missing = $this->validateIsEmptyTextField( - $object->getTitle(), - $xactions); - - if ($missing) { - $error = new PhabricatorApplicationTransactionValidationError( - $type, - pht('Required'), - pht('Title is required.'), - nonempty(last($xactions), null)); - - $error->setIsMissingFieldError(true); - $errors[] = $error; - } - break; - case PhamePostTransaction::TYPE_BLOG: - if ($this->getIsNewObject()) { - if (!$xactions) { - $error = new PhabricatorApplicationTransactionValidationError( - $type, - pht('Required'), - pht( - 'When creating a post, you must specify which blog it '. - 'should belong to.'), - null); - - $error->setIsMissingFieldError(true); - - $errors[] = $error; - break; - } - } - - foreach ($xactions as $xaction) { - $new_phid = $xaction->getNewValue(); - - $blog = id(new PhameBlogQuery()) - ->setViewer($this->getActor()) - ->withPHIDs(array($new_phid)) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->execute(); - - if ($blog) { - continue; - } - - $errors[] = new PhabricatorApplicationTransactionValidationError( - $type, - pht('Invalid'), - pht( - 'The specified blog PHID ("%s") is not valid. You can only '. - 'create a post on (or move a post into) a blog which you '. - 'have permission to see and edit.', - $new_phid), - $xaction); - } - - break; - } - return $errors; - } - protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { diff --git a/src/applications/phame/storage/PhamePostTransaction.php b/src/applications/phame/storage/PhamePostTransaction.php index 6e54aeda6d..1c259911f3 100644 --- a/src/applications/phame/storage/PhamePostTransaction.php +++ b/src/applications/phame/storage/PhamePostTransaction.php @@ -1,14 +1,7 @@ getTransactionType()) { - case self::TYPE_BODY: - $blocks[] = $this->getNewValue(); - break; - } - - return $blocks; - } - - public function shouldHide() { - return parent::shouldHide(); - } - - public function getRequiredHandlePHIDs() { - $phids = parent::getRequiredHandlePHIDs(); - - switch ($this->getTransactionType()) { - case self::TYPE_BLOG: - $old = $this->getOldValue(); - $new = $this->getNewValue(); - - if ($old) { - $phids[] = $old; - } - - if ($new) { - $phids[] = $new; - } - break; - } - - return $phids; - } - - - public function getIcon() { - $old = $this->getOldValue(); - $new = $this->getNewValue(); - switch ($this->getTransactionType()) { - case PhabricatorTransactions::TYPE_CREATE: - return 'fa-plus'; - break; - case self::TYPE_HEADERIMAGE: - return 'fa-camera-retro'; - break; - case self::TYPE_VISIBILITY: - if ($new == PhameConstants::VISIBILITY_PUBLISHED) { - return 'fa-globe'; - } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { - return 'fa-ban'; - } else { - return 'fa-eye-slash'; - } - break; - } - return parent::getIcon(); - } - public function getMailTags() { $tags = parent::getMailTags(); @@ -110,200 +46,4 @@ final class PhamePostTransaction return $tags; } - - public function getTitle() { - $author_phid = $this->getAuthorPHID(); - $object_phid = $this->getObjectPHID(); - - $old = $this->getOldValue(); - $new = $this->getNewValue(); - - $type = $this->getTransactionType(); - switch ($type) { - case PhabricatorTransactions::TYPE_CREATE: - return pht( - '%s authored this post.', - $this->renderHandleLink($author_phid)); - case self::TYPE_BLOG: - return pht( - '%s moved this post from "%s" to "%s".', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($old), - $this->renderHandleLink($new)); - case self::TYPE_TITLE: - if ($old === null) { - return pht( - '%s authored this post.', - $this->renderHandleLink($author_phid)); - } else { - return pht( - '%s updated the post\'s name to "%s".', - $this->renderHandleLink($author_phid), - $new); - } - break; - case self::TYPE_SUBTITLE: - if ($old === null) { - return pht( - '%s set the post\'s subtitle to "%s".', - $this->renderHandleLink($author_phid), - $new); - } else { - return pht( - '%s updated the post\'s subtitle to "%s".', - $this->renderHandleLink($author_phid), - $new); - } - break; - case self::TYPE_BODY: - return pht( - '%s updated the blog post.', - $this->renderHandleLink($author_phid)); - break; - case self::TYPE_HEADERIMAGE: - return pht( - '%s updated the header image.', - $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 if ($new == PhameConstants::VISIBILITY_ARCHIVED) { - return pht( - '%s archived this post.', - $this->renderHandleLink($author_phid)); - } else { - return pht( - '%s published this post.', - $this->renderHandleLink($author_phid)); - } - break; - } - - return parent::getTitle(); - } - - public function getTitleForFeed() { - $author_phid = $this->getAuthorPHID(); - $object_phid = $this->getObjectPHID(); - - $old = $this->getOldValue(); - $new = $this->getNewValue(); - - $type = $this->getTransactionType(); - switch ($type) { - case PhabricatorTransactions::TYPE_CREATE: - return pht( - '%s authored %s.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - case self::TYPE_BLOG: - return pht( - '%s moved post "%s" from "%s" to "%s".', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid), - $this->renderHandleLink($old), - $this->renderHandleLink($new)); - case self::TYPE_TITLE: - if ($old === null) { - return pht( - '%s authored %s.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - } else { - return pht( - '%s updated the name for %s.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - } - break; - case self::TYPE_SUBTITLE: - return pht( - '%s updated the subtitle for %s.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - break; - case self::TYPE_BODY: - return pht( - '%s updated the blog post %s.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - break; - case self::TYPE_HEADERIMAGE: - return pht( - '%s updated the header image for post %s.', - $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 if ($new == PhameConstants::VISIBILITY_ARCHIVED) { - return pht( - '%s marked %s as archived.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - } else { - return pht( - '%s published %s.', - $this->renderHandleLink($author_phid), - $this->renderHandleLink($object_phid)); - } - break; - } - - return parent::getTitleForFeed(); - } - - public function getRemarkupBodyForFeed(PhabricatorFeedStory $story) { - $old = $this->getOldValue(); - - switch ($this->getTransactionType()) { - case self::TYPE_BODY: - if ($old === null) { - return $this->getNewValue(); - } - break; - } - - return null; - } - - public function getColor() { - switch ($this->getTransactionType()) { - case PhabricatorTransactions::TYPE_CREATE: - return PhabricatorTransactions::COLOR_GREEN; - } - return parent::getColor(); - } - - public function hasChangeDetails() { - switch ($this->getTransactionType()) { - case self::TYPE_BODY: - return ($this->getOldValue() !== null); - } - - return parent::hasChangeDetails(); - } - - public function renderChangeDetails(PhabricatorUser $viewer) { - switch ($this->getTransactionType()) { - case self::TYPE_BODY: - $old = $this->getOldValue(); - $new = $this->getNewValue(); - - return $this->renderTextCorpusChangeDetails( - $viewer, - $old, - $new); - } - - return parent::renderChangeDetails($viewer); - } - } diff --git a/src/applications/phame/xaction/PhameBlogNameTransaction.php b/src/applications/phame/xaction/PhameBlogNameTransaction.php index dbca5304a8..c219ba494b 100644 --- a/src/applications/phame/xaction/PhameBlogNameTransaction.php +++ b/src/applications/phame/xaction/PhameBlogNameTransaction.php @@ -23,7 +23,7 @@ final class PhameBlogNameTransaction public function getTitleForFeed() { return pht( - '%s renamed %s blog froms %s to %s.', + '%s renamed %s blog from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderOldValue(), diff --git a/src/applications/phame/xaction/PhameBlogStatusTransaction.php b/src/applications/phame/xaction/PhameBlogStatusTransaction.php index 21345ea249..b3366bece7 100644 --- a/src/applications/phame/xaction/PhameBlogStatusTransaction.php +++ b/src/applications/phame/xaction/PhameBlogStatusTransaction.php @@ -45,11 +45,11 @@ final class PhameBlogStatusTransaction public function getIcon() { $new = $this->getNewValue(); - if ($new == PhameBlog::STATUS_ARCHIVED) { - return 'fa-ban'; - } else { - return 'fa-check'; - } + if ($new == PhameBlog::STATUS_ARCHIVED) { + return 'fa-ban'; + } else { + return 'fa-check'; } + } } diff --git a/src/applications/phame/xaction/PhamePostBlogTransaction.php b/src/applications/phame/xaction/PhamePostBlogTransaction.php new file mode 100644 index 0000000000..cfe335a6ce --- /dev/null +++ b/src/applications/phame/xaction/PhamePostBlogTransaction.php @@ -0,0 +1,64 @@ +getBlogPHID(); + } + + public function applyInternalEffects($object, $value) { + $object->setBlogPHID($value); + } + + public function getTitle() { + return pht( + '%s changed the blog for this post.', + $this->renderAuthor()); + } + + public function getTitleForFeed() { + return pht( + '%s changed the blog for post %s.', + $this->renderAuthor(), + $this->renderObject()); + } + + public function validateTransactions($object, array $xactions) { + $errors = array(); + + if ($this->isEmptyTextTransaction($object->getBlogPHID(), $xactions)) { + $errors[] = $this->newRequiredError( + pht('Posts must be attached to a blog.')); + } + + foreach ($xactions as $xaction) { + $new_phid = $xaction->getNewValue(); + + $blog = id(new PhameBlogQuery()) + ->setViewer($this->getActor()) + ->withPHIDs(array($new_phid)) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->execute(); + + if ($blog) { + continue; + } + + $errors[] = $this->newInvalidError( + pht('The specified blog PHID ("%s") is not valid. You can only '. + 'create a post on (or move a post into) a blog which you '. + 'have permission to see and edit.', + $new_phid)); + } + + return $errors; + } + +} diff --git a/src/applications/phame/xaction/PhamePostBodyTransaction.php b/src/applications/phame/xaction/PhamePostBodyTransaction.php new file mode 100644 index 0000000000..bf34cf73ff --- /dev/null +++ b/src/applications/phame/xaction/PhamePostBodyTransaction.php @@ -0,0 +1,60 @@ +getBody(); + } + + public function applyInternalEffects($object, $value) { + $object->setBody($value); + } + + public function getTitle() { + return pht( + '%s updated the post content.', + $this->renderAuthor()); + } + + public function getTitleForFeed() { + return pht( + '%s updated the post content for %s.', + $this->renderAuthor(), + $this->renderObject()); + } + + public function hasChangeDetailView() { + return true; + } + + public function getMailDiffSectionHeader() { + return pht('CHANGES TO POST CONTENT'); + } + + public function newChangeDetailView() { + $viewer = $this->getViewer(); + + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) + ->setViewer($viewer) + ->setOldText($this->getOldValue()) + ->setNewText($this->getNewValue()); + } + + public function newRemarkupChanges() { + $changes = array(); + + $changes[] = $this->newRemarkupChange() + ->setOldValue($this->getOldValue()) + ->setNewValue($this->getNewValue()); + + return $changes; + } + + public function getIcon() { + return 'fa-file-text-o'; + } + +} diff --git a/src/applications/phame/xaction/PhamePostHeaderImageTransaction.php b/src/applications/phame/xaction/PhamePostHeaderImageTransaction.php new file mode 100644 index 0000000000..2b9631cdc4 --- /dev/null +++ b/src/applications/phame/xaction/PhamePostHeaderImageTransaction.php @@ -0,0 +1,33 @@ +getHeaderImagePHID(); + } + + public function applyInternalEffects($object, $value) { + $object->setHeaderImagePHID($value); + } + + public function getTitle() { + return pht( + '%s changed the header image for this post.', + $this->renderAuthor()); + } + + public function getTitleForFeed() { + return pht( + '%s changed the header image for post %s.', + $this->renderAuthor(), + $this->renderObject()); + } + + public function getIcon() { + return 'fa-camera'; + } + +} diff --git a/src/applications/phame/xaction/PhamePostSubtitleTransaction.php b/src/applications/phame/xaction/PhamePostSubtitleTransaction.php new file mode 100644 index 0000000000..05b0f34790 --- /dev/null +++ b/src/applications/phame/xaction/PhamePostSubtitleTransaction.php @@ -0,0 +1,63 @@ +getSubtitle(); + } + + public function applyInternalEffects($object, $value) { + $object->setSubtitle($value); + } + + public function getTitle() { + $old = $this->getOldValue(); + if ($old === null) { + return pht( + '%s set this post\'s subtitle to "%s".', + $this->renderAuthor(), + $this->renderNewValue()); + } else { + return pht( + '%s updated the post\'s subtitle to "%s".', + $this->renderAuthor(), + $this->renderNewValue()); + } + } + + public function getTitleForFeed() { + $old = $this->getOldValue(); + if ($old === null) { + return pht( + '%s set the subtitle for %s.', + $this->renderAuthor(), + $this->renderObject()); + } else { + return pht( + '%s updated the subtitle for %s.', + $this->renderAuthor(), + $this->renderObject()); + } + } + + public function validateTransactions($object, array $xactions) { + $errors = array(); + + $max_length = $object->getColumnMaximumByteLength('subtitle'); + foreach ($xactions as $xaction) { + $new_value = $xaction->getNewValue(); + $new_length = strlen($new_value); + if ($new_length > $max_length) { + $errors[] = $this->newInvalidError( + pht('The subtitle can be no longer than %s characters.', + new PhutilNumber($max_length))); + } + } + + return $errors; + } + +} diff --git a/src/applications/phame/xaction/PhamePostTitleTransaction.php b/src/applications/phame/xaction/PhamePostTitleTransaction.php new file mode 100644 index 0000000000..99c556cc3a --- /dev/null +++ b/src/applications/phame/xaction/PhamePostTitleTransaction.php @@ -0,0 +1,55 @@ +getTitle(); + } + + public function applyInternalEffects($object, $value) { + $object->setTitle($value); + } + + public function getTitle() { + return pht( + '%s renamed this blog post from %s to %s.', + $this->renderAuthor(), + $this->renderOldValue(), + $this->renderNewValue()); + } + + public function getTitleForFeed() { + return pht( + '%s renamed %s blog post from %s to %s.', + $this->renderAuthor(), + $this->renderObject(), + $this->renderOldValue(), + $this->renderNewValue()); + } + + public function validateTransactions($object, array $xactions) { + $errors = array(); + + if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) { + $errors[] = $this->newRequiredError( + pht('Posts must have a title.')); + } + + $max_length = $object->getColumnMaximumByteLength('title'); + foreach ($xactions as $xaction) { + $new_value = $xaction->getNewValue(); + $new_length = strlen($new_value); + if ($new_length > $max_length) { + $errors[] = $this->newInvalidError( + pht('The title can be no longer than %s characters.', + new PhutilNumber($max_length))); + } + } + + return $errors; + } + +} diff --git a/src/applications/phame/xaction/PhamePostTransactionType.php b/src/applications/phame/xaction/PhamePostTransactionType.php new file mode 100644 index 0000000000..b8ce182bc7 --- /dev/null +++ b/src/applications/phame/xaction/PhamePostTransactionType.php @@ -0,0 +1,4 @@ +getVisibility(); + } + + public function applyInternalEffects($object, $value) { + if ($value == PhameConstants::VISIBILITY_DRAFT) { + $object->setDatePublished(0); + } else if ($value == PhameConstants::VISIBILITY_ARCHIVED) { + $object->setDatePublished(0); + } else { + $object->setDatePublished(PhabricatorTime::getNow()); + } + $object->setVisibility($value); + } + + public function getTitle() { + $new = $this->getNewValue(); + if ($new == PhameConstants::VISIBILITY_DRAFT) { + return pht( + '%s marked this post as a draft.', + $this->renderAuthor()); + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { + return pht( + '%s archived this post.', + $this->renderAuthor()); + } else { + return pht( + '%s published this post.', + $this->renderAuthor()); + } + } + + public function getTitleForFeed() { + $new = $this->getNewValue(); + if ($new == PhameConstants::VISIBILITY_DRAFT) { + return pht( + '%s marked %s as a draft.', + $this->renderAuthor(), + $this->renderObject()); + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { + return pht( + '%s marked %s as archived.', + $this->renderAuthor(), + $this->renderObject()); + } else { + return pht( + '%s published %s.', + $this->renderAuthor(), + $this->renderObject()); + } + } + + public function getIcon() { + $new = $this->getNewValue(); + if ($new == PhameConstants::VISIBILITY_PUBLISHED) { + return 'fa-rss'; + } else if ($new == PhameConstants::VISIBILITY_ARCHIVED) { + return 'fa-ban'; + } else { + return 'fa-eye-slash'; + } + } +}