public function execute()
 {
     $viewer = $this->getViewer();
     $conpherence_app = 'PhabricatorConpherenceApplication';
     $is_c_installed = PhabricatorApplication::isClassInstalledForViewer($conpherence_app, $viewer);
     $raw_message_count_number = null;
     $message_count_number = null;
     if ($is_c_installed) {
         $unread_status = ConpherenceParticipationStatus::BEHIND;
         $unread = id(new ConpherenceParticipantCountQuery())->withParticipantPHIDs(array($viewer->getPHID()))->withParticipationStatus($unread_status)->execute();
         $raw_message_count_number = idx($unread, $viewer->getPHID(), 0);
         $message_count_number = $this->formatNumber($raw_message_count_number);
     }
     $conpherence_data = array('isInstalled' => $is_c_installed, 'countType' => 'messages', 'count' => $message_count_number, 'rawCount' => $raw_message_count_number);
     $this->setConpherenceData($conpherence_data);
     $notification_app = 'PhabricatorNotificationsApplication';
     $is_n_installed = PhabricatorApplication::isClassInstalledForViewer($notification_app, $viewer);
     $notification_count_number = null;
     $raw_notification_count_number = null;
     if ($is_n_installed) {
         $raw_notification_count_number = id(new PhabricatorFeedStoryNotification())->countUnread($viewer);
         $notification_count_number = $this->formatNumber($raw_notification_count_number);
     }
     $notification_data = array('isInstalled' => $is_n_installed, 'countType' => 'notifications', 'count' => $notification_count_number, 'rawCount' => $raw_notification_count_number);
     $this->setNotificationData($notification_data);
     return array($notification_app => $this->getNotificationData(), $conpherence_app => $this->getConpherenceData());
 }
 public function buildIconNavView(PhabricatorProject $project)
 {
     $this->setProject($project);
     $viewer = $this->getViewer();
     $id = $project->getID();
     $picture = $project->getProfileImageURI();
     $name = $project->getName();
     $columns = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($project->getPHID()))->execute();
     if ($columns) {
         $board_icon = 'fa-columns';
     } else {
         $board_icon = 'fa-columns grey';
     }
     $nav = new AphrontSideNavFilterView();
     $nav->setIconNav(true);
     $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
     $nav->addIcon("profile/{$id}/", $name, null, $picture);
     $class = 'PhabricatorManiphestApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $phid = $project->getPHID();
         $nav->addIcon("board/{$id}/", pht('Workboard'), $board_icon);
         $query_uri = urisprintf('/maniphest/?statuses=open()&projects=%s#R', $phid);
         $nav->addIcon(null, pht('Open Tasks'), 'fa-anchor', null, $query_uri);
     }
     $nav->addIcon("feed/{$id}/", pht('Feed'), 'fa-newspaper-o');
     $nav->addIcon("members/{$id}/", pht('Members'), 'fa-group');
     $nav->addIcon("details/{$id}/", pht('Edit Details'), 'fa-pencil');
     return $nav;
 }
 protected function getBuiltinProfilePanels($object)
 {
     $viewer = $this->getViewer();
     $panels = array();
     $panels[] = $this->newPanel()->setBuiltinKey(self::PANEL_PROFILE)->setPanelKey(PhabricatorPeopleDetailsProfilePanel::PANELKEY);
     // TODO: Convert this into a proper panel type.
     $have_calendar = PhabricatorApplication::isClassInstalledForViewer('PhabricatorCalendarApplication', $viewer);
     if ($have_calendar) {
         $uri = urisprintf('/p/%s/calendar/', $object->getUsername());
         $panels[] = $this->newPanel()->setBuiltinKey('calendar')->setPanelKey(PhabricatorLinkProfilePanel::PANELKEY)->setPanelProperty('icon', 'calendar')->setPanelProperty('name', pht('Calendar'))->setPanelProperty('uri', $uri);
     }
     $have_maniphest = PhabricatorApplication::isClassInstalledForViewer('PhabricatorManiphestApplication', $viewer);
     if ($have_maniphest) {
         $uri = urisprintf('/maniphest/?statuses=open()&assigned=%s#R', $object->getPHID());
         $panels[] = $this->newPanel()->setBuiltinKey('tasks')->setPanelKey(PhabricatorLinkProfilePanel::PANELKEY)->setPanelProperty('icon', 'maniphest')->setPanelProperty('name', pht('Open Tasks'))->setPanelProperty('uri', $uri);
     }
     $have_differential = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDifferentialApplication', $viewer);
     if ($have_differential) {
         $uri = urisprintf('/differential/?authors=%s#R', $object->getPHID());
         $panels[] = $this->newPanel()->setBuiltinKey('revisions')->setPanelKey(PhabricatorLinkProfilePanel::PANELKEY)->setPanelProperty('icon', 'differential')->setPanelProperty('name', pht('Revisions'))->setPanelProperty('uri', $uri);
     }
     $have_diffusion = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDiffusionApplication', $viewer);
     if ($have_diffusion) {
         $uri = urisprintf('/audit/?authors=%s#R', $object->getPHID());
         $panels[] = $this->newPanel()->setBuiltinKey('commits')->setPanelKey(PhabricatorLinkProfilePanel::PANELKEY)->setPanelProperty('icon', 'diffusion')->setPanelProperty('name', pht('Commits'))->setPanelProperty('uri', $uri);
     }
     $panels[] = $this->newPanel()->setBuiltinKey(self::PANEL_MANAGE)->setPanelKey(PhabricatorPeopleManageProfilePanel::PANELKEY);
     return $panels;
 }
 public function buildIconNavView(PhabricatorUser $user)
 {
     $viewer = $this->getViewer();
     $picture = $user->getProfileImageURI();
     $name = $user->getUsername();
     $nav = new AphrontSideNavFilterView();
     $nav->setIconNav(true);
     $nav->setBaseURI(new PhutilURI('/p/'));
     $nav->addIcon("{$name}/", $name, null, $picture);
     $class = 'PhabricatorCalendarApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $nav->addIcon("{$name}/calendar/", pht('Calendar'), 'fa-calendar');
     }
     $class = 'PhabricatorManiphestApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $phid = $user->getPHID();
         $view_uri = sprintf('/maniphest/?statuses=open()&assigned=%s#R', $phid);
         $nav->addIcon('maniphest', pht('Open Tasks'), 'fa-anchor', null, $view_uri);
     }
     $class = 'PhabricatorDifferentialApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $username = phutil_escape_uri($name);
         $view_uri = '/differential/?authors=' . $username;
         $nav->addIcon('differential', pht('Revisions'), 'fa-cog', null, $view_uri);
     }
     $class = 'PhabricatorAuditApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $username = phutil_escape_uri($name);
         $view_uri = '/audit/?authors=' . $username;
         $nav->addIcon('audit', pht('Commits'), 'fa-code', null, $view_uri);
     }
     return $nav;
 }
 private function buildMainResponse()
 {
     require_celerity_resource('phabricator-dashboard-css');
     $viewer = $this->getViewer();
     $has_maniphest = PhabricatorApplication::isClassInstalledForViewer('PhabricatorManiphestApplication', $viewer);
     $has_diffusion = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDiffusionApplication', $viewer);
     $has_differential = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDifferentialApplication', $viewer);
     $revision_panel = null;
     if ($has_differential) {
         $revision_panel = $this->buildRevisionPanel();
     }
     $tasks_panel = null;
     if ($has_maniphest) {
         $tasks_panel = $this->buildTasksPanel();
     }
     $repository_panel = null;
     if ($has_diffusion) {
         $repository_panel = $this->buildRepositoryPanel();
     }
     $feed_panel = $this->buildFeedPanel();
     $dashboard = id(new AphrontMultiColumnView())->setFluidlayout(true)->setGutter(AphrontMultiColumnView::GUTTER_LARGE);
     $main_panel = phutil_tag('div', array('class' => 'homepage-panel'), array($revision_panel, $tasks_panel, $repository_panel));
     $dashboard->addColumn($main_panel, 'thirds');
     $side_panel = phutil_tag('div', array('class' => 'homepage-side-panel'), array($feed_panel));
     $dashboard->addColumn($side_panel, 'third');
     $view = id(new PHUIBoxView())->addClass('dashboard-view')->appendChild($dashboard);
     return $view;
 }
 public function execute()
 {
     $viewer = $this->getViewer();
     $conpherence_app = 'PhabricatorConpherenceApplication';
     $is_c_installed = PhabricatorApplication::isClassInstalledForViewer($conpherence_app, $viewer);
     if ($is_c_installed) {
         $raw_message_count_number = $viewer->getUnreadMessageCount();
         $message_count_number = $this->formatNumber($raw_message_count_number);
     } else {
         $raw_message_count_number = null;
         $message_count_number = null;
     }
     $conpherence_data = array('isInstalled' => $is_c_installed, 'countType' => 'messages', 'count' => $message_count_number, 'rawCount' => $raw_message_count_number);
     $this->setConpherenceData($conpherence_data);
     $notification_app = 'PhabricatorNotificationsApplication';
     $is_n_installed = PhabricatorApplication::isClassInstalledForViewer($notification_app, $viewer);
     if ($is_n_installed) {
         $raw_notification_count_number = $viewer->getUnreadNotificationCount();
         $notification_count_number = $this->formatNumber($raw_notification_count_number);
     } else {
         $notification_count_number = null;
         $raw_notification_count_number = null;
     }
     $notification_data = array('isInstalled' => $is_n_installed, 'countType' => 'notifications', 'count' => $notification_count_number, 'rawCount' => $raw_notification_count_number);
     $this->setNotificationData($notification_data);
     return array($notification_app => $this->getNotificationData(), $conpherence_app => $this->getConpherenceData());
 }
 private function buildMainResponse(array $projects)
 {
     assert_instances_of($projects, 'PhabricatorProject');
     $viewer = $this->getRequest()->getUser();
     $has_maniphest = PhabricatorApplication::isClassInstalledForViewer('PhabricatorManiphestApplication', $viewer);
     $has_audit = PhabricatorApplication::isClassInstalledForViewer('PhabricatorAuditApplication', $viewer);
     $has_differential = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDifferentialApplication', $viewer);
     if ($has_maniphest) {
         $unbreak_panel = $this->buildUnbreakNowPanel();
         $triage_panel = $this->buildNeedsTriagePanel($projects);
         $tasks_panel = $this->buildTasksPanel();
     } else {
         $unbreak_panel = null;
         $triage_panel = null;
         $tasks_panel = null;
     }
     if ($has_audit) {
         $audit_panel = $this->buildAuditPanel();
         $commit_panel = $this->buildCommitPanel();
     } else {
         $audit_panel = null;
         $commit_panel = null;
     }
     if (PhabricatorEnv::getEnvConfig('welcome.html') !== null) {
         $welcome_panel = $this->buildWelcomePanel();
     } else {
         $welcome_panel = null;
     }
     if ($has_differential) {
         $revision_panel = $this->buildRevisionPanel();
     } else {
         $revision_panel = null;
     }
     return array($welcome_panel, $unbreak_panel, $triage_panel, $revision_panel, $tasks_panel, $audit_panel, $commit_panel, $this->minipanels);
 }
 public function isEnabledForObject($object)
 {
     $viewer = $this->getViewer();
     $has_app = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDifferentialApplication', $viewer);
     if (!$has_app) {
         return false;
     }
     return $object instanceof DifferentialRevision;
 }
 public function isEnabledForObject($object)
 {
     $viewer = $this->getViewer();
     $has_app = PhabricatorApplication::isClassInstalledForViewer('PhabricatorManiphestApplication', $viewer);
     if (!$has_app) {
         return false;
     }
     return $object instanceof ManiphestTask;
 }
 public function isEnabledForObject($object)
 {
     $viewer = $this->getViewer();
     $has_app = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDiffusionApplication', $viewer);
     if (!$has_app) {
         return false;
     }
     return $object instanceof PhabricatorRepositoryCommit;
 }
 public function shouldEnableForObject($object)
 {
     $viewer = $this->getViewer();
     // Workboards are only available if Maniphest is installed.
     $class = 'PhabricatorManiphestApplication';
     if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         return false;
     }
     return true;
 }
 public function processRequest()
 {
     $viewer = $this->getRequest()->getUser();
     $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withUsernames(array($this->username))->needProfileImage(true)->needAvailability(true)->executeOne();
     if (!$user) {
         return new Aphront404Response();
     }
     require_celerity_resource('phabricator-profile-css');
     $profile = $user->loadUserProfile();
     $username = phutil_escape_uri($user->getUserName());
     $picture = $user->getProfileImageURI();
     $header = id(new PHUIHeaderView())->setHeader($user->getFullName())->setSubheader($profile->getTitle())->setImage($picture);
     $actions = id(new PhabricatorActionListView())->setObject($user)->setObjectURI($this->getRequest()->getRequestURI())->setUser($viewer);
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $user, PhabricatorPolicyCapability::CAN_EDIT);
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-pencil')->setName(pht('Edit Profile'))->setHref($this->getApplicationURI('editprofile/' . $user->getID() . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit));
     $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-picture-o')->setName(pht('Edit Profile Picture'))->setHref($this->getApplicationURI('picture/' . $user->getID() . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit));
     if ($viewer->getIsAdmin()) {
         $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-wrench')->setName(pht('Edit Settings'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref('/settings/' . $user->getID() . '/'));
         if ($user->getIsAdmin()) {
             $empower_icon = 'fa-arrow-circle-o-down';
             $empower_name = pht('Remove Administrator');
         } else {
             $empower_icon = 'fa-arrow-circle-o-up';
             $empower_name = pht('Make Administrator');
         }
         $actions->addAction(id(new PhabricatorActionView())->setIcon($empower_icon)->setName($empower_name)->setDisabled($user->getPHID() == $viewer->getPHID())->setWorkflow(true)->setHref($this->getApplicationURI('empower/' . $user->getID() . '/')));
         $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-tag')->setName(pht('Change Username'))->setWorkflow(true)->setHref($this->getApplicationURI('rename/' . $user->getID() . '/')));
         if ($user->getIsDisabled()) {
             $disable_icon = 'fa-check-circle-o';
             $disable_name = pht('Enable User');
         } else {
             $disable_icon = 'fa-ban';
             $disable_name = pht('Disable User');
         }
         $actions->addAction(id(new PhabricatorActionView())->setIcon($disable_icon)->setName($disable_name)->setDisabled($user->getPHID() == $viewer->getPHID())->setWorkflow(true)->setHref($this->getApplicationURI('disable/' . $user->getID() . '/')));
         $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-times')->setName(pht('Delete User'))->setDisabled($user->getPHID() == $viewer->getPHID())->setWorkflow(true)->setHref($this->getApplicationURI('delete/' . $user->getID() . '/')));
         $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-envelope')->setName(pht('Send Welcome Email'))->setWorkflow(true)->setHref($this->getApplicationURI('welcome/' . $user->getID() . '/')));
     }
     $properties = $this->buildPropertyView($user, $actions);
     $name = $user->getUsername();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($name);
     $class = 'PhabricatorConpherenceApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $href = '/conpherence/new/?participant=' . $user->getPHID();
         $image = id(new PHUIIconView())->setIconFont('fa-comments');
         $button = id(new PHUIButtonView())->setTag('a')->setColor(PHUIButtonView::SIMPLE)->setIcon($image)->setHref($href)->setText(pht('Send Message'))->setWorkflow(true);
         $header->addActionLink($button);
     }
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $nav = $this->buildIconNavView($user);
     $nav->selectFilter("{$name}/");
     $nav->appendChild($object_box);
     return $this->buildApplicationPage($nav, array('title' => $user->getUsername()));
 }
 private function buildBadges(PhabricatorUser $user, $viewer)
 {
     $class = 'PhabricatorBadgesApplication';
     $items = array();
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $badge_phids = $user->getBadgePHIDs();
         if ($badge_phids) {
             $badges = id(new PhabricatorBadgesQuery())->setViewer($viewer)->withPHIDs($badge_phids)->execute();
             foreach ($badges as $badge) {
                 $items[] = id(new PHUIBadgeMiniView())->setIcon($badge->getIcon())->setHeader($badge->getName())->setQuality($badge->getQuality());
             }
         }
     }
     return $items;
 }
 protected function newNavigationMenuItems(PhabricatorProfilePanelConfiguration $config)
 {
     $viewer = $this->getViewer();
     // Workboards are only available if Maniphest is installed.
     $class = 'PhabricatorManiphestApplication';
     if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         return array();
     }
     $project = $config->getProfileObject();
     $has_workboard = $project->getHasWorkboard();
     $id = $project->getID();
     $href = "/project/board/{$id}/";
     $name = $this->getDisplayName($config);
     $item = $this->newItem()->setHref($href)->setName($name)->setDisabled(!$has_workboard)->setIcon('fa-columns');
     return array($item);
 }
 public function processRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     // TODO: It would be nice to simply disable this panel, but we can't do
     // viewer-based checks for enabled panels right now.
     $app_class = 'PhabricatorOAuthServerApplication';
     $installed = PhabricatorApplication::isClassInstalledForViewer($app_class, $viewer);
     if (!$installed) {
         $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('OAuth Not Available'))->appendParagraph(pht('You do not have access to OAuth authorizations.'))->addCancelButton('/settings/');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $authorizations = id(new PhabricatorOAuthClientAuthorizationQuery())->setViewer($viewer)->withUserPHIDs(array($viewer->getPHID()))->execute();
     $authorizations = mpull($authorizations, null, 'getID');
     $panel_uri = $this->getPanelURI();
     $revoke = $request->getInt('revoke');
     if ($revoke) {
         if (empty($authorizations[$revoke])) {
             return new Aphront404Response();
         }
         if ($request->isFormPost()) {
             $authorizations[$revoke]->delete();
             return id(new AphrontRedirectResponse())->setURI($panel_uri);
         }
         $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Revoke Authorization?'))->appendParagraph(pht('This application will no longer be able to access Phabricator ' . 'on your behalf.'))->addSubmitButton(pht('Revoke Authorization'))->addCancelButton($panel_uri);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $highlight = $request->getInt('id');
     $rows = array();
     $rowc = array();
     foreach ($authorizations as $authorization) {
         if ($highlight == $authorization->getID()) {
             $rowc[] = 'highlighted';
         } else {
             $rowc[] = null;
         }
         $button = javelin_tag('a', array('href' => $this->getPanelURI('?revoke=' . $authorization->getID()), 'class' => 'small grey button', 'sigil' => 'workflow'), pht('Revoke'));
         $rows[] = array(phutil_tag('a', array('href' => $authorization->getClient()->getViewURI()), $authorization->getClient()->getName()), $authorization->getScopeString(), phabricator_datetime($authorization->getDateCreated(), $viewer), phabricator_datetime($authorization->getDateModified(), $viewer), $button);
     }
     $table = new AphrontTableView($rows);
     $table->setNoDataString(pht("You haven't authorized any OAuth applications."));
     $table->setRowClasses($rowc);
     $table->setHeaders(array(pht('Application'), pht('Scope'), pht('Created'), pht('Updated'), null));
     $table->setColumnClasses(array('pri', 'wide', 'right', 'right', 'action'));
     $header = id(new PHUIHeaderView())->setHeader(pht('OAuth Application Authorizations'));
     $panel = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($table);
     return $panel;
 }
 protected function willFilterPage(array $engines)
 {
     $viewer = $this->getViewer();
     foreach ($engines as $key => $engine) {
         $app_class = $engine->getEngineApplicationClass();
         if ($app_class === null) {
             continue;
         }
         $can_see = PhabricatorApplication::isClassInstalledForViewer($app_class, $viewer);
         if (!$can_see) {
             $this->didRejectResult($engine);
             unset($engines[$key]);
             continue;
         }
     }
     return $engines;
 }
 public function shouldEnableForObject($object)
 {
     $viewer = $this->getViewer();
     // Only render this element for milestones.
     if (!$object->isMilestone()) {
         return false;
     }
     // Don't show if points aren't configured.
     if (!ManiphestTaskPoints::getIsEnabled()) {
         return false;
     }
     // Points are only available if Maniphest is installed.
     $class = 'PhabricatorManiphestApplication';
     if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         return false;
     }
     return true;
 }
 private function buildBadgesView(PhabricatorUser $user)
 {
     $viewer = $this->getViewer();
     $class = 'PhabricatorBadgesApplication';
     $box = null;
     if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         $badge_phids = $user->getBadgePHIDs();
         if ($badge_phids) {
             $badges = id(new PhabricatorBadgesQuery())->setViewer($viewer)->withPHIDs($badge_phids)->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))->execute();
             $flex = new PHUIBadgeBoxView();
             foreach ($badges as $badge) {
                 $item = id(new PHUIBadgeView())->setIcon($badge->getIcon())->setHeader($badge->getName())->setSubhead($badge->getFlavor())->setQuality($badge->getQuality());
                 $flex->addItem($item);
             }
             $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Badges'))->appendChild($flex)->setBackground(PHUIBoxView::GREY);
         }
     }
     return $box;
 }
 protected function buildTableOfContents(array $changesets, array $visible_changesets, array $coverage)
 {
     $viewer = $this->getViewer();
     $toc_view = id(new PHUIDiffTableOfContentsListView())->setUser($viewer);
     $have_owners = PhabricatorApplication::isClassInstalledForViewer('PhabricatorOwnersApplication', $viewer);
     if ($have_owners) {
         $repository_phid = null;
         if ($changesets) {
             $changeset = head($changesets);
             $diff = $changeset->getDiff();
             $repository_phid = $diff->getRepositoryPHID();
         }
         if (!$repository_phid) {
             $have_owners = false;
         } else {
             if ($viewer->getPHID()) {
                 $packages = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))->withAuthorityPHIDs(array($viewer->getPHID()))->execute();
                 $toc_view->setAuthorityPackages($packages);
             }
             // TODO: For Subversion, we should adjust these paths to be relative to
             // the repository root where possible.
             $paths = mpull($changesets, 'getFilename');
             $control_query = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))->withControl($repository_phid, $paths);
             $control_query->execute();
         }
     }
     foreach ($changesets as $changeset_id => $changeset) {
         $is_visible = isset($visible_changesets[$changeset_id]);
         $anchor = $changeset->getAnchorName();
         $filename = $changeset->getFilename();
         $coverage_id = 'differential-mcoverage-' . md5($filename);
         $item = id(new PHUIDiffTableOfContentsItemView())->setChangeset($changeset)->setIsVisible($is_visible)->setAnchor($anchor)->setCoverage(idx($coverage, $filename))->setCoverageID($coverage_id);
         if ($have_owners) {
             $package = $control_query->getControllingPackageForPath($repository_phid, $changeset->getFilename());
             if ($package) {
                 $item->setPackage($package);
             }
         }
         $toc_view->addItem($item);
     }
     return $toc_view;
 }
 public function loadResults()
 {
     $viewer = $this->getViewer();
     $raw_query = $this->getRawQuery();
     $results = array();
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         $uri = $application->getTypeaheadURI();
         if (!$uri) {
             continue;
         }
         $is_installed = PhabricatorApplication::isClassInstalledForViewer(get_class($application), $viewer);
         if (!$is_installed) {
             continue;
         }
         $name = $application->getName() . ' ' . $application->getShortDescription();
         $img = 'phui-font-fa phui-icon-view ' . $application->getIcon();
         $results[] = id(new PhabricatorTypeaheadResult())->setName($name)->setURI($uri)->setPHID($application->getPHID())->setPriorityString($application->getName())->setDisplayName($application->getName())->setDisplayType($application->getShortDescription())->setPriorityType('apps')->setImageSprite('phabricator-search-icon ' . $img)->setIcon($application->getIcon())->addAttribute($application->getShortDescription());
     }
     return $this->filterResultsAgainstTokens($results);
 }
 protected function newNavigationMenuItems(PhabricatorProfilePanelConfiguration $config)
 {
     $viewer = $this->getViewer();
     // Workboards are only available if Maniphest is installed.
     $class = 'PhabricatorManiphestApplication';
     if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         return array();
     }
     $project = $config->getProfileObject();
     $columns = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($project->getPHID()))->execute();
     if ($columns) {
         $icon = 'fa-columns';
     } else {
         $icon = 'fa-columns grey';
     }
     $id = $project->getID();
     $href = "/project/board/{$id}/";
     $name = $this->getDisplayName($config);
     $item = id(new PHUIListItemView())->setRenderNameAsTooltip(true)->setType(PHUIListItemView::TYPE_ICON_NAV)->setHref($href)->setName($name)->setIcon($icon);
     return array($item);
 }
 private function buildBadgesView(PhabricatorUser $user)
 {
     $viewer = $this->getViewer();
     $class = 'PhabricatorBadgesApplication';
     if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
         return null;
     }
     $badge_phids = $user->getBadgePHIDs();
     if ($badge_phids) {
         $badges = id(new PhabricatorBadgesQuery())->setViewer($viewer)->withPHIDs($badge_phids)->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))->execute();
         $flex = new PHUIBadgeBoxView();
         foreach ($badges as $badge) {
             $item = id(new PHUIBadgeView())->setIcon($badge->getIcon())->setHeader($badge->getName())->setSubhead($badge->getFlavor())->setQuality($badge->getQuality());
             $flex->addItem($item);
         }
     } else {
         $error = id(new PHUIBoxView())->addClass('mlb')->appendChild(pht('User does not have any badges.'));
         $flex = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NODATA)->appendChild($error);
     }
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Badges'))->addClass('project-view-badges')->appendChild($flex)->setBackground(PHUIObjectBoxView::GREY);
     return $box;
 }
 private function handleHovercardEvent($event)
 {
     $viewer = $event->getUser();
     $hovercard = $event->getValue('hovercard');
     $object_handle = $event->getValue('handle');
     $phid = $object_handle->getPHID();
     $user = $event->getValue('object');
     if (!$user instanceof PhabricatorUser) {
         return;
     }
     $profile = $user->loadUserProfile();
     $hovercard->setTitle($user->getUsername());
     $hovercard->setDetail(pht('%s - %s.', $user->getRealname(), nonempty($profile->getTitle(), pht('No title was found befitting of this rare specimen'))));
     if ($user->getIsDisabled()) {
         $hovercard->addField(pht('Account'), pht('Disabled'));
     } else {
         if (!$user->isUserActivated()) {
             $hovercard->addField(pht('Account'), pht('Not Activated'));
         } else {
             if (PhabricatorApplication::isClassInstalledForViewer('PhabricatorCalendarApplication', $viewer)) {
                 $statuses = id(new PhabricatorCalendarEvent())->loadCurrentStatuses(array($user->getPHID()));
                 if ($statuses) {
                     $current_status = reset($statuses);
                     $dateto = phabricator_datetime($current_status->getDateTo(), $user);
                     $hovercard->addField(pht('Status'), $current_status->getDescription());
                     $hovercard->addField(pht('Until'), $dateto);
                 } else {
                     $hovercard->addField(pht('Status'), pht('Available'));
                 }
             }
         }
     }
     $hovercard->addField(pht('User since'), phabricator_date($user->getDateCreated(), $user));
     if ($profile->getBlurb()) {
         $hovercard->addField(pht('Blurb'), id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(120)->truncateString($profile->getBlurb()));
     }
     $event->setValue('hovercard', $hovercard);
 }
 private function handleHovercardEvent($event)
 {
     $viewer = $event->getUser();
     $hovercard = $event->getValue('hovercard');
     $object_handle = $event->getValue('handle');
     $phid = $object_handle->getPHID();
     $user = $event->getValue('object');
     if (!$user instanceof PhabricatorUser) {
         return;
     }
     // Reload to get availability.
     $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withIDs(array($user->getID()))->needAvailability(true)->needProfile(true)->executeOne();
     $hovercard->setTitle($user->getUsername());
     $profile = $user->getUserProfile();
     $detail = $user->getRealName();
     if ($profile->getTitle()) {
         $detail .= ' - ' . $profile->getTitle() . '.';
     }
     $hovercard->setDetail($detail);
     if ($user->getIsDisabled()) {
         $hovercard->addField(pht('Account'), pht('Disabled'));
     } else {
         if (!$user->isUserActivated()) {
             $hovercard->addField(pht('Account'), pht('Not Activated'));
         } else {
             if (PhabricatorApplication::isClassInstalledForViewer('PhabricatorCalendarApplication', $viewer)) {
                 $hovercard->addField(pht('Status'), $user->getAvailabilityDescription($viewer));
             }
         }
     }
     $hovercard->addField(pht('User Since'), phabricator_date($user->getDateCreated(), $viewer));
     if ($profile->getBlurb()) {
         $hovercard->addField(pht('Blurb'), id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(120)->truncateString($profile->getBlurb()));
     }
     $event->setValue('hovercard', $hovercard);
 }
 public static final function buildExtensionPanels(PhabricatorUser $viewer, $object)
 {
     $extensions = self::getAllExtensions();
     foreach ($extensions as $extension) {
         $extension->setViewer($viewer);
     }
     foreach ($extensions as $key => $extension) {
         $application = $extension->getExtensionApplication();
         if (!$application instanceof PhabricatorApplication) {
             throw new Exception(pht('Curtain extension ("%s", of class "%s") did not return an ' . 'application from method "%s". This method must return an ' . 'object of class "%s".', $key, get_class($extension), 'getExtensionApplication()', 'PhabricatorApplication'));
         }
         $has_application = PhabricatorApplication::isClassInstalledForViewer(get_class($application), $viewer);
         if (!$has_application) {
             unset($extensions[$key]);
         }
     }
     foreach ($extensions as $key => $extension) {
         if (!$extension->shouldEnableForObject($object)) {
             unset($extensions[$key]);
         }
     }
     $result = array();
     foreach ($extensions as $key => $extension) {
         $panels = $extension->buildCurtainPanels($object);
         if (!is_array($panels)) {
             throw new Exception(pht('Curtain extension ("%s", of class "%s") did not return a list of ' . 'curtain panels from method "%s". This method must return an ' . 'array, and each value in the array must be a "%s" object.', $key, get_class($extension), 'buildCurtainPanels()', 'PHUICurtainPanelView'));
         }
         foreach ($panels as $panel_key => $panel) {
             if (!$panel instanceof PHUICurtainPanelView) {
                 throw new Exception(pht('Curtain extension ("%s", of class "%s") returned a list of ' . 'curtain panels from "%s" that contains an invalid value: ' . 'a value (with key "%s") is not an object of class "%s". ' . 'Each item in the returned array must be a panel.', $key, get_class($extension), 'buildCurtainPanels()', $panel_key, 'PHUICurtainPanelView'));
             }
             $result[] = $panel;
         }
     }
     return $result;
 }
 protected function renderInput()
 {
     $id = $this->getID();
     if (!$id) {
         $id = celerity_generate_unique_node_id();
         $this->setID($id);
     }
     $viewer = $this->getUser();
     if (!$viewer) {
         throw new PhutilInvalidStateException('setUser');
     }
     // We need to have this if previews render images, since Ajax can not
     // currently ship JS or CSS.
     require_celerity_resource('lightbox-attachment-css');
     if (!$this->getDisabled()) {
         Javelin::initBehavior('aphront-drag-and-drop-textarea', array('target' => $id, 'activatedClass' => 'aphront-textarea-drag-and-drop', 'uri' => '/file/dropupload/', 'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold()));
     }
     $root_id = celerity_generate_unique_node_id();
     $user_datasource = new PhabricatorPeopleDatasource();
     $proj_datasource = id(new PhabricatorProjectDatasource())->setParameters(array('autocomplete' => 1));
     Javelin::initBehavior('phabricator-remarkup-assist', array('pht' => array('bold text' => pht('bold text'), 'italic text' => pht('italic text'), 'monospaced text' => pht('monospaced text'), 'List Item' => pht('List Item'), 'Quoted Text' => pht('Quoted Text'), 'data' => pht('data'), 'name' => pht('name'), 'URL' => pht('URL')), 'disabled' => $this->getDisabled(), 'rootID' => $root_id, 'autocompleteMap' => (object) array(64 => array('datasourceURI' => $user_datasource->getDatasourceURI(), 'headerIcon' => 'fa-user', 'headerText' => pht('Find User:'******'hintText' => $user_datasource->getPlaceholderText()), 35 => array('datasourceURI' => $proj_datasource->getDatasourceURI(), 'headerIcon' => 'fa-briefcase', 'headerText' => pht('Find Project:'), 'hintText' => $proj_datasource->getPlaceholderText()))));
     Javelin::initBehavior('phabricator-tooltips', array());
     $actions = array('fa-bold' => array('tip' => pht('Bold'), 'nodevice' => true), 'fa-italic' => array('tip' => pht('Italics'), 'nodevice' => true), 'fa-text-width' => array('tip' => pht('Monospaced'), 'nodevice' => true), 'fa-link' => array('tip' => pht('Link'), 'nodevice' => true), array('spacer' => true, 'nodevice' => true), 'fa-list-ul' => array('tip' => pht('Bulleted List'), 'nodevice' => true), 'fa-list-ol' => array('tip' => pht('Numbered List'), 'nodevice' => true), 'fa-code' => array('tip' => pht('Code Block'), 'nodevice' => true), 'fa-quote-right' => array('tip' => pht('Quote'), 'nodevice' => true), 'fa-table' => array('tip' => pht('Table'), 'nodevice' => true), 'fa-cloud-upload' => array('tip' => pht('Upload File')));
     $can_use_macros = !$this->disableMacro && function_exists('imagettftext');
     if ($can_use_macros) {
         $can_use_macros = PhabricatorApplication::isClassInstalledForViewer('PhabricatorMacroApplication', $viewer);
     }
     if ($can_use_macros) {
         $actions[] = array('spacer' => true);
         $actions['fa-meh-o'] = array('tip' => pht('Meme'));
     }
     $actions['fa-eye'] = array('tip' => pht('Preview'), 'align' => 'right');
     $actions[] = array('spacer' => true, 'align' => 'right');
     $actions['fa-life-bouy'] = array('tip' => pht('Help'), 'align' => 'right', 'href' => PhabricatorEnv::getDoclink('Remarkup Reference'));
     if (!$this->disableFullScreen) {
         $actions[] = array('spacer' => true, 'align' => 'right');
         $actions['fa-arrows-alt'] = array('tip' => pht('Fullscreen Mode'), 'align' => 'right');
     }
     $buttons = array();
     foreach ($actions as $action => $spec) {
         $classes = array();
         if (idx($spec, 'align') == 'right') {
             $classes[] = 'remarkup-assist-right';
         }
         if (idx($spec, 'nodevice')) {
             $classes[] = 'remarkup-assist-nodevice';
         }
         if (idx($spec, 'spacer')) {
             $classes[] = 'remarkup-assist-separator';
             $buttons[] = phutil_tag('span', array('class' => implode(' ', $classes)), '');
             continue;
         } else {
             $classes[] = 'remarkup-assist-button';
         }
         $href = idx($spec, 'href', '#');
         if ($href == '#') {
             $meta = array('action' => $action);
             $mustcapture = true;
             $target = null;
         } else {
             $meta = array();
             $mustcapture = null;
             $target = '_blank';
         }
         $content = null;
         $tip = idx($spec, 'tip');
         if ($tip) {
             $meta['tip'] = $tip;
             $content = javelin_tag('span', array('aural' => true), $tip);
         }
         $sigils = array();
         $sigils[] = 'remarkup-assist';
         if (!$this->getDisabled()) {
             $sigils[] = 'has-tooltip';
         }
         $buttons[] = javelin_tag('a', array('class' => implode(' ', $classes), 'href' => $href, 'sigil' => implode(' ', $sigils), 'meta' => $meta, 'mustcapture' => $mustcapture, 'target' => $target, 'tabindex' => -1), phutil_tag('div', array('class' => 'remarkup-assist phui-icon-view phui-font-fa bluegrey ' . $action), $content));
     }
     $buttons = phutil_tag('div', array('class' => 'remarkup-assist-bar'), $buttons);
     $use_monospaced = $viewer->compareUserSetting(PhabricatorMonospacedTextareasSetting::SETTINGKEY, PhabricatorMonospacedTextareasSetting::VALUE_TEXT_MONOSPACED);
     if ($use_monospaced) {
         $monospaced_textareas_class = 'PhabricatorMonospaced';
     } else {
         $monospaced_textareas_class = null;
     }
     $this->setCustomClass('remarkup-assist-textarea ' . $monospaced_textareas_class);
     return javelin_tag('div', array('sigil' => 'remarkup-assist-control', 'class' => $this->getDisabled() ? 'disabled-control' : null, 'id' => $root_id), array($buttons, parent::renderInput()));
 }
 private function buildQuicksandConfig()
 {
     $viewer = $this->getRequest()->getUser();
     $controller = $this->getController();
     $dropdown_query = id(new AphlictDropdownDataQuery())->setViewer($viewer);
     $dropdown_query->execute();
     $rendered_dropdowns = array();
     $applications = array('PhabricatorHelpApplication');
     foreach ($applications as $application_class) {
         if (!PhabricatorApplication::isClassInstalledForViewer($application_class, $viewer)) {
             continue;
         }
         $application = PhabricatorApplication::getByClass($application_class);
         $rendered_dropdowns[$application_class] = $application->buildMainMenuExtraNodes($viewer, $controller);
     }
     $hisec_warning_config = $this->getHighSecurityWarningConfig();
     $console_config = null;
     $console = $this->getConsole();
     if ($console) {
         $console_config = $this->getConsoleConfig();
     }
     $upload_enabled = false;
     if ($controller) {
         $upload_enabled = $controller->isGlobalDragAndDropUploadEnabled();
     }
     $application_class = null;
     $application_search_icon = null;
     $controller = $this->getController();
     if ($controller) {
         $application = $controller->getCurrentApplication();
         if ($application) {
             $application_class = get_class($application);
             if ($application->getApplicationSearchDocumentTypes()) {
                 $application_search_icon = $application->getIcon();
             }
         }
     }
     return array('title' => $this->getTitle(), 'aphlictDropdownData' => array($dropdown_query->getNotificationData(), $dropdown_query->getConpherenceData()), 'globalDragAndDrop' => $upload_enabled, 'aphlictDropdowns' => $rendered_dropdowns, 'hisecWarningConfig' => $hisec_warning_config, 'consoleConfig' => $console_config, 'applicationClass' => $application_class, 'applicationSearchIcon' => $application_search_icon) + $this->buildAphlictListenConfigData();
 }
 private function buildTableOfContents(array $changesets)
 {
     $drequest = $this->getDiffusionRequest();
     $viewer = $this->getViewer();
     $toc_view = id(new PHUIDiffTableOfContentsListView())->setUser($viewer);
     // TODO: This is hacky, we just want access to the linkX() methods on
     // DiffusionView.
     $diffusion_view = id(new DiffusionEmptyResultView())->setDiffusionRequest($drequest);
     $have_owners = PhabricatorApplication::isClassInstalledForViewer('PhabricatorOwnersApplication', $viewer);
     if (!$changesets) {
         $have_owners = false;
     }
     if ($have_owners) {
         if ($viewer->getPHID()) {
             $packages = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))->withAuthorityPHIDs(array($viewer->getPHID()))->execute();
             $toc_view->setAuthorityPackages($packages);
         }
         $repository = $drequest->getRepository();
         $repository_phid = $repository->getPHID();
         $control_query = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))->withControl($repository_phid, mpull($changesets, 'getFilename'));
         $control_query->execute();
     }
     foreach ($changesets as $changeset_id => $changeset) {
         $path = $changeset->getFilename();
         $anchor = substr(md5($path), 0, 8);
         $history_link = $diffusion_view->linkHistory($path);
         $browse_link = $diffusion_view->linkBrowse($path);
         $item = id(new PHUIDiffTableOfContentsItemView())->setChangeset($changeset)->setAnchor($anchor)->setContext(array($history_link, ' ', $browse_link));
         if ($have_owners) {
             $package = $control_query->getControllingPackageForPath($repository_phid, $changeset->getFilename());
             if ($package) {
                 $item->setPackage($package);
             }
         }
         $toc_view->addItem($item);
     }
     return $toc_view;
 }
 public final function execute(PhutilArgumentParser $args)
 {
     $this->args = $args;
     $viewer = $this->getUser();
     $have_diffusion = PhabricatorApplication::isClassInstalledForViewer('PhabricatorDiffusionApplication', $viewer);
     if (!$have_diffusion) {
         throw new Exception(pht('You do not have permission to access the Diffusion application, ' . 'so you can not interact with repositories over SSH.'));
     }
     $repository = $this->identifyRepository();
     $this->setRepository($repository);
     $is_cluster_request = $this->getIsClusterRequest();
     $uri = $repository->getAlmanacServiceURI($viewer, $is_cluster_request, array('ssh'));
     if ($uri) {
         $this->proxyURI = $uri;
     }
     try {
         return $this->executeRepositoryOperations();
     } catch (Exception $ex) {
         $this->writeError(get_class($ex) . ': ' . $ex->getMessage());
         return 1;
     }
 }
 public function handleRequest(AphrontRequest $request)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $query = $request->getStr('q');
     $offset = $request->getInt('offset');
     $select_phid = null;
     $is_browse = $request->getURIData('action') == 'browse';
     $select = $request->getStr('select');
     if ($select) {
         $select = phutil_json_decode($select);
         $query = idx($select, 'q');
         $offset = idx($select, 'offset');
         $select_phid = idx($select, 'phid');
     }
     // Default this to the query string to make debugging a little bit easier.
     $raw_query = nonempty($request->getStr('raw'), $query);
     // This makes form submission easier in the debug view.
     $class = nonempty($request->getURIData('class'), $request->getStr('class'));
     $sources = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorTypeaheadDatasource')->execute();
     if (isset($sources[$class])) {
         $source = $sources[$class];
         $source->setParameters($request->getRequestData());
         $source->setViewer($viewer);
         // NOTE: Wrapping the source in a Composite datasource ensures we perform
         // application visibility checks for the viewer, so we do not need to do
         // those separately.
         $composite = new PhabricatorTypeaheadRuntimeCompositeDatasource();
         $composite->addDatasource($source);
         $hard_limit = 1000;
         $limit = 100;
         $composite->setViewer($viewer)->setQuery($query)->setRawQuery($raw_query)->setLimit($limit + 1);
         if ($is_browse) {
             if (!$composite->isBrowsable()) {
                 return new Aphront404Response();
             }
             if ($offset + $limit >= $hard_limit) {
                 // Offset-based paging is intrinsically slow; hard-cap how far we're
                 // willing to go with it.
                 return new Aphront404Response();
             }
             $composite->setOffset($offset)->setIsBrowse(true);
         }
         $results = $composite->loadResults();
         if ($is_browse) {
             // If this is a request for a specific token after the user clicks
             // "Select", return the token in wire format so it can be added to
             // the tokenizer.
             if ($select_phid !== null) {
                 $map = mpull($results, null, 'getPHID');
                 $token = idx($map, $select_phid);
                 if (!$token) {
                     return new Aphront404Response();
                 }
                 $payload = array('key' => $token->getPHID(), 'token' => $token->getWireFormat());
                 return id(new AphrontAjaxResponse())->setContent($payload);
             }
             $format = $request->getStr('format');
             switch ($format) {
                 case 'html':
                 case 'dialog':
                     // These are the acceptable response formats.
                     break;
                 default:
                     // Return a dialog if format information is missing or invalid.
                     $format = 'dialog';
                     break;
             }
             $next_link = null;
             if (count($results) > $limit) {
                 $results = array_slice($results, 0, $limit, $preserve_keys = true);
                 if ($offset + 2 * $limit < $hard_limit) {
                     $next_uri = id(new PhutilURI($request->getRequestURI()))->setQueryParam('offset', $offset + $limit)->setQueryParam('q', $query)->setQueryParam('raw', $raw_query)->setQueryParam('format', 'html');
                     $next_link = javelin_tag('a', array('href' => $next_uri, 'class' => 'typeahead-browse-more', 'sigil' => 'typeahead-browse-more', 'mustcapture' => true), pht('More Results'));
                 } else {
                     // If the user has paged through more than 1K results, don't
                     // offer to page any further.
                     $next_link = javelin_tag('div', array('class' => 'typeahead-browse-hard-limit'), pht('You reach the edge of the abyss.'));
                 }
             }
             $exclude = $request->getStrList('exclude');
             $exclude = array_fuse($exclude);
             $select = array('offset' => $offset, 'q' => $query);
             $items = array();
             foreach ($results as $result) {
                 // Disable already-selected tokens.
                 $disabled = isset($exclude[$result->getPHID()]);
                 $value = $select + array('phid' => $result->getPHID());
                 $value = json_encode($value);
                 $button = phutil_tag('button', array('class' => 'small grey', 'name' => 'select', 'value' => $value, 'disabled' => $disabled ? 'disabled' : null), pht('Select'));
                 $information = $this->renderBrowseResult($result, $button);
                 $items[] = phutil_tag('div', array('class' => 'typeahead-browse-item grouped'), $information);
             }
             $markup = array($items, $next_link);
             if ($format == 'html') {
                 $content = array('markup' => hsprintf('%s', $markup));
                 return id(new AphrontAjaxResponse())->setContent($content);
             }
             $this->requireResource('typeahead-browse-css');
             $this->initBehavior('typeahead-browse');
             $input_id = celerity_generate_unique_node_id();
             $frame_id = celerity_generate_unique_node_id();
             $config = array('inputID' => $input_id, 'frameID' => $frame_id, 'uri' => (string) $request->getRequestURI());
             $this->initBehavior('typeahead-search', $config);
             $search = javelin_tag('input', array('type' => 'text', 'id' => $input_id, 'class' => 'typeahead-browse-input', 'autocomplete' => 'off', 'placeholder' => $source->getPlaceholderText()));
             $frame = phutil_tag('div', array('class' => 'typeahead-browse-frame', 'id' => $frame_id), $markup);
             $browser = array(phutil_tag('div', array('class' => 'typeahead-browse-header'), $search), $frame);
             $function_help = null;
             if ($source->getAllDatasourceFunctions()) {
                 $reference_uri = '/typeahead/help/' . get_class($source) . '/';
                 $reference_link = phutil_tag('a', array('href' => $reference_uri, 'target' => '_blank'), pht('Reference: Advanced Functions'));
                 $function_help = array(id(new PHUIIconView())->setIcon('fa-book'), ' ', $reference_link);
             }
             return $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FORM)->setRenderDialogAsDiv(true)->setTitle($source->getBrowseTitle())->appendChild($browser)->setResizeX(true)->setResizeY($frame_id)->addFooter($function_help)->addCancelButton('/', pht('Close'));
         }
     } else {
         if ($is_browse) {
             return new Aphront404Response();
         } else {
             $results = array();
         }
     }
     $content = mpull($results, 'getWireFormat');
     $content = array_values($content);
     if ($request->isAjax()) {
         return id(new AphrontAjaxResponse())->setContent($content);
     }
     // If there's a non-Ajax request to this endpoint, show results in a tabular
     // format to make it easier to debug typeahead output.
     foreach ($sources as $key => $source) {
         // This can happen with composite or generic sources.
         if (!$source->getDatasourceApplicationClass()) {
             continue;
         }
         if (!PhabricatorApplication::isClassInstalledForViewer($source->getDatasourceApplicationClass(), $viewer)) {
             unset($sources[$key]);
         }
     }
     $options = array_fuse(array_keys($sources));
     asort($options);
     $form = id(new AphrontFormView())->setUser($viewer)->setAction('/typeahead/class/')->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Source Class'))->setName('class')->setValue($class)->setOptions($options))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Query'))->setName('q')->setValue($request->getStr('q')))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Raw Query'))->setName('raw')->setValue($request->getStr('raw')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Query')));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Token Query'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
     // Make "\n" delimiters more visible.
     foreach ($content as $key => $row) {
         $content[$key][0] = str_replace("\n", '<\\n>', $row[0]);
     }
     $table = new AphrontTableView($content);
     $table->setHeaders(array(pht('Name'), pht('URI'), pht('PHID'), pht('Priority'), pht('Display Name'), pht('Display Type'), pht('Image URI'), pht('Priority Type'), pht('Icon'), pht('Closed'), pht('Sprite'), pht('Color'), pht('Type'), pht('Unique'), pht('Auto'), pht('Phase')));
     $result_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Token Results (%s)', $class))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->appendChild($table);
     $title = pht('Typeahead Results');
     $header = id(new PHUIHeaderView())->setHeader($title);
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $result_box));
     return $this->newPage()->setTitle($title)->appendChild($view);
 }