[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class PhragmentController extends PhabricatorController { 4 5 protected function loadParentFragments($path) { 6 $components = explode('/', $path); 7 8 $combinations = array(); 9 $current = ''; 10 foreach ($components as $component) { 11 $current .= '/'.$component; 12 $current = trim($current, '/'); 13 if (trim($current) === '') { 14 continue; 15 } 16 17 $combinations[] = $current; 18 } 19 20 $fragments = array(); 21 $results = id(new PhragmentFragmentQuery()) 22 ->setViewer($this->getRequest()->getUser()) 23 ->needLatestVersion(true) 24 ->withPaths($combinations) 25 ->execute(); 26 foreach ($combinations as $combination) { 27 $found = false; 28 foreach ($results as $fragment) { 29 if ($fragment->getPath() === $combination) { 30 $fragments[] = $fragment; 31 $found = true; 32 break; 33 } 34 } 35 if (!$found) { 36 return null; 37 } 38 } 39 return $fragments; 40 } 41 42 protected function buildApplicationCrumbsWithPath(array $fragments) { 43 $crumbs = $this->buildApplicationCrumbs(); 44 $crumbs->addTextCrumb('/', '/phragment/'); 45 foreach ($fragments as $parent) { 46 $crumbs->addTextCrumb( 47 $parent->getName(), 48 '/phragment/browse/'.$parent->getPath()); 49 } 50 return $crumbs; 51 } 52 53 protected function createCurrentFragmentView($fragment, $is_history_view) { 54 if ($fragment === null) { 55 return null; 56 } 57 58 $viewer = $this->getRequest()->getUser(); 59 60 $phids = array(); 61 $phids[] = $fragment->getLatestVersionPHID(); 62 63 $snapshot_phids = array(); 64 $snapshots = id(new PhragmentSnapshotQuery()) 65 ->setViewer($viewer) 66 ->withPrimaryFragmentPHIDs(array($fragment->getPHID())) 67 ->execute(); 68 foreach ($snapshots as $snapshot) { 69 $phids[] = $snapshot->getPHID(); 70 $snapshot_phids[] = $snapshot->getPHID(); 71 } 72 73 $this->loadHandles($phids); 74 75 $file = null; 76 $file_uri = null; 77 if (!$fragment->isDirectory()) { 78 $file = id(new PhabricatorFileQuery()) 79 ->setViewer($viewer) 80 ->withPHIDs(array($fragment->getLatestVersion()->getFilePHID())) 81 ->executeOne(); 82 if ($file !== null) { 83 $file_uri = $file->getDownloadURI(); 84 } 85 } 86 87 $header = id(new PHUIHeaderView()) 88 ->setHeader($fragment->getName()) 89 ->setPolicyObject($fragment) 90 ->setUser($viewer); 91 92 $can_edit = PhabricatorPolicyFilter::hasCapability( 93 $viewer, 94 $fragment, 95 PhabricatorPolicyCapability::CAN_EDIT); 96 97 $zip_uri = $this->getApplicationURI('zip/'.$fragment->getPath()); 98 99 $actions = id(new PhabricatorActionListView()) 100 ->setUser($viewer) 101 ->setObject($fragment) 102 ->setObjectURI($fragment->getURI()); 103 $actions->addAction( 104 id(new PhabricatorActionView()) 105 ->setName(pht('Download Fragment')) 106 ->setHref($this->isCorrectlyConfigured() ? $file_uri : null) 107 ->setDisabled($file === null || !$this->isCorrectlyConfigured()) 108 ->setIcon('fa-download')); 109 $actions->addAction( 110 id(new PhabricatorActionView()) 111 ->setName(pht('Download Contents as ZIP')) 112 ->setHref($this->isCorrectlyConfigured() ? $zip_uri : null) 113 ->setDisabled(!$this->isCorrectlyConfigured()) 114 ->setIcon('fa-floppy-o')); 115 if (!$fragment->isDirectory()) { 116 $actions->addAction( 117 id(new PhabricatorActionView()) 118 ->setName(pht('Update Fragment')) 119 ->setHref($this->getApplicationURI('update/'.$fragment->getPath())) 120 ->setDisabled(!$can_edit) 121 ->setWorkflow(!$can_edit) 122 ->setIcon('fa-refresh')); 123 } else { 124 $actions->addAction( 125 id(new PhabricatorActionView()) 126 ->setName(pht('Convert to File')) 127 ->setHref($this->getApplicationURI('update/'.$fragment->getPath())) 128 ->setDisabled(!$can_edit) 129 ->setWorkflow(!$can_edit) 130 ->setIcon('fa-file-o')); 131 } 132 $actions->addAction( 133 id(new PhabricatorActionView()) 134 ->setName(pht('Set Fragment Policies')) 135 ->setHref($this->getApplicationURI('policy/'.$fragment->getPath())) 136 ->setDisabled(!$can_edit) 137 ->setWorkflow(!$can_edit) 138 ->setIcon('fa-asterisk')); 139 if ($is_history_view) { 140 $actions->addAction( 141 id(new PhabricatorActionView()) 142 ->setName(pht('View Child Fragments')) 143 ->setHref($this->getApplicationURI('browse/'.$fragment->getPath())) 144 ->setIcon('fa-search-plus')); 145 } else { 146 $actions->addAction( 147 id(new PhabricatorActionView()) 148 ->setName(pht('View History')) 149 ->setHref($this->getApplicationURI('history/'.$fragment->getPath())) 150 ->setIcon('fa-list')); 151 } 152 $actions->addAction( 153 id(new PhabricatorActionView()) 154 ->setName(pht('Create Snapshot')) 155 ->setHref($this->getApplicationURI( 156 'snapshot/create/'.$fragment->getPath())) 157 ->setDisabled(!$can_edit) 158 ->setWorkflow(!$can_edit) 159 ->setIcon('fa-files-o')); 160 $actions->addAction( 161 id(new PhabricatorActionView()) 162 ->setName(pht('Promote Snapshot to Here')) 163 ->setHref($this->getApplicationURI( 164 'snapshot/promote/latest/'.$fragment->getPath())) 165 ->setWorkflow(true) 166 ->setDisabled(!$can_edit) 167 ->setIcon('fa-arrow-circle-up')); 168 169 $properties = id(new PHUIPropertyListView()) 170 ->setUser($viewer) 171 ->setObject($fragment) 172 ->setActionList($actions); 173 174 if (!$fragment->isDirectory()) { 175 if ($fragment->isDeleted()) { 176 $properties->addProperty( 177 pht('Type'), 178 pht('File (Deleted)')); 179 } else { 180 $properties->addProperty( 181 pht('Type'), 182 pht('File')); 183 } 184 $properties->addProperty( 185 pht('Latest Version'), 186 $this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); 187 } else { 188 $properties->addProperty( 189 pht('Type'), 190 pht('Directory')); 191 } 192 193 if (count($snapshot_phids) > 0) { 194 $properties->addProperty( 195 pht('Snapshots'), 196 $this->renderHandlesForPHIDs($snapshot_phids)); 197 } 198 199 return id(new PHUIObjectBoxView()) 200 ->setHeader($header) 201 ->addPropertyList($properties); 202 } 203 204 function renderConfigurationWarningIfRequired() { 205 $alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain'); 206 if ($alt === null) { 207 return id(new AphrontErrorView()) 208 ->setTitle(pht('security.alternate-file-domain must be configured!')) 209 ->setSeverity(AphrontErrorView::SEVERITY_ERROR) 210 ->appendChild(phutil_tag('p', array(), pht( 211 'Because Phragment generates files (such as ZIP archives and '. 212 'patches) as they are requested, it requires that you configure '. 213 'the `security.alternate-file-domain` option. This option on it\'s '. 214 'own will also provide additional security when serving files '. 215 'across Phabricator.'))); 216 } 217 return null; 218 } 219 220 /** 221 * We use this to disable the download links if the alternate domain is 222 * not configured correctly. Although the download links will mostly work 223 * for logged in users without an alternate domain, the behaviour is 224 * reasonably non-consistent and will deny public users, even if policies 225 * are configured otherwise (because the Files app does not support showing 226 * the info page to viewers who are not logged in). 227 */ 228 function isCorrectlyConfigured() { 229 $alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain'); 230 return $alt !== null; 231 } 232 233 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |