public function processRequest()
 {
     $request = $this->getRequest();
     $methods = $this->getAllMethods();
     if (empty($methods[$this->method])) {
         return new Aphront404Response();
     }
     $this->setFilter('method/' . $this->method);
     $method_class = $methods[$this->method];
     $method_object = newv($method_class, array());
     $status = $method_object->getMethodStatus();
     $reason = $method_object->getMethodStatusDescription();
     $status_view = null;
     if ($status != ConduitAPIMethod::METHOD_STATUS_STABLE) {
         $status_view = new AphrontErrorView();
         switch ($status) {
             case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
                 $status_view->setTitle('Deprecated Method');
                 $status_view->appendChild(phutil_escape_html(nonempty($reason, "This method is deprecated.")));
                 break;
             case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
                 $status_view->setSeverity(AphrontErrorView::SEVERITY_WARNING);
                 $status_view->setTitle('Unstable Method');
                 $status_view->appendChild(phutil_escape_html(nonempty($reason, "This method is new and unstable. Its interface is subject " . "to change.")));
                 break;
         }
     }
     $error_description = array();
     $error_types = $method_object->defineErrorTypes();
     if ($error_types) {
         $error_description[] = '<ul>';
         foreach ($error_types as $error => $meaning) {
             $error_description[] = '<li>' . '<strong>' . phutil_escape_html($error) . ':</strong> ' . phutil_escape_html($meaning) . '</li>';
         }
         $error_description[] = '</ul>';
         $error_description = implode("\n", $error_description);
     } else {
         $error_description = "This method does not raise any specific errors.";
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser())->setAction('/api/' . $this->method)->appendChild(id(new AphrontFormStaticControl())->setLabel('Description')->setValue($method_object->getMethodDescription()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Returns')->setValue($method_object->defineReturnType()))->appendChild(id(new AphrontFormMarkupControl())->setLabel('Errors')->setValue($error_description))->appendChild('<p class="aphront-form-instructions">Enter parameters using ' . '<strong>JSON</strong>. For instance, to enter a list, type: ' . '<tt>["apple", "banana", "cherry"]</tt>');
     $params = $method_object->defineParamTypes();
     foreach ($params as $param => $desc) {
         $form->appendChild(id(new AphrontFormTextControl())->setLabel($param)->setName("params[{$param}]")->setCaption(phutil_escape_html($desc)));
     }
     $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Output Format')->setName('output')->setOptions(array('human' => 'Human Readable', 'json' => 'JSON')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Call Method'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Conduit API: ' . phutil_escape_html($this->method));
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     return $this->buildStandardPageResponse(array($status_view, $panel), array('title' => 'Conduit Console - ' . $this->method));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     // There's no sense in showing a change password panel if the user
     // can't change their password
     if (!$editable || !PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) {
         return new Aphront400Response();
     }
     $errors = array();
     if ($request->isFormPost()) {
         if ($user->comparePassword($request->getStr('old_pw'))) {
             $pass = $request->getStr('new_pw');
             $conf = $request->getStr('conf_pw');
             if ($pass === $conf) {
                 if (strlen($pass)) {
                     $user->setPassword($pass);
                     // This write is unguarded because the CSRF token has already
                     // been checked in the call to $request->isFormPost() and
                     // the CSRF token depends on the password hash, so when it
                     // is changed here the CSRF token check will fail.
                     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                     $user->save();
                     unset($unguarded);
                     return id(new AphrontRedirectResponse())->setURI('/settings/page/password/?saved=true');
                 } else {
                     $errors[] = 'Your new password is too short.';
                 }
             } else {
                 $errors[] = 'New password and confirmation do not match.';
             }
         } else {
             $errors[] = 'The old password you entered is incorrect.';
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your password has been updated.</p>');
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Error Changing Password');
         $notice->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($user)->appendChild(id(new AphrontFormPasswordControl())->setLabel('Old Password')->setName('old_pw'));
     $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setName('new_pw'));
     $form->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setName('conf_pw'));
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Change Password');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $task = id(new PhabricatorWorkerActiveTask())->load($this->id);
     if (!$task) {
         $task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
     }
     if (!$task) {
         $title = pht('Task Does Not Exist');
         $error_view = new AphrontErrorView();
         $error_view->setTitle(pht('No Such Task'));
         $error_view->appendChild(phutil_tag('p', array(), pht('This task may have recently been garbage collected.')));
         $error_view->setSeverity(AphrontErrorView::SEVERITY_NODATA);
         $content = $error_view;
     } else {
         $title = pht('Task %d', $task->getID());
         $header = id(new PHUIHeaderView())->setHeader(pht('Task %d (%s)', $task->getID(), $task->getTaskClass()));
         $actions = $this->buildActionListView($task);
         $properties = $this->buildPropertyListView($task, $actions);
         $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
         $retry_head = id(new PHUIHeaderView())->setHeader(pht('Retries'));
         $retry_info = $this->buildRetryListView($task);
         $retry_box = id(new PHUIObjectBoxView())->setHeader($retry_head)->addPropertyList($retry_info);
         $content = array($object_box, $retry_box);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($title);
     return $this->buildApplicationPage(array($crumbs, $content), array('title' => $title));
 }
 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')));
 }
 private function generateWarningView($status, array $titles, $id, $content)
 {
     $warning = new AphrontErrorView();
     $warning->setSeverity(AphrontErrorView::SEVERITY_ERROR);
     $warning->setID($id);
     $warning->appendChild($content);
     $warning->setTitle(idx($titles, $status, 'Warning'));
     return $warning;
 }
 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'));
     if ($drequest->getRawCommit()) {
         $is_commit = true;
         $query = DiffusionCommitTagsQuery::newFromDiffusionRequest($drequest);
         $query->setOffset($pager->getOffset());
         $query->setLimit($pager->getPageSize() + 1);
         $tags = $query->loadTags();
     } else {
         $is_commit = false;
         $query = DiffusionTagListQuery::newFromDiffusionRequest($drequest);
         $query->setOffset($pager->getOffset());
         $query->setLimit($pager->getPageSize() + 1);
         $tags = $query->loadTags();
     }
     $tags = $pager->sliceResults($tags);
     $content = null;
     if (!$tags) {
         $content = new AphrontErrorView();
         $content->setTitle('No Tags');
         if ($is_commit) {
             $content->appendChild('This commit has no tags.');
         } else {
             $content->appendChild('This repository has no tags.');
         }
         $content->setSeverity(AphrontErrorView::SEVERITY_NODATA);
     } else {
         $commits = id(new PhabricatorAuditCommitQuery())->withIdentifiers($drequest->getRepository()->getID(), mpull($tags, 'getCommitIdentifier'))->needCommitData(true)->execute();
         $view = id(new DiffusionTagListView())->setTags($tags)->setUser($user)->setCommits($commits)->setDiffusionRequest($drequest);
         $phids = $view->getRequiredHandlePHIDs();
         $handles = $this->loadViewerHandles($phids);
         $view->setHandles($handles);
         $panel = id(new AphrontPanelView())->setHeader('Tags')->appendChild($view)->appendChild($pager);
         $content = $panel;
     }
     return $this->buildStandardPageResponse(array($this->buildCrumbs(array('tags' => true, 'commit' => $drequest->getRawCommit())), $content), array('title' => array('Tags', $repository->getCallsign() . ' Repository')));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $admin = $request->getUser();
     if ($this->id) {
         $user = id(new PhabricatorUser())->load($this->id);
         if (!$user) {
             return new Aphront404Response();
         }
     } else {
         $user = new PhabricatorUser();
     }
     $views = array('basic' => 'Basic Information', 'role' => 'Edit Role', 'cert' => 'Conduit Certificate');
     if (!$user->getID()) {
         $view = 'basic';
     } else {
         if (isset($views[$this->view])) {
             $view = $this->view;
         } else {
             $view = 'basic';
         }
     }
     $content = array();
     if ($request->getStr('saved')) {
         $notice = new AphrontErrorView();
         $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $notice->setTitle('Changes Saved');
         $notice->appendChild('<p>Your changes were saved.</p>');
         $content[] = $notice;
     }
     switch ($view) {
         case 'basic':
             $response = $this->processBasicRequest($user);
             break;
         case 'role':
             $response = $this->processRoleRequest($user);
             break;
         case 'cert':
             $response = $this->processCertificateRequest($user);
             break;
     }
     if ($response instanceof AphrontResponse) {
         return $response;
     }
     $content[] = $response;
     if ($user->getID()) {
         $side_nav = new AphrontSideNavView();
         $side_nav->appendChild($content);
         foreach ($views as $key => $name) {
             $side_nav->addNavItem(phutil_render_tag('a', array('href' => '/people/edit/' . $user->getID() . '/' . $key . '/', 'class' => $key == $view ? 'aphront-side-nav-selected' : null), phutil_escape_html($name)));
         }
         $content = $side_nav;
     }
     return $this->buildStandardPageResponse($content, array('title' => 'Edit User'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $mail = new PhabricatorMetaMTAMail();
         $mail->addTos($request->getArr('to'));
         $mail->addCCs($request->getArr('cc'));
         $mail->setSubject($request->getStr('subject'));
         $mail->setBody($request->getStr('body'));
         $files = $request->getArr('files');
         if ($files) {
             foreach ($files as $phid) {
                 $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
                 $mail->addAttachment(new PhabricatorMetaMTAAttachment($file->loadFileData(), $file->getName(), $file->getMimeType()));
             }
         }
         $mail->setFrom($request->getUser()->getPHID());
         $mail->setSimulatedFailureCount($request->getInt('failures'));
         $mail->setIsHTML($request->getInt('html'));
         $mail->setIsBulk($request->getInt('bulk'));
         $mail->setMailTags($request->getStrList('mailtags'));
         $mail->save();
         if ($request->getInt('immediately')) {
             $mail->sendNow();
         }
         return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('/view/' . $mail->getID() . '/'));
     }
     $failure_caption = "Enter a number to simulate that many consecutive send failures before " . "really attempting to deliver via the underlying MTA.";
     $doclink_href = PhabricatorEnv::getDoclink('article/Configuring_Outbound_Email.html');
     $doclink = phutil_render_tag('a', array('href' => $doclink_href, 'target' => '_blank'), 'Configuring Outbound Email');
     $instructions = '<p class="aphront-form-instructions">This form will send a normal ' . 'email using the settings you have configured for Phabricator. For more ' . 'information, see ' . $doclink . '.</p>';
     $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
     $warning = null;
     if ($adapter == 'PhabricatorMailImplementationTestAdapter') {
         $warning = new AphrontErrorView();
         $warning->setTitle('Email is Disabled');
         $warning->setSeverity(AphrontErrorView::SEVERITY_WARNING);
         $warning->appendChild('<p>This installation of Phabricator is currently set to use ' . '<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver ' . 'outbound email. This completely disables outbound email! All ' . 'outbound email will be thrown in a deep, dark hole until you ' . 'configure a real adapter.</p>');
     }
     $panel_id = celerity_generate_unique_node_id();
     $phdlink_href = PhabricatorEnv::getDoclink('article/Managing_Daemons_with_phd.html');
     $phdlink = phutil_render_tag('a', array('href' => $phdlink_href, 'target' => '_blank'), '"phd start"');
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     $form->appendChild($instructions)->appendChild(id(new AphrontFormStaticControl())->setLabel('Adapter')->setValue($adapter))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('To')->setName('to')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTextControl())->setLabel('Subject')->setName('subject'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormTextControl())->setLabel('Mail Tags')->setName('mailtags')->setCaption('Example: <tt>differential-cc, differential-comment</tt>'))->appendChild(id(new AphrontFormDragAndDropUploadControl())->setLabel('Attach Files')->setName('files')->setDragAndDropTarget($panel_id)->setActivatedClass('aphront-panel-view-drag-and-drop'))->appendChild(id(new AphrontFormTextControl())->setLabel('Simulate Failures')->setName('failures')->setCaption($failure_caption))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('HTML')->addCheckbox('html', '1', 'Send as HTML email.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Bulk')->addCheckbox('bulk', '1', 'Send with bulk email headers.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Send Now')->addCheckbox('immediately', '1', 'Send immediately. (Do not enqueue for daemons.)', PhabricatorEnv::getEnvConfig('metamta.send-immediately'))->setCaption('Daemons can be started with ' . $phdlink . '.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Mail'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Send Email');
     $panel->appendChild($form);
     $panel->setID($panel_id);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('send');
     $nav->appendChild(array($warning, $panel));
     return $this->buildApplicationPage($nav, array('title' => 'Send Test'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $xscript = id(new HeraldTranscriptQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne();
     if (!$xscript) {
         return new Aphront404Response();
     }
     require_celerity_resource('herald-test-css');
     $nav = $this->buildSideNav();
     $object_xscript = $xscript->getObjectTranscript();
     if (!$object_xscript) {
         $notice = id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle(pht('Old Transcript'))->appendChild(phutil_tag('p', array(), pht('Details of this transcript have been garbage collected.')));
         $nav->appendChild($notice);
     } else {
         $map = HeraldAdapter::getEnabledAdapterMap($viewer);
         $object_type = $object_xscript->getType();
         if (empty($map[$object_type])) {
             // TODO: We should filter these out in the Query, but we have to load
             // the objectTranscript right now, which is potentially enormous. We
             // should denormalize the object type, or move the data into a separate
             // table, and then filter this earlier (and thus raise a better error).
             // For now, just block access so we don't violate policies.
             throw new Exception(pht('This transcript has an invalid or inaccessible adapter.'));
         }
         $this->adapter = HeraldAdapter::getAdapterForContentType($object_type);
         $filter = $this->getFilterPHIDs();
         $this->filterTranscript($xscript, $filter);
         $phids = array_merge($filter, $this->getTranscriptPHIDs($xscript));
         $phids = array_unique($phids);
         $phids = array_filter($phids);
         $handles = $this->loadViewerHandles($phids);
         $this->handles = $handles;
         if ($xscript->getDryRun()) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle(pht('Dry Run'));
             $notice->appendChild(pht('This was a dry run to test Herald ' . 'rules, no actions were executed.'));
             $nav->appendChild($notice);
         }
         $warning_panel = $this->buildWarningPanel($xscript);
         $nav->appendChild($warning_panel);
         $apply_xscript_panel = $this->buildApplyTranscriptPanel($xscript);
         $nav->appendChild($apply_xscript_panel);
         $action_xscript_panel = $this->buildActionTranscriptPanel($xscript);
         $nav->appendChild($action_xscript_panel);
         $object_xscript_panel = $this->buildObjectTranscriptPanel($xscript);
         $nav->appendChild($object_xscript_panel);
     }
     $crumbs = id($this->buildApplicationCrumbs())->addTextCrumb(pht('Transcripts'), $this->getApplicationURI('/transcript/'))->addTextCrumb($xscript->getID());
     $nav->setCrumbs($crumbs);
     return $this->buildApplicationPage($nav, array('title' => pht('Transcript')));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     $e_realname = $editable ? true : null;
     $errors = array();
     if ($request->isFormPost()) {
         if ($editable) {
             $user->setRealName($request->getStr('realname'));
             if (!strlen($user->getRealName())) {
                 $errors[] = 'Real name must be nonempty.';
                 $e_realname = 'Required';
             }
         }
         $new_timezone = $request->getStr('timezone');
         if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
             $user->setTimezoneIdentifier($new_timezone);
         } else {
             $errors[] = 'The selected timezone is not a valid timezone.';
         }
         if (!$errors) {
             $user->save();
             return id(new AphrontRedirectResponse())->setURI('/settings/page/account/?saved=true');
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your changes have been saved.</p>');
             $notice = $notice->render();
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Form Errors');
         $notice->setErrors($errors);
         $notice = $notice->render();
     }
     $timezone_ids = DateTimeZone::listIdentifiers();
     $timezone_id_map = array_combine($timezone_ids, $timezone_ids);
     $form = new AphrontFormView();
     $form->setUser($user)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormStaticControl())->setLabel('Username')->setValue($user->getUsername()))->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setError($e_realname)->setValue($user->getRealName())->setDisabled(!$editable))->appendChild(id(new AphrontFormSelectControl())->setLabel('Timezone')->setName('timezone')->setOptions($timezone_id_map)->setValue($user->getTimezoneIdentifier()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Account Settings');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
 public function processRequest()
 {
     try {
         $status = PhabricatorNotificationClient::getServerStatus();
         $status = $this->renderServerStatus($status);
     } catch (Exception $ex) {
         $status = new AphrontErrorView();
         $status->setTitle('Notification Server Issue');
         $status->appendChild(hsprintf('Unable to determine server status. This probably means the server ' . 'is not in great shape. The specific issue encountered was:' . '<br />' . '<br />' . '<strong>%s</strong> %s', get_class($ex), phutil_escape_html_newlines($ex->getMessage())));
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Status'));
     return $this->buildApplicationPage(array($crumbs, $status), array('title' => pht('Notification Server Status'), 'device' => false));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $task = id(new PhabricatorWorkerTask())->load($this->id);
     if (!$task) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('No Such Task');
         $error_view->appendChild('<p>This task may have recently completed.</p>');
         $error_view->setSeverity(AphrontErrorView::SEVERITY_WARNING);
         return $this->buildStandardPageResponse($error_view, array('title' => 'Task Does Not Exist'));
     }
     $data = id(new PhabricatorWorkerTaskData())->loadOneWhere('id = %d', $task->getDataID());
     $extra = null;
     switch ($task->getTaskClass()) {
         case 'PhabricatorRepositorySvnCommitChangeParserWorker':
         case 'PhabricatorRepositoryGitCommitChangeParserWorker':
             $commit_id = idx($data->getData(), 'commitID');
             if ($commit_id) {
                 $commit = id(new PhabricatorRepositoryCommit())->load($commit_id);
                 if ($commit) {
                     $repository = id(new PhabricatorRepository())->load($commit->getRepositoryID());
                     if ($repository) {
                         $extra = "<strong>NOTE:</strong> " . "You can manually retry this task by running this script:" . "<pre>" . "phabricator/\$ ./scripts/repository/reparse.php " . "r" . phutil_escape_html($repository->getCallsign()) . phutil_escape_html($commit->getCommitIdentifier()) . " " . "--change" . "</pre>";
                     }
                 }
             }
             break;
         default:
             break;
     }
     if ($data) {
         $data = json_encode($data->getData());
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue($task->getID()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Type')->setValue($task->getTaskClass()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Lease Owner')->setValue($task->getLeaseOwner()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Lease Expires')->setValue($task->getLeaseExpires() - time()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Failure Count')->setValue($task->getFailureCount()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Data')->setValue($data));
     if ($extra) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel('More')->setValue($extra));
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/daemon/', 'Back'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Task Detail');
     $panel->setWidth(AphrontPanelView::WIDTH_WIDE);
     $panel->appendChild($form);
     $panel->addButton(javelin_render_tag('a', array('href' => '/daemon/task/' . $task->getID() . '/delete/', 'class' => 'button grey', 'sigil' => 'workflow'), 'Delete Task'));
     $panel->addButton(javelin_render_tag('a', array('href' => '/daemon/task/' . $task->getID() . '/release/', 'class' => 'button grey', 'sigil' => 'workflow'), 'Free Lease'));
     $nav = $this->buildSideNavView();
     $nav->selectFilter('');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'Task'));
 }
 public function render()
 {
     $drequest = $this->getDiffusionRequest();
     $commit = $drequest->getCommit();
     $callsign = $drequest->getRepository()->getCallsign();
     if ($commit) {
         $commit = "r{$callsign}{$commit}";
     } else {
         $commit = 'HEAD';
     }
     switch ($this->browseQuery->getReasonForEmptyResultSet()) {
         case DiffusionBrowseQuery::REASON_IS_NONEXISTENT:
             $title = 'Path Does Not Exist';
             // TODO: Under git, this error message should be more specific. It
             // may exist on some other branch.
             $body = "This path does not exist anywhere.";
             $severity = AphrontErrorView::SEVERITY_ERROR;
             break;
         case DiffusionBrowseQuery::REASON_IS_EMPTY:
             $title = 'Empty Directory';
             $body = "This path was an empty directory at {$commit}.\n";
             $severity = AphrontErrorView::SEVERITY_NOTICE;
             break;
         case DiffusionBrowseQuery::REASON_IS_DELETED:
             $deleted = $this->browseQuery->getDeletedAtCommit();
             $existed = $this->browseQuery->getExistedAtCommit();
             $deleted = self::linkCommit($drequest->getRepository(), $deleted);
             $browse = $this->linkBrowse($drequest->getPath(), array('text' => 'existed', 'commit' => $existed, 'params' => array('view' => $this->view)));
             $existed = "r{$callsign}{$existed}";
             $title = 'Path Was Deleted';
             $body = "This path does not exist at {$commit}. It was deleted in " . "{$deleted} and last {$browse} at {$existed}.";
             $severity = AphrontErrorView::SEVERITY_WARNING;
             break;
         case DiffusionBrowseQuery::REASON_IS_UNTRACKED_PARENT:
             $subdir = $drequest->getRepository()->getDetail('svn-subpath');
             $title = 'Directory Not Tracked';
             $body = "This repository is configured to track only one subdirectory " . "of the entire repository ('" . phutil_escape_html($subdir) . "'), " . "but you aren't looking at something in that subdirectory, so no " . "information is available.";
             $severity = AphrontErrorView::SEVERITY_WARNING;
             break;
         default:
             throw new Exception("Unknown failure reason!");
     }
     $error_view = new AphrontErrorView();
     $error_view->setSeverity($severity);
     $error_view->setTitle($title);
     $error_view->appendChild('<p>' . $body . '</p>');
     return $error_view->render();
 }
예제 #14
0
 public function renderExample()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $sevs = array(AphrontErrorView::SEVERITY_ERROR => 'Error', AphrontErrorView::SEVERITY_WARNING => 'Warning', AphrontErrorView::SEVERITY_NOTICE => 'Notice', AphrontErrorView::SEVERITY_NODATA => 'No Data');
     $views = array();
     foreach ($sevs as $sev => $title) {
         $view = new AphrontErrorView();
         $view->setSeverity($sev);
         $view->setTitle($title);
         $view->appendChild('Several issues were encountered.');
         $view->setErrors(array('Overcooked.', 'Too much salt.', 'Full of sand.'));
         $views[] = $view;
     }
     return $views;
 }
예제 #15
0
 public function buildResponseString()
 {
     if ($this->shouldStopForDebugging()) {
         $view = new PhabricatorStandardPageView();
         $view->setRequest($this->getRequest());
         $view->setApplicationName('Debug');
         $view->setTitle('Stopped on Redirect');
         $error = new AphrontErrorView();
         $error->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $error->setTitle('Stopped on Redirect');
         $link = phutil_render_tag('a', array('href' => $this->getURI()), 'Continue to: ' . phutil_escape_html($this->getURI()));
         $error->appendChild('<p>You were stopped here because <tt>debug.stop-on-redirect</tt> ' . 'is set in your configuration.</p>' . '<p>' . $link . '</p>');
         $view->appendChild($error);
         return $view->render();
     }
     return '';
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         if (!$request->isDialogFormPost()) {
             $dialog = new AphrontDialogView();
             $dialog->setUser($user);
             $dialog->setTitle('Really regenerate session?');
             $dialog->setSubmitURI('/settings/page/conduit/');
             $dialog->addSubmitButton('Regenerate');
             $dialog->addCancelbutton('/settings/page/conduit/');
             $dialog->appendChild('<p>Really destroy the old certificate? Any established ' . 'sessions will be terminated.');
             return id(new AphrontDialogResponse())->setDialog($dialog);
         }
         $conn = $user->establishConnection('w');
         queryfx($conn, 'DELETE FROM %T WHERE userPHID = %s AND type LIKE %>', PhabricatorUser::SESSION_TABLE, $user->getPHID(), 'conduit');
         // This implicitly regenerates the certificate.
         $user->setConduitCertificate(null);
         $user->save();
         return id(new AphrontRedirectResponse())->setURI('/settings/page/conduit/?regenerated=true');
     }
     if ($request->getStr('regenerated')) {
         $notice = new AphrontErrorView();
         $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $notice->setTitle('Certificate Regenerated');
         $notice->appendChild('<p>Your old certificate has been destroyed and you have been issued ' . 'a new certificate. Sessions established under the old certificate ' . 'are no longer valid.</p>');
         $notice = $notice->render();
     } else {
         $notice = null;
     }
     $cert_form = new AphrontFormView();
     $cert_form->setUser($user)->appendChild('<p class="aphront-form-instructions">This certificate allows you to ' . 'authenticate over Conduit, the Phabricator API. Normally, you just ' . 'run <tt>arc install-certificate</tt> to install it.')->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Certificate')->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)->setValue($user->getConduitCertificate()));
     $cert = new AphrontPanelView();
     $cert->setHeader('Arcanist Certificate');
     $cert->appendChild($cert_form);
     $cert->setWidth(AphrontPanelView::WIDTH_FORM);
     $regen_form = new AphrontFormView();
     $regen_form->setUser($user)->setAction('/settings/page/conduit/')->appendChild('<p class="aphront-form-instructions">You can regenerate this ' . 'certificate, which will invalidate the old certificate and create ' . 'a new one.</p>')->appendChild(id(new AphrontFormSubmitControl())->setValue('Regenerate Certificate'));
     $regen = new AphrontPanelView();
     $regen->setHeader('Regenerate Certificate');
     $regen->appendChild($regen_form);
     $regen->setWidth(AphrontPanelView::WIDTH_FORM);
     return id(new AphrontNullView())->appendChild(array($notice, $cert, $regen));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $editable = $this->getAccountEditable();
     $e_email = true;
     $errors = array();
     if ($request->isFormPost()) {
         if (!$editable) {
             return new Aphront400Response();
         }
         $user->setEmail($request->getStr('email'));
         if (!strlen($user->getEmail())) {
             $errors[] = 'You must enter an e-mail address.';
             $e_email = 'Required';
         }
         if (!$errors) {
             $user->save();
             return id(new AphrontRedirectResponse())->setURI('/settings/page/email/?saved=true');
         }
     }
     $notice = null;
     if (!$errors) {
         if ($request->getStr('saved')) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Changes Saved');
             $notice->appendChild('<p>Your changes have been saved.</p>');
         }
     } else {
         $notice = new AphrontErrorView();
         $notice->setTitle('Form Errors');
         $notice->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setDisabled(!$editable)->setCaption('Note: there is no email validation yet; double-check your ' . 'typing.')->setValue($user->getEmail())->setError($e_email));
     if ($editable) {
         $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'));
     }
     $panel = new AphrontPanelView();
     $panel->setHeader('Email Settings');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return id(new AphrontNullView())->appendChild(array($notice, $panel));
 }
 public function processRequest(AphrontRequest $request)
 {
     $user = $this->getUser();
     $viewer = $request->getUser();
     id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession($viewer, $request, '/settings/');
     if ($request->isFormPost()) {
         if (!$request->isDialogFormPost()) {
             $dialog = new AphrontDialogView();
             $dialog->setUser($viewer);
             $dialog->setTitle(pht('Really regenerate session?'));
             $dialog->setSubmitURI($this->getPanelURI());
             $dialog->addSubmitButton(pht('Regenerate'));
             $dialog->addCancelbutton($this->getPanelURI());
             $dialog->appendChild(phutil_tag('p', array(), pht('Really destroy the old certificate? Any established ' . 'sessions will be terminated.')));
             return id(new AphrontDialogResponse())->setDialog($dialog);
         }
         $sessions = id(new PhabricatorAuthSessionQuery())->setViewer($user)->withIdentityPHIDs(array($user->getPHID()))->withSessionTypes(array(PhabricatorAuthSession::TYPE_CONDUIT))->execute();
         foreach ($sessions as $session) {
             $session->delete();
         }
         // This implicitly regenerates the certificate.
         $user->setConduitCertificate(null);
         $user->save();
         return id(new AphrontRedirectResponse())->setURI($this->getPanelURI('?regenerated=true'));
     }
     if ($request->getStr('regenerated')) {
         $notice = new AphrontErrorView();
         $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $notice->setTitle(pht('Certificate Regenerated'));
         $notice->appendChild(phutil_tag('p', array(), pht('Your old certificate has been destroyed and you have been issued ' . 'a new certificate. Sessions established under the old certificate ' . 'are no longer valid.')));
         $notice = $notice->render();
     } else {
         $notice = null;
     }
     Javelin::initBehavior('select-on-click');
     $cert_form = new AphrontFormView();
     $cert_form->setUser($viewer)->appendChild(phutil_tag('p', array('class' => 'aphront-form-instructions'), pht('This certificate allows you to authenticate over Conduit, ' . 'the Phabricator API. Normally, you just run %s to install it.', phutil_tag('tt', array(), 'arc install-certificate'))))->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Certificate'))->setHeight(AphrontFormTextAreaControl::HEIGHT_SHORT)->setReadonly(true)->setSigil('select-on-click')->setValue($user->getConduitCertificate()));
     $cert_form = id(new PHUIObjectBoxView())->setHeaderText(pht('Arcanist Certificate'))->setForm($cert_form);
     $regen_instruction = pht('You can regenerate this certificate, which ' . 'will invalidate the old certificate and create a new one.');
     $regen_form = new AphrontFormView();
     $regen_form->setUser($viewer)->setAction($this->getPanelURI())->setWorkflow(true)->appendChild(phutil_tag('p', array('class' => 'aphront-form-instructions'), $regen_instruction))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Regenerate Certificate')));
     $regen_form = id(new PHUIObjectBoxView())->setHeaderText(pht('Regenerate Certificate'))->setForm($regen_form);
     return array($notice, $cert_form, $regen_form);
 }
 public function processRequest()
 {
     $uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
     $uri = new PhutilURI($uri);
     $uri->setPath('/status/');
     $future = id(new HTTPSFuture($uri))->setTimeout(3);
     try {
         list($body) = $future->resolvex();
         $body = json_decode($body, true);
         if (!is_array($body)) {
             throw new Exception("Expected JSON response from server!");
         }
         $status = $this->renderServerStatus($body);
     } catch (Exception $ex) {
         $status = new AphrontErrorView();
         $status->setTitle("Notification Server Issue");
         $status->appendChild('Unable to determine server status. This probably means the server ' . 'is not in great shape. The specific issue encountered was:' . '<br />' . '<br />' . '<strong>' . phutil_escape_html(get_class($ex)) . '</strong> ' . nl2br(phutil_escape_html($ex->getMessage())));
     }
     return $this->buildStandardPageResponse($status, array('title' => 'Aphlict Server Status'));
 }
 protected function renderDaemonNotice()
 {
     $documentation = phutil_render_tag('a', array('href' => PhabricatorEnv::getDoclink('article/Diffusion_User_Guide.html')), 'Diffusion User Guide');
     $common = "Without this daemon, Phabricator will not be able to import or update " . "repositories. For instructions on starting the daemon, see " . "<strong>{$documentation}</strong>.";
     try {
         $daemon_running = $this->isPullDaemonRunning();
         if ($daemon_running) {
             return null;
         }
         $title = "Repository Daemon Not Running";
         $message = "<p>The repository daemon is not running on this machine. " . "{$common}</p>";
     } catch (CommandException $ex) {
         $title = "Unable To Verify Repository Daemon";
         $message = "<p>Unable to determine if the repository daemon is running on this " . "machine. {$common}</p>" . "<p><strong>Exception:</strong> " . phutil_escape_html($ex->getMessage()) . "</p>";
     }
     $view = new AphrontErrorView();
     $view->setSeverity(AphrontErrorView::SEVERITY_WARNING);
     $view->setTitle($title);
     $view->appendChild($message);
     return $view;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $mail = new PhabricatorMetaMTAMail();
         $mail->addTos($request->getArr('to'));
         $mail->addCCs($request->getArr('cc'));
         $mail->setSubject($request->getStr('subject'));
         $mail->setBody($request->getStr('body'));
         $mail->setFrom($request->getUser()->getPHID());
         $mail->setSimulatedFailureCount($request->getInt('failures'));
         $mail->setIsHTML($request->getInt('html'));
         $mail->save();
         if ($request->getInt('immediately')) {
             $mail->sendNow();
         }
         return id(new AphrontRedirectResponse())->setURI('/mail/view/' . $mail->getID() . '/');
     }
     $failure_caption = "Enter a number to simulate that many consecutive send failures before " . "really attempting to deliver via the underlying MTA.";
     $doclink_href = PhabricatorEnv::getDoclink('article/Configuring_Outbound_Email.html');
     $doclink = phutil_render_tag('a', array('href' => $doclink_href, 'target' => '_blank'), 'Configuring Outbound Email');
     $instructions = '<p class="aphront-form-instructions">This form will send a normal ' . 'email using the settings you have configured for Phabricator. For more ' . 'information, see ' . $doclink . '.</p>';
     $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
     $warning = null;
     if ($adapter == 'PhabricatorMailImplementationTestAdapter') {
         $warning = new AphrontErrorView();
         $warning->setTitle('Email is Disabled');
         $warning->setSeverity(AphrontErrorView::SEVERITY_WARNING);
         $warning->appendChild('<p>This installation of Phabricator is currently set to use ' . '<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver ' . 'outbound email. This completely disables outbound email! All ' . 'outbound email will be thrown in a deep, dark hole until you ' . 'configure a real adapter.</p>');
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     $form->setAction('/mail/send/');
     $form->appendChild($instructions)->appendChild(id(new AphrontFormStaticControl())->setLabel('Configured Adapter')->setValue($adapter))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('To')->setName('to')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTextControl())->setLabel('Subject')->setName('subject'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormTextControl())->setLabel('Simulate Failures')->setName('failures')->setCaption($failure_caption))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('HTML')->addCheckbox('html', '1', 'Send as HTML email.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Send Now')->addCheckbox('immediately', '1', 'Send immediately, not via MetaMTA background script.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Mail'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Send Email');
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_WIDE);
     return $this->buildStandardPageResponse(array($warning, $panel), array('title' => 'Send Mail'));
 }
 public function processRequest()
 {
     $xscript = id(new HeraldTranscript())->load($this->id);
     if (!$xscript) {
         throw new Exception('Uknown transcript!');
     }
     require_celerity_resource('herald-test-css');
     $nav = $this->buildSideNav();
     $object_xscript = $xscript->getObjectTranscript();
     if (!$object_xscript) {
         $notice = id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle('Old Transcript')->appendChild('<p>Details of this transcript have been garbage collected.</p>');
         $nav->appendChild($notice);
     } else {
         $filter = $this->getFilterPHIDs();
         $this->filterTranscript($xscript, $filter);
         $phids = array_merge($filter, $this->getTranscriptPHIDs($xscript));
         $phids = array_unique($phids);
         $phids = array_filter($phids);
         $handles = $this->loadViewerHandles($phids);
         $this->handles = $handles;
         if ($xscript->getDryRun()) {
             $notice = new AphrontErrorView();
             $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
             $notice->setTitle('Dry Run');
             $notice->appendChild('This was a dry run to test Herald rules, no actions were executed.');
             $nav->appendChild($notice);
         }
         $apply_xscript_panel = $this->buildApplyTranscriptPanel($xscript);
         $nav->appendChild($apply_xscript_panel);
         $action_xscript_panel = $this->buildActionTranscriptPanel($xscript);
         $nav->appendChild($action_xscript_panel);
         $object_xscript_panel = $this->buildObjectTranscriptPanel($xscript);
         $nav->appendChild($object_xscript_panel);
     }
     $main_nav = $this->renderNav();
     $main_nav->selectFilter('transcript');
     $main_nav->appendChild($nav);
     return $this->buildStandardPageResponse($main_nav, array('title' => 'Transcript'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if ($this->username) {
         $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $this->username);
     } else {
         $user = $request->getUser();
     }
     $content = array();
     if (!$user) {
         $error_view = new AphrontErrorView();
         $error_view->setSeverity(AphrontErrorView::SEVERITY_ERROR);
         $error_body = 'User name ' . '<b>' . phutil_escape_html($this->username) . '</b>' . ' doesn\'t exist.';
         $error_view->setTitle("Error");
         $error_view->appendChild('<p>' . $error_body . '</p>');
         $content[] = $error_view;
     } else {
         $pager = new AphrontPagerView();
         $pager->setOffset($request->getInt('offset'));
         $pager->setURI($request->getRequestURI(), 'offset');
         $query = new PhabricatorSearchQuery();
         $query->setParameter('type', PhabricatorPHIDConstants::PHID_TYPE_CMIT);
         $query->setParameter('author', array($user->getPHID()));
         $query->setParameter('limit', $pager->getPageSize() + 1);
         $query->setParameter('offset', $pager->getOffset());
         $user_link = phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUsername()));
         $executor = new PhabricatorSearchMySQLExecutor();
         $results = $executor->executeSearch($query);
         $results = $pager->sliceResults($results);
         $result_phids = ipull($results, 'phid');
         $commit_table = self::createCommitTable($result_phids, $user);
         $list_panel = new AphrontPanelView();
         $list_panel->setHeader('Commits by ' . $user_link);
         $list_panel->appendChild($commit_table);
         $list_panel->appendChild($pager);
         $content[] = $list_panel;
     }
     return $this->buildStandardPageResponse($content, array('title' => 'Commit List'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $email = $user->loadPrimaryEmail();
     if ($user->getIsEmailVerified()) {
         return id(new AphrontRedirectResponse())->setURI('/');
     }
     $email_address = $email->getAddress();
     $sent = null;
     if ($request->isFormPost()) {
         $email->sendVerificationEmail($user);
         $sent = new AphrontErrorView();
         $sent->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $sent->setTitle(pht('Email Sent'));
         $sent->appendChild(pht('Another verification email was sent to %s.', phutil_tag('strong', array(), $email_address)));
     }
     $must_verify = pht('You must verify your email address to login. You should have a ' . 'new email message from Phabricator with verification instructions ' . 'in your inbox (%s).', phutil_tag('strong', array(), $email_address));
     $send_again = pht('If you did not receive an email, you can click the button below ' . 'to try sending another one.');
     $dialog = id(new AphrontDialogView())->setUser($user)->setTitle(pht('Check Your Email'))->appendParagraph($must_verify)->appendParagraph($send_again)->addSubmitButton(pht('Send Another Email'));
     return $this->buildApplicationPage(array($sent, $dialog), array('title' => pht('Must Verify Email')));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $task = id(new PhabricatorWorkerTask())->load($this->id);
     if (!$task) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('No Such Task');
         $error_view->appendChild('<p>This task may have recently completed.</p>');
         $error_view->setSeverity(AphrontErrorView::SEVERITY_WARNING);
         return $this->buildStandardPageResponse($error_view, array('title' => 'Task Does Not Exist'));
     }
     $data = id(new PhabricatorWorkerTaskData())->loadOneWhere('id = %d', $task->getDataID());
     if ($data) {
         $data = json_encode($data->getData());
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue($task->getID()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Type')->setValue($task->getTaskClass()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Lease Owner')->setValue($task->getLeaseOwner()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Lease Expires')->setValue($task->getLeaseExpires() - time()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Failure Count')->setValue($task->getFailureCount()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Data')->setValue($data))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/daemon/'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Task Detail');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return $this->buildStandardPageResponse($panel, array('title' => 'Task'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $email = $user->loadPrimaryEmail();
     if ($email->getIsVerified()) {
         return id(new AphrontRedirectResponse())->setURI('/');
     }
     $email_address = $email->getAddress();
     $sent = null;
     if ($request->isFormPost()) {
         $email->sendVerificationEmail($user);
         $sent = new AphrontErrorView();
         $sent->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $sent->setTitle('Email Sent');
         $sent->appendChild('<p>Another verification email was sent to <strong>' . phutil_escape_html($email_address) . '</strong>.</p>');
     }
     $error_view = new AphrontRequestFailureView();
     $error_view->setHeader('Check Your Email');
     $error_view->appendChild('<p>You must verify your email address to login. You should have a new ' . 'email message from Phabricator with verification instructions in your ' . 'inbox (<strong>' . phutil_escape_html($email_address) . '</strong>).</p>');
     $error_view->appendChild('<p>If you did not receive an email, you can click the button below ' . 'to try sending another one.</p>');
     $error_view->appendChild('<div class="aphront-failure-continue">' . phabricator_render_form($user, array('action' => '/login/mustverify/', 'method' => 'POST'), phutil_render_tag('button', array(), 'Send Another Email')) . '</div>');
     return $this->buildStandardPageResponse(array($sent, $error_view), array('title' => 'Must Verify Email'));
 }
 private function processDeleteRequest(PhabricatorUser $user)
 {
     $request = $this->getRequest();
     $admin = $request->getUser();
     if ($user->getPHID() == $admin->getPHID()) {
         $error = new AphrontErrorView();
         $error->setTitle('You Shall Journey No Farther');
         $error->appendChild('<p>As you stare into the gaping maw of the abyss, something holds ' . 'you back.</p>' . '<p>You can not delete your own account.</p>');
         return $error;
     }
     $e_username = true;
     $username = null;
     $errors = array();
     if ($request->isFormPost()) {
         $username = $request->getStr('username');
         if (!strlen($username)) {
             $e_username = '******';
             $errors[] = 'You must type the username to confirm deletion.';
         } else {
             if ($username != $user->getUsername()) {
                 $e_username = '******';
                 $errors[] = 'You must type the username correctly.';
             }
         }
         if (!$errors) {
             id(new PhabricatorUserEditor())->setActor($admin)->deleteUser($user);
             return id(new AphrontRedirectResponse())->setURI('/people/');
         }
     }
     if ($errors) {
         $errors = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     } else {
         $errors = null;
     }
     $form = new AphrontFormView();
     $form->setUser($admin)->setAction($request->getRequestURI())->appendChild('<p class="aphront-form-instructions">' . '<strong>Be careful when deleting users!</strong> ' . 'If this user interacted with anything, it is generally better ' . 'to disable them, not delete them. If you delete them, it will ' . 'no longer be possible to search for their objects, for example, ' . 'and you will lose other information about their history. Disabling ' . 'them instead will prevent them from logging in but not destroy ' . 'any of their data.' . '</p>' . '<p class="aphront-form-instructions">' . 'It is generally safe to delete newly created users (and test users ' . 'and so on), but less safe to delete established users. If ' . 'possible, disable them instead.' . '</p>')->appendChild(id(new AphrontFormStaticControl())->setLabel('Username')->setValue($user->getUsername()))->appendChild(id(new AphrontFormTextControl())->setLabel('Confirm')->setValue($username)->setName('username')->setCaption("Type the username again to confirm deletion.")->setError($e_username))->appendChild(id(new AphrontFormSubmitControl())->setValue('Delete User'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Delete User');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     return array($errors, $panel);
 }
 public function processRequest()
 {
     $drequest = $this->getDiffusionRequest();
     $request = $this->getRequest();
     $user = $request->getUser();
     $callsign = $drequest->getRepository()->getCallsign();
     $content = array();
     $content[] = $this->buildCrumbs(array('commit' => true));
     $detail_panel = new AphrontPanelView();
     $repository = $drequest->getRepository();
     $commit = $drequest->loadCommit();
     if (!$commit) {
         // TODO: Make more user-friendly.
         throw new Exception('This commit has not parsed yet.');
     }
     $commit_data = $drequest->loadCommitData();
     $is_foreign = $commit_data->getCommitDetail('foreign-svn-stub');
     if ($is_foreign) {
         $subpath = $commit_data->getCommitDetail('svn-subpath');
         $error_panel = new AphrontErrorView();
         $error_panel->setWidth(AphrontErrorView::WIDTH_WIDE);
         $error_panel->setTitle('Commit Not Tracked');
         $error_panel->setSeverity(AphrontErrorView::SEVERITY_WARNING);
         $error_panel->appendChild("This Diffusion repository is configured to track only one " . "subdirectory of the entire Subversion repository, and this commit " . "didn't affect the tracked subdirectory ('" . phutil_escape_html($subpath) . "'), so no information is available.");
         $content[] = $error_panel;
     } else {
         $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
         require_celerity_resource('diffusion-commit-view-css');
         require_celerity_resource('phabricator-remarkup-css');
         $property_table = $this->renderPropertyTable($commit, $commit_data);
         $detail_panel->appendChild('<div class="diffusion-commit-view">' . '<div class="diffusion-commit-dateline">' . 'r' . $callsign . $commit->getCommitIdentifier() . ' &middot; ' . phabricator_datetime($commit->getEpoch(), $user) . '</div>' . '<h1>Revision Detail</h1>' . '<div class="diffusion-commit-details">' . $property_table . '<hr />' . '<div class="diffusion-commit-message phabricator-remarkup">' . $engine->markupText($commit_data->getCommitMessage()) . '</div>' . '</div>' . '</div>');
         $content[] = $detail_panel;
     }
     $change_query = DiffusionPathChangeQuery::newFromDiffusionRequest($drequest);
     $changes = $change_query->loadChanges();
     $original_changes_count = count($changes);
     if ($request->getStr('show_all') !== 'true' && $original_changes_count > self::CHANGES_LIMIT) {
         $changes = array_slice($changes, 0, self::CHANGES_LIMIT);
     }
     $change_table = new DiffusionCommitChangeTableView();
     $change_table->setDiffusionRequest($drequest);
     $change_table->setPathChanges($changes);
     $count = count($changes);
     $bad_commit = null;
     if ($count == 0) {
         $bad_commit = queryfx_one(id(new PhabricatorRepository())->establishConnection('r'), 'SELECT * FROM %T WHERE fullCommitName = %s', PhabricatorRepository::TABLE_BADCOMMIT, 'r' . $callsign . $commit->getCommitIdentifier());
     }
     if ($bad_commit) {
         $error_panel = new AphrontErrorView();
         $error_panel->setWidth(AphrontErrorView::WIDTH_WIDE);
         $error_panel->setTitle('Bad Commit');
         $error_panel->appendChild(phutil_escape_html($bad_commit['description']));
         $content[] = $error_panel;
     } else {
         if ($is_foreign) {
             // Don't render anything else.
         } else {
             if (!count($changes)) {
                 $no_changes = new AphrontErrorView();
                 $no_changes->setWidth(AphrontErrorView::WIDTH_WIDE);
                 $no_changes->setSeverity(AphrontErrorView::SEVERITY_WARNING);
                 $no_changes->setTitle('Not Yet Parsed');
                 // TODO: This can also happen with weird SVN changes that don't do
                 // anything (or only alter properties?), although the real no-changes case
                 // is extremely rare and might be impossible to produce organically. We
                 // should probably write some kind of "Nothing Happened!" change into the
                 // DB once we parse these changes so we can distinguish between
                 // "not parsed yet" and "no changes".
                 $no_changes->appendChild("This commit hasn't been fully parsed yet (or doesn't affect any " . "paths).");
                 $content[] = $no_changes;
             } else {
                 $change_panel = new AphrontPanelView();
                 $change_panel->setHeader("Changes (" . number_format($count) . ")");
                 if ($count !== $original_changes_count) {
                     $show_all_button = phutil_render_tag('a', array('class' => 'button green', 'href' => '?show_all=true'), phutil_escape_html('Show All Changes'));
                     $warning_view = id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_WARNING)->setTitle(sprintf("Showing only the first %d changes out of %s!", self::CHANGES_LIMIT, number_format($original_changes_count)));
                     $change_panel->appendChild($warning_view);
                     $change_panel->addButton($show_all_button);
                 }
                 $change_panel->appendChild($change_table);
                 $content[] = $change_panel;
                 $changesets = DiffusionPathChange::convertToDifferentialChangesets($changes);
                 $vcs = $repository->getVersionControlSystem();
                 switch ($vcs) {
                     case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
                         $vcs_supports_directory_changes = true;
                         break;
                     case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
                         $vcs_supports_directory_changes = false;
                         break;
                     default:
                         throw new Exception("Unknown VCS.");
                 }
                 $references = array();
                 foreach ($changesets as $key => $changeset) {
                     $file_type = $changeset->getFileType();
                     if ($file_type == DifferentialChangeType::FILE_DIRECTORY) {
                         if (!$vcs_supports_directory_changes) {
                             unset($changesets[$key]);
                             continue;
                         }
                     }
                     $branch = $drequest->getBranchURIComponent($drequest->getBranch());
                     $filename = $changeset->getFilename();
                     $commit = $drequest->getCommit();
                     $reference = "{$branch}{$filename};{$commit}";
                     $references[$key] = $reference;
                 }
                 $change_list = new DifferentialChangesetListView();
                 $change_list->setChangesets($changesets);
                 $change_list->setRenderingReferences($references);
                 $change_list->setRenderURI('/diffusion/' . $callsign . '/diff/');
                 // TODO: This is pretty awkward, unify the CSS between Diffusion and
                 // Differential better.
                 require_celerity_resource('differential-core-view-css');
                 $change_list = '<div class="differential-primary-pane">' . $change_list->render() . '</div>';
                 $content[] = $change_list;
             }
         }
     }
     return $this->buildStandardPageResponse($content, array('title' => 'Diffusion'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $slug = PhrictionDocument::normalizeSlug($this->slug);
     if ($slug != $this->slug) {
         $uri = PhrictionDocument::getSlugURI($slug);
         // Canonicalize pages to their one true URI.
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     require_celerity_resource('phriction-document-css');
     $document = id(new PhrictionDocument())->loadOneWhere('slug = %s', $slug);
     $breadcrumbs = $this->renderBreadcrumbs($slug);
     $version_note = null;
     if (!$document) {
         $create_uri = '/phriction/edit/?slug=' . $slug;
         $page_content = '<div class="phriction-content">' . '<em>No content here!</em><br />' . 'No document found at <tt>' . phutil_escape_html($slug) . '</tt>. ' . 'You can <strong>' . phutil_render_tag('a', array('href' => $create_uri), 'create a new document') . '</strong>.' . '</div>';
         $page_title = 'Page Not Found';
         $button = phutil_render_tag('a', array('href' => $create_uri, 'class' => 'green button'), 'Create Page');
         $buttons = $button;
     } else {
         $version = $request->getInt('v');
         if ($version) {
             $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $version);
             if (!$content) {
                 return new Aphront404Response();
             }
             if ($content->getID() != $document->getContentID()) {
                 $version_note = new AphrontErrorView();
                 $version_note->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
                 $version_note->setTitle('Older Version');
                 $version_note->appendChild('You are viewing an older version of this document, as it ' . 'appeared on ' . phabricator_datetime($content->getDateCreated(), $user) . '.');
             }
         } else {
             $content = id(new PhrictionContent())->load($document->getContentID());
         }
         $page_title = $content->getTitle();
         $project_phid = null;
         if (PhrictionDocument::isProjectSlug($slug)) {
             $project = id(new PhabricatorProject())->loadOneWhere('phrictionSlug = %s', PhrictionDocument::getProjectSlugIdentifier($slug));
             $project_phid = $project->getPHID();
         }
         $phids = array_filter(array($content->getAuthorPHID(), $project_phid));
         $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
         $age = time() - $content->getDateCreated();
         $age = floor($age / (60 * 60 * 24));
         if ($age < 1) {
             $when = 'today';
         } else {
             if ($age == 1) {
                 $when = 'yesterday';
             } else {
                 $when = "{$age} days ago";
             }
         }
         $project_info = null;
         if ($project_phid) {
             $project_info = '<br />This document is about the project ' . $handles[$project_phid]->renderLink() . '.';
         }
         $byline = '<div class="phriction-byline">' . "Last updated {$when} by " . $handles[$content->getAuthorPHID()]->renderLink() . '.' . $project_info . '</div>';
         $doc_status = $document->getStatus();
         if ($doc_status == PhrictionDocumentStatus::STATUS_EXISTS) {
             $core_content = $content->renderContent();
         } else {
             if ($doc_status == PhrictionDocumentStatus::STATUS_DELETED) {
                 $notice = new AphrontErrorView();
                 $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
                 $notice->setTitle('Document Deleted');
                 $notice->appendChild('This document has been deleted. You can edit it to put new content ' . 'here, or use history to revert to an earlier version.');
                 $core_content = $notice->render();
             } else {
                 throw new Exception("Unknown document status '{$doc_status}'!");
             }
         }
         $page_content = '<div class="phriction-content">' . $byline . $core_content . '</div>';
         $edit_button = phutil_render_tag('a', array('href' => '/phriction/edit/' . $document->getID() . '/', 'class' => 'button'), 'Edit Document');
         $history_button = phutil_render_tag('a', array('href' => PhrictionDocument::getSlugURI($slug, 'history'), 'class' => 'button grey'), 'View History');
         // these float right so history_button which is right most goes first
         $buttons = $history_button . $edit_button;
     }
     if ($version_note) {
         $version_note = $version_note->render();
     }
     $children = $this->renderChildren($slug);
     $page = '<div class="phriction-header">' . $buttons . '<h1>' . phutil_escape_html($page_title) . '</h1>' . $breadcrumbs . '</div>' . $version_note . $page_content . $children;
     return $this->buildStandardPageResponse($page, array('title' => 'Phriction - ' . $page_title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($this->id) {
         $document = id(new PhrictionDocument())->load($this->id);
         if (!$document) {
             return new Aphront404Response();
         }
         $revert = $request->getInt('revert');
         if ($revert) {
             $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $revert);
             if (!$content) {
                 return new Aphront404Response();
             }
         } else {
             $content = id(new PhrictionContent())->load($document->getContentID());
         }
     } else {
         $slug = $request->getStr('slug');
         $slug = PhabricatorSlug::normalize($slug);
         if (!$slug) {
             return new Aphront404Response();
         }
         $document = id(new PhrictionDocument())->loadOneWhere('slug = %s', $slug);
         if ($document) {
             $content = id(new PhrictionContent())->load($document->getContentID());
         } else {
             $document = new PhrictionDocument();
             $document->setSlug($slug);
             $content = new PhrictionContent();
             $content->setSlug($slug);
             $default_title = PhabricatorSlug::getDefaultTitle($slug);
             $content->setTitle($default_title);
         }
     }
     if ($request->getBool('nodraft')) {
         $draft = null;
         $draft_key = null;
     } else {
         if ($document->getPHID()) {
             $draft_key = $document->getPHID() . ':' . $content->getVersion();
         } else {
             $draft_key = 'phriction:' . $content->getSlug();
         }
         $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $user->getPHID(), $draft_key);
     }
     require_celerity_resource('phriction-document-css');
     $e_title = true;
     $errors = array();
     if ($request->isFormPost()) {
         $title = $request->getStr('title');
         if (!strlen($title)) {
             $e_title = 'Required';
             $errors[] = 'Document title is required.';
         } else {
             $e_title = null;
         }
         if (!count($errors)) {
             $editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug()))->setUser($user)->setTitle($title)->setContent($request->getStr('content'))->setDescription($request->getStr('description'));
             $editor->save();
             if ($draft) {
                 $draft->delete();
             }
             $uri = PhrictionDocument::getSlugURI($document->getSlug());
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     if ($document->getID()) {
         $panel_header = 'Edit Phriction Document';
         $submit_button = 'Save Changes';
         $delete_button = phutil_render_tag('a', array('href' => '/phriction/delete/' . $document->getID() . '/', 'class' => 'grey button'), 'Delete Document');
     } else {
         $panel_header = 'Create New Phriction Document';
         $submit_button = 'Create Document';
         $delete_button = null;
     }
     $uri = $document->getSlug();
     $uri = PhrictionDocument::getSlugURI($uri);
     $uri = PhabricatorEnv::getProductionURI($uri);
     $remarkup_reference = phutil_render_tag('a', array('href' => PhabricatorEnv::getDoclink('article/Remarkup_Reference.html'), 'tabindex' => '-1', 'target' => '_blank'), 'Formatting Reference');
     $cancel_uri = PhrictionDocument::getSlugURI($document->getSlug());
     if ($draft && strlen($draft->getDraft()) && $draft->getDraft() != $content->getContent()) {
         $content_text = $draft->getDraft();
         $discard = phutil_render_tag('a', array('href' => $request->getRequestURI()->alter('nodraft', true)), 'discard this draft');
         $draft_note = new AphrontErrorView();
         $draft_note->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
         $draft_note->setTitle('Recovered Draft');
         $draft_note->appendChild('<p>Showing a saved draft of your edits, you can ' . $discard . '.</p>');
     } else {
         $content_text = $content->getContent();
         $draft_note = null;
     }
     $form = id(new AphrontFormView())->setUser($user)->setAction($request->getRequestURI()->getPath())->addHiddenInput('slug', $document->getSlug())->addHiddenInput('nodraft', $request->getBool('nodraft'))->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setValue($content->getTitle())->setError($e_title)->setName('title'))->appendChild(id(new AphrontFormStaticControl())->setLabel('URI')->setValue($uri))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Content')->setValue($content_text)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setName('content')->setID('document-textarea')->setEnableDragAndDropFileUploads(true)->setCaption($remarkup_reference))->appendChild(id(new AphrontFormTextControl())->setLabel('Edit Notes')->setValue($content->getDescription())->setError(null)->setName('description'))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button));
     $panel = id(new AphrontPanelView())->setWidth(AphrontPanelView::WIDTH_WIDE)->setHeader($panel_header)->appendChild($form);
     if ($delete_button) {
         $panel->addButton($delete_button);
     }
     $preview_panel = '<div class="aphront-panel-preview aphront-panel-preview-wide">
     <div class="phriction-document-preview-header">
       Document Preview
     </div>
     <div id="document-preview">
       <div class="aphront-panel-preview-loading-text">
         Loading preview...
       </div>
     </div>
   </div>';
     Javelin::initBehavior('phriction-document-preview', array('preview' => 'document-preview', 'textarea' => 'document-textarea', 'uri' => '/phriction/preview/?draftkey=' . $draft_key));
     return $this->buildStandardPageResponse(array($draft_note, $error_view, $panel, $preview_panel), array('title' => 'Edit Document'));
 }