public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $inlines = $this->loadInlineComments();
     assert_instances_of($inlines, 'PhabricatorInlineCommentInterface');
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($user);
     foreach ($inlines as $inline) {
         $engine->addObject($inline, PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
     }
     $engine->process();
     $phids = array($user->getPHID());
     $handles = $this->loadViewerHandles($phids);
     $views = array();
     foreach ($inlines as $inline) {
         $view = new DifferentialInlineCommentView();
         $view->setInlineComment($inline);
         $view->setMarkupEngine($engine);
         $view->setHandles($handles);
         $view->setEditable(false);
         $view->setPreview(true);
         $views[] = $view->render();
     }
     $views = phutil_implode_html("\n", $views);
     return id(new AphrontAjaxResponse())->setContent($views);
 }
 private function buildChangesetParser($type, $data, $file)
 {
     $parser = new ArcanistDiffParser();
     $changes = $parser->parseDiff($data);
     $diff = DifferentialDiff::newFromRawChanges($changes);
     if (count($diff->getChangesets()) !== 1) {
         throw new Exception("Expected one changeset: {$file}");
     }
     $changeset = head($diff->getChangesets());
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer(new PhabricatorUser());
     $cparser = new DifferentialChangesetParser();
     $cparser->setDisableCache(true);
     $cparser->setChangeset($changeset);
     $cparser->setMarkupEngine($engine);
     if ($type == 'one') {
         $cparser->setRenderer(new DifferentialChangesetOneUpTestRenderer());
     } else {
         if ($type == 'two') {
             $cparser->setRenderer(new DifferentialChangesetTwoUpTestRenderer());
         } else {
             throw new Exception("Unknown renderer type '{$type}'!");
         }
     }
     return $cparser;
 }
 public function render()
 {
     $old = $this->oldText;
     $new = $this->newText;
     // TODO: On mobile, or perhaps by default, we should switch to 1-up once
     // that is built.
     if (strlen($old)) {
         $old = phutil_utf8_hard_wrap($old, 80);
         $old = implode("\n", $old) . "\n";
     }
     if (strlen($new)) {
         $new = phutil_utf8_hard_wrap($new, 80);
         $new = implode("\n", $new) . "\n";
     }
     try {
         $engine = new PhabricatorDifferenceEngine();
         $changeset = $engine->generateChangesetFromFileContent($old, $new);
         $whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL;
         $markup_engine = new PhabricatorMarkupEngine();
         $markup_engine->setViewer($this->getUser());
         $parser = new DifferentialChangesetParser();
         $parser->setUser($this->getUser());
         $parser->setChangeset($changeset);
         $parser->setMarkupEngine($markup_engine);
         $parser->setWhitespaceMode($whitespace_mode);
         return $parser->render(0, PHP_INT_MAX, array());
     } catch (Exception $ex) {
         return $ex->getMessage();
     }
 }
 private function buildChangesetParsers($type, $data, $file)
 {
     $parser = new ArcanistDiffParser();
     $changes = $parser->parseDiff($data);
     $diff = DifferentialDiff::newFromRawChanges(PhabricatorUser::getOmnipotentUser(), $changes);
     $changesets = $diff->getChangesets();
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer(new PhabricatorUser());
     $parsers = array();
     foreach ($changesets as $changeset) {
         $cparser = new DifferentialChangesetParser();
         $cparser->setUser(new PhabricatorUser());
         $cparser->setDisableCache(true);
         $cparser->setChangeset($changeset);
         $cparser->setMarkupEngine($engine);
         if ($type == 'one') {
             $cparser->setRenderer(new DifferentialChangesetOneUpTestRenderer());
         } else {
             if ($type == 'two') {
                 $cparser->setRenderer(new DifferentialChangesetTwoUpTestRenderer());
             } else {
                 throw new Exception(pht('Unknown renderer type "%s"!', $type));
             }
         }
         $parsers[] = $cparser;
     }
     return $parsers;
 }
 private function buildDocument(PhabricatorMarkupEngine $engine, LegalpadDocumentBody $body)
 {
     $view = new PHUIPropertyListView();
     $view->addClass('legalpad');
     $view->addSectionHeader(pht('Document'));
     $view->addTextContent($engine->getOutput($body, LegalpadDocumentBody::MARKUP_FIELD_TEXT));
     return $view;
 }
 private function buildPropertyView(PholioMock $mock, PhabricatorMarkupEngine $engine, PhabricatorActionListView $actions)
 {
     $viewer = $this->getViewer();
     $properties = id(new PHUIPropertyListView())->setUser($viewer)->setObject($mock)->setActionList($actions);
     $properties->addProperty(pht('Author'), $viewer->renderHandle($mock->getAuthorPHID()));
     $properties->addProperty(pht('Created'), phabricator_datetime($mock->getDateCreated(), $viewer));
     if ($this->getManiphestTaskPHIDs()) {
         $properties->addProperty(pht('Maniphest Tasks'), $viewer->renderHandleList($this->getManiphestTaskPHIDs()));
     }
     $properties->invokeWillRenderEvent();
     $properties->addSectionHeader(pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
     $properties->addImageContent($engine->getOutput($mock, PholioMock::MARKUP_FIELD_DESCRIPTION));
     return $properties;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     // this means we're using "show more" on a diff of a description and
     // should thus use the rendering reference to identify the transaction
     $ref = $request->getStr('ref');
     if ($ref) {
         $this->setTransactionID($ref);
     }
     $transaction_id = $this->getTransactionID();
     $transaction = id(new ManiphestTransaction())->load($transaction_id);
     if (!$transaction) {
         return new Aphront404Response();
     }
     $transactions = array($transaction);
     $phids = array();
     foreach ($transactions as $transaction) {
         foreach ($transaction->extractPHIDs() as $phid) {
             $phids[$phid] = $phid;
         }
     }
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $engine = PhabricatorMarkupEngine::newManiphestMarkupEngine();
     $view = new ManiphestTransactionDetailView();
     $view->setTransactionGroup($transactions);
     $view->setHandles($handles);
     $view->setUser($user);
     $view->setMarkupEngine($engine);
     $view->setRenderSummaryOnly(true);
     $view->setRenderFullSummary(true);
     $view->setRangeSpecification($request->getStr('range'));
     return id(new AphrontAjaxResponse())->setContent($view->render());
 }
 public function renderPropertyViewValue(array $handles)
 {
     if (!strlen($this->getValue())) {
         return null;
     }
     return PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setPreserveLinebreaks(true)->setContent($this->getValue()), 'default', $this->getViewer());
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $transaction = id(new ManiphestTransaction())->load($this->transactionID);
     if (!$transaction) {
         return new Aphront404Response();
     }
     $transactions = array($transaction);
     $phids = array();
     foreach ($transactions as $transaction) {
         foreach ($transaction->extractPHIDs() as $phid) {
             $phids[$phid] = $phid;
         }
     }
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $engine = PhabricatorMarkupEngine::newManiphestMarkupEngine();
     $view = new ManiphestTransactionDetailView();
     $view->setTransactionGroup($transactions);
     $view->setHandles($handles);
     $view->setUser($user);
     $view->setMarkupEngine($engine);
     $view->setRenderSummaryOnly(true);
     $view->setRenderFullSummary(true);
     return id(new AphrontAjaxResponse())->setContent($view->render());
 }
 public function save()
 {
     if (!$this->viewer) {
         throw new Exception("Must set user before saving question");
     }
     if (!$this->question) {
         throw new Exception("Must set question before saving it");
     }
     $viewer = $this->viewer;
     $question = $this->question;
     $question->save();
     // search index
     $question->attachRelated();
     PhabricatorSearchPonderIndexer::indexQuestion($question);
     // subscribe author and @mentions
     $subeditor = id(new PhabricatorSubscriptionsEditor())->setObject($question)->setUser($viewer);
     $subeditor->subscribeExplicit(array($question->getAuthorPHID()));
     $content = $question->getContent();
     $at_mention_phids = PhabricatorMarkupEngine::extractPHIDsFromMentions(array($content));
     $subeditor->subscribeImplicit($at_mention_phids);
     $subeditor->save();
     if ($this->shouldEmail && $at_mention_phids) {
         id(new PonderMentionMail($question, $question, $viewer))->setToPHIDs($at_mention_phids)->send();
     }
 }
 private function buildPropertyView(PhabricatorApplication $application, PhabricatorActionListView $actions)
 {
     $viewer = $this->getRequest()->getUser();
     $properties = id(new PHUIPropertyListView());
     $properties->setActionList($actions);
     $properties->addProperty(pht('Description'), $application->getShortDescription());
     if ($application->getFlavorText()) {
         $properties->addProperty(null, phutil_tag('em', array(), $application->getFlavorText()));
     }
     if ($application->isPrototype()) {
         $proto_href = PhabricatorEnv::getDoclink('User Guide: Prototype Applications');
         $learn_more = phutil_tag('a', array('href' => $proto_href, 'target' => '_blank'), pht('Learn More'));
         $properties->addProperty(pht('Prototype'), pht('This application is a prototype. %s', $learn_more));
     }
     $overview = $application->getOverview();
     if ($overview) {
         $properties->addSectionHeader(pht('Overview'), PHUIPropertyListView::ICON_SUMMARY);
         $properties->addTextContent(PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($overview), 'default', $viewer));
     }
     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions($viewer, $application);
     $properties->addSectionHeader(pht('Policies'), 'fa-lock');
     foreach ($application->getCapabilities() as $capability) {
         $properties->addProperty($application->getCapabilityLabel($capability), idx($descriptions, $capability));
     }
     return $properties;
 }
 public function addRemarkupSection($header, $text)
 {
     try {
         $engine = PhabricatorMarkupEngine::newMarkupEngine(array());
         $engine->setConfig('viewer', $this->getViewer());
         $engine->setMode(PhutilRemarkupEngine::MODE_TEXT);
         $styled_text = $engine->markupText($text);
         $this->addPlaintextSection($header, $styled_text);
     } catch (Exception $ex) {
         phlog($ex);
         $this->addTextSection($header, $text);
     }
     try {
         $mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array());
         $mail_engine->setConfig('viewer', $this->getViewer());
         $mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL);
         $mail_engine->setConfig('uri.base', PhabricatorEnv::getProductionURI('/'));
         $html = $mail_engine->markupText($text);
         $this->addHTMLSection($header, $html);
     } catch (Exception $ex) {
         phlog($ex);
         $this->addHTMLSection($header, $text);
     }
     return $this;
 }
