diff --git a/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php b/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php index 23c825caf1..ff6564c95e 100644 --- a/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php +++ b/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php @@ -1,147 +1,143 @@ provider = $provider; return $this; } public function getProvider() { return $this->provider; } public function getApplicationName() { return 'auth'; } public function getApplicationTransactionType() { return PhabricatorPHIDConstants::PHID_TYPE_AUTH; } public function getApplicationTransactionCommentObject() { return null; } - public function getApplicationObjectTypeName() { - return pht('authentication provider'); - } - public function getIcon() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_ENABLE: if ($new) { return 'new'; } else { return 'delete'; } } return parent::getIcon(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_ENABLE: if ($new) { return 'green'; } else { return 'red'; } } return parent::getColor(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_ENABLE: if ($old === null) { return pht( '%s created this provider.', $this->renderHandleLink($author_phid)); } else if ($new) { return pht( '%s enabled this provider.', $this->renderHandleLink($author_phid)); } else { return pht( '%s disabled this provider.', $this->renderHandleLink($author_phid)); } break; case self::TYPE_REGISTRATION: if ($new) { return pht( '%s enabled registration.', $this->renderHandleLink($author_phid)); } else { return pht( '%s disabled registration.', $this->renderHandleLink($author_phid)); } break; case self::TYPE_LINK: if ($new) { return pht( '%s enabled accont linking.', $this->renderHandleLink($author_phid)); } else { return pht( '%s disabled account linking.', $this->renderHandleLink($author_phid)); } break; case self::TYPE_UNLINK: if ($new) { return pht( '%s enabled account unlinking.', $this->renderHandleLink($author_phid)); } else { return pht( '%s disabled account unlinking.', $this->renderHandleLink($author_phid)); } break; case self::TYPE_PROPERTY: $provider = $this->getProvider(); if ($provider) { $title = $provider->renderConfigPropertyTransactionTitle($this); if (strlen($title)) { return $title; } } return pht( '%s edited a property of this provider.', $this->renderHandleLink($author_phid)); break; } return parent::getTitle(); } } diff --git a/src/applications/config/storage/PhabricatorConfigTransaction.php b/src/applications/config/storage/PhabricatorConfigTransaction.php index ad03fb6b46..ebfd944252 100644 --- a/src/applications/config/storage/PhabricatorConfigTransaction.php +++ b/src/applications/config/storage/PhabricatorConfigTransaction.php @@ -1,126 +1,121 @@ getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_EDIT: // TODO: After T2213 show the actual values too; for now, we don't // have the tools to do it without making a bit of a mess of it. $old_del = idx($old, 'deleted'); $new_del = idx($new, 'deleted'); if ($old_del && !$new_del) { return pht( '%s created this configuration entry.', $this->renderHandleLink($author_phid)); } else if (!$old_del && $new_del) { return pht( '%s deleted this configuration entry.', $this->renderHandleLink($author_phid)); } else if ($old_del && $new_del) { // This is a bug. return pht( '%s deleted this configuration entry (again?).', $this->renderHandleLink($author_phid)); } else { return pht( '%s edited this configuration entry.', $this->renderHandleLink($author_phid)); } break; } return parent::getTitle(); } public function getIcon() { switch ($this->getTransactionType()) { case self::TYPE_EDIT: return 'edit'; } return parent::getIcon(); } public function hasChangeDetails() { switch ($this->getTransactionType()) { case self::TYPE_EDIT: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); if ($old['deleted']) { $old_text = ''; } else { $old_text = PhabricatorConfigJSON::prettyPrintJSON($old['value']); } if ($new['deleted']) { $new_text = ''; } else { $new_text = PhabricatorConfigJSON::prettyPrintJSON($new['value']); } $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText($old_text) ->setNewText($new_text); return $view->render(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_EDIT: $old_del = idx($old, 'deleted'); $new_del = idx($new, 'deleted'); if ($old_del && !$new_del) { return PhabricatorTransactions::COLOR_GREEN; } else if (!$old_del && $new_del) { return PhabricatorTransactions::COLOR_RED; } else { return PhabricatorTransactions::COLOR_BLUE; } break; } } } diff --git a/src/applications/conpherence/storage/ConpherenceTransaction.php b/src/applications/conpherence/storage/ConpherenceTransaction.php index 4d05ea7bf4..3853867b84 100644 --- a/src/applications/conpherence/storage/ConpherenceTransaction.php +++ b/src/applications/conpherence/storage/ConpherenceTransaction.php @@ -1,157 +1,153 @@ getTransactionType()) { case ConpherenceTransactionType::TYPE_PARTICIPANTS: return pht( 'You can not add a participant who has already been added.'); break; } return parent::getNoEffectDescription(); } public function shouldHide() { $old = $this->getOldValue(); switch ($this->getTransactionType()) { case ConpherenceTransactionType::TYPE_PARTICIPANTS: return ($old === null); case ConpherenceTransactionType::TYPE_TITLE: case ConpherenceTransactionType::TYPE_DATE_MARKER: return false; case ConpherenceTransactionType::TYPE_FILES: return true; // we used to have them so just always hide case ConpherenceTransactionType::TYPE_PICTURE: case ConpherenceTransactionType::TYPE_PICTURE_CROP: return true; } return parent::shouldHide(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case ConpherenceTransactionType::TYPE_TITLE: if ($old && $new) { $title = pht( '%s renamed this conpherence from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } else if ($old) { $title = pht( '%s deleted the conpherence name "%s".', $this->renderHandleLink($author_phid), $old); } else { $title = pht( '%s named this conpherence "%s".', $this->renderHandleLink($author_phid), $new); } return $title; case ConpherenceTransactionType::TYPE_FILES: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { $title = pht( '%s edited files(s), added %d and removed %d.', $this->renderHandleLink($author_phid), count($add), count($rem)); } else if ($add) { $title = pht( '%s added %d files(s).', $this->renderHandleLink($author_phid), count($add)); } else { $title = pht( '%s removed %d file(s).', $this->renderHandleLink($author_phid), count($rem)); } return $title; break; case ConpherenceTransactionType::TYPE_PARTICIPANTS: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { $title = pht( '%s edited participant(s), added %d: %s; removed %d: %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add), count($rem), $this->renderHandleList($rem)); } else if ($add) { $title = pht( '%s added %d participant(s): %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add)); } else { $title = pht( '%s removed %d participant(s): %s.', $this->renderHandleLink($author_phid), count($rem), $this->renderHandleList($rem)); } return $title; break; } return parent::getTitle(); } public function getRequiredHandlePHIDs() { $phids = parent::getRequiredHandlePHIDs(); $old = $this->getOldValue(); $new = $this->getNewValue(); $phids[] = $this->getAuthorPHID(); switch ($this->getTransactionType()) { case ConpherenceTransactionType::TYPE_TITLE: case ConpherenceTransactionType::TYPE_FILES: case ConpherenceTransactionType::TYPE_DATE_MARKER: break; case ConpherenceTransactionType::TYPE_PARTICIPANTS: $phids = array_merge($phids, $this->getOldValue()); $phids = array_merge($phids, $this->getNewValue()); break; } return $phids; } } diff --git a/src/applications/differential/storage/DifferentialTransaction.php b/src/applications/differential/storage/DifferentialTransaction.php index 738d61b9ba..745805e4a6 100644 --- a/src/applications/differential/storage/DifferentialTransaction.php +++ b/src/applications/differential/storage/DifferentialTransaction.php @@ -1,21 +1,17 @@ getOldValue(); switch ($this->getTransactionType()) { case LegalpadTransactionType::TYPE_TITLE: case LegalpadTransactionType::TYPE_TEXT: return ($old === null); } return parent::shouldHide(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); $type = $this->getTransactionType(); switch ($type) { case LegalpadTransactionType::TYPE_TITLE: return pht( '%s renamed this document from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); break; case LegalpadTransactionType::TYPE_TEXT: return pht( "%s updated the document's text.", $this->renderHandleLink($author_phid)); break; } return parent::getTitle(); } public function hasChangeDetails() { switch ($this->getTransactionType()) { case LegalpadTransactionType::TYPE_TITLE: case LegalpadTransactionType::TYPE_TEXT: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText($old) ->setNewText($new); return $view->render(); } } diff --git a/src/applications/macro/storage/PhabricatorMacroTransaction.php b/src/applications/macro/storage/PhabricatorMacroTransaction.php index bfac84cdd6..ab97055271 100644 --- a/src/applications/macro/storage/PhabricatorMacroTransaction.php +++ b/src/applications/macro/storage/PhabricatorMacroTransaction.php @@ -1,231 +1,227 @@ getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_FILE: if ($old !== null) { $phids[] = $old; } $phids[] = $new; break; } return $phids; } public function shouldHide() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_NAME: return ($old === null); } return parent::shouldHide(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_NAME: return pht( '%s renamed this macro from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); break; case PhabricatorMacroTransactionType::TYPE_DISABLED: if ($new) { return pht( '%s disabled this macro.', $this->renderHandleLink($author_phid)); } else { return pht( '%s restored this macro.', $this->renderHandleLink($author_phid)); } break; case PhabricatorMacroTransactionType::TYPE_FILE: if ($old === null) { return pht( '%s created this macro.', $this->renderHandleLink($author_phid)); } else { return pht( '%s changed the image for this macro from %s to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($old), $this->renderHandleLink($new)); } break; } return parent::getTitle(); } public function getTitleForFeed() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_NAME: return pht( '%s renamed %s from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $old, $new); case PhabricatorMacroTransactionType::TYPE_DISABLED: if ($new) { return pht( '%s disabled %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } else { return pht( '%s restored %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } case PhabricatorMacroTransactionType::TYPE_FILE: if ($old === null) { return pht( '%s created %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } else { return pht( '%s updated the image for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } } return parent::getTitleForFeed(); } public function getActionName() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_NAME: if ($old === null) { return pht('Created'); } else { return pht('Renamed'); } case PhabricatorMacroTransactionType::TYPE_DISABLED: if ($new) { return pht('Disabled'); } else { return pht('Restored'); } case PhabricatorMacroTransactionType::TYPE_FILE: if ($old === null) { return pht('Created'); } else { return pht('Edited Image'); } } return parent::getActionName(); } public function getActionStrength() { switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_DISABLED: return 2.0; case PhabricatorMacroTransactionType::TYPE_FILE: return 1.5; } return parent::getActionStrength(); } public function getIcon() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_NAME: return 'edit'; case PhabricatorMacroTransactionType::TYPE_FILE: if ($old === null) { return 'create'; } else { return 'edit'; } case PhabricatorMacroTransactionType::TYPE_DISABLED: if ($new) { return 'delete'; } else { return 'undo'; } } return parent::getIcon(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorMacroTransactionType::TYPE_NAME: return PhabricatorTransactions::COLOR_BLUE; case PhabricatorMacroTransactionType::TYPE_FILE: if ($old === null) { return PhabricatorTransactions::COLOR_GREEN; } else { return PhabricatorTransactions::COLOR_BLUE; } case PhabricatorMacroTransactionType::TYPE_DISABLED: if ($new) { return PhabricatorTransactions::COLOR_BLACK; } else { return PhabricatorTransactions::COLOR_SKY; } } return parent::getColor(); } } diff --git a/src/applications/paste/storage/PhabricatorPasteTransaction.php b/src/applications/paste/storage/PhabricatorPasteTransaction.php index 2a86ff16b3..05bcb00151 100644 --- a/src/applications/paste/storage/PhabricatorPasteTransaction.php +++ b/src/applications/paste/storage/PhabricatorPasteTransaction.php @@ -1,138 +1,134 @@ getTransactionType()) { case self::TYPE_CREATE: $phids[] = $this->getObjectPHID(); break; } return $phids; } public function shouldHide() { $old = $this->getOldValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: case self::TYPE_LANGUAGE: return $old === null; } return parent::shouldHide(); } public function getIcon() { switch ($this->getTransactionType()) { case self::TYPE_CREATE: return 'create'; break; case self::TYPE_TITLE: case self::TYPE_LANGUAGE: return 'edit'; break; } return parent::getIcon(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); $type = $this->getTransactionType(); switch ($type) { case PhabricatorPasteTransaction::TYPE_CREATE: return pht( '%s created "%s".', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PhabricatorPasteTransaction::TYPE_TITLE: return pht( '%s updated the paste\'s title to "%s".', $this->renderHandleLink($author_phid), $new); break; case PhabricatorPasteTransaction::TYPE_LANGUAGE: return pht( "%s updated the paste's language.", $this->renderHandleLink($author_phid)); break; } return parent::getTitle(); } public function getTitleForFeed() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); $type = $this->getTransactionType(); switch ($type) { case PhabricatorPasteTransaction::TYPE_CREATE: return pht( '%s created %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PhabricatorPasteTransaction::TYPE_TITLE: return pht( '%s updated the title for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PhabricatorPasteTransaction::TYPE_LANGUAGE: return pht( '%s update the language for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; } return parent::getTitleForFeed(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorPasteTransaction::TYPE_CREATE: return PhabricatorTransactions::COLOR_GREEN; } return parent::getColor(); } } diff --git a/src/applications/people/storage/PhabricatorUserTransaction.php b/src/applications/people/storage/PhabricatorUserTransaction.php index 50b8c5c36a..eb7e29929e 100644 --- a/src/applications/people/storage/PhabricatorUserTransaction.php +++ b/src/applications/people/storage/PhabricatorUserTransaction.php @@ -1,23 +1,19 @@ getAuthorPHID(); switch ($this->getTransactionType()) { case self::TYPE_EDIT_KEY: return pht( '%s created this variable.', $this->renderHandleLink($author_phid)); case self::TYPE_EDIT_VALUE: return pht( '%s updated this variable.', $this->renderHandleLink($author_phid)); } return parent::getTitle(); } public function hasChangeDetails() { switch ($this->getTransactionType()) { case self::TYPE_EDIT_VALUE: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText(json_encode($old)) ->setNewText(json_encode($new)); return $view->render(); } } diff --git a/src/applications/pholio/storage/PholioTransaction.php b/src/applications/pholio/storage/PholioTransaction.php index 9c6a3f5b56..9ddb4c4235 100644 --- a/src/applications/pholio/storage/PholioTransaction.php +++ b/src/applications/pholio/storage/PholioTransaction.php @@ -1,344 +1,340 @@ getObjectPHID(); $new = $this->getNewValue(); $old = $this->getOldValue(); switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_IMAGE_FILE: $phids = array_merge($phids, $new, $old); break; case PholioTransactionType::TYPE_IMAGE_REPLACE: $phids[] = $new; $phids[] = $old; break; case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: case PholioTransactionType::TYPE_IMAGE_NAME: case PholioTransactionType::TYPE_IMAGE_SEQUENCE: $phids[] = key($new); break; } return $phids; } public function shouldHide() { $old = $this->getOldValue(); switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_DESCRIPTION: return ($old === null); case PholioTransactionType::TYPE_IMAGE_NAME: case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: return ($old === array(null => null)); // this is boring / silly to surface; changing sequence is NBD case PholioTransactionType::TYPE_IMAGE_SEQUENCE: return true; } return parent::shouldHide(); } public function getIcon() { switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_INLINE: return 'comment'; case PholioTransactionType::TYPE_NAME: case PholioTransactionType::TYPE_DESCRIPTION: case PholioTransactionType::TYPE_IMAGE_NAME: case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: case PholioTransactionType::TYPE_IMAGE_SEQUENCE: return 'edit'; case PholioTransactionType::TYPE_IMAGE_FILE: case PholioTransactionType::TYPE_IMAGE_REPLACE: return 'attach'; } return parent::getIcon(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); $type = $this->getTransactionType(); switch ($type) { case PholioTransactionType::TYPE_NAME: if ($old === null) { return pht( '%s created "%s".', $this->renderHandleLink($author_phid), $new); } else { return pht( '%s renamed this mock from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } break; case PholioTransactionType::TYPE_DESCRIPTION: return pht( "%s updated the mock's description.", $this->renderHandleLink($author_phid)); break; case PholioTransactionType::TYPE_INLINE: $count = 1; foreach ($this->getTransactionGroup() as $xaction) { if ($xaction->getTransactionType() == $type) { $count++; } } return pht( '%s added %d inline comment(s).', $this->renderHandleLink($author_phid), $count); break; case PholioTransactionType::TYPE_IMAGE_REPLACE: return pht( '%s replaced %s with %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($old), $this->renderHandleLink($new)); break; case PholioTransactionType::TYPE_IMAGE_FILE: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { return pht( '%s edited image(s), added %d: %s; removed %d: %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add), count($rem), $this->renderHandleList($rem)); } else if ($add) { return pht( '%s added %d image(s): %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add)); } else { return pht( '%s removed %d image(s): %s.', $this->renderHandleLink($author_phid), count($rem), $this->renderHandleList($rem)); } break; case PholioTransactionType::TYPE_IMAGE_NAME: return pht( '%s renamed an image (%s) from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderHandleLink(key($new)), reset($old), reset($new)); break; case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: return pht( '%s updated an image\'s (%s) description.', $this->renderHandleLink($author_phid), $this->renderHandleLink(key($new))); break; case PholioTransactionType::TYPE_IMAGE_SEQUENCE: return pht( '%s updated an image\'s (%s) sequence.', $this->renderHandleLink($author_phid), $this->renderHandleLink(key($new))); break; } return parent::getTitle(); } public function getTitleForFeed() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); $type = $this->getTransactionType(); switch ($type) { case PholioTransactionType::TYPE_NAME: if ($old === null) { return pht( '%s created %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } else { return pht( '%s renamed %s from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $old, $new); } break; case PholioTransactionType::TYPE_DESCRIPTION: return pht( '%s updated the description for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PholioTransactionType::TYPE_INLINE: return pht( '%s added an inline comment to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PholioTransactionType::TYPE_IMAGE_REPLACE: case PholioTransactionType::TYPE_IMAGE_FILE: return pht( '%s updated images of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PholioTransactionType::TYPE_IMAGE_NAME: return pht( '%s updated the image names of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: return pht( '%s updated image descriptions of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; case PholioTransactionType::TYPE_IMAGE_SEQUENCE: return pht( '%s updated image sequence of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); break; } return parent::getTitleForFeed(); } public function getBodyForFeed(PhabricatorFeedStory $story) { $text = null; switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_NAME: if ($this->getOldValue() === null) { $mock = $story->getPrimaryObject(); $text = $mock->getDescription(); } break; case PholioTransactionType::TYPE_INLINE: $text = $this->getComment()->getContent(); break; } if ($text) { return phutil_escape_html_newlines( phutil_utf8_shorten($text, 128)); } return parent::getBodyForFeed($story); } public function hasChangeDetails() { switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_DESCRIPTION: case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); if ($this->getTransactionType() == PholioTransactionType::TYPE_IMAGE_DESCRIPTION) { $old = reset($old); $new = reset($new); } $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText($old) ->setNewText($new); return $view->render(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_NAME: if ($old === null) { return PhabricatorTransactions::COLOR_GREEN; } case PholioTransactionType::TYPE_DESCRIPTION: case PholioTransactionType::TYPE_IMAGE_NAME: case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: case PholioTransactionType::TYPE_IMAGE_SEQUENCE: return PhabricatorTransactions::COLOR_BLUE; case PholioTransactionType::TYPE_IMAGE_REPLACE: return PhabricatorTransactions::COLOR_YELLOW; case PholioTransactionType::TYPE_IMAGE_FILE: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { return PhabricatorTransactions::COLOR_YELLOW; } else if ($add) { return PhabricatorTransactions::COLOR_GREEN; } else { return PhabricatorTransactions::COLOR_RED; } } return parent::getColor(); } public function getNoEffectDescription() { switch ($this->getTransactionType()) { case PholioTransactionType::TYPE_IMAGE_NAME: return pht('The image title was not updated.'); case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: return pht('The image description was not updated.'); case PholioTransactionType::TYPE_IMAGE_SEQUENCE: return pht('The image sequence was not updated.'); } return parent::getNoEffectDescription(); } } diff --git a/src/applications/phortune/storage/PhortuneAccountTransaction.php b/src/applications/phortune/storage/PhortuneAccountTransaction.php index 770c504853..6cb0384089 100644 --- a/src/applications/phortune/storage/PhortuneAccountTransaction.php +++ b/src/applications/phortune/storage/PhortuneAccountTransaction.php @@ -1,74 +1,70 @@ getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_NAME: if ($old === null) { return pht( '%s created this account.', $this->renderHandleLink($author_phid)); } else { return pht( '%s renamed this account from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } break; case PhabricatorTransactions::TYPE_EDGE: switch ($this->getMetadataValue('edge:type')) { case PhabricatorEdgeConfig::TYPE_ACCOUNT_HAS_MEMBER: $add = array_diff(array_keys($new), array_keys($old)); $rem = array_diff(array_keys($old), array_keys($new)); if ($add && $rem) { return pht( '%s changed account members, added %s; removed %s.', $this->renderHandleLink($author_phid), $this->renderHandleList($add), $this->renderHandleList($rem)); } else if ($add) { return pht( '%s added account members: %s', $this->renderHandleLink($author_phid), $this->renderHandleList($add)); } else { return pht( '%s removed account members: %s', $this->renderHandleLink($author_phid), $this->renderHandleList($add)); } break; } break; } return parent::getTitle(); } } diff --git a/src/applications/phortune/storage/PhortuneProductTransaction.php b/src/applications/phortune/storage/PhortuneProductTransaction.php index 1a9e770d1e..246b2675a3 100644 --- a/src/applications/phortune/storage/PhortuneProductTransaction.php +++ b/src/applications/phortune/storage/PhortuneProductTransaction.php @@ -1,83 +1,79 @@ getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_NAME: if ($old === null) { return pht( '%s created this product.', $this->renderHandleLink($author_phid)); } else { return pht( '%s renamed this product from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } break; case self::TYPE_PRICE: if ($old === null) { return pht( '%s set product price to %s.', $this->renderHandleLink($author_phid), PhortuneCurrency::newFromUSDCents($new) ->formatForDisplay()); } else { return pht( '%s changed product price from %s to %s.', $this->renderHandleLink($author_phid), PhortuneCurrency::newFromUSDCents($old) ->formatForDisplay(), PhortuneCurrency::newFromUSDCents($new) ->formatForDisplay()); } break; case self::TYPE_TYPE: $map = PhortuneProduct::getTypeMap(); if ($old === null) { return pht( '%s set product type to "%s".', $this->renderHandleLink($author_phid), $map[$new]); } else { return pht( '%s changed product type from "%s" to "%s".', $this->renderHandleLink($author_phid), $map[$old], $map[$new]); } break; } return parent::getTitle(); } } diff --git a/src/applications/ponder/storage/PonderAnswerTransaction.php b/src/applications/ponder/storage/PonderAnswerTransaction.php index d29ec89821..d8a2ff4fd0 100644 --- a/src/applications/ponder/storage/PonderAnswerTransaction.php +++ b/src/applications/ponder/storage/PonderAnswerTransaction.php @@ -1,48 +1,44 @@ getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_CONTENT: // TODO: This is not so good. return pht( '%s edited their answer to %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } return $this->getTitle(); } } diff --git a/src/applications/ponder/storage/PonderQuestionTransaction.php b/src/applications/ponder/storage/PonderQuestionTransaction.php index 5bc1c9b16e..90f509ebaa 100644 --- a/src/applications/ponder/storage/PonderQuestionTransaction.php +++ b/src/applications/ponder/storage/PonderQuestionTransaction.php @@ -1,236 +1,232 @@ getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: if ($old === null) { return pht( '%s asked this question.', $this->renderHandleLink($author_phid)); } else { return pht( '%s edited the question title from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } case self::TYPE_CONTENT: return pht( '%s edited the question description.', $this->renderHandleLink($author_phid)); case self::TYPE_ANSWERS: // TODO: This could be richer. return pht( '%s added an answer.', $this->renderHandleLink($author_phid)); case self::TYPE_STATUS: switch ($new) { case PonderQuestionStatus::STATUS_OPEN: return pht( '%s reopened this question.', $this->renderHandleLink($author_phid)); case PonderQuestionStatus::STATUS_CLOSED: return pht( '%s closed this question.', $this->renderHandleLink($author_phid)); } } return parent::getTitle(); } public function getIcon() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: case self::TYPE_CONTENT: return 'edit'; case self::TYPE_STATUS: switch ($new) { case PonderQuestionStatus::STATUS_OPEN: return 'enable'; case PonderQuestionStatus::STATUS_CLOSED: return 'disable'; } case self::TYPE_ANSWERS: return 'new'; } return parent::getIcon(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: case self::TYPE_CONTENT: return PhabricatorTransactions::COLOR_BLUE; case self::TYPE_ANSWERS: return PhabricatorTransactions::COLOR_GREEN; case self::TYPE_STATUS: switch ($new) { case PonderQuestionStatus::STATUS_OPEN: return PhabricatorTransactions::COLOR_GREEN; case PonderQuestionStatus::STATUS_CLOSED: return PhabricatorTransactions::COLOR_BLACK; } } } public function hasChangeDetails() { switch ($this->getTransactionType()) { case self::TYPE_CONTENT: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText($old) ->setNewText($new); return $view->render(); } public function getActionStrength() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: if ($old === null) { return 3; } break; case self::TYPE_ANSWERS: return 2; } return parent::getActionStrength(); } public function getActionName() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: if ($old === null) { return pht('Asked'); } break; case self::TYPE_ANSWERS: return pht('Answered'); } return parent::getActionName(); } public function shouldHide() { switch ($this->getTransactionType()) { case self::TYPE_CONTENT: if ($this->getOldValue() === null) { return true; } else { return false; } break; } return parent::shouldHide(); } public function getTitleForFeed() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_TITLE: if ($old === null) { return pht( '%s asked a question: %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } else { return pht( '%s edited the title of %s (was "%s")', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid), $old); } case self::TYPE_CONTENT: return pht( '%s edited the description of %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case self::TYPE_ANSWERS: // TODO: This could be richer, too. return pht( '%s answered %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case self::TYPE_STATUS: switch ($new) { case PonderQuestionStatus::STATUS_OPEN: return pht( '%s reopened %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case PonderQuestionStatus::STATUS_CLOSED: return pht( '%s closed %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } } return $this->getTitle(); } } diff --git a/src/applications/releeph/storage/ReleephBranchTransaction.php b/src/applications/releeph/storage/ReleephBranchTransaction.php index 94c4812722..d9805aff88 100644 --- a/src/applications/releeph/storage/ReleephBranchTransaction.php +++ b/src/applications/releeph/storage/ReleephBranchTransaction.php @@ -1,19 +1,15 @@ getTransactionType()) { default; break; } return parent::hasChangeDetails(); } public function getRequiredHandlePHIDs() { $phids = parent::getRequiredHandlePHIDs(); $phids[] = $this->getObjectPHID(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case ReleephRequestTransaction::TYPE_REQUEST: case ReleephRequestTransaction::TYPE_DISCOVERY: $phids[] = $new; break; case ReleephRequestTransaction::TYPE_EDIT_FIELD: self::searchForPHIDs($this->getOldValue(), $phids); self::searchForPHIDs($this->getNewValue(), $phids); break; } return $phids; } public function getTitle() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case ReleephRequestTransaction::TYPE_REQUEST: return pht( '%s requested %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($new)); break; case ReleephRequestTransaction::TYPE_USER_INTENT: return $this->getIntentTitle(); break; case ReleephRequestTransaction::TYPE_EDIT_FIELD: $field = newv($this->getMetadataValue('fieldClass'), array()); $name = $field->getName(); $markup = $name; if ($this->getRenderingTarget() === PhabricatorApplicationTransaction::TARGET_HTML) { $markup = hsprintf('%s', $name); } return pht( '%s changed the %s to "%s"', $this->renderHandleLink($author_phid), $markup, $field->normalizeForTransactionView($this, $new)); break; case ReleephRequestTransaction::TYPE_PICK_STATUS: switch ($new) { case ReleephRequest::PICK_OK: return pht('%s found this request picks without error', $this->renderHandleLink($author_phid)); case ReleephRequest::REVERT_OK: return pht('%s found this request reverts without error', $this->renderHandleLink($author_phid)); case ReleephRequest::PICK_FAILED: return pht("%s couldn't pick this request", $this->renderHandleLink($author_phid)); case ReleephRequest::REVERT_FAILED: return pht("%s couldn't revert this request", $this->renderHandleLink($author_phid)); } break; case ReleephRequestTransaction::TYPE_COMMIT: $action_type = $this->getMetadataValue('action'); switch ($action_type) { case 'pick': return pht( '%s picked this request and committed the result upstream', $this->renderHandleLink($author_phid)); break; case 'revert': return pht( '%s reverted this request and committed the result upstream', $this->renderHandleLink($author_phid)); break; } break; case ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH: $action = $new ? pht('picked') : pht('reverted'); return pht( '%s marked this request as manually %s', $this->renderHandleLink($author_phid), $action); break; case ReleephRequestTransaction::TYPE_DISCOVERY: return pht('%s discovered this commit as %s', $this->renderHandleLink($author_phid), $this->renderHandleLink($new)); break; default: return parent::getTitle(); break; } } public function getActionStrength() { return parent::getActionStrength(); } public function getActionName() { switch ($this->getTransactionType()) { case self::TYPE_REQUEST: return pht('Requested'); case self::TYPE_COMMIT: $action_type = $this->getMetadataValue('action'); switch ($action_type) { case 'pick': return pht('Picked'); case 'revert': return pht('Reverted'); } } return parent::getActionName(); } public function getColor() { $new = $this->getNewValue(); switch ($this->getTransactionType()) { case ReleephRequestTransaction::TYPE_USER_INTENT: switch ($new) { case ReleephRequest::INTENT_WANT: return PhabricatorTransactions::COLOR_GREEN; case ReleephRequest::INTENT_PASS: return PhabricatorTransactions::COLOR_RED; } } return parent::getColor(); } private static function searchForPHIDs($thing, array &$phids) { /** * To implement something like getRequiredHandlePHIDs() in a * ReleephFieldSpecification, we'd have to provide the field with its * ReleephRequest (so that it could load the PHIDs from the * ReleephRequest's storage, and return them.) * * We don't have fields initialized with their ReleephRequests, but we can * make a good guess at what handles will be needed for rendering the field * in this transaction by inspecting the old and new values. */ if (!is_array($thing)) { $thing = array($thing); } foreach ($thing as $value) { if (phid_get_type($value) !== PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { $phids[] = $value; } } } private function getIntentTitle() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $new = $this->getNewValue(); $is_pusher = $this->getMetadataValue('isPusher'); switch ($new) { case ReleephRequest::INTENT_WANT: if ($is_pusher) { return pht( '%s approved this request', $this->renderHandleLink($author_phid)); } else { return pht( '%s wanted this request', $this->renderHandleLink($author_phid)); } case ReleephRequest::INTENT_PASS: if ($is_pusher) { return pht( '%s rejected this request', $this->renderHandleLink($author_phid)); } else { return pht( '%s passed on this request', $this->renderHandleLink($author_phid)); } } } public function shouldHide() { $type = $this->getTransactionType(); if ($type === ReleephRequestTransaction::TYPE_USER_INTENT && $this->getMetadataValue('isRQCreate')) { return true; } if ($this->isBoringPickStatus()) { return true; } // ReleephSummaryFieldSpecification is usually blank when an RQ is created, // creating a transaction change from null to "". Hide these! if ($type === ReleephRequestTransaction::TYPE_EDIT_FIELD) { if ($this->getOldValue() === null && $this->getNewValue() === "") { return true; } } return parent::shouldHide(); } public function isBoringPickStatus() { $type = $this->getTransactionType(); if ($type === ReleephRequestTransaction::TYPE_PICK_STATUS) { $new = $this->getNewValue(); if ($new === ReleephRequest::PICK_OK || $new === ReleephRequest::REVERT_OK) { return true; } } return false; } } diff --git a/src/applications/repository/storage/PhabricatorRepositoryTransaction.php b/src/applications/repository/storage/PhabricatorRepositoryTransaction.php index 24d99c168c..e2ea5bd3bf 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryTransaction.php +++ b/src/applications/repository/storage/PhabricatorRepositoryTransaction.php @@ -1,88 +1,84 @@ getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case self::TYPE_NAME: return pht( '%s renamed this repository from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); case self::TYPE_DESCRIPTION: return pht( '%s updated the description of this repository.', $this->renderHandleLink($author_phid)); case self::TYPE_ENCODING: if (strlen($old) && !strlen($new)) { return pht( '%s removed the "%s" encoding configured for this repository.', $this->renderHandleLink($author_phid), $old); } else if (strlen($new) && !strlen($old)) { return pht( '%s set the encoding for this repository to "%s".', $this->renderHandleLink($author_phid), $new); } else { return pht( '%s changed the repository encoding from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } } return parent::getTitle(); } public function hasChangeDetails() { switch ($this->getTransactionType()) { case self::TYPE_DESCRIPTION: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText($old) ->setNewText($new); return $view->render(); } } diff --git a/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php b/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php index ec9f090f69..bdd04c8540 100644 --- a/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php @@ -1,139 +1,135 @@ getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: return ($old === null); } return parent::shouldHide(); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorSlowvoteTransaction::TYPE_QUESTION: if ($old === null) { return pht( '%s created this poll.', $this->renderHandleLink($author_phid)); } else { return pht( '%s changed the poll question from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } break; case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: return pht( '%s updated the description for this poll.', $this->renderHandleLink($author_phid)); case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: // TODO: This could be more detailed return pht( '%s changed who can see the responses.', $this->renderHandleLink($author_phid)); case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: if ($new) { return pht( '%s made poll responses appear in a random order.', $this->renderHandleLink($author_phid)); } else { return pht( '%s made poll responses appear in a fixed order.', $this->renderHandleLink($author_phid)); } break; } return parent::getTitle(); } public function getIcon() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorSlowvoteTransaction::TYPE_QUESTION: case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: return 'edit'; } return parent::getIcon(); } public function getColor() { $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorSlowvoteTransaction::TYPE_QUESTION: case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: return PhabricatorTransactions::COLOR_BLUE; } return parent::getColor(); } public function hasChangeDetails() { switch ($this->getTransactionType()) { case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: return true; } return parent::hasChangeDetails(); } public function renderChangeDetails(PhabricatorUser $viewer) { $old = $this->getOldValue(); $new = $this->getNewValue(); $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) ->setUser($viewer) ->setOldText($old) ->setNewText($new); return $view->render(); } } diff --git a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php index b9e348c0b5..f90d24bd94 100644 --- a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php +++ b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php @@ -1,473 +1,483 @@ getApplicationTransactionType()); + if ($type) { + return $type->getTypeName(); + } + + return pht('Object'); + } public function getApplicationTransactionCommentObject() { throw new Exception("Not implemented!"); } public function getApplicationTransactionViewObject() { return new PhabricatorApplicationTransactionView(); } public function getMetadataValue($key, $default = null) { return idx($this->metadata, $key, $default); } public function setMetadataValue($key, $value) { $this->metadata[$key] = $value; return $this; } public function generatePHID() { $type = PhabricatorApplicationTransactionPHIDTypeTransaction::TYPECONST; $subtype = $this->getApplicationTransactionType(); return PhabricatorPHID::generateNewPHID($type, $subtype); } public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'oldValue' => self::SERIALIZATION_JSON, 'newValue' => self::SERIALIZATION_JSON, 'metadata' => self::SERIALIZATION_JSON, ), ) + parent::getConfiguration(); } public function setContentSource(PhabricatorContentSource $content_source) { $this->contentSource = $content_source->serialize(); return $this; } public function getContentSource() { return PhabricatorContentSource::newFromSerialized($this->contentSource); } public function hasComment() { return $this->getComment() && strlen($this->getComment()->getContent()); } public function getComment() { if ($this->commentNotLoaded) { throw new Exception("Comment for this transaction was not loaded."); } return $this->comment; } public function attachComment( PhabricatorApplicationTransactionComment $comment) { $this->comment = $comment; $this->commentNotLoaded = false; return $this; } public function setCommentNotLoaded($not_loaded) { $this->commentNotLoaded = $not_loaded; return $this; } /* -( Rendering )---------------------------------------------------------- */ public function setRenderingTarget($rendering_target) { $this->renderingTarget = $rendering_target; return $this; } public function getRenderingTarget() { return $this->renderingTarget; } public function getRequiredHandlePHIDs() { $phids = array(); $old = $this->getOldValue(); $new = $this->getNewValue(); $phids[] = array($this->getAuthorPHID()); switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_SUBSCRIBERS: $phids[] = $old; $phids[] = $new; break; case PhabricatorTransactions::TYPE_EDGE: $phids[] = ipull($old, 'dst'); $phids[] = ipull($new, 'dst'); break; case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_VIEW_POLICY: if (!PhabricatorPolicyQuery::isGlobalPolicy($old)) { $phids[] = array($old); } if (!PhabricatorPolicyQuery::isGlobalPolicy($new)) { $phids[] = array($new); } break; } return array_mergev($phids); } public function setHandles(array $handles) { $this->handles = $handles; return $this; } public function getHandle($phid) { if (empty($this->handles[$phid])) { throw new Exception( "Transaction requires a handle ('{$phid}') it did not load."); } return $this->handles[$phid]; } public function getHandleIfExists($phid) { return idx($this->handles, $phid); } public function getHandles() { if ($this->handles === null) { throw new Exception( 'Transaction requires handles and it did not load them.' ); } return $this->handles; } public function renderHandleLink($phid) { if ($this->renderingTarget == self::TARGET_HTML) { return $this->getHandle($phid)->renderLink(); } else { return hsprintf('%s', $this->getHandle($phid)->getName()); } } public function renderHandleList(array $phids) { $links = array(); foreach ($phids as $phid) { $links[] = $this->renderHandleLink($phid); } return phutil_implode_html(', ', $links); } public function getIcon() { switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: return 'comment'; case PhabricatorTransactions::TYPE_SUBSCRIBERS: return 'message'; case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: return 'lock'; case PhabricatorTransactions::TYPE_EDGE: return 'link'; } return null; } public function getColor() { return null; } public function shouldHide() { switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: if ($this->getOldValue() === null) { return true; } else { return false; } break; } return false; } public function shouldHideForMail() { return $this->shouldHide(); } public function getNoEffectDescription() { switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: return pht('You can not post an empty comment.'); case PhabricatorTransactions::TYPE_VIEW_POLICY: return pht( 'This %s already has that view policy.', $this->getApplicationObjectTypeName()); case PhabricatorTransactions::TYPE_EDIT_POLICY: return pht( 'This %s already has that edit policy.', $this->getApplicationObjectTypeName()); case PhabricatorTransactions::TYPE_SUBSCRIBERS: return pht( 'All users are already subscribed to this %s.', $this->getApplicationObjectTypeName()); case PhabricatorTransactions::TYPE_EDGE: return pht('Edges already exist; transaction has no effect.'); } return pht('Transaction has no effect.'); } public function getTitle() { $author_phid = $this->getAuthorPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: return pht( '%s added a comment.', $this->renderHandleLink($author_phid)); case PhabricatorTransactions::TYPE_VIEW_POLICY: return pht( '%s changed the visibility of this %s from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->getApplicationObjectTypeName(), PhabricatorPolicy::newFromPolicyAndHandle( $old, $this->getHandleIfExists($old))->renderDescription(), PhabricatorPolicy::newFromPolicyAndHandle( $new, $this->getHandleIfExists($new))->renderDescription()); case PhabricatorTransactions::TYPE_EDIT_POLICY: return pht( '%s changed the edit policy of this %s from "%s" to "%s".', $this->renderHandleLink($author_phid), $this->getApplicationObjectTypeName(), PhabricatorPolicy::newFromPolicyAndHandle( $old, $this->getHandleIfExists($old))->renderDescription(), PhabricatorPolicy::newFromPolicyAndHandle( $new, $this->getHandleIfExists($new))->renderDescription()); case PhabricatorTransactions::TYPE_SUBSCRIBERS: $add = array_diff($new, $old); $rem = array_diff($old, $new); if ($add && $rem) { return pht( '%s edited subscriber(s), added %d: %s; removed %d: %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add), count($rem), $this->renderHandleList($rem)); } else if ($add) { return pht( '%s added %d subscriber(s): %s.', $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add)); } else { return pht( '%s removed %d subscriber(s): %s.', $this->renderHandleLink($author_phid), count($rem), $this->renderHandleList($rem)); } break; case PhabricatorTransactions::TYPE_EDGE: $new = ipull($new, 'dst'); $old = ipull($old, 'dst'); $add = array_diff($new, $old); $rem = array_diff($old, $new); $type = $this->getMetadata('edge:type'); $type = head($type); if ($add && $rem) { $string = PhabricatorEdgeConfig::getEditStringForEdgeType($type); return pht( $string, $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add), count($rem), $this->renderHandleList($rem)); } else if ($add) { $string = PhabricatorEdgeConfig::getAddStringForEdgeType($type); return pht( $string, $this->renderHandleLink($author_phid), count($add), $this->renderHandleList($add)); } else { $string = PhabricatorEdgeConfig::getRemoveStringForEdgeType($type); return pht( $string, $this->renderHandleLink($author_phid), count($rem), $this->renderHandleList($rem)); } default: return pht( '%s edited this %s.', $this->renderHandleLink($author_phid), $this->getApplicationObjectTypeName()); } } public function getTitleForFeed() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: return pht( '%s added a comment to %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case PhabricatorTransactions::TYPE_VIEW_POLICY: return pht( '%s changed the visibility for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case PhabricatorTransactions::TYPE_EDIT_POLICY: return pht( '%s changed the edit policy for %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case PhabricatorTransactions::TYPE_SUBSCRIBERS: return pht( '%s updated subscribers of %s.', $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); case PhabricatorTransactions::TYPE_EDGE: $type = $this->getMetadata('edge:type'); $type = head($type); $string = PhabricatorEdgeConfig::getFeedStringForEdgeType($type); return pht( $string, $this->renderHandleLink($author_phid), $this->renderHandleLink($object_phid)); } return $this->getTitle(); } public function getBodyForFeed(PhabricatorFeedStory $story) { $old = $this->getOldValue(); $new = $this->getNewValue(); $body = null; switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: $text = $this->getComment()->getContent(); $body = phutil_escape_html_newlines( phutil_utf8_shorten($text, 128)); break; } return $body; } public function getActionStrength() { switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: return 0.5; } return 1.0; } public function getActionName() { switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: return pht('Commented On'); case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: return pht('Changed Policy'); case PhabricatorTransactions::TYPE_SUBSCRIBERS: return pht('Changed Subscribers'); default: return pht('Updated'); } } public function getMailTags() { return array(); } public function hasChangeDetails() { return false; } public function renderChangeDetails(PhabricatorUser $viewer) { return null; } public function attachTransactionGroup(array $group) { assert_instances_of($group, 'PhabricatorApplicationTransaction'); $this->transactionGroup = $group; return $this; } public function getTransactionGroup() { return $this->transactionGroup; } /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return $this->getViewPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: return $this->getEditPolicy(); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return ($viewer->getPHID() == $this->getAuthorPHID()); } }