コード例 #1
0
 protected function getVerb()
 {
     $comment = $this->getComment();
     $action = $comment->getAction();
     $verb = DifferentialAction::getActionPastTenseVerb($action);
     return $verb;
 }
 public function runBackgroundTasks()
 {
     $iterator = new PhabricatorTimelineIterator('ircdiffx', array('difx'));
     if (!$this->skippedOldEvents) {
         // Since we only want to post notifications about new events, skip
         // everything that's happened in the past when we start up so we'll
         // only process real-time events.
         foreach ($iterator as $event) {
             // Ignore all old events.
         }
         $this->skippedOldEvents = true;
         return;
     }
     foreach ($iterator as $event) {
         $data = $event->getData();
         if (!$data) {
             continue;
         }
         $actor_phid = $data['actor_phid'];
         $phids = array($actor_phid);
         $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
         $verb = DifferentialAction::getActionPastTenseVerb($data['action']);
         $actor_name = $handles[$actor_phid]->getName();
         $message = "{$actor_name} {$verb} revision D" . $data['revision_id'] . ".";
         foreach ($this->getConfig('notification.channels') as $channel) {
             $this->write('PRIVMSG', "{$channel} :{$message}");
         }
     }
 }
コード例 #3
0
 public function renderView()
 {
     $data = $this->getStoryData();
     $author_phid = $data->getAuthorPHID();
     $view = new PhabricatorFeedStoryView();
     $revision_phid = $data->getValue('revision_phid');
     $action = $data->getValue('action');
     $verb = DifferentialAction::getActionPastTenseVerb($action);
     $view->setTitle($this->linkTo($author_phid) . " {$verb} revision " . $this->linkTo($revision_phid) . '.');
     $view->setEpoch($data->getEpoch());
     $action = $data->getValue('action');
     switch ($action) {
         case DifferentialAction::ACTION_CREATE:
         case DifferentialAction::ACTION_COMMIT:
             $full_size = true;
             break;
         default:
             $full_size = false;
             break;
     }
     if ($full_size) {
         $view->setImage($this->getHandle($author_phid)->getImageURI());
         $content = $this->renderSummary($data->getValue('feedback_content'));
         $view->appendChild($content);
     } else {
         $view->setOneLineStory(true);
     }
     return $view;
 }
コード例 #4
0
 private function getLineForData($data)
 {
     $actor_phid = $data->getAuthorPHID();
     $owner_phid = $data->getValue('revision_author_phid');
     $revision_phid = $data->getValue('revision_phid');
     $action = $data->getValue('action');
     $actor_link = $this->linkTo($actor_phid);
     $revision_link = $this->linkTo($revision_phid);
     $owner_link = $this->linkTo($owner_phid);
     $verb = DifferentialAction::getActionPastTenseVerb($action);
     $one_line = "{$actor_link} {$verb} revision {$revision_link}";
     return $one_line;
 }
