diff --git a/src/applications/differential/view/DifferentialChangesetListView.php b/src/applications/differential/view/DifferentialChangesetListView.php index a819390bfb..289dd23ff7 100644 --- a/src/applications/differential/view/DifferentialChangesetListView.php +++ b/src/applications/differential/view/DifferentialChangesetListView.php @@ -1,311 +1,316 @@ changesets = $changesets; return $this; } public function setVisibleChangesets($visible_changesets) { $this->visibleChangesets = $visible_changesets; return $this; } public function setInlineCommentControllerURI($uri) { $this->inlineURI = $uri; return $this; } public function setUser(PhabricatorUser $user) { $this->user = $user; return $this; } public function setRepository(PhabricatorRepository $repository) { $this->repository = $repository; return $this; } public function setDiff(DifferentialDiff $diff) { $this->diff = $diff; return $this; } public function setRenderingReferences(array $references) { $this->references = $references; return $this; } public function setSymbolIndexes(array $indexes) { $this->symbolIndexes = $indexes; return $this; } public function setRenderURI($render_uri) { $this->renderURI = $render_uri; return $this; } public function setWhitespace($whitespace) { $this->whitespace = $whitespace; return $this; } public function setVsMap(array $vs_map) { $this->vsMap = $vs_map; return $this; } public function getVsMap() { return $this->vsMap; } public function setStandaloneURI($uri) { $this->standaloneURI = $uri; return $this; } public function setRawFileURIs($l, $r) { $this->leftRawFileURI = $l; $this->rightRawFileURI = $r; return $this; } public function render() { require_celerity_resource('differential-changeset-view-css'); $changesets = $this->changesets; Javelin::initBehavior('buoyant', array()); Javelin::initBehavior('differential-toggle-files', array()); $output = array(); $mapping = array(); foreach ($changesets as $key => $changeset) { $file = $changeset->getFilename(); $class = 'differential-changeset'; if (!$this->inlineURI) { $class .= ' differential-changeset-noneditable'; } $ref = $this->references[$key]; $detail = new DifferentialChangesetDetailView(); $view_options = $this->renderViewOptionsDropdown( $detail, $ref, $changeset); + $prefs = $this->user->loadPreferences(); + $pref_symbols = $prefs->getPreference( + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_SYMBOLS); $detail->setChangeset($changeset); $detail->addButton($view_options); - $detail->setSymbolIndex(idx($this->symbolIndexes, $key)); + if ($pref_symbols != 'disabled') { + $detail->setSymbolIndex(idx($this->symbolIndexes, $key)); + } $detail->setVsChangesetID(idx($this->vsMap, $changeset->getID())); $detail->setEditable(true); $uniq_id = 'diff-'.$changeset->getAnchorName(); if (isset($this->visibleChangesets[$key])) { $load = 'Loading...'; $mapping[$uniq_id] = $ref; } else { $load = javelin_render_tag( 'a', array( 'href' => '#'.$uniq_id, 'meta' => array( 'id' => $uniq_id, 'ref' => $ref, 'kill' => true, ), 'sigil' => 'differential-load', 'mustcapture' => true, ), 'Load'); } $detail->appendChild( phutil_render_tag( 'div', array( 'id' => $uniq_id, ), '
'.$load.'
')); $output[] = $detail->render(); } require_celerity_resource('aphront-tooltip-css'); Javelin::initBehavior('differential-populate', array( 'registry' => $mapping, 'whitespace' => $this->whitespace, 'uri' => $this->renderURI, )); Javelin::initBehavior('differential-show-more', array( 'uri' => $this->renderURI, 'whitespace' => $this->whitespace, )); Javelin::initBehavior('differential-comment-jump', array()); if ($this->inlineURI) { $undo_templates = $this->renderUndoTemplates(); Javelin::initBehavior('differential-edit-inline-comments', array( 'uri' => $this->inlineURI, 'undo_templates' => $undo_templates, 'stage' => 'differential-review-stage', )); } return phutil_render_tag( 'div', array( 'class' => 'differential-review-stage', 'id' => 'differential-review-stage', ), implode("\n", $output)); } /** * Render the "Undo" markup for the inline comment undo feature. */ private function renderUndoTemplates() { $link = javelin_render_tag( 'a', array( 'href' => '#', 'sigil' => 'differential-inline-comment-undo', ), 'Undo'); $div = phutil_render_tag( 'div', array( 'class' => 'differential-inline-undo', ), 'Changes discarded. '.$link); $template = ''. ''. ''. '
%s%s
'; return array( 'l' => sprintf($template, $div, ''), 'r' => sprintf($template, '', $div), ); } private function renderViewOptionsDropdown( DifferentialChangesetDetailView $detail, $ref, DifferentialChangeset $changeset) { $meta = array(); $qparams = array( 'ref' => $ref, 'whitespace' => $this->whitespace, ); if ($this->standaloneURI) { $uri = new PhutilURI($this->standaloneURI); $uri->setQueryParams($uri->getQueryParams() + $qparams); $meta['standaloneURI'] = (string)$uri; } $repository = $this->repository; if ($repository) { $meta['diffusionURI'] = (string)$repository->getDiffusionBrowseURIForPath( $changeset->getAbsoluteRepositoryPath($repository, $this->diff)); } $change = $changeset->getChangeType(); if ($this->leftRawFileURI) { if ($change != DifferentialChangeType::TYPE_ADD) { $uri = new PhutilURI($this->leftRawFileURI); $uri->setQueryParams($uri->getQueryParams() + $qparams); $meta['leftURI'] = (string)$uri; } } if ($this->rightRawFileURI) { if ($change != DifferentialChangeType::TYPE_DELETE && $change != DifferentialChangeType::TYPE_MULTICOPY) { $uri = new PhutilURI($this->rightRawFileURI); $uri->setQueryParams($uri->getQueryParams() + $qparams); $meta['rightURI'] = (string)$uri; } } $user = $this->user; if ($user && $repository) { $path = ltrim( $changeset->getAbsoluteRepositoryPath($repository, $this->diff), '/'); $line = 1; // TODO: get first changed line $callsign = $repository->getCallsign(); $editor_link = $user->loadEditorLink($path, $line, $callsign); if ($editor_link) { $meta['editor'] = $editor_link; } else { $meta['editorConfigure'] = '/settings/page/preferences/'; } } $meta['containerID'] = $detail->getID(); Javelin::initBehavior( 'differential-dropdown-menus', array()); return javelin_render_tag( 'a', array( 'class' => 'button small grey', 'meta' => $meta, 'href' => idx($meta, 'detailURI', '#'), 'target' => '_blank', 'sigil' => 'differential-view-options', ), "View Options \xE2\x96\xBC"); } } diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php index d88bad10b5..1eea798a0b 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php @@ -1,816 +1,819 @@ getRequest(); $drequest = $this->getDiffusionRequest(); $before = $request->getStr('before'); if ($before) { return $this->buildBeforeResponse($before); } $path = $drequest->getPath(); $selected = $request->getStr('view'); $preferences = $request->getUser()->loadPreferences(); if (!$selected) { $selected = $preferences->getPreference( PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, 'highlighted'); } else if ($request->isFormPost() && $selected != 'raw') { $preferences->setPreference( PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, $selected); $preferences->save(); return id(new AphrontRedirectResponse()) ->setURI($request->getRequestURI()->alter('view', $selected)); } $needs_blame = ($selected == 'blame' || $selected == 'plainblame'); $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( $this->diffusionRequest); $file_query->setNeedsBlame($needs_blame); $file_query->loadFileContent(); $data = $file_query->getRawData(); if ($selected === 'raw') { return $this->buildRawResponse($path, $data); } // Build the content of the file. $corpus = $this->buildCorpus( $selected, $file_query, $needs_blame, $drequest, $path, $data); require_celerity_resource('diffusion-source-css'); if ($this->corpusType == 'text') { $view_select_panel = $this->renderViewSelectPanel($selected); } else { $view_select_panel = null; } // Render the page. $content = array(); $content[] = $this->buildCrumbs( array( 'branch' => true, 'path' => true, 'view' => 'browse', )); $follow = $request->getStr('follow'); if ($follow) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_WARNING); $notice->setTitle('Unable to Continue'); switch ($follow) { case 'first': $notice->appendChild( "Unable to continue tracing the history of this file because ". "this commit is the first commit in the repository."); break; case 'created': $notice->appendChild( "Unable to continue tracing the history of this file because ". "this commit created the file."); break; } $content[] = $notice; } $renamed = $request->getStr('renamed'); if ($renamed) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('File Renamed'); $notice->appendChild( "File history passes through a rename from '". phutil_escape_html($drequest->getPath())."' to '". phutil_escape_html($renamed)."'."); $content[] = $notice; } $content[] = $view_select_panel; $content[] = $corpus; $content[] = $this->buildOpenRevisions(); $nav = $this->buildSideNav('browse', true); $nav->appendChild($content); $basename = basename($this->getDiffusionRequest()->getPath()); return $this->buildStandardPageResponse( $nav, array( 'title' => $basename, )); } private function buildCorpus($selected, DiffusionFileContentQuery $file_query, $needs_blame, DiffusionRequest $drequest, $path, $data) { if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { $file = $this->loadFileForData($path, $data); $file_uri = $file->getBestURI(); if ($file->isViewableImage()) { $this->corpusType = 'image'; return $this->buildImageCorpus($file_uri); } else { $this->corpusType = 'binary'; return $this->buildBinaryCorpus($file_uri, $data); } } switch ($selected) { case 'plain': $style = "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; $corpus = phutil_render_tag( 'textarea', array( 'style' => $style, ), phutil_escape_html($file_query->getRawData())); break; case 'plainblame': $style = "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); $rows = array(); foreach ($text_list as $k => $line) { $rev = $rev_list[$k]; if (isset($blame_dict[$rev]['handle'])) { $author = $blame_dict[$rev]['handle']->getName(); } else { $author = $blame_dict[$rev]['author']; } $rows[] = sprintf("%-10s %-20s %s", substr($rev, 0, 7), $author, $line); } $corpus = phutil_render_tag( 'textarea', array( 'style' => $style, ), phutil_escape_html(implode("\n", $rows))); break; case 'highlighted': case 'blame': default: require_celerity_resource('syntax-highlighting-css'); list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); $text_list = implode("\n", $text_list); $text_list = PhabricatorSyntaxHighlighter::highlightWithFilename( $path, $text_list); $text_list = explode("\n", $text_list); $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, $needs_blame, $drequest, $file_query, $selected); $id = celerity_generate_unique_node_id(); $projects = $drequest->loadArcanistProjects(); $langs = array(); foreach ($projects as $project) { $ls = $project->getSymbolIndexLanguages(); if (!$ls) { continue; } $dep_projects = $project->getSymbolIndexProjects(); $dep_projects[] = $project->getPHID(); foreach ($ls as $lang) { if (!isset($langs[$lang])) { $langs[$lang] = array(); } $langs[$lang] += $dep_projects + array($project); } } $lang = last(explode('.', $drequest->getPath())); - if (isset($langs[$lang])) { + $prefs = $this->getRequest()->getUser()->loadPreferences(); + $pref_symbols = $prefs->getPreference( + PhabricatorUserPreferences::PREFERENCE_DIFFUSION_SYMBOLS); + if (isset($langs[$lang]) && $pref_symbols != 'disabled') { Javelin::initBehavior( 'repository-crossreference', array( 'container' => $id, 'lang' => $lang, 'projects' => $langs[$lang], )); } $corpus_table = phutil_render_tag( 'table', array( 'class' => "diffusion-source remarkup-code PhabricatorMonospaced", ), implode("\n", $rows)); $corpus = phutil_render_tag( 'div', array( 'style' => 'padding: 0 2em;', 'id' => $id, ), $corpus_table); break; } return $corpus; } private function renderViewSelectPanel($selected) { $request = $this->getRequest(); $select = AphrontFormSelectControl::renderSelectTag( $selected, array( 'highlighted' => 'View as Highlighted Text', 'blame' => 'View as Highlighted Text with Blame', 'plain' => 'View as Plain Text', 'plainblame' => 'View as Plain Text with Blame', 'raw' => 'View as raw document', ), array( 'name' => 'view', )); $view_select_panel = new AphrontPanelView(); $view_select_form = phabricator_render_form( $request->getUser(), array( 'action' => $request->getRequestURI()->alter('view', null), 'method' => 'post', 'class' => 'diffusion-browse-type-form', ), $select. ' '. $this->renderEditButton()); $view_select_panel->appendChild($view_select_form); $view_select_panel->appendChild('
'); return $view_select_panel; } private function renderEditButton() { $request = $this->getRequest(); $user = $request->getUser(); $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); $path = $drequest->getPath(); $line = 1; $callsign = $repository->getCallsign(); $editor_link = $user->loadEditorLink($path, $line, $callsign); if (!$editor_link) { return null; } return phutil_render_tag( 'a', array( 'href' => $editor_link, 'class' => 'button', ), 'Edit'); } private function buildDisplayRows( array $text_list, array $rev_list, array $blame_dict, $needs_blame, DiffusionRequest $drequest, DiffusionFileContentQuery $file_query, $selected) { if ($blame_dict) { $epoch_list = ipull(ifilter($blame_dict, 'epoch'), 'epoch'); $epoch_min = min($epoch_list); $epoch_max = max($epoch_list); $epoch_range = ($epoch_max - $epoch_min) + 1; } $line_arr = array(); $line_str = $drequest->getLine(); $ranges = explode(',', $line_str); foreach ($ranges as $range) { if (strpos($range, '-') !== false) { list($min, $max) = explode('-', $range, 2); $line_arr[] = array( 'min' => min($min, $max), 'max' => max($min, $max), ); } else if (strlen($range)) { $line_arr[] = array( 'min' => $range, 'max' => $range, ); } } $display = array(); $line_number = 1; $last_rev = null; $color = null; foreach ($text_list as $k => $line) { $display_line = array( 'color' => null, 'epoch' => null, 'commit' => null, 'author' => null, 'target' => null, 'highlighted' => null, 'line' => $line_number, 'data' => $line, ); if ($needs_blame) { // If the line's rev is same as the line above, show empty content // with same color; otherwise generate blame info. The newer a change // is, the more saturated the color. // TODO: SVN doesn't always give us blame for the last line, if empty? // Bug with our stuff or with SVN? $rev = idx($rev_list, $k, $last_rev); if ($last_rev == $rev) { $display_line['color'] = $color; } else { $blame = $blame_dict[$rev]; if (!isset($blame['epoch'])) { $color = '#ffd'; // Render as warning. } else { $color_ratio = ($blame['epoch'] - $epoch_min) / $epoch_range; $color_value = 0xF6 * (1.0 - $color_ratio); $color = sprintf( '#%02x%02x%02x', $color_value, 0xF6, $color_value); } $display_line['epoch'] = idx($blame, 'epoch'); $display_line['color'] = $color; $display_line['commit'] = $rev; if (isset($blame['handle'])) { $author_link = $blame['handle']->renderLink(); } else { $author_link = phutil_render_tag( 'span', array( ), phutil_escape_html($blame['author'])); } $display_line['author'] = $author_link; $last_rev = $rev; } } if ($line_arr) { if ($line_number == $line_arr[0]['min']) { $display_line['target'] = true; } foreach ($line_arr as $range) { if ($line_number >= $range['min'] && $line_number <= $range['max']) { $display_line['highlighted'] = true; } } } $display[] = $display_line; ++$line_number; } $commits = array_filter(ipull($display, 'commit')); if ($commits) { $commits = id(new PhabricatorAuditCommitQuery()) ->withIdentifiers($drequest->getRepository()->getID(), $commits) ->needCommitData(true) ->execute(); $commits = mpull($commits, null, 'getCommitIdentifier'); } $revision_ids = id(new DifferentialRevision()) ->loadIDsByCommitPHIDs(mpull($commits, 'getPHID')); $revisions = array(); if ($revision_ids) { $revisions = id(new DifferentialRevision())->loadAllWhere( 'id IN (%Ld)', $revision_ids); } $request = $this->getRequest(); $user = $request->getUser(); Javelin::initBehavior('phabricator-oncopy', array()); $rows = array(); foreach ($display as $line) { $line_href = $drequest->generateURI( array( 'action' => 'browse', 'line' => $line['line'], 'stable' => true, 'params' => array('view' => $selected), )); $blame = array(); if ($line['color']) { $color = $line['color']; $before_link = null; $commit_link = null; $revision_link = null; if (idx($line, 'commit')) { $commit = $line['commit']; $summary = 'Unknown'; if (idx($commits, $commit)) { $summary = $commits[$commit]->getCommitData()->getSummary(); } $tooltip = phabricator_date( $line['epoch'], $user)." \xC2\xB7 ".$summary; Javelin::initBehavior('phabricator-tooltips', array()); require_celerity_resource('aphront-tooltip-css'); $commit_link = javelin_render_tag( 'a', array( 'href' => $drequest->generateURI( array( 'action' => 'commit', 'commit' => $line['commit'], )), 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => $tooltip, 'align' => 'E', 'size' => 600, ), ), phutil_escape_html(phutil_utf8_shorten($line['commit'], 9, ''))); $revision_id = null; if (idx($commits, $commit)) { $revision_id = idx($revision_ids, $commits[$commit]->getPHID()); } if ($revision_id) { $revision = idx($revisions, $revision_id); if (!$revision) { $tooltip = '(Invalid revision)'; } else { $tooltip = phabricator_date($revision->getDateModified(), $user). " \xC2\xB7 ". $revision->getTitle(); } $revision_link = javelin_render_tag( 'a', array( 'href' => '/D'.$revision_id, 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => $tooltip, 'align' => 'E', 'size' => 600, ), ), 'D'.$revision_id); } $before_link = javelin_render_tag( 'a', array( 'href' => $line_href->alter('before', $commit), 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => 'Skip Past This Commit', 'align' => 'E', 'size' => 300, ), ), "\xC2\xAB"); } $blame[] = phutil_render_tag( 'th', array( 'class' => 'diffusion-blame-link', 'style' => 'background: '.$color, ), $before_link); $blame[] = phutil_render_tag( 'th', array( 'class' => 'diffusion-rev-link', 'style' => 'background: '.$color, ), $commit_link); $blame[] = phutil_render_tag( 'th', array( 'class' => 'diffusion-rev-link', 'style' => 'background: '.$color, ), $revision_link); $blame[] = phutil_render_tag( 'th', array( 'class' => 'diffusion-author-link', 'style' => 'background: '.$color, ), idx($line, 'author')); } $line_link = phutil_render_tag( 'a', array( 'href' => $line_href, ), phutil_escape_html($line['line'])); $blame[] = phutil_render_tag( 'th', array( 'class' => 'diffusion-line-link', 'style' => isset($color) ? 'background: '.$color : null, ), $line_link); $blame = implode('', $blame); if ($line['target']) { Javelin::initBehavior( 'diffusion-jump-to', array( 'target' => 'scroll_target', )); $anchor_text = ''; } else { $anchor_text = null; } $line_text = phutil_render_tag( 'td', array( ), $anchor_text. "\xE2\x80\x8B". // NOTE: See phabricator-oncopy behavior. $line['data']); $rows[] = phutil_render_tag( 'tr', array( 'style' => ($line['highlighted'] ? 'background: #ffff00;' : null), ), $blame. $line_text); } return $rows; } private static function renderRevision(DiffusionRequest $drequest, $revision) { $callsign = $drequest->getCallsign(); $name = 'r'.$callsign.$revision; return phutil_render_tag( 'a', array( 'href' => '/'.$name, ), $name ); } private static function renderBrowse( DiffusionRequest $drequest, $path, $name = null, $rev = null, $line = null, $view = null, $title = null) { $callsign = $drequest->getCallsign(); if ($name === null) { $name = $path; } $at = null; if ($rev) { $at = ';'.$rev; } if ($view) { $view = '?view='.$view; } if ($line) { $line = '$'.$line; } return phutil_render_tag( 'a', array( 'href' => "/diffusion/{$callsign}/browse/{$path}{$at}{$line}{$view}", 'title' => $title, ), $name ); } private function loadFileForData($path, $data) { return PhabricatorFile::buildFromFileDataOrHash( $data, array( 'name' => basename($path), )); } private function buildRawResponse($path, $data) { $file = $this->loadFileForData($path, $data); return id(new AphrontRedirectResponse())->setURI($file->getBestURI()); } private function buildImageCorpus($file_uri) { $panel = new AphrontPanelView(); $panel->setHeader('Image'); $panel->addButton($this->renderEditButton()); $panel->appendChild( phutil_render_tag( 'img', array( 'src' => $file_uri, ))); return $panel; } private function buildBinaryCorpus($file_uri, $data) { $panel = new AphrontPanelView(); $panel->setHeader('Binary File'); $panel->addButton($this->renderEditButton()); $panel->appendChild( '

'. 'This is a binary file. '. 'It is '.number_format(strlen($data)).' bytes in length.'. '

'); $panel->addButton( phutil_render_tag( 'a', array( 'href' => $file_uri, 'class' => 'button green', ), 'Download Binary File...')); return $panel; } private function buildBeforeResponse($before) { $request = $this->getRequest(); $drequest = $this->getDiffusionRequest(); // NOTE: We need to get the grandparent so we can capture filename changes // in the parent. $parent = $this->loadParentRevisionOf($before); $old_filename = null; $was_created = false; if ($parent) { $grandparent = $this->loadParentRevisionOf( $parent->getCommitIdentifier()); if ($grandparent) { $rename_query = DiffusionRenameHistoryQuery::newFromDiffusionRequest( $drequest); $rename_query->setOldCommit($grandparent->getCommitIdentifier()); $old_filename = $rename_query->loadOldFilename(); $was_created = $rename_query->getWasCreated(); } } $follow = null; if ($was_created) { // If the file was created in history, that means older commits won't // have it. Since we know it existed at 'before', it must have been // created then; jump there. $target_commit = $before; $follow = 'created'; } else if ($parent) { // If we found a parent, jump to it. This is the normal case. $target_commit = $parent->getCommitIdentifier(); } else { // If there's no parent, this was probably created in the initial commit? // And the "was_created" check will fail because we can't identify the // grandparent. Keep the user at 'before'. $target_commit = $before; $follow = 'first'; } $path = $drequest->getPath(); $renamed = null; if ($old_filename !== null && $old_filename !== $path) { $renamed = $path; $path = $old_filename; } $before_uri = $drequest->generateURI( array( 'action' => 'browse', 'commit' => $target_commit, // If there's a follow error, drop the line so the user sees the // message. 'line' => $follow ? null : $drequest->getLine(), 'path' => $path, )); $before_uri->setQueryParams($request->getRequestURI()->getQueryParams()); $before_uri = $before_uri->alter('before', null); $before_uri = $before_uri->alter('renamed', $renamed); $before_uri = $before_uri->alter('follow', $follow); return id(new AphrontRedirectResponse())->setURI($before_uri); } private function loadParentRevisionOf($commit) { $drequest = $this->getDiffusionRequest(); $before_req = DiffusionRequest::newFromDictionary( array( 'repository' => $drequest->getRepository(), 'commit' => $commit, )); $query = DiffusionCommitParentsQuery::newFromDiffusionRequest($before_req); $parents = $query->loadParents(); return head($parents); } } diff --git a/src/applications/people/controller/settings/panels/PhabricatorUserPreferenceSettingsPanelController.php b/src/applications/people/controller/settings/panels/PhabricatorUserPreferenceSettingsPanelController.php index f650a76008..09d5c10ce6 100644 --- a/src/applications/people/controller/settings/panels/PhabricatorUserPreferenceSettingsPanelController.php +++ b/src/applications/people/controller/settings/panels/PhabricatorUserPreferenceSettingsPanelController.php @@ -1,129 +1,141 @@ getRequest(); $user = $request->getUser(); $preferences = $user->loadPreferences(); - $pref_monospaced = PhabricatorUserPreferences::PREFERENCE_MONOSPACED; - $pref_editor = PhabricatorUserPreferences::PREFERENCE_EDITOR; - $pref_titles = PhabricatorUserPreferences::PREFERENCE_TITLES; + $pref_monospaced = PhabricatorUserPreferences::PREFERENCE_MONOSPACED; + $pref_editor = PhabricatorUserPreferences::PREFERENCE_EDITOR; + $pref_titles = PhabricatorUserPreferences::PREFERENCE_TITLES; + $pref_symbols = PhabricatorUserPreferences::PREFERENCE_DIFFUSION_SYMBOLS; if ($request->isFormPost()) { $monospaced = $request->getStr($pref_monospaced); // Prevent the user from doing stupid things. $monospaced = preg_replace('/[^a-z0-9 ,"]+/i', '', $monospaced); $preferences->setPreference($pref_titles, $request->getStr($pref_titles)); $preferences->setPreference($pref_editor, $request->getStr($pref_editor)); + $preferences->setPreference($pref_symbols, + $request->getStr($pref_symbols)); $preferences->setPreference($pref_monospaced, $monospaced); $preferences->save(); return id(new AphrontRedirectResponse()) ->setURI('/settings/page/preferences/?saved=true'); } $example_string = << PhabricatorEnv::getDoclink( 'article/User_Guide_Configuring_an_External_Editor.html'), ), 'User Guide: Configuring an External Editor'); $font_default = PhabricatorEnv::getEnvConfig('style.monospace'); $font_default = phutil_escape_html($font_default); $form = id(new AphrontFormView()) ->setUser($user) ->setAction('/settings/page/preferences/') ->appendChild( id(new AphrontFormSelectControl()) ->setLabel('Page Titles') ->setName($pref_titles) ->setValue($preferences->getPreference($pref_titles)) ->setOptions( array( 'glyph' => "In page titles, show Tool names as unicode glyphs: \xE2\x9A\x99", 'text' => 'In page titles, show Tool names as plain text: [Differential]', ))) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Editor Link') ->setName($pref_editor) ->setCaption( 'Link to edit files in external editor. '. '%f is replaced by filename, %l by line number, %r by repository '. 'callsign, %% by literal %. '. "For documentation, see {$editor_doc_link}.") ->setValue($preferences->getPreference($pref_editor))) ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Monospaced Font') ->setName($pref_monospaced) ->setCaption( 'Overrides default fonts in tools like Differential. '. '(Default: '.$font_default.')') ->setValue($preferences->getPreference($pref_monospaced))) ->appendChild( id(new AphrontFormMarkupControl()) ->setValue( '
'.
           phutil_escape_html($example_string).
           '
')) + ->appendChild( + id(new AphrontFormRadioButtonControl()) + ->setLabel('Symbol Links') + ->setName($pref_symbols) + ->setValue($preferences->getPreference($pref_symbols) ?: 'enabled') + ->addButton('enabled', 'Enabled (default)', + 'Use this setting to disable linking symbol names in Differential '. + 'and Diffusion to their definitions. This is enabled by default.') + ->addButton('disabled', 'Disabled', null)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Save Preferences')); $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); $panel->setHeader('Display Preferences'); $panel->appendChild($form); $error_view = null; if ($request->getStr('saved') === 'true') { $error_view = id(new AphrontErrorView()) ->setTitle('Preferences Saved') ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) ->setErrors(array('Your preferences have been saved.')); } return id(new AphrontNullView()) ->appendChild( array( $error_view, $panel, )); } } diff --git a/src/applications/people/storage/PhabricatorUserPreferences.php b/src/applications/people/storage/PhabricatorUserPreferences.php index d569d8929a..2d4941207b 100644 --- a/src/applications/people/storage/PhabricatorUserPreferences.php +++ b/src/applications/people/storage/PhabricatorUserPreferences.php @@ -1,61 +1,62 @@ array( 'preferences' => self::SERIALIZATION_JSON, ), self::CONFIG_TIMESTAMPS => false, ) + parent::getConfiguration(); } public function getPreference($key, $default = null) { return idx($this->preferences, $key, $default); } public function setPreference($key, $value) { $this->preferences[$key] = $value; return $this; } public function unsetPreference($key) { unset($this->preferences[$key]); return $this; } }