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 @@ -81,34 +81,6 @@ final class DiffusionBrowseController extends DiffusionController { $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); @@ -122,6 +94,16 @@ final class DiffusionBrowseController extends DiffusionController { $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); 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 @@ -9,8 +9,6 @@ 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'); 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 @@ -110,6 +110,14 @@ final class DiffusionRepositoryController extends DiffusionController { $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( 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,7 +1,7 @@ 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 @@ -6,8 +6,14 @@ +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');