@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Paste - add transactions

Summary: Ref T3650. This adds a create transaction, transactions for metadata (title, langauge, view policy), and comments. Editor is used on all create /edit paths.

Test Plan: made some pastes via web and email - yay. edited pastes - yay. verified txns showed up on pastes and in feed correctly.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T3516, T3650

Differential Revision: https://secure.phabricator.com/D6645

+620 -39
+46
resources/sql/patches/20130801.pastexactions.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorPaste(); 4 + $x_table = new PhabricatorPasteTransaction(); 5 + 6 + $conn_w = $table->establishConnection('w'); 7 + $conn_w->openTransaction(); 8 + 9 + echo "Adding transactions for existing paste objects...\n"; 10 + 11 + $rows = new LiskRawMigrationIterator($conn_w, 'pastebin_paste'); 12 + foreach ($rows as $row) { 13 + 14 + $id = $row['id']; 15 + echo "Adding transactions for paste id {$id}...\n"; 16 + 17 + $xaction_phid = PhabricatorPHID::generateNewPHID( 18 + PhabricatorApplicationTransactionPHIDTypeTransaction::TYPECONST); 19 + 20 + queryfx( 21 + $conn_w, 22 + 'INSERT INTO %T (phid, authorPHID, objectPHID, viewPolicy, editPolicy, 23 + transactionType, oldValue, newValue, 24 + contentSource, metadata, dateCreated, dateModified) 25 + VALUES (%s, %s, %s, %s, %s, %s, %ns, %ns, %s, %s, %d, %d)', 26 + $x_table->getTableName(), 27 + $xaction_phid, 28 + $row['authorPHID'], 29 + $row['phid'], 30 + 'public', 31 + $row['authorPHID'], 32 + PhabricatorPasteTransaction::TYPE_CREATE, 33 + 'null', 34 + $row['filePHID'], 35 + PhabricatorContentSource::newForSource( 36 + PhabricatorContentSource::SOURCE_LEGACY, 37 + array())->serialize(), 38 + '[]', 39 + $row['dateCreated'], 40 + $row['dateCreated']); 41 + 42 + } 43 + 44 + $conn_w->saveTransaction(); 45 + 46 + echo "Done.\n";
+43
resources/sql/patches/20130801.pastexactions.sql
··· 1 + CREATE TABLE {$NAMESPACE}_pastebin.pastebin_pastetransaction ( 2 + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, 3 + phid VARCHAR(64) NOT NULL COLLATE utf8_bin, 4 + authorPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, 5 + objectPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, 6 + viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, 7 + editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, 8 + commentPHID VARCHAR(64) COLLATE utf8_bin, 9 + commentVersion INT UNSIGNED NOT NULL, 10 + transactionType VARCHAR(32) NOT NULL COLLATE utf8_bin, 11 + oldValue LONGTEXT NOT NULL COLLATE utf8_bin, 12 + newValue LONGTEXT NOT NULL COLLATE utf8_bin, 13 + contentSource LONGTEXT NOT NULL COLLATE utf8_bin, 14 + metadata LONGTEXT NOT NULL COLLATE utf8_bin, 15 + dateCreated INT UNSIGNED NOT NULL, 16 + dateModified INT UNSIGNED NOT NULL, 17 + 18 + UNIQUE KEY `key_phid` (phid), 19 + KEY `key_object` (objectPHID) 20 + 21 + ) ENGINE=InnoDB, COLLATE utf8_general_ci; 22 + 23 + CREATE TABLE {$NAMESPACE}_pastebin.pastebin_pastetransaction_comment ( 24 + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, 25 + phid VARCHAR(64) NOT NULL COLLATE utf8_bin, 26 + transactionPHID VARCHAR(64) COLLATE utf8_bin, 27 + authorPHID VARCHAR(64) NOT NULL COLLATE utf8_bin, 28 + viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, 29 + editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, 30 + commentVersion INT UNSIGNED NOT NULL, 31 + content LONGTEXT NOT NULL COLLATE utf8_bin, 32 + contentSource LONGTEXT NOT NULL COLLATE utf8_bin, 33 + isDeleted BOOL NOT NULL, 34 + dateCreated INT UNSIGNED NOT NULL, 35 + dateModified INT UNSIGNED NOT NULL, 36 + 37 + lineNumber INT UNSIGNED, 38 + lineLength INT UNSIGNED, 39 + 40 + UNIQUE KEY `key_phid` (phid), 41 + UNIQUE KEY `key_version` (transactionPHID, commentVersion) 42 + 43 + ) ENGINE=InnoDB, COLLATE utf8_general_ci;
+10
src/__phutil_library_map__.php
··· 1364 1364 'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php', 1365 1365 'PhabricatorPagedFormExample' => 'applications/uiexample/examples/PhabricatorPagedFormExample.php', 1366 1366 'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php', 1367 + 'PhabricatorPasteCommentController' => 'applications/paste/controller/PhabricatorPasteCommentController.php', 1367 1368 'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php', 1368 1369 'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php', 1369 1370 'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php', 1370 1371 'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php', 1372 + 'PhabricatorPasteEditor' => 'applications/paste/editor/PhabricatorPasteEditor.php', 1371 1373 'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php', 1372 1374 'PhabricatorPastePHIDTypePaste' => 'applications/paste/phid/PhabricatorPastePHIDTypePaste.php', 1373 1375 'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php', 1374 1376 'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php', 1375 1377 'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php', 1376 1378 'PhabricatorPasteTestDataGenerator' => 'applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php', 1379 + 'PhabricatorPasteTransaction' => 'applications/paste/storage/PhabricatorPasteTransaction.php', 1380 + 'PhabricatorPasteTransactionComment' => 'applications/paste/storage/PhabricatorPasteTransactionComment.php', 1381 + 'PhabricatorPasteTransactionQuery' => 'applications/paste/query/PhabricatorPasteTransactionQuery.php', 1377 1382 'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php', 1378 1383 'PhabricatorPeopleController' => 'applications/people/controller/PhabricatorPeopleController.php', 1379 1384 'PhabricatorPeopleEditController' => 'applications/people/controller/PhabricatorPeopleEditController.php', ··· 3406 3411 1 => 'PhabricatorTokenReceiverInterface', 3407 3412 2 => 'PhabricatorPolicyInterface', 3408 3413 ), 3414 + 'PhabricatorPasteCommentController' => 'PhabricatorPasteController', 3409 3415 'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions', 3410 3416 'PhabricatorPasteController' => 'PhabricatorController', 3411 3417 'PhabricatorPasteDAO' => 'PhabricatorLiskDAO', 3412 3418 'PhabricatorPasteEditController' => 'PhabricatorPasteController', 3419 + 'PhabricatorPasteEditor' => 'PhabricatorApplicationTransactionEditor', 3413 3420 'PhabricatorPasteListController' => 3414 3421 array( 3415 3422 0 => 'PhabricatorPasteController', ··· 3420 3427 'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject', 3421 3428 'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine', 3422 3429 'PhabricatorPasteTestDataGenerator' => 'PhabricatorTestDataGenerator', 3430 + 'PhabricatorPasteTransaction' => 'PhabricatorApplicationTransaction', 3431 + 'PhabricatorPasteTransactionComment' => 'PhabricatorApplicationTransactionComment', 3432 + 'PhabricatorPasteTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3423 3433 'PhabricatorPasteViewController' => 'PhabricatorPasteController', 3424 3434 'PhabricatorPeopleController' => 'PhabricatorController', 3425 3435 'PhabricatorPeopleEditController' => 'PhabricatorPeopleController',
+1 -1
src/applications/macro/application/PhabricatorApplicationMacro.php
··· 21 21 public function getApplicationGroup() { 22 22 return self::GROUP_UTILITIES; 23 23 } 24 - 24 + 25 25 public function getQuickCreateURI() { 26 26 return $this->getBaseURI().'create/'; 27 27 }
+4
src/applications/paste/application/PhabricatorApplicationPaste.php
··· 1 1 <?php 2 2 3 + /** 4 + * group paste 5 + */ 3 6 final class PhabricatorApplicationPaste extends PhabricatorApplication { 4 7 5 8 public function getBaseURI() { ··· 35 38 '(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController', 36 39 'create/' => 'PhabricatorPasteEditController', 37 40 'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController', 41 + 'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController', 38 42 ), 39 43 ); 40 44 }
+73
src/applications/paste/controller/PhabricatorPasteCommentController.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PhabricatorPasteCommentController 7 + extends PhabricatorPasteController { 8 + 9 + private $id; 10 + 11 + public function willProcessRequest(array $data) { 12 + $this->id = idx($data, 'id'); 13 + } 14 + 15 + public function processRequest() { 16 + $request = $this->getRequest(); 17 + $user = $request->getUser(); 18 + 19 + if (!$request->isFormPost()) { 20 + return new Aphront400Response(); 21 + } 22 + 23 + $paste = id(new PhabricatorPasteQuery()) 24 + ->setViewer($user) 25 + ->withIDs(array($this->id)) 26 + ->executeOne(); 27 + if (!$paste) { 28 + return new Aphront404Response(); 29 + } 30 + 31 + $is_preview = $request->isPreviewRequest(); 32 + $draft = PhabricatorDraft::buildFromRequest($request); 33 + 34 + $view_uri = $paste->getURI(); 35 + 36 + $xactions = array(); 37 + $xactions[] = id(new PhabricatorPasteTransaction()) 38 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 39 + ->attachComment( 40 + id(new PhabricatorPasteTransactionComment()) 41 + ->setContent($request->getStr('comment'))); 42 + 43 + $editor = id(new PhabricatorPasteEditor()) 44 + ->setActor($user) 45 + ->setContinueOnNoEffect($request->isContinueRequest()) 46 + ->setContentSourceFromRequest($request) 47 + ->setIsPreview($is_preview); 48 + 49 + try { 50 + $xactions = $editor->applyTransactions($paste, $xactions); 51 + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { 52 + return id(new PhabricatorApplicationTransactionNoEffectResponse()) 53 + ->setCancelURI($view_uri) 54 + ->setException($ex); 55 + } 56 + 57 + if ($draft) { 58 + $draft->replaceOrDelete(); 59 + } 60 + 61 + if ($request->isAjax()) { 62 + return id(new PhabricatorApplicationTransactionResponse()) 63 + ->setViewer($user) 64 + ->setTransactions($xactions) 65 + ->setIsPreview($is_preview) 66 + ->setAnchorOffset($request->getStr('anchor')); 67 + } else { 68 + return id(new AphrontRedirectResponse()) 69 + ->setURI($view_uri); 70 + } 71 + } 72 + 73 + }
+3
src/applications/paste/controller/PhabricatorPasteController.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group paste 5 + */ 3 6 abstract class PhabricatorPasteController extends PhabricatorController { 4 7 5 8 public function buildSideNavView($for_app = false) {
+47 -24
src/applications/paste/controller/PhabricatorPasteEditController.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group paste 5 + */ 3 6 final class PhabricatorPasteEditController extends PhabricatorPasteController { 4 7 5 8 private $id; ··· 59 62 $text = null; 60 63 $e_text = true; 61 64 $errors = array(); 65 + if ($is_create && $parent) { 66 + $v_title = pht('Fork of %s', $parent->getFullName()); 67 + $v_language = $parent->getLanguage(); 68 + $v_text = $parent->getRawContent(); 69 + } else { 70 + $v_title = $paste->getTitle(); 71 + $v_language = $paste->getLanguage(); 72 + $v_text = ''; 73 + } 74 + $v_policy = $paste->getViewPolicy(); 75 + 62 76 if ($request->isFormPost()) { 77 + $xactions = array(); 63 78 64 79 if ($is_create) { 65 - $text = $request->getStr('text'); 66 - if (!strlen($text)) { 80 + $v_text = $request->getStr('text'); 81 + if (!strlen($v_text)) { 67 82 $e_text = pht('Required'); 68 83 $errors[] = pht('The paste may not be blank.'); 69 84 } else { 70 85 $e_text = null; 71 86 } 72 - } 87 + } 73 88 74 - $paste->setTitle($request->getStr('title')); 75 - $paste->setLanguage($request->getStr('language')); 76 - $paste->setViewPolicy($request->getStr('can_view')); 89 + $v_title = $request->getStr('title'); 90 + $v_language = $request->getStr('language'); 91 + $v_policy = $request->getStr('can_view'); 77 92 78 93 // NOTE: The author is the only editor and can always view the paste, 79 94 // so it's impossible for them to choose an invalid policy. 80 95 81 96 if (!$errors) { 82 97 if ($is_create) { 83 - $paste_file = PhabricatorFile::newFromFileData( 84 - $text, 85 - array( 86 - 'name' => $paste->getTitle(), 87 - 'mime-type' => 'text/plain; charset=utf-8', 88 - 'authorPHID' => $user->getPHID(), 89 - )); 90 - $paste->setFilePHID($paste_file->getPHID()); 98 + $xactions[] = id(new PhabricatorPasteTransaction()) 99 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 100 + ->setNewValue(array( 101 + 'title' => $v_title, 102 + 'text' => $v_text)); 91 103 } 92 - $paste->save(); 104 + $xactions[] = id(new PhabricatorPasteTransaction()) 105 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE) 106 + ->setNewValue($v_title); 107 + $xactions[] = id(new PhabricatorPasteTransaction()) 108 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE) 109 + ->setNewValue($v_language); 110 + $xactions[] = id(new PhabricatorPasteTransaction()) 111 + ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 112 + ->setNewValue($v_policy); 113 + $editor = id(new PhabricatorPasteEditor()) 114 + ->setActor($user) 115 + ->setContentSourceFromRequest($request) 116 + ->setContinueOnNoEffect(true); 117 + $xactions = $editor->applyTransactions($paste, $xactions); 93 118 return id(new AphrontRedirectResponse())->setURI($paste->getURI()); 94 - } 95 - } else { 96 - if ($is_create && $parent) { 97 - $paste->setTitle(pht('Fork of %s', $parent->getFullName())); 98 - $paste->setLanguage($parent->getLanguage()); 99 - $text = $parent->getRawContent(); 119 + } else { 120 + // make sure we update policy so its correctly populated to what 121 + // the user chose 122 + $paste->setViewPolicy($v_policy); 100 123 } 101 124 } 102 125 ··· 120 143 ->appendChild( 121 144 id(new AphrontFormTextControl()) 122 145 ->setLabel(pht('Title')) 123 - ->setValue($paste->getTitle()) 146 + ->setValue($v_title) 124 147 ->setName('title')) 125 148 ->appendChild( 126 149 id(new AphrontFormSelectControl()) 127 150 ->setLabel(pht('Language')) 128 151 ->setName('language') 129 - ->setValue($paste->getLanguage()) 152 + ->setValue($v_language) 130 153 ->setOptions($langs)); 131 154 132 155 $policies = id(new PhabricatorPolicyQuery()) ··· 148 171 id(new AphrontFormTextAreaControl()) 149 172 ->setLabel(pht('Text')) 150 173 ->setError($e_text) 151 - ->setValue($text) 174 + ->setValue($v_text) 152 175 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) 153 176 ->setCustomClass('PhabricatorMonospaced') 154 177 ->setName('text'));
+3
src/applications/paste/controller/PhabricatorPasteListController.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group paste 5 + */ 3 6 final class PhabricatorPasteListController extends PhabricatorPasteController 4 7 implements PhabricatorApplicationSearchResultsControllerInterface { 5 8
+49
src/applications/paste/controller/PhabricatorPasteViewController.php
··· 1 1 <?php 2 2 3 + /** 4 + * group paste 5 + */ 3 6 final class PhabricatorPasteViewController extends PhabricatorPasteController { 4 7 5 8 private $id; ··· 58 61 ->setName('P'.$paste->getID()) 59 62 ->setHref('/P'.$paste->getID())); 60 63 64 + $xactions = id(new PhabricatorPasteTransactionQuery()) 65 + ->setViewer($request->getUser()) 66 + ->withObjectPHIDs(array($paste->getPHID())) 67 + ->execute(); 68 + 69 + $engine = id(new PhabricatorMarkupEngine()) 70 + ->setViewer($user); 71 + foreach ($xactions as $xaction) { 72 + if ($xaction->getComment()) { 73 + $engine->addObject( 74 + $xaction->getComment(), 75 + PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 76 + } 77 + } 78 + $engine->process(); 79 + 80 + $timeline = id(new PhabricatorApplicationTransactionView()) 81 + ->setUser($user) 82 + ->setObjectPHID($paste->getPHID()) 83 + ->setTransactions($xactions) 84 + ->setMarkupEngine($engine); 85 + 86 + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 87 + 88 + $add_comment_header = id(new PhabricatorHeaderView()) 89 + ->setHeader( 90 + $is_serious 91 + ? pht('Add Comment') 92 + : pht('Debate Paste Accuracy')); 93 + 94 + $submit_button_name = $is_serious 95 + ? pht('Add Comment') 96 + : pht('Pity the Fool'); 97 + 98 + $draft = PhabricatorDraft::newFromUserAndKey($user, $paste->getPHID()); 99 + 100 + $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) 101 + ->setUser($user) 102 + ->setObjectPHID($paste->getPHID()) 103 + ->setDraft($draft) 104 + ->setAction($this->getApplicationURI('/comment/'.$paste->getID().'/')) 105 + ->setSubmitButtonName($submit_button_name); 106 + 61 107 return $this->buildApplicationPage( 62 108 array( 63 109 $crumbs, ··· 65 111 $actions, 66 112 $properties, 67 113 $source_code, 114 + $timeline, 115 + $add_comment_header, 116 + $add_comment_form 68 117 ), 69 118 array( 70 119 'title' => $paste->getFullName(),
+126
src/applications/paste/editor/PhabricatorPasteEditor.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PhabricatorPasteEditor 7 + extends PhabricatorApplicationTransactionEditor { 8 + 9 + public function getTransactionTypes() { 10 + $types = parent::getTransactionTypes(); 11 + 12 + $types[] = PhabricatorPasteTransaction::TYPE_CREATE; 13 + $types[] = PhabricatorPasteTransaction::TYPE_TITLE; 14 + $types[] = PhabricatorPasteTransaction::TYPE_LANGUAGE; 15 + $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 16 + $types[] = PhabricatorTransactions::TYPE_COMMENT; 17 + 18 + return $types; 19 + } 20 + 21 + protected function getCustomTransactionOldValue( 22 + PhabricatorLiskDAO $object, 23 + PhabricatorApplicationTransaction $xaction) { 24 + 25 + switch ($xaction->getTransactionType()) { 26 + case PhabricatorPasteTransaction::TYPE_CREATE: 27 + return null; 28 + case PhabricatorPasteTransaction::TYPE_TITLE: 29 + return $object->getTitle(); 30 + case PhabricatorPasteTransaction::TYPE_LANGUAGE: 31 + return $object->getLanguage(); 32 + } 33 + } 34 + 35 + protected function getCustomTransactionNewValue( 36 + PhabricatorLiskDAO $object, 37 + PhabricatorApplicationTransaction $xaction) { 38 + 39 + switch ($xaction->getTransactionType()) { 40 + case PhabricatorPasteTransaction::TYPE_CREATE: 41 + // this was set via applyInitialEffects 42 + return $object->getFilePHID(); 43 + case PhabricatorPasteTransaction::TYPE_TITLE: 44 + case PhabricatorPasteTransaction::TYPE_LANGUAGE: 45 + return $xaction->getNewValue(); 46 + } 47 + } 48 + 49 + protected function applyCustomInternalTransaction( 50 + PhabricatorLiskDAO $object, 51 + PhabricatorApplicationTransaction $xaction) { 52 + 53 + switch ($xaction->getTransactionType()) { 54 + case PhabricatorPasteTransaction::TYPE_TITLE: 55 + $object->setTitle($xaction->getNewValue()); 56 + break; 57 + case PhabricatorPasteTransaction::TYPE_LANGUAGE: 58 + $object->setLanguage($xaction->getNewValue()); 59 + break; 60 + } 61 + } 62 + 63 + protected function applyCustomExternalTransaction( 64 + PhabricatorLiskDAO $object, 65 + PhabricatorApplicationTransaction $xaction) { 66 + } 67 + 68 + 69 + protected function shouldApplyInitialEffects( 70 + PhabricatorLiskDAO $object, 71 + array $xactions) { 72 + 73 + foreach ($xactions as $xaction) { 74 + if ($xaction->getTransactionType() == 75 + PhabricatorPasteTransaction::TYPE_CREATE) { 76 + return true; 77 + } 78 + } 79 + return false; 80 + } 81 + 82 + protected function applyInitialEffects( 83 + PhabricatorLiskDAO $object, 84 + array $xactions) { 85 + 86 + foreach ($xactions as $xaction) { 87 + switch ($xaction->getTransactionType()) { 88 + case PhabricatorPasteTransaction::TYPE_CREATE: 89 + $data = $xaction->getNewValue(); 90 + $paste_file = PhabricatorFile::newFromFileData( 91 + $data['text'], 92 + array( 93 + 'name' => $data['title'], 94 + 'mime-type' => 'text/plain; charset=utf-8', 95 + 'authorPHID' => $this->getActor()->getPHID(), 96 + )); 97 + $object->setFilePHID($paste_file->getPHID()); 98 + break; 99 + } 100 + } 101 + } 102 + 103 + protected function supportsMail() { 104 + return false; 105 + } 106 + 107 + protected function getMailTo(PhabricatorLiskDAO $object) { 108 + return array( 109 + $object->getAuthorPHID(), 110 + $this->requireActor()->getPHID(), 111 + ); 112 + } 113 + 114 + protected function getMailCC(PhabricatorLiskDAO $object) { 115 + return array(); 116 + } 117 + 118 + protected function supportsFeed() { 119 + return true; 120 + } 121 + 122 + protected function supportsSearch() { 123 + return false; 124 + } 125 + 126 + }
+26 -13
src/applications/paste/mail/PasteCreateMailReceiver.php
··· 35 35 if (!$title) { 36 36 $title = pht('Pasted via email.'); 37 37 } 38 - $paste_file = PhabricatorFile::newFromFileData( 39 - $mail->getCleanTextBody(), 38 + $xactions = array(); 39 + $xactions[] = id(new PhabricatorPasteTransaction()) 40 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 41 + ->setNewValue(array( 42 + 'title' => $title, 43 + 'text' => $mail->getCleanTextBody())); 44 + $xactions[] = id(new PhabricatorPasteTransaction()) 45 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE) 46 + ->setNewValue($title); 47 + $xactions[] = id(new PhabricatorPasteTransaction()) 48 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE) 49 + ->setNewValue(''); // auto-detect 50 + $xactions[] = id(new PhabricatorPasteTransaction()) 51 + ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 52 + ->setNewValue(PhabricatorPolicies::POLICY_USER); 53 + 54 + $paste = id(new PhabricatorPaste()) 55 + ->setAuthorPHID($sender->getPHID()); 56 + $content_source = PhabricatorContentSource::newForSource( 57 + PhabricatorContentSource::SOURCE_EMAIL, 40 58 array( 41 - 'name' => $title, 42 - 'mime-type' => 'text/plain; charset=utf-8', 43 - 'authorPHID' => $sender->getPHID(), 59 + 'id' => $mail->getID(), 44 60 )); 45 - 46 - $paste = id(new PhabricatorPaste()) 47 - ->setAuthorPHID($sender->getPHID()) 48 - ->setTitle($title) 49 - ->setFilePHID($paste_file->getPHID()) 50 - ->setLanguage('') // auto-detect 51 - ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 52 - ->save(); 61 + $editor = id(new PhabricatorPasteEditor()) 62 + ->setActor($sender) 63 + ->setContentSource($content_source) 64 + ->setContinueOnNoEffect(true); 65 + $xactions = $editor->applyTransactions($paste, $xactions); 53 66 54 67 $mail->setRelatedPHID($paste->getPHID()); 55 68
+1 -1
src/applications/paste/phid/PhabricatorPastePHIDTypePaste.php
··· 38 38 $name = $paste->getFullName(); 39 39 40 40 $handle->setName("P{$id}"); 41 - $handle->setFullName("P{$id}: {$name}"); 41 + $handle->setFullName($name); 42 42 $handle->setURI("/P{$id}"); 43 43 } 44 44 }
+3
src/applications/paste/query/PhabricatorPasteQuery.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group paste 5 + */ 3 6 final class PhabricatorPasteQuery 4 7 extends PhabricatorCursorPagedPolicyAwareQuery { 5 8
+3
src/applications/paste/query/PhabricatorPasteSearchEngine.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group paste 5 + */ 3 6 final class PhabricatorPasteSearchEngine 4 7 extends PhabricatorApplicationSearchEngine { 5 8
+13
src/applications/paste/query/PhabricatorPasteTransactionQuery.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PhabricatorPasteTransactionQuery 7 + extends PhabricatorApplicationTransactionQuery { 8 + 9 + public function getTemplateApplicationTransaction() { 10 + return new PhabricatorPasteTransaction(); 11 + } 12 + 13 + }
+3
src/applications/paste/storage/PhabricatorPaste.php
··· 1 1 <?php 2 2 3 + /** 4 + * @group paste 5 + */ 3 6 final class PhabricatorPaste extends PhabricatorPasteDAO 4 7 implements PhabricatorTokenReceiverInterface, PhabricatorPolicyInterface { 5 8
+138
src/applications/paste/storage/PhabricatorPasteTransaction.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PhabricatorPasteTransaction 7 + extends PhabricatorApplicationTransaction { 8 + 9 + const TYPE_CREATE = 'paste.create'; 10 + const TYPE_TITLE = 'paste.title'; 11 + const TYPE_LANGUAGE = 'paste.language'; 12 + 13 + public function getApplicationName() { 14 + return 'pastebin'; 15 + } 16 + 17 + public function getApplicationTransactionType() { 18 + return PhabricatorPastePHIDTypePaste::TYPECONST; 19 + } 20 + 21 + public function getApplicationTransactionCommentObject() { 22 + return new PhabricatorPasteTransactionComment(); 23 + } 24 + 25 + public function getApplicationObjectTypeName() { 26 + return pht('paste'); 27 + } 28 + 29 + public function getRequiredHandlePHIDs() { 30 + $phids = parent::getRequiredHandlePHIDs(); 31 + 32 + switch ($this->getTransactionType()) { 33 + case self::TYPE_CREATE: 34 + $phids[] = $this->getObjectPHID(); 35 + break; 36 + } 37 + 38 + return $phids; 39 + } 40 + 41 + public function shouldHide() { 42 + $old = $this->getOldValue(); 43 + switch ($this->getTransactionType()) { 44 + case self::TYPE_TITLE: 45 + case self::TYPE_LANGUAGE: 46 + return $old === null; 47 + } 48 + return parent::shouldHide(); 49 + } 50 + 51 + public function getIcon() { 52 + switch ($this->getTransactionType()) { 53 + case self::TYPE_CREATE: 54 + return 'create'; 55 + break; 56 + case self::TYPE_TITLE: 57 + case self::TYPE_LANGUAGE: 58 + return 'edit'; 59 + break; 60 + } 61 + return parent::getIcon(); 62 + } 63 + 64 + public function getTitle() { 65 + $author_phid = $this->getAuthorPHID(); 66 + $object_phid = $this->getObjectPHID(); 67 + 68 + $old = $this->getOldValue(); 69 + $new = $this->getNewValue(); 70 + 71 + $type = $this->getTransactionType(); 72 + switch ($type) { 73 + case PhabricatorPasteTransaction::TYPE_CREATE: 74 + return pht( 75 + '%s created "%s".', 76 + $this->renderHandleLink($author_phid), 77 + $this->renderHandleLink($object_phid)); 78 + break; 79 + case PhabricatorPasteTransaction::TYPE_TITLE: 80 + return pht( 81 + '%s updated the paste\'s title to "%s".', 82 + $this->renderHandleLink($author_phid), 83 + $new); 84 + break; 85 + case PhabricatorPasteTransaction::TYPE_LANGUAGE: 86 + return pht( 87 + "%s updated the paste's language.", 88 + $this->renderHandleLink($author_phid)); 89 + break; 90 + } 91 + 92 + return parent::getTitle(); 93 + } 94 + 95 + public function getTitleForFeed() { 96 + $author_phid = $this->getAuthorPHID(); 97 + $object_phid = $this->getObjectPHID(); 98 + 99 + $old = $this->getOldValue(); 100 + $new = $this->getNewValue(); 101 + 102 + $type = $this->getTransactionType(); 103 + switch ($type) { 104 + case PhabricatorPasteTransaction::TYPE_CREATE: 105 + return pht( 106 + '%s created %s.', 107 + $this->renderHandleLink($author_phid), 108 + $this->renderHandleLink($object_phid)); 109 + break; 110 + case PhabricatorPasteTransaction::TYPE_TITLE: 111 + return pht( 112 + '%s updated the title for %s.', 113 + $this->renderHandleLink($author_phid), 114 + $this->renderHandleLink($object_phid)); 115 + break; 116 + case PhabricatorPasteTransaction::TYPE_LANGUAGE: 117 + return pht( 118 + '%s update the language for %s.', 119 + $this->renderHandleLink($author_phid), 120 + $this->renderHandleLink($object_phid)); 121 + break; 122 + } 123 + 124 + return parent::getTitleForFeed(); 125 + } 126 + 127 + public function getColor() { 128 + $old = $this->getOldValue(); 129 + $new = $this->getNewValue(); 130 + 131 + switch ($this->getTransactionType()) { 132 + case PhabricatorPasteTransaction::TYPE_CREATE: 133 + return PhabricatorTransactions::COLOR_GREEN; 134 + } 135 + 136 + return parent::getColor(); 137 + } 138 + }
+20
src/applications/paste/storage/PhabricatorPasteTransactionComment.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PhabricatorPasteTransactionComment 7 + extends PhabricatorApplicationTransactionComment { 8 + 9 + protected $lineNumber; 10 + protected $lineLength; 11 + 12 + public function getApplicationTransactionObject() { 13 + return new PhabricatorPasteTransaction(); 14 + } 15 + 16 + public function shouldUseMarkupCache($field) { 17 + // Only cache submitted comments. 18 + return ($this->getTransactionPHID() != null); 19 + } 20 + }
+8
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1499 1499 'type' => 'php', 1500 1500 'name' => $this->getPatchPath('20130728.ponderxcomment.php'), 1501 1501 ), 1502 + '20130801.pastexactions.sql' => array( 1503 + 'type' => 'sql', 1504 + 'name' => $this->getPatchPath('20130801.pastexactions.sql'), 1505 + ), 1506 + '20130801.pastexactions.php' => array( 1507 + 'type' => 'php', 1508 + 'name' => $this->getPatchPath('20130801.pastexactions.php'), 1509 + ), 1502 1510 ); 1503 1511 } 1504 1512 }