diff --git a/src/applications/paste/editor/PhabricatorPasteEditor.php b/src/applications/paste/editor/PhabricatorPasteEditor.php index 319ac444ee..b120f58a57 100644 --- a/src/applications/paste/editor/PhabricatorPasteEditor.php +++ b/src/applications/paste/editor/PhabricatorPasteEditor.php @@ -1,101 +1,123 @@ newPasteTitle; + } + public function getEditorApplicationClass() { return 'PhabricatorPasteApplication'; } public function getEditorObjectsDescription() { return pht('Pastes'); } public function getCreateObjectTitle($author, $object) { return pht('%s created this paste.', $author); } public function getCreateObjectTitleForFeed($author, $object) { return pht('%s created %s.', $author, $object); } public function getTransactionTypes() { $types = parent::getTransactionTypes(); $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; $types[] = PhabricatorTransactions::TYPE_COMMENT; return $types; } + protected function expandTransactions( + PhabricatorLiskDAO $object, + array $xactions) { + + $new_title = $object->getTitle(); + foreach ($xactions as $xaction) { + $type = $xaction->getTransactionType(); + if ($type === PhabricatorPasteTitleTransaction::TRANSACTIONTYPE) { + $new_title = $xaction->getNewValue(); + } + } + $this->newPasteTitle = $new_title; + + return parent::expandTransactions($object, $xactions); + } + protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { if ($this->getIsNewObject()) { return false; } return true; } protected function getMailSubjectPrefix() { return pht('[Paste]'); } protected function getMailTo(PhabricatorLiskDAO $object) { return array( $object->getAuthorPHID(), $this->getActingAsPHID(), ); } public function getMailTagsMap() { return array( PhabricatorPasteTransaction::MAILTAG_CONTENT => pht('Paste title, language or text changes.'), PhabricatorPasteTransaction::MAILTAG_COMMENT => pht('Someone comments on a paste.'), PhabricatorPasteTransaction::MAILTAG_OTHER => pht('Other paste activity not listed above occurs.'), ); } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new PasteReplyHandler()) ->setMailReceiver($object); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $id = $object->getID(); $name = $object->getTitle(); return id(new PhabricatorMetaMTAMail()) ->setSubject("P{$id}: {$name}"); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); $body->addLinkSection( pht('PASTE DETAIL'), PhabricatorEnv::getProductionURI('/P'.$object->getID())); return $body; } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function supportsSearch() { return true; } } diff --git a/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php b/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php index 1e4ad2d26c..8df9ad8057 100644 --- a/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php +++ b/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php @@ -1,116 +1,123 @@ getFilePHID(); } public function applyInternalEffects($object, $value) { $object->setFilePHID($value); } public function extractFilePHIDs($object, $value) { return array($value); } public function validateTransactions($object, array $xactions) { if ($object->getFilePHID() || $xactions) { return array(); } $error = $this->newError( pht('Required'), pht('You must provide content to create a paste.')); $error->setIsMissingFieldError(true); return array($error); } public function generateNewValue($object, $value) { // If this transaction does not really change the paste content, return // the current file PHID so this transaction no-ops. $old_content = $object->getRawContent(); if ($value === $old_content) { $file_phid = $object->getFilePHID(); if ($file_phid) { return $file_phid; } } $editor = $this->getEditor(); $actor = $editor->getActor(); $file = $this->newFileForPaste($actor, $value); return $file->getPHID(); } private function newFileForPaste(PhabricatorUser $actor, $data) { + $editor = $this->getEditor(); + + $file_name = $editor->getNewPasteTitle(); + if (!strlen($file_name)) { + $file_name = 'raw-paste-data.txt'; + } + return PhabricatorFile::newFromFileData( $data, array( - 'name' => 'raw.txt', + 'name' => $file_name, 'mime-type' => 'text/plain; charset=utf-8', 'authorPHID' => $actor->getPHID(), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, )); } public function getIcon() { return 'fa-plus'; } public function getTitle() { return pht( '%s edited the content of this paste.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( '%s edited %s.', $this->renderAuthor(), $this->renderObject()); } public function hasChangeDetailView() { return true; } public function getMailDiffSectionHeader() { return pht('CHANGES TO PASTE CONTENT'); } public function newChangeDetailView() { $viewer = $this->getViewer(); $old = $this->getOldValue(); $new = $this->getNewValue(); $files = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($old, $new)) ->execute(); $files = mpull($files, null, 'getPHID'); $old_text = ''; if (idx($files, $old)) { $old_text = $files[$old]->loadFileData(); } $new_text = ''; if (idx($files, $new)) { $new_text = $files[$new]->loadFileData(); } return id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setViewer($viewer) ->setOldText($old_text) ->setNewText($new_text); } }