[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorPasteTransaction 4 extends PhabricatorApplicationTransaction { 5 6 const TYPE_CONTENT = 'paste.create'; 7 const TYPE_TITLE = 'paste.title'; 8 const TYPE_LANGUAGE = 'paste.language'; 9 10 public function getApplicationName() { 11 return 'pastebin'; 12 } 13 14 public function getApplicationTransactionType() { 15 return PhabricatorPastePastePHIDType::TYPECONST; 16 } 17 18 public function getApplicationTransactionCommentObject() { 19 return new PhabricatorPasteTransactionComment(); 20 } 21 22 public function getRequiredHandlePHIDs() { 23 $phids = parent::getRequiredHandlePHIDs(); 24 25 switch ($this->getTransactionType()) { 26 case self::TYPE_CONTENT: 27 $phids[] = $this->getObjectPHID(); 28 break; 29 } 30 31 return $phids; 32 } 33 34 public function shouldHide() { 35 $old = $this->getOldValue(); 36 switch ($this->getTransactionType()) { 37 case self::TYPE_TITLE: 38 case self::TYPE_LANGUAGE: 39 return ($old === null); 40 } 41 return parent::shouldHide(); 42 } 43 44 public function getIcon() { 45 switch ($this->getTransactionType()) { 46 case self::TYPE_CONTENT: 47 return 'fa-plus'; 48 break; 49 case self::TYPE_TITLE: 50 case self::TYPE_LANGUAGE: 51 return 'fa-pencil'; 52 break; 53 } 54 return parent::getIcon(); 55 } 56 57 public function getTitle() { 58 $author_phid = $this->getAuthorPHID(); 59 $object_phid = $this->getObjectPHID(); 60 61 $old = $this->getOldValue(); 62 $new = $this->getNewValue(); 63 64 $type = $this->getTransactionType(); 65 switch ($type) { 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 } 76 break; 77 case PhabricatorPasteTransaction::TYPE_TITLE: 78 return pht( 79 '%s updated the paste\'s title to "%s".', 80 $this->renderHandleLink($author_phid), 81 $new); 82 break; 83 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 84 return pht( 85 "%s updated the paste's language.", 86 $this->renderHandleLink($author_phid)); 87 break; 88 } 89 90 return parent::getTitle(); 91 } 92 93 public function getTitleForFeed(PhabricatorFeedStory $story) { 94 $author_phid = $this->getAuthorPHID(); 95 $object_phid = $this->getObjectPHID(); 96 97 $old = $this->getOldValue(); 98 $new = $this->getNewValue(); 99 100 $type = $this->getTransactionType(); 101 switch ($type) { 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 } 114 break; 115 case PhabricatorPasteTransaction::TYPE_TITLE: 116 return pht( 117 '%s updated the title for %s.', 118 $this->renderHandleLink($author_phid), 119 $this->renderHandleLink($object_phid)); 120 break; 121 case PhabricatorPasteTransaction::TYPE_LANGUAGE: 122 return pht( 123 '%s update the language for %s.', 124 $this->renderHandleLink($author_phid), 125 $this->renderHandleLink($object_phid)); 126 break; 127 } 128 129 return parent::getTitleForFeed($story); 130 } 131 132 public function getColor() { 133 $old = $this->getOldValue(); 134 $new = $this->getNewValue(); 135 136 switch ($this->getTransactionType()) { 137 case self::TYPE_CONTENT: 138 return PhabricatorTransactions::COLOR_GREEN; 139 } 140 141 return parent::getColor(); 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 185 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |