Summary: Ref T7689. Ref T4100. This advances the goals of removing `loadViewerHandles()` (only 67 callsites remain!) and letting tokenizers some day take token functions like `viewer()` and `members(differential)`. Test Plan: - Sent a new message; used "To". - I simplified the cancel URI construction slightly because it's moot in all normal cases. - Edited a thread; used "Add Participants". - Searched rooms; used "Participants". - Searched countdowns; used "Authors". - Created a diff; used "Repository". - Edited a revision; edited "Projects"; edited "Reveiwers"; edited "Subscribers". - Searched for revisions; edited "responsible users"; "authors"; "reviwers"; "subscribers"; "repositories". - Added revision comments; edited "Add Reveiwers"; "Add Subscribers". - Commented on a commit; edited "Add Auditors"; "Add subscribers". - Edited a commit; edited "Projects". - Edited a repository; edited "Projects". - Searched feed, used "include Users"; "include Proejcts". - Searched files, used "authors". - Edited initiative; edited "Projects". - Searched backers; used "Backers". - Searched initiatives; used "Owners". - Edited build plans; edited "Run Command". - Searched Herald; used "Authors". - Added signature exemption in Legalpad. - Searhced legalpad; used "creators"; used "contributors". - Searched signatures; used "documents"; used "signers". - Created meme. - Searched macros; used "Authors". - Used "Projects" in Maniphest reports. - Used Maniphest comment actions. - Edited Maniphest tasks; edited "Assigned To"; edited "CC"; edited "projects". - Used "parent" in Maniphest task creation workflow. - Searched for projects; used "assigned to"; "in any projec"; "in all projects"; "not in projects"; "in users' projects"; "authors"; "subscribers". - Edited Maniphest bug filing domains, used "Default Author". - Searched for OAuth applications, used "Creators". - Edited Owners pacakge; edited "Primary Owner"; edited "Owners". - Searched for Owners packages; used "Owner". - OMG this UI is OLD - Edited a paste; edited "Projects". - Searched for paste; used "Authors". - Searched user activity log; used "Actors"; used "Users". - Edited a mock; edited "Projects"; edited "CC". - Searched for mocks; used "Authors". - Edited Phortune account; edited "Members". - Edited Phortune merchant account; edited "Members". - Searched Phrequent; used "Users". - Edited Ponder question; sued "projects". - Searched Ponder; used "Authors"; used "Answered By". - Added project members. - Searched for projects; used "Members". - Edited a Releeph product; edited "Pushers". - Searched pull requests; searched "Requestors". - Edited an arcanist project; used "Uses Symbols From". - Searhced push logs; used "Repositories"; used "Pushers". - Searched repositories; used "In nay project". - Used global search; used Authors/owners/Subscribers/In Any Project. - Edited a slowvote; used "Projects". - Searched slovotes; used "Authors". - Created a custom "Users" field; edited and searched for it. - Made a whole lot of typos in this list. ^^^^^^ Did not test: - Lint is nontrivial to test locally, I'll test it in production. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100, T7689 Differential Revision: https://secure.phabricator.com/D12224
214 lines
6.1 KiB
PHP
214 lines
6.1 KiB
PHP
<?php
|
|
|
|
final class DifferentialDiffCreateController extends DifferentialController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $this->getViewer();
|
|
|
|
// If we're on the "Update Diff" workflow, load the revision we're going
|
|
// to update.
|
|
$revision = null;
|
|
$revision_id = $request->getURIData('revisionID');
|
|
if ($revision_id) {
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($revision_id))
|
|
->requireCapabilities(
|
|
array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
))
|
|
->executeOne();
|
|
if (!$revision) {
|
|
return new Aphront404Response();
|
|
}
|
|
}
|
|
|
|
$diff = null;
|
|
// This object is just for policy stuff
|
|
$diff_object = DifferentialDiff::initializeNewDiff($viewer);
|
|
$repository_phid = null;
|
|
$errors = array();
|
|
$e_diff = null;
|
|
$e_file = null;
|
|
$validation_exception = null;
|
|
if ($request->isFormPost()) {
|
|
|
|
$repository_tokenizer = $request->getArr(
|
|
id(new DifferentialRepositoryField())->getFieldKey());
|
|
if ($repository_tokenizer) {
|
|
$repository_phid = reset($repository_tokenizer);
|
|
}
|
|
|
|
if ($request->getFileExists('diff-file')) {
|
|
$diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
|
|
} else {
|
|
$diff = $request->getStr('diff');
|
|
}
|
|
|
|
if (!strlen($diff)) {
|
|
$errors[] = pht(
|
|
'You can not create an empty diff. Paste a diff or upload a '.
|
|
'file containing a diff.');
|
|
$e_diff = pht('Required');
|
|
$e_file = pht('Required');
|
|
}
|
|
|
|
if (!$errors) {
|
|
try {
|
|
$call = new ConduitCall(
|
|
'differential.createrawdiff',
|
|
array(
|
|
'diff' => $diff,
|
|
'repositoryPHID' => $repository_phid,
|
|
'viewPolicy' => $request->getStr('viewPolicy'),
|
|
));
|
|
$call->setUser($viewer);
|
|
$result = $call->execute();
|
|
|
|
$diff_id = $result['id'];
|
|
|
|
$uri = $this->getApplicationURI("diff/{$diff_id}/");
|
|
$uri = new PhutilURI($uri);
|
|
if ($revision) {
|
|
$uri->setQueryParam('revisionID', $revision->getID());
|
|
}
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
$validation_exception = $ex;
|
|
}
|
|
}
|
|
}
|
|
|
|
$form = new AphrontFormView();
|
|
$arcanist_href = PhabricatorEnv::getDoclink('Arcanist User Guide');
|
|
$arcanist_link = phutil_tag(
|
|
'a',
|
|
array(
|
|
'href' => $arcanist_href,
|
|
'target' => '_blank',
|
|
),
|
|
'Learn More');
|
|
|
|
$cancel_uri = $this->getApplicationURI();
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
->setViewer($viewer)
|
|
->setObject($diff_object)
|
|
->execute();
|
|
|
|
$info_view = null;
|
|
if (!$request->isFormPost()) {
|
|
$info_view = id(new PHUIInfoView())
|
|
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
|
->setErrors(
|
|
array(
|
|
array(
|
|
pht(
|
|
'The best way to create a diff is to use the Arcanist '.
|
|
'command-line tool.'),
|
|
' ',
|
|
$arcanist_link,
|
|
),
|
|
pht(
|
|
'You can also paste a diff below, or upload a file '.
|
|
'containing a diff (for example, from %s, %s or %s).',
|
|
phutil_tag('tt', array(), 'svn diff'),
|
|
phutil_tag('tt', array(), 'git diff'),
|
|
phutil_tag('tt', array(), 'hg diff --git')),
|
|
));
|
|
}
|
|
|
|
if ($revision) {
|
|
$title = pht('Update Diff');
|
|
$header = pht('Update Diff');
|
|
$button = pht('Continue');
|
|
} else {
|
|
$title = pht('Create Diff');
|
|
$header = pht('Create New Diff');
|
|
$button = pht('Create Diff');
|
|
}
|
|
|
|
$form
|
|
->setEncType('multipart/form-data')
|
|
->setUser($viewer);
|
|
|
|
if ($revision) {
|
|
$revision_handles = $this->loadViewerHandles(array($revision->getPHID()));
|
|
$revision_handle = head($revision_handles);
|
|
|
|
$form->appendChild(
|
|
id(new AphrontFormMarkupControl())
|
|
->setLabel(pht('Updating Revision'))
|
|
->setValue($revision_handle->renderLink()));
|
|
}
|
|
|
|
if ($repository_phid) {
|
|
$repository_value = array($repository_phid);
|
|
} else {
|
|
$repository_value = array();
|
|
}
|
|
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormTextAreaControl())
|
|
->setLabel(pht('Raw Diff'))
|
|
->setName('diff')
|
|
->setValue($diff)
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
|
->setError($e_diff))
|
|
->appendChild(
|
|
id(new AphrontFormFileControl())
|
|
->setLabel(pht('Raw Diff From File'))
|
|
->setName('diff-file')
|
|
->setError($e_file))
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setName(id(new DifferentialRepositoryField())->getFieldKey())
|
|
->setLabel(pht('Repository'))
|
|
->setDatasource(new DiffusionRepositoryDatasource())
|
|
->setValue($repository_value)
|
|
->setLimit(1))
|
|
->appendChild(
|
|
id(new AphrontFormPolicyControl())
|
|
->setUser($viewer)
|
|
->setName('viewPolicy')
|
|
->setPolicyObject($diff_object)
|
|
->setPolicies($policies)
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
|
->appendChild(
|
|
id(new AphrontFormSubmitControl())
|
|
->addCancelButton($cancel_uri)
|
|
->setValue($button));
|
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
|
->setHeaderText($header)
|
|
->setValidationException($validation_exception)
|
|
->setForm($form)
|
|
->setFormErrors($errors);
|
|
|
|
if ($info_view) {
|
|
$form_box->setInfoView($info_view);
|
|
}
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
if ($revision) {
|
|
$crumbs->addTextCrumb(
|
|
$revision->getMonogram(),
|
|
'/'.$revision->getMonogram());
|
|
}
|
|
$crumbs->addTextCrumb($title);
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$form_box,
|
|
),
|
|
array(
|
|
'title' => $title,
|
|
));
|
|
}
|
|
|
|
}
|