Page MenuHomePhabricator

D14167.diff
No OneTemporary

D14167.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2510,6 +2510,7 @@
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
'PhabricatorPastePastePHIDType' => 'applications/paste/phid/PhabricatorPastePastePHIDType.php',
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
+ 'PhabricatorPasteRawController' => 'applications/paste/controller/PhabricatorPasteRawController.php',
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
'PhabricatorPasteSchemaSpec' => 'applications/paste/storage/PhabricatorPasteSchemaSpec.php',
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
@@ -6545,6 +6546,7 @@
'PhabricatorPasteListController' => 'PhabricatorPasteController',
'PhabricatorPastePastePHIDType' => 'PhabricatorPHIDType',
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorPasteRawController' => 'PhabricatorPasteController',
'PhabricatorPasteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'PhabricatorPasteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
diff --git a/src/applications/paste/application/PhabricatorPasteApplication.php b/src/applications/paste/application/PhabricatorPasteApplication.php
--- a/src/applications/paste/application/PhabricatorPasteApplication.php
+++ b/src/applications/paste/application/PhabricatorPasteApplication.php
@@ -40,6 +40,7 @@
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
'create/' => 'PhabricatorPasteEditController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
+ 'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController',
),
);
diff --git a/src/applications/paste/controller/PhabricatorPasteRawController.php b/src/applications/paste/controller/PhabricatorPasteRawController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/paste/controller/PhabricatorPasteRawController.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Redirect to the current raw contents of a Paste.
+ *
+ * This controller provides a stable URI for getting the current contents of
+ * a paste, and slightly simplifies the view controller.
+ */
+final class PhabricatorPasteRawController
+ extends PhabricatorPasteController {
+
+ public function shouldAllowPublic() {
+ return true;
+ }
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $request->getViewer();
+ $id = $request->getURIData('id');
+
+ $paste = id(new PhabricatorPasteQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->executeOne();
+ if (!$paste) {
+ return new Aphront404Response();
+ }
+
+ $file = id(new PhabricatorFileQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array($paste->getFilePHID()))
+ ->executeOne();
+ if (!$file) {
+ return new Aphront400Response();
+ }
+
+ return $file->getRedirectResponse();
+ }
+
+}
diff --git a/src/applications/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php
--- a/src/applications/paste/controller/PhabricatorPasteViewController.php
+++ b/src/applications/paste/controller/PhabricatorPasteViewController.php
@@ -42,14 +42,6 @@
return new Aphront404Response();
}
- $file = id(new PhabricatorFileQuery())
- ->setViewer($viewer)
- ->withPHIDs(array($paste->getFilePHID()))
- ->executeOne();
- if (!$file) {
- return new Aphront400Response();
- }
-
$forks = id(new PhabricatorPasteQuery())
->setViewer($viewer)
->withParentPHIDs(array($paste->getPHID()))
@@ -57,7 +49,7 @@
$fork_phids = mpull($forks, 'getPHID');
$header = $this->buildHeaderView($paste);
- $actions = $this->buildActionView($viewer, $paste, $file);
+ $actions = $this->buildActionView($viewer, $paste);
$properties = $this->buildPropertyView($paste, $fork_phids, $actions);
$object_box = id(new PHUIObjectBoxView())
@@ -139,8 +131,7 @@
private function buildActionView(
PhabricatorUser $viewer,
- PhabricatorPaste $paste,
- PhabricatorFile $file) {
+ PhabricatorPaste $paste) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
@@ -148,7 +139,8 @@
PhabricatorPolicyCapability::CAN_EDIT);
$can_fork = $viewer->isLoggedIn();
- $fork_uri = $this->getApplicationURI('/create/?parent='.$paste->getID());
+ $id = $paste->getID();
+ $fork_uri = $this->getApplicationURI('/create/?parent='.$id);
return id(new PhabricatorActionListView())
->setUser($viewer)
@@ -160,7 +152,7 @@
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
- ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')))
+ ->setHref($this->getApplicationURI("edit/{$id}/")))
->addAction(
id(new PhabricatorActionView())
->setName(pht('Fork This Paste'))
@@ -172,7 +164,7 @@
id(new PhabricatorActionView())
->setName(pht('View Raw File'))
->setIcon('fa-file-text-o')
- ->setHref($file->getBestURI()));
+ ->setHref($this->getApplicationURI("raw/{$id}/")));
}
private function buildPropertyView(

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 2, 10:46 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6717877
Default Alt Text
D14167.diff (5 KB)

Event Timeline