private function buildSourceCodeView(PhabricatorPaste $paste, PhabricatorFile $file) { $language = $paste->getLanguage(); $source = $file->loadFileData(); if (empty($language)) { $source = PhabricatorSyntaxHighlighter::highlightWithFilename($paste->getTitle(), $source); } else { $source = PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source); } $lines = explode("\n", $source); return id(new PhabricatorSourceCodeView())->setLines($lines); }
private function buildCorpus($paste, $file) { // Blantently copied from DiffusionBrowseFileController require_celerity_resource('diffusion-source-css'); require_celerity_resource('syntax-highlighting-css'); $language = $paste->getLanguage(); $source = $file->loadFileData(); if (empty($language)) { $source = PhabricatorSyntaxHighlighter::highlightWithFilename($paste->getTitle(), $source); } else { $source = PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source); } $text_list = explode("\n", $source); $rows = $this->buildDisplayRows($text_list); $corpus_table = phutil_render_tag('table', array('class' => 'diffusion-source remarkup-code PhabricatorMonospaced'), implode("\n", $rows)); $corpus = phutil_render_tag('div', array('style' => 'padding: 0pt 2em;'), $corpus_table); return $corpus; }
private function buildCorpus($paste, $file) { // Blantently copied from DiffusionBrowseFileController require_celerity_resource('diffusion-source-css'); require_celerity_resource('syntax-highlighting-css'); $language = $paste->getLanguage(); $source = $file->loadFileData(); if (empty($language)) { $source = PhabricatorSyntaxHighlighter::highlightWithFilename($paste->getTitle(), $source); } else { $source = PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source); } $text_list = explode("\n", $source); Javelin::initBehavior('phabricator-oncopy', array()); $rows = $this->buildDisplayRows($text_list); // TODO: Split the "one-up source listing" view into its own class and // share it properly between Paste and Diffusion. $corpus_table = phutil_render_tag('table', array('class' => 'diffusion-source remarkup-code PhabricatorMonospaced'), implode("\n", $rows)); $corpus = phutil_render_tag('div', array('style' => 'padding: 0pt 2em;'), $corpus_table); return $corpus; }
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())); $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 = javelin_render_tag('table', array('class' => "diffusion-source remarkup-code PhabricatorMonospaced", 'sigil' => 'diffusion-source'), implode("\n", $rows)); $corpus = phutil_render_tag('div', array('style' => 'padding: 0 2em;', 'id' => $id), $corpus_table); break; } return $corpus; }
private function buildCorpus($show_blame, $show_color, $file_corpus, $needs_blame, DiffusionRequest $drequest, $path, $data) { $viewer = $this->getViewer(); $blame_timeout = 15; $blame_failed = false; $highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; $blame_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; $can_highlight = strlen($file_corpus) <= $highlight_limit; $can_blame = strlen($file_corpus) <= $blame_limit; if ($needs_blame && $can_blame) { $blame = $this->loadBlame($path, $drequest->getCommit(), $blame_timeout); list($blame_list, $blame_commits) = $blame; if ($blame_list === null) { $blame_failed = true; $blame_list = array(); } } else { $blame_list = array(); $blame_commits = array(); } if (!$show_color) { $corpus = $this->renderPlaintextCorpus($file_corpus, $blame_list, $blame_commits, $show_blame); } else { if ($can_highlight) { require_celerity_resource('syntax-highlighting-css'); $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename($path, $file_corpus); $lines = phutil_split_lines($highlighted); } else { $lines = phutil_split_lines($file_corpus); } $rows = $this->buildDisplayRows($lines, $blame_list, $blame_commits, $show_blame, $show_color); $corpus_table = javelin_tag('table', array('class' => 'diffusion-source remarkup-code PhabricatorMonospaced', 'sigil' => 'phabricator-source'), $rows); if ($this->getRequest()->isAjax()) { return $corpus_table; } $id = celerity_generate_unique_node_id(); $repo = $drequest->getRepository(); $symbol_repos = nonempty($repo->getSymbolSources(), array()); $symbol_repos[] = $repo->getPHID(); $lang = last(explode('.', $drequest->getPath())); $repo_languages = $repo->getSymbolLanguages(); $repo_languages = nonempty($repo_languages, array()); $repo_languages = array_fill_keys($repo_languages, true); $needs_symbols = true; if ($repo_languages && $symbol_repos) { $have_symbols = id(new DiffusionSymbolQuery())->existsSymbolsInRepository($repo->getPHID()); if (!$have_symbols) { $needs_symbols = false; } } if ($needs_symbols && $repo_languages) { $needs_symbols = isset($repo_languages[$lang]); } if ($needs_symbols) { Javelin::initBehavior('repository-crossreference', array('container' => $id, 'lang' => $lang, 'repositories' => $symbol_repos)); } $corpus = phutil_tag('div', array('id' => $id), $corpus_table); Javelin::initBehavior('load-blame', array('id' => $id)); } $edit = $this->renderEditButton(); $file = $this->renderFileButton(); $header = id(new PHUIHeaderView())->setHeader(pht('File Contents'))->addActionLink($edit)->addActionLink($file); $corpus = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($corpus)->setCollapsed(true); $messages = array(); if (!$can_highlight) { $messages[] = pht('This file is larger than %s, so syntax highlighting is disabled ' . 'by default.', phutil_format_bytes($highlight_limit)); } if ($show_blame && !$can_blame) { $messages[] = pht('This file is larger than %s, so blame is disabled.', phutil_format_bytes($blame_limit)); } if ($blame_failed) { $messages[] = pht('Failed to load blame information for this file in %s second(s).', new PhutilNumber($blame_timeout)); } if ($messages) { $corpus->setInfoView(id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_WARNING)->setErrors($messages)); } return $corpus; }
private function buildCorpus($show_blame, $show_color, DiffusionFileContent $file_content, $needs_blame, DiffusionRequest $drequest, $path, $data) { if (!$show_color) { $style = 'border: none; width: 100%; height: 80em; font-family: monospace'; if (!$show_blame) { $corpus = phutil_tag('textarea', array('style' => $style), $file_content->getCorpus()); } else { $text_list = $file_content->getTextList(); $rev_list = $file_content->getRevList(); $blame_dict = $file_content->getBlameDict(); $rows = array(); foreach ($text_list as $k => $line) { $rev = $rev_list[$k]; $author = $blame_dict[$rev]['author']; $rows[] = sprintf('%-10s %-20s %s', substr($rev, 0, 7), $author, $line); } $corpus = phutil_tag('textarea', array('style' => $style), implode("\n", $rows)); } } else { require_celerity_resource('syntax-highlighting-css'); $text_list = $file_content->getTextList(); $rev_list = $file_content->getRevList(); $blame_dict = $file_content->getBlameDict(); $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, $show_blame, $show_color); $corpus_table = javelin_tag('table', array('class' => 'diffusion-source remarkup-code PhabricatorMonospaced', 'sigil' => 'phabricator-source'), $rows); if ($this->getRequest()->isAjax()) { return $corpus_table; } $id = celerity_generate_unique_node_id(); $repo = $drequest->getRepository(); $symbol_repos = nonempty($repo->getSymbolSources(), array()); $symbol_repos[] = $repo; $lang = last(explode('.', $drequest->getPath())); $repo_languages = $repo->getSymbolLanguages(); $repo_languages = nonempty($repo_languages, array()); $repo_languages = array_fill_keys($repo_languages, true); $needs_symbols = true; if ($repo_languages && $symbol_repos) { $have_symbols = id(new DiffusionSymbolQuery())->existsSymbolsInRepository($repo->getPHID()); if (!$have_symbols) { $needs_symbols = false; } } if ($needs_symbols && $repo_languages) { $needs_symbols = isset($repo_languages[$lang]); } if ($needs_symbols) { Javelin::initBehavior('repository-crossreference', array('container' => $id, 'lang' => $lang, 'repositories' => $symbol_repos)); } $corpus = phutil_tag('div', array('id' => $id), $corpus_table); Javelin::initBehavior('load-blame', array('id' => $id)); } $edit = $this->renderEditButton(); $file = $this->renderFileButton(); $header = id(new PHUIHeaderView())->setHeader(pht('File Contents'))->addActionLink($edit)->addActionLink($file); $corpus = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($corpus); return $corpus; }
private function buildContent(PhabricatorPaste $paste) { $language = $paste->getLanguage(); $source = $paste->getRawContent(); if (empty($language)) { return PhabricatorSyntaxHighlighter::highlightWithFilename($paste->getTitle(), $source); } else { return PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source); } }
private function buildCorpus($selected, $file_query, $needs_blame, $drequest, $path, $data) { $image_type = $this->getImageType($path); if ($image_type && !$selected) { $corpus = phutil_render_tag('img', array('style' => 'padding-bottom: 10px', 'src' => 'data:' . $image_type . ';base64,' . base64_encode($data))); return $corpus; } $document_type = $this->getDocumentType($path); if ($document_type && !$selected || !phutil_is_utf8($data)) { $data = $file_query->getRawData(); $document_type_description = $document_type ? $document_type : 'binary'; $corpus = phutil_render_tag('p', array('style' => 'text-align: center;'), phutil_render_tag('a', array('href' => '?view=raw', 'class' => 'button'), "View {$document_type_description}")); return $corpus; } // TODO: blame of blame. 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); $corpus_table = phutil_render_tag('table', array('class' => "diffusion-source remarkup-code PhabricatorMonospaced"), implode("\n", $rows)); $corpus = phutil_render_tag('div', array('style' => 'padding: 0pt 2em;'), $corpus_table); break; } return $corpus; }
private function highlightSource($source, $title, $language) { if (empty($language)) { return PhabricatorSyntaxHighlighter::highlightWithFilename($title, $source); } else { return PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source); } }
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); $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;'), $corpus_table); break; } return $corpus; }
private function buildCorpus($selected) { $needs_blame = $selected == 'blame' || $selected == 'plainblame'; $file_query = DiffusionFileContentQuery::newFromDiffusionRequest($this->diffusionRequest); $file_query->setNeedsBlame($needs_blame); $file_query->loadFileContent(); $drequest = $this->getDiffusionRequest(); $path = $drequest->getPath(); $image_type = $this->getImageType($path); if ($image_type && !$selected) { $data = $file_query->getRawData(); $corpus = phutil_render_tag('img', array('style' => 'padding-bottom: 10px', 'src' => 'data:' . $image_type . ';base64,' . base64_encode($data))); return $corpus; } // TODO: blame of blame. 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]; $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); $corpus_table = phutil_render_tag('table', array('class' => "diffusion-source remarkup-code PhabricatorMonospaced"), implode("\n", $rows)); $corpus = phutil_render_tag('div', array('style' => 'padding: 0pt 2em;'), $corpus_table); break; } return $corpus; }