public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $key => $application) {
         if (!$application->shouldAppearInLaunchView()) {
             unset($applications[$key]);
         }
     }
     $groups = PhabricatorApplication::getApplicationGroups();
     $applications = msort($applications, 'getApplicationOrder');
     $applications = mgroup($applications, 'getApplicationGroup');
     $applications = array_select_keys($applications, array_keys($groups));
     $view = array();
     foreach ($applications as $group => $application_list) {
         $status = array();
         foreach ($application_list as $key => $application) {
             $status[$key] = $application->loadStatus($user);
         }
         $views = array();
         foreach ($application_list as $key => $application) {
             $views[] = id(new PhabricatorApplicationLaunchView())->setApplication($application)->setApplicationStatus(idx($status, $key, array()))->setUser($user);
         }
         $view[] = id(new PhabricatorHeaderView())->setHeader($groups[$group]);
         $view[] = phutil_render_tag('div', array('class' => 'phabricator-application-list'), id(new AphrontNullView())->appendChild($views)->render());
     }
     return $this->buildApplicationPage($view, array('title' => 'Applications', 'device' => true));
 }
 private function getApplicationRoutes()
 {
     $applications = PhabricatorApplication::getAllInstalledApplications();
     $routes = array();
     foreach ($applications as $application) {
         $routes += $application->getRoutes();
     }
     return $routes;
 }
 public function getRoutingMaps()
 {
     $applications = PhabricatorApplication::getAllInstalledApplications();
     $maps = array();
     foreach ($applications as $application) {
         $maps[] = $this->newRoutingMap()->setApplication($application)->setRoutes($application->getResourceRoutes());
     }
     return $maps;
 }
 public static function getAllApplicationIterators()
 {
     $apps = PhabricatorApplication::getAllInstalledApplications();
     $iterators = array();
     foreach ($apps as $app) {
         foreach ($app->getFactObjectsForAnalysis() as $object) {
             $iterator = new PhabricatorFactUpdateIterator($object);
             $iterators[get_class($object)] = $iterator;
         }
     }
     return $iterators;
 }
 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;
         }
         $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())->setImageuRI($application->getIconURI())->setPriorityType('apps')->setImageSprite('phabricator-search-icon ' . $img);
     }
     return $this->filterResultsAgainstTokens($results);
 }
 public static function initialize()
 {
     $listeners = PhabricatorEnv::getEnvConfig('events.listeners');
     foreach ($listeners as $listener) {
         id(new $listener())->register();
     }
     // Register the DarkConosole event logger.
     id(new DarkConsoleEventPluginAPI())->register();
     id(new ManiphestEdgeEventListener())->register();
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         $listeners = $application->getEventListeners();
         foreach ($listeners as $listener) {
             $listener->register();
         }
     }
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $applications = PhabricatorApplication::getAllInstalledApplications();
     $applications = msort($applications, 'getName');
     foreach ($applications as $key => $application) {
         if (!$application->shouldAppearInLaunchView()) {
             unset($applications[$key]);
         }
     }
     $status = array();
     foreach ($applications as $key => $application) {
         $status[$key] = $application->loadStatus($user);
     }
     $views = array();
     foreach ($applications as $key => $application) {
         $views[] = id(new PhabricatorApplicationLaunchView())->setApplication($application)->setApplicationStatus(idx($status, $key, array()))->setUser($user);
     }
     $view = phutil_render_tag('div', array('class' => 'phabricator-application-list'), id(new AphrontNullView())->appendChild($views)->render());
     return $this->buildStandardPageResponse($view, array('title' => 'Applications'));
 }
 public static function initialize()
 {
     // NOTE: If any of this fails, we just log it and move on. It's important
     // to try to make it through here because users may have difficulty fixing
     // fix the errors if we don't: for example, if we fatal here a user may not
     // be able to run `bin/config` in order to remove an invalid listener.
     // Load automatic listeners.
     $listeners = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorAutoEventListener')->execute();
     // Load configured listeners.
     $config_listeners = PhabricatorEnv::getEnvConfig('events.listeners');
     foreach ($config_listeners as $listener_class) {
         try {
             $listeners[] = newv($listener_class, array());
         } catch (Exception $ex) {
             phlog($ex);
         }
     }
     // Add built-in listeners.
     $listeners[] = new DarkConsoleEventPluginAPI();
     // Add application listeners.
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         $app_listeners = $application->getEventListeners();
         foreach ($app_listeners as $listener) {
             $listener->setApplication($application);
             $listeners[] = $listener;
         }
     }
     // Now, register all of the listeners.
     foreach ($listeners as $listener) {
         try {
             $listener->register();
         } catch (Exception $ex) {
             phlog($ex);
         }
     }
 }
 /**
  * Map a specific path to the corresponding controller. For a description
  * of routing, see @{method:buildController}.
  *
  * @return pair<AphrontController,dict> Controller and dictionary of request
  *                                      parameters.
  * @task routing
  */
 public final function buildControllerForPath($path)
 {
     $maps = array();
     $maps[] = array(null, $this->getURIMap());
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         $maps[] = array($application, $application->getRoutes());
     }
     $current_application = null;
     $controller_class = null;
     foreach ($maps as $map_info) {
         list($application, $map) = $map_info;
         $mapper = new AphrontURIMapper($map);
         list($controller_class, $uri_data) = $mapper->mapPath($path);
         if ($controller_class) {
             if ($application) {
                 $current_application = $application;
             }
             break;
         }
     }
     if (!$controller_class) {
         return array(null, null);
     }
     $request = $this->getRequest();
     $controller = newv($controller_class, array($request));
     if ($current_application) {
         $controller->setCurrentApplication($current_application);
     }
     return array($controller, $uri_data);
 }
 public function render()
 {
     $viewer = $this->getViewer();
     require_celerity_resource('phabricator-main-menu-view');
     $header_id = celerity_generate_unique_node_id();
     $menu_bar = array();
     $alerts = array();
     $search_button = '';
     $app_button = '';
     $aural = null;
     if ($viewer->isLoggedIn() && $viewer->isUserActivated()) {
         list($menu, $dropdowns, $aural) = $this->renderNotificationMenu();
         if (array_filter($menu)) {
             $alerts[] = $menu;
         }
         $menu_bar = array_merge($menu_bar, $dropdowns);
         $app_button = $this->renderApplicationMenuButton($header_id);
         $search_button = $this->renderSearchMenuButton($header_id);
     } else {
         $app_button = $this->renderApplicationMenuButton($header_id);
         if (PhabricatorEnv::getEnvConfig('policy.allow-public')) {
             $search_button = $this->renderSearchMenuButton($header_id);
         }
     }
     $search_menu = $this->renderPhabricatorSearchMenu();
     if ($alerts) {
         $alerts = javelin_tag('div', array('class' => 'phabricator-main-menu-alerts', 'aural' => false), $alerts);
     }
     if ($aural) {
         $aural = javelin_tag('span', array('aural' => true), phutil_implode_html(' ', $aural));
     }
     $applications = PhabricatorApplication::getAllInstalledApplications();
     $menus = array();
     $controller = $this->getController();
     foreach ($applications as $application) {
         $app_actions = $application->buildMainMenuItems($viewer, $controller);
         $app_extra = $application->buildMainMenuExtraNodes($viewer, $controller);
         foreach ($app_actions as $action) {
             $menus[] = id(new PHUIMainMenuView())->setMenuBarItem($action)->setOrder($action->getOrder());
         }
         if ($app_extra !== null) {
             $menus[] = id(new PHUIMainMenuView())->appendChild($app_extra);
         }
     }
     $extensions = PhabricatorMainMenuBarExtension::getAllEnabledExtensions();
     foreach ($extensions as $extension) {
         $extension->setViewer($viewer);
         $controller = $this->getController();
         if ($controller) {
             $extension->setController($controller);
             $application = $controller->getCurrentApplication();
             if ($application) {
                 $extension->setApplication($application);
             }
         }
     }
     foreach ($extensions as $key => $extension) {
         if (!$extension->isExtensionEnabledForViewer($extension->getViewer())) {
             unset($extensions[$key]);
         }
     }
     foreach ($extensions as $extension) {
         foreach ($extension->buildMainMenus() as $menu) {
             $menus[] = $menu;
         }
     }
     $menus = msort($menus, 'getOrder');
     $bar_items = array();
     foreach ($menus as $menu) {
         $menu_bar[] = $menu;
         $item = $menu->getMenuBarItem();
         if ($item === null) {
             continue;
         }
         $bar_items[] = $item;
     }
     $application_menu = $this->renderApplicationMenu($bar_items);
     $classes = array();
     $classes[] = 'phabricator-main-menu';
     $classes[] = 'phabricator-main-menu-background';
     return phutil_tag('div', array('class' => implode(' ', $classes), 'id' => $header_id), array($app_button, $search_button, $this->renderPhabricatorLogo(), $alerts, $aural, $application_menu, $search_menu, $menu_bar));
 }
 public function renderApplicationMenu()
 {
     $user = $this->getUser();
     $controller = $this->getController();
     $applications = PhabricatorApplication::getAllInstalledApplications();
     $actions = array();
     foreach ($applications as $application) {
         $app_actions = $application->buildMainMenuItems($user, $controller);
         foreach ($app_actions as $action) {
             $actions[] = $action;
         }
     }
     $actions = msort($actions, 'getOrder');
     $view = $this->getApplicationMenu();
     if (!$view) {
         $view = new PHUIListView();
     }
     $view->addClass('phabricator-dark-menu');
     $view->addClass('phabricator-application-menu');
     if ($actions) {
         $view->addMenuItem(id(new PHUIListItemView())->setType(PHUIListItemView::TYPE_LABEL)->setName(pht('Actions')));
         foreach ($actions as $action) {
             $view->addMenuItem($action);
         }
     }
     return $view;
 }
 /**
  * @task engine
  */
 public static function newMarkupEngine(array $options)
 {
     $options += self::getMarkupEngineDefaultConfiguration();
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('preserve-linebreaks', $options['preserve-linebreaks']);
     $engine->setConfig('pygments.enabled', $options['pygments']);
     $engine->setConfig('uri.allowed-protocols', $options['uri.allowed-protocols']);
     $engine->setConfig('differential.diff', $options['differential.diff']);
     $engine->setConfig('header.generate-toc', $options['header.generate-toc']);
     $engine->setConfig('syntax-highlighter.engine', $options['syntax-highlighter.engine']);
     $engine->setConfig('uri.full', $options['uri.full']);
     $rules = array();
     $rules[] = new PhutilRemarkupEscapeRemarkupRule();
     $rules[] = new PhutilRemarkupMonospaceRule();
     $rules[] = new PhutilRemarkupDocumentLinkRule();
     $rules[] = new PhabricatorNavigationRemarkupRule();
     if ($options['youtube']) {
         $rules[] = new PhabricatorYoutubeRemarkupRule();
     }
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         foreach ($application->getRemarkupRules() as $rule) {
             $rules[] = $rule;
         }
     }
     $rules[] = new PhutilRemarkupHyperlinkRule();
     if ($options['macros']) {
         $rules[] = new PhabricatorImageMacroRemarkupRule();
         $rules[] = new PhabricatorMemeRemarkupRule();
     }
     $rules[] = new PhutilRemarkupBoldRule();
     $rules[] = new PhutilRemarkupItalicRule();
     $rules[] = new PhutilRemarkupDelRule();
     $rules[] = new PhutilRemarkupUnderlineRule();
     foreach (self::loadCustomInlineRules() as $rule) {
         $rules[] = $rule;
     }
     $blocks = array();
     $blocks[] = new PhutilRemarkupQuotesBlockRule();
     $blocks[] = new PhutilRemarkupReplyBlockRule();
     $blocks[] = new PhutilRemarkupLiteralBlockRule();
     $blocks[] = new PhutilRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupHorizontalRuleBlockRule();
     $blocks[] = new PhutilRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupNoteBlockRule();
     $blocks[] = new PhutilRemarkupTableBlockRule();
     $blocks[] = new PhutilRemarkupSimpleTableBlockRule();
     $blocks[] = new PhutilRemarkupInterpreterBlockRule();
     $blocks[] = new PhutilRemarkupDefaultBlockRule();
     foreach (self::loadCustomBlockRules() as $rule) {
         $blocks[] = $rule;
     }
     foreach ($blocks as $block) {
         $block->setMarkupRules($rules);
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }
 private function renderMainMenu()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $menu = new PhabricatorMainMenuView();
     $menu->setUser($user);
     $keyboard_config = array('helpURI' => '/help/keyboardshortcut/');
     if ($user->isLoggedIn()) {
         $search = new PhabricatorMainMenuSearchView();
         $search->setUser($user);
         $search->setScope($this->getSearchDefaultScope());
         $menu->appendChild($search);
         $pref_shortcut = PhabricatorUserPreferences::PREFERENCE_SEARCH_SHORTCUT;
         if ($user->loadPreferences()->getPreference($pref_shortcut, true)) {
             $keyboard_config['searchID'] = $search->getID();
         }
     }
     Javelin::initBehavior('phabricator-keyboard-shortcuts', $keyboard_config);
     $applications = PhabricatorApplication::getAllInstalledApplications();
     $icon_views = array();
     foreach ($applications as $application) {
         $icon_views[] = $application->buildMainMenuItems($this->getRequest()->getUser(), $this->getController());
     }
     $icon_views = array_mergev($icon_views);
     $icon_views = msort($icon_views, 'getSortOrder');
     $menu->appendChild($icon_views);
     return $menu->render();
 }
 private function renderNotificationMenu()
 {
     $user = $this->user;
     require_celerity_resource('phabricator-notification-css');
     require_celerity_resource('phabricator-notification-menu-css');
     require_celerity_resource('sprite-menu-css');
     $container_classes = array('sprite-menu', 'alert-notifications');
     $aural = array();
     $message_tag = '';
     $message_notification_dropdown = '';
     $conpherence = 'PhabricatorConpherenceApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($conpherence, $user)) {
         $message_id = celerity_generate_unique_node_id();
         $message_count_id = celerity_generate_unique_node_id();
         $message_dropdown_id = celerity_generate_unique_node_id();
         $unread_status = ConpherenceParticipationStatus::BEHIND;
         $unread = id(new ConpherenceParticipantCountQuery())->withParticipantPHIDs(array($user->getPHID()))->withParticipationStatus($unread_status)->execute();
         $message_count_number = idx($unread, $user->getPHID(), 0);
         if ($message_count_number) {
             $aural[] = phutil_tag('a', array('href' => '/conpherence/'), pht('%s unread messages.', new PhutilNumber($message_count_number)));
         } else {
             $aural[] = pht('No messages.');
         }
         if ($message_count_number > 999) {
             $message_count_number = "∞";
         }
         $message_count_tag = phutil_tag('span', array('id' => $message_count_id, 'class' => 'phabricator-main-menu-message-count'), $message_count_number);
         $message_icon_tag = phutil_tag('span', array('class' => 'sprite-menu phabricator-main-menu-message-icon'), '');
         if ($message_count_number) {
             $container_classes[] = 'message-unread';
         }
         $message_tag = phutil_tag('a', array('href' => '/conpherence/', 'class' => implode(' ', $container_classes), 'id' => $message_id), array($message_icon_tag, $message_count_tag));
         Javelin::initBehavior('aphlict-dropdown', array('bubbleID' => $message_id, 'countID' => $message_count_id, 'dropdownID' => $message_dropdown_id, 'loadingText' => pht('Loading...'), 'uri' => '/conpherence/panel/'));
         $message_notification_dropdown = javelin_tag('div', array('id' => $message_dropdown_id, 'class' => 'phabricator-notification-menu', 'sigil' => 'phabricator-notification-menu', 'style' => 'display: none;'), '');
     }
     $bubble_tag = '';
     $notification_dropdown = '';
     $notification_app = 'PhabricatorNotificationsApplication';
     if (PhabricatorApplication::isClassInstalledForViewer($notification_app, $user)) {
         $count_id = celerity_generate_unique_node_id();
         $dropdown_id = celerity_generate_unique_node_id();
         $bubble_id = celerity_generate_unique_node_id();
         $count_number = id(new PhabricatorFeedStoryNotification())->countUnread($user);
         if ($count_number) {
             $aural[] = phutil_tag('a', array('href' => '/notification/'), pht('%s unread notifications.', new PhutilNumber($count_number)));
         } else {
             $aural[] = pht('No notifications.');
         }
         if ($count_number > 999) {
             $count_number = "∞";
         }
         $count_tag = phutil_tag('span', array('id' => $count_id, 'class' => 'phabricator-main-menu-alert-count'), $count_number);
         $icon_tag = phutil_tag('span', array('class' => 'sprite-menu phabricator-main-menu-alert-icon'), '');
         if ($count_number) {
             $container_classes[] = 'alert-unread';
         }
         $bubble_tag = phutil_tag('a', array('href' => '/notification/', 'class' => implode(' ', $container_classes), 'id' => $bubble_id), array($icon_tag, $count_tag));
         Javelin::initBehavior('aphlict-dropdown', array('bubbleID' => $bubble_id, 'countID' => $count_id, 'dropdownID' => $dropdown_id, 'loadingText' => pht('Loading...'), 'uri' => '/notification/panel/'));
         $notification_dropdown = javelin_tag('div', array('id' => $dropdown_id, 'class' => 'phabricator-notification-menu', 'sigil' => 'phabricator-notification-menu', 'style' => 'display: none;'), '');
     }
     $dropdowns = array($notification_dropdown, $message_notification_dropdown);
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         $dropdowns[] = $application->buildMainMenuExtraNodes($this->getUser(), $this->getController());
     }
     return array(array($bubble_tag, $message_tag), $dropdowns, $aural);
 }
示例#15
0
 private function renderApplications()
 {
     $core = array();
     $current = $this->currentApplication;
     $meta = null;
     $group_core = PhabricatorApplication::GROUP_CORE;
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         if ($application instanceof PhabricatorApplicationApplications) {
             $meta = $application;
             continue;
         }
         if ($application->getApplicationGroup() != $group_core) {
             continue;
         }
         if ($application->getApplicationOrder() !== null) {
             $core[] = $application;
         }
     }
     $core = msort($core, 'getApplicationOrder');
     if ($meta) {
         $core[] = $meta;
     }
     $core = mpull($core, null, 'getPHID');
     if ($current && empty($core[$current->getPHID()])) {
         array_unshift($core, $current);
     }
     Javelin::initBehavior('phabricator-tooltips', array());
     require_celerity_resource('aphront-tooltip-css');
     $apps = array();
     foreach ($core as $phid => $application) {
         $classes = array();
         $classes[] = 'phabricator-nav-app-item';
         if ($current && $phid == $current->getPHID()) {
             $selected = true;
         } else {
             $selected = false;
         }
         $iclasses = array();
         $iclasses[] = 'phabricator-nav-app-item-icon';
         $style = null;
         if ($application->getIconURI()) {
             $style = 'background-image: url(' . $application->getIconURI() . '); ' . 'background-size: 30px auto;';
         } else {
             $iclasses[] = 'autosprite';
             $sprite = $application->getAutospriteName();
             if ($selected) {
                 $sprite .= '-selected';
             }
             $iclasses[] = 'app-' . $sprite;
         }
         $icon = phutil_render_tag('span', array('class' => implode(' ', $iclasses), 'style' => $style), '');
         $apps[] = javelin_render_tag('a', array('class' => implode(' ', $classes), 'href' => $application->getBaseURI(), 'sigil' => 'has-tooltip', 'meta' => array('tip' => $application->getName(), 'align' => 'E')), $icon . phutil_escape_html($application->getName()));
     }
     return id(new AphrontNullView())->appendChild($apps);
 }
示例#16
0
 private function renderApplications()
 {
     $core = array();
     $current = $this->currentApplication;
     $meta = null;
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         if ($application instanceof PhabricatorApplicationApplications) {
             $meta = $application;
             continue;
         }
         if ($application->getCoreApplicationOrder() !== null) {
             $core[] = $application;
         }
     }
     $core = msort($core, 'getCoreApplicationOrder');
     if ($meta) {
         $core[] = $meta;
     }
     $core = mpull($core, null, 'getPHID');
     if ($current && empty($core[$current->getPHID()])) {
         array_unshift($core, $current);
     }
     $apps = array();
     foreach ($core as $phid => $application) {
         $classes = array();
         $classes[] = 'phabricator-nav-app-item';
         if ($current && $phid == $current->getPHID()) {
             $classes[] = 'phabricator-nav-app-item-selected';
         }
         $iclasses = array();
         $iclasses[] = 'phabricator-nav-app-item-icon';
         $style = null;
         if ($application->getIconURI()) {
             $style = 'background-image: url(' . $application->getIconURI() . '); ' . 'background-size: 30px auto;';
         } else {
             $iclasses[] = 'autosprite';
             $iclasses[] = 'app-' . $application->getAutospriteName();
         }
         $icon = phutil_render_tag('span', array('class' => implode(' ', $iclasses), 'style' => $style), '');
         $apps[] = phutil_render_tag('a', array('class' => implode(' ', $classes), 'href' => $application->getBaseURI()), $icon . phutil_escape_html($application->getName()));
     }
     return id(new AphrontNullView())->appendChild($apps);
 }
 public function testApplicationsInstalled()
 {
     $all = PhabricatorApplication::getAllApplications();
     $installed = PhabricatorApplication::getAllInstalledApplications();
     $this->assertEqual(count($all), count($installed), 'In test cases, all applications should default to installed.');
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $query = $request->getStr('q');
     $need_rich_data = false;
     $need_users = false;
     $need_applications = false;
     $need_all_users = false;
     $need_lists = false;
     $need_projs = false;
     $need_repos = false;
     $need_packages = false;
     $need_upforgrabs = false;
     $need_arcanist_projects = false;
     $need_noproject = false;
     $need_symbols = false;
     switch ($this->type) {
         case 'mainsearch':
             $need_users = true;
             $need_applications = true;
             $need_rich_data = true;
             $need_symbols = true;
             break;
         case 'searchowner':
             $need_users = true;
             $need_upforgrabs = true;
             break;
         case 'searchproject':
             $need_projs = true;
             $need_noproject = true;
             break;
         case 'users':
             $need_users = true;
             break;
         case 'mailable':
             $need_users = true;
             $need_lists = true;
             break;
         case 'allmailable':
             $need_users = true;
             $need_all_users = true;
             $need_lists = true;
             break;
         case 'projects':
             $need_projs = true;
             break;
         case 'usersorprojects':
             $need_users = true;
             $need_projs = true;
             break;
         case 'repositories':
             $need_repos = true;
             break;
         case 'packages':
             $need_packages = true;
             break;
         case 'accounts':
             $need_users = true;
             $need_all_users = true;
             break;
         case 'arcanistprojects':
             $need_arcanist_projects = true;
             break;
     }
     $results = array();
     if ($need_upforgrabs) {
         $results[] = id(new PhabricatorTypeaheadResult())->setName('upforgrabs (Up For Grabs)')->setPHID(ManiphestTaskOwner::OWNER_UP_FOR_GRABS);
     }
     if ($need_noproject) {
         $results[] = id(new PhabricatorTypeaheadResult())->setName('noproject (No Project)')->setPHID(ManiphestTaskOwner::PROJECT_NO_PROJECT);
     }
     if ($need_users) {
         $columns = array('isSystemAgent', 'isAdmin', 'isDisabled', 'userName', 'realName', 'phid');
         if ($query) {
             // This is an arbitrary limit which is just larger than any limit we
             // actually use in the application.
             // TODO: The datasource should pass this in the query.
             $limit = 15;
             $user_table = new PhabricatorUser();
             $conn_r = $user_table->establishConnection('r');
             $ids = queryfx_all($conn_r, 'SELECT id FROM %T WHERE username LIKE %>
         ORDER BY username ASC LIMIT %d', $user_table->getTableName(), $query, $limit);
             $ids = ipull($ids, 'id');
             if (count($ids) < $limit) {
                 // If we didn't find enough username hits, look for real name hits.
                 // We need to pull the entire pagesize so that we end up with the
                 // right number of items if this query returns many duplicate IDs
                 // that we've already selected.
                 $realname_ids = queryfx_all($conn_r, 'SELECT DISTINCT userID FROM %T WHERE token LIKE %>
           ORDER BY token ASC LIMIT %d', PhabricatorUser::NAMETOKEN_TABLE, $query, $limit);
                 $realname_ids = ipull($realname_ids, 'userID');
                 $ids = array_merge($ids, $realname_ids);
                 $ids = array_unique($ids);
                 $ids = array_slice($ids, 0, $limit);
             }
             // Always add the logged-in user because some tokenizers autosort them
             // first. They'll be filtered out on the client side if they don't
             // match the query.
             $ids[] = $request->getUser()->getID();
             if ($ids) {
                 $users = id(new PhabricatorUser())->loadColumnsWhere($columns, 'id IN (%Ld)', $ids);
             } else {
                 $users = array();
             }
         } else {
             $users = id(new PhabricatorUser())->loadColumns($columns);
         }
         if ($need_rich_data) {
             $phids = mpull($users, 'getPHID');
             $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
         }
         foreach ($users as $user) {
             if (!$need_all_users) {
                 if ($user->getIsSystemAgent()) {
                     continue;
                 }
                 if ($user->getIsDisabled()) {
                     continue;
                 }
             }
             $result = id(new PhabricatorTypeaheadResult())->setName($user->getFullName())->setURI('/p/' . $user->getUsername())->setPHID($user->getPHID())->setPriorityString($user->getUsername());
             if ($need_rich_data) {
                 $display_type = 'User';
                 if ($user->getIsAdmin()) {
                     $display_type = 'Administrator';
                 }
                 $result->setDisplayType($display_type);
                 $result->setImageURI($handles[$user->getPHID()]->getImageURI());
                 $result->setPriorityType('user');
             }
             $results[] = $result;
         }
     }
     if ($need_lists) {
         $lists = id(new PhabricatorMetaMTAMailingList())->loadAll();
         foreach ($lists as $list) {
             $results[] = id(new PhabricatorTypeaheadResult())->setName($list->getName())->setURI($list->getURI())->setPHID($list->getPHID());
         }
     }
     if ($need_projs) {
         $projs = id(new PhabricatorProject())->loadAllWhere('status != %d', PhabricatorProjectStatus::STATUS_ARCHIVED);
         foreach ($projs as $proj) {
             $results[] = id(new PhabricatorTypeaheadResult())->setName($proj->getName())->setURI('/project/view/' . $proj->getID() . '/')->setPHID($proj->getPHID());
         }
     }
     if ($need_repos) {
         $repos = id(new PhabricatorRepository())->loadAll();
         foreach ($repos as $repo) {
             $results[] = id(new PhabricatorTypeaheadResult())->setName('r' . $repo->getCallsign() . ' (' . $repo->getName() . ')')->setURI('/diffusion/' . $repo->getCallsign() . '/')->setPHID($repo->getPHID())->setPriorityString('r' . $repo->getCallsign());
         }
     }
     if ($need_packages) {
         $packages = id(new PhabricatorOwnersPackage())->loadAll();
         foreach ($packages as $package) {
             $results[] = id(new PhabricatorTypeaheadResult())->setName($package->getName())->setURI('/owners/package/' . $package->getID() . '/')->setPHID($package->getPHID());
         }
     }
     if ($need_arcanist_projects) {
         $arcprojs = id(new PhabricatorRepositoryArcanistProject())->loadAll();
         foreach ($arcprojs as $proj) {
             $results[] = id(new PhabricatorTypeaheadResult())->setName($proj->getName())->setPHID($proj->getPHID());
         }
     }
     if ($need_applications) {
         $applications = PhabricatorApplication::getAllInstalledApplications();
         foreach ($applications as $application) {
             $uri = $application->getTypeaheadURI();
             if (!$uri) {
                 continue;
             }
             $name = $application->getName() . ' ' . $application->getShortDescription();
             $results[] = id(new PhabricatorTypeaheadResult())->setName($name)->setURI($uri)->setPHID($application->getPHID())->setPriorityString($application->getName())->setDisplayName($application->getName())->setDisplayType($application->getShortDescription())->setImageuRI($application->getIconURI())->setPriorityType('apps');
         }
     }
     if ($need_symbols) {
         $symbols = id(new DiffusionSymbolQuery())->setNamePrefix($query)->setLimit(15)->needArcanistProjects(true)->needRepositories(true)->needPaths(true)->execute();
         foreach ($symbols as $symbol) {
             $lang = $symbol->getSymbolLanguage();
             $name = $symbol->getSymbolName();
             $type = $symbol->getSymbolType();
             $proj = $symbol->getArcanistProject()->getName();
             $results[] = id(new PhabricatorTypeaheadResult())->setName($name)->setURI($symbol->getURI())->setPHID(md5($symbol->getURI()))->setDisplayName($symbol->getName())->setDisplayType(strtoupper($lang) . ' ' . ucwords($type) . ' (' . $proj . ')')->setPriorityType('symb');
         }
     }
     $content = mpull($results, 'getWireFormat');
     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.
     $rows = array();
     foreach ($results as $result) {
         $wire = $result->getWireFormat();
         foreach ($wire as $k => $v) {
             $wire[$k] = phutil_escape_html($v);
         }
         $rows[] = $wire;
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Name', 'URI', 'PHID', 'Priority', 'Display Name', 'Display Type', 'Image URI', 'Priority Type'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Typeahead Results');
     $panel->appendChild($table);
     return $this->buildStandardPageResponse($panel, array('title' => 'Typeahead Results'));
 }