Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15283965
D8970.id21288.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Referenced Files
None
Subscribers
None
D8970.id21288.diff
View Options
diff --git a/resources/sql/patches/20130801.pastexactions.php b/resources/sql/patches/20130801.pastexactions.php
--- a/resources/sql/patches/20130801.pastexactions.php
+++ b/resources/sql/patches/20130801.pastexactions.php
@@ -30,7 +30,7 @@
$row['phid'],
'public',
$row['authorPHID'],
- PhabricatorPasteTransaction::TYPE_CREATE,
+ PhabricatorPasteTransaction::TYPE_CONTENT,
'null',
$row['filePHID'],
PhabricatorContentSource::newForSource(
diff --git a/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php b/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
--- a/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
+++ b/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
@@ -51,7 +51,7 @@
$xactions = array();
$xactions[] = id(new PhabricatorPasteTransaction())
- ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE)
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
->setNewValue($file->getPHID());
$xactions[] = id(new PhabricatorPasteTransaction())
diff --git a/src/applications/paste/controller/PhabricatorPasteEditController.php b/src/applications/paste/controller/PhabricatorPasteEditController.php
--- a/src/applications/paste/controller/PhabricatorPasteEditController.php
+++ b/src/applications/paste/controller/PhabricatorPasteEditController.php
@@ -42,6 +42,7 @@
}
$paste->setAuthorPHID($user->getPHID());
+ $paste->attachRawContent('');
} else {
$is_create = false;
@@ -53,6 +54,7 @@
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($this->id))
+ ->needRawContent(true)
->executeOne();
if (!$paste) {
return new Aphront404Response();
@@ -69,22 +71,20 @@
} else {
$v_title = $paste->getTitle();
$v_language = $paste->getLanguage();
- $v_text = '';
+ $v_text = $paste->getRawContent();
}
$v_policy = $paste->getViewPolicy();
if ($request->isFormPost()) {
$xactions = array();
- if ($is_create) {
- $v_text = $request->getStr('text');
- if (!strlen($v_text)) {
- $e_text = pht('Required');
- $errors[] = pht('The paste may not be blank.');
- } else {
- $e_text = null;
- }
- }
+ $v_text = $request->getStr('text');
+ if (!strlen($v_text)) {
+ $e_text = pht('Required');
+ $errors[] = pht('The paste may not be blank.');
+ } else {
+ $e_text = null;
+ }
$v_title = $request->getStr('title');
$v_language = $request->getStr('language');
@@ -94,14 +94,14 @@
// so it's impossible for them to choose an invalid policy.
if (!$errors) {
- if ($is_create) {
+ if ($is_create || ($v_text !== $paste->getRawContent())) {
$file = PhabricatorPasteEditor::initializeFileForPaste(
$user,
$v_title,
$v_text);
$xactions[] = id(new PhabricatorPasteTransaction())
- ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE)
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
->setNewValue($file->getPHID());
}
@@ -161,31 +161,15 @@
->setPolicies($policies)
->setName('can_view'));
- if ($is_create) {
- $form
- ->appendChild(
- id(new AphrontFormTextAreaControl())
- ->setLabel(pht('Text'))
- ->setError($e_text)
- ->setValue($v_text)
- ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
- ->setCustomClass('PhabricatorMonospaced')
- ->setName('text'));
- } else {
- $fork_link = phutil_tag(
- 'a',
- array(
- 'href' => $this->getApplicationURI('?parent='.$paste->getID())
- ),
- pht('Fork'));
- $form
- ->appendChild(
- id(new AphrontFormMarkupControl())
+ $form
+ ->appendChild(
+ id(new AphrontFormTextAreaControl())
->setLabel(pht('Text'))
- ->setValue(pht(
- 'Paste text can not be edited. %s to create a new paste.',
- $fork_link)));
- }
+ ->setError($e_text)
+ ->setValue($v_text)
+ ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
+ ->setCustomClass('PhabricatorMonospaced')
+ ->setName('text'));
$submit = new AphrontFormSubmitControl();
diff --git a/src/applications/paste/editor/PhabricatorPasteEditor.php b/src/applications/paste/editor/PhabricatorPasteEditor.php
--- a/src/applications/paste/editor/PhabricatorPasteEditor.php
+++ b/src/applications/paste/editor/PhabricatorPasteEditor.php
@@ -23,7 +23,7 @@
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
- $types[] = PhabricatorPasteTransaction::TYPE_CREATE;
+ $types[] = PhabricatorPasteTransaction::TYPE_CONTENT;
$types[] = PhabricatorPasteTransaction::TYPE_TITLE;
$types[] = PhabricatorPasteTransaction::TYPE_LANGUAGE;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
@@ -37,8 +37,8 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
- return null;
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
+ return $object->getFilePHID();
case PhabricatorPasteTransaction::TYPE_TITLE:
return $object->getTitle();
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
@@ -51,7 +51,7 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
case PhabricatorPasteTransaction::TYPE_TITLE:
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
return $xaction->getNewValue();
@@ -63,7 +63,7 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
$object->setFilePHID($xaction->getNewValue());
return;
case PhabricatorPasteTransaction::TYPE_TITLE:
@@ -72,6 +72,9 @@
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
$object->setLanguage($xaction->getNewValue());
return;
+ case PhabricatorTransactions::TYPE_VIEW_POLICY:
+ $object->setViewPolicy($xaction->getNewValue());
+ return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
@@ -82,9 +85,10 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
case PhabricatorPasteTransaction::TYPE_TITLE:
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
+ case PhabricatorTransactions::TYPE_VIEW_POLICY:
return;
}
@@ -96,7 +100,7 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
return array($xaction->getNewValue());
}
@@ -108,7 +112,7 @@
array $xactions) {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
return false;
default:
break;
diff --git a/src/applications/paste/mail/PasteCreateMailReceiver.php b/src/applications/paste/mail/PasteCreateMailReceiver.php
--- a/src/applications/paste/mail/PasteCreateMailReceiver.php
+++ b/src/applications/paste/mail/PasteCreateMailReceiver.php
@@ -44,7 +44,7 @@
$xactions = array();
$xactions[] = id(new PhabricatorPasteTransaction())
- ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE)
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
->setNewValue($file->getPHID());
$xactions[] = id(new PhabricatorPasteTransaction())
diff --git a/src/applications/paste/query/PhabricatorPasteQuery.php b/src/applications/paste/query/PhabricatorPasteQuery.php
--- a/src/applications/paste/query/PhabricatorPasteQuery.php
+++ b/src/applications/paste/query/PhabricatorPasteQuery.php
@@ -157,7 +157,13 @@
}
private function getContentCacheKey(PhabricatorPaste $paste) {
- return 'P'.$paste->getID().':content/'.$paste->getLanguage();
+ return implode(
+ ':',
+ array(
+ 'P'.$paste->getID(),
+ $paste->getFilePHID(),
+ $paste->getLanguage(),
+ ));
}
private function loadRawContent(array $pastes) {
diff --git a/src/applications/paste/storage/PhabricatorPasteTransaction.php b/src/applications/paste/storage/PhabricatorPasteTransaction.php
--- a/src/applications/paste/storage/PhabricatorPasteTransaction.php
+++ b/src/applications/paste/storage/PhabricatorPasteTransaction.php
@@ -3,7 +3,7 @@
final class PhabricatorPasteTransaction
extends PhabricatorApplicationTransaction {
- const TYPE_CREATE = 'paste.create';
+ const TYPE_CONTENT = 'paste.create';
const TYPE_TITLE = 'paste.title';
const TYPE_LANGUAGE = 'paste.language';
@@ -23,7 +23,7 @@
$phids = parent::getRequiredHandlePHIDs();
switch ($this->getTransactionType()) {
- case self::TYPE_CREATE:
+ case self::TYPE_CONTENT:
$phids[] = $this->getObjectPHID();
break;
}
@@ -36,14 +36,14 @@
switch ($this->getTransactionType()) {
case self::TYPE_TITLE:
case self::TYPE_LANGUAGE:
- return $old === null;
+ return ($old === null);
}
return parent::shouldHide();
}
public function getIcon() {
switch ($this->getTransactionType()) {
- case self::TYPE_CREATE:
+ case self::TYPE_CONTENT:
return 'fa-plus';
break;
case self::TYPE_TITLE:
@@ -63,11 +63,16 @@
$type = $this->getTransactionType();
switch ($type) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
- return pht(
- '%s created "%s".',
- $this->renderHandleLink($author_phid),
- $this->renderHandleLink($object_phid));
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
+ if ($old === null) {
+ return pht(
+ '%s created this paste.',
+ $this->renderHandleLink($author_phid));
+ } else {
+ return pht(
+ '%s edited the content of this paste.',
+ $this->renderHandleLink($author_phid));
+ }
break;
case PhabricatorPasteTransaction::TYPE_TITLE:
return pht(
@@ -94,11 +99,18 @@
$type = $this->getTransactionType();
switch ($type) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
- return pht(
- '%s created %s.',
- $this->renderHandleLink($author_phid),
- $this->renderHandleLink($object_phid));
+ case PhabricatorPasteTransaction::TYPE_CONTENT:
+ if ($old === null) {
+ return pht(
+ '%s created %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ } else {
+ return pht(
+ '%s edited %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
break;
case PhabricatorPasteTransaction::TYPE_TITLE:
return pht(
@@ -122,10 +134,52 @@
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
+ case self::TYPE_CONTENT:
return PhabricatorTransactions::COLOR_GREEN;
}
return parent::getColor();
}
+
+
+ public function hasChangeDetails() {
+ switch ($this->getTransactionType()) {
+ case self::TYPE_CONTENT:
+ return ($this->getOldValue() !== null);
+ }
+
+ return parent::hasChangeDetails();
+ }
+
+ public function renderChangeDetails(PhabricatorUser $viewer) {
+ switch ($this->getTransactionType()) {
+ case self::TYPE_CONTENT:
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ $files = id(new PhabricatorFileQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array_filter(array($old, $new)))
+ ->execute();
+ $files = mpull($files, null, 'getPHID');
+
+ $old_text = '';
+ if (idx($files, $old)) {
+ $old_text = $files[$old]->loadFileData();
+ }
+
+ $new_text = '';
+ if (idx($files, $new)) {
+ $new_text = $files[$new]->loadFileData();
+ }
+
+ return $this->renderTextCorpusChangeDetails(
+ $viewer,
+ $old_text,
+ $new_text);
+ }
+
+ return parent::renderChangeDetails($viewer);
+ }
+
}
diff --git a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php
--- a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php
+++ b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php
@@ -822,7 +822,10 @@
break;
}
- return $this->renderTextCorpusChangeDetails();
+ return $this->renderTextCorpusChangeDetails(
+ $viewer,
+ $this->getOldValue(),
+ $this->getNewValue());
}
public function renderTextCorpusChangeDetails(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 5, 8:59 AM (1 d, 9 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7224392
Default Alt Text
D8970.id21288.diff (13 KB)
Attached To
Mode
D8970: Allow pastes to be edited
Attached
Detach File
Event Timeline
Log In to Comment