コード例 #5
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $phid_arr = $request->getArr('view_user');
         $view_target = head($phid_arr);
         return id(new AphrontRedirectResponse())->setURI($request->getRequestURI()->alter('phid', $view_target));
     }
     $params = array_filter(array('phid' => $request->getStr('phid')));
     // Fill in the defaults we'll actually use for calculations if any
     // parameters are missing.
     $params += array('phid' => $user->getPHID());
     $side_nav = new AphrontSideNavFilterView();
     $side_nav->setBaseURI(id(new PhutilURI('/differential/stats/'))->alter('phid', $params['phid']));
     foreach (array(DifferentialAction::ACTION_CLOSE, DifferentialAction::ACTION_ACCEPT, DifferentialAction::ACTION_REJECT, DifferentialAction::ACTION_UPDATE, DifferentialAction::ACTION_COMMENT) as $action) {
         $verb = ucfirst(DifferentialAction::getActionPastTenseVerb($action));
         $side_nav->addFilter($action, $verb);
     }
     $this->filter = $side_nav->selectFilter($this->filter, DifferentialAction::ACTION_CLOSE);
     $panels = array();
     $handles = $this->loadViewerHandles(array($params['phid']));
     $filter_form = id(new AphrontFormView())->setAction('/differential/stats/' . $this->filter . '/')->setUser($user);
     $filter_form->appendChild($this->renderControl($params['phid'], $handles));
     $filter_form->appendChild(id(new AphrontFormSubmitControl())->setValue('Filter Revisions'));
     $side_nav->appendChild($filter_form);
     $comments = $this->loadComments($params['phid']);
     $revisions = $this->loadRevisions($params['phid']);
     $diffs = $this->loadDiffs($revisions);
     $panel = new AphrontPanelView();
     $panel->setHeader('Differential rate analysis');
     $panel->appendChild(id(new DifferentialRevisionStatsView())->setComments($comments)->setFilter($this->filter)->setRevisions($revisions)->setDiffs($diffs)->setUser($user));
     $panels[] = $panel;
     foreach ($panels as $panel) {
         $side_nav->appendChild($panel);
     }
     return $this->buildStandardPageResponse($side_nav, array('title' => 'Differential statistics'));
 }
コード例 #6
0
 public function renderView()
 {
     $data = $this->getStoryData();
     $handles = $this->getHandles();
     $author_phid = $data->getAuthorPHID();
     $objects = $this->getObjects();
     $view = new PhabricatorFeedStoryView();
     $revision_phid = $data->getValue('revision_phid');
     $action = $data->getValue('action');
     $verb = DifferentialAction::getActionPastTenseVerb($action);
     $view->setTitle('<strong>' . $handles[$author_phid]->renderLink() . '</strong>' . ' ' . $verb . ' revision ' . '<strong>' . $handles[$revision_phid]->renderLink() . '</strong>.');
     $view->setEpoch($data->getEpoch());
     $action = $data->getValue('action');
     switch ($action) {
         case DifferentialAction::ACTION_CREATE:
         case DifferentialAction::ACTION_COMMIT:
             $full_size = true;
             break;
         default:
             $full_size = false;
             break;
     }
     if ($full_size) {
         if (!empty($objects[$author_phid])) {
             $image_phid = $objects[$author_phid]->getProfileImagePHID();
             $image_uri = PhabricatorFileURI::getViewURIForPHID($image_phid);
             $view->setImage($image_uri);
         }
         $content = phutil_escape_html($data->getValue('feedback_content'));
         $content = str_replace("\n", '<br />', $content);
         $view->appendChild($content);
     } else {
         $view->setOneLineStory(true);
     }
     return $view;
 }
