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($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 {
         require_celerity_resource('syntax-highlighting-css');
         if ($can_highlight) {
             $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename($path, $file_corpus);
         } else {
             // Highlight as plain text to escape the content properly.
             $highlighted = PhabricatorSyntaxHighlighter::highlightWithLanguage('txt', $file_corpus);
         }
         $lines = phutil_split_lines($highlighted);
         $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(basename($this->getDiffusionRequest()->getPath()))->setHeaderIcon('fa-file-code-o')->addActionLink($edit)->addActionLink($file);
     $corpus = id(new PHUIObjectBoxView())->setHeader($header)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->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 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 highlightSource($source, $title, $language)
 {
     if (empty($language)) {
         return PhabricatorSyntaxHighlighter::highlightWithFilename($title, $source);
     } else {
         return PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source);
     }
 }