Path: blob/master/src/applications/differential/view/DifferentialChangesetDetailView.php
12256 views
<?php12final class DifferentialChangesetDetailView extends AphrontView {34private $changeset;5private $buttons = array();6private $editable;7private $symbolIndex;8private $id;9private $vsChangesetID;10private $renderURI;11private $renderingRef;12private $autoload;13private $repository;14private $diff;15private $changesetResponse;16private $branch;1718public function setAutoload($autoload) {19$this->autoload = $autoload;20return $this;21}2223public function getAutoload() {24return $this->autoload;25}2627public function setRenderingRef($rendering_ref) {28$this->renderingRef = $rendering_ref;29return $this;30}3132public function getRenderingRef() {33return $this->renderingRef;34}3536public function setChangesetResponse(PhabricatorChangesetResponse $response) {37$this->changesetResponse = $response;38return $this;39}4041public function getChangesetResponse() {42return $this->changesetResponse;43}4445public function setRenderURI($render_uri) {46$this->renderURI = $render_uri;47return $this;48}4950public function getRenderURI() {51return $this->renderURI;52}5354public function setChangeset($changeset) {55$this->changeset = $changeset;56return $this;57}5859public function addButton($button) {60$this->buttons[] = $button;61return $this;62}6364public function setEditable($editable) {65$this->editable = $editable;66return $this;67}6869public function setSymbolIndex($symbol_index) {70$this->symbolIndex = $symbol_index;71return $this;72}7374public function setBranch($branch) {75$this->branch = $branch;76return $this;77}7879public function getBranch() {80return $this->branch;81}8283public function getID() {84if (!$this->id) {85$this->id = celerity_generate_unique_node_id();86}87return $this->id;88}8990public function setID($id) {91$this->id = $id;92return $this;93}9495public function setVsChangesetID($vs_changeset_id) {96$this->vsChangesetID = $vs_changeset_id;97return $this;98}99100public function getVsChangesetID() {101return $this->vsChangesetID;102}103104public function render() {105$viewer = $this->getViewer();106107$this->requireResource('differential-changeset-view-css');108$this->requireResource('syntax-highlighting-css');109110Javelin::initBehavior('phabricator-oncopy', array());111112$changeset = $this->changeset;113$class = 'differential-changeset';114if (!$this->editable) {115$class .= ' differential-changeset-immutable';116}117118$buttons = null;119if ($this->buttons) {120$buttons = phutil_tag(121'div',122array(123'class' => 'differential-changeset-buttons',124),125$this->buttons);126}127128$id = $this->getID();129130if ($this->symbolIndex) {131Javelin::initBehavior(132'repository-crossreference',133array(134'container' => $id,135) + $this->symbolIndex);136}137138$display_filename = $changeset->getDisplayFilename();139$display_icon = FileTypeIcon::getFileIcon($display_filename);140$icon = id(new PHUIIconView())141->setIcon($display_icon);142143$changeset_id = $this->changeset->getID();144145$vs_id = $this->getVsChangesetID();146if (!$vs_id) {147// Showing a changeset normally.148$left_id = $changeset_id;149$right_id = $changeset_id;150} else if ($vs_id == -1) {151// Showing a synthetic "deleted" changeset for a file which was152// removed between changes.153$left_id = $changeset_id;154$right_id = null;155} else {156// Showing a diff-of-diffs.157$left_id = $vs_id;158$right_id = $changeset_id;159}160161// In the persistent banner, emphasize the current filename.162$path_part = dirname($display_filename);163$file_part = basename($display_filename);164$display_parts = array();165if (strlen($path_part)) {166$path_part = $path_part.'/';167$display_parts[] = phutil_tag(168'span',169array(170'class' => 'diff-banner-path',171),172$path_part);173}174$display_parts[] = phutil_tag(175'span',176array(177'class' => 'diff-banner-file',178),179$file_part);180181$response = $this->getChangesetResponse();182if ($response) {183$is_loaded = true;184$changeset_markup = $response->getRenderedChangeset();185$changeset_state = $response->getChangesetState();186} else {187$is_loaded = false;188$changeset_markup = null;189$changeset_state = null;190}191192$path_parts = trim($display_filename, '/');193$path_parts = explode('/', $path_parts);194195$show_path_uri = null;196$show_directory_uri = null;197198$repository = $this->getRepository();199if ($repository) {200$diff = $this->getDiff();201if ($diff) {202$repo_path = $changeset->getAbsoluteRepositoryPath($repository, $diff);203204$repo_dir = dirname($repo_path);205if ($repo_dir === $repo_path) {206$repo_dir = null;207}208209$show_path_uri = $repository->getDiffusionBrowseURIForPath(210$viewer,211$repo_path,212idx($changeset->getMetadata(), 'line:first'),213$this->getBranch());214215if ($repo_dir !== null) {216$repo_dir = rtrim($repo_dir, '/').'/';217218$show_directory_uri = $repository->getDiffusionBrowseURIForPath(219$viewer,220$repo_dir,221null,222$this->getBranch());223}224}225}226227if ($show_path_uri) {228$show_path_uri = phutil_string_cast($show_path_uri);229}230231if ($show_directory_uri) {232$show_directory_uri = phutil_string_cast($show_directory_uri);233}234235return javelin_tag(236'div',237array(238'sigil' => 'differential-changeset',239'meta' => array(240'left' => $left_id,241'right' => $right_id,242'renderURI' => $this->getRenderURI(),243'ref' => $this->getRenderingRef(),244'autoload' => $this->getAutoload(),245'displayPath' => hsprintf('%s', $display_parts),246'icon' => $display_icon,247'pathParts' => $path_parts,248'symbolPath' => $display_filename,249250'pathIconIcon' => $changeset->getPathIconIcon(),251'pathIconColor' => $changeset->getPathIconColor(),252'isLowImportance' => $changeset->getIsLowImportanceChangeset(),253'isOwned' => $changeset->getIsOwnedChangeset(),254255'editorURITemplate' => $this->getEditorURITemplate(),256'editorConfigureURI' => $this->getEditorConfigureURI(),257258'loaded' => $is_loaded,259'changesetState' => $changeset_state,260261'showPathURI' => $show_path_uri,262'showDirectoryURI' => $show_directory_uri,263),264'class' => $class,265'id' => $id,266),267array(268id(new PhabricatorAnchorView())269->setAnchorName($changeset->getAnchorName())270->setNavigationMarker(true)271->render(),272$buttons,273javelin_tag(274'h1',275array(276'class' => 'differential-file-icon-header',277'sigil' => 'changeset-header',278),279array(280$icon,281javelin_tag(282'span',283array(284'class' => 'differential-changeset-path-name',285'sigil' => 'changeset-header-path-name',286),287$display_filename),288)),289javelin_tag(290'div',291array(292'class' => 'changeset-view-content',293'sigil' => 'changeset-view-content',294),295array(296$changeset_markup,297$this->renderChildren(),298)),299));300}301302public function setRepository(PhabricatorRepository $repository) {303$this->repository = $repository;304return $this;305}306307public function getRepository() {308return $this->repository;309}310311public function getChangeset() {312return $this->changeset;313}314315public function setDiff(DifferentialDiff $diff) {316$this->diff = $diff;317return $this;318}319320public function getDiff() {321return $this->diff;322}323324private function getEditorURITemplate() {325$repository = $this->getRepository();326if (!$repository) {327return null;328}329330$viewer = $this->getViewer();331332$link_engine = PhabricatorEditorURIEngine::newForViewer($viewer);333if (!$link_engine) {334return null;335}336337$link_engine->setRepository($repository);338339$changeset = $this->getChangeset();340$diff = $this->getDiff();341342$path = $changeset->getAbsoluteRepositoryPath($repository, $diff);343$path = ltrim($path, '/');344345return $link_engine->getURITokensForPath($path);346}347348private function getEditorConfigureURI() {349$viewer = $this->getViewer();350351if (!$viewer->isLoggedIn()) {352return null;353}354355return '/settings/panel/editor/';356}357358}359360361