2011-03-08 02:25:47 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionBrowseController extends DiffusionController {
|
2011-03-08 02:25:47 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
2011-03-08 23:29:02 +01:00
|
|
|
$drequest = $this->diffusionRequest;
|
2013-04-23 20:12:02 +02:00
|
|
|
$is_file = false;
|
2011-03-08 02:25:47 +01:00
|
|
|
|
2012-12-14 23:07:39 +01:00
|
|
|
if ($this->getRequest()->getStr('before')) {
|
|
|
|
$is_file = true;
|
2013-04-23 20:12:02 +02:00
|
|
|
} else if ($this->getRequest()->getStr('grep') == '') {
|
Diffusion - move DiffusionBrowseQuery => Conduit
Summary: see title. Ref T2784.
Test Plan:
In diffusion, for each of SVN, Mercurial, and Git, I loaded up /diffusion/CALLSIGN/. I verified the README was displayed and things looked good. Next I clicked on "browse" on the top-most commit and verified things looked correct. Also clicked through to a file for a good measure and things looked good.
In owners, for each of SVN, Mercurial, and Git, I played around with the path typeahead / validator. It worked correctly!
Reviewers: epriestley
Reviewed By: epriestley
CC: chad, aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5883
2013-05-10 20:02:58 +02:00
|
|
|
$results = DiffusionBrowseResultSet::newFromConduit(
|
|
|
|
$this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.browsequery',
|
|
|
|
array(
|
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'commit' => $drequest->getCommit(),
|
|
|
|
)));
|
|
|
|
$reason = $results->getReasonForEmptyResultSet();
|
|
|
|
$is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE);
|
2012-12-14 23:07:39 +01:00
|
|
|
}
|
2011-03-08 02:25:47 +01:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
if ($is_file) {
|
|
|
|
$controller = new DiffusionBrowseFileController($this->getRequest());
|
|
|
|
$controller->setDiffusionRequest($drequest);
|
|
|
|
$controller->setCurrentApplication($this->getCurrentApplication());
|
|
|
|
return $this->delegateToController($controller);
|
|
|
|
}
|
|
|
|
|
2011-03-08 03:21:43 +01:00
|
|
|
$content = array();
|
|
|
|
|
2012-04-24 03:36:25 +02:00
|
|
|
if ($drequest->getTagContent()) {
|
2013-05-11 17:23:19 +02:00
|
|
|
$title = pht('Tag: %s', $drequest->getSymbolicCommit());
|
2012-04-24 03:36:25 +02:00
|
|
|
|
|
|
|
$tag_view = new AphrontPanelView();
|
2013-02-13 23:50:15 +01:00
|
|
|
$tag_view->setHeader($title);
|
2012-04-24 03:36:25 +02:00
|
|
|
$tag_view->appendChild(
|
|
|
|
$this->markupText($drequest->getTagContent()));
|
|
|
|
|
|
|
|
$content[] = $tag_view;
|
|
|
|
}
|
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$content[] = $this->renderSearchForm();
|
2011-03-08 03:21:43 +01:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
if ($this->getRequest()->getStr('grep') != '') {
|
|
|
|
$content[] = $this->renderSearchResults();
|
2011-03-08 03:21:43 +01:00
|
|
|
|
2011-03-08 02:25:47 +01:00
|
|
|
} else {
|
Diffusion - move DiffusionBrowseQuery => Conduit
Summary: see title. Ref T2784.
Test Plan:
In diffusion, for each of SVN, Mercurial, and Git, I loaded up /diffusion/CALLSIGN/. I verified the README was displayed and things looked good. Next I clicked on "browse" on the top-most commit and verified things looked correct. Also clicked through to a file for a good measure and things looked good.
In owners, for each of SVN, Mercurial, and Git, I played around with the path typeahead / validator. It worked correctly!
Reviewers: epriestley
Reviewed By: epriestley
CC: chad, aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5883
2013-05-10 20:02:58 +02:00
|
|
|
if (!$results->isValidResults()) {
|
2013-04-23 20:12:02 +02:00
|
|
|
$empty_result = new DiffusionEmptyResultView();
|
|
|
|
$empty_result->setDiffusionRequest($drequest);
|
Diffusion - move DiffusionBrowseQuery => Conduit
Summary: see title. Ref T2784.
Test Plan:
In diffusion, for each of SVN, Mercurial, and Git, I loaded up /diffusion/CALLSIGN/. I verified the README was displayed and things looked good. Next I clicked on "browse" on the top-most commit and verified things looked correct. Also clicked through to a file for a good measure and things looked good.
In owners, for each of SVN, Mercurial, and Git, I played around with the path typeahead / validator. It worked correctly!
Reviewers: epriestley
Reviewed By: epriestley
CC: chad, aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5883
2013-05-10 20:02:58 +02:00
|
|
|
$empty_result->setDiffusionBrowseResultSet($results);
|
2013-04-23 20:12:02 +02:00
|
|
|
$empty_result->setView($this->getRequest()->getStr('view'));
|
|
|
|
$content[] = $empty_result;
|
|
|
|
|
|
|
|
} else {
|
2011-04-03 01:44:19 +02:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$phids = array();
|
Diffusion - move DiffusionBrowseQuery => Conduit
Summary: see title. Ref T2784.
Test Plan:
In diffusion, for each of SVN, Mercurial, and Git, I loaded up /diffusion/CALLSIGN/. I verified the README was displayed and things looked good. Next I clicked on "browse" on the top-most commit and verified things looked correct. Also clicked through to a file for a good measure and things looked good.
In owners, for each of SVN, Mercurial, and Git, I played around with the path typeahead / validator. It worked correctly!
Reviewers: epriestley
Reviewed By: epriestley
CC: chad, aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5883
2013-05-10 20:02:58 +02:00
|
|
|
foreach ($results->getPaths() as $result) {
|
2013-04-23 20:12:02 +02:00
|
|
|
$data = $result->getLastCommitData();
|
|
|
|
if ($data) {
|
|
|
|
if ($data->getCommitDetail('authorPHID')) {
|
|
|
|
$phids[$data->getCommitDetail('authorPHID')] = true;
|
|
|
|
}
|
2011-04-03 01:44:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$phids = array_keys($phids);
|
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-04-03 01:44:19 +02:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$browse_table = new DiffusionBrowseTableView();
|
|
|
|
$browse_table->setDiffusionRequest($drequest);
|
|
|
|
$browse_table->setHandles($handles);
|
Diffusion - move DiffusionBrowseQuery => Conduit
Summary: see title. Ref T2784.
Test Plan:
In diffusion, for each of SVN, Mercurial, and Git, I loaded up /diffusion/CALLSIGN/. I verified the README was displayed and things looked good. Next I clicked on "browse" on the top-most commit and verified things looked correct. Also clicked through to a file for a good measure and things looked good.
In owners, for each of SVN, Mercurial, and Git, I played around with the path typeahead / validator. It worked correctly!
Reviewers: epriestley
Reviewed By: epriestley
CC: chad, aran, Korvin
Maniphest Tasks: T2784
Differential Revision: https://secure.phabricator.com/D5883
2013-05-10 20:02:58 +02:00
|
|
|
$browse_table->setPaths($results->getPaths());
|
2013-04-23 20:12:02 +02:00
|
|
|
$browse_table->setUser($this->getRequest()->getUser());
|
2011-03-08 02:25:47 +01:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$browse_panel = new AphrontPanelView();
|
|
|
|
$browse_panel->appendChild($browse_table);
|
|
|
|
$browse_panel->setNoBackground();
|
2011-03-08 02:25:47 +01:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$content[] = $browse_panel;
|
|
|
|
}
|
2011-03-08 02:25:47 +01:00
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
$content[] = $this->buildOpenRevisions();
|
2011-10-02 21:52:54 +02:00
|
|
|
|
2013-05-21 22:47:06 +02:00
|
|
|
$readme = $this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.readmequery',
|
|
|
|
array(
|
2013-08-13 19:11:15 +02:00
|
|
|
'paths' => $results->getPathDicts(),
|
2013-05-21 22:47:06 +02:00
|
|
|
));
|
2013-05-11 17:23:19 +02:00
|
|
|
if ($readme) {
|
|
|
|
$box = new PHUIBoxView();
|
|
|
|
$box->setShadow(true);
|
|
|
|
$box->appendChild($readme);
|
|
|
|
$box->addPadding(PHUI::PADDING_LARGE);
|
2013-07-03 19:10:07 +02:00
|
|
|
$box->addMargin(PHUI::MARGIN_LARGE);
|
2012-04-30 16:47:41 +02:00
|
|
|
|
2013-07-03 19:10:07 +02:00
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader(pht('README'));
|
2013-05-11 17:23:19 +02:00
|
|
|
|
2013-07-03 19:10:07 +02:00
|
|
|
$content[] = array(
|
|
|
|
$header,
|
|
|
|
$box,
|
|
|
|
);
|
2013-04-23 20:12:02 +02:00
|
|
|
}
|
2013-05-11 17:23:19 +02:00
|
|
|
|
2012-04-30 16:47:41 +02:00
|
|
|
}
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$nav = $this->buildSideNav('browse', false);
|
|
|
|
$nav->appendChild($content);
|
2011-03-08 02:25:47 +01:00
|
|
|
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
$crumbs = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'branch' => true,
|
|
|
|
'path' => true,
|
|
|
|
'view' => 'browse',
|
|
|
|
));
|
|
|
|
$nav->setCrumbs($crumbs);
|
|
|
|
return $this->buildApplicationPage(
|
2011-03-13 01:17:34 +01:00
|
|
|
$nav,
|
2011-03-08 02:25:47 +01:00
|
|
|
array(
|
2013-05-11 17:23:19 +02:00
|
|
|
'device' => true,
|
2012-04-24 03:36:25 +02:00
|
|
|
'title' => array(
|
|
|
|
nonempty(basename($drequest->getPath()), '/'),
|
|
|
|
$drequest->getRepository()->getCallsign().' Repository',
|
|
|
|
),
|
2011-03-08 02:25:47 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-04-23 20:12:02 +02:00
|
|
|
|
|
|
|
private function renderSearchForm() {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($this->getRequest()->getUser())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setMethod('GET');
|
2013-04-23 20:12:02 +02:00
|
|
|
|
|
|
|
switch ($drequest->getRepository()->getVersionControlSystem()) {
|
|
|
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
|
|
|
$form->appendChild(pht('Search is not available in Subversion.'));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Search Here'))
|
|
|
|
->setName('grep')
|
|
|
|
->setValue($this->getRequest()->getStr('grep'))
|
|
|
|
->setCaption(pht('Regular expression')))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Grep')));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-11 17:23:19 +02:00
|
|
|
$filter = new AphrontListFilterView();
|
|
|
|
$filter->appendChild($form);
|
|
|
|
|
|
|
|
return $filter;
|
2013-04-23 20:12:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderSearchResults() {
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$results = array();
|
|
|
|
$no_data = pht('No results found.');
|
|
|
|
|
|
|
|
$limit = 100;
|
|
|
|
$page = $this->getRequest()->getInt('page', 0);
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$pager->setPageSize($limit);
|
|
|
|
$pager->setOffset($page);
|
|
|
|
$pager->setURI($this->getRequest()->getRequestURI(), 'page');
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2013-05-17 23:11:20 +02:00
|
|
|
$results = $this->callConduitWithDiffusionRequest(
|
|
|
|
'diffusion.searchquery',
|
|
|
|
array(
|
|
|
|
'grep' => $this->getRequest()->getStr('grep'),
|
|
|
|
'stableCommitName' => $drequest->getStableCommitName(),
|
|
|
|
'path' => $drequest->getPath(),
|
|
|
|
'limit' => $limit + 1,
|
|
|
|
'offset' => $page));
|
|
|
|
|
|
|
|
} catch (ConduitException $ex) {
|
|
|
|
$err = $ex->getErrorDescription();
|
|
|
|
if ($err != '') {
|
2013-04-25 02:10:39 +02:00
|
|
|
return id(new AphrontErrorView())
|
|
|
|
->setTitle(pht('Search Error'))
|
2013-05-17 23:11:20 +02:00
|
|
|
->appendChild($err);
|
2013-04-25 02:10:39 +02:00
|
|
|
}
|
2013-04-23 20:12:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$results = $pager->sliceResults($results);
|
|
|
|
|
|
|
|
require_celerity_resource('syntax-highlighting-css');
|
|
|
|
|
|
|
|
// NOTE: This can be wrong because we may find the string inside the
|
|
|
|
// comment. But it's correct in most cases and highlighting the whole file
|
|
|
|
// would be too expensive.
|
|
|
|
$futures = array();
|
|
|
|
$engine = PhabricatorSyntaxHighlighter::newEngine();
|
|
|
|
foreach ($results as $result) {
|
|
|
|
list($path, $line, $string) = $result;
|
|
|
|
$futures["{$path}:{$line}"] = $engine->getHighlightFuture(
|
|
|
|
$engine->getLanguageFromFilename($path),
|
|
|
|
ltrim($string));
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Futures($futures)->limit(8)->resolveAll();
|
|
|
|
} catch (PhutilSyntaxHighlighterException $ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($results as $result) {
|
|
|
|
list($path, $line, $string) = $result;
|
|
|
|
|
|
|
|
$href = $drequest->generateURI(array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'path' => $path,
|
|
|
|
'line' => $line,
|
|
|
|
));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$string = $futures["{$path}:{$line}"]->resolve();
|
|
|
|
} catch (PhutilSyntaxHighlighterException $ex) {
|
|
|
|
}
|
|
|
|
|
|
|
|
$string = phutil_tag(
|
|
|
|
'pre',
|
|
|
|
array('class' => 'PhabricatorMonospaced'),
|
|
|
|
$string);
|
|
|
|
|
|
|
|
$path = Filesystem::readablePath($path, $drequest->getPath());
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
phutil_tag('a', array('href' => $href), $path),
|
|
|
|
$line,
|
|
|
|
$string,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setClassName('remarkup-code')
|
|
|
|
->setHeaders(array(pht('Path'), pht('Line'), pht('String')))
|
|
|
|
->setColumnClasses(array('', 'n', 'wide'))
|
|
|
|
->setNoDataString($no_data);
|
|
|
|
|
|
|
|
return id(new AphrontPanelView())
|
|
|
|
->setHeader(pht('Search Results'))
|
|
|
|
->appendChild($table)
|
|
|
|
->appendChild($pager);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-24 03:36:25 +02:00
|
|
|
private function markupText($text) {
|
|
|
|
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
2013-03-04 21:33:05 +01:00
|
|
|
$engine->setConfig('viewer', $this->getRequest()->getUser());
|
2013-02-13 23:50:15 +01:00
|
|
|
$text = $engine->markupText($text);
|
2012-04-24 03:36:25 +02:00
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$text = phutil_tag(
|
2012-04-24 03:36:25 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup',
|
|
|
|
),
|
|
|
|
$text);
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2011-03-08 02:25:47 +01:00
|
|
|
}
|