mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 19:32:40 +01:00
2d588715bc
Summary: Fixes T9995. I think letting users customize slugs is not a hugely compelling as a product feature, and this fixes the issue with slugs that have "/" characters in them and makes the move to EditEngine easier since I don't have to deal with the weird JS thing. Instead, just generate slugs automatically. No more JS, no more separate field, things automatically update if you rename a blog, and now that URIs have IDs in them the old URI will still work after a rename. Test Plan: - Applied migration. - Created new posts. - Edited existing posts. - Visited various posts. - Created a post with a bunch of "/" in the title, things still worked fine. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9995 Differential Revision: https://secure.phabricator.com/D14792
213 lines
5.9 KiB
PHP
213 lines
5.9 KiB
PHP
<?php
|
|
|
|
final class PhamePostEditor
|
|
extends PhabricatorApplicationTransactionEditor {
|
|
|
|
public function getEditorApplicationClass() {
|
|
return 'PhabricatorPhameApplication';
|
|
}
|
|
|
|
public function getEditorObjectsDescription() {
|
|
return pht('Phame Posts');
|
|
}
|
|
|
|
public function getTransactionTypes() {
|
|
$types = parent::getTransactionTypes();
|
|
|
|
$types[] = PhamePostTransaction::TYPE_TITLE;
|
|
$types[] = PhamePostTransaction::TYPE_BODY;
|
|
$types[] = PhamePostTransaction::TYPE_VISIBILITY;
|
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
|
|
|
return $types;
|
|
}
|
|
|
|
protected function getCustomTransactionOldValue(
|
|
PhabricatorLiskDAO $object,
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
return $object->getTitle();
|
|
case PhamePostTransaction::TYPE_BODY:
|
|
return $object->getBody();
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
return $object->getVisibility();
|
|
}
|
|
}
|
|
|
|
protected function getCustomTransactionNewValue(
|
|
PhabricatorLiskDAO $object,
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
case PhamePostTransaction::TYPE_BODY:
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
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_BODY:
|
|
return $object->setBody($xaction->getNewValue());
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
|
|
$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_BODY:
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
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;
|
|
}
|
|
return $errors;
|
|
}
|
|
|
|
protected function shouldSendMail(
|
|
PhabricatorLiskDAO $object,
|
|
array $xactions) {
|
|
if ($object->isDraft()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected function shouldPublishFeedStory(
|
|
PhabricatorLiskDAO $object,
|
|
array $xactions) {
|
|
if ($object->isDraft()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected function getMailTo(PhabricatorLiskDAO $object) {
|
|
$phids = array();
|
|
$phids[] = $object->getBloggerPHID();
|
|
$phids[] = $this->requireActor()->getPHID();
|
|
|
|
$blog_phid = $object->getBlogPHID();
|
|
if ($blog_phid) {
|
|
$cc_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
|
$blog_phid);
|
|
foreach ($cc_phids as $cc) {
|
|
$phids[] = $cc;
|
|
}
|
|
}
|
|
return $phids;
|
|
}
|
|
|
|
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
|
|
$phid = $object->getPHID();
|
|
$title = $object->getTitle();
|
|
|
|
return id(new PhabricatorMetaMTAMail())
|
|
->setSubject($title)
|
|
->addHeader('Thread-Topic', $phid);
|
|
}
|
|
|
|
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
|
return id(new PhamePostReplyHandler())
|
|
->setMailReceiver($object);
|
|
}
|
|
|
|
protected function buildMailBody(
|
|
PhabricatorLiskDAO $object,
|
|
array $xactions) {
|
|
|
|
$body = parent::buildMailBody($object, $xactions);
|
|
|
|
// We don't send mail if the object is a draft, and we only want
|
|
// to include the full body of the post on the either the
|
|
// first creation or if it was created as a draft, once it goes live.
|
|
if ($this->getIsNewObject()) {
|
|
$body->addRemarkupSection(null, $object->getBody());
|
|
} else {
|
|
foreach ($xactions as $xaction) {
|
|
switch ($xaction->getTransactionType()) {
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
if (!$object->isDraft()) {
|
|
$body->addRemarkupSection(null, $object->getBody());
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$body->addLinkSection(
|
|
pht('POST DETAIL'),
|
|
PhabricatorEnv::getProductionURI($object->getViewURI()));
|
|
|
|
return $body;
|
|
}
|
|
|
|
public function getMailTagsMap() {
|
|
return array(
|
|
PhamePostTransaction::MAILTAG_CONTENT =>
|
|
pht("A post's content changes."),
|
|
PhamePostTransaction::MAILTAG_SUBSCRIBERS =>
|
|
pht("A post's subscribers change."),
|
|
PhamePostTransaction::MAILTAG_COMMENT =>
|
|
pht('Someone comments on a post.'),
|
|
PhamePostTransaction::MAILTAG_OTHER =>
|
|
pht('Other post activity not listed above occurs.'),
|
|
);
|
|
}
|
|
|
|
protected function getMailSubjectPrefix() {
|
|
return '[Phame]';
|
|
}
|
|
|
|
protected function supportsSearch() {
|
|
return false;
|
|
}
|
|
|
|
}
|