1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-29 17:00:59 +01:00

Merge pull request #74 from mareksapota-fb/master

Pull request for differential revision D1019
This commit is contained in:
Evan Priestley 2011-10-19 15:31:22 -07:00
commit 0cb9f3dcf5
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'));