2011-03-08 18:54:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-16 20:08:54 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-03-08 18:54:55 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionBrowseFileController extends DiffusionController {
|
2011-03-08 18:54:55 +01:00
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
private $corpusType = 'text';
|
2011-04-02 00:34:45 +02:00
|
|
|
|
2011-03-08 18:54:55 +01:00
|
|
|
public function processRequest() {
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2011-03-23 03:34:47 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$path = $drequest->getPath();
|
2011-03-23 03:34:47 +01:00
|
|
|
$selected = $request->getStr('view');
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
$needs_blame = ($selected == 'blame' || $selected == 'plainblame');
|
|
|
|
$file_query = DiffusionFileContentQuery::newFromDiffusionRequest(
|
|
|
|
$this->diffusionRequest);
|
|
|
|
$file_query->setNeedsBlame($needs_blame);
|
|
|
|
$file_query->loadFileContent();
|
|
|
|
$data = $file_query->getRawData();
|
2011-03-22 07:57:32 +01:00
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
if ($selected === 'raw') {
|
|
|
|
return $this->buildRawResponse($path, $data);
|
2012-03-14 07:50:34 +01:00
|
|
|
}
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
// Build the content of the file.
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
$corpus = $this->buildCorpus(
|
|
|
|
$selected,
|
|
|
|
$file_query,
|
|
|
|
$needs_blame,
|
|
|
|
$drequest,
|
|
|
|
$path,
|
2012-03-20 03:52:24 +01:00
|
|
|
$data);
|
|
|
|
|
|
|
|
require_celerity_resource('diffusion-source-css');
|
|
|
|
|
|
|
|
if ($this->corpusType == 'text') {
|
|
|
|
$view_select_panel = $this->renderViewSelectPanel();
|
|
|
|
} else {
|
|
|
|
$view_select_panel = null;
|
|
|
|
}
|
2011-03-26 20:42:12 +01:00
|
|
|
|
|
|
|
// Render the page.
|
|
|
|
$content = array();
|
|
|
|
$content[] = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'branch' => true,
|
|
|
|
'path' => true,
|
|
|
|
'view' => 'browse',
|
|
|
|
));
|
|
|
|
$content[] = $view_select_panel;
|
|
|
|
$content[] = $corpus;
|
2011-10-02 21:52:54 +02:00
|
|
|
$content[] = $this->buildOpenRevisions();
|
2011-03-26 20:42:12 +01:00
|
|
|
|
|
|
|
$nav = $this->buildSideNav('browse', true);
|
|
|
|
$nav->appendChild($content);
|
|
|
|
|
2011-04-19 06:21:08 +02:00
|
|
|
$basename = basename($this->getDiffusionRequest()->getPath());
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$nav,
|
|
|
|
array(
|
2011-04-19 06:21:08 +02:00
|
|
|
'title' => $basename,
|
2011-03-26 20:42:12 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
private function buildCorpus($selected,
|
|
|
|
$file_query,
|
|
|
|
$needs_blame,
|
|
|
|
$drequest,
|
|
|
|
$path,
|
|
|
|
$data) {
|
2011-04-01 22:42:00 +02:00
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
|
|
|
|
$file = $this->loadFileForData($path, $data);
|
|
|
|
$file_uri = $file->getBestURI();
|
|
|
|
|
|
|
|
if ($file->isViewableImage()) {
|
|
|
|
$this->corpusType = 'image';
|
|
|
|
return $this->buildImageCorpus($file_uri);
|
|
|
|
} else {
|
|
|
|
$this->corpusType = 'binary';
|
|
|
|
return $this->buildBinaryCorpus($file_uri, $data);
|
|
|
|
}
|
Allow Diffusion to display PDF files
Summary:
When Diffusion encounters an image file, it displays it as an
image, but when it encounters a PDF file, it currently shows only some
gibberish. This fixes that.
Test Plan:
I tried it. Embedding a large PDF in a data URL is a little
bit slow, but it works.
Reviewers: tuomaspelkonen, epriestley, gc3, waltermundt, jungejason, nh
Reviewed By: epriestley
CC: aran, tuomaspelkonen, epriestley, jaapweel
Differential Revision: 915
2011-09-09 00:23:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
// TODO: blame of blame.
|
2011-03-23 03:34:47 +01:00
|
|
|
switch ($selected) {
|
|
|
|
case 'plain':
|
|
|
|
$style =
|
|
|
|
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
|
|
|
|
$corpus = phutil_render_tag(
|
|
|
|
'textarea',
|
|
|
|
array(
|
|
|
|
'style' => $style,
|
|
|
|
),
|
2011-03-26 20:42:12 +01:00
|
|
|
phutil_escape_html($file_query->getRawData()));
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2011-03-23 03:34:47 +01:00
|
|
|
break;
|
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
case 'plainblame':
|
|
|
|
$style =
|
|
|
|
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
|
|
|
|
list($text_list, $rev_list, $blame_dict) =
|
|
|
|
$file_query->getBlameData();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($text_list as $k => $line) {
|
|
|
|
$rev = $rev_list[$k];
|
2011-10-18 21:58:45 +02:00
|
|
|
if (isset($blame_dict[$rev]['handle'])) {
|
|
|
|
$author = $blame_dict[$rev]['handle']->getName();
|
|
|
|
} else {
|
|
|
|
$author = $blame_dict[$rev]['author'];
|
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
$rows[] =
|
2011-06-07 01:08:49 +02:00
|
|
|
sprintf("%-10s %-20s %s", substr($rev, 0, 7), $author, $line);
|
2011-04-01 03:28:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$corpus = phutil_render_tag(
|
|
|
|
'textarea',
|
|
|
|
array(
|
|
|
|
'style' => $style,
|
|
|
|
),
|
|
|
|
phutil_escape_html(implode("\n", $rows)));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-03-23 03:34:47 +01:00
|
|
|
case 'highlighted':
|
2011-03-26 20:42:12 +01:00
|
|
|
case 'blame':
|
2011-03-23 03:34:47 +01:00
|
|
|
default:
|
|
|
|
require_celerity_resource('syntax-highlighting-css');
|
2011-03-08 18:54:55 +01:00
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData();
|
2011-03-26 20:42:12 +01:00
|
|
|
|
2011-07-06 21:12:17 +02:00
|
|
|
$text_list = implode("\n", $text_list);
|
|
|
|
$text_list = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
|
|
|
$path,
|
|
|
|
$text_list);
|
|
|
|
$text_list = explode("\n", $text_list);
|
2011-03-23 03:34:47 +01:00
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
$rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict,
|
2011-04-02 00:34:45 +02:00
|
|
|
$needs_blame, $drequest, $file_query, $selected);
|
2011-03-23 03:34:47 +01:00
|
|
|
|
|
|
|
$corpus_table = phutil_render_tag(
|
|
|
|
'table',
|
|
|
|
array(
|
2011-03-31 04:21:09 +02:00
|
|
|
'class' => "diffusion-source remarkup-code PhabricatorMonospaced",
|
2011-03-23 03:34:47 +01:00
|
|
|
),
|
|
|
|
implode("\n", $rows));
|
|
|
|
$corpus = phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'style' => 'padding: 0pt 2em;',
|
|
|
|
),
|
|
|
|
$corpus_table);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
return $corpus;
|
|
|
|
}
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
private function renderViewSelectPanel() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$select = AphrontFormSelectControl::renderSelectTag(
|
|
|
|
$request->getStr('view'),
|
|
|
|
array(
|
|
|
|
'highlighted' => 'View as Highlighted Text',
|
|
|
|
'blame' => 'View as Highlighted Text with Blame',
|
|
|
|
'plain' => 'View as Plain Text',
|
|
|
|
'plainblame' => 'View as Plain Text with Blame',
|
|
|
|
'raw' => 'View as raw document',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'view',
|
|
|
|
));
|
|
|
|
|
|
|
|
$view_select_panel = new AphrontPanelView();
|
|
|
|
$view_select_form = phutil_render_tag(
|
|
|
|
'form',
|
|
|
|
array(
|
|
|
|
'action' => $request->getRequestURI(),
|
|
|
|
'method' => 'get',
|
|
|
|
'class' => 'diffusion-browse-type-form',
|
|
|
|
),
|
|
|
|
$select.
|
|
|
|
' <button>View</button> '.
|
|
|
|
$this->renderEditButton());
|
|
|
|
|
|
|
|
$view_select_panel->appendChild($view_select_form);
|
|
|
|
$view_select_panel->appendChild('<div style="clear: both;"></div>');
|
|
|
|
|
|
|
|
return $view_select_panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderEditButton() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
$path = $drequest->getPath();
|
|
|
|
$line = 1;
|
|
|
|
|
2012-04-05 02:53:16 +02:00
|
|
|
$callsign = $repository->getCallsign();
|
|
|
|
$editor_link = $user->loadEditorLink($path, $line, $callsign);
|
2012-03-20 03:52:24 +01:00
|
|
|
if (!$editor_link) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $editor_link,
|
|
|
|
'class' => 'button',
|
|
|
|
),
|
|
|
|
'Edit');
|
|
|
|
}
|
2011-03-13 01:17:34 +01:00
|
|
|
|
2011-05-25 09:50:20 +02:00
|
|
|
private function buildDisplayRows($text_list, $rev_list, $blame_dict,
|
2011-04-02 00:34:45 +02:00
|
|
|
$needs_blame, DiffusionRequest $drequest, $file_query, $selected) {
|
2011-04-01 03:28:24 +02:00
|
|
|
$last_rev = null;
|
2012-03-07 22:41:55 +01:00
|
|
|
$color = '#eeeeee';
|
2011-03-26 20:42:12 +01:00
|
|
|
$rows = array();
|
|
|
|
$n = 1;
|
2011-05-25 09:50:20 +02:00
|
|
|
$view = $this->getRequest()->getStr('view');
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2011-05-18 16:44:53 +02:00
|
|
|
if ($blame_dict) {
|
|
|
|
$epoch_list = ipull($blame_dict, 'epoch');
|
2012-03-07 22:41:55 +01:00
|
|
|
$epoch_max = max($epoch_list);
|
|
|
|
$epoch_min = min($epoch_list);
|
|
|
|
$epoch_range = $epoch_max - $epoch_min + 1;
|
2011-05-18 16:44:53 +02:00
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2012-02-25 20:45:51 +01:00
|
|
|
$targ = '';
|
|
|
|
$min_line = 0;
|
|
|
|
$line = $drequest->getLine();
|
2012-03-07 22:41:55 +01:00
|
|
|
if (strpos($line, '-') !== false) {
|
|
|
|
list($min, $max) = explode('-', $line, 2);
|
2012-02-25 20:45:51 +01:00
|
|
|
$min_line = min($min, $max);
|
|
|
|
$max_line = max($min, $max);
|
|
|
|
} else if (strlen($line)) {
|
|
|
|
$min_line = $line;
|
|
|
|
$max_line = $line;
|
|
|
|
}
|
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
foreach ($text_list as $k => $line) {
|
|
|
|
if ($needs_blame) {
|
|
|
|
// If the line's rev is same as the line above, show empty content
|
|
|
|
// with same color; otherwise generate blame info. The newer a change
|
|
|
|
// is, the darker the color.
|
|
|
|
$rev = $rev_list[$k];
|
|
|
|
if ($last_rev == $rev) {
|
|
|
|
$blame_info =
|
2011-04-02 00:34:45 +02:00
|
|
|
($file_query->getSupportsBlameOnBlame() ?
|
|
|
|
'<th style="background: '.$color.'; width: 2em;"></th>' : '').
|
2011-03-26 20:42:12 +01:00
|
|
|
'<th style="background: '.$color.'; width: 9em;"></th>'.
|
|
|
|
'<th style="background: '.$color.'"></th>';
|
|
|
|
} else {
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2012-03-15 03:52:42 +01:00
|
|
|
$revision_time = null;
|
2012-03-07 22:41:55 +01:00
|
|
|
if ($blame_dict) {
|
|
|
|
$color_number = (int)(0xEE -
|
|
|
|
0xEE * ($blame_dict[$rev]['epoch'] - $epoch_min) / $epoch_range);
|
|
|
|
$color = sprintf('#%02xee%02x', $color_number, $color_number);
|
2012-03-15 03:52:42 +01:00
|
|
|
$revision_time = phabricator_datetime(
|
|
|
|
$blame_dict[$rev]['epoch'],
|
|
|
|
$this->getRequest()->getUser());
|
2012-03-07 22:41:55 +01:00
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
|
2011-03-26 20:42:12 +01:00
|
|
|
$revision_link = self::renderRevision(
|
2011-04-01 03:28:24 +02:00
|
|
|
$drequest,
|
|
|
|
substr($rev, 0, 7));
|
2011-03-26 20:42:12 +01:00
|
|
|
|
2011-04-02 00:34:45 +02:00
|
|
|
if (!$file_query->getSupportsBlameOnBlame()) {
|
|
|
|
$prev_link = '';
|
|
|
|
} else {
|
|
|
|
$prev_rev = $file_query->getPrevRev($rev);
|
|
|
|
$path = $drequest->getPath();
|
|
|
|
$prev_link = self::renderBrowse(
|
|
|
|
$drequest,
|
|
|
|
$path,
|
|
|
|
"\xC2\xAB",
|
|
|
|
$prev_rev,
|
|
|
|
$n,
|
2012-01-27 23:00:12 +01:00
|
|
|
$selected,
|
|
|
|
'Blame previous revision');
|
2012-03-01 03:18:04 +01:00
|
|
|
$prev_link = phutil_render_tag(
|
|
|
|
'th',
|
|
|
|
array(
|
|
|
|
'class' => 'diffusion-wide-link',
|
|
|
|
'style' => 'background: '.$color.'; width: 2em;',
|
|
|
|
),
|
|
|
|
$prev_link);
|
2011-04-02 00:34:45 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 21:58:45 +02:00
|
|
|
if (isset($blame_dict[$rev]['handle'])) {
|
|
|
|
$author_link = $blame_dict[$rev]['handle']->renderLink();
|
|
|
|
} else {
|
|
|
|
$author_link = phutil_escape_html($blame_dict[$rev]['author']);
|
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
$blame_info =
|
2011-04-02 00:34:45 +02:00
|
|
|
$prev_link .
|
2012-03-15 03:52:42 +01:00
|
|
|
'<th style="background: '.$color.'; width: 12em;" title="'.
|
|
|
|
phutil_escape_html($revision_time).'">'.$revision_link.'</th>'.
|
2011-06-07 01:08:49 +02:00
|
|
|
'<th style="background: '.$color.'; width: 12em'.
|
2011-03-26 20:42:12 +01:00
|
|
|
'; font-weight: normal; color: #333;">'.$author_link.'</th>';
|
2011-04-01 03:28:24 +02:00
|
|
|
$last_rev = $rev;
|
2011-03-26 20:42:12 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-04-01 03:28:24 +02:00
|
|
|
$blame_info = null;
|
2011-03-26 20:42:12 +01:00
|
|
|
}
|
|
|
|
|
2011-04-01 03:28:24 +02:00
|
|
|
// Highlight the line of interest if needed.
|
2012-02-25 20:45:51 +01:00
|
|
|
if ($min_line > 0 && ($n >= $min_line && $n <= $max_line)) {
|
2011-03-26 20:42:12 +01:00
|
|
|
$tr = '<tr style="background: #ffff00;">';
|
2012-02-25 20:45:51 +01:00
|
|
|
if ($targ == '') {
|
|
|
|
$targ = '<a id="scroll_target"></a>';
|
|
|
|
Javelin::initBehavior('diffusion-jump-to',
|
|
|
|
array('target' => 'scroll_target'));
|
|
|
|
}
|
2011-03-26 20:42:12 +01:00
|
|
|
} else {
|
|
|
|
$tr = '<tr>';
|
|
|
|
$targ = null;
|
|
|
|
}
|
|
|
|
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
$href = $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'stable' => true,
|
|
|
|
));
|
|
|
|
$href = (string)$href;
|
|
|
|
|
|
|
|
$query_params = null;
|
|
|
|
if ($view) {
|
|
|
|
$query_params = '?view='.$view;
|
|
|
|
}
|
|
|
|
|
|
|
|
$link = phutil_render_tag(
|
2011-03-26 20:42:12 +01:00
|
|
|
'a',
|
|
|
|
array(
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
'href' => $href.'$'.$n.$query_params,
|
2011-03-26 20:42:12 +01:00
|
|
|
),
|
|
|
|
$n);
|
|
|
|
|
2012-03-01 03:18:04 +01:00
|
|
|
$rows[] = $tr.$blame_info.
|
Fix many encoding and architecture problems in Diffusion request and URI handling
Summary:
Diffusion request/uri handling is currently a big, hastily ported mess. In particular, it has:
- Tons and tons of duplicated code.
- Bugs with handling unusual branch and file names.
- An excessively large (and yet insufficiently expressive) API on DiffusionRequest, including a nonsensical concrete base class.
- Other tools were doing hacky things like passing ":" branch names.
This diff attempts to fix these issues.
- Make the base class abstract (it was concrete ONLY for "/diffusion/").
- Move all URI generation to DiffusionRequest. Make the core static. Add unit tests.
- Delete the 300 copies of URI generation code throughout Diffusion.
- Move all URI parsing to DiffusionRequest. Make the core static. Add unit tests.
- Add an appropriate static initializer for other callers.
- Convert all code calling `newFromAphrontRequestDictionary` outside of Diffusion to the new `newFromDictionary` API.
- Refactor static initializers to be sensibly-sized.
- Refactor derived DiffusionRequest classes to remove duplicated code.
- Properly encode branch names (fixes branches with "/", see <https://github.com/facebook/phabricator/issues/100>).
- Properly encode path names (fixes issues in D1742).
- Properly escape delimiter characters ";" and "$" in path names so files like "$100" are not interpreted as "line 100".
- Fix a couple warnings.
- Fix a couple lint issues.
- Fix a bug where we would not parse filenames with spaces in them correctly in the Git browse query.
- Fix a bug where Git change queries would fail unnecessarily.
- Provide or improve some documentation.
This thing is pretty gigantic but also kind of hard to split up. If it's unreasonably difficult to review, let me know and I can take a stab at it though.
This supplants D1742.
Test Plan:
- Used home, repository, branch, browse, change, history, diff (ajax), lastmodified (ajax) views of Diffusion.
- Used Owners typeaheads and search.
- Used diffusion.getrecentcommitsbypath method.
- Pushed a change to an absurdly-named file on an absurdly-named branch, everything worked properly.
{F9185}
Reviewers: nh, vrana, btrahan
Reviewed By: btrahan
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1921
2012-03-20 03:52:14 +01:00
|
|
|
'<th class="diffusion-wide-link">'.$link.'</th>'.
|
2012-03-01 03:18:04 +01:00
|
|
|
'<td>'.$targ.$line.'</td></tr>';
|
2011-03-26 20:42:12 +01:00
|
|
|
++$n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rows;
|
2011-03-08 18:54:55 +01:00
|
|
|
}
|
2011-04-01 03:28:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
private static function renderRevision(DiffusionRequest $drequest,
|
|
|
|
$revision) {
|
|
|
|
|
|
|
|
$callsign = $drequest->getCallsign();
|
|
|
|
|
|
|
|
$name = 'r'.$callsign.$revision;
|
|
|
|
return phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/'.$name,
|
|
|
|
),
|
|
|
|
$name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-04-01 22:42:00 +02:00
|
|
|
|
2011-04-02 00:34:45 +02:00
|
|
|
private static function renderBrowse(
|
|
|
|
DiffusionRequest $drequest,
|
|
|
|
$path,
|
|
|
|
$name = null,
|
|
|
|
$rev = null,
|
|
|
|
$line = null,
|
2012-01-27 23:00:12 +01:00
|
|
|
$view = null,
|
|
|
|
$title = null) {
|
2011-04-02 00:34:45 +02:00
|
|
|
|
|
|
|
$callsign = $drequest->getCallsign();
|
|
|
|
|
|
|
|
if ($name === null) {
|
|
|
|
$name = $path;
|
|
|
|
}
|
|
|
|
|
|
|
|
$at = null;
|
|
|
|
if ($rev) {
|
|
|
|
$at = ';'.$rev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($view) {
|
|
|
|
$view = '?view='.$view;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($line) {
|
|
|
|
$line = '$'.$line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => "/diffusion/{$callsign}/browse/{$path}{$at}{$line}{$view}",
|
2012-01-27 23:00:12 +01:00
|
|
|
'title' => $title,
|
2011-04-02 00:34:45 +02:00
|
|
|
),
|
|
|
|
$name
|
|
|
|
);
|
2011-04-01 22:42:00 +02:00
|
|
|
}
|
|
|
|
|
2012-03-20 03:52:24 +01:00
|
|
|
private function loadFileForData($path, $data) {
|
|
|
|
$hash = PhabricatorHash::digest($data);
|
|
|
|
|
|
|
|
$file = id(new PhabricatorFile())->loadOneWhere(
|
|
|
|
'contentHash = %s LIMIT 1',
|
|
|
|
$hash);
|
|
|
|
if (!$file) {
|
|
|
|
// We're just caching the data; this is always safe.
|
|
|
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
|
|
|
|
|
|
$file = PhabricatorFile::newFromFileData(
|
|
|
|
$data,
|
|
|
|
array(
|
|
|
|
'name' => basename($path),
|
|
|
|
));
|
|
|
|
|
|
|
|
unset($unguarded);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildRawResponse($path, $data) {
|
|
|
|
$file = $this->loadFileForData($path, $data);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($file->getBestURI());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildImageCorpus($file_uri) {
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Image');
|
|
|
|
$panel->addButton($this->renderEditButton());
|
|
|
|
$panel->appendChild(
|
|
|
|
phutil_render_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => $file_uri,
|
|
|
|
)));
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildBinaryCorpus($file_uri, $data) {
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Binary File');
|
|
|
|
$panel->addButton($this->renderEditButton());
|
|
|
|
$panel->appendChild(
|
|
|
|
'<p>'.
|
|
|
|
'This is a binary file. '.
|
|
|
|
'It is '.number_format(strlen($data)).' bytes in length.'.
|
|
|
|
'</p>');
|
|
|
|
$panel->addButton(
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $file_uri,
|
|
|
|
'class' => 'button green',
|
|
|
|
),
|
|
|
|
'Download Binary File...'));
|
|
|
|
return $panel;
|
|
|
|
}
|
|
|
|
|
2011-04-02 00:34:45 +02:00
|
|
|
|
2011-03-08 18:54:55 +01:00
|
|
|
}
|