From a11053d0fa928ade215ff1eb9714d8728cda993a Mon Sep 17 00:00:00 2001 From: Marek Sapota Date: Tue, 18 Oct 2011 19:46:52 -0700 Subject: [PATCH] Add possibility to upload a diff file instead of using copy-paste. Test Plan: Go to /differential/diff/create and upload a diff file - result should be the same as pasting the diff into the textarea. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Differential Revision: 1019 --- .../DifferentialDiffCreateController.php | 15 +++++++++++++-- .../controller/diffcreate/__init__.php | 2 ++ .../files/storage/file/PhabricatorFile.php | 8 +++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/applications/differential/controller/diffcreate/DifferentialDiffCreateController.php b/src/applications/differential/controller/diffcreate/DifferentialDiffCreateController.php index 86416188bc..c21ded7164 100644 --- a/src/applications/differential/controller/diffcreate/DifferentialDiffCreateController.php +++ b/src/applications/differential/controller/diffcreate/DifferentialDiffCreateController.php @@ -24,7 +24,12 @@ class DifferentialDiffCreateController extends DifferentialController { if ($request->isFormPost()) { $parser = new ArcanistDiffParser(); - $diff = $request->getStr('diff'); + $diff = null; + try { + $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']); + } catch (Exception $ex) { + $diff = $request->getStr('diff'); + } $changes = $parser->parseDiff($diff); $diff = DifferentialDiff::newFromRawChanges($changes); @@ -42,17 +47,23 @@ class DifferentialDiffCreateController extends DifferentialController { $form = new AphrontFormView(); $form ->setAction('/differential/diff/create/') + ->setEncType('multipart/form-data') ->setUser($request->getUser()) ->appendChild( '

The best way to create a '. 'Differential diff is by using Arcanist, but you '. 'can also just paste a diff (e.g., from svn diff or '. - 'git diff) into this box if you really want.

') + 'git diff) into this box or upload it as a file if you '. + 'really want.

') ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel('Raw Diff') ->setName('diff') ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)) + ->appendChild( + id(new AphrontFormFileControl()) + ->setLabel('Raw Diff from file') + ->setName('diff-file')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue("Create Diff \xC2\xBB")); diff --git a/src/applications/differential/controller/diffcreate/__init__.php b/src/applications/differential/controller/diffcreate/__init__.php index fd56eba3fb..3bc3857036 100644 --- a/src/applications/differential/controller/diffcreate/__init__.php +++ b/src/applications/differential/controller/diffcreate/__init__.php @@ -12,7 +12,9 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/differential/constants/lintstatus'); phutil_require_module('phabricator', 'applications/differential/controller/base'); phutil_require_module('phabricator', 'applications/differential/storage/diff'); +phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'view/form/base'); +phutil_require_module('phabricator', 'view/form/control/file'); phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/layout/panel'); diff --git a/src/applications/files/storage/file/PhabricatorFile.php b/src/applications/files/storage/file/PhabricatorFile.php index f380a89660..9f8199de18 100644 --- a/src/applications/files/storage/file/PhabricatorFile.php +++ b/src/applications/files/storage/file/PhabricatorFile.php @@ -41,7 +41,7 @@ class PhabricatorFile extends PhabricatorFileDAO { PhabricatorPHIDConstants::PHID_TYPE_FILE); } - public static function newFromPHPUpload($spec, array $params = array()) { + public static function readUploadedFileData($spec) { if (!$spec) { throw new Exception("No file was uploaded!"); } @@ -64,6 +64,12 @@ class PhabricatorFile extends PhabricatorFileDAO { throw new Exception("File size disagrees with uploaded size."); } + return $file_data; + } + + public static function newFromPHPUpload($spec, array $params = array()) { + $file_data = self::readUploadedFileData($spec); + $file_name = nonempty( idx($params, 'name'), idx($spec, 'name'));