@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
2
fork

Configure Feed

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

at recaptime-dev/main 198 lines 5.1 kB view raw
1<?php 2 3abstract class PhabricatorApplicationTransactionComment 4 extends PhabricatorLiskDAO 5 implements 6 PhabricatorMarkupInterface, 7 PhabricatorPolicyInterface, 8 PhabricatorDestructibleInterface { 9 10 const MARKUP_FIELD_COMMENT = 'markup:comment'; 11 12 protected $transactionPHID; 13 protected $commentVersion; 14 protected $authorPHID; 15 protected $viewPolicy; 16 protected $editPolicy; 17 protected $content; 18 protected $contentSource; 19 protected $isDeleted = 0; 20 21 private $oldComment = self::ATTACHABLE; 22 23 abstract public function getApplicationTransactionObject(); 24 25 public function generatePHID() { 26 return PhabricatorPHID::generateNewPHID( 27 PhabricatorPHIDConstants::PHID_TYPE_XCMT); 28 } 29 30 protected function getConfiguration() { 31 return array( 32 self::CONFIG_AUX_PHID => true, 33 self::CONFIG_COLUMN_SCHEMA => array( 34 'transactionPHID' => 'phid?', 35 'commentVersion' => 'uint32', 36 'content' => 'text', 37 'contentSource' => 'text', 38 'isDeleted' => 'bool', 39 ), 40 self::CONFIG_KEY_SCHEMA => array( 41 'key_version' => array( 42 'columns' => array('transactionPHID', 'commentVersion'), 43 'unique' => true, 44 ), 45 ), 46 ) + parent::getConfiguration(); 47 } 48 49 public function getApplicationName() { 50 return $this->getApplicationTransactionObject()->getApplicationName(); 51 } 52 53 public function getTableName() { 54 $xaction = $this->getApplicationTransactionObject(); 55 return self::getTableNameFromTransaction($xaction); 56 } 57 58 public static function getTableNameFromTransaction( 59 PhabricatorApplicationTransaction $xaction) { 60 return $xaction->getTableName().'_comment'; 61 } 62 63 public function setContentSource(PhabricatorContentSource $content_source) { 64 $this->contentSource = $content_source->serialize(); 65 return $this; 66 } 67 68 public function setContentSourceFromRequest(AphrontRequest $request) { 69 return $this->setContentSource( 70 PhabricatorContentSource::newFromRequest($request)); 71 } 72 73 public function getContentSource() { 74 return PhabricatorContentSource::newFromSerialized($this->contentSource); 75 } 76 77 /** 78 * Whether the transaction removes the comment 79 * @return bool True if the transaction removes the comment 80 */ 81 public function getIsRemoved() { 82 return ($this->getIsDeleted() == 2); 83 } 84 85 public function setIsRemoved($removed) { 86 if ($removed) { 87 $this->setIsDeleted(2); 88 } else { 89 $this->setIsDeleted(0); 90 } 91 return $this; 92 } 93 94 public function attachOldComment( 95 PhabricatorApplicationTransactionComment $old_comment) { 96 $this->oldComment = $old_comment; 97 return $this; 98 } 99 100 public function getOldComment() { 101 return $this->assertAttached($this->oldComment); 102 } 103 104 public function hasOldComment() { 105 return ($this->oldComment !== self::ATTACHABLE); 106 } 107 108 public function getRawRemarkupURI() { 109 return urisprintf( 110 '/transactions/raw/%s/', 111 $this->getTransactionPHID()); 112 } 113 114 public function isEmptyComment() { 115 $content = $this->getContent(); 116 117 // The comment is empty if there's no content, or if the content only has 118 // whitespace. 119 if (!strlen(trim($content))) { 120 return true; 121 } 122 123 return false; 124 } 125 126/* -( PhabricatorMarkupInterface )----------------------------------------- */ 127 128 129 public function getMarkupFieldKey($field) { 130 return PhabricatorPHIDConstants::PHID_TYPE_XCMT.':'.$this->getPHID(); 131 } 132 133 134 public function newMarkupEngine($field) { 135 return PhabricatorMarkupEngine::getEngine(); 136 } 137 138 139 public function getMarkupText($field) { 140 return $this->getContent(); 141 } 142 143 144 public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 145 require_celerity_resource('phabricator-remarkup-css'); 146 return phutil_tag( 147 'div', 148 array( 149 'class' => 'phabricator-remarkup', 150 ), 151 $output); 152 } 153 154 155 public function shouldUseMarkupCache($field) { 156 return (bool)$this->getPHID(); 157 } 158 159/* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 160 161 162 public function getCapabilities() { 163 return array( 164 PhabricatorPolicyCapability::CAN_VIEW, 165 PhabricatorPolicyCapability::CAN_EDIT, 166 ); 167 } 168 169 public function getPolicy($capability) { 170 switch ($capability) { 171 case PhabricatorPolicyCapability::CAN_VIEW: 172 return $this->getViewPolicy(); 173 case PhabricatorPolicyCapability::CAN_EDIT: 174 return $this->getEditPolicy(); 175 } 176 } 177 178 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 179 return ($viewer->getPHID() == $this->getAuthorPHID()); 180 } 181 182 public function describeAutomaticCapability($capability) { 183 return pht( 184 'Comments are visible to users who can see the object which was '. 185 'commented on. Comments can be edited by their authors.'); 186 } 187 188 189/* -( PhabricatorDestructibleInterface )----------------------------------- */ 190 191 public function destroyObjectPermanently( 192 PhabricatorDestructionEngine $engine) { 193 $this->openTransaction(); 194 $this->delete(); 195 $this->saveTransaction(); 196 } 197 198}