コード例 #7
0
 public function render()
 {
     if (!$this->user) {
         throw new Exception("Call setUser() before rendering!");
     }
     require_celerity_resource('phabricator-remarkup-css');
     require_celerity_resource('differential-revision-comment-css');
     $comment = $this->comment;
     $action = $comment->getAction();
     $action_class = 'differential-comment-action-' . $action;
     $info = array();
     $content = $comment->getContent();
     $hide_comments = true;
     if (strlen(rtrim($content))) {
         $hide_comments = false;
         $cache = $comment->getCache();
         if (strlen($cache)) {
             $content = $cache;
         } else {
             $content = $this->markupEngine->markupText($content);
             if ($comment->getID()) {
                 $comment->setCache($content);
                 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                 $comment->save();
                 unset($unguarded);
             }
         }
         $content = '<div class="phabricator-remarkup">' . $content . '</div>';
     }
     $inline_render = $this->renderInlineComments();
     if ($inline_render) {
         $hide_comments = false;
     }
     $author = $this->handles[$comment->getAuthorPHID()];
     $author_link = $author->renderLink();
     $metadata = $comment->getMetadata();
     $added_reviewers = idx($metadata, DifferentialComment::METADATA_ADDED_REVIEWERS, array());
     $added_ccs = idx($metadata, DifferentialComment::METADATA_ADDED_CCS, array());
     $verb = DifferentialAction::getActionPastTenseVerb($comment->getAction());
     $verb = phutil_escape_html($verb);
     $actions = array();
     switch ($comment->getAction()) {
         case DifferentialAction::ACTION_ADDCCS:
             $actions[] = "{$author_link} added CCs: " . $this->renderHandleList($added_ccs) . ".";
             $added_ccs = null;
             break;
         case DifferentialAction::ACTION_ADDREVIEWERS:
             $actions[] = "{$author_link} added reviewers: " . $this->renderHandleList($added_reviewers) . ".";
             $added_reviewers = null;
             break;
         case DifferentialAction::ACTION_UPDATE:
             $diff_id = idx($metadata, DifferentialComment::METADATA_DIFF_ID);
             if ($diff_id) {
                 $diff_link = phutil_render_tag('a', array('href' => '/D' . $comment->getRevisionID() . '?id=' . $diff_id), 'Diff #' . phutil_escape_html($diff_id));
                 $actions[] = "{$author_link} updated this revision to {$diff_link}.";
             } else {
                 $actions[] = "{$author_link} {$verb} this revision.";
             }
             break;
         default:
             $actions[] = "{$author_link} {$verb} this revision.";
             break;
     }
     if ($added_reviewers) {
         $actions[] = "{$author_link} added reviewers: " . $this->renderHandleList($added_reviewers) . ".";
     }
     if ($added_ccs) {
         $actions[] = "{$author_link} added CCs: " . $this->renderHandleList($added_ccs) . ".";
     }
     foreach ($actions as $key => $action) {
         $actions[$key] = '<div>' . $action . '</div>';
     }
     $xaction_view = id(new PhabricatorTransactionView())->setUser($this->user)->setImageURI($author->getImageURI())->setContentSource($comment->getContentSource())->addClass($action_class)->setActions($actions);
     if ($this->preview) {
         $xaction_view->setIsPreview($this->preview);
     } else {
         $xaction_view->setEpoch($comment->getDateCreated());
         if ($this->anchorName) {
             $anchor_name = $this->anchorName;
             $anchor_text = 'D' . $comment->getRevisionID() . '#' . $anchor_name;
             $xaction_view->setAnchor($anchor_name, $anchor_text);
         }
     }
     if (!$hide_comments) {
         $xaction_view->appendChild('<div class="differential-comment-core">' . $content . '</div>' . $this->renderSingleView($inline_render));
     }
     return $xaction_view->render();
 }