Example #13
0
 public function appendRemarkupInstructions($remarkup)
 {
     if ($this->getUser() === null) {
         throw new Exception('Call `setUser` before appending Remarkup to PHUIFormLayoutView.');
     }
     return $this->appendInstructions(PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($remarkup), 'default', $this->getUser()));
 }
Example #14
0
 public function appendRemarkupInstructions($remarkup)
 {
     if ($this->getUser() === null) {
         throw new PhutilInvalidStateException('setUser');
     }
     return $this->appendInstructions(PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($remarkup), 'default', $this->getUser()));
 }
 protected function getTagContent()
 {
     require_celerity_resource('ponder-view-css');
     $answer = $this->answer;
     $viewer = $this->getUser();
     $author_phid = $answer->getAuthorPHID();
     $actions = $this->buildAnswerActions();
     $action_button = id(new PHUIButtonView())->setTag('a')->setText(pht('Actions'))->setHref('#')->setIconFont('fa-bars')->setDropdownMenu($actions);
     $header = id(new PHUIHeaderView())->setUser($viewer)->setEpoch($answer->getDateCreated())->setHeader($viewer->renderHandle($author_phid))->addActionLink($action_button);
     $content = phutil_tag('div', array('class' => 'phabricator-remarkup mlt mlb msr msl'), PhabricatorMarkupEngine::renderOneObject($answer, $answer->getMarkupField(), $viewer));
     $id = $answer->getID();
     $anchor = id(new PhabricatorAnchorView())->setAnchorName("A{$id}");
     $content_id = celerity_generate_unique_node_id();
     $footer = id(new PonderFooterView())->setContentID($content_id)->setCount(count($this->transactions));
     $votes = $answer->getVoteCount();
     if ($votes) {
         $icon = id(new PHUIIconView())->setIconFont('fa-thumbs-up');
         $helpful = phutil_tag('span', array('class' => 'ponder-footer-action'), array($votes, $icon));
         $footer->addAction($helpful);
     }
     $answer_view = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($anchor)->appendChild($content)->appendChild($footer);
     $transaction_view = id(new PhabricatorApplicationTransactionView())->setUser($viewer)->setObjectPHID($answer->getPHID())->setTransactions($this->transactions)->setMarkupEngine($this->engine);
     $comment_view = id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($answer->getPHID())->setShowPreview(false)->setHeaderText(pht('Answer Comment'))->setAction("/ponder/answer/comment/{$id}/")->setSubmitButtonName(pht('Comment'));
     $hidden_view = phutil_tag('div', array('id' => $content_id, 'style' => 'display: none;'), array($transaction_view, $comment_view));
     return array($answer_view, $hidden_view);
 }
 private function markupText($text)
 {
     $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
     $text = $engine->markupText($text);
     $text = phutil_render_tag('div', array('class' => 'phabricator-remarkup'), $text);
     return $text;
 }
 public function addRemarkupSection($text)
 {
     try {
         $engine = PhabricatorMarkupEngine::newMarkupEngine(array());
         $engine->setConfig('viewer', $this->getViewer());
         $engine->setMode(PhutilRemarkupEngine::MODE_TEXT);
         $styled_text = $engine->markupText($text);
         $this->sections[] = $styled_text;
     } catch (Exception $ex) {
         phlog($ex);
         $this->sections[] = $text;
     }
     try {
         $mail_engine = PhabricatorMarkupEngine::newMarkupEngine(array());
         $mail_engine->setConfig('viewer', $this->getViewer());
         $mail_engine->setMode(PhutilRemarkupEngine::MODE_HTML_MAIL);
         $mail_engine->setConfig('uri.base', PhabricatorEnv::getProductionURI('/'));
         $html = $mail_engine->markupText($text);
         $this->htmlSections[] = $html;
     } catch (Exception $ex) {
         phlog($ex);
         $this->htmlSections[] = phutil_escape_html_newlines(phutil_tag('div', array(), $text));
     }
     return $this;
 }
    public function renderExample()
    {
        $viewer = $this->getRequest()->getUser();
        $content = pht(<<<EOCONTENT
This is some **remarkup text** using ~~exactly one style~~ //various styles//.

  - Fruit
    - Apple
    - Banana
    - Cherry
  - Vegetables
    1. Carrot
    2. Celery

NOTE: This is a note.

(NOTE) This is also a note.

WARNING: This is a warning.

(WARNING) This is also a warning.

IMPORTANT: This is not really important.

(IMPORTANT) This isn't important either.

EOCONTENT
);
        $remarkup = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($content), 'default', $viewer);
        $frame = id(new PHUIBoxView())->addPadding(PHUI::PADDING_LARGE)->appendChild($remarkup);
        return id(new PHUIObjectBoxView())->setHeaderText(pht('Remarkup Example'))->appendChild($frame);
    }
 private function renderProperties(PhameBlog $blog, PhabricatorUser $viewer, PhabricatorActionListView $actions)
 {
     require_celerity_resource('aphront-tooltip-css');
     Javelin::initBehavior('phabricator-tooltips');
     $properties = id(new PHUIPropertyListView())->setUser($viewer)->setObject($blog)->setActionList($actions);
     $skin = $blog->getSkin();
     if (!$skin) {
         $skin = pht('(No external skin)');
     }
     $domain = $blog->getDomain();
     if (!$domain) {
         $domain = pht('(No external domain)');
     }
     $properties->addProperty(pht('Skin'), $skin);
     $properties->addProperty(pht('Domain'), $domain);
     $feed_uri = PhabricatorEnv::getProductionURI($this->getApplicationURI('blog/feed/' . $blog->getID() . '/'));
     $properties->addProperty(pht('Atom URI'), javelin_tag('a', array('href' => $feed_uri, 'sigil' => 'has-tooltip', 'meta' => array('tip' => pht('Atom URI does not support custom domains.'), 'size' => 320)), $feed_uri));
     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions($viewer, $blog);
     $properties->addProperty(pht('Editable By'), $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
     $engine = id(new PhabricatorMarkupEngine())->setViewer($viewer)->addObject($blog, PhameBlog::MARKUP_FIELD_DESCRIPTION)->process();
     $properties->invokeWillRenderEvent();
     if (strlen($blog->getDescription())) {
         $description = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($blog->getDescription()), 'default', $viewer);
         $properties->addSectionHeader(pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
         $properties->addTextContent($description);
     }
     return $properties;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $books = id(new DivinerBookQuery())->setViewer($viewer)->execute();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setBorder(true);
     $crumbs->addTextCrumb(pht('Books'));
     $query_button = id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('query/'))->setText(pht('Advanced Search'))->setIcon('fa-search');
     $header = id(new PHUIHeaderView())->setHeader(pht('Documentation Books'))->addActionLink($query_button);
     $document = new PHUIDocumentViewPro();
     $document->setHeader($header);
     $document->addClass('diviner-view');
     if ($books) {
         $books = msort($books, 'getTitle');
         $list = array();
         foreach ($books as $book) {
             $item = id(new DivinerBookItemView())->setTitle($book->getTitle())->setHref('/book/' . $book->getName() . '/')->setSubtitle($book->getPreface());
             $list[] = $item;
         }
         $list = id(new PHUIBoxView())->addPadding(PHUI::PADDING_MEDIUM_TOP)->appendChild($list);
         $document->appendChild($list);
     } else {
         $text = pht("(NOTE) **Looking for Phabricator documentation?** " . "If you're looking for help and information about Phabricator, " . "you can [[https://secure.phabricator.com/diviner/ | " . "browse the public Phabricator documentation]] on the live site.\n\n" . "Diviner is the documentation generator used to build the " . "Phabricator documentation.\n\n" . "You haven't generated any Diviner documentation books yet, so " . "there's nothing to show here. If you'd like to generate your own " . "local copy of the Phabricator documentation and have it appear " . "here, run this command:\n\n" . "  %s\n\n", 'phabricator/ $ ./bin/diviner generate');
         $text = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($text), 'default', $viewer);
         $document->appendChild($text);
     }
     return $this->buildApplicationPage(array($crumbs, $document), array('title' => pht('Documentation Books')));
 }
 private function renderItemCommonProperties(PhabricatorUser $viewer, NuanceItem $item, PHUIPropertyListView $view)
 {
     $complaint = $item->getNuanceProperty('complaint');
     $complaint = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($complaint), 'default', $viewer);
     $view->addSectionHeader(pht('Complaint'), 'fa-exclamation-circle');
     $view->addTextContent($complaint);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $author_phid = $request->getUser()->getPHID();
     $action = $request->getStr('action');
     $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
     $comment = new DifferentialComment();
     $comment->setContent($request->getStr('content'));
     $comment->setAction($action);
     $comment->setAuthorPHID($author_phid);
     $handles = array($author_phid);
     $reviewers = $request->getStr('reviewers');
     if (($action == DifferentialAction::ACTION_ADDREVIEWERS || $action == DifferentialAction::ACTION_REQUEST) && $reviewers) {
         $reviewers = explode(',', $reviewers);
         $comment->setMetadata(array(DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers));
         $handles = array_merge($handles, $reviewers);
     }
     $ccs = $request->getStr('ccs');
     if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) {
         $ccs = explode(',', $ccs);
         $comment->setMetadata(array(DifferentialComment::METADATA_ADDED_CCS => $ccs));
         $handles = array_merge($handles, $ccs);
     }
     $handles = id(new PhabricatorObjectHandleData($handles))->loadHandles();
     $view = new DifferentialRevisionCommentView();
     $view->setUser($request->getUser());
     $view->setComment($comment);
     $view->setHandles($handles);
     $view->setMarkupEngine($engine);
     $view->setPreview(true);
     $view->setTargetDiff(null);
     $draft = new PhabricatorDraft();
     $draft->setAuthorPHID($author_phid)->setDraftKey('differential-comment-' . $this->id)->setDraft($comment->getContent())->replace();
     return id(new AphrontAjaxResponse())->setContent($view->render());
 }
