public function processRequest()
 {
     $title = 'OAuth Clients';
     $request = $this->getRequest();
     $current_user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $page_size = 100;
     $pager = new AphrontPagerView();
     $request_uri = $request->getRequestURI();
     $pager->setURI($request_uri, 'offset');
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     $query = new PhabricatorOAuthServerClientQuery();
     $query->withCreatorPHIDs(array($current_user->getPHID()));
     $clients = $query->executeWithPager($pager);
     $rows = array();
     $rowc = array();
     $highlight = $this->getHighlightPHIDs();
     foreach ($clients as $client) {
         $row = array(phutil_render_tag('a', array('href' => $client->getViewURI()), phutil_escape_html($client->getName())), $client->getPHID(), $client->getSecret(), phutil_render_tag('a', array('href' => $client->getRedirectURI()), phutil_escape_html($client->getRedirectURI())), phutil_render_tag('a', array('class' => 'small button grey', 'href' => $client->getEditURI()), 'Edit'));
         $rows[] = $row;
         if (isset($highlight[$client->getPHID()])) {
             $rowc[] = 'highlighted';
         } else {
             $rowc[] = '';
         }
     }
     $panel = $this->buildClientList($rows, $rowc, $title);
     return $this->buildStandardPageResponse(array($this->getNoticeView(), $panel->appendChild($pager)), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $blueprint = id(new DrydockBlueprintQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne();
     if (!$blueprint) {
         return new Aphront404Response();
     }
     $title = $blueprint->getBlueprintName();
     $header = id(new PHUIHeaderView())->setHeader($title)->setUser($viewer)->setPolicyObject($blueprint);
     $actions = $this->buildActionListView($blueprint);
     $properties = $this->buildPropertyListView($blueprint, $actions);
     $blueprint_uri = 'blueprint/' . $blueprint->getID() . '/';
     $blueprint_uri = $this->getApplicationURI($blueprint_uri);
     $resources = id(new DrydockResourceQuery())->withBlueprintPHIDs(array($blueprint->getPHID()))->setViewer($viewer)->execute();
     $resource_list = id(new DrydockResourceListView())->setUser($viewer)->setResources($resources)->render();
     $resource_list->setNoDataString(pht('This blueprint has no resources.'));
     $pager = new AphrontPagerView();
     $pager->setURI(new PhutilURI($blueprint_uri), 'offset');
     $pager->setOffset($request->getInt('offset'));
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID()));
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $field_list = PhabricatorCustomField::getObjectFields($blueprint, PhabricatorCustomField::ROLE_VIEW);
     $field_list->setViewer($viewer)->readFieldsFromStorage($blueprint);
     $field_list->appendFieldsToPropertyList($blueprint, $viewer, $properties);
     $timeline = $this->buildTransactionTimeline($blueprint, new DrydockBlueprintTransactionQuery());
     $timeline->setShouldTerminate(true);
     return $this->buildApplicationPage(array($crumbs, $object_box, $resource_list, $timeline), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'page');
     $pager->setOffset($request->getInt('page'));
     $query = id(new PhabricatorTokenReceiverQuery());
     $objects = $query->setViewer($user)->executeWithOffsetPager($pager);
     $counts = $query->getTokenCounts();
     $handles = array();
     $phids = array();
     if ($counts) {
         $phids = mpull($objects, 'getPHID');
         $handles = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs($phids)->execute();
     }
     $list = new PHUIObjectItemListView();
     foreach ($phids as $object) {
         $count = idx($counts, $object, 0);
         $item = id(new PHUIObjectItemView());
         $handle = $handles[$object];
         $item->setHeader($handle->getFullName());
         $item->setHref($handle->getURI());
         $item->addAttribute(pht('Tokens: %s', $count));
         $list->addItem($item);
     }
     $title = pht('Token Leader Board');
     $nav = $this->buildSideNav();
     $nav->setCrumbs($this->buildApplicationCrumbs()->addTextCrumb($title));
     $nav->selectFilter('leaders/');
     $nav->appendChild($list);
     $nav->appendChild($pager);
     return $this->buildApplicationPage($nav, array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $nav = $this->buildSideNav('log');
     $query = new DrydockLogQuery();
     $resource_ids = $request->getStrList('resource');
     if ($resource_ids) {
         $query->withResourceIDs($resource_ids);
     }
     $lease_ids = $request->getStrList('lease');
     if ($lease_ids) {
         $query->withLeaseIDs($lease_ids);
     }
     $pager = new AphrontPagerView();
     $pager->setPageSize(500);
     $pager->setOffset($request->getInt('offset'));
     $pager->setURI($request->getRequestURI(), 'offset');
     $logs = $query->executeWithOffsetPager($pager);
     $rows = array();
     foreach ($logs as $log) {
         $rows[] = array($log->getResourceID(), $log->getLeaseID(), phutil_escape_html($log->getMessage()), phabricator_datetime($log->getEpoch(), $user));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Resource', 'Lease', 'Message', 'Date'));
     $table->setColumnClasses(array('', '', 'wide', ''));
     $panel = new AphrontPanelView();
     $panel->setHeader('Drydock Logs');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Logs'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $this->answerOffset = $request->getInt('aoff');
     $pages = array('feed' => 'All Questions', 'questions' => 'Your Questions', 'answers' => 'Your Answers');
     $side_nav = $this->buildSideNavView();
     $this->page = $side_nav->selectFilter($this->page, 'feed');
     $title = $pages[$this->page];
     switch ($this->page) {
         case 'feed':
         case 'questions':
             $pager = new AphrontPagerView();
             $pager->setOffset($request->getStr('offset'));
             $pager->setURI($request->getRequestURI(), 'offset');
             $query = new PonderQuestionQuery();
             if ($this->page == 'feed') {
                 $query->setOrder(PonderQuestionQuery::ORDER_HOTTEST);
             } else {
                 $query->setOrder(PonderQuestionQuery::ORDER_CREATED)->withAuthorPHIDs(array($user->getPHID()));
             }
             $questions = $query->executeWithOffsetPager($pager);
             $this->loadHandles(mpull($questions, 'getAuthorPHID'));
             $view = $this->buildQuestionListView($questions);
             $view->setPager($pager);
             $side_nav->appendChild(id(new PhabricatorHeaderView())->setHeader($title));
             $side_nav->appendChild($view);
             break;
         case 'answers':
             $answers = PonderAnswerQuery::loadByAuthorWithQuestions($user, $user->getPHID(), $this->answerOffset, self::PROFILE_ANSWER_PAGE_SIZE + 1);
             $side_nav->appendChild(id(new PonderUserProfileView())->setUser($user)->setAnswers($answers)->setAnswerOffset($this->answerOffset)->setPageSize(self::PROFILE_ANSWER_PAGE_SIZE)->setURI(new PhutilURI("/ponder/profile/"), "aoff"));
             break;
     }
     return $this->buildApplicationPage($side_nav, array('device' => true, 'title' => $title));
 }
 private function loadPolls(AphrontPagerView $pager, $view)
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $poll = new PhabricatorSlowvotePoll();
     $conn = $poll->establishConnection('r');
     $offset = $pager->getOffset();
     $limit = $pager->getPageSize() + 1;
     switch ($view) {
         case self::VIEW_ALL:
             $data = queryfx_all($conn, 'SELECT * FROM %T ORDER BY id DESC LIMIT %d, %d', $poll->getTableName(), $offset, $limit);
             break;
         case self::VIEW_CREATED:
             $data = queryfx_all($conn, 'SELECT * FROM %T WHERE authorPHID = %s ORDER BY id DESC
         LIMIT %d, %d', $poll->getTableName(), $user->getPHID(), $offset, $limit);
             break;
         case self::VIEW_VOTED:
             $choice = new PhabricatorSlowvoteChoice();
             $data = queryfx_all($conn, 'SELECT p.* FROM %T p JOIN %T o
         ON o.pollID = p.id
         WHERE o.authorPHID = %s
         GROUP BY p.id
         ORDER BY p.id DESC
         LIMIT %d, %d', $poll->getTableName(), $choice->getTableName(), $user->getPHID(), $offset, $limit);
             break;
     }
     $data = $pager->sliceResults($data);
     return $poll->loadAllFromArray($data);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $edit_query = new HeraldEditLogQuery();
     if ($this->id) {
         $edit_query->withRuleIDs(array($this->id));
     }
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setOffset($request->getStr('offset'));
     $edits = $edit_query->executeWithOffsetPager($pager);
     $need_phids = mpull($edits, 'getEditorPHID');
     $handles = $this->loadViewerHandles($need_phids);
     $list_view = id(new HeraldRuleEditHistoryView())->setEdits($edits)->setHandles($handles)->setUser($this->getRequest()->getUser());
     $panel = new AphrontPanelView();
     $panel->setHeader(pht('Edit History'));
     $panel->appendChild($list_view);
     $panel->setNoBackground();
     $crumbs = $this->buildApplicationCrumbs($can_create = false)->addTextCrumb(pht('Edit History'), $this->getApplicationURI('herald/history'));
     $nav = $this->buildSideNavView();
     $nav->selectFilter('history');
     $nav->appendChild($panel);
     $nav->setCrumbs($crumbs);
     return $this->buildApplicationPage($nav, array('title' => pht('Rule Edit History')));
 }
 public final function executeWithOffsetPager(AphrontPagerView $pager)
 {
     $this->setLimit($pager->getPageSize() + 1);
     $this->setOffset($pager->getOffset());
     $results = $this->execute();
     return $pager->sliceResults($results);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $lease = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne();
     if (!$lease) {
         return new Aphront404Response();
     }
     $lease_uri = $this->getApplicationURI('lease/' . $lease->getID() . '/');
     $title = pht('Lease %d', $lease->getID());
     $header = id(new PHUIHeaderView())->setHeader($title);
     $actions = $this->buildActionListView($lease);
     $properties = $this->buildPropertyListView($lease, $actions);
     $pager = new AphrontPagerView();
     $pager->setURI(new PhutilURI($lease_uri), 'offset');
     $pager->setOffset($request->getInt('offset'));
     $logs = id(new DrydockLogQuery())->setViewer($viewer)->withLeaseIDs(array($lease->getID()))->executeWithOffsetPager($pager);
     $log_table = id(new DrydockLogListView())->setUser($viewer)->setLogs($logs)->render();
     $log_table->appendChild($pager);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setActionList($actions);
     $crumbs->addTextCrumb($title, $lease_uri);
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     return $this->buildApplicationPage(array($crumbs, $object_box, $log_table), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $conn_table = new PhabricatorConduitConnectionLog();
     $call_table = new PhabricatorConduitMethodCallLog();
     $conn_r = $call_table->establishConnection('r');
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $calls = $call_table->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $calls = $pager->sliceResults($calls);
     $pager->setURI(new PhutilURI('/conduit/log/'), 'page');
     $pager->setEnableKeyboardShortcuts(true);
     $min = $pager->getOffset() + 1;
     $max = $min + count($calls) - 1;
     $conn_ids = array_filter(mpull($calls, 'getConnectionID'));
     $conns = array();
     if ($conn_ids) {
         $conns = $conn_table->loadAllWhere('id IN (%Ld)', $conn_ids);
     }
     $table = $this->renderCallTable($calls, $conns);
     $panel = new AphrontPanelView();
     $panel->setHeader('Conduit Method Calls (' . $min . '-' . $max . ')');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $this->setShowSideNav(false);
     return $this->buildStandardPageResponse($panel, array('title' => 'Conduit Logs'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $nav = new AphrontSideNavView();
     $links = array('calls' => 'All Calls');
     if (empty($links[$this->view])) {
         $this->view = key($links);
     }
     foreach ($links as $slug => $name) {
         $nav->addNavItem(phutil_render_tag('a', array('href' => '/conduit/log/view/' . $slug . '/', 'class' => $slug == $this->view ? 'aphront-side-nav-selected' : null), phutil_escape_html($name)));
     }
     $conn_table = new PhabricatorConduitConnectionLog();
     $call_table = new PhabricatorConduitMethodCallLog();
     $conn_r = $call_table->establishConnection('r');
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $calls = $call_table->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $calls = $pager->sliceResults($calls);
     $pager->setURI(new PhutilURI('/conduit/log/view/' . $this->view . '/'), 'page');
     $pager->setEnableKeyboardShortcuts(true);
     $min = $pager->getOffset() + 1;
     $max = $min + count($calls) - 1;
     $conn_ids = array_filter(mpull($calls, 'getConnectionID'));
     $conns = array();
     if ($conn_ids) {
         $conns = $conn_table->loadAllWhere('id IN (%Ld)', $conn_ids);
     }
     $table = $this->renderCallTable($calls, $conns);
     $panel = new AphrontPanelView();
     $panel->setHeader('Conduit Method Calls (' . $min . '-' . $max . ')');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Conduit Logs', 'tab' => 'logs'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $is_admin = $viewer->getIsAdmin();
     $user = new PhabricatorUser();
     $count = queryfx_one($user->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $user->getTableName());
     $count = idx($count, 'N', 0);
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page', 0));
     $pager->setCount($count);
     $pager->setURI($request->getRequestURI(), 'page');
     $users = id(new PhabricatorPeopleQuery())->needPrimaryEmail(true)->executeWithOffsetPager($pager);
     $rows = array();
     foreach ($users as $user) {
         $primary_email = $user->loadPrimaryEmail();
         if ($primary_email && $primary_email->getIsVerified()) {
             $email = 'Verified';
         } else {
             $email = 'Unverified';
         }
         $status = array();
         if ($user->getIsDisabled()) {
             $status[] = 'Disabled';
         }
         if ($user->getIsAdmin()) {
             $status[] = 'Admin';
         }
         if ($user->getIsSystemAgent()) {
             $status[] = 'System Agent';
         }
         $status = implode(', ', $status);
         $rows[] = array(phabricator_date($user->getDateCreated(), $viewer), phabricator_time($user->getDateCreated(), $viewer), phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUserName())), phutil_escape_html($user->getRealName()), $status, $email, phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/people/edit/' . $user->getID() . '/'), 'Administrate User'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Join Date', 'Time', 'Username', 'Real Name', 'Roles', 'Email', ''));
     $table->setColumnClasses(array(null, 'right', 'pri', 'wide', null, null, 'action'));
     $table->setColumnVisibility(array(true, true, true, true, $is_admin, $is_admin, $is_admin));
     $panel = new AphrontPanelView();
     $panel->setHeader('People (' . number_format($count) . ')');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     if ($is_admin) {
         $panel->addButton(phutil_render_tag('a', array('href' => '/people/edit/', 'class' => 'button green'), 'Create New Account'));
         if (PhabricatorEnv::getEnvConfig('ldap.auth-enabled')) {
             $panel->addButton(phutil_render_tag('a', array('href' => '/people/ldap/', 'class' => 'button green'), 'Import from LDAP'));
         }
     }
     $nav = $this->buildSideNavView();
     $nav->selectFilter('people');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'People'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $pager = new AphrontPagerView();
     $pager->setPageSize(250);
     $pager->setOffset($offset);
     $pager->setURI($request->getRequestURI(), 'offset');
     $list = new PhabricatorMetaMTAMailingList();
     $conn_r = $list->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T
     ORDER BY name ASC
     LIMIT %d, %d', $list->getTableName(), $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $lists = $list->loadAllFromArray($data);
     $rows = array();
     foreach ($lists as $list) {
         $rows[] = array(phutil_escape_html($list->getName()), phutil_escape_html($list->getEmail()), phutil_render_tag('a', array('class' => 'button grey small', 'href' => $this->getApplicationURI('/edit/' . $list->getID() . '/')), 'Edit'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Name', 'Email', ''));
     $table->setColumnClasses(array(null, 'wide', 'action'));
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('Mailing Lists');
     $panel->setCreateButton('Add New List', $this->getApplicationURI('/edit/'));
     $panel->appendChild($pager);
     return $this->buildApplicationPage($panel, array('title' => 'Mailing Lists'));
 }
 private function renderListPanel()
 {
     if (!$this->packagePHID) {
         return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle('No package seleted. Please select one from above.');
     }
     $package = id(new PhabricatorOwnersPackage())->loadOneWhere("phid = %s", $this->packagePHID);
     if ($this->view === 'audit' && !$package->getAuditingEnabled()) {
         return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle("Package doesn't have auditing enabled. " . "Please choose another one.");
     }
     $conn_r = id(new PhabricatorOwnersPackageCommitRelationship())->establishConnection('r');
     $status_arr = $this->getStatusArr();
     $offset = $this->request->getInt('offset', 0);
     $pager = new AphrontPagerView();
     $pager->setPageSize(50);
     $pager->setOffset($offset);
     $pager->setURI($this->request->getRequestURI(), 'offset');
     $data = queryfx_all($conn_r, 'SELECT commitPHID, auditStatus, auditReasons FROM %T
     WHERE packagePHID = %s AND auditStatus in (%Ls)
     ORDER BY id DESC
     LIMIT %d, %d', id(new PhabricatorOwnersPackageCommitRelationship())->getTableName(), $package->getPHID(), $status_arr, $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $data = ipull($data, null, 'commitPHID');
     $list_panel = $this->renderCommitTable($data, $package);
     $list_panel->appendChild($pager);
     return $list_panel;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $upload_panel = $this->renderUploadPanel();
     $author = null;
     $author_username = $request->getStr('author');
     if ($author_username) {
         $author = id(new PhabricatorUser())->loadOneWhere('userName = %s', $author_username);
         if (!$author) {
             return id(new Aphront404Response());
         }
         $title = 'Files Uploaded by ' . phutil_escape_html($author->getUsername());
     } else {
         $title = 'Files';
     }
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     if ($author) {
         $files = id(new PhabricatorFile())->loadAllWhere('authorPHID = %s ORDER BY id DESC LIMIT %d, %d', $author->getPHID(), $pager->getOffset(), $pager->getPageSize() + 1);
     } else {
         $files = id(new PhabricatorFile())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     }
     $files = $pager->sliceResults($files);
     $pager->setURI($request->getRequestURI(), 'page');
     $phids = mpull($files, 'getAuthorPHID');
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $highlighted = $request->getStr('h');
     $highlighted = explode('-', $highlighted);
     $highlighted = array_fill_keys($highlighted, true);
     $rows = array();
     $rowc = array();
     foreach ($files as $file) {
         if ($file->isViewableInBrowser()) {
             $view_button = phutil_render_tag('a', array('class' => 'small button grey', 'href' => '/file/view/' . $file->getPHID() . '/'), 'View');
         } else {
             $view_button = null;
         }
         if (isset($highlighted[$file->getID()])) {
             $rowc[] = 'highlighted';
         } else {
             $rowc[] = '';
         }
         $rows[] = array(phutil_escape_html('F' . $file->getID()), $file->getAuthorPHID() ? $handles[$file->getAuthorPHID()]->renderLink() : null, phutil_render_tag('a', array('href' => $file->getViewURI()), phutil_escape_html($file->getName())), phutil_escape_html(number_format($file->getByteSize()) . ' bytes'), phutil_render_tag('a', array('class' => 'small button grey', 'href' => '/file/info/' . $file->getPHID() . '/'), 'Info'), $view_button, phutil_render_tag('a', array('class' => 'small button grey', 'href' => '/file/download/' . $file->getPHID() . '/'), 'Download'), phabricator_date($file->getDateCreated(), $user), phabricator_time($file->getDateCreated(), $user));
     }
     $table = new AphrontTableView($rows);
     $table->setRowClasses($rowc);
     $table->setHeaders(array('File ID', 'Author', 'Name', 'Size', '', '', '', 'Created', ''));
     $table->setColumnClasses(array(null, '', 'wide pri', 'right', 'action', 'action', 'action', '', 'right'));
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader($title);
     $panel->appendChild($pager);
     return $this->buildStandardPageResponse(array($upload_panel, $panel), array('title' => 'Files', 'tab' => 'files'));
 }
 public function processRequest()
 {
     $drequest = $this->diffusionRequest;
     $request = $this->getRequest();
     $page_size = $request->getInt('pagesize', 100);
     $offset = $request->getInt('page', 0);
     $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest);
     $history_query->setOffset($offset);
     $history_query->setLimit($page_size + 1);
     if (!$request->getBool('copies')) {
         $history_query->needDirectChanges(true);
         $history_query->needChildChanges(true);
     }
     $history = $history_query->loadHistory();
     $phids = array();
     foreach ($history as $item) {
         $data = $item->getCommitData();
         if ($data) {
             if ($data->getCommitDetail('authorPHID')) {
                 $phids[$data->getCommitDetail('authorPHID')] = true;
             }
         }
     }
     $phids = array_keys($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $pager = new AphrontPagerView();
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     if (count($history) == $page_size + 1) {
         array_pop($history);
         $pager->setHasMorePages(true);
     } else {
         $pager->setHasMorePages(false);
     }
     $pager->setURI($request->getRequestURI(), 'page');
     $content = array();
     $content[] = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history'));
     if ($request->getBool('copies')) {
         $button_title = 'Hide Copies/Branches';
     } else {
         $button_title = 'Show Copies/Branches';
     }
     $button_uri = $request->getRequestURI()->alter('copies', !$request->getBool('copies'));
     $button = phutil_render_tag('a', array('class' => 'button small grey', 'href' => $button_uri), phutil_escape_html($button_title));
     $history_table = new DiffusionHistoryTableView();
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHandles($handles);
     $history_table->setHistory($history);
     $history_panel = new AphrontPanelView();
     $history_panel->setHeader('History');
     $history_panel->addButton($button);
     $history_panel->appendChild($history_table);
     $history_panel->appendChild($pager);
     $content[] = $history_panel;
     // TODO: Sometimes we do have a change view, we need to look at the most
     // recent history entry to figure it out.
     $nav = $this->buildSideNav('history', false);
     $nav->appendChild($content);
     return $this->buildStandardPageResponse($nav, array('title' => 'history'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $macro_table = new PhabricatorFileImageMacro();
     $macros = $macro_table->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize());
     // Get an exact count since the size here is reasonably going to be a few
     // thousand at most in any reasonable case.
     $count = queryfx_one($macro_table->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $macro_table->getTableName());
     $count = $count['N'];
     $pager->setCount($count);
     $pager->setURI($request->getRequestURI(), 'page');
     $rows = array();
     foreach ($macros as $macro) {
         $src = PhabricatorFileURI::getViewURIForPHID($macro->getFilePHID());
         $rows[] = array(phutil_render_tag('a', array('href' => '/file/macro/edit/' . $macro->getID() . '/'), phutil_escape_html($macro->getName())), phutil_render_tag('a', array('href' => $src, 'target' => '_blank'), phutil_render_tag('img', array('src' => $src))), javelin_render_tag('a', array('href' => '/file/macro/delete/' . $macro->getID() . '/', 'sigil' => 'workflow', 'class' => 'grey small button'), 'Delete'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Name', 'Image', ''));
     $table->setColumnClasses(array('pri', 'wide thumb', 'action'));
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('Image Macros');
     $panel->setCreateButton('New Image Macro', '/file/macro/edit/');
     $panel->appendChild($pager);
     return $this->buildStandardPageResponse($panel, array('title' => 'Image Macros', 'tab' => 'macros'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $pastes = id(new PhabricatorPaste())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $pastes = $pager->sliceResults($pastes);
     $pager->setURI($request->getRequestURI(), 'page');
     $phids = mpull($pastes, 'getAuthorPHID');
     $handles = array();
     if ($phids) {
         $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     }
     $rows = array();
     foreach ($pastes as $paste) {
         $handle = $handles[$paste->getAuthorPHID()];
         $rows[] = array(phutil_escape_html('P' . $paste->getID()), phutil_render_tag('a', array('href' => '/p/' . $handle->getName() . '/'), phutil_escape_html($handle->getName())), phutil_escape_html($paste->getLanguage()), phutil_render_tag('a', array('href' => '/P' . $paste->getID()), phutil_escape_html(nonempty($paste->getTitle(), 'Untitled Masterwork P' . $paste->getID()))), phutil_render_tag('a', array('href' => PhabricatorFileURI::getViewURIForPHID($paste->getFilePHID())), phutil_escape_html($paste->getFilePHID())));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Paste ID', 'Author', 'Language', 'Title', 'File'));
     $table->setColumnClasses(array(null, null, null, 'wide pri', null));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $panel->setHeader("Paste");
     $panel->setCreateButton('Paste Something', '/paste/');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     return $this->buildStandardPageResponse($panel, array('title' => 'Paste List', 'tab' => 'list'));
 }
 public function processRequest()
 {
     $drequest = $this->getDiffusionRequest();
     $request = $this->getRequest();
     $user = $request->getUser();
     $repository = $drequest->getRepository();
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setOffset($request->getInt('offset'));
     // TODO: Add support for branches that contain commit
     $query = DiffusionBranchQuery::newFromDiffusionRequest($drequest);
     $query->setOffset($pager->getOffset());
     $query->setLimit($pager->getPageSize() + 1);
     $branches = $query->loadBranches();
     $branches = $pager->sliceResults($branches);
     $content = null;
     if (!$branches) {
         $content = new AphrontErrorView();
         $content->setTitle('No Branches');
         $content->appendChild('This repository has no branches.');
         $content->setSeverity(AphrontErrorView::SEVERITY_NODATA);
     } else {
         $commits = id(new PhabricatorAuditCommitQuery())->withIdentifiers($drequest->getRepository()->getID(), mpull($branches, 'getHeadCommitIdentifier'))->needCommitData(true)->execute();
         $view = id(new DiffusionBranchTableView())->setBranches($branches)->setUser($user)->setCommits($commits)->setDiffusionRequest($drequest);
         $panel = id(new AphrontPanelView())->setHeader('Branches')->appendChild($view)->appendChild($pager);
         $content = $panel;
     }
     return $this->buildStandardPageResponse(array($this->buildCrumbs(array('branches' => true)), $content), array('title' => array('Branches', $repository->getCallsign() . ' Repository')));
 }
 public function processRequest()
 {
     $drequest = $this->getDiffusionRequest();
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $repository = $drequest->getRepository();
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setOffset($request->getInt('offset'));
     // TODO: Add support for branches that contain commit
     $branches = $this->callConduitWithDiffusionRequest('diffusion.branchquery', array('offset' => $pager->getOffset(), 'limit' => $pager->getPageSize() + 1));
     $branches = $pager->sliceResults($branches);
     $branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches);
     $content = null;
     if (!$branches) {
         $content = $this->renderStatusMessage(pht('No Branches'), pht('This repository has no branches.'));
     } else {
         $commits = id(new DiffusionCommitQuery())->setViewer($viewer)->withIdentifiers(mpull($branches, 'getCommitIdentifier'))->withRepository($repository)->execute();
         $view = id(new DiffusionBranchTableView())->setUser($viewer)->setBranches($branches)->setCommits($commits)->setDiffusionRequest($drequest);
         $panel = id(new AphrontPanelView())->setNoBackground(true)->appendChild($view)->appendChild($pager);
         $content = $panel;
     }
     $crumbs = $this->buildCrumbs(array('branches' => true));
     return $this->buildApplicationPage(array($crumbs, $content), array('title' => array(pht('Branches'), 'r' . $repository->getCallsign()), 'device' => false));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $pager->setURI($request->getRequestURI(), 'page');
     $timers = id(new PhabricatorTimer())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $timers = $pager->sliceResults($timers);
     $phids = mpull($timers, 'getAuthorPHID');
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $rows = array();
     foreach ($timers as $timer) {
         $edit_button = null;
         $delete_button = null;
         if ($user->getIsAdmin() || $user->getPHID() == $timer->getAuthorPHID()) {
             $edit_button = phutil_render_tag('a', array('class' => 'small button grey', 'href' => '/countdown/edit/' . $timer->getID() . '/'), 'Edit');
             $delete_button = javelin_render_tag('a', array('class' => 'small button grey', 'href' => '/countdown/delete/' . $timer->getID() . '/', 'sigil' => 'workflow'), 'Delete');
         }
         $rows[] = array(phutil_escape_html($timer->getID()), $handles[$timer->getAuthorPHID()]->renderLink(), phutil_render_tag('a', array('href' => '/countdown/' . $timer->getID() . '/'), phutil_escape_html($timer->getTitle())), phabricator_datetime($timer->getDatepoint(), $user), $edit_button, $delete_button);
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('ID', 'Author', 'Title', 'End Date', '', ''));
     $table->setColumnClasses(array(null, null, 'wide pri', null, 'action', 'action'));
     $panel = id(new AphrontPanelView())->appendChild($table)->setHeader('Timers')->setCreateButton('Create Timer', '/countdown/edit/')->appendChild($pager);
     return $this->buildStandardPageResponse($panel, array('title' => 'Countdown'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $pager->setURI($request->getRequestURI(), 'page');
     $mails = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $mails = $pager->sliceResults($mails);
     $phids = array_merge(mpull($mails, 'getAuthorPHID'), mpull($mails, 'getRelatedPHID'));
     $phids = array_unique(array_filter($phids));
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $rows = array();
     foreach ($mails as $mail) {
         $rows[] = array($mail->getID(), phabricator_date($mail->getDateCreated(), $user), phabricator_time($mail->getDateCreated(), $user), $mail->getAuthorPHID() ? $handles[$mail->getAuthorPHID()]->renderLink() : '-', $mail->getRelatedPHID() ? $handles[$mail->getRelatedPHID()]->renderLink() : '-', phutil_escape_html($mail->getMessage()));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('ID', 'Date', 'Time', 'Author', 'Object', 'Message'));
     $table->setColumnClasses(array(null, null, 'right', null, null, 'wide'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Received Mail');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('received');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'Received Mail'));
 }
 protected function processDiffusionRequest(AphrontRequest $request)
 {
     $drequest = $this->diffusionRequest;
     $viewer = $request->getUser();
     $repository = $drequest->getRepository();
     $page_size = $request->getInt('pagesize', 100);
     $offset = $request->getInt('offset', 0);
     $params = array('commit' => $drequest->getCommit(), 'path' => $drequest->getPath(), 'offset' => $offset, 'limit' => $page_size + 1);
     if (!$request->getBool('copies')) {
         $params['needDirectChanges'] = true;
         $params['needChildChanges'] = true;
     }
     $history_results = $this->callConduitWithDiffusionRequest('diffusion.historyquery', $params);
     $history = DiffusionPathChange::newFromConduit($history_results['pathChanges']);
     $pager = new AphrontPagerView();
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     $history = $pager->sliceResults($history);
     $pager->setURI($request->getRequestURI(), 'offset');
     $show_graph = !strlen($drequest->getPath());
     $content = array();
     $history_table = new DiffusionHistoryTableView();
     $history_table->setUser($request->getUser());
     $history_table->setDiffusionRequest($drequest);
     $history_table->setHistory($history);
     $history_table->loadRevisions();
     $phids = $history_table->getRequiredHandlePHIDs();
     $handles = $this->loadViewerHandles($phids);
     $history_table->setHandles($handles);
     if ($show_graph) {
         $history_table->setParents($history_results['parents']);
         $history_table->setIsHead($offset == 0);
     }
     $history_panel = new PHUIObjectBoxView();
     $history_panel->setHeaderText(pht('History'));
     $history_panel->appendChild($history_table);
     $content[] = $history_panel;
     $header = id(new PHUIHeaderView())->setUser($viewer)->setPolicyObject($repository)->setHeader($this->renderPathLinks($drequest, $mode = 'history'));
     $actions = $this->buildActionView($drequest);
     $properties = $this->buildPropertyView($drequest, $actions);
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $crumbs = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history'));
     return $this->buildApplicationPage(array($crumbs, $object_box, $content, $pager), array('title' => array(pht('History'), pht('%s Repository', $drequest->getRepository()->getCallsign()))));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $page_size = 1000;
     $pager = new AphrontPagerView();
     $request_uri = $request->getRequestURI();
     $pager->setURI($request_uri, 'offset');
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     $query = new PhabricatorChatLogQuery();
     $query->withChannels(array($this->channel));
     $logs = $query->executeWithPager($pager);
     require_celerity_resource('phabricator-chatlog-css');
     $last_author = null;
     $last_epoch = null;
     $row_idx = 0;
     $row_colors = array('normal', 'alternate');
     $out = array();
     $out[] = '<table class="phabricator-chat-log">';
     foreach ($logs as $log) {
         $this_author = $log->getAuthor();
         $this_epoch = $log->getEpoch();
         if ($this_author !== $last_author || $this_epoch - 60 * 5 > $last_epoch) {
             ++$row_idx;
             $out[] = '<tr class="initial ' . $row_colors[$row_idx % 2] . '">';
             $out[] = '<td class="timestamp">' . phabricator_datetime($log->getEpoch(), $user) . '</td>';
             $author = $log->getAuthor();
             $author = phutil_utf8_shorten($author, 18);
             $out[] = '<td class="author">' . phutil_escape_html($author) . '</td>';
         } else {
             $out[] = '<tr class="' . $row_colors[$row_idx % 2] . '">';
             $out[] = '<td class="similar" colspan="2"></td>';
         }
         $out[] = '<td class="message">' . phutil_escape_html($log->getMessage()) . '</td>';
         $out[] = '</tr>';
         $last_author = $this_author;
         $last_epoch = $this_epoch;
     }
     $out[] = '</table>';
     return $this->buildStandardPageResponse(array(implode("\n", $out), $pager), array('title' => 'Channel Log'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $pager = new AphrontPagerView();
     $page_size = 50;
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setPageSize($page_size);
     $pager->setOffset($request->getInt('offset'));
     if ($this->getBloggerName()) {
         $blogger = id(new PhabricatorUser())->loadOneWhere('username = %s', $this->getBloggerName());
         if (!$blogger) {
             return new Aphront404Response();
         }
         $page_title = 'Posts by ' . $this->getBloggerName();
         if ($blogger->getPHID() == $user->getPHID()) {
             $actions = array('view', 'edit');
         } else {
             $actions = array('view');
         }
         $this->setShowSideNav(false);
     } else {
         $blogger = $user;
         $page_title = 'Posts by ' . $user->getUserName();
         $actions = array('view', 'edit');
         $this->setShowSideNav(true);
     }
     $phid = $blogger->getPHID();
     // user gets to see their own unpublished stuff
     if ($phid == $user->getPHID() && $this->isDraft()) {
         $post_visibility = PhamePost::VISIBILITY_DRAFT;
     } else {
         $post_visibility = PhamePost::VISIBILITY_PUBLISHED;
     }
     $query = new PhamePostQuery();
     $query->withBloggerPHID($phid);
     $query->withVisibility($post_visibility);
     $posts = $query->executeWithPager($pager);
     $bloggers = array($blogger->getPHID() => $blogger);
     $panel = id(new PhamePostListView())->setUser($user)->setBloggers($bloggers)->setPosts($posts)->setActions($actions)->setDraftList($this->isDraft());
     return $this->buildStandardPageResponse(array($panel, $pager), array('title' => $page_title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI('/notification/'));
     $nav->addFilter('all', 'All Notifications');
     $nav->addFilter('unread', 'Unread Notifications');
     $filter = $nav->selectFilter($this->filter, 'all');
     $pager = new AphrontPagerView();
     $pager->setURI($request->getRequestURI(), 'offset');
     $pager->setOffset($request->getInt('offset'));
     $query = new PhabricatorNotificationQuery();
     $query->setUserPHID($user->getPHID());
     switch ($filter) {
         case 'unread':
             $query->withUnread(true);
             $header = pht('Unread Notifications');
             $no_data = pht('You have no unread notifications.');
             break;
         default:
             $header = pht('Notifications');
             $no_data = pht('You have no notifications.');
             break;
     }
     $notifications = $query->executeWithOffsetPager($pager);
     if ($notifications) {
         $builder = new PhabricatorNotificationBuilder($notifications);
         $view = $builder->buildView();
     } else {
         $view = '<div class="phabricator-notification no-notifications">' . $no_data . '</div>';
     }
     $view = array('<div class="phabricator-notification-list">', $view, '</div>');
     $panel = new AphrontPanelView();
     $panel->setHeader($header);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->addButton(javelin_render_tag('a', array('href' => '/notification/clear/', 'class' => 'button', 'sigil' => 'workflow'), 'Mark All Read'));
     $panel->appendChild($view);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Notifications'));
 }
 public function processRequest()
 {
     $title = 'OAuth Client Authorizations';
     $request = $this->getRequest();
     $current_user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $page_size = 100;
     $pager = new AphrontPagerView();
     $request_uri = $request->getRequestURI();
     $pager->setURI($request_uri, 'offset');
     $pager->setPageSize($page_size);
     $pager->setOffset($offset);
     $query = new PhabricatorOAuthClientAuthorizationQuery();
     $query->withUserPHIDs(array($current_user->getPHID()));
     $authorizations = $query->executeWithOffsetPager($pager);
     $client_authorizations = mpull($authorizations, null, 'getClientPHID');
     $client_phids = array_keys($client_authorizations);
     if ($client_phids) {
         $clients = id(new PhabricatorOAuthServerClient())->loadAllWhere('phid in (%Ls)', $client_phids);
     } else {
         $clients = array();
     }
     $client_dict = mpull($clients, null, 'getPHID');
     $rows = array();
     $rowc = array();
     $highlight = $this->getHighlightPHIDs();
     foreach ($client_authorizations as $client_phid => $authorization) {
         $client = $client_dict[$client_phid];
         $created = phabricator_datetime($authorization->getDateCreated(), $current_user);
         $updated = phabricator_datetime($authorization->getDateModified(), $current_user);
         $scope_doc_href = PhabricatorEnv::getDoclink('article/Using_the_Phabricator_OAuth_Server.html#scopes');
         $row = array(phutil_render_tag('a', array('href' => $client->getViewURI()), phutil_escape_html($client->getName())), phutil_render_tag('a', array('href' => $scope_doc_href), $authorization->getScopeString()), phabricator_datetime($authorization->getDateCreated(), $current_user), phabricator_datetime($authorization->getDateModified(), $current_user), phutil_render_tag('a', array('class' => 'small button grey', 'href' => $authorization->getEditURI()), 'Edit'));
         $rows[] = $row;
         if (isset($highlight[$authorization->getPHID()])) {
             $rowc[] = 'highlighted';
         } else {
             $rowc[] = '';
         }
     }
     $panel = $this->buildClientAuthorizationList($rows, $rowc, $title);
     return $this->buildStandardPageResponse(array($this->getNoticeView(), $panel->appendChild($pager)), array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $nav = $this->buildSideNav('resource');
     $pager = new AphrontPagerView();
     $pager->setURI(new PhutilURI('/drydock/resource/'), 'page');
     $data = id(new DrydockResource())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $phids = mpull($data, 'getOwnerPHID');
     $handles = $this->loadViewerHandles($phids);
     $rows = array();
     foreach ($data as $resource) {
         $rows[] = array($resource->getID(), $resource->getOwnerPHID() ? $handles[$resource->getOwnerPHID()]->renderLink() : null, phutil_escape_html($resource->getType()), DrydockResourceStatus::getNameForStatus($resource->getStatus()), phutil_escape_html(nonempty($resource->getName(), 'Unnamed')), phabricator_datetime($resource->getDateCreated(), $user));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('ID', 'Owner', 'Type', 'Status', 'Resource', 'Created'));
     $table->setColumnClasses(array('', '', '', '', 'pri wide', 'right'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Drydock Resources');
     $panel->addButton(phutil_render_tag('a', array('href' => '/drydock/resource/allocate/', 'class' => 'green button'), 'Allocate Resource'));
     $panel->appendChild($table);
     $panel->appendChild($pager);
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Resources'));
 }
 public function processRequest()
 {
     // Get a page of mails together with pager.
     $request = $this->getRequest();
     $user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $related_phid = $request->getStr('phid');
     $status = $request->getStr('status');
     $pager = new AphrontPagerView();
     $pager->setOffset($offset);
     $pager->setURI($request->getRequestURI(), 'offset');
     $mail = new PhabricatorMetaMTAMail();
     $conn_r = $mail->establishConnection('r');
     $wheres = array();
     if ($status) {
         $wheres[] = qsprintf($conn_r, 'status = %s', $status);
     }
     if ($related_phid) {
         $wheres[] = qsprintf($conn_r, 'relatedPHID = %s', $related_phid);
     }
     if (count($wheres)) {
         $where_clause = 'WHERE ' . implode($wheres, ' AND ');
     } else {
         $where_clause = 'WHERE 1 = 1';
     }
     $data = queryfx_all($conn_r, 'SELECT * FROM %T
     %Q
     ORDER BY id DESC
     LIMIT %d, %d', $mail->getTableName(), $where_clause, $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $mails = $mail->loadAllFromArray($data);
     // Render the details table.
     $rows = array();
     foreach ($mails as $mail) {
         $next_retry = $mail->getNextRetry() - time();
         if ($next_retry <= 0) {
             $next_retry = "None";
         } else {
             $next_retry = phabricator_format_relative_time_detailed($next_retry);
         }
         $rows[] = array(PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()), $mail->getRetryCount(), $next_retry, phabricator_datetime($mail->getDateCreated(), $user), phabricator_format_relative_time_detailed(time() - $mail->getDateModified()), phutil_escape_html($mail->getSubject()), phutil_render_tag('a', array('class' => 'button small grey', 'href' => $this->getApplicationURI('/view/' . $mail->getID() . '/')), 'View'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Status', 'Retry', 'Next', 'Created', 'Updated', 'Subject', ''));
     $table->setColumnClasses(array(null, null, null, null, null, 'wide', 'action'));
     // Render the whole page.
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('MetaMTA Messages');
     $panel->appendChild($pager);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('sent');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'Sent Mail'));
 }
 private function loadDocuments(AphrontPagerView $pager)
 {
     // TODO: Do we want/need a query object for this?
     $document_dao = new PhrictionDocument();
     $content_dao = new PhrictionContent();
     $conn = $document_dao->establishConnection('r');
     switch ($this->view) {
         case 'all':
             $data = queryfx_all($conn, 'SELECT * FROM %T ORDER BY id DESC LIMIT %d, %d', $document_dao->getTableName(), $pager->getOffset(), $pager->getPageSize() + 1);
             break;
         case 'updates':
             // TODO: This query is a little suspicious, verify we don't need to key
             // or change it once we get more data.
             $data = queryfx_all($conn, 'SELECT d.* FROM %T d JOIN %T c ON c.documentID = d.id
         GROUP BY c.documentID
         ORDER BY MAX(c.id) DESC LIMIT %d, %d', $document_dao->getTableName(), $content_dao->getTableName(), $pager->getOffset(), $pager->getPageSize() + 1);
             break;
         default:
             throw new Exception("Unknown view '{$this->view}'!");
     }
     $data = $pager->sliceResults($data);
     $documents = $document_dao->loadAllFromArray($data);
     if ($documents) {
         $content = $content_dao->loadAllWhere('documentID IN (%Ld)', mpull($documents, 'getID'));
         $content = mpull($content, null, 'getDocumentID');
         foreach ($documents as $document) {
             $document->attachContent($content[$document->getID()]);
         }
     }
     return $documents;
 }