コード例 #8
0
 public function render()
 {
     if (!$this->user) {
         throw new Exception("Call setUser() before rendering!");
     }
     require_celerity_resource('phabricator-remarkup-css');
     require_celerity_resource('differential-revision-comment-css');
     $comment = $this->comment;
     $action = $comment->getAction();
     $action_class = 'differential-comment-action-' . $action;
     if ($this->preview) {
         $date = 'COMMENT PREVIEW';
     } else {
         $date = phabricator_datetime($comment->getDateCreated(), $this->user);
     }
     $info = array();
     $content_source = new PhabricatorContentSourceView();
     $content_source->setContentSource($comment->getContentSource());
     $content_source->setUser($this->user);
     $info[] = $content_source->render();
     $info[] = $date;
     $comment_anchor = null;
     $num = $this->commentNumber;
     if ($num && !$this->preview) {
         Javelin::initBehavior('phabricator-watch-anchor');
         $info[] = phutil_render_tag('a', array('name' => 'comment-' . $num, 'href' => '#comment-' . $num), 'Comment D' . $comment->getRevisionID() . '#' . $num);
         $comment_anchor = 'anchor-comment-' . $num;
     }
     $info = implode(' &middot; ', array_filter($info));
     $author = $this->handles[$comment->getAuthorPHID()];
     $author_link = $author->renderLink();
     $verb = DifferentialAction::getActionPastTenseVerb($comment->getAction());
     $verb = phutil_escape_html($verb);
     $content = $comment->getContent();
     $head_content = null;
     if (strlen(rtrim($content))) {
         $title = "{$author_link} {$verb} this revision:";
         $cache = $comment->getCache();
         if (strlen($cache)) {
             $content = $cache;
         } else {
             $content = $this->markupEngine->markupText($content);
             if ($comment->getID()) {
                 $comment->setCache($content);
                 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                 $comment->save();
                 unset($unguarded);
             }
         }
         $content = '<div class="phabricator-remarkup">' . $content . '</div>';
     } else {
         $title = null;
         $head_content = '<div class="differential-comment-nocontent">' . "<p>{$author_link} {$verb} this revision.</p>" . '</div>';
         $content = null;
     }
     if ($this->inlines) {
         $inline_render = array();
         $inlines = $this->inlines;
         $changesets = $this->changesets;
         $inlines_by_changeset = mgroup($inlines, 'getChangesetID');
         $inlines_by_changeset = array_select_keys($inlines_by_changeset, array_keys($this->changesets));
         $inline_render[] = '<table class="differential-inline-summary">';
         foreach ($inlines_by_changeset as $changeset_id => $inlines) {
             $changeset = $changesets[$changeset_id];
             $inlines = msort($inlines, 'getLineNumber');
             $inline_render[] = '<tr>' . '<th colspan="3">' . phutil_escape_html($changeset->getFileName()) . '</th>' . '</tr>';
             foreach ($inlines as $inline) {
                 if (!$inline->getLineLength()) {
                     $lines = $inline->getLineNumber();
                 } else {
                     $lines = $inline->getLineNumber() . "–" . ($inline->getLineNumber() + $inline->getLineLength());
                 }
                 $on_target = $this->target && $this->target->getID() == $changeset->getDiffID();
                 $is_visible = false;
                 if ($inline->getIsNewFile()) {
                     // This comment is on the right side of the versus diff, and visible
                     // on the left side of the page.
                     if ($this->versusDiffID) {
                         if ($changeset->getDiffID() == $this->versusDiffID) {
                             $is_visible = true;
                         }
                     }
                     // This comment is on the right side of the target diff, and visible
                     // on the right side of the page.
                     if ($on_target) {
                         $is_visible = true;
                     }
                 } else {
                     // Ths comment is on the left side of the target diff, and visible
                     // on the left side of the page.
                     if (!$this->versusDiffID) {
                         if ($on_target) {
                             $is_visible = true;
                         }
                     }
                     // TODO: We still get one edge case wrong here, when we have a
                     // versus diff and the file didn't exist in the old version. The
                     // comment is visible because we show the left side of the target
                     // diff when there's no corresponding file in the versus diff, but
                     // we incorrectly link it off-page.
                 }
                 $where = null;
                 if ($is_visible) {
                     $lines = phutil_render_tag('a', array('href' => '#inline-' . $inline->getID(), 'class' => 'num'), $lines);
                 } else {
                     $diff_id = $changeset->getDiffID();
                     $lines = phutil_render_tag('a', array('href' => '?id=' . $diff_id . '#inline-' . $inline->getID(), 'class' => 'num', 'target' => '_blank'), $lines . " ↗");
                     $where = '(On Diff #' . $diff_id . ')';
                 }
                 $inline_content = $inline->getContent();
                 if (strlen($inline_content)) {
                     $inline_cache = $inline->getCache();
                     if ($inline_cache) {
                         $inline_content = $inline_cache;
                     } else {
                         $inline_content = $this->markupEngine->markupText($inline_content);
                         if ($inline->getID()) {
                             $inline->setCache($inline_content);
                             $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                             $inline->save();
                             unset($unguarded);
                         }
                     }
                 }
                 $inline_render[] = '<tr>' . '<td class="inline-line-number">' . $lines . '</td>' . '<td class="inline-which-diff">' . $where . '</td>' . '<td>' . '<div class="phabricator-remarkup">' . $inline_content . '</div>' . '</td>' . '</tr>';
             }
         }
         $inline_render[] = '</table>';
         $inline_render = implode("\n", $inline_render);
         $inline_render = '<div class="differential-inline-summary-section">' . 'Inline Comments' . '</div>' . $inline_render;
     } else {
         $inline_render = null;
     }
     $background = null;
     $uri = $author->getImageURI();
     if ($uri) {
         $background = "background-image: url('{$uri}');";
     }
     $metadata_blocks = array();
     $metadata = $comment->getMetadata();
     $added_reviewers = idx($metadata, DifferentialComment::METADATA_ADDED_REVIEWERS);
     if ($added_reviewers) {
         $reviewers = 'Added reviewers: ' . $this->renderHandleList($added_reviewers);
         $metadata_blocks[] = $reviewers;
     }
     $added_ccs = idx($metadata, DifferentialComment::METADATA_ADDED_CCS);
     if ($added_ccs) {
         $ccs = 'Added CCs: ' . $this->renderHandleList($added_ccs);
         $metadata_blocks[] = $ccs;
     }
     if ($metadata_blocks) {
         $metadata_blocks = '<div class="differential-comment-metadata">' . implode("\n", $metadata_blocks) . '</div>';
     } else {
         $metadata_blocks = null;
     }
     return phutil_render_tag('div', array('class' => "differential-comment {$action_class}", 'id' => $comment_anchor), '<div class="differential-comment-head">' . '<span class="differential-comment-info">' . $info . '</span>' . '<span class="differential-comment-title">' . $title . '</span>' . '<div style="clear: both;"></div>' . '</div>' . '<div class="differential-comment-body" style="' . $background . '">' . '<div class="differential-comment-content">' . $head_content . $metadata_blocks . '<div class="differential-comment-core">' . $content . '</div>' . $inline_render . '</div>' . '</div>');
 }
