@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Show README on repository screen in Diffusion

Summary:
- Show README on the repository screen.
- Move README to the bottom of the page for both repository and browse screens.
- Support "README.rainbow".

Test Plan: Looked at repository, browse screens. Made a "README.rainbow".

Reviewers: btrahan, vrana, jungejason

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1104

Differential Revision: https://secure.phabricator.com/D2336

+86 -31
+10 -28
src/applications/diffusion/controller/browse/DiffusionBrowseController.php
··· 81 81 $phids = array_keys($phids); 82 82 $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); 83 83 84 - if ($readme) { 85 - $readme_request = DiffusionRequest::newFromDictionary( 86 - array( 87 - 'repository' => $drequest->getRepository(), 88 - 'commit' => $drequest->getStableCommitName(), 89 - 'path' => $readme->getFullPath(), 90 - )); 91 - 92 - $content_query = DiffusionFileContentQuery::newFromDiffusionRequest( 93 - $readme_request); 94 - $content_query->loadFileContent(); 95 - $readme_content = $content_query->getRawData(); 96 - 97 - if (preg_match('/.txt$/', $readme->getPath())) { 98 - $readme_content = phutil_escape_html($readme_content); 99 - $readme_content = nl2br($readme_content); 100 - } else { 101 - // Markup extensionless files as remarkup so we get links and such. 102 - $readme_content = $this->markupText($readme_content); 103 - } 104 - 105 - $readme_panel = new AphrontPanelView(); 106 - $readme_panel->setHeader('README'); 107 - $readme_panel->appendChild($readme_content); 108 - 109 - $content[] = $readme_panel; 110 - } 111 - 112 84 $browse_table = new DiffusionBrowseTableView(); 113 85 $browse_table->setDiffusionRequest($drequest); 114 86 $browse_table->setHandles($handles); ··· 121 93 } 122 94 123 95 $content[] = $this->buildOpenRevisions(); 96 + 97 + $readme_content = $browse_query->renderReadme($results); 98 + if ($readme_content) { 99 + $readme_panel = new AphrontPanelView(); 100 + $readme_panel->setHeader('README'); 101 + $readme_panel->appendChild($readme_content); 102 + 103 + $content[] = $readme_panel; 104 + } 105 + 124 106 125 107 $nav = $this->buildSideNav('browse', false); 126 108 $nav->appendChild($content);
-2
src/applications/diffusion/controller/browse/__init__.php
··· 9 9 phutil_require_module('phabricator', 'applications/diffusion/controller/base'); 10 10 phutil_require_module('phabricator', 'applications/diffusion/controller/file'); 11 11 phutil_require_module('phabricator', 'applications/diffusion/query/browse/base'); 12 - phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base'); 13 - phutil_require_module('phabricator', 'applications/diffusion/request/base'); 14 12 phutil_require_module('phabricator', 'applications/diffusion/view/browsetable'); 15 13 phutil_require_module('phabricator', 'applications/diffusion/view/emptyresult'); 16 14 phutil_require_module('phabricator', 'applications/markup/engine');
+8
src/applications/diffusion/controller/repository/DiffusionRepositoryController.php
··· 110 110 $content[] = $branch_panel; 111 111 } 112 112 113 + $readme = $browse_query->renderReadme($browse_results); 114 + if ($readme) { 115 + $panel = new AphrontPanelView(); 116 + $panel->setHeader('README'); 117 + $panel->appendChild($readme); 118 + $content[] = $panel; 119 + } 120 + 113 121 return $this->buildStandardPageResponse( 114 122 $content, 115 123 array(
+62 -1
src/applications/diffusion/query/browse/base/DiffusionBrowseQuery.php
··· 1 1 <?php 2 2 3 3 /* 4 - * Copyright 2011 Facebook, Inc. 4 + * Copyright 2012 Facebook, Inc. 5 5 * 6 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 7 * you may not use this file except in compliance with the License. ··· 91 91 final public function needValidityOnly($need_validity_only) { 92 92 $this->validityOnly = $need_validity_only; 93 93 return $this; 94 + } 95 + 96 + final public function renderReadme(array $results) { 97 + $drequest = $this->getRequest(); 98 + 99 + $readme = null; 100 + foreach ($results as $result) { 101 + $path = $result->getPath(); 102 + if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow)$/i', $path)) { 103 + $readme = $result; 104 + break; 105 + } 106 + } 107 + 108 + if (!$readme) { 109 + return null; 110 + } 111 + 112 + $readme_request = DiffusionRequest::newFromDictionary( 113 + array( 114 + 'repository' => $drequest->getRepository(), 115 + 'commit' => $drequest->getStableCommitName(), 116 + 'path' => $readme->getFullPath(), 117 + )); 118 + 119 + $content_query = DiffusionFileContentQuery::newFromDiffusionRequest( 120 + $readme_request); 121 + $content_query->loadFileContent(); 122 + $readme_content = $content_query->getRawData(); 123 + 124 + 125 + if (preg_match('/\\.txt$/', $readme->getPath())) { 126 + $readme_content = phutil_escape_html($readme_content); 127 + $readme_content = nl2br($readme_content); 128 + 129 + $class = null; 130 + } else if (preg_match('/\\.rainbow$/', $readme->getPath())) { 131 + $highlighter = new PhutilRainbowSyntaxHighlighter(); 132 + $readme_content = $highlighter 133 + ->getHighlightFuture($readme_content) 134 + ->resolve(); 135 + $readme_content = nl2br($readme_content); 136 + 137 + require_celerity_resource('syntax-highlighting-css'); 138 + $class = 'remarkup-code'; 139 + } else { 140 + // Markup extensionless files as remarkup so we get links and such. 141 + $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine(); 142 + $readme_content = $engine->markupText($readme_content); 143 + 144 + $class = 'phabricator-remarkup'; 145 + } 146 + 147 + $readme_content = phutil_render_tag( 148 + 'div', 149 + array( 150 + 'class' => $class, 151 + ), 152 + $readme_content); 153 + 154 + return $readme_content; 94 155 } 95 156 96 157 abstract protected function executeQuery();
+6
src/applications/diffusion/query/browse/base/__init__.php
··· 6 6 7 7 8 8 9 + phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base'); 10 + phutil_require_module('phabricator', 'applications/diffusion/request/base'); 11 + phutil_require_module('phabricator', 'applications/markup/engine'); 9 12 phutil_require_module('phabricator', 'applications/repository/constants/repositorytype'); 13 + phutil_require_module('phabricator', 'infrastructure/celerity/api'); 10 14 15 + phutil_require_module('phutil', 'markup'); 16 + phutil_require_module('phutil', 'markup/syntax/highlighter/rainbow'); 11 17 phutil_require_module('phutil', 'symbols'); 12 18 13 19