1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 03:50:54 +01:00

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
This commit is contained in:
Marek Sapota 2011-10-18 19:46:52 -07:00
parent dfa2e29a01
commit a11053d0fa
3 changed files with 22 additions and 3 deletions

View file

@ -24,7 +24,12 @@ class DifferentialDiffCreateController extends DifferentialController {
if ($request->isFormPost()) { if ($request->isFormPost()) {
$parser = new ArcanistDiffParser(); $parser = new ArcanistDiffParser();
$diff = null;
try {
$diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
} catch (Exception $ex) {
$diff = $request->getStr('diff'); $diff = $request->getStr('diff');
}
$changes = $parser->parseDiff($diff); $changes = $parser->parseDiff($diff);
$diff = DifferentialDiff::newFromRawChanges($changes); $diff = DifferentialDiff::newFromRawChanges($changes);
@ -42,17 +47,23 @@ class DifferentialDiffCreateController extends DifferentialController {
$form = new AphrontFormView(); $form = new AphrontFormView();
$form $form
->setAction('/differential/diff/create/') ->setAction('/differential/diff/create/')
->setEncType('multipart/form-data')
->setUser($request->getUser()) ->setUser($request->getUser())
->appendChild( ->appendChild(
'<p class="aphront-form-instructions">The best way to create a '. '<p class="aphront-form-instructions">The best way to create a '.
'Differential diff is by using <strong>Arcanist</strong>, but you '. 'Differential diff is by using <strong>Arcanist</strong>, but you '.
'can also just paste a diff (e.g., from <tt>svn diff</tt> or '. 'can also just paste a diff (e.g., from <tt>svn diff</tt> or '.
'<tt>git diff</tt>) into this box if you really want.</p>') '<tt>git diff</tt>) into this box or upload it as a file if you '.
'really want.</p>')
->appendChild( ->appendChild(
id(new AphrontFormTextAreaControl()) id(new AphrontFormTextAreaControl())
->setLabel('Raw Diff') ->setLabel('Raw Diff')
->setName('diff') ->setName('diff')
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))
->appendChild(
id(new AphrontFormFileControl())
->setLabel('Raw Diff from file')
->setName('diff-file'))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue("Create Diff \xC2\xBB")); ->setValue("Create Diff \xC2\xBB"));

View file

@ -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/constants/lintstatus');
phutil_require_module('phabricator', 'applications/differential/controller/base'); phutil_require_module('phabricator', 'applications/differential/controller/base');
phutil_require_module('phabricator', 'applications/differential/storage/diff'); 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/base');
phutil_require_module('phabricator', 'view/form/control/file');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');

View file

@ -41,7 +41,7 @@ class PhabricatorFile extends PhabricatorFileDAO {
PhabricatorPHIDConstants::PHID_TYPE_FILE); PhabricatorPHIDConstants::PHID_TYPE_FILE);
} }
public static function newFromPHPUpload($spec, array $params = array()) { public static function readUploadedFileData($spec) {
if (!$spec) { if (!$spec) {
throw new Exception("No file was uploaded!"); throw new Exception("No file was uploaded!");
} }
@ -64,6 +64,12 @@ class PhabricatorFile extends PhabricatorFileDAO {
throw new Exception("File size disagrees with uploaded size."); 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( $file_name = nonempty(
idx($params, 'name'), idx($params, 'name'),
idx($spec, 'name')); idx($spec, 'name'));