コード例 #9
0
 public function render()
 {
     if (!$this->user) {
         throw new Exception("Call setUser() before rendering!");
     }
     require_celerity_resource('phabricator-remarkup-css');
     require_celerity_resource('differential-revision-comment-css');
     $comment = $this->comment;
     $action = $comment->getAction();
     $action_class = 'differential-comment-action-' . phutil_escape_html($action);
     if ($this->preview) {
         $date = 'COMMENT PREVIEW';
     } else {
         $date = phabricator_datetime($comment->getDateCreated(), $this->user);
     }
     $info = array($date);
     $comment_anchor = null;
     $num = $this->commentNumber;
     if ($num && !$this->preview) {
         Javelin::initBehavior('phabricator-watch-anchor');
         $info[] = phutil_render_tag('a', array('name' => 'comment-' . $num, 'href' => '#comment-' . $num), 'Comment D' . $comment->getRevisionID() . '#' . $num);
         $comment_anchor = 'anchor-comment-' . $num;
     }
     $info = implode(' &middot; ', $info);
     $author = $this->handles[$comment->getAuthorPHID()];
     $author_link = $author->renderLink();
     $verb = DifferentialAction::getActionPastTenseVerb($comment->getAction());
     $verb = phutil_escape_html($verb);
     $content = $comment->getContent();
     $head_content = null;
     if (strlen(rtrim($content))) {
         $title = "{$author_link} {$verb} this revision:";
         $cache = $comment->getCache();
         if (strlen($cache)) {
             $content = $cache;
         } else {
             $content = $this->markupEngine->markupText($content);
             if ($comment->getID()) {
                 $comment->setCache($content);
                 $comment->save();
             }
         }
         $content = '<div class="phabricator-remarkup">' . $content . '</div>';
     } else {
         $title = null;
         $head_content = '<div class="differential-comment-nocontent">' . "<p>{$author_link} {$verb} this revision.</p>" . '</div>';
         $content = null;
     }
     if ($this->inlines) {
         $inline_render = array();
         $inlines = $this->inlines;
         $changesets = $this->changesets;
         $inlines_by_changeset = mgroup($inlines, 'getChangesetID');
         $inlines_by_changeset = array_select_keys($inlines_by_changeset, array_keys($this->changesets));
         $inline_render[] = '<table class="differential-inline-summary">';
         foreach ($inlines_by_changeset as $changeset_id => $inlines) {
             $changeset = $changesets[$changeset_id];
             $inlines = msort($inlines, 'getLineNumber');
             $inline_render[] = '<tr>' . '<th colspan="2">' . phutil_escape_html($changeset->getFileName()) . '</th>' . '</tr>';
             foreach ($inlines as $inline) {
                 if (!$inline->getLineLength()) {
                     $lines = $inline->getLineNumber();
                 } else {
                     $lines = $inline->getLineNumber() . "–" . ($inline->getLineNumber() + $inline->getLineLength());
                 }
                 if (!$this->target || $changeset->getDiffID() === $this->target->getID()) {
                     $lines = phutil_render_tag('a', array('href' => '#inline-' . $inline->getID(), 'class' => 'num'), $lines);
                 }
                 $inline_content = $inline->getContent();
                 if (strlen($inline_content)) {
                     $inline_cache = $inline->getCache();
                     if ($inline_cache) {
                         $inline_content = $inline_cache;
                     } else {
                         $inline_content = $this->markupEngine->markupText($inline_content);
                         if ($inline->getID()) {
                             $inline->setCache($inline_content);
                             $inline->save();
                         }
                     }
                 }
                 $inline_render[] = '<tr>' . '<td class="inline-line-number">' . $lines . '</td>' . '<td>' . '<div class="phabricator-remarkup">' . $inline_content . '</div>' . '</td>' . '</tr>';
             }
         }
         $inline_render[] = '</table>';
         $inline_render = implode("\n", $inline_render);
         $inline_render = '<div class="differential-inline-summary-section">' . 'Inline Comments' . '</div>' . $inline_render;
     } else {
         $inline_render = null;
     }
     $background = null;
     $uri = $author->getImageURI();
     if ($uri) {
         $background = "background-image: url('{$uri}');";
     }
     $metadata_blocks = array();
     $metadata = $comment->getMetadata();
     $added_reviewers = idx($metadata, DifferentialComment::METADATA_ADDED_REVIEWERS);
     if ($added_reviewers) {
         $reviewers = 'Added reviewers: ' . $this->renderHandleList($added_reviewers);
         $metadata_blocks[] = $reviewers;
     }
     $added_ccs = idx($metadata, DifferentialComment::METADATA_ADDED_CCS);
     if ($added_ccs) {
         $ccs = 'Added CCs: ' . $this->renderHandleList($added_ccs);
         $metadata_blocks[] = $ccs;
     }
     if ($metadata_blocks) {
         $metadata_blocks = '<div class="differential-comment-metadata">' . implode("\n", $metadata_blocks) . '</div>';
     } else {
         $metadata_blocks = null;
     }
     return phutil_render_tag('div', array('class' => "differential-comment {$action_class}", 'id' => $comment_anchor), '<div class="differential-comment-head">' . '<span class="differential-comment-info">' . $info . '</span>' . '<span class="differential-comment-title">' . $title . '</span>' . '<div style="clear: both;"></div>' . '</div>' . '<div class="differential-comment-body" style="' . $background . '">' . '<div class="differential-comment-content">' . $head_content . $metadata_blocks . '<div class="differential-comment-core">' . $content . '</div>' . $inline_render . '</div>' . '</div>');
 }