Example #23
0
 protected function getTagContent()
 {
     require_celerity_resource('ponder-view-css');
     $answer = $this->answer;
     $viewer = $this->getUser();
     $status = $answer->getStatus();
     $author_phid = $answer->getAuthorPHID();
     $actions = $this->buildAnswerActions();
     $handle = $this->handle;
     $id = $answer->getID();
     if ($status == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
         $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $answer, PhabricatorPolicyCapability::CAN_EDIT);
         $message = array();
         $message[] = phutil_tag('em', array(), pht('This answer has been hidden.'));
         if ($can_edit) {
             $message[] = phutil_tag('a', array('href' => "/ponder/answer/edit/{$id}/"), pht('Edit Answer'));
         }
         $message = phutil_implode_html(' ', $message);
         return id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NODATA)->appendChild($message);
     }
     $action_button = id(new PHUIButtonView())->setTag('a')->setText(pht('Actions'))->setHref('#')->setIcon('fa-bars')->setDropdownMenu($actions);
     $header_name = phutil_tag('a', array('href' => $handle->getURI()), $handle->getName());
     $header = id(new PHUIHeaderView())->setUser($viewer)->setEpoch($answer->getDateModified())->setHeader($header_name)->addActionLink($action_button)->setImage($handle->getImageURI())->setImageURL($handle->getURI());
     $content = phutil_tag('div', array('class' => 'phabricator-remarkup'), PhabricatorMarkupEngine::renderOneObject($answer, $answer->getMarkupField(), $viewer));
     $anchor = id(new PhabricatorAnchorView())->setAnchorName("A{$id}");
     $content_id = celerity_generate_unique_node_id();
     $footer = id(new PonderFooterView())->setContentID($content_id)->setCount(count($this->transactions));
     $content = phutil_tag_div('ponder-answer-content', array($anchor, $content, $footer));
     $answer_view = id(new PHUIObjectBoxView())->setHeader($header)->setBackground(PHUIObjectBoxView::GREY)->addClass('ponder-answer')->appendChild($content);
     $comment_view = id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($answer->getPHID())->setShowPreview(false)->setHeaderText(pht('Answer Comment'))->setAction("/ponder/answer/comment/{$id}/")->setSubmitButtonName(pht('Comment'));
     $hidden_view = phutil_tag('div', array('id' => $content_id, 'style' => 'display: none;'), array($this->timeline, $comment_view));
     return array($answer_view, $hidden_view);
 }
 public function renderValueForRevisionView()
 {
     $diff = $this->getDiff();
     $ustar = DifferentialRevisionUpdateHistoryView::renderDiffUnitStar($diff);
     $umsg = DifferentialRevisionUpdateHistoryView::getDiffUnitMessage($diff);
     $postponed_count = 0;
     $udata = $this->getDiffProperty('arc:unit');
     $utail = null;
     if ($udata) {
         $unit_messages = array();
         foreach ($udata as $test) {
             $name = idx($test, 'name');
             $result = idx($test, 'result');
             if ($result != DifferentialUnitTestResult::RESULT_POSTPONED && $result != DifferentialUnitTestResult::RESULT_PASS) {
                 $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
                 $userdata = phutil_utf8_shorten(idx($test, 'userdata'), 512);
                 $userdata = $engine->markupText($userdata);
                 $unit_messages[] = '<li>' . '<span class="unit-result-' . phutil_escape_html($result) . '">' . phutil_escape_html(ucwords($result)) . '</span>' . ' ' . phutil_escape_html($name) . '<p>' . $userdata . '</p>' . '</li>';
             } else {
                 if ($result == DifferentialUnitTestResult::RESULT_POSTPONED) {
                     $postponed_count++;
                 }
             }
         }
         $uexcuse = $this->getUnitExcuse();
         if ($unit_messages) {
             $utail = '<div class="differential-unit-block">' . $uexcuse . '<ul>' . implode("\n", $unit_messages) . '</ul>' . '</div>';
         }
     }
     if ($postponed_count > 0 && $diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) {
         $umsg = $postponed_count . ' ' . $umsg;
     }
     return $ustar . ' ' . $umsg . $utail;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $books = id(new DivinerBookQuery())->setViewer($viewer)->execute();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Books'));
     $search_icon = id(new PHUIIconView())->setIconFont('fa-search');
     $query_button = id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('query/'))->setText(pht('Advanced Search'))->setIcon($search_icon);
     $header = id(new PHUIHeaderView())->setHeader(pht('Documentation Books'))->addActionLink($query_button);
     $document = new PHUIDocumentView();
     $document->setHeader($header);
     $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS);
     $document->addClass('diviner-view');
     if ($books) {
         $books = msort($books, 'getTitle');
         $list = array();
         foreach ($books as $book) {
             $item = id(new DivinerBookItemView())->setTitle($book->getTitle())->setHref('/book/' . $book->getName() . '/')->setSubtitle($book->getPreface());
             $list[] = $item;
         }
         $list = id(new PHUIBoxView())->addPadding(PHUI::PADDING_LARGE_LEFT)->addPadding(PHUI::PADDING_LARGE_RIGHT)->addPadding(PHUI::PADDING_SMALL_TOP)->addPadding(PHUI::PADDING_SMALL_BOTTOM)->appendChild($list);
         $document->appendChild($list);
     } else {
         $text = pht("(NOTE) **Looking for Phabricator documentation?** If you're looking " . "for help and information about Phabricator, you can " . "[[ https://secure.phabricator.com/diviner/ | browse the public " . "Phabricator documentation ]] on the live site.\n\n" . "Diviner is the documentation generator used to build the Phabricator " . "documentation.\n\n" . "You haven't generated any Diviner documentation books yet, so " . "there's nothing to show here. If you'd like to generate your own " . "local copy of the Phabricator documentation and have it appear " . "here, run this command:\n\n" . "  phabricator/ \$ ./bin/diviner generate\n\n" . "Right now, Diviner isn't very useful for generating documentation " . "for projects other than Phabricator. If you're interested in using " . "it in your own projects, leave feedback for us on " . "[[ https://secure.phabricator.com/T4558 | T4558 ]].");
         $text = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($text), 'default', $viewer);
         $document->appendChild($text);
     }
     return $this->buildApplicationPage(array($crumbs, $document), array('title' => pht('Documentation Books'), 'fonts' => true));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $class = $request->getURIData('class');
     $sources = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorTypeaheadDatasource')->loadObjects();
     if (!isset($sources[$class])) {
         return new Aphront404Response();
     }
     $source = $sources[$class];
     $application_class = $source->getDatasourceApplicationClass();
     if ($application_class) {
         $result = id(new PhabricatorApplicationQuery())->setViewer($this->getViewer())->withClasses(array($application_class))->execute();
         if (!$result) {
             return new Aphront404Response();
         }
     }
     $source->setViewer($viewer);
     $title = pht('Typeahead Function Help');
     $functions = $source->getAllDatasourceFunctions();
     ksort($functions);
     $content = array();
     $content[] = '= ' . pht('Overview');
     $content[] = pht('Typeahead functions are an advanced feature which allow you to build ' . 'more powerful queries. This document explains functions available ' . 'for the selected control.' . "\n\n" . 'For general help with search, see the [[ %s | Search User Guide ]] in ' . 'the documentation.' . "\n\n" . 'Note that different controls support //different// functions ' . '(depending on what the control is doing), so these specific functions ' . 'may not work everywhere. You can always check the help for a control ' . 'to review which functions are available for that control.', PhabricatorEnv::getDoclink('Search User Guide'));
     $table = array();
     $table_header = array(pht('Function'), pht('Token Name'), pht('Summary'));
     $table[] = '| ' . implode(' | ', $table_header) . ' |';
     $table[] = '|---|---|---|';
     foreach ($functions as $function => $spec) {
         $spec = $spec + array('summary' => null, 'arguments' => null);
         if (idx($spec, 'arguments')) {
             $signature = '**' . $function . '(**//' . $spec['arguments'] . '//**)**';
         } else {
             $signature = '**' . $function . '()**';
         }
         $name = idx($spec, 'name', '');
         $summary = idx($spec, 'summary', '');
         $table[] = '| ' . $signature . ' | ' . $name . ' | ' . $summary . ' |';
     }
     $table = implode("\n", $table);
     $content[] = '= ' . pht('Function Quick Reference');
     $content[] = pht('This table briefly describes available functions for this control. ' . 'For details on a particular function, see the corresponding section ' . 'below.');
     $content[] = $table;
     $content[] = '= ' . pht('Using Typeahead Functions');
     $content[] = pht("In addition to typing user and project names to build queries, you can " . "also type the names of special functions which give you more options " . "and the ability to express more complex queries.\n\n" . "Functions have an internal name (like `%s`) and a human-readable name, " . "like `Current Viewer`. In general, you can type either one to select " . "the function. You can also click the {nav icon=search} button on any " . "typeahead control to browse available functions and find this " . "documentation.\n\n" . "This documentation uses the internal names to make it clear where " . "tokens begin and end. Specifically, you will find queries written " . "out like this in the documentation:\n\n%s\n\n" . "When this query is actually shown in the control, it will look more " . "like this:\n\n%s", 'viewer()', '> viewer(), alincoln', '> {nav Current Viewer} {nav alincoln (Abraham Lincoln)}');
     $middot = "ยท";
     foreach ($functions as $function => $spec) {
         $arguments = idx($spec, 'arguments', '');
         $name = idx($spec, 'name');
         $content[] = '= ' . $function . '(' . $arguments . ') ' . $middot . ' ' . $name;
         $content[] = $spec['description'];
     }
     $content = implode("\n\n", $content);
     $content_box = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($content), 'default', $viewer);
     $header = id(new PHUIHeaderView())->setHeader($title);
     $document = id(new PHUIDocumentView())->setHeader($header)->appendChild($content_box);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Function Help'));
     return $this->buildApplicationPage(array($crumbs, $document), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $text = $request->getStr('text');
     $output = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setPreserveLinebreaks(true)->setContent($text), 'default', $viewer);
     return id(new AphrontAjaxResponse())->setContent($output);
 }
 private function buildDocumentView(LegalpadDocument $document, PhabricatorMarkupEngine $engine)
 {
     $viewer = $this->getViewer();
     $view = id(new PHUIPropertyListView())->setUser($viewer);
     $document_body = $document->getDocumentBody();
     $document_text = $engine->getOutput($document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT);
     $preamble_box = null;
     if (strlen($document->getPreamble())) {
         $preamble_text = new PHUIRemarkupView($viewer, $document->getPreamble());
         $view->addTextContent($preamble_text);
         $view->addSectionHeader('');
         $view->addTextContent($document_text);
     } else {
         $view->addTextContent($document_text);
     }
     return id(new PHUIObjectBoxView())->setHeaderText(pht('DOCUMENT'))->addPropertyList($view)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
 }
 protected function markupText($text)
 {
     $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
     $engine->setConfig('viewer', $this->getRequest()->getUser());
     $text = $engine->markupText($text);
     $text = phutil_tag('div', array('class' => 'phabricator-remarkup'), $text);
     return $text;
 }
 public function renderValueForRevisionView()
 {
     if (!$this->value) {
         return null;
     }
     $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
     return $engine->markupText($this->value);
 }