Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
index ca20c59a91..963840bf64 100644
--- a/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
+++ b/src/applications/diffusion/controller/browse/DiffusionBrowseController.php
@@ -1,152 +1,134 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* 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.
*/
final class DiffusionBrowseController extends DiffusionController {
public function processRequest() {
$drequest = $this->diffusionRequest;
$browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
$results = $browse_query->loadPaths();
$content = array();
$content[] = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
if ($drequest->getTagContent()) {
$title = 'Tag: '.$drequest->getSymbolicCommit();
$tag_view = new AphrontPanelView();
$tag_view->setHeader(phutil_escape_html($title));
$tag_view->appendChild(
$this->markupText($drequest->getTagContent()));
$content[] = $tag_view;
}
if (!$results) {
if ($browse_query->getReasonForEmptyResultSet() ==
DiffusionBrowseQuery::REASON_IS_FILE) {
$controller = new DiffusionBrowseFileController($this->getRequest());
$controller->setDiffusionRequest($drequest);
return $this->delegateToController($controller);
}
$empty_result = new DiffusionEmptyResultView();
$empty_result->setDiffusionRequest($drequest);
$empty_result->setBrowseQuery($browse_query);
$empty_result->setView($this->getRequest()->getStr('view'));
$content[] = $empty_result;
} else {
$readme = null;
$phids = array();
foreach ($results as $result) {
$data = $result->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
$path = $result->getPath();
if (preg_match('/^readme(|\.txt|\.remarkup)$/i', $path)) {
$readme = $result;
}
}
$phids = array_keys($phids);
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
- if ($readme) {
- $readme_request = DiffusionRequest::newFromDictionary(
- array(
- 'repository' => $drequest->getRepository(),
- 'commit' => $drequest->getStableCommitName(),
- 'path' => $readme->getFullPath(),
- ));
-
- $content_query = DiffusionFileContentQuery::newFromDiffusionRequest(
- $readme_request);
- $content_query->loadFileContent();
- $readme_content = $content_query->getRawData();
-
- if (preg_match('/.txt$/', $readme->getPath())) {
- $readme_content = phutil_escape_html($readme_content);
- $readme_content = nl2br($readme_content);
- } else {
- // Markup extensionless files as remarkup so we get links and such.
- $readme_content = $this->markupText($readme_content);
- }
-
- $readme_panel = new AphrontPanelView();
- $readme_panel->setHeader('README');
- $readme_panel->appendChild($readme_content);
-
- $content[] = $readme_panel;
- }
-
$browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles);
$browse_table->setPaths($results);
$browse_panel = new AphrontPanelView();
$browse_panel->appendChild($browse_table);
$content[] = $browse_panel;
}
$content[] = $this->buildOpenRevisions();
+ $readme_content = $browse_query->renderReadme($results);
+ if ($readme_content) {
+ $readme_panel = new AphrontPanelView();
+ $readme_panel->setHeader('README');
+ $readme_panel->appendChild($readme_content);
+
+ $content[] = $readme_panel;
+ }
+
+
$nav = $this->buildSideNav('browse', false);
$nav->appendChild($content);
return $this->buildStandardPageResponse(
$nav,
array(
'title' => array(
nonempty(basename($drequest->getPath()), '/'),
$drequest->getRepository()->getCallsign().' Repository',
),
));
}
private function markupText($text) {
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
$text = $engine->markupText($text);
$text = phutil_render_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$text);
return $text;
}
}
diff --git a/src/applications/diffusion/controller/browse/__init__.php b/src/applications/diffusion/controller/browse/__init__.php
index 1e19848118..fd95903c27 100644
--- a/src/applications/diffusion/controller/browse/__init__.php
+++ b/src/applications/diffusion/controller/browse/__init__.php
@@ -1,24 +1,22 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/controller/file');
phutil_require_module('phabricator', 'applications/diffusion/query/browse/base');
-phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base');
-phutil_require_module('phabricator', 'applications/diffusion/request/base');
phutil_require_module('phabricator', 'applications/diffusion/view/browsetable');
phutil_require_module('phabricator', 'applications/diffusion/view/emptyresult');
phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionBrowseController.php');
diff --git a/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php b/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
index 114efa8335..8863be0b8c 100644
--- a/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
+++ b/src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
@@ -1,211 +1,219 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* 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.
*/
final class DiffusionRepositoryController extends DiffusionController {
public function processRequest() {
$drequest = $this->diffusionRequest;
$content = array();
$crumbs = $this->buildCrumbs();
$content[] = $crumbs;
$content[] = $this->buildPropertiesTable($drequest->getRepository());
$history_query = DiffusionHistoryQuery::newFromDiffusionRequest(
$drequest);
$history_query->setLimit(15);
$history_query->needParents(true);
$history = $history_query->loadHistory();
$browse_query = DiffusionBrowseQuery::newFromDiffusionRequest($drequest);
$browse_results = $browse_query->loadPaths();
$phids = array();
foreach ($history as $item) {
$data = $item->getCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
}
foreach ($browse_results as $item) {
$data = $item->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
}
$phids = array_keys($phids);
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$history_table = new DiffusionHistoryTableView();
$history_table->setDiffusionRequest($drequest);
$history_table->setHandles($handles);
$history_table->setHistory($history);
$history_table->setParents($history_query->getParents());
$history_table->setIsHead(true);
$callsign = $drequest->getRepository()->getCallsign();
$all = phutil_render_tag(
'a',
array(
'href' => "/diffusion/{$callsign}/history/",
),
'View Full Commit History');
$panel = new AphrontPanelView();
$panel->setHeader("Recent Commits &middot; {$all}");
$panel->appendChild($history_table);
$content[] = $panel;
$browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles);
$browse_table->setPaths($browse_results);
$browse_panel = new AphrontPanelView();
$browse_panel->setHeader('Browse Repository');
$browse_panel->appendChild($browse_table);
$content[] = $browse_panel;
$content[] = $this->buildTagListTable($drequest);
if ($drequest->getBranch() !== null) {
$branch_query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
$branches = $branch_query->loadBranches();
$branch_table = new DiffusionBranchTableView();
$branch_table->setDiffusionRequest($drequest);
$branch_table->setBranches($branches);
$branch_panel = new AphrontPanelView();
$branch_panel->setHeader('Branches');
$branch_panel->appendChild($branch_table);
$content[] = $branch_panel;
}
+ $readme = $browse_query->renderReadme($browse_results);
+ if ($readme) {
+ $panel = new AphrontPanelView();
+ $panel->setHeader('README');
+ $panel->appendChild($readme);
+ $content[] = $panel;
+ }
+
return $this->buildStandardPageResponse(
$content,
array(
'title' => $drequest->getRepository()->getName(),
));
}
private function buildPropertiesTable(PhabricatorRepository $repository) {
$properties = array();
$properties['Name'] = $repository->getName();
$properties['Callsign'] = $repository->getCallsign();
$properties['Description'] = $repository->getDetail('description');
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$properties['Clone URI'] = $repository->getPublicRemoteURI();
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$properties['Repository Root'] = $repository->getPublicRemoteURI();
break;
}
$rows = array();
foreach ($properties as $key => $value) {
$rows[] = array(
phutil_escape_html($key),
phutil_escape_html($value));
}
$table = new AphrontTableView($rows);
$table->setColumnClasses(
array(
'header',
'wide',
));
$panel = new AphrontPanelView();
$panel->setHeader('Repository Properties');
$panel->appendChild($table);
return $panel;
}
private function buildTagListTable(DiffusionRequest $drequest) {
$tag_limit = 25;
$query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
$query->setLimit($tag_limit + 1);
$tags = $query->loadTags();
if (!$tags) {
return null;
}
$more_tags = (count($tags) > $tag_limit);
$tags = array_slice($tags, 0, $tag_limit);
$commits = id(new PhabricatorAuditCommitQuery())
->withIdentifiers(
$drequest->getRepository()->getID(),
mpull($tags, 'getCommitIdentifier'))
->needCommitData(true)
->execute();
$view = new DiffusionTagListView();
$view->setDiffusionRequest($drequest);
$view->setTags($tags);
$view->setUser($this->getRequest()->getUser());
$view->setCommits($commits);
$phids = $view->getRequiredHandlePHIDs();
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$view->setHandles($handles);
$panel = new AphrontPanelView();
$panel->setHeader('Tags');
if ($more_tags) {
$panel->setCaption('Showing the '.$tag_limit.' most recent tags.');
}
$panel->addButton(
phutil_render_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'tags',
)),
'class' => 'grey button',
),
"Show All Tags \xC2\xBB"));
$panel->appendChild($view);
return $panel;
}
}
diff --git a/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php b/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
index 61603c1a93..4c38efcc62 100644
--- a/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
+++ b/src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
@@ -1,97 +1,158 @@
<?php
/*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
*
* 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.
*/
abstract class DiffusionBrowseQuery {
private $request;
protected $reason;
protected $existedAtCommit;
protected $deletedAtCommit;
protected $validityOnly;
const REASON_IS_FILE = 'is-file';
const REASON_IS_DELETED = 'is-deleted';
const REASON_IS_NONEXISTENT = 'nonexistent';
const REASON_BAD_COMMIT = 'bad-commit';
const REASON_IS_EMPTY = 'empty';
const REASON_IS_UNTRACKED_PARENT = 'untracked-parent';
final private function __construct() {
// <private>
}
final public static function newFromDiffusionRequest(
DiffusionRequest $request) {
$repository = $request->getRepository();
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
// TODO: Verify local-path?
$class = 'DiffusionGitBrowseQuery';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$class = 'DiffusionMercurialBrowseQuery';
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$class = 'DiffusionSvnBrowseQuery';
break;
default:
throw new Exception("Unsupported VCS!");
}
PhutilSymbolLoader::loadClass($class);
$query = new $class();
$query->request = $request;
return $query;
}
final protected function getRequest() {
return $this->request;
}
final public function getReasonForEmptyResultSet() {
return $this->reason;
}
final public function getExistedAtCommit() {
return $this->existedAtCommit;
}
final public function getDeletedAtCommit() {
return $this->deletedAtCommit;
}
final public function loadPaths() {
return $this->executeQuery();
}
final public function shouldOnlyTestValidity() {
return $this->validityOnly;
}
final public function needValidityOnly($need_validity_only) {
$this->validityOnly = $need_validity_only;
return $this;
}
+ final public function renderReadme(array $results) {
+ $drequest = $this->getRequest();
+
+ $readme = null;
+ foreach ($results as $result) {
+ $path = $result->getPath();
+ if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow)$/i', $path)) {
+ $readme = $result;
+ break;
+ }
+ }
+
+ if (!$readme) {
+ return null;
+ }
+
+ $readme_request = DiffusionRequest::newFromDictionary(
+ array(
+ 'repository' => $drequest->getRepository(),
+ 'commit' => $drequest->getStableCommitName(),
+ 'path' => $readme->getFullPath(),
+ ));
+
+ $content_query = DiffusionFileContentQuery::newFromDiffusionRequest(
+ $readme_request);
+ $content_query->loadFileContent();
+ $readme_content = $content_query->getRawData();
+
+
+ if (preg_match('/\\.txt$/', $readme->getPath())) {
+ $readme_content = phutil_escape_html($readme_content);
+ $readme_content = nl2br($readme_content);
+
+ $class = null;
+ } else if (preg_match('/\\.rainbow$/', $readme->getPath())) {
+ $highlighter = new PhutilRainbowSyntaxHighlighter();
+ $readme_content = $highlighter
+ ->getHighlightFuture($readme_content)
+ ->resolve();
+ $readme_content = nl2br($readme_content);
+
+ require_celerity_resource('syntax-highlighting-css');
+ $class = 'remarkup-code';
+ } else {
+ // Markup extensionless files as remarkup so we get links and such.
+ $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
+ $readme_content = $engine->markupText($readme_content);
+
+ $class = 'phabricator-remarkup';
+ }
+
+ $readme_content = phutil_render_tag(
+ 'div',
+ array(
+ 'class' => $class,
+ ),
+ $readme_content);
+
+ return $readme_content;
+ }
+
abstract protected function executeQuery();
}
diff --git a/src/applications/diffusion/query/browse/base/__init__.php b/src/applications/diffusion/query/browse/base/__init__.php
index 3e2ddb571f..6eec942c39 100644
--- a/src/applications/diffusion/query/browse/base/__init__.php
+++ b/src/applications/diffusion/query/browse/base/__init__.php
@@ -1,14 +1,20 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
+phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base');
+phutil_require_module('phabricator', 'applications/diffusion/request/base');
+phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
+phutil_require_module('phabricator', 'infrastructure/celerity/api');
+phutil_require_module('phutil', 'markup');
+phutil_require_module('phutil', 'markup/syntax/highlighter/rainbow');
phutil_require_module('phutil', 'symbols');
phutil_require_source('DiffusionBrowseQuery.php');

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 15, 3:44 PM (18 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
338107
Default Alt Text
(19 KB)

Event Timeline