@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.

Allow pastes to be edited

Summary: Fixes T4814.

Test Plan: Edited pastes from the web UI.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4814

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

+115 -64
+1 -1
resources/sql/patches/20130801.pastexactions.php
··· 30 30 $row['phid'], 31 31 'public', 32 32 $row['authorPHID'], 33 - PhabricatorPasteTransaction::TYPE_CREATE, 33 + PhabricatorPasteTransaction::TYPE_CONTENT, 34 34 'null', 35 35 $row['filePHID'], 36 36 PhabricatorContentSource::newForSource(
+1 -1
src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
··· 51 51 $xactions = array(); 52 52 53 53 $xactions[] = id(new PhabricatorPasteTransaction()) 54 - ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 54 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT) 55 55 ->setNewValue($file->getPHID()); 56 56 57 57 $xactions[] = id(new PhabricatorPasteTransaction())
+20 -36
src/applications/paste/controller/PhabricatorPasteEditController.php
··· 42 42 } 43 43 44 44 $paste->setAuthorPHID($user->getPHID()); 45 + $paste->attachRawContent(''); 45 46 } else { 46 47 $is_create = false; 47 48 ··· 53 54 PhabricatorPolicyCapability::CAN_EDIT, 54 55 )) 55 56 ->withIDs(array($this->id)) 57 + ->needRawContent(true) 56 58 ->executeOne(); 57 59 if (!$paste) { 58 60 return new Aphront404Response(); ··· 69 71 } else { 70 72 $v_title = $paste->getTitle(); 71 73 $v_language = $paste->getLanguage(); 72 - $v_text = ''; 74 + $v_text = $paste->getRawContent(); 73 75 } 74 76 $v_policy = $paste->getViewPolicy(); 75 77 76 78 if ($request->isFormPost()) { 77 79 $xactions = array(); 78 80 79 - if ($is_create) { 80 - $v_text = $request->getStr('text'); 81 - if (!strlen($v_text)) { 82 - $e_text = pht('Required'); 83 - $errors[] = pht('The paste may not be blank.'); 84 - } else { 85 - $e_text = null; 86 - } 87 - } 81 + $v_text = $request->getStr('text'); 82 + if (!strlen($v_text)) { 83 + $e_text = pht('Required'); 84 + $errors[] = pht('The paste may not be blank.'); 85 + } else { 86 + $e_text = null; 87 + } 88 88 89 89 $v_title = $request->getStr('title'); 90 90 $v_language = $request->getStr('language'); ··· 94 94 // so it's impossible for them to choose an invalid policy. 95 95 96 96 if (!$errors) { 97 - if ($is_create) { 97 + if ($is_create || ($v_text !== $paste->getRawContent())) { 98 98 $file = PhabricatorPasteEditor::initializeFileForPaste( 99 99 $user, 100 100 $v_title, 101 101 $v_text); 102 102 103 103 $xactions[] = id(new PhabricatorPasteTransaction()) 104 - ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 104 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT) 105 105 ->setNewValue($file->getPHID()); 106 106 } 107 107 ··· 161 161 ->setPolicies($policies) 162 162 ->setName('can_view')); 163 163 164 - if ($is_create) { 165 - $form 166 - ->appendChild( 167 - id(new AphrontFormTextAreaControl()) 168 - ->setLabel(pht('Text')) 169 - ->setError($e_text) 170 - ->setValue($v_text) 171 - ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) 172 - ->setCustomClass('PhabricatorMonospaced') 173 - ->setName('text')); 174 - } else { 175 - $fork_link = phutil_tag( 176 - 'a', 177 - array( 178 - 'href' => $this->getApplicationURI('?parent='.$paste->getID()) 179 - ), 180 - pht('Fork')); 181 - $form 182 - ->appendChild( 183 - id(new AphrontFormMarkupControl()) 164 + $form 165 + ->appendChild( 166 + id(new AphrontFormTextAreaControl()) 184 167 ->setLabel(pht('Text')) 185 - ->setValue(pht( 186 - 'Paste text can not be edited. %s to create a new paste.', 187 - $fork_link))); 188 - } 168 + ->setError($e_text) 169 + ->setValue($v_text) 170 + ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) 171 + ->setCustomClass('PhabricatorMonospaced') 172 + ->setName('text')); 189 173 190 174 $submit = new AphrontFormSubmitControl(); 191 175
+12 -8
src/applications/paste/editor/PhabricatorPasteEditor.php
··· 23 23 public function getTransactionTypes() { 24 24 $types = parent::getTransactionTypes(); 25 25 26 - $types[] = PhabricatorPasteTransaction::TYPE_CREATE; 26 + $types[] = PhabricatorPasteTransaction::TYPE_CONTENT; 27 27 $types[] = PhabricatorPasteTransaction::TYPE_TITLE; 28 28 $types[] = PhabricatorPasteTransaction::TYPE_LANGUAGE; 29 29 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; ··· 37 37 PhabricatorApplicationTransaction $xaction) { 38 38 39 39 switch ($xaction->getTransactionType()) { 40 - case PhabricatorPasteTransaction::TYPE_CREATE: 41 - return null; 40 + case PhabricatorPasteTransaction::TYPE_CONTENT: 41 + return $object->getFilePHID(); 42 42 case PhabricatorPasteTransaction::TYPE_TITLE: 43 43 return $object->getTitle(); 44 44 case PhabricatorPasteTransaction::TYPE_LANGUAGE: ··· 51 51 PhabricatorApplicationTransaction $xaction) { 52 52 53 53 switch ($xaction->getTransactionType()) { 54 - case PhabricatorPasteTransaction::TYPE_CREATE: 54 + case PhabricatorPasteTransaction::TYPE_CONTENT: 55 55 case PhabricatorPasteTransaction::TYPE_TITLE: 56 56 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 57 57 return $xaction->getNewValue(); ··· 63 63 PhabricatorApplicationTransaction $xaction) { 64 64 65 65 switch ($xaction->getTransactionType()) { 66 - case PhabricatorPasteTransaction::TYPE_CREATE: 66 + case PhabricatorPasteTransaction::TYPE_CONTENT: 67 67 $object->setFilePHID($xaction->getNewValue()); 68 68 return; 69 69 case PhabricatorPasteTransaction::TYPE_TITLE: ··· 72 72 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 73 73 $object->setLanguage($xaction->getNewValue()); 74 74 return; 75 + case PhabricatorTransactions::TYPE_VIEW_POLICY: 76 + $object->setViewPolicy($xaction->getNewValue()); 77 + return; 75 78 } 76 79 77 80 return parent::applyCustomInternalTransaction($object, $xaction); ··· 82 85 PhabricatorApplicationTransaction $xaction) { 83 86 84 87 switch ($xaction->getTransactionType()) { 85 - case PhabricatorPasteTransaction::TYPE_CREATE: 88 + case PhabricatorPasteTransaction::TYPE_CONTENT: 86 89 case PhabricatorPasteTransaction::TYPE_TITLE: 87 90 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 91 + case PhabricatorTransactions::TYPE_VIEW_POLICY: 88 92 return; 89 93 } 90 94 ··· 96 100 PhabricatorApplicationTransaction $xaction) { 97 101 98 102 switch ($xaction->getTransactionType()) { 99 - case PhabricatorPasteTransaction::TYPE_CREATE: 103 + case PhabricatorPasteTransaction::TYPE_CONTENT: 100 104 return array($xaction->getNewValue()); 101 105 } 102 106 ··· 108 112 array $xactions) { 109 113 foreach ($xactions as $xaction) { 110 114 switch ($xaction->getTransactionType()) { 111 - case PhabricatorPasteTransaction::TYPE_CREATE: 115 + case PhabricatorPasteTransaction::TYPE_CONTENT: 112 116 return false; 113 117 default: 114 118 break;
+1 -1
src/applications/paste/mail/PasteCreateMailReceiver.php
··· 44 44 $xactions = array(); 45 45 46 46 $xactions[] = id(new PhabricatorPasteTransaction()) 47 - ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE) 47 + ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT) 48 48 ->setNewValue($file->getPHID()); 49 49 50 50 $xactions[] = id(new PhabricatorPasteTransaction())
+7 -1
src/applications/paste/query/PhabricatorPasteQuery.php
··· 157 157 } 158 158 159 159 private function getContentCacheKey(PhabricatorPaste $paste) { 160 - return 'P'.$paste->getID().':content/'.$paste->getLanguage(); 160 + return implode( 161 + ':', 162 + array( 163 + 'P'.$paste->getID(), 164 + $paste->getFilePHID(), 165 + $paste->getLanguage(), 166 + )); 161 167 } 162 168 163 169 private function loadRawContent(array $pastes) {
+69 -15
src/applications/paste/storage/PhabricatorPasteTransaction.php
··· 3 3 final class PhabricatorPasteTransaction 4 4 extends PhabricatorApplicationTransaction { 5 5 6 - const TYPE_CREATE = 'paste.create'; 6 + const TYPE_CONTENT = 'paste.create'; 7 7 const TYPE_TITLE = 'paste.title'; 8 8 const TYPE_LANGUAGE = 'paste.language'; 9 9 ··· 23 23 $phids = parent::getRequiredHandlePHIDs(); 24 24 25 25 switch ($this->getTransactionType()) { 26 - case self::TYPE_CREATE: 26 + case self::TYPE_CONTENT: 27 27 $phids[] = $this->getObjectPHID(); 28 28 break; 29 29 } ··· 36 36 switch ($this->getTransactionType()) { 37 37 case self::TYPE_TITLE: 38 38 case self::TYPE_LANGUAGE: 39 - return $old === null; 39 + return ($old === null); 40 40 } 41 41 return parent::shouldHide(); 42 42 } 43 43 44 44 public function getIcon() { 45 45 switch ($this->getTransactionType()) { 46 - case self::TYPE_CREATE: 46 + case self::TYPE_CONTENT: 47 47 return 'fa-plus'; 48 48 break; 49 49 case self::TYPE_TITLE: ··· 63 63 64 64 $type = $this->getTransactionType(); 65 65 switch ($type) { 66 - case PhabricatorPasteTransaction::TYPE_CREATE: 67 - return pht( 68 - '%s created "%s".', 69 - $this->renderHandleLink($author_phid), 70 - $this->renderHandleLink($object_phid)); 66 + case PhabricatorPasteTransaction::TYPE_CONTENT: 67 + if ($old === null) { 68 + return pht( 69 + '%s created this paste.', 70 + $this->renderHandleLink($author_phid)); 71 + } else { 72 + return pht( 73 + '%s edited the content of this paste.', 74 + $this->renderHandleLink($author_phid)); 75 + } 71 76 break; 72 77 case PhabricatorPasteTransaction::TYPE_TITLE: 73 78 return pht( ··· 94 99 95 100 $type = $this->getTransactionType(); 96 101 switch ($type) { 97 - case PhabricatorPasteTransaction::TYPE_CREATE: 98 - return pht( 99 - '%s created %s.', 100 - $this->renderHandleLink($author_phid), 101 - $this->renderHandleLink($object_phid)); 102 + case PhabricatorPasteTransaction::TYPE_CONTENT: 103 + if ($old === null) { 104 + return pht( 105 + '%s created %s.', 106 + $this->renderHandleLink($author_phid), 107 + $this->renderHandleLink($object_phid)); 108 + } else { 109 + return pht( 110 + '%s edited %s.', 111 + $this->renderHandleLink($author_phid), 112 + $this->renderHandleLink($object_phid)); 113 + } 102 114 break; 103 115 case PhabricatorPasteTransaction::TYPE_TITLE: 104 116 return pht( ··· 122 134 $new = $this->getNewValue(); 123 135 124 136 switch ($this->getTransactionType()) { 125 - case PhabricatorPasteTransaction::TYPE_CREATE: 137 + case self::TYPE_CONTENT: 126 138 return PhabricatorTransactions::COLOR_GREEN; 127 139 } 128 140 129 141 return parent::getColor(); 130 142 } 143 + 144 + 145 + public function hasChangeDetails() { 146 + switch ($this->getTransactionType()) { 147 + case self::TYPE_CONTENT: 148 + return ($this->getOldValue() !== null); 149 + } 150 + 151 + return parent::hasChangeDetails(); 152 + } 153 + 154 + public function renderChangeDetails(PhabricatorUser $viewer) { 155 + switch ($this->getTransactionType()) { 156 + case self::TYPE_CONTENT: 157 + $old = $this->getOldValue(); 158 + $new = $this->getNewValue(); 159 + 160 + $files = id(new PhabricatorFileQuery()) 161 + ->setViewer($viewer) 162 + ->withPHIDs(array_filter(array($old, $new))) 163 + ->execute(); 164 + $files = mpull($files, null, 'getPHID'); 165 + 166 + $old_text = ''; 167 + if (idx($files, $old)) { 168 + $old_text = $files[$old]->loadFileData(); 169 + } 170 + 171 + $new_text = ''; 172 + if (idx($files, $new)) { 173 + $new_text = $files[$new]->loadFileData(); 174 + } 175 + 176 + return $this->renderTextCorpusChangeDetails( 177 + $viewer, 178 + $old_text, 179 + $new_text); 180 + } 181 + 182 + return parent::renderChangeDetails($viewer); 183 + } 184 + 131 185 }
+4 -1
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 822 822 break; 823 823 } 824 824 825 - return $this->renderTextCorpusChangeDetails(); 825 + return $this->renderTextCorpusChangeDetails( 826 + $viewer, 827 + $this->getOldValue(), 828 + $this->getNewValue()); 826 829 } 827 830 828 831 public function renderTextCorpusChangeDetails(