public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $results = $this->getBrowseQueryResults();
     $reason = $results->getReasonForEmptyResultSet();
     $content = array();
     $actions = $this->buildActionView($drequest);
     $properties = $this->buildPropertyView($drequest, $actions);
     $object_box = id(new PHUIObjectBoxView())->setHeader($this->buildHeaderView($drequest))->addPropertyList($properties);
     $content[] = $object_box;
     $content[] = $this->renderSearchForm($collapsed = true);
     if (!$results->isValidResults()) {
         $empty_result = new DiffusionEmptyResultView();
         $empty_result->setDiffusionRequest($drequest);
         $empty_result->setDiffusionBrowseResultSet($results);
         $empty_result->setView($this->getRequest()->getStr('view'));
         $content[] = $empty_result;
     } else {
         $phids = array();
         foreach ($results->getPaths() as $result) {
             $data = $result->getLastCommitData();
             if ($data) {
                 if ($data->getCommitDetail('authorPHID')) {
                     $phids[$data->getCommitDetail('authorPHID')] = true;
                 }
             }
         }
         $phids = array_keys($phids);
         $handles = $this->loadViewerHandles($phids);
         $browse_table = new DiffusionBrowseTableView();
         $browse_table->setDiffusionRequest($drequest);
         $browse_table->setHandles($handles);
         $browse_table->setPaths($results->getPaths());
         $browse_table->setUser($this->getRequest()->getUser());
         $browse_panel = new AphrontPanelView();
         $browse_panel->appendChild($browse_table);
         $browse_panel->setNoBackground();
         $content[] = $browse_panel;
     }
     $content[] = $this->buildOpenRevisions();
     $readme = $this->callConduitWithDiffusionRequest('diffusion.readmequery', array('paths' => $results->getPathDicts(), 'commit' => $drequest->getStableCommit()));
     if ($readme) {
         $box = new PHUIBoxView();
         $box->appendChild($readme);
         $box->addPadding(PHUI::PADDING_LARGE);
         $object_box = id(new PHUIObjectBoxView())->setHeaderText(pht('README'))->appendChild($box);
         $content[] = $object_box;
     }
     $crumbs = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'browse'));
     return $this->buildApplicationPage(array($crumbs, $content), array('title' => array(nonempty(basename($drequest->getPath()), '/'), $drequest->getRepository()->getCallsign() . ' Repository')));
 }
 private function processSearchRequest($request)
 {
     $panel = new PHUIBoxView();
     $admin = $request->getUser();
     $search = $request->getStr('query');
     $ldap_provider = PhabricatorLDAPAuthProvider::getLDAPProvider();
     if (!$ldap_provider) {
         throw new Exception(pht('No LDAP provider enabled!'));
     }
     $ldap_adapter = $ldap_provider->getAdapter();
     $ldap_adapter->setLoginUsername($request->getStr('username'));
     $ldap_adapter->setLoginPassword(new PhutilOpaqueEnvelope($request->getStr('password')));
     // This causes us to connect and bind.
     // TODO: Clean up this discard mode stuff.
     DarkConsoleErrorLogPluginAPI::enableDiscardMode();
     $ldap_adapter->getAccountID();
     DarkConsoleErrorLogPluginAPI::disableDiscardMode();
     $results = $ldap_adapter->searchLDAP('%Q', $search);
     foreach ($results as $key => $record) {
         $account_id = $ldap_adapter->readLDAPRecordAccountID($record);
         if (!$account_id) {
             unset($results[$key]);
             continue;
         }
         $info = array($account_id, $ldap_adapter->readLDAPRecordEmail($record), $ldap_adapter->readLDAPRecordRealName($record));
         $results[$key] = $info;
         $results[$key][] = $this->renderUserInputs($info);
     }
     $form = id(new AphrontFormView())->setUser($admin);
     $table = new AphrontTableView($results);
     $table->setHeaders(array(pht('Username'), pht('Email'), pht('Real Name'), pht('Import?')));
     $form->appendChild($table);
     $form->setAction($request->getRequestURI()->alter('import', 'true')->alter('search', null))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Import')));
     $panel->appendChild($form);
     return $panel;
 }
 private function buildNormalContent(DiffusionRequest $drequest)
 {
     $repository = $drequest->getRepository();
     $phids = array();
     $content = array();
     try {
         $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => 0, 'limit' => 15));
         $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
         foreach ($history as $item) {
             $data = $item->getCommitData();
             if ($data) {
                 if ($data->getCommitDetail('authorPHID')) {
                     $phids[$data->getCommitDetail('authorPHID')] = true;
                 }
                 if ($data->getCommitDetail('committerPHID')) {
                     $phids[$data->getCommitDetail('committerPHID')] = true;
                 }
             }
         }
         $history_exception = null;
     } catch (Exception $ex) {
         $history_results = null;
         $history = null;
         $history_exception = $ex;
     }
     try {
         $browse_results = DiffusionBrowseResultSet::newFromConduit($this->callConduitWithDiffusionRequest('diffusion.browsequery', array('path' => $drequest->getPath(), 'commit' => $drequest->getCommit())));
         $browse_paths = $browse_results->getPaths();
         foreach ($browse_paths as $item) {
             $data = $item->getLastCommitData();
             if ($data) {
                 if ($data->getCommitDetail('authorPHID')) {
                     $phids[$data->getCommitDetail('authorPHID')] = true;
                 }
                 if ($data->getCommitDetail('committerPHID')) {
                     $phids[$data->getCommitDetail('committerPHID')] = true;
                 }
             }
         }
         $browse_exception = null;
     } catch (Exception $ex) {
         $browse_results = null;
         $browse_paths = null;
         $browse_exception = $ex;
     }
     $phids = array_keys($phids);
     $handles = $this->loadViewerHandles($phids);
     if ($browse_results) {
         $readme = $this->callConduitWithDiffusionRequest('diffusion.readmequery', array('paths' => $browse_results->getPathDicts(), 'commit' => $drequest->getStableCommit()));
     } else {
         $readme = null;
     }
     $content[] = $this->buildBrowseTable($browse_results, $browse_paths, $browse_exception, $handles);
     $content[] = $this->buildHistoryTable($history_results, $history, $history_exception, $handles);
     try {
         $content[] = $this->buildTagListTable($drequest);
     } catch (Exception $ex) {
         if (!$repository->isImporting()) {
             $content[] = $this->renderStatusMessage(pht('Unable to Load Tags'), $ex->getMessage());
         }
     }
     try {
         $content[] = $this->buildBranchListTable($drequest);
     } catch (Exception $ex) {
         if (!$repository->isImporting()) {
             $content[] = $this->renderStatusMessage(pht('Unable to Load Branches'), $ex->getMessage());
         }
     }
     if ($readme) {
         $box = new PHUIBoxView();
         $box->appendChild($readme);
         $box->addPadding(PHUI::PADDING_LARGE);
         $panel = new PHUIObjectBoxView();
         $panel->setHeaderText(pht('README'));
         $panel->appendChild($box);
         $content[] = $panel;
     }
     return $content;
 }