public function getAuthenticateURI()
 {
     $uri = new PhutilURI($this->getAuthenticateBaseURI());
     $uri->setQueryParam('client_id', $this->getClientID());
     $uri->setQueryParam('scope', $this->getScope());
     $uri->setQueryParam('redirect_uri', $this->getRedirectURI());
     $uri->setQueryParam('state', $this->getState());
     foreach ($this->getExtraAuthenticateParameters() as $key => $value) {
         $uri->setQueryParam($key, $value);
     }
     return (string) $uri;
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://disqus.com/api/3.0/users/details.json');
     $uri->setQueryParam('api_key', $this->getClientID());
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $uri = (string) $uri;
     $future = new HTTPSFuture($uri);
     $future->setMethod('GET');
     list($body) = $future->resolvex();
     $data = json_decode($body, true);
     if (!is_array($data)) {
         throw new Exception("Expected valid JSON response from Disqus account data request, " . "got: " . $body);
     }
     return $data['response'];
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $uri = new PhutilURI('/fact/chart/');
         $uri->setQueryParam('y1', $request->getStr('y1'));
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $types = array('+N:*', '+N:DREV', 'updated');
     $engines = PhabricatorFactEngine::loadAllEngines();
     $specs = PhabricatorFactSpec::newSpecsForFactTypes($engines, $types);
     $facts = id(new PhabricatorFactAggregate())->loadAllWhere('factType IN (%Ls)', $types);
     $rows = array();
     foreach ($facts as $fact) {
         $spec = $specs[$fact->getFactType()];
         $name = $spec->getName();
         $value = $spec->formatValueForDisplay($user, $fact->getValueX());
         $rows[] = array(phutil_escape_html($name), phutil_escape_html($value));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Fact', 'Value'));
     $table->setColumnClasses(array('wide', 'n'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Facts!');
     $panel->appendChild($table);
     $chart_form = $this->buildChartForm();
     return $this->buildStandardPageResponse(array($chart_form, $panel), array('title' => 'Facts!'));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     if ($request->isFormPost()) {
         $uri = new PhutilURI('/fact/chart/');
         $uri->setQueryParam('y1', $request->getStr('y1'));
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $types = array('+N:*', '+N:DREV', 'updated');
     $engines = PhabricatorFactEngine::loadAllEngines();
     $specs = PhabricatorFactSpec::newSpecsForFactTypes($engines, $types);
     $facts = id(new PhabricatorFactAggregate())->loadAllWhere('factType IN (%Ls)', $types);
     $rows = array();
     foreach ($facts as $fact) {
         $spec = $specs[$fact->getFactType()];
         $name = $spec->getName();
         $value = $spec->formatValueForDisplay($viewer, $fact->getValueX());
         $rows[] = array($name, $value);
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array(pht('Fact'), pht('Value')));
     $table->setColumnClasses(array('wide', 'n'));
     $panel = new PHUIObjectBoxView();
     $panel->setHeaderText(pht('Facts'));
     $panel->setTable($table);
     $chart_form = $this->buildChartForm();
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Home'));
     $title = pht('Facts');
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild(array($chart_form, $panel));
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://disqus.com/api/3.0/users/details.json');
     $uri->setQueryParam('api_key', $this->getClientID());
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $uri = (string) $uri;
     $future = new HTTPSFuture($uri);
     $future->setMethod('GET');
     list($body) = $future->resolvex();
     try {
         $data = phutil_json_decode($body);
         return $data['response'];
     } catch (PhutilJSONParserException $ex) {
         throw new PhutilProxyException(pht('Expected valid JSON response from Disqus account data request.'), $ex);
     }
 }
 protected function loadOAuthAccountData()
 {
     $fields = array('id', 'name', 'email', 'link', 'security_settings', 'picture');
     $uri = new PhutilURI('https://graph.facebook.com/me');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $uri->setQueryParam('fields', implode(',', $fields));
     list($body) = id(new HTTPSFuture($uri))->resolvex();
     $data = json_decode($body, true);
     if (!is_array($data)) {
         throw new Exception("Expected valid JSON response from Facebook account data request, " . "got: " . $body);
     }
     if ($this->requireSecureBrowsing) {
         if (empty($data['security_settings']['secure_browsing']['enabled'])) {
             throw new Exception(pht("This Phabricator install requires you to enable Secure Browsing " . "on your Facebook account in order to use it to log in to " . "Phabricator. For more information, see %s", 'https://www.facebook.com/help/156201551113407/'));
         }
     }
     return $data;
 }
 public function render()
 {
     $handles = $this->handles;
     require_celerity_resource('maniphest-task-summary-css');
     $list = new PHUIObjectItemListView();
     if ($this->noDataString) {
         $list->setNoDataString($this->noDataString);
     } else {
         $list->setNoDataString(pht('No tasks.'));
     }
     $status_map = ManiphestTaskStatus::getTaskStatusMap();
     $color_map = ManiphestTaskPriority::getColorMap();
     $priority_map = ManiphestTaskPriority::getTaskPriorityMap();
     if ($this->showBatchControls) {
         Javelin::initBehavior('maniphest-list-editor');
     }
     foreach ($this->tasks as $task) {
         $item = id(new PHUIObjectItemView())->setUser($this->getUser())->setObject($task)->setObjectName('T' . $task->getID())->setHeader($task->getTitle())->setHref('/T' . $task->getID());
         if ($task->getOwnerPHID()) {
             $owner = $handles[$task->getOwnerPHID()];
             $item->addByline(pht('Assigned: %s', $owner->renderLink()));
         }
         $status = $task->getStatus();
         $pri = idx($priority_map, $task->getPriority());
         $status_name = idx($status_map, $task->getStatus());
         $tooltip = pht('%s, %s', $status_name, $pri);
         $icon = ManiphestTaskStatus::getStatusIcon($task->getStatus());
         $color = idx($color_map, $task->getPriority(), 'grey');
         if ($task->isClosed()) {
             $item->setDisabled(true);
             $color = 'grey';
         }
         $item->setStatusIcon($icon . ' ' . $color, $tooltip);
         $item->addIcon('none', phabricator_datetime($task->getDateModified(), $this->getUser()));
         if ($this->showSubpriorityControls) {
             $item->setGrippable(true);
         }
         if ($this->showSubpriorityControls || $this->showBatchControls) {
             $item->addSigil('maniphest-task');
         }
         $project_handles = array_select_keys($handles, array_reverse($task->getProjectPHIDs()));
         $item->addAttribute(id(new PHUIHandleTagListView())->setLimit(4)->setNoDataString(pht('No Projects'))->setSlim(true)->setHandles($project_handles));
         $item->setMetadata(array('taskID' => $task->getID()));
         if ($this->showBatchControls) {
             $href = new PhutilURI('/maniphest/task/edit/' . $task->getID() . '/');
             if (!$this->showSubpriorityControls) {
                 $href->setQueryParam('ungrippable', 'true');
             }
             $item->addAction(id(new PHUIListItemView())->setIcon('fa-pencil')->addSigil('maniphest-edit-task')->setHref($href));
         }
         $list->addItem($item);
     }
     return $list;
 }
 private function buildLoginMenu()
 {
     $controller = $this->getController();
     $uri = new PhutilURI('/auth/start/');
     if ($controller) {
         $path = $controller->getRequest()->getPath();
         $uri->setQueryParam('next', $path);
     }
     $bar_item = id(new PHUIListItemView())->addClass('core-menu-item')->setName(pht('Log In'))->setIcon('fa-sign-in')->setHref($uri)->setAural(pht('Log In'));
     return id(new PHUIMainMenuView())->setOrder(900)->setMenuBarItem($bar_item);
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://api.amazon.com/user/profile');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $future = new HTTPSFuture($uri);
     list($body) = $future->resolvex();
     $data = json_decode($body, true);
     if (!is_array($data)) {
         throw new Exception("Expected valid JSON response from Amazon account data request, " . "got: " . $body);
     }
     return $data;
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://api.amazon.com/user/profile');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $future = new HTTPSFuture($uri);
     list($body) = $future->resolvex();
     try {
         return phutil_json_decode($body);
     } catch (PhutilJSONParserException $ex) {
         throw new PhutilProxyException(pht('Expected valid JSON response from Amazon account data request.'), $ex);
     }
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $project_id = $request->getURIData('projectID');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($project_id))->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $this->setProject($project);
     $column = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$column) {
         return new Aphront404Response();
     }
     $column_phid = $column->getPHID();
     $view_uri = $this->getApplicationURI('/board/' . $project_id . '/');
     $view_uri = new PhutilURI($view_uri);
     foreach ($request->getPassthroughRequestData() as $key => $value) {
         $view_uri->setQueryParam($key, $value);
     }
     if ($column->isDefaultColumn()) {
         return $this->newDialog()->setTitle(pht('Can Not Hide Default Column'))->appendParagraph(pht('You can not hide the default/backlog column on a board.'))->addCancelButton($view_uri, pht('Okay'));
     }
     if ($request->isFormPost()) {
         if ($column->isHidden()) {
             $new_status = PhabricatorProjectColumn::STATUS_ACTIVE;
         } else {
             $new_status = PhabricatorProjectColumn::STATUS_HIDDEN;
         }
         $type_status = PhabricatorProjectColumnTransaction::TYPE_STATUS;
         $xactions = array(id(new PhabricatorProjectColumnTransaction())->setTransactionType($type_status)->setNewValue($new_status));
         $editor = id(new PhabricatorProjectColumnTransactionEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->applyTransactions($column, $xactions);
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     if ($column->isHidden()) {
         $title = pht('Show Column');
     } else {
         $title = pht('Hide Column');
     }
     if ($column->isHidden()) {
         $body = pht('Are you sure you want to show this column?');
     } else {
         $body = pht('Are you sure you want to hide this column? It will no longer ' . 'appear on the workboard.');
     }
     $dialog = $this->newDialog()->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle($title)->appendChild($body)->setDisableWorkflowOnCancel(true)->addCancelButton($view_uri)->addSubmitButton($title);
     foreach ($request->getPassthroughRequestData() as $key => $value) {
         $dialog->addHiddenInput($key, $value);
     }
     return $dialog;
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://api.github.com/user');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $future = new HTTPSFuture($uri);
     // NOTE: GitHub requires a User-Agent string.
     $future->addHeader('User-Agent', 'PhutilAuthAdapterOAuthGitHub');
     list($body) = $future->resolvex();
     $data = json_decode($body, true);
     if (!is_array($data)) {
         throw new Exception("Expected valid JSON response from GitHub account data request, " . "got: " . $body);
     }
     return $data;
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://api.github.com/user');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $future = new HTTPSFuture($uri);
     // NOTE: GitHub requires a User-Agent string.
     $future->addHeader('User-Agent', __CLASS__);
     list($body) = $future->resolvex();
     try {
         return phutil_json_decode($body);
     } catch (PhutilJSONParserException $ex) {
         throw new PhutilProxyException(pht('Expected valid JSON response from GitHub account data request.'), $ex);
     }
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $file = id(new PhabricatorFileQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->executeOne();
     if (!$file) {
         return new Aphront404Response();
     }
     $monogram = $file->getMonogram();
     $xdst = id(new PhabricatorTransformedFile())->loadAllWhere('transformedPHID = %s', $file->getPHID());
     $dst_rows = array();
     foreach ($xdst as $source) {
         $dst_rows[] = array($source->getTransform(), $viewer->renderHandle($source->getOriginalPHID()));
     }
     $dst_table = id(new AphrontTableView($dst_rows))->setHeaders(array(pht('Key'), pht('Source')))->setColumnClasses(array('', 'wide'))->setNoDataString(pht('This file was not created by transforming another file.'));
     $xsrc = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID());
     $xsrc = mpull($xsrc, 'getTransformedPHID', 'getTransform');
     $src_rows = array();
     $xforms = PhabricatorFileTransform::getAllTransforms();
     foreach ($xforms as $xform) {
         $dst_phid = idx($xsrc, $xform->getTransformKey());
         if ($xform->canApplyTransform($file)) {
             $can_apply = pht('Yes');
             $view_href = $file->getURIForTransform($xform);
             $view_href = new PhutilURI($view_href);
             $view_href->setQueryParam('regenerate', 'true');
             $view_text = pht('Regenerate');
             $view_link = phutil_tag('a', array('class' => 'small grey button', 'href' => $view_href), $view_text);
         } else {
             $can_apply = phutil_tag('em', array(), pht('No'));
             $view_link = phutil_tag('em', array(), pht('None'));
         }
         if ($dst_phid) {
             $dst_link = $viewer->renderHandle($dst_phid);
         } else {
             $dst_link = phutil_tag('em', array(), pht('None'));
         }
         $src_rows[] = array($xform->getTransformName(), $xform->getTransformKey(), $can_apply, $dst_link, $view_link);
     }
     $src_table = id(new AphrontTableView($src_rows))->setHeaders(array(pht('Name'), pht('Key'), pht('Supported'), pht('Transform'), pht('View')))->setColumnClasses(array('wide', '', '', '', 'action'));
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($monogram, '/' . $monogram);
     $crumbs->addTextCrumb(pht('Transforms'));
     $crumbs->setBorder(true);
     $dst_box = id(new PHUIObjectBoxView())->setHeaderText(pht('File Sources'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($dst_table);
     $src_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Available Transforms'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTable($src_table);
     $title = pht('%s Transforms', $file->getName());
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-arrows-alt');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($dst_box, $src_box));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://www.googleapis.com/plus/v1/people/me');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $future = new HTTPSFuture($uri);
     list($status, $body) = $future->resolve();
     if ($status->isError()) {
         $this->tryToThrowSpecializedError($status, $body);
         throw $status;
     }
     try {
         return phutil_json_decode($body);
     } catch (PhutilJSONParserException $ex) {
         throw new PhutilProxyException(pht('Expected valid JSON response from Google account data request.'), $ex);
     }
 }
 protected function loadOAuthAccountData()
 {
     $uri = new PhutilURI('https://www.googleapis.com/plus/v1/people/me');
     $uri->setQueryParam('access_token', $this->getAccessToken());
     $future = new HTTPSFuture($uri);
     list($status, $body) = $future->resolve();
     if ($status->isError()) {
         $this->tryToThrowSpecializedError($status, $body);
         throw $status;
     }
     $data = json_decode($body, true);
     if (!is_array($data)) {
         throw new Exception("Expected valid JSON response from Google account data request, " . "got: " . $body);
     }
     return $data;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $project_id = $request->getURIData('projectID');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($project_id))->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $this->setProject($project);
     $target = $request->getURIData('target');
     switch ($target) {
         case 'filter':
             $title = pht('Set Board Default Filter');
             $body = pht('Make the current filter the new default filter for this board? ' . 'All users will see the new filter as the default when they view ' . 'the board.');
             $button = pht('Save Default Filter');
             $xaction_value = $request->getStr('filter');
             $xaction_type = PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER;
             break;
         case 'sort':
             $title = pht('Set Board Default Order');
             $body = pht('Make the current sort order the new default order for this board? ' . 'All users will see the new order as the default when they view ' . 'the board.');
             $button = pht('Save Default Order');
             $xaction_value = $request->getStr('order');
             $xaction_type = PhabricatorProjectTransaction::TYPE_DEFAULT_SORT;
             break;
         default:
             return new Aphront404Response();
     }
     $id = $project->getID();
     $view_uri = $this->getApplicationURI("board/{$id}/");
     $view_uri = new PhutilURI($view_uri);
     foreach ($request->getPassthroughRequestData() as $key => $value) {
         $view_uri->setQueryParam($key, $value);
     }
     if ($request->isFormPost()) {
         $xactions = array();
         $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType($xaction_type)->setNewValue($xaction_value);
         id(new PhabricatorProjectTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $xactions);
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     $dialog = $this->newDialog()->setTitle($title)->appendChild($body)->setDisableWorkflowOnCancel(true)->addCancelButton($view_uri)->addSubmitButton($title);
     foreach ($request->getPassthroughRequestData() as $key => $value) {
         $dialog->addHiddenInput($key, $value);
     }
     return $dialog;
 }
 protected function getProxiedFuture()
 {
     if (!$this->future) {
         $params = $this->params;
         if (!$this->action) {
             throw new Exception(pht('You must %s!', 'setRawSlackQuery()'));
         }
         if (!$this->accessToken) {
             throw new Exception(pht('You must %s!', 'setAccessToken()'));
         }
         $uri = new PhutilURI('https://slack.com/');
         $uri->setPath('/api/' . $this->action);
         $uri->setQueryParam('token', $this->accessToken);
         $future = new HTTPSFuture($uri);
         $future->setData($this->params);
         $future->setMethod($this->method);
         $this->future = $future;
     }
     return $this->future;
 }
 public function buildMainMenuItems(PhabricatorUser $user, PhabricatorController $controller = null)
 {
     $items = array();
     if ($user->isLoggedIn()) {
         $item = id(new PHUIListItemView())->addClass('core-menu-item')->setName(pht('Log Out'))->setIcon('fa-sign-out')->setWorkflow(true)->setHref('/logout/')->setSelected($controller instanceof PhabricatorLogoutController)->setAural(pht('Log Out'))->setOrder(900);
         $items[] = $item;
     } else {
         if ($controller instanceof PhabricatorAuthController) {
             // Don't show the "Login" item on auth controllers, since they're
             // generally all related to logging in anyway.
         } else {
             $uri = new PhutilURI('/auth/start/');
             if ($controller) {
                 $path = $controller->getRequest()->getPath();
                 $uri->setQueryParam('next', $path);
             }
             $item = id(new PHUIListItemView())->addClass('core-menu-item')->setName(pht('Log In'))->setIcon('fa-sign-in')->setHref($uri)->setAural(pht('Log In'))->setOrder(900);
             $items[] = $item;
         }
     }
     return $items;
 }
Beispiel #20
0
 protected function getProxiedFuture()
 {
     if (!$this->future) {
         $params = $this->params;
         if (!$this->action) {
             throw new Exception('You must setRawTwitchQuery()!');
         }
         if (!$this->accessToken) {
             throw new Exception('You must setAccessToken()!');
         }
         $uri = new PhutilURI('https://api.twitch.tv/');
         $uri->setPath('/kraken/' . ltrim($this->action, '/'));
         $uri->setQueryParam('oauth_token', $this->accessToken);
         $future = new HTTPSFuture($uri);
         $future->setData($this->params);
         $future->setMethod($this->method);
         // NOTE: This is how the Twitch API is versioned.
         $future->addHeader('Accept', 'application/vnd.twitchtv.2+json');
         // NOTE: This is required to avoid rate limiting.
         $future->addHeader('Client-ID', $this->clientID);
         $this->future = $future;
     }
     return $this->future;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         // Redirect to GET so URIs can be copy/pasted.
         $task_ids = $request->getStr('set_tasks');
         $task_ids = nonempty($task_ids, null);
         $search_text = $request->getStr('set_search');
         $search_text = nonempty($search_text, null);
         $min_priority = $request->getInt('set_lpriority');
         $min_priority = nonempty($min_priority, null);
         $max_priority = $request->getInt('set_hpriority');
         $max_priority = nonempty($max_priority, null);
         $uri = $request->getRequestURI()->alter('users', $this->getArrToStrList('set_users'))->alter('projects', $this->getArrToStrList('set_projects'))->alter('xprojects', $this->getArrToStrList('set_xprojects'))->alter('owners', $this->getArrToStrList('set_owners'))->alter('authors', $this->getArrToStrList('set_authors'))->alter('lpriority', $min_priority)->alter('hpriority', $max_priority)->alter('tasks', $task_ids)->alter('search', $search_text);
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $nav = $this->buildBaseSideNav();
     $has_filter = array('action' => true, 'created' => true, 'subscribed' => true, 'triage' => true, 'projecttriage' => true, 'projectall' => true);
     $query = null;
     $key = $request->getStr('key');
     if (!$key && !$this->view) {
         if ($this->getDefaultQuery()) {
             $key = $this->getDefaultQuery()->getQueryKey();
         }
     }
     if ($key) {
         $query = id(new PhabricatorSearchQuery())->loadOneWhere('queryKey = %s', $key);
     }
     // If the user is running a saved query, load query parameters from that
     // query. Otherwise, build a new query object from the HTTP request.
     if ($query) {
         $nav->selectFilter('Q:' . $query->getQueryKey(), 'custom');
         $this->view = 'custom';
     } else {
         $this->view = $nav->selectFilter($this->view, 'action');
         $query = $this->buildQueryFromRequest();
     }
     // Execute the query.
     list($tasks, $handles, $total_count) = self::loadTasks($query);
     // Extract information we need to render the filters from the query.
     $search_text = $query->getParameter('fullTextSearch');
     $user_phids = $query->getParameter('userPHIDs', array());
     $task_ids = $query->getParameter('taskIDs', array());
     $owner_phids = $query->getParameter('ownerPHIDs', array());
     $author_phids = $query->getParameter('authorPHIDs', array());
     $project_phids = $query->getParameter('projectPHIDs', array());
     $exclude_project_phids = $query->getParameter('excludeProjectPHIDs', array());
     $low_priority = $query->getParameter('lowPriority');
     $high_priority = $query->getParameter('highPriority');
     $page_size = $query->getParameter('limit');
     $page = $query->getParameter('offset');
     $q_status = $query->getParameter('status');
     $q_group = $query->getParameter('group');
     $q_order = $query->getParameter('order');
     $form = id(new AphrontFormView())->setUser($user)->setAction($request->getRequestURI()->alter('key', null)->alter($this->getStatusRequestKey(), $this->getStatusRequestValue($q_status))->alter($this->getOrderRequestKey(), $this->getOrderRequestValue($q_order))->alter($this->getGroupRequestKey(), $this->getGroupRequestValue($q_group)));
     if (isset($has_filter[$this->view])) {
         $tokens = array();
         foreach ($user_phids as $phid) {
             $tokens[$phid] = $handles[$phid]->getFullName();
         }
         $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchowner/')->setName('set_users')->setLabel('Users')->setValue($tokens));
     }
     if ($this->view == 'custom') {
         $form->appendChild(id(new AphrontFormTextControl())->setName('set_search')->setLabel('Search')->setValue($search_text));
         $form->appendChild(id(new AphrontFormTextControl())->setName('set_tasks')->setLabel('Task IDs')->setValue(join(',', $task_ids)));
         $tokens = array();
         foreach ($owner_phids as $phid) {
             $tokens[$phid] = $handles[$phid]->getFullName();
         }
         $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchowner/')->setName('set_owners')->setLabel('Owners')->setValue($tokens));
         $tokens = array();
         foreach ($author_phids as $phid) {
             $tokens[$phid] = $handles[$phid]->getFullName();
         }
         $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/users/')->setName('set_authors')->setLabel('Authors')->setValue($tokens));
     }
     $tokens = array();
     foreach ($project_phids as $phid) {
         $tokens[$phid] = $handles[$phid]->getFullName();
     }
     if ($this->view != 'projectall' && $this->view != 'projecttriage') {
         $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchproject/')->setName('set_projects')->setLabel('Projects')->setValue($tokens));
     }
     if ($this->view == 'custom') {
         $tokens = array();
         foreach ($exclude_project_phids as $phid) {
             $tokens[$phid] = $handles[$phid]->getFullName();
         }
         $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/projects/')->setName('set_xprojects')->setLabel('Exclude Projects')->setValue($tokens));
         $priority = ManiphestTaskPriority::getLowestPriority();
         if ($low_priority) {
             $priority = $low_priority;
         }
         $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Min Priority')->setName('set_lpriority')->setValue($priority)->setOptions(array_reverse(ManiphestTaskPriority::getTaskPriorityMap(), true)));
         $priority = ManiphestTaskPriority::getHighestPriority();
         if ($high_priority) {
             $priority = $high_priority;
         }
         $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Max Priority')->setName('set_hpriority')->setValue($priority)->setOptions(ManiphestTaskPriority::getTaskPriorityMap()));
     }
     $form->appendChild($this->renderStatusControl($q_status))->appendChild($this->renderGroupControl($q_group))->appendChild($this->renderOrderControl($q_order));
     $submit = id(new AphrontFormSubmitControl())->setValue('Filter Tasks');
     // Only show "Save..." for novel queries which have some kind of query
     // parameters set.
     if ($this->view === 'custom' && empty($key) && $request->getRequestURI()->getQueryParams()) {
         $submit->addCancelButton('/maniphest/custom/edit/?key=' . $query->getQueryKey(), 'Save Custom Query...');
     }
     $form->appendChild($submit);
     $create_uri = new PhutilURI('/maniphest/task/create/');
     if ($project_phids) {
         // If we have project filters selected, use them as defaults for task
         // creation.
         $create_uri->setQueryParam('projects', implode(';', $project_phids));
     }
     $filter = new AphrontListFilterView();
     $filter->addButton(phutil_render_tag('a', array('href' => (string) $create_uri, 'class' => 'green button'), 'Create New Task'));
     if (empty($key)) {
         $filter->appendChild($form);
     }
     $nav->appendChild($filter);
     $have_tasks = false;
     foreach ($tasks as $group => $list) {
         if (count($list)) {
             $have_tasks = true;
             break;
         }
     }
     require_celerity_resource('maniphest-task-summary-css');
     $list_container = new AphrontNullView();
     $list_container->appendChild('<div class="maniphest-list-container">');
     if (!$have_tasks) {
         $list_container->appendChild('<h1 class="maniphest-task-group-header">' . 'No matching tasks.' . '</h1>');
     } else {
         $pager = new AphrontPagerView();
         $pager->setURI($request->getRequestURI(), 'offset');
         $pager->setPageSize($page_size);
         $pager->setOffset($page);
         $pager->setCount($total_count);
         $cur = $pager->getOffset() + 1;
         $max = min($pager->getOffset() + $page_size, $total_count);
         $tot = $total_count;
         $cur = number_format($cur);
         $max = number_format($max);
         $tot = number_format($tot);
         $list_container->appendChild('<div class="maniphest-total-result-count">' . "Displaying tasks {$cur} - {$max} of {$tot}." . '</div>');
         $selector = new AphrontNullView();
         $group = $query->getParameter('group');
         $order = $query->getParameter('order');
         $is_draggable = $group == 'priority' || $group == 'none' && $order == 'priority';
         $lists = new AphrontNullView();
         $lists->appendChild('<div class="maniphest-group-container">');
         foreach ($tasks as $group => $list) {
             $task_list = new ManiphestTaskListView();
             $task_list->setShowBatchControls(true);
             if ($is_draggable) {
                 $task_list->setShowSubpriorityControls(true);
             }
             $task_list->setUser($user);
             $task_list->setTasks($list);
             $task_list->setHandles($handles);
             $count = number_format(count($list));
             $lists->appendChild(javelin_render_tag('h1', array('class' => 'maniphest-task-group-header', 'sigil' => 'task-group', 'meta' => array('priority' => head($list)->getPriority())), phutil_escape_html($group) . ' (' . $count . ')'));
             $lists->appendChild($task_list);
         }
         $lists->appendChild('</div>');
         $selector->appendChild($lists);
         $selector->appendChild($this->renderBatchEditor($query));
         $form_id = celerity_generate_unique_node_id();
         $selector = phabricator_render_form($user, array('method' => 'POST', 'action' => '/maniphest/batch/', 'id' => $form_id), $selector->render());
         $list_container->appendChild($selector);
         $list_container->appendChild($pager);
         Javelin::initBehavior('maniphest-subpriority-editor', array('root' => $form_id, 'uri' => '/maniphest/subpriority/'));
     }
     $list_container->appendChild('</div>');
     $nav->appendChild($list_container);
     return $this->buildStandardPageResponse($nav, array('title' => 'Task List'));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $subscription = id(new PhortuneSubscriptionQuery())->setViewer($viewer)->withIDs(array($request->getURIData('id')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$subscription) {
         return new Aphront404Response();
     }
     id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession($viewer, $request, $this->getApplicationURI($subscription->getEditURI()));
     $merchant = $subscription->getMerchant();
     $account = $subscription->getAccount();
     $title = pht('Subscription: %s', $subscription->getSubscriptionName());
     $header = id(new PHUIHeaderView())->setHeader($subscription->getSubscriptionName());
     $view_uri = $subscription->getURI();
     $valid_methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->withStatuses(array(PhortunePaymentMethod::STATUS_ACTIVE))->withMerchantPHIDs(array($merchant->getPHID()))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute();
     $valid_methods = mpull($valid_methods, null, 'getPHID');
     $current_phid = $subscription->getDefaultPaymentMethodPHID();
     $errors = array();
     if ($request->isFormPost()) {
         $default_method_phid = $request->getStr('defaultPaymentMethodPHID');
         if (!$default_method_phid) {
             $default_method_phid = null;
             $e_method = null;
         } else {
             if ($default_method_phid == $current_phid) {
                 // If you have an invalid setting already, it's OK to retain it.
                 $e_method = null;
             } else {
                 if (empty($valid_methods[$default_method_phid])) {
                     $e_method = pht('Invalid');
                     $errors[] = pht('You must select a valid default payment method.');
                 }
             }
         }
         // TODO: We should use transactions here, and move the validation logic
         // inside the Editor.
         if (!$errors) {
             $subscription->setDefaultPaymentMethodPHID($default_method_phid);
             $subscription->save();
             return id(new AphrontRedirectResponse())->setURI($view_uri);
         }
     }
     // Add the option to disable autopay.
     $disable_options = array('' => pht('(Disable Autopay)'));
     // Don't require the user to make a valid selection if the current method
     // has become invalid.
     // TODO: This should probably have a note about why this is bogus.
     if ($current_phid && empty($valid_methods[$current_phid])) {
         $handles = $this->loadViewerHandles(array($current_phid));
         $current_options = array($current_phid => $handles[$current_phid]->getName());
     } else {
         $current_options = array();
     }
     // Add any available options.
     $valid_options = mpull($valid_methods, 'getFullDisplayName', 'getPHID');
     $options = $disable_options + $current_options + $valid_options;
     $crumbs = $this->buildApplicationCrumbs();
     $this->addAccountCrumb($crumbs, $account);
     $crumbs->addTextCrumb(pht('Subscription %d', $subscription->getID()), $view_uri);
     $crumbs->addTextCrumb(pht('Edit'));
     $uri = $this->getApplicationURI($account->getID() . '/card/new/');
     $uri = new PhutilURI($uri);
     $uri->setQueryParam('merchantID', $merchant->getID());
     $uri->setQueryParam('subscriptionID', $subscription->getID());
     $add_method_button = phutil_tag('a', array('href' => $uri, 'class' => 'button grey'), pht('Add Payment Method...'));
     $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setName('defaultPaymentMethodPHID')->setLabel(pht('Autopay With'))->setValue($current_phid)->setOptions($options))->appendChild(id(new AphrontFormMarkupControl())->setValue($add_method_button))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Changes'))->addCancelButton($view_uri));
     $box = id(new PHUIObjectBoxView())->setUser($viewer)->setHeaderText(pht('Edit %s', $subscription->getSubscriptionName()))->setFormErrors($errors)->appendChild($form);
     return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title));
 }
 private function verifyRemotePermissions($viewer, $revision, $repository)
 {
     $github_user = $this->account->getUsername();
     $github_repo = $this->findGitHubRepo($repository);
     $uri = urisprintf('https://api.github.com/repos/%s/collaborators/%s', $github_repo, $github_user);
     $uri = new PhutilURI($uri);
     $uri->setQueryParam('access_token', $this->getAccessToken());
     list($status, $body, $headers) = id(new HTTPSFuture($uri))->resolve();
     // Likely status codes:
     // 204 No Content: Has permissions. Token might be too weak.
     // 404 Not Found: Not a collaborator.
     // 401 Unauthorized: Token is bad/revoked.
     $no_permission = $status->getStatusCode() == 404;
     if ($no_permission) {
         throw new Exception(pht("You don't have permission to push to this repository. " . "Push permissions for this repository are managed on GitHub."));
     }
     $scopes = BaseHTTPFuture::getHeader($headers, 'X-OAuth-Scopes');
     if (strpos($scopes, 'public_repo') === false) {
         $provider_key = $this->provider->getProviderKey();
         $refresh_token_uri = new PhutilURI("/auth/refresh/{$provider_key}/");
         $refresh_token_uri->setQueryParam('scope', 'public_repo');
         return id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Stronger token needed'))->appendChild(pht('In order to complete this action, you need a ' . 'stronger GitHub token.'))->setSubmitURI($refresh_token_uri)->addCancelButton('/D' . $revision->getId())->setDisableWorkflowOnSubmit(true)->addSubmitButton(pht('Refresh Account Link'));
     }
 }
 private function buildLoginValidateResponse(PhabricatorUser $user)
 {
     $validate_uri = new PhutilURI($this->getApplicationURI('validate/'));
     $validate_uri->setQueryParam('expect', $user->getUsername());
     return id(new AphrontRedirectResponse())->setURI((string) $validate_uri);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $e_phame_title = null;
     $e_title = null;
     $errors = array();
     if ($this->isPostEdit()) {
         $posts = id(new PhamePostQuery())->withPHIDs(array($this->getPostPHID()))->execute();
         $post = reset($posts);
         if (empty($post)) {
             return new Aphront404Response();
         }
         if ($post->getBloggerPHID() != $user->getPHID()) {
             return new Aphront403Response();
         }
         $post_noun = ucfirst($post->getHumanName());
         $cancel_uri = $post->getViewURI($user->getUsername());
         $submit_button = 'Save Changes';
         $delete_button = javelin_render_tag('a', array('href' => $post->getDeleteURI(), 'class' => 'grey button', 'sigil' => 'workflow'), 'Delete ' . $post_noun);
         $page_title = 'Edit ' . $post_noun;
     } else {
         $post = id(new PhamePost())->setBloggerPHID($user->getPHID())->setVisibility(PhamePost::VISIBILITY_DRAFT);
         $cancel_uri = '/phame/draft/';
         $submit_button = 'Create Draft';
         $delete_button = null;
         $page_title = 'Create Draft';
     }
     $this->setPost($post);
     $this->loadEdgesAndBlogs();
     if ($request->isFormPost()) {
         $saved = true;
         $visibility = $request->getInt('visibility');
         $comments = $request->getStr('comments_widget');
         $data = array('comments_widget' => $comments);
         $phame_title = $request->getStr('phame_title');
         $phame_title = PhabricatorSlug::normalize($phame_title);
         $title = $request->getStr('title');
         $post->setTitle($title);
         $post->setPhameTitle($phame_title);
         $post->setBody($request->getStr('body'));
         $post->setVisibility($visibility);
         $post->setConfigData($data);
         // only publish once...!
         if ($visibility == PhamePost::VISIBILITY_PUBLISHED) {
             if (!$post->getDatePublished()) {
                 $post->setDatePublished(time());
             }
             // this is basically a cast of null to 0 if its a new post
         } else {
             if (!$post->getDatePublished()) {
                 $post->setDatePublished(0);
             }
         }
         if ($phame_title == '/') {
             $errors[] = 'Phame title must be nonempty.';
             $e_phame_title = 'Required';
         }
         if (empty($title)) {
             $errors[] = 'Title must be nonempty.';
             $e_title = 'Required';
         }
         $blogs_published = array_keys($this->getPostBlogs());
         $blogs_to_publish = array();
         $blogs_to_depublish = array();
         if ($visibility == PhamePost::VISIBILITY_PUBLISHED) {
             $blogs_arr = $request->getArr('blogs');
             $blogs_to_publish = array_values($blogs_arr);
             $blogs_to_depublish = array_diff($blogs_published, $blogs_to_publish);
         } else {
             $blogs_to_depublish = $blogs_published;
         }
         if (empty($errors)) {
             try {
                 $post->save();
                 $editor = new PhabricatorEdgeEditor();
                 $edge_type = PhabricatorEdgeConfig::TYPE_POST_HAS_BLOG;
                 $editor->setUser($user);
                 foreach ($blogs_to_publish as $phid) {
                     $editor->addEdge($post->getPHID(), $edge_type, $phid);
                 }
                 foreach ($blogs_to_depublish as $phid) {
                     $editor->removeEdge($post->getPHID(), $edge_type, $phid);
                 }
                 $editor->save();
             } catch (AphrontQueryDuplicateKeyException $e) {
                 $saved = false;
                 $e_phame_title = 'Not Unique';
                 $errors[] = 'Another post already uses this slug. ' . 'Each post must have a unique slug.';
             }
         } else {
             $saved = false;
         }
         if ($saved) {
             $uri = new PhutilURI($post->getViewURI($user->getUsername()));
             $uri->setQueryParam('saved', true);
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     }
     $panel = new AphrontPanelView();
     $panel->setHeader($page_title);
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     if ($delete_button) {
         $panel->addButton($delete_button);
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setName('title')->setValue($post->getTitle())->setID('post-title')->setError($e_title))->appendChild(id(new AphrontFormTextControl())->setLabel('Phame Title')->setName('phame_title')->setValue(rtrim($post->getPhameTitle(), '/'))->setID('post-phame-title')->setCaption('Up to 64 alphanumeric characters ' . 'with underscores for spaces. ' . 'Formatting is enforced.')->setError($e_phame_title))->appendChild(id(new PhabricatorRemarkupControl())->setLabel('Body')->setName('body')->setValue($post->getBody())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setID('post-body'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Visibility')->setName('visibility')->setValue($post->getVisibility())->setOptions(PhamePost::getVisibilityOptionsForSelect())->setID('post-visibility'))->appendChild($this->getBlogCheckboxControl($post))->appendChild(id(new AphrontFormSelectControl())->setLabel('Comments Widget')->setName('comments_widget')->setvalue($post->getCommentsWidget())->setOptions($post->getCommentsWidgetOptionsForSelect()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button));
     $panel->appendChild($form);
     $preview_panel = '<div class="aphront-panel-preview ">
      <div class="phame-post-preview-header">
        Post Preview
      </div>
      <div id="post-preview">
        <div class="aphront-panel-preview-loading-text">
          Loading preview...
        </div>
      </div>
    </div>';
     Javelin::initBehavior('phame-post-preview', array('preview' => 'post-preview', 'body' => 'post-body', 'title' => 'post-title', 'phame_title' => 'post-phame-title', 'uri' => '/phame/post/preview/'));
     $visibility_data = array('select_id' => 'post-visibility', 'current' => $post->getVisibility(), 'published' => PhamePost::VISIBILITY_PUBLISHED, 'draft' => PhamePost::VISIBILITY_DRAFT, 'change_uri' => $post->getChangeVisibilityURI());
     $blogs_data = array('checkbox_id' => 'post-blogs', 'have_published' => (bool) count($this->getPostBlogs()));
     Javelin::initBehavior('phame-post-blogs', array('blogs' => $blogs_data, 'visibility' => $visibility_data));
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Errors saving post.')->setErrors($errors);
     } else {
         $error_view = null;
     }
     $this->setShowSideNav(true);
     return $this->buildStandardPageResponse(array($error_view, $panel, $preview_panel), array('title' => $page_title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         // Redirect to GET so URIs can be copy/pasted.
         $user_phids = $request->getArr('set_users');
         $proj_phids = $request->getArr('set_projects');
         $task_ids = $request->getStr('set_tasks');
         $user_phids = implode(',', $user_phids);
         $proj_phids = implode(',', $proj_phids);
         $user_phids = nonempty($user_phids, null);
         $proj_phids = nonempty($proj_phids, null);
         $task_ids = nonempty($task_ids, null);
         $uri = $request->getRequestURI()->alter('users', $user_phids)->alter('projects', $proj_phids)->alter('tasks', $task_ids);
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $nav = new AphrontSideNavFilterView();
     $nav->setBaseURI(new PhutilURI('/maniphest/view/'));
     $nav->addLabel('User Tasks');
     $nav->addFilter('action', 'Assigned');
     $nav->addFilter('created', 'Created');
     $nav->addFilter('subscribed', 'Subscribed');
     $nav->addFilter('triage', 'Need Triage');
     $nav->addSpacer();
     $nav->addLabel('All Tasks');
     $nav->addFilter('alltriage', 'Need Triage');
     $nav->addFilter('all', 'All Tasks');
     $nav->addSpacer();
     $nav->addFilter('custom', 'Custom');
     $this->view = $nav->selectFilter($this->view, 'action');
     $has_filter = array('action' => true, 'created' => true, 'subscribed' => true, 'triage' => true);
     list($status_map, $status_links) = $this->renderStatusLinks();
     list($grouping, $group_links) = $this->renderGroupLinks();
     list($order, $order_links) = $this->renderOrderLinks();
     $user_phids = $request->getStr('users');
     if (strlen($user_phids)) {
         $user_phids = explode(',', $user_phids);
     } else {
         $user_phids = array($user->getPHID());
     }
     $project_phids = $request->getStr('projects');
     if (strlen($project_phids)) {
         $project_phids = explode(',', $project_phids);
     } else {
         $project_phids = array();
     }
     $task_ids = $request->getStrList('tasks');
     $page = $request->getInt('page');
     $page_size = self::DEFAULT_PAGE_SIZE;
     list($tasks, $handles, $total_count) = $this->loadTasks($user_phids, $project_phids, $task_ids, array('status' => $status_map, 'group' => $grouping, 'order' => $order, 'offset' => $page, 'limit' => $page_size));
     $form = id(new AphrontFormView())->setUser($user)->setAction($request->getRequestURI());
     if (isset($has_filter[$this->view])) {
         $tokens = array();
         foreach ($user_phids as $phid) {
             $tokens[$phid] = $handles[$phid]->getFullName();
         }
         $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/searchowner/')->setName('set_users')->setLabel('Users')->setValue($tokens));
     }
     if ($this->view == 'custom') {
         $form->appendChild(id(new AphrontFormTextControl())->setName('set_tasks')->setLabel('Task IDs')->setValue(join(',', $task_ids)));
     }
     $tokens = array();
     foreach ($project_phids as $phid) {
         $tokens[$phid] = $handles[$phid]->getFullName();
     }
     $form->appendChild(id(new AphrontFormTokenizerControl())->setDatasource('/typeahead/common/projects/')->setName('set_projects')->setLabel('Projects')->setValue($tokens));
     $form->appendChild(id(new AphrontFormToggleButtonsControl())->setLabel('Status')->setValue($status_links))->appendChild(id(new AphrontFormToggleButtonsControl())->setLabel('Group')->setValue($group_links))->appendChild(id(new AphrontFormToggleButtonsControl())->setLabel('Order')->setValue($order_links));
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Filter Tasks'));
     $create_uri = new PhutilURI('/maniphest/task/create/');
     if ($project_phids) {
         // If we have project filters selected, use them as defaults for task
         // creation.
         $create_uri->setQueryParam('projects', implode(';', $project_phids));
     }
     $filter = new AphrontListFilterView();
     $filter->addButton(phutil_render_tag('a', array('href' => (string) $create_uri, 'class' => 'green button'), 'Create New Task'));
     $filter->appendChild($form);
     $nav->appendChild($filter);
     $have_tasks = false;
     foreach ($tasks as $group => $list) {
         if (count($list)) {
             $have_tasks = true;
             break;
         }
     }
     require_celerity_resource('maniphest-task-summary-css');
     if (!$have_tasks) {
         $nav->appendChild('<h1 class="maniphest-task-group-header">' . 'No matching tasks.' . '</h1>');
     } else {
         $pager = new AphrontPagerView();
         $pager->setURI($request->getRequestURI(), 'page');
         $pager->setPageSize($page_size);
         $pager->setOffset($page);
         $pager->setCount($total_count);
         $cur = $pager->getOffset() + 1;
         $max = min($pager->getOffset() + $page_size, $total_count);
         $tot = $total_count;
         $cur = number_format($cur);
         $max = number_format($max);
         $tot = number_format($tot);
         $nav->appendChild('<div class="maniphest-total-result-count">' . "Displaying tasks {$cur} - {$max} of {$tot}." . '</div>');
         foreach ($tasks as $group => $list) {
             $task_list = new ManiphestTaskListView();
             $task_list->setUser($user);
             $task_list->setTasks($list);
             $task_list->setHandles($handles);
             $count = number_format(count($list));
             $nav->appendChild('<h1 class="maniphest-task-group-header">' . phutil_escape_html($group) . ' (' . $count . ')' . '</h1>');
             $nav->appendChild($task_list);
         }
         $nav->appendChild($pager);
     }
     return $this->buildStandardPageResponse($nav, array('title' => 'Task List'));
 }
 /**
  * Add current state parameters (like order and the visibility of hidden
  * columns) to a URI.
  *
  * This allows actions which toggle or adjust one piece of state to keep
  * the rest of the board state persistent. If no URI is provided, this method
  * starts with the request URI.
  *
  * @param string|null   URI to add state parameters to.
  * @return PhutilURI    URI with state parameters.
  */
 private function getURIWithState($base = null)
 {
     if ($base === null) {
         $base = $this->getRequest()->getRequestURI();
     }
     $base = new PhutilURI($base);
     if ($this->sortKey != PhabricatorProjectColumn::DEFAULT_ORDER) {
         $base->setQueryParam('order', $this->sortKey);
     } else {
         $base->setQueryParam('order', null);
     }
     $base->setQueryParam('hidden', $this->showHidden ? 'true' : null);
     return $base;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     // If we're on the "Update Diff" workflow, load the revision we're going
     // to update.
     $revision = null;
     $revision_id = $request->getURIData('revisionID');
     if ($revision_id) {
         $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($revision_id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$revision) {
             return new Aphront404Response();
         }
     }
     $diff = null;
     // This object is just for policy stuff
     $diff_object = DifferentialDiff::initializeNewDiff($viewer);
     $repository_phid = null;
     $errors = array();
     $e_diff = null;
     $e_file = null;
     $validation_exception = null;
     if ($request->isFormPost()) {
         $repository_tokenizer = $request->getArr(id(new DifferentialRepositoryField())->getFieldKey());
         if ($repository_tokenizer) {
             $repository_phid = reset($repository_tokenizer);
         }
         if ($request->getFileExists('diff-file')) {
             $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
         } else {
             $diff = $request->getStr('diff');
         }
         if (!strlen($diff)) {
             $errors[] = pht('You can not create an empty diff. Paste a diff or upload a ' . 'file containing a diff.');
             $e_diff = pht('Required');
             $e_file = pht('Required');
         }
         if (!$errors) {
             try {
                 $call = new ConduitCall('differential.createrawdiff', array('diff' => $diff, 'repositoryPHID' => $repository_phid, 'viewPolicy' => $request->getStr('viewPolicy')));
                 $call->setUser($viewer);
                 $result = $call->execute();
                 $diff_id = $result['id'];
                 $uri = $this->getApplicationURI("diff/{$diff_id}/");
                 $uri = new PhutilURI($uri);
                 if ($revision) {
                     $uri->setQueryParam('revisionID', $revision->getID());
                 }
                 return id(new AphrontRedirectResponse())->setURI($uri);
             } catch (PhabricatorApplicationTransactionValidationException $ex) {
                 $validation_exception = $ex;
             }
         }
     }
     $form = new AphrontFormView();
     $arcanist_href = PhabricatorEnv::getDoclink('Arcanist User Guide');
     $arcanist_link = phutil_tag('a', array('href' => $arcanist_href, 'target' => '_blank'), pht('Learn More'));
     $cancel_uri = $this->getApplicationURI();
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($diff_object)->execute();
     $info_view = null;
     if (!$request->isFormPost()) {
         $info_view = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->setErrors(array(array(pht('The best way to create a diff is to use the Arcanist ' . 'command-line tool.'), ' ', $arcanist_link), pht('You can also paste a diff below, or upload a file ' . 'containing a diff (for example, from %s, %s or %s).', phutil_tag('tt', array(), 'svn diff'), phutil_tag('tt', array(), 'git diff'), phutil_tag('tt', array(), 'hg diff --git'))));
     }
     if ($revision) {
         $title = pht('Update Diff');
         $header = pht('Update Diff');
         $button = pht('Continue');
     } else {
         $title = pht('Create Diff');
         $header = pht('Create New Diff');
         $button = pht('Create Diff');
     }
     $form->setEncType('multipart/form-data')->setUser($viewer);
     if ($revision) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Updating Revision'))->setValue($viewer->renderHandle($revision->getPHID())));
     }
     if ($repository_phid) {
         $repository_value = array($repository_phid);
     } else {
         $repository_value = array();
     }
     $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Raw Diff'))->setName('diff')->setValue($diff)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setError($e_diff))->appendChild(id(new AphrontFormFileControl())->setLabel(pht('Raw Diff From File'))->setName('diff-file')->setError($e_file))->appendControl(id(new AphrontFormTokenizerControl())->setName(id(new DifferentialRepositoryField())->getFieldKey())->setLabel(pht('Repository'))->setDatasource(new DiffusionRepositoryDatasource())->setValue($repository_value)->setLimit(1))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setName('viewPolicy')->setPolicyObject($diff_object)->setPolicies($policies)->setCapability(PhabricatorPolicyCapability::CAN_VIEW))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($button));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($header)->setValidationException($validation_exception)->setForm($form)->setFormErrors($errors);
     if ($info_view) {
         $form_box->setInfoView($info_view);
     }
     $crumbs = $this->buildApplicationCrumbs();
     if ($revision) {
         $crumbs->addTextCrumb($revision->getMonogram(), '/' . $revision->getMonogram());
     }
     $crumbs->addTextCrumb($title);
     return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title));
 }
 /**
  * Get the fully-qualified production URI for a documentation resource.
  *
  * @task read
  */
 public static function getDoclink($resource, $type = 'article')
 {
     $uri = new PhutilURI('https://secure.phabricator.com/diviner/find/');
     $uri->setQueryParam('name', $resource);
     $uri->setQueryParam('type', $type);
     $uri->setQueryParam('jump', true);
     return (string) $uri;
 }
 /**
  * Add passthrough parameters to the URI so they aren't lost when we
  * redirect to acquire tokens.
  */
 private function addURIParameters(PhutilURI $uri)
 {
     $request = $this->getRequest();
     if ($request->getBool('download')) {
         $uri->setQueryParam('download', 1);
     }
     return $uri;
 }