public function processRequest()
 {
     if ($this->id) {
         $macro = id(new PhabricatorFileImageMacro())->load($this->id);
         if (!$macro) {
             return new Aphront404Response();
         }
     } else {
         $macro = new PhabricatorFileImageMacro();
     }
     $errors = array();
     $e_name = true;
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $macro->setName($request->getStr('name'));
         if (!strlen($macro->getName())) {
             $errors[] = 'Macro name is required.';
             $e_name = 'Required';
         } else {
             if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) {
                 $errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.';
                 $e_name = 'Invalid';
             } else {
                 $e_name = null;
             }
         }
         if (!$errors) {
             $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
             $macro->setFilePHID($file->getPHID());
             try {
                 $macro->save();
                 return id(new AphrontRedirectResponse())->setURI('/file/macro/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $errors[] = 'Macro name is not unique!';
                 $e_name = 'Duplicate';
             }
         }
     }
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     } else {
         $error_view = null;
     }
     $form = new AphrontFormView();
     $form->setAction('/file/macro/edit/');
     $form->setUser($request->getUser());
     $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/'));
     $panel = new AphrontPanelView();
     if ($macro->getID()) {
         $panel->setHeader('Edit Image Macro');
     } else {
         $panel->setHeader('Create Image Macro');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Image Macro'));
 }
 public function processRequest()
 {
     $event = id(new PhabricatorTimelineEvent('NULL'))->load($this->id);
     if (!$event) {
         return new Aphront404Response();
     }
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($event->getDataID()) {
         $data = id(new PhabricatorTimelineEventData())->load($event->getDataID());
     }
     if ($data) {
         $data = json_encode($data->getEventData());
     } else {
         $data = 'null';
     }
     $form = new AphrontFormView();
     $form->setUser($user)->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue($event->getID()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Type')->setValue($event->getType()))->appendChild(id(new AphrontFormTextAreaControl())->setDisabled(true)->setLabel('Data')->setValue($data))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/daemon/timeline/'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Event');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('timeline');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'Timeline Event'));
 }
 public function processRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $ldap_info = id(new PhabricatorUserLDAPInfo())->loadOneWhere('userID = %d', $user->getID());
     $forms = array();
     if (!$ldap_info) {
         $unlink = 'Link LDAP Account';
         $unlink_form = new AphrontFormView();
         $unlink_form->setUser($user)->setAction('/ldap/login/')->appendChild('<p class="aphront-form-instructions">There is currently no ' . 'LDAP account linked to your Phabricator account. You can link an ' . 'account, which will allow you to use it to log into Phabricator</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('LDAP username')->setName('username'))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Password')->setName('password'))->appendChild(id(new AphrontFormSubmitControl())->setValue("Link LDAP Account ยป"));
         $forms['Link Account'] = $unlink_form;
     } else {
         $unlink = 'Unlink LDAP Account';
         $unlink_form = new AphrontFormView();
         $unlink_form->setUser($user)->appendChild('<p class="aphront-form-instructions">You may unlink this account ' . 'from your LDAP account. This will prevent you from logging in with ' . 'your LDAP credentials.</p>')->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/ldap/unlink/', $unlink));
         $forms['Unlink Account'] = $unlink_form;
     }
     $panel = new AphrontPanelView();
     $panel->setHeader('LDAP Account Settings');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     foreach ($forms as $name => $form) {
         if ($name) {
             $panel->appendChild('<br /><h1>' . $name . '</h1><br />');
         }
         $panel->appendChild($form);
     }
     return array($panel);
 }
 private function buildChartForm()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $table = new PhabricatorFactRaw();
     $conn_r = $table->establishConnection('r');
     $table_name = $table->getTableName();
     $facts = queryfx_all($conn_r, 'SELECT DISTINCT factType from %T', $table_name);
     $specs = PhabricatorFactSpec::newSpecsForFactTypes(PhabricatorFactEngine::loadAllEngines(), ipull($facts, 'factType'));
     $options = array();
     foreach ($specs as $spec) {
         if ($spec->getUnit() == PhabricatorFactSpec::UNIT_COUNT) {
             $options[$spec->getType()] = $spec->getName();
         }
     }
     if (!$options) {
         return id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setTitle(pht('No Chartable Facts'))->appendChild('<p>' . pht('There are no facts that can be plotted yet.') . '</p>');
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormSelectControl())->setLabel('Y-Axis')->setName('y1')->setOptions($options))->appendChild(id(new AphrontFormSubmitControl())->setValue('Plot Chart'));
     $panel = new AphrontPanelView();
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Plot Chart');
     return $panel;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $parser = new ArcanistDiffParser();
         $diff = null;
         try {
             $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
         } catch (Exception $ex) {
             $diff = $request->getStr('diff');
         }
         $changes = $parser->parseDiff($diff);
         $diff = DifferentialDiff::newFromRawChanges($changes);
         $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
         $diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP);
         $diff->setAuthorPHID($request->getUser()->getPHID());
         $diff->setCreationMethod('web');
         $diff->save();
         return id(new AphrontRedirectResponse())->setURI('/differential/diff/' . $diff->getID() . '/');
     }
     $form = new AphrontFormView();
     $arcanist_href = PhabricatorEnv::getDoclink('article/Arcanist_User_Guide.html');
     $arcanist_link = phutil_render_tag('a', array('href' => $arcanist_href, 'target' => '_blank'), 'Arcanist');
     $form->setAction('/differential/diff/create/')->setEncType('multipart/form-data')->setUser($request->getUser())->appendChild('<p class="aphront-form-instructions">The best way to create a ' . "Differential diff is by using {$arcanist_link}, but you " . 'can also just paste a diff (e.g., from <tt>svn diff</tt> or ' . '<tt>git diff</tt>) into this box or upload it as a file if you ' . 'really want.</p>')->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Raw Diff')->setName('diff')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))->appendChild(id(new AphrontFormFileControl())->setLabel('Raw Diff from file')->setName('diff-file'))->appendChild(id(new AphrontFormSubmitControl())->setValue("Create Diff ยป"));
     $panel = new AphrontPanelView();
     $panel->setHeader('Create New Diff');
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse($panel, array('title' => 'Create Diff', 'tab' => 'create'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $receiver = PhabricatorMetaMTAReceivedMail::loadReceiverObject($request->getStr('obj'));
         if (!$receiver) {
             throw new Exception("No such task or revision!");
         }
         $hash = PhabricatorMetaMTAReceivedMail::computeMailHash($receiver->getMailKey(), $user->getPHID());
         $received = new PhabricatorMetaMTAReceivedMail();
         $received->setHeaders(array('to' => $request->getStr('obj') . '+' . $user->getID() . '+' . $hash . '@'));
         $received->setBodies(array('text' => $request->getStr('body')));
         $received->save();
         $received->processReceivedMail();
         $phid = $receiver->getPHID();
         $handles = $this->loadViewerHandles(array($phid));
         $uri = $handles[$phid]->getURI();
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     $form->setAction($this->getApplicationURI('/receive/'));
     $form->appendChild('<p class="aphront-form-instructions">This form will simulate ' . 'sending mail to an object.</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('To')->setName('obj')->setCaption('e.g. <tt>D1234</tt> or <tt>T1234</tt>'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Receive Mail'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Receive Email');
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('receive');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'Receive Test'));
 }
    public function processRequest()
    {
        $request = $this->getRequest();
        $user = $request->getUser();
        $preferences = $user->loadPreferences();
        if ($request->isFormPost()) {
            $monospaced = $request->getStr(PhabricatorUserPreferences::PREFERENCE_MONOSPACED);
            // Prevent the user from doing stupid things.
            $monospaced = preg_replace('/[^a-z0-9 ,"]+/i', '', $monospaced);
            $pref_dict = array(PhabricatorUserPreferences::PREFERENCE_TITLES => $request->getStr(PhabricatorUserPreferences::PREFERENCE_TITLES), PhabricatorUserPreferences::PREFERENCE_MONOSPACED => $monospaced);
            $preferences->setPreferences($pref_dict);
            $preferences->save();
            return id(new AphrontRedirectResponse())->setURI('/settings/page/preferences/?saved=true');
        }
        $example_string = <<<EXAMPLE
// This is what your monospaced font currently looks like.
function helloWorld() {
  alert("Hello world!");
}
EXAMPLE;
        $form = id(new AphrontFormView())->setUser($user)->setAction('/settings/page/preferences/')->appendChild(id(new AphrontFormSelectControl())->setLabel('Page Titles')->setName(PhabricatorUserPreferences::PREFERENCE_TITLES)->setValue($preferences->getPreference(PhabricatorUserPreferences::PREFERENCE_TITLES))->setOptions(array('glyph' => "In page titles, show Tool names as unicode glyphs: โš™", 'text' => 'In page titles, show Tool names as plain text: [Differential]')))->appendChild(id(new AphrontFormTextControl())->setLabel('Monospaced Font')->setName(PhabricatorUserPreferences::PREFERENCE_MONOSPACED)->setCaption('Overrides default fonts in tools like Differential. ' . '(Default: 10px "Menlo", "Consolas", "Monaco", ' . 'monospace)')->setValue($preferences->getPreference(PhabricatorUserPreferences::PREFERENCE_MONOSPACED)))->appendChild(id(new AphrontFormMarkupControl())->setValue('<pre class="PhabricatorMonospaced">' . phutil_escape_html($example_string) . '</pre>'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Preferences'));
        $panel = new AphrontPanelView();
        $panel->setWidth(AphrontPanelView::WIDTH_WIDE);
        $panel->setHeader('Phabricator Preferences');
        $panel->appendChild($form);
        $error_view = null;
        if ($request->getStr('saved') === 'true') {
            $error_view = id(new AphrontErrorView())->setTitle('Preferences Saved')->setSeverity(AphrontErrorView::SEVERITY_NOTICE)->setErrors(array('Your preferences have been saved.'));
        }
        return id(new AphrontNullView())->appendChild(array($error_view, $panel));
    }
 public function processRequest()
 {
     $method_groups = $this->getMethodFilters();
     $rows = array();
     foreach ($method_groups as $group => $methods) {
         foreach ($methods as $info) {
             switch ($info['status']) {
                 case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
                     $status = 'Deprecated';
                     break;
                 case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
                     $status = 'Unstable';
                     break;
                 default:
                     $status = null;
                     break;
             }
             $rows[] = array($group, phutil_render_tag('a', array('href' => '/conduit/method/' . $info['full_name']), phutil_escape_html($info['full_name'])), $info['description'], $status);
             $group = null;
         }
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Group', 'Name', 'Description', 'Status'));
     $table->setColumnClasses(array('pri', 'pri', 'wide', null));
     $panel = new AphrontPanelView();
     $panel->setHeader('Conduit Methods');
     $panel->appendChild($table);
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $utils = new AphrontPanelView();
     $utils->setHeader('Utilities');
     $utils->appendChild('<ul>' . '<li><a href="/conduit/log/">Log</a> - Conduit Method Calls</li>' . '<li><a href="/conduit/token/">Token</a> - Certificate Install</li>' . '</ul>');
     $utils->setWidth(AphrontPanelView::WIDTH_FULL);
     $this->setShowSideNav(false);
     return $this->buildStandardPageResponse(array($panel, $utils), array('title' => 'Conduit Console'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $source = $request->getStr('source');
         $future = xhpast_get_parser_future($source);
         $resolved = $future->resolve();
         // This is just to let it throw exceptions if stuff is broken.
         $parse_tree = XHPASTTree::newFromDataAndResolvedExecFuture($source, $resolved);
         list($err, $stdout, $stderr) = $resolved;
         $storage_tree = new PhabricatorXHPASTViewParseTree();
         $storage_tree->setInput($source);
         $storage_tree->setStdout($stdout);
         $storage_tree->setAuthorPHID($user->getPHID());
         $storage_tree->save();
         return id(new AphrontRedirectResponse())->setURI('/xhpast/view/' . $storage_tree->getID() . '/');
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Source')->setName('source')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))->appendChild(id(new AphrontFormSubmitControl())->setValue('Parse'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Generate XHP AST');
     $panel->setWidth(AphrontPanelView::WIDTH_WIDE);
     $panel->appendChild($form);
     return $this->buildStandardPageResponse($panel, array('title' => 'XHPAST View'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $content_type_map = HeraldContentTypeConfig::getContentTypeMap();
     if (empty($content_type_map[$this->contentType])) {
         $this->contentType = head_key($content_type_map);
     }
     $rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
     if (empty($rule_type_map[$this->ruleType])) {
         $this->ruleType = HeraldRuleTypeConfig::RULE_TYPE_PERSONAL;
     }
     // Reorder array to put "personal" first.
     $rule_type_map = array_select_keys($rule_type_map, array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL)) + $rule_type_map;
     $captions = array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL => 'Personal rules notify you about events. You own them, but they can ' . 'only affect you.', HeraldRuleTypeConfig::RULE_TYPE_GLOBAL => 'Global rules notify anyone about events. No one owns them, and ' . 'anyone can edit them. Usually, Global rules are used to notify ' . 'mailing lists.');
     $radio = id(new AphrontFormRadioButtonControl())->setLabel('Type')->setName('rule_type')->setValue($this->ruleType);
     foreach ($rule_type_map as $value => $name) {
         $radio->addButton($value, $name, idx($captions, $value));
     }
     $form = id(new AphrontFormView())->setUser($user)->setAction('/herald/rule/')->appendChild(id(new AphrontFormSelectControl())->setLabel('New rule for')->setName('content_type')->setValue($this->contentType)->setOptions($content_type_map))->appendChild($radio)->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Rule')->addCancelButton('/herald/view/' . $this->contentType . '/'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Create New Herald Rule');
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $panel->appendChild($form);
     $nav = $this->renderNav();
     $nav->selectFilter('new');
     $nav->appendChild($panel);
     return $this->buildStandardPageResponse($nav, array('title' => 'Create Herald Rule'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $phids = $request->getStrList('phids');
     if ($phids) {
         $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
         $rows = array();
         foreach ($handles as $handle) {
             if ($handle->getURI()) {
                 $link = phutil_render_tag('a', array('href' => $handle->getURI()), phutil_escape_html($handle->getURI()));
             } else {
                 $link = null;
             }
             $rows[] = array(phutil_escape_html($handle->getPHID()), phutil_escape_html($handle->getType()), phutil_escape_html($handle->getName()), $link);
         }
         $table = new AphrontTableView($rows);
         $table->setHeaders(array('PHID', 'Type', 'Name', 'URI'));
         $table->setColumnClasses(array(null, null, null, 'wide'));
         $panel = new AphrontPanelView();
         $panel->setHeader('PHID Handles');
         $panel->appendChild($table);
         return $this->buildStandardPageResponse($panel, array('title' => 'PHID Lookup Results'));
     }
     $lookup_form = new AphrontFormView();
     $lookup_form->setUser($request->getUser());
     $lookup_form->setAction('/phid/')->appendChild(id(new AphrontFormTextAreaControl())->setName('phids')->setCaption('Enter PHIDs separated by spaces or commas.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Lookup PHIDs'));
     $lookup_panel = new AphrontPanelView();
     $lookup_panel->setHeader('Lookup PHIDs');
     $lookup_panel->appendChild($lookup_form);
     $lookup_panel->setWidth(AphrontPanelView::WIDTH_WIDE);
     return $this->buildStandardPageResponse(array($lookup_panel), array('title' => 'PHID Lookup'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $log = id(new PhabricatorDaemonLog())->load($this->id);
     if (!$log) {
         return new Aphront404Response();
     }
     $events = id(new PhabricatorDaemonLogEvent())->loadAllWhere('logID = %d ORDER BY id DESC LIMIT 1000', $log->getID());
     $content = array();
     $argv = $log->getArgv();
     $argv = implode("\n", $argv);
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormStaticControl())->setLabel('Daemon')->setValue($log->getDaemon()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Host')->setValue($log->getHost()))->appendChild(id(new AphrontFormStaticControl())->setLabel('PID')->setValue($log->getPID()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Started')->setValue(phabricator_datetime($log->getDateCreated(), $user)))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Argv')->setValue($argv));
     $panel = new AphrontPanelView();
     $panel->setHeader('Daemon Details');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild($form);
     $content[] = $panel;
     $event_view = new PhabricatorDaemonLogEventsView();
     $event_view->setUser($user);
     $event_view->setEvents($events);
     $log_panel = new AphrontPanelView();
     $log_panel->setHeader('Daemon Logs');
     $log_panel->appendChild($event_view);
     $content[] = $log_panel;
     return $this->buildStandardPageResponse($content, array('title' => 'Daemon Log'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $project = id(new PhabricatorRepositoryArcanistProject())->load($this->id);
     if (!$project) {
         return new Aphront404Response();
     }
     $repositories = id(new PhabricatorRepository())->loadAll();
     $repos = array(0 => 'None');
     foreach ($repositories as $repository) {
         $callsign = $repository->getCallsign();
         $name = $repository->getname();
         $repos[$repository->getID()] = "r{$callsign} ({$name})";
     }
     if ($request->isFormPost()) {
         $repo_id = $request->getInt('repository', 0);
         if (isset($repos[$repo_id])) {
             $project->setRepositoryID($repo_id);
             $project->save();
             return id(new AphrontRedirectResponse())->setURI('/repository/');
         }
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setValue($project->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue($project->getPHID()))->appendChild(id(new AphrontFormSelectControl())->setLabel('Repository')->setOptions($repos)->setName('repository')->setValue($project->getRepositoryID()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/repository/')->setValue('Save'));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Edit Arcanist Project');
     $panel->appendChild($form);
     return $this->buildStandardPageResponse($panel, array('title' => 'Edit Project'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page'));
     $pastes = id(new PhabricatorPaste())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1);
     $pastes = $pager->sliceResults($pastes);
     $pager->setURI($request->getRequestURI(), 'page');
     $phids = mpull($pastes, 'getAuthorPHID');
     $handles = array();
     if ($phids) {
         $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     }
     $rows = array();
     foreach ($pastes as $paste) {
         $handle = $handles[$paste->getAuthorPHID()];
         $rows[] = array(phutil_escape_html('P' . $paste->getID()), phutil_render_tag('a', array('href' => '/p/' . $handle->getName() . '/'), phutil_escape_html($handle->getName())), phutil_escape_html($paste->getLanguage()), phutil_render_tag('a', array('href' => '/P' . $paste->getID()), phutil_escape_html(nonempty($paste->getTitle(), 'Untitled Masterwork P' . $paste->getID()))), phutil_render_tag('a', array('href' => PhabricatorFileURI::getViewURIForPHID($paste->getFilePHID())), phutil_escape_html($paste->getFilePHID())));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Paste ID', 'Author', 'Language', 'Title', 'File'));
     $table->setColumnClasses(array(null, null, null, 'wide pri', null));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $panel->setHeader("Paste");
     $panel->setCreateButton('Paste Something', '/paste/');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     return $this->buildStandardPageResponse($panel, array('title' => 'Paste List', 'tab' => 'list'));
 }
 public function processRequest()
 {
     $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();
     $project = new PhabricatorProject();
     $project->setAuthorPHID($user->getPHID());
     $profile = new PhabricatorProjectProfile();
     $e_name = true;
     $errors = array();
     if ($request->isFormPost()) {
         try {
             $editor = new PhabricatorProjectEditor($project);
             $editor->setUser($user);
             $editor->setName($request->getStr('name'));
             $editor->save();
         } catch (PhabricatorProjectNameCollisionException $ex) {
             $e_name = 'Not Unique';
             $errors[] = $ex->getMessage();
         }
         $project->setStatus(PhabricatorProjectStatus::ONGOING);
         $profile->setBlurb($request->getStr('blurb'));
         if (!$errors) {
             $project->save();
             $profile->setProjectPHID($project->getPHID());
             $profile->save();
             id(new PhabricatorProjectAffiliation())->setUserPHID($user->getPHID())->setProjectPHID($project->getPHID())->setRole('Owner')->setIsOwner(true)->save();
             if ($request->isAjax()) {
                 return id(new AphrontAjaxResponse())->setContent(array('phid' => $project->getPHID(), 'name' => $project->getName()));
             } else {
                 return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/');
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     }
     if ($request->isAjax()) {
         $form = new AphrontFormLayoutView();
     } else {
         $form = new AphrontFormView();
         $form->setUser($user);
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setValue($profile->getBlurb()));
     if ($request->isAjax()) {
         if ($error_view) {
             $error_view->setWidth(AphrontErrorView::WIDTH_DIALOG);
         }
         $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle('Create a New Project')->appendChild($error_view)->appendChild($form)->addSubmitButton('Create Project')->addCancelButton('/project/');
         return id(new AphrontDialogResponse())->setDialog($dialog);
     } else {
         $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Create')->addCancelButton('/project/'));
         $panel = new AphrontPanelView();
         $panel->setWidth(AphrontPanelView::WIDTH_FORM)->setHeader('Create a New Project')->appendChild($form);
         return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create new Project'));
     }
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $resource = new DrydockResource();
     $json = new PhutilJSON();
     $err_attributes = true;
     $err_capabilities = true;
     $json_attributes = $json->encodeFormatted($resource->getAttributes());
     $json_capabilities = $json->encodeFormatted($resource->getCapabilities());
     $errors = array();
     if ($request->isFormPost()) {
         $raw_attributes = $request->getStr('attributes');
         $attributes = json_decode($raw_attributes, true);
         if (!is_array($attributes)) {
             $err_attributes = 'Invalid';
             $errors[] = 'Enter attributes as a valid JSON object.';
             $json_attributes = $raw_attributes;
         } else {
             $resource->setAttributes($attributes);
             $json_attributes = $json->encodeFormatted($attributes);
             $err_attributes = null;
         }
         $raw_capabilities = $request->getStr('capabilities');
         $capabilities = json_decode($raw_capabilities, true);
         if (!is_array($capabilities)) {
             $err_capabilities = 'Invalid';
             $errors[] = 'Enter capabilities as a valid JSON object.';
             $json_capabilities = $raw_capabilities;
         } else {
             $resource->setCapabilities($capabilities);
             $json_capabilities = $json->encodeFormatted($capabilities);
             $err_capabilities = null;
         }
         $resource->setBlueprintClass($request->getStr('blueprint'));
         $resource->setType($resource->getBlueprint()->getType());
         $resource->setOwnerPHID($user->getPHID());
         $resource->setName($request->getStr('name'));
         if (!$errors) {
             $resource->save();
             return id(new AphrontRedirectResponse())->setURI('/drydock/resource/');
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     }
     $blueprints = id(new PhutilSymbolLoader())->setType('class')->setAncestorClass('DrydockBlueprint')->selectAndLoadSymbols();
     $blueprints = ipull($blueprints, 'name', 'name');
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Allocate Drydock Resource');
     $form = id(new AphrontFormView())->setUser($request->getUser())->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($resource->getName()))->appendChild(id(new AphrontFormSelectControl())->setLabel('Blueprint')->setOptions($blueprints)->setName('blueprint')->setValue($resource->getBlueprintClass()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Attributes')->setName('attributes')->setValue($json_attributes)->setError($err_attributes)->setCaption('Specify attributes in JSON.'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Capabilities')->setName('capabilities')->setValue($json_capabilities)->setError($err_capabilities)->setCaption('Specify capabilities in JSON.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Allocate Resource'));
     $panel->appendChild($form);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Allocate Resource'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $e_name = true;
     $e_callsign = true;
     $repository = new PhabricatorRepository();
     $type_map = PhabricatorRepositoryType::getAllRepositoryTypes();
     $errors = array();
     if ($request->isFormPost()) {
         $repository->setName($request->getStr('name'));
         $repository->setCallsign($request->getStr('callsign'));
         $repository->setVersionControlSystem($request->getStr('type'));
         if (!strlen($repository->getName())) {
             $e_name = 'Required';
             $errors[] = 'Repository name is required.';
         } else {
             $e_name = null;
         }
         if (!strlen($repository->getCallsign())) {
             $e_callsign = 'Required';
             $errors[] = 'Callsign is required.';
         } else {
             if (!preg_match('/^[A-Z]+$/', $repository->getCallsign())) {
                 $e_callsign = 'Invalid';
                 $errors[] = 'Callsign must be ALL UPPERCASE LETTERS.';
             } else {
                 $e_callsign = null;
             }
         }
         if (empty($type_map[$repository->getVersionControlSystem()])) {
             $errors[] = 'Invalid version control system.';
         }
         if (!$errors) {
             try {
                 $repository->save();
                 return id(new AphrontRedirectResponse())->setURI('/repository/edit/' . $repository->getID() . '/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $e_callsign = 'Duplicate';
                 $errors[] = 'Callsign must be unique. Another repository already ' . 'uses that callsign.';
             }
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setErrors($errors);
         $error_view->setTitle('Form Errors');
     }
     $form = new AphrontFormView();
     $form->setUser($user)->setAction('/repository/create/')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($repository->getName())->setError($e_name)->setCaption('Human-readable repository name.'))->appendChild('<p class="aphront-form-instructions">Select a "Callsign" &mdash; a ' . 'short, uppercase string to identify revisions in this repository. If ' . 'you choose "EX", revisions in this repository will be identified ' . 'with the prefix "rEX".</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('Callsign')->setName('callsign')->setValue($repository->getCallsign())->setError($e_callsign)->setCaption('Short, UPPERCASE identifier. Once set, it can not be changed.'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Type')->setName('type')->setOptions($type_map)->setValue($repository->getVersionControlSystem()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Repository')->addCancelButton('/repository/'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Create Repository');
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create Repository'));
 }
 public function processRequest()
 {
     if ($this->id) {
         $item = id(new PhabricatorDirectoryItem())->load($this->id);
         if (!$item) {
             return new Aphront404Response();
         }
     } else {
         $item = new PhabricatorDirectoryItem();
     }
     $e_name = true;
     $e_href = true;
     $errors = array();
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $item->setName($request->getStr('name'));
         $item->setHref($request->getStr('href'));
         $item->setDescription($request->getStr('description'));
         $item->setCategoryID($request->getStr('categoryID'));
         $item->setSequence($request->getStr('sequence'));
         if (!strlen($item->getName())) {
             $errors[] = 'Item name is required.';
             $e_name = 'Required';
         }
         if (!strlen($item->getHref())) {
             $errors[] = 'Item link is required.';
             $e_href = 'Required';
         }
         if (!$errors) {
             $item->save();
             return id(new AphrontRedirectResponse())->setURI('/directory/item/');
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     if ($item->getID()) {
         $form->setAction('/directory/item/edit/' . $item->getID() . '/');
     } else {
         $form->setAction('/directory/item/edit/');
     }
     $categories = id(new PhabricatorDirectoryCategory())->loadAll();
     $category_map = mpull($categories, 'getName', 'getID');
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($item->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Category')->setName('categoryID')->setOptions($category_map)->setValue($item->getCategoryID()))->appendChild(id(new AphrontFormTextControl())->setLabel('Link')->setName('href')->setValue($item->getHref())->setError($e_href))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Description')->setName('description')->setValue($item->getDescription()))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setCaption('Items in a category are sorted by "order", then by name.')->setValue((int) $item->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/item/'));
     $panel = new AphrontPanelView();
     if ($item->getID()) {
         $panel->setHeader('Edit Directory Item');
     } else {
         $panel->setHeader('Create New Directory Item');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Item'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if (!PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) {
         return new Aphront400Response();
     }
     $token = $this->token;
     $email = $request->getStr('email');
     $target_user = id(new PhabricatorUser())->loadOneWhere('email = %s', $email);
     if (!$target_user || !$target_user->validateEmailToken($token)) {
         $view = new AphrontRequestFailureView();
         $view->setHeader('Unable to Login');
         $view->appendChild('<p>The authentication information in the link you clicked is ' . 'invalid or out of date. Make sure you are copy-and-pasting the ' . 'entire link into your browser. You can try again, or request ' . 'a new email.</p>');
         $view->appendChild('<div class="aphront-failure-continue">' . '<a class="button" href="/login/email/">Send Another Email</a>' . '</div>');
         return $this->buildStandardPageResponse($view, array('title' => 'Email Sent'));
     }
     if ($request->getUser()->getPHID() != $target_user->getPHID()) {
         $session_key = $target_user->establishSession('web');
         $request->setCookie('phusr', $target_user->getUsername());
         $request->setCookie('phsid', $session_key);
     }
     $errors = array();
     $e_pass = true;
     $e_confirm = true;
     if ($request->isFormPost()) {
         $e_pass = '******';
         $e_confirm = 'Error';
         $pass = $request->getStr('password');
         $confirm = $request->getStr('confirm');
         if (strlen($pass) < 3) {
             $errors[] = 'That password is ridiculously short.';
         }
         if ($pass !== $confirm) {
             $errors[] = "Passwords do not match.";
         }
         if (!$errors) {
             $target_user->setPassword($pass);
             $target_user->save();
             return id(new AphrontRedirectResponse())->setURI('/');
         }
     }
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Password Reset Failed');
         $error_view->setErrors($errors);
     } else {
         $error_view = null;
     }
     $form = new AphrontFormView();
     $form->setUser($target_user)->setAction('/login/etoken/' . $token . '/')->addHiddenInput('email', $email)->appendChild(id(new AphrontFormPasswordControl())->setLabel('New Password')->setName('password')->setError($e_pass))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Confirm Password')->setName('confirm')->setError($e_confirm))->appendChild(id(new AphrontFormSubmitControl())->setValue('Reset Password')->addCancelButton('/', 'Skip'));
     $panel = new AphrontPanelView();
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->setHeader('Reset Password');
     $panel->appendChild($form);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create New Account'));
 }
 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();
     $user = $request->getUser();
     $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid);
     if (!$file) {
         return new Aphront404Response();
     }
     $author_child = null;
     if ($file->getAuthorPHID()) {
         $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $file->getAuthorPHID());
         if ($author) {
             $author_child = id(new AphrontFormStaticControl())->setLabel('Author')->setName('author')->setValue($author->getUserName());
         }
     }
     $form = new AphrontFormView();
     $submit = new AphrontFormSubmitControl();
     $form->setAction($file->getViewURI());
     if ($file->isViewableInBrowser()) {
         $submit->setValue('View File');
     } else {
         $submit->setValue('Download File');
     }
     if ($user->getPHID() == $file->getAuthorPHID() || $user->getIsAdmin()) {
         $submit->addCancelButton('/file/delete/' . $file->getID() . '/', 'Delete File');
     }
     $file_id = 'F' . $file->getID();
     $form->setUser($user);
     $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setName('name')->setValue($file->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setName('id')->setValue($file_id)->setCaption('Download this file with: <tt>arc download ' . phutil_escape_html($file_id) . '</tt>'))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setName('phid')->setValue($file->getPHID()))->appendChild($author_child)->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setName('created')->setValue(phabricator_datetime($file->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Mime Type')->setName('mime')->setValue($file->getMimeType()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Size')->setName('size')->setValue($file->getByteSize() . ' bytes'))->appendChild(id(new AphrontFormStaticControl())->setLabel('Engine')->setName('storageEngine')->setValue($file->getStorageEngine()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Format')->setName('storageFormat')->setValue($file->getStorageFormat()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Handle')->setName('storageHandle')->setValue($file->getStorageHandle()))->appendChild(id($submit));
     $panel = new AphrontPanelView();
     $panel->setHeader('File Info - ' . $file->getName());
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $xform_panel = null;
     $transformations = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID());
     if ($transformations) {
         $transformed_phids = mpull($transformations, 'getTransformedPHID');
         $transformed_files = id(new PhabricatorFile())->loadAllWhere('phid in (%Ls)', $transformed_phids);
         $transformed_map = mpull($transformed_files, null, 'getPHID');
         $rows = array();
         foreach ($transformations as $transformed) {
             $phid = $transformed->getTransformedPHID();
             $rows[] = array(phutil_escape_html($transformed->getTransform()), phutil_render_tag('a', array('href' => $transformed_map[$phid]->getBestURI()), $phid));
         }
         $table = new AphrontTableView($rows);
         $table->setHeaders(array('Transform', 'File'));
         $xform_panel = new AphrontPanelView();
         $xform_panel->appendChild($table);
         $xform_panel->setWidth(AphrontPanelView::WIDTH_FORM);
         $xform_panel->setHeader('Transformations');
     }
     return $this->buildStandardPageResponse(array($panel, $xform_panel), array('title' => 'File Info - ' . $file->getName()));
 }
 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();
     $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()
 {
     $user = $this->getRequest()->getUser();
     $old_token = id(new PhabricatorConduitCertificateToken())->loadOneWhere('userPHID = %s', $user->getPHID());
     if ($old_token) {
         $old_token->delete();
     }
     $token = id(new PhabricatorConduitCertificateToken())->setUserPHID($user->getPHID())->setToken(sha1(Filesystem::readRandomBytes(128)))->save();
     $panel = new AphrontPanelView();
     $panel->setHeader('Certificate Install Token');
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     $panel->appendChild('<p class="aphront-form-instructions">Copy and paste this token into ' . 'the prompt given to you by "arc install-certificate":</p>' . '<p style="padding: 0 0 1em 4em;">' . '<strong>' . phutil_escape_html($token->getToken()) . '</strong>' . '</p>' . '<p class="aphront-form-instructions">arc will then complete the ' . 'install process for you.</p>');
     return $this->buildStandardPageResponse($panel, array('title' => 'Certificate Install Token'));
 }
 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 processRequest()
 {
     if ($this->id) {
         $category = id(new PhabricatorDirectoryCategory())->load($this->id);
         if (!$category) {
             return new Aphront404Response();
         }
     } else {
         $category = new PhabricatorDirectoryCategory();
     }
     $e_name = true;
     $errors = array();
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $category->setName($request->getStr('name'));
         $category->setSequence($request->getStr('sequence'));
         if (!strlen($category->getName())) {
             $errors[] = 'Category name is required.';
             $e_name = 'Required';
         }
         if (!$errors) {
             $category->save();
             return id(new AphrontRedirectResponse())->setURI('/directory/category/');
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     if ($category->getID()) {
         $form->setAction('/directory/category/edit/' . $category->getID() . '/');
     } else {
         $form->setAction('/directory/category/edit/');
     }
     $categories = id(new PhabricatorDirectoryCategory())->loadAll();
     $category_map = mpull($categories, 'getName', 'getID');
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($category->getName())->setError($e_name))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setValue((int) $category->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/category/'));
     $panel = new AphrontPanelView();
     if ($category->getID()) {
         $panel->setHeader('Edit Directory Category');
     } else {
         $panel->setHeader('Create New Directory Category');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Category'));
 }
 public function processRequest()
 {
     if ($this->id) {
         $list = id(new PhabricatorMetaMTAMailingList())->load($this->id);
         if (!$list) {
             return new Aphront404Response();
         }
     } else {
         $list = new PhabricatorMetaMTAMailingList();
     }
     $e_email = true;
     $errors = array();
     $request = $this->getRequest();
     if ($request->isFormPost()) {
         $list->setName($request->getStr('name'));
         $list->setEmail($request->getStr('email'));
         $list->setURI($request->getStr('uri'));
         if (!strlen($list->getEmail())) {
             $e_email = 'Required';
             $errors[] = 'Email is required.';
         }
         if (!$errors) {
             $list->save();
             return id(new AphrontRedirectResponse())->setURI('/mail/lists/');
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     if ($list->getID()) {
         $form->setAction('/mail/lists/edit/' . $list->getID() . '/');
     } else {
         $form->setAction('/mail/lists/edit/');
     }
     $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($list->getEmail())->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel('URI')->setName('uri')->setValue($list->getURI()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue(nonempty($list->getID(), '-')))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue(nonempty($list->getPHID(), '-')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/mail/lists/'));
     $panel = new AphrontPanelView();
     if ($list->getID()) {
         $panel->setHeader('Edit Mailing List');
     } else {
         $panel->setHeader('Create New Mailing List');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Mailing List'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $map = HeraldContentTypeConfig::getContentTypeMap();
     if (empty($map[$this->type])) {
         reset($map);
         $this->type = key($map);
     }
     $form = id(new AphrontFormView())->setUser($user)->setAction('/herald/rule/')->appendChild(id(new AphrontFormSelectControl())->setLabel('New rule for')->setName('type')->setValue($this->type)->setOptions($map))->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Rule')->addCancelButton('/herald/view/' . $this->type . '/'));
     $panel = new AphrontPanelView();
     $panel->setHeader('Create New Herald Rule');
     $panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $panel->appendChild($form);
     return $this->buildStandardPageResponse($panel, array('title' => 'Create Herald Rule'));
 }
 private function renderUploadPanel()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     require_celerity_resource('files-css');
     $upload_id = celerity_generate_unique_node_id();
     $panel_id = celerity_generate_unique_node_id();
     $upload_panel = new AphrontPanelView();
     $upload_panel->setHeader('Upload Files');
     $upload_panel->setCreateButton('Basic Uploader', '/file/upload/');
     $upload_panel->setWidth(AphrontPanelView::WIDTH_FULL);
     $upload_panel->setID($panel_id);
     $upload_panel->appendChild(phutil_render_tag('div', array('id' => $upload_id, 'style' => 'display: none;', 'class' => 'files-drag-and-drop'), ''));
     Javelin::initBehavior('files-drag-and-drop', array('uri' => '/file/dropupload/', 'browseURI' => '/file/?author=' . $user->getUsername(), 'control' => $upload_id, 'target' => $panel_id, 'activatedClass' => 'aphront-panel-view-drag-and-drop'));
     return $upload_panel;
 }