public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $package = id(new PhabricatorOwnersPackage())->load($this->id); if (!$package) { return new Aphront404Response(); } $paths = $package->loadPaths(); $owners = $package->loadOwners(); $phids = array(); foreach ($paths as $path) { $phids[$path->getRepositoryPHID()] = true; } foreach ($owners as $owner) { $phids[$owner->getUserPHID()] = true; } $phids = array_keys($phids); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $rows = array(); $rows[] = array('Name', phutil_escape_html($package->getName())); $rows[] = array('Description', phutil_escape_html($package->getDescription())); $primary_owner = null; $primary_phid = $package->getPrimaryOwnerPHID(); if ($primary_phid && isset($handles[$primary_phid])) { $primary_owner = '<strong>' . $handles[$primary_phid]->renderLink() . '</strong>'; } $rows[] = array('Primary Owner', $primary_owner); $owner_links = array(); foreach ($owners as $owner) { $owner_links[] = $handles[$owner->getUserPHID()]->renderLink(); } $owner_links = implode('<br />', $owner_links); $rows[] = array('Owners', $owner_links); $rows[] = array('Auditing', $package->getAuditingEnabled() ? 'Enabled' : 'Disabled'); $rows[] = array('Related Commits', phutil_render_tag('a', array('href' => '/owners/related/view/all/?phid=' . $package->getPHID()), phutil_escape_html('Related Commits'))); $path_links = array(); foreach ($paths as $path) { $callsign = $handles[$path->getRepositoryPHID()]->getName(); $repo = phutil_escape_html('r' . $callsign); $path_link = phutil_render_tag('a', array('href' => '/diffusion/' . $callsign . '/browse/:' . $path->getPath()), phutil_escape_html($path->getPath())); $path_links[] = $repo . ' ' . $path_link; } $path_links = implode('<br />', $path_links); $rows[] = array('Paths', $path_links); $table = new AphrontTableView($rows); $table->setColumnClasses(array('header', 'wide')); $panel = new AphrontPanelView(); $panel->setHeader('Package Details for "' . phutil_escape_html($package->getName()) . '"'); $panel->addButton(javelin_render_tag('a', array('href' => '/owners/delete/' . $package->getID() . '/', 'class' => 'button grey', 'sigil' => 'workflow'), 'Delete Package')); $panel->addButton(phutil_render_tag('a', array('href' => '/owners/edit/' . $package->getID() . '/', 'class' => 'button'), 'Edit Package')); $panel->appendChild($table); $nav = new AphrontSideNavView(); $nav->appendChild($panel); $nav->addNavItem(phutil_render_tag('a', array('href' => '/owners/package/' . $package->getID() . '/', 'class' => 'aphront-side-nav-selected'), 'Package Details')); return $this->buildStandardPageResponse($nav, array('title' => "Package '" . $package->getName() . "'")); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $is_admin = $viewer->getIsAdmin(); $user = new PhabricatorUser(); $count = queryfx_one($user->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $user->getTableName()); $count = idx($count, 'N', 0); $pager = new AphrontPagerView(); $pager->setOffset($request->getInt('page', 0)); $pager->setCount($count); $pager->setURI($request->getRequestURI(), 'page'); $users = id(new PhabricatorPeopleQuery())->needPrimaryEmail(true)->executeWithOffsetPager($pager); $rows = array(); foreach ($users as $user) { $primary_email = $user->loadPrimaryEmail(); if ($primary_email && $primary_email->getIsVerified()) { $email = 'Verified'; } else { $email = 'Unverified'; } $status = array(); if ($user->getIsDisabled()) { $status[] = 'Disabled'; } if ($user->getIsAdmin()) { $status[] = 'Admin'; } if ($user->getIsSystemAgent()) { $status[] = 'System Agent'; } $status = implode(', ', $status); $rows[] = array(phabricator_date($user->getDateCreated(), $viewer), phabricator_time($user->getDateCreated(), $viewer), phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUserName())), phutil_escape_html($user->getRealName()), $status, $email, phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/people/edit/' . $user->getID() . '/'), 'Administrate User')); } $table = new AphrontTableView($rows); $table->setHeaders(array('Join Date', 'Time', 'Username', 'Real Name', 'Roles', 'Email', '')); $table->setColumnClasses(array(null, 'right', 'pri', 'wide', null, null, 'action')); $table->setColumnVisibility(array(true, true, true, true, $is_admin, $is_admin, $is_admin)); $panel = new AphrontPanelView(); $panel->setHeader('People (' . number_format($count) . ')'); $panel->appendChild($table); $panel->appendChild($pager); if ($is_admin) { $panel->addButton(phutil_render_tag('a', array('href' => '/people/edit/', 'class' => 'button green'), 'Create New Account')); if (PhabricatorEnv::getEnvConfig('ldap.auth-enabled')) { $panel->addButton(phutil_render_tag('a', array('href' => '/people/ldap/', 'class' => 'button green'), 'Import from LDAP')); } } $nav = $this->buildSideNavView(); $nav->selectFilter('people'); $nav->appendChild($panel); return $this->buildApplicationPage($nav, array('title' => 'People')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $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() { $request = $this->getRequest(); $user = $request->getUser(); $nav = $this->buildSideNav('resource'); $pager = new AphrontPagerView(); $pager->setURI(new PhutilURI('/drydock/resource/'), 'page'); $data = id(new DrydockResource())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize() + 1); $data = $pager->sliceResults($data); $phids = mpull($data, 'getOwnerPHID'); $handles = $this->loadViewerHandles($phids); $rows = array(); foreach ($data as $resource) { $rows[] = array($resource->getID(), $resource->getOwnerPHID() ? $handles[$resource->getOwnerPHID()]->renderLink() : null, phutil_escape_html($resource->getType()), DrydockResourceStatus::getNameForStatus($resource->getStatus()), phutil_escape_html(nonempty($resource->getName(), 'Unnamed')), phabricator_datetime($resource->getDateCreated(), $user)); } $table = new AphrontTableView($rows); $table->setHeaders(array('ID', 'Owner', 'Type', 'Status', 'Resource', 'Created')); $table->setColumnClasses(array('', '', '', '', 'pri wide', 'right')); $panel = new AphrontPanelView(); $panel->setHeader('Drydock Resources'); $panel->addButton(phutil_render_tag('a', array('href' => '/drydock/resource/allocate/', 'class' => 'green button'), 'Allocate Resource')); $panel->appendChild($table); $panel->appendChild($pager); $nav->appendChild($panel); return $this->buildStandardPageResponse($nav, array('title' => 'Resources')); }
public function processRequest() { $phid = $this->getAuthorizationPHID(); $title = 'Edit OAuth Client Authorization'; $request = $this->getRequest(); $current_user = $request->getUser(); $authorization = id(new PhabricatorOAuthClientAuthorization())->loadOneWhere('phid = %s', $phid); if (empty($authorization)) { return new Aphront404Response(); } if ($authorization->getUserPHID() != $current_user->getPHID()) { $message = 'Access denied to client authorization with phid ' . $phid . '. ' . 'Only the user who authorized the client has permission to ' . 'edit the authorization.'; return id(new Aphront403Response())->setForbiddenText($message); } if ($request->isFormPost()) { $scopes = PhabricatorOAuthServerScope::getScopesFromRequest($request); $authorization->setScope($scopes); $authorization->save(); return id(new AphrontRedirectResponse())->setURI('/oauthserver/clientauthorization/?edited=' . $phid); } $client_phid = $authorization->getClientPHID(); $client = id(new PhabricatorOAuthServerClient())->loadOneWhere('phid = %s', $client_phid); $created = phabricator_datetime($authorization->getDateCreated(), $current_user); $updated = phabricator_datetime($authorization->getDateModified(), $current_user); $panel = new AphrontPanelView(); $delete_button = phutil_render_tag('a', array('href' => $authorization->getDeleteURI(), 'class' => 'grey button'), 'Delete OAuth Client Authorization'); $panel->addButton($delete_button); $panel->setHeader($title); $form = id(new AphrontFormView())->setUser($current_user)->appendChild(id(new AphrontFormMarkupControl())->setLabel('Client')->setValue(phutil_render_tag('a', array('href' => $client->getViewURI()), phutil_escape_html($client->getName()))))->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setValue($created))->appendChild(id(new AphrontFormStaticControl())->setLabel('Last Updated')->setValue($updated))->appendChild(PhabricatorOAuthServerScope::getCheckboxControl($authorization->getScope()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save OAuth Client Authorization')->addCancelButton('/oauthserver/clientauthorization/')); $panel->appendChild($form); return $this->buildStandardPageResponse($panel, array('title' => $title)); }
public function processRequest() { $drequest = $this->diffusionRequest; $request = $this->getRequest(); $page_size = $request->getInt('pagesize', 100); $offset = $request->getInt('page', 0); $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest); $history_query->setOffset($offset); $history_query->setLimit($page_size + 1); if (!$request->getBool('copies')) { $history_query->needDirectChanges(true); $history_query->needChildChanges(true); } $history = $history_query->loadHistory(); $phids = array(); foreach ($history as $item) { $data = $item->getCommitData(); if ($data) { if ($data->getCommitDetail('authorPHID')) { $phids[$data->getCommitDetail('authorPHID')] = true; } } } $phids = array_keys($phids); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $pager = new AphrontPagerView(); $pager->setPageSize($page_size); $pager->setOffset($offset); if (count($history) == $page_size + 1) { array_pop($history); $pager->setHasMorePages(true); } else { $pager->setHasMorePages(false); } $pager->setURI($request->getRequestURI(), 'page'); $content = array(); $content[] = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history')); if ($request->getBool('copies')) { $button_title = 'Hide Copies/Branches'; } else { $button_title = 'Show Copies/Branches'; } $button_uri = $request->getRequestURI()->alter('copies', !$request->getBool('copies')); $button = phutil_render_tag('a', array('class' => 'button small grey', 'href' => $button_uri), phutil_escape_html($button_title)); $history_table = new DiffusionHistoryTableView(); $history_table->setDiffusionRequest($drequest); $history_table->setHandles($handles); $history_table->setHistory($history); $history_panel = new AphrontPanelView(); $history_panel->setHeader('History'); $history_panel->addButton($button); $history_panel->appendChild($history_table); $history_panel->appendChild($pager); $content[] = $history_panel; // TODO: Sometimes we do have a change view, we need to look at the most // recent history entry to figure it out. $nav = $this->buildSideNav('history', false); $nav->appendChild($content); return $this->buildStandardPageResponse($nav, array('title' => 'history')); }
public function processRequest() { $request = $this->getRequest(); $current_user = $request->getUser(); $error = null; $phid = $this->getClientPHID(); $client = id(new PhabricatorOAuthServerClient())->loadOneWhere('phid = %s', $phid); $title = 'View OAuth Client'; // validate the client if (empty($client)) { $message = 'No client found with id ' . $phid . '.'; return $this->buildStandardPageResponse($this->buildErrorView($message), array('title' => $title)); } $panel = new AphrontPanelView(); $panel->setHeader($title); $form = id(new AphrontFormView())->setUser($current_user)->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setValue($client->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue($phid)); if ($current_user->getPHID() == $client->getCreatorPHID()) { $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Secret')->setValue($client->getSecret())); } $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Redirect URI')->setValue($client->getRedirectURI())); $created = phabricator_datetime($client->getDateCreated(), $current_user); $updated = phabricator_datetime($client->getDateModified(), $current_user); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setValue($created))->appendChild(id(new AphrontFormStaticControl())->setLabel('Last Updated')->setValue($updated)); $panel->appendChild($form); $admin_panel = null; if ($client->getCreatorPHID() == $current_user->getPHID()) { $edit_button = phutil_render_tag('a', array('href' => $client->getEditURI(), 'class' => 'grey button'), 'Edit OAuth Client'); $panel->addButton($edit_button); $create_authorization_form = id(new AphrontFormView())->setUser($current_user)->addHiddenInput('action', 'testclientauthorization')->addHiddenInput('client_phid', $phid)->setAction('/oauthserver/test/')->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Scopeless Test Authorization')); $admin_panel = id(new AphrontPanelView())->setHeader('Admin Tools')->appendChild($create_authorization_form); } return $this->buildStandardPageResponse(array($error, $panel, $admin_panel), array('title' => $title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $paste = id(new PhabricatorPasteQuery())->setViewer($user)->withPasteIDs(array($this->id))->executeOne(); if (!$paste) { return new Aphront404Response(); } $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $paste->getFilePHID()); if (!$file) { return new Aphront400Response(); } $corpus = $this->buildCorpus($paste, $file); $paste_panel = new AphrontPanelView(); $author_phid = $paste->getAuthorPHID(); $header = 'Viewing Paste ' . $paste->getID() . ' by ' . PhabricatorObjectHandleData::loadOneHandle($author_phid)->renderLink(); if (strlen($paste->getTitle())) { $header .= ' - ' . phutil_escape_html($paste->getTitle()); } $paste_panel->setHeader($header); $paste_panel->setWidth(AphrontPanelView::WIDTH_FULL); $paste_panel->addButton(phutil_render_tag('a', array('href' => '/paste/?fork=' . $paste->getID(), 'class' => 'green button'), 'Fork This')); $raw_uri = $file->getBestURI(); $paste_panel->addButton(phutil_render_tag('a', array('href' => $raw_uri, 'class' => 'button'), 'View Raw Text')); $paste_panel->appendChild($corpus); $forks_panel = null; $forks_of_this_paste = id(new PhabricatorPaste())->loadAllWhere('parentPHID = %s', $paste->getPHID()); if ($forks_of_this_paste) { $forks_panel = new AphrontPanelView(); $forks_panel->setHeader("Forks of this paste"); $forks = array(); foreach ($forks_of_this_paste as $fork) { $forks[] = array($fork->getID(), phutil_render_tag('a', array('href' => '/P' . $fork->getID()), phutil_escape_html($fork->getTitle()))); } $forks_table = new AphrontTableView($forks); $forks_table->setHeaders(array('Paste ID', 'Title')); $forks_table->setColumnClasses(array(null, 'wide pri')); $forks_panel->appendChild($forks_table); } return $this->buildStandardPageResponse(array($paste_panel, $forks_panel), array('title' => 'Paste: ' . nonempty($paste->getTitle(), 'P' . $paste->getID()), 'tab' => 'view')); }
public function render() { DarkConsoleXHProfPluginAPI::includeXHProfLib(); $GLOBALS['display_calls'] = true; $totals = array(); $flat = xhprof_compute_flat_info($this->profileData, $totals); unset($GLOBALS['display_calls']); $aggregated = array(); foreach ($flat as $call => $counters) { $parts = explode('@', $call, 2); $agg_call = reset($parts); if (empty($aggregated[$agg_call])) { $aggregated[$agg_call] = $counters; } else { foreach ($aggregated[$agg_call] as $key => $val) { if ($key != 'wt') { $aggregated[$agg_call][$key] += $counters[$key]; } } } } $flat = $aggregated; $flat = isort($flat, 'wt'); $flat = array_reverse($flat); $rows = array(); $rows[] = array('Total', number_format($totals['ct']), number_format($totals['wt']) . ' us', '100.0%', number_format($totals['wt']) . ' us', '100.0%'); if ($this->limit) { $flat = array_slice($flat, 0, $this->limit); } foreach ($flat as $call => $counters) { $rows[] = array($this->renderSymbolLink($call), number_format($counters['ct']), number_format($counters['wt']) . ' us', sprintf('%.1f%%', 100 * $counters['wt'] / $totals['wt']), number_format($counters['excl_wt']) . ' us', sprintf('%.1f%%', 100 * $counters['excl_wt'] / $totals['wt'])); } Javelin::initBehavior('phabricator-tooltips'); $table = new AphrontTableView($rows); $table->setHeaders(array('Symbol', 'Count', javelin_render_tag('span', array('sigil' => 'has-tooltip', 'meta' => array('tip' => 'Total wall time spent in this function and all of ' . 'its children (chilren are other functions it called ' . 'while executing).', 'size' => 200)), 'Wall Time (Inclusive)'), '%', javelin_render_tag('span', array('sigil' => 'has-tooltip', 'meta' => array('tip' => 'Wall time spent in this function, excluding time ' . 'spent in children (children are other functions it ' . 'called while executing).', 'size' => 200)), 'Wall Time (Exclusive)'), '%')); $table->setColumnClasses(array('wide pri', 'n', 'n', 'n', 'n', 'n')); $panel = new AphrontPanelView(); $panel->setHeader('XHProf Profile'); if ($this->file) { $panel->addButton(phutil_render_tag('a', array('href' => $this->file->getBestURI(), 'class' => 'green button'), 'Download .xhprof Profile')); } $panel->appendChild($table); return $panel->render(); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI('/notification/')); $nav->addFilter('all', 'All Notifications'); $nav->addFilter('unread', 'Unread Notifications'); $filter = $nav->selectFilter($this->filter, 'all'); $pager = new AphrontPagerView(); $pager->setURI($request->getRequestURI(), 'offset'); $pager->setOffset($request->getInt('offset')); $query = new PhabricatorNotificationQuery(); $query->setUserPHID($user->getPHID()); switch ($filter) { case 'unread': $query->withUnread(true); $header = pht('Unread Notifications'); $no_data = pht('You have no unread notifications.'); break; default: $header = pht('Notifications'); $no_data = pht('You have no notifications.'); break; } $notifications = $query->executeWithOffsetPager($pager); if ($notifications) { $builder = new PhabricatorNotificationBuilder($notifications); $view = $builder->buildView(); } else { $view = '<div class="phabricator-notification no-notifications">' . $no_data . '</div>'; } $view = array('<div class="phabricator-notification-list">', $view, '</div>'); $panel = new AphrontPanelView(); $panel->setHeader($header); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->addButton(javelin_render_tag('a', array('href' => '/notification/clear/', 'class' => 'button', 'sigil' => 'workflow'), 'Mark All Read')); $panel->appendChild($view); $panel->appendChild($pager); $nav->appendChild($panel); return $this->buildStandardPageResponse($nav, array('title' => 'Notifications')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $nav = $this->buildBaseSideNav(); $queries = id(new ManiphestSavedQuery())->loadAllWhere('userPHID = %s ORDER BY name ASC', $user->getPHID()); $default = null; if ($request->isFormPost()) { $new_default = null; foreach ($queries as $query) { if ($query->getID() == $request->getInt('default')) { $new_default = $query; } } if ($this->getDefaultQuery()) { $this->getDefaultQuery()->setIsDefault(0)->save(); } if ($new_default) { $new_default->setIsDefault(1)->save(); } return id(new AphrontRedirectResponse())->setURI('/maniphest/custom/'); } $rows = array(); foreach ($queries as $query) { if ($query->getIsDefault()) { $default = $query; } $rows[] = array(phutil_render_tag('input', array('type' => 'radio', 'name' => 'default', 'value' => $query->getID(), 'checked' => $query->getIsDefault() ? 'checked' : null)), phutil_render_tag('a', array('href' => '/maniphest/view/custom/?key=' . $query->getQueryKey()), phutil_escape_html($query->getName())), phutil_render_tag('a', array('href' => '/maniphest/custom/edit/' . $query->getID() . '/', 'class' => 'grey small button'), 'Edit'), javelin_render_tag('a', array('href' => '/maniphest/custom/delete/' . $query->getID() . '/', 'class' => 'grey small button', 'sigil' => 'workflow'), 'Delete')); } $rows[] = array(phutil_render_tag('input', array('type' => 'radio', 'name' => 'default', 'value' => 0, 'checked' => $default === null ? 'checked' : null)), '<em>No Default</em>', '', ''); $table = new AphrontTableView($rows); $table->setHeaders(array('Default', 'Name', 'Edit', 'Delete')); $table->setColumnClasses(array('radio', 'wide pri', 'action', 'action')); $panel = new AphrontPanelView(); $panel->setHeader('Saved Custom Queries'); $panel->addButton(phutil_render_tag('button', array(), 'Save Default Query')); $panel->appendChild($table); $form = phabricator_render_form($user, array('method' => 'POST', 'action' => $request->getRequestURI()), $panel->render()); $nav->selectFilter('saved', 'saved'); $nav->appendChild($form); return $this->buildStandardPageResponse($nav, array('title' => 'Saved Queries')); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $is_admin = $viewer->getIsAdmin(); $user = new PhabricatorUser(); $count = queryfx_one($user->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $user->getTableName()); $count = idx($count, 'N', 0); $pager = new AphrontPagerView(); $pager->setOffset($request->getInt('page', 0)); $pager->setCount($count); $pager->setURI($request->getRequestURI(), 'page'); $users = id(new PhabricatorUser())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize()); $rows = array(); foreach ($users as $user) { $status = ''; if ($user->getIsDisabled()) { $status = 'Disabled'; } else { if ($user->getIsAdmin()) { $status = 'Admin'; } else { $status = '-'; } } $rows[] = array(phabricator_date($user->getDateCreated(), $viewer), phabricator_time($user->getDateCreated(), $viewer), phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUserName())), phutil_escape_html($user->getRealName()), $status, phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/people/edit/' . $user->getID() . '/'), 'Administrate User')); } $table = new AphrontTableView($rows); $table->setHeaders(array('Join Date', 'Time', 'Username', 'Real Name', 'Status', '')); $table->setColumnClasses(array(null, 'right', 'pri', 'wide', null, 'action')); $table->setColumnVisibility(array(true, true, true, true, $is_admin, $is_admin)); $panel = new AphrontPanelView(); $panel->setHeader('People (' . number_format($count) . ')'); $panel->appendChild($table); $panel->appendChild($pager); if ($is_admin) { $panel->addButton(phutil_render_tag('a', array('href' => '/people/edit/', 'class' => 'button green'), 'Create New Account')); } return $this->buildStandardPageResponse($panel, array('title' => 'People', 'tab' => 'directory')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $e_phame_title = null; $e_title = null; $errors = array(); if ($this->isPostEdit()) { $posts = id(new PhamePostQuery())->withPHIDs(array($this->getPostPHID()))->execute(); $post = reset($posts); if (empty($post)) { return new Aphront404Response(); } if ($post->getBloggerPHID() != $user->getPHID()) { return new Aphront403Response(); } $post_noun = ucfirst($post->getHumanName()); $cancel_uri = $post->getViewURI($user->getUsername()); $submit_button = 'Save Changes'; $delete_button = javelin_render_tag('a', array('href' => $post->getDeleteURI(), 'class' => 'grey button', 'sigil' => 'workflow'), 'Delete ' . $post_noun); $page_title = 'Edit ' . $post_noun; } else { $post = id(new PhamePost())->setBloggerPHID($user->getPHID())->setVisibility(PhamePost::VISIBILITY_DRAFT); $cancel_uri = '/phame/draft/'; $submit_button = 'Create Draft'; $delete_button = null; $page_title = 'Create Draft'; } $this->setPost($post); $this->loadEdgesAndBlogs(); if ($request->isFormPost()) { $saved = true; $visibility = $request->getInt('visibility'); $comments = $request->getStr('comments_widget'); $data = array('comments_widget' => $comments); $phame_title = $request->getStr('phame_title'); $phame_title = PhabricatorSlug::normalize($phame_title); $title = $request->getStr('title'); $post->setTitle($title); $post->setPhameTitle($phame_title); $post->setBody($request->getStr('body')); $post->setVisibility($visibility); $post->setConfigData($data); // only publish once...! if ($visibility == PhamePost::VISIBILITY_PUBLISHED) { if (!$post->getDatePublished()) { $post->setDatePublished(time()); } // this is basically a cast of null to 0 if its a new post } else { if (!$post->getDatePublished()) { $post->setDatePublished(0); } } if ($phame_title == '/') { $errors[] = 'Phame title must be nonempty.'; $e_phame_title = 'Required'; } if (empty($title)) { $errors[] = 'Title must be nonempty.'; $e_title = 'Required'; } $blogs_published = array_keys($this->getPostBlogs()); $blogs_to_publish = array(); $blogs_to_depublish = array(); if ($visibility == PhamePost::VISIBILITY_PUBLISHED) { $blogs_arr = $request->getArr('blogs'); $blogs_to_publish = array_values($blogs_arr); $blogs_to_depublish = array_diff($blogs_published, $blogs_to_publish); } else { $blogs_to_depublish = $blogs_published; } if (empty($errors)) { try { $post->save(); $editor = new PhabricatorEdgeEditor(); $edge_type = PhabricatorEdgeConfig::TYPE_POST_HAS_BLOG; $editor->setUser($user); foreach ($blogs_to_publish as $phid) { $editor->addEdge($post->getPHID(), $edge_type, $phid); } foreach ($blogs_to_depublish as $phid) { $editor->removeEdge($post->getPHID(), $edge_type, $phid); } $editor->save(); } catch (AphrontQueryDuplicateKeyException $e) { $saved = false; $e_phame_title = 'Not Unique'; $errors[] = 'Another post already uses this slug. ' . 'Each post must have a unique slug.'; } } else { $saved = false; } if ($saved) { $uri = new PhutilURI($post->getViewURI($user->getUsername())); $uri->setQueryParam('saved', true); return id(new AphrontRedirectResponse())->setURI($uri); } } $panel = new AphrontPanelView(); $panel->setHeader($page_title); $panel->setWidth(AphrontPanelView::WIDTH_FULL); if ($delete_button) { $panel->addButton($delete_button); } $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setName('title')->setValue($post->getTitle())->setID('post-title')->setError($e_title))->appendChild(id(new AphrontFormTextControl())->setLabel('Phame Title')->setName('phame_title')->setValue(rtrim($post->getPhameTitle(), '/'))->setID('post-phame-title')->setCaption('Up to 64 alphanumeric characters ' . 'with underscores for spaces. ' . 'Formatting is enforced.')->setError($e_phame_title))->appendChild(id(new PhabricatorRemarkupControl())->setLabel('Body')->setName('body')->setValue($post->getBody())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setID('post-body'))->appendChild(id(new AphrontFormSelectControl())->setLabel('Visibility')->setName('visibility')->setValue($post->getVisibility())->setOptions(PhamePost::getVisibilityOptionsForSelect())->setID('post-visibility'))->appendChild($this->getBlogCheckboxControl($post))->appendChild(id(new AphrontFormSelectControl())->setLabel('Comments Widget')->setName('comments_widget')->setvalue($post->getCommentsWidget())->setOptions($post->getCommentsWidgetOptionsForSelect()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button)); $panel->appendChild($form); $preview_panel = '<div class="aphront-panel-preview "> <div class="phame-post-preview-header"> Post Preview </div> <div id="post-preview"> <div class="aphront-panel-preview-loading-text"> Loading preview... </div> </div> </div>'; Javelin::initBehavior('phame-post-preview', array('preview' => 'post-preview', 'body' => 'post-body', 'title' => 'post-title', 'phame_title' => 'post-phame-title', 'uri' => '/phame/post/preview/')); $visibility_data = array('select_id' => 'post-visibility', 'current' => $post->getVisibility(), 'published' => PhamePost::VISIBILITY_PUBLISHED, 'draft' => PhamePost::VISIBILITY_DRAFT, 'change_uri' => $post->getChangeVisibilityURI()); $blogs_data = array('checkbox_id' => 'post-blogs', 'have_published' => (bool) count($this->getPostBlogs())); Javelin::initBehavior('phame-post-blogs', array('blogs' => $blogs_data, 'visibility' => $visibility_data)); if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Errors saving post.')->setErrors($errors); } else { $error_view = null; } $this->setShowSideNav(true); return $this->buildStandardPageResponse(array($error_view, $panel, $preview_panel), array('title' => $page_title)); }
public function buildCommitPanel() { $request = $this->getRequest(); $user = $request->getUser(); $phids = array($user->getPHID()); $query = new PhabricatorAuditCommitQuery(); $query->withAuthorPHIDs($phids); $query->withStatus(PhabricatorAuditQuery::STATUS_OPEN); $query->needCommitData(true); $query->setLimit(10); $commits = $query->execute(); if (!$commits) { return $this->renderMinipanel('No Problem Commits', 'No one has raised concerns with your commits.'); } $view = new PhabricatorAuditCommitListView(); $view->setCommits($commits); $view->setUser($user); $phids = $view->getRequiredHandlePHIDs(); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $view->setHandles($handles); $panel = new AphrontPanelView(); $panel->setHeader('Problem Commits'); $panel->setCaption('Commits which auditors have raised concerns about.'); $panel->appendChild($view); $panel->addButton(phutil_render_tag('a', array('href' => '/audit/', 'class' => 'button grey'), "View Problem Commits ยป")); return $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() . ' · ' . 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() { $drequest = $this->diffusionRequest; $request = $this->getRequest(); $page_size = $request->getInt('pagesize', 100); $offset = $request->getInt('page', 0); $history_query = DiffusionHistoryQuery::newFromDiffusionRequest($drequest); $history_query->setOffset($offset); $history_query->setLimit($page_size + 1); if (!$request->getBool('copies')) { $history_query->needDirectChanges(true); $history_query->needChildChanges(true); } $show_graph = !strlen($drequest->getPath()); if ($show_graph) { $history_query->needParents(true); } $history = $history_query->loadHistory(); $pager = new AphrontPagerView(); $pager->setPageSize($page_size); $pager->setOffset($offset); if (count($history) == $page_size + 1) { array_pop($history); $pager->setHasMorePages(true); } else { $pager->setHasMorePages(false); } $pager->setURI($request->getRequestURI(), 'page'); $content = array(); $content[] = $this->buildCrumbs(array('branch' => true, 'path' => true, 'view' => 'history')); if ($request->getBool('copies')) { $button_title = 'Hide Copies/Branches'; $copies_new = null; } else { $button_title = 'Show Copies/Branches'; $copies_new = true; } $button = phutil_render_tag('a', array('class' => 'button small grey', 'href' => $request->getRequestURI()->alter('copies', $copies_new)), phutil_escape_html($button_title)); $history_table = new DiffusionHistoryTableView(); $history_table->setDiffusionRequest($drequest); $history_table->setHistory($history); $history_table->loadRevisions(); $phids = $history_table->getRequiredHandlePHIDs(); $handles = $this->loadViewerHandles($phids); $history_table->setHandles($handles); if ($show_graph) { $history_table->setParents($history_query->getParents()); $history_table->setIsHead($offset == 0); } $history_panel = new AphrontPanelView(); $history_panel->setHeader('History'); $history_panel->addButton($button); $history_panel->appendChild($history_table); $history_panel->appendChild($pager); $content[] = $history_panel; // TODO: Sometimes we do have a change view, we need to look at the most // recent history entry to figure it out. $nav = $this->buildSideNav('history', false); $nav->appendChild($content); return $this->buildStandardPageResponse($nav, array('title' => 'history')); }
private function buildBinaryCorpus($file_uri, $data) { $panel = new AphrontPanelView(); $panel->setHeader('Binary File'); $panel->addButton($this->renderEditButton()); $panel->appendChild('<p>' . 'This is a binary file. ' . 'It is ' . number_format(strlen($data)) . ' bytes in length.' . '</p>'); $panel->addButton(phutil_render_tag('a', array('href' => $file_uri, 'class' => 'button green'), 'Download Binary File...')); return $panel; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $package = id(new PhabricatorOwnersPackage())->load($this->id); if (!$package) { return new Aphront404Response(); } $this->package = $package; $paths = $package->loadPaths(); $owners = $package->loadOwners(); $repository_phids = array(); foreach ($paths as $path) { $repository_phids[$path->getRepositoryPHID()] = true; } if ($repository_phids) { $repositories = id(new PhabricatorRepository())->loadAllWhere('phid in (%Ls)', array_keys($repository_phids)); $repositories = mpull($repositories, null, 'getPHID'); } else { $repositories = array(); } $phids = array(); foreach ($owners as $owner) { $phids[$owner->getUserPHID()] = true; } $phids = array_keys($phids); $handles = $this->loadViewerHandles($phids); $rows = array(); $rows[] = array('Name', phutil_escape_html($package->getName())); $rows[] = array('Description', phutil_escape_html($package->getDescription())); $primary_owner = null; $primary_phid = $package->getPrimaryOwnerPHID(); if ($primary_phid && isset($handles[$primary_phid])) { $primary_owner = '<strong>' . $handles[$primary_phid]->renderLink() . '</strong>'; } $rows[] = array('Primary Owner', $primary_owner); $owner_links = array(); foreach ($owners as $owner) { $owner_links[] = $handles[$owner->getUserPHID()]->renderLink(); } $owner_links = implode('<br />', $owner_links); $rows[] = array('Owners', $owner_links); $rows[] = array('Auditing', $package->getAuditingEnabled() ? 'Enabled' : 'Disabled'); $path_links = array(); foreach ($paths as $path) { $repo = $repositories[$path->getRepositoryPHID()]; $href = DiffusionRequest::generateDiffusionURI(array('callsign' => $repo->getCallsign(), 'branch' => $repo->getDefaultBranch(), 'path' => $path->getPath(), 'action' => 'browse')); $repo_name = '<strong>' . phutil_escape_html($repo->getName()) . '</strong>'; $path_link = phutil_render_tag('a', array('href' => (string) $href), phutil_escape_html($path->getPath())); $path_links[] = $repo_name . ' ' . $path_link; } $path_links = implode('<br />', $path_links); $rows[] = array('Paths', $path_links); $table = new AphrontTableView($rows); $table->setColumnClasses(array('header', 'wide')); $panel = new AphrontPanelView(); $panel->setHeader('Package Details for "' . phutil_escape_html($package->getName()) . '"'); $panel->addButton(javelin_render_tag('a', array('href' => '/owners/delete/' . $package->getID() . '/', 'class' => 'button grey', 'sigil' => 'workflow'), 'Delete Package')); $panel->addButton(phutil_render_tag('a', array('href' => '/owners/edit/' . $package->getID() . '/', 'class' => 'button'), 'Edit Package')); $panel->appendChild($table); $key = 'package/' . $package->getID(); $this->setSideNavFilter($key); $commit_views = array(); $commit_uri = id(new PhutilURI('/audit/view/packagecommits/'))->setQueryParams(array('phid' => $package->getPHID())); $attention_query = id(new PhabricatorAuditCommitQuery())->withPackagePHIDs(array($package->getPHID()))->withStatus(PhabricatorAuditCommitQuery::STATUS_OPEN)->needCommitData(true)->needAudits(true)->setLimit(10); $attention_commits = $attention_query->execute(); if ($attention_commits) { $view = new PhabricatorAuditCommitListView(); $view->setUser($user); $view->setCommits($attention_commits); $commit_views[] = array('view' => $view, 'header' => 'Commits in this Package that Need Attention', 'button' => phutil_render_tag('a', array('href' => $commit_uri->alter('status', 'open'), 'class' => 'button grey'), 'View All Problem Commits')); } $all_query = id(new PhabricatorAuditCommitQuery())->withPackagePHIDs(array($package->getPHID()))->needCommitData(true)->needAudits(true)->setLimit(100); $all_commits = $all_query->execute(); $view = new PhabricatorAuditCommitListView(); $view->setUser($user); $view->setCommits($all_commits); $view->setNoDataString('No commits in this package.'); $commit_views[] = array('view' => $view, 'header' => 'Recent Commits in Package', 'button' => phutil_render_tag('a', array('href' => $commit_uri, 'class' => 'button grey'), 'View All Package Commits')); $phids = array(); foreach ($commit_views as $commit_view) { $phids[] = $commit_view['view']->getRequiredHandlePHIDs(); } $phids = array_mergev($phids); $handles = $this->loadViewerHandles($phids); $commit_panels = array(); foreach ($commit_views as $commit_view) { $commit_panel = new AphrontPanelView(); $commit_panel->setHeader(phutil_escape_html($commit_view['header'])); if (isset($commit_view['button'])) { $commit_panel->addButton($commit_view['button']); } $commit_view['view']->setHandles($handles); $commit_panel->appendChild($commit_view['view']); $commit_panels[] = $commit_panel; } return $this->buildStandardPageResponse(array($panel, $commit_panels), array('title' => "Package '" . $package->getName() . "'")); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $package = id(new PhabricatorOwnersPackage())->load($this->id); if (!$package) { return new Aphront404Response(); } $this->package = $package; $paths = $package->loadPaths(); $owners = $package->loadOwners(); $repository_phids = array(); foreach ($paths as $path) { $repository_phids[$path->getRepositoryPHID()] = true; } if ($repository_phids) { $repositories = id(new PhabricatorRepositoryQuery())->setViewer($user)->withPHIDs(array_keys($repository_phids))->execute(); $repositories = mpull($repositories, null, 'getPHID'); } else { $repositories = array(); } $phids = array(); foreach ($owners as $owner) { $phids[$owner->getUserPHID()] = true; } $phids = array_keys($phids); $handles = $this->loadViewerHandles($phids); $rows = array(); $rows[] = array(pht('Name'), $package->getName()); $rows[] = array(pht('Description'), $package->getDescription()); $primary_owner = null; $primary_phid = $package->getPrimaryOwnerPHID(); if ($primary_phid && isset($handles[$primary_phid])) { $primary_owner = phutil_tag('strong', array(), $handles[$primary_phid]->renderLink()); } $rows[] = array(pht('Primary Owner'), $primary_owner); $owner_links = array(); foreach ($owners as $owner) { $owner_links[] = $handles[$owner->getUserPHID()]->renderLink(); } $owner_links = phutil_implode_html(phutil_tag('br'), $owner_links); $rows[] = array(pht('Owners'), $owner_links); $rows[] = array(pht('Auditing'), $package->getAuditingEnabled() ? pht('Enabled') : pht('Disabled')); $path_links = array(); foreach ($paths as $path) { $repo = idx($repositories, $path->getRepositoryPHID()); if (!$repo) { continue; } $href = DiffusionRequest::generateDiffusionURI(array('callsign' => $repo->getCallsign(), 'branch' => $repo->getDefaultBranch(), 'path' => $path->getPath(), 'action' => 'browse')); $repo_name = phutil_tag('strong', array(), $repo->getName()); $path_link = phutil_tag('a', array('href' => (string) $href), $path->getPath()); $path_links[] = hsprintf('%s %s %s', $path->getExcluded() ? "โ" : '+', $repo_name, $path_link); } $path_links = phutil_implode_html(phutil_tag('br'), $path_links); $rows[] = array(pht('Paths'), $path_links); $table = new AphrontTableView($rows); $table->setColumnClasses(array('header', 'wide')); $panel = new AphrontPanelView(); $panel->setNoBackground(); $panel->setHeader(pht('Package Details for "%s"', $package->getName())); $panel->addButton(javelin_tag('a', array('href' => '/owners/delete/' . $package->getID() . '/', 'class' => 'button grey', 'sigil' => 'workflow'), pht('Delete Package'))); $panel->addButton(phutil_tag('a', array('href' => '/owners/edit/' . $package->getID() . '/', 'class' => 'button'), pht('Edit Package'))); $panel->appendChild($table); $key = 'package/' . $package->getID(); $this->setSideNavFilter($key); $commit_views = array(); $commit_uri = id(new PhutilURI('/audit/view/packagecommits/'))->setQueryParams(array('phid' => $package->getPHID())); $attention_commits = id(new DiffusionCommitQuery())->setViewer($request->getUser())->withAuditorPHIDs(array($package->getPHID()))->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN)->needCommitData(true)->setLimit(10)->execute(); if ($attention_commits) { $view = id(new PhabricatorAuditListView())->setUser($user)->setCommits($attention_commits); $commit_views[] = array('view' => $view, 'header' => pht('Commits in this Package that Need Attention'), 'button' => phutil_tag('a', array('href' => $commit_uri->alter('status', 'open'), 'class' => 'button grey'), pht('View All Problem Commits'))); } $all_commits = id(new DiffusionCommitQuery())->setViewer($request->getUser())->withAuditorPHIDs(array($package->getPHID()))->needCommitData(true)->setLimit(100)->execute(); $view = id(new PhabricatorAuditListView())->setUser($user)->setCommits($all_commits)->setNoDataString(pht('No commits in this package.')); $commit_views[] = array('view' => $view, 'header' => pht('Recent Commits in Package'), 'button' => phutil_tag('a', array('href' => $commit_uri, 'class' => 'button grey'), pht('View All Package Commits'))); $phids = array(); foreach ($commit_views as $commit_view) { $phids[] = $commit_view['view']->getRequiredHandlePHIDs(); } $phids = array_mergev($phids); $handles = $this->loadViewerHandles($phids); $commit_panels = array(); foreach ($commit_views as $commit_view) { $commit_panel = new AphrontPanelView(); $commit_panel->setNoBackground(); $commit_panel->setHeader($commit_view['header']); if (isset($commit_view['button'])) { $commit_panel->addButton($commit_view['button']); } $commit_view['view']->setHandles($handles); $commit_panel->appendChild($commit_view['view']); $commit_panels[] = $commit_panel; } $nav = $this->buildSideNavView(); $nav->appendChild($panel); $nav->appendChild($commit_panels); return $this->buildApplicationPage(array($nav), array('title' => pht('Package %s', $package->getName()))); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $e_name = null; $e_bloggers = null; $errors = array(); if ($this->isBlogEdit()) { $blogs = id(new PhameBlogQuery())->withPHIDs(array($this->getBlogPHID()))->execute(); $blog = reset($blogs); if (empty($blog)) { return new Aphront404Response(); } $bloggers = $blog->loadBloggers()->getBloggers(); // TODO -- make this check use a policy if (!isset($bloggers[$user->getPHID()]) && !$user->isAdmin()) { return new Aphront403Response(); } $blogger_tokens = mpull($bloggers, 'getFullName', 'getPHID'); $submit_button = 'Save Changes'; $delete_button = javelin_render_tag('a', array('href' => $blog->getDeleteURI(), 'class' => 'grey button', 'sigil' => 'workflow'), 'Delete Blog'); $page_title = 'Edit Blog'; } else { $blog = id(new PhameBlog())->setCreatorPHID($user->getPHID()); $blogger_tokens = array($user->getPHID() => $user->getFullName()); $submit_button = 'Create Blog'; $delete_button = null; $page_title = 'Create Blog'; } if ($request->isFormPost()) { $saved = true; $name = $request->getStr('name'); $description = $request->getStr('description'); $blogger_arr = $request->getArr('bloggers'); if (empty($blogger_arr)) { $error = 'Bloggers must be nonempty.'; if ($this->isBlogEdit()) { $error .= ' To delete the blog, use the delete button.'; } else { $error .= ' A blog cannot exist without bloggers.'; } $e_bloggers = 'Required'; $errors[] = $error; } $new_bloggers = array_values($blogger_arr); if ($this->isBlogEdit()) { $old_bloggers = array_keys($blogger_tokens); } else { $old_bloggers = array(); } if (empty($name)) { $errors[] = 'Name must be nonempty.'; $e_name = 'Required'; } $blog->setName($name); $blog->setDescription($description); if (empty($errors)) { $blog->save(); $add_phids = $new_bloggers; $rem_phids = array_diff($old_bloggers, $new_bloggers); $editor = new PhabricatorEdgeEditor(); $edge_type = PhabricatorEdgeConfig::TYPE_BLOG_HAS_BLOGGER; $editor->setUser($user); foreach ($add_phids as $phid) { $editor->addEdge($blog->getPHID(), $edge_type, $phid); } foreach ($rem_phids as $phid) { $editor->removeEdge($blog->getPHID(), $edge_type, $phid); } $editor->save(); } else { $saved = false; } if ($saved) { $uri = new PhutilURI($blog->getViewURI()); $uri->setQueryParam('new', true); return id(new AphrontRedirectResponse())->setURI($uri); } } $panel = new AphrontPanelView(); $panel->setHeader($page_title); $panel->setWidth(AphrontPanelView::WIDTH_FULL); if ($delete_button) { $panel->addButton($delete_button); } $remarkup_reference = phutil_render_tag('a', array('href' => PhabricatorEnv::getDoclink('article/Remarkup_Reference.html'), 'tabindex' => '-1', 'target' => '_blank'), 'Formatting Reference'); $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($blog->getName())->setID('blog-name')->setError($e_name))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Description')->setName('description')->setValue($blog->getDescription())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setID('blog-description')->setCaption($remarkup_reference))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('Bloggers')->setName('bloggers')->setValue($blogger_tokens)->setUser($user)->setDatasource('/typeahead/common/users/')->setError($e_bloggers))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/phame/blog/')->setValue($submit_button)); $panel->appendChild($form); if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Errors saving blog.')->setErrors($errors); } else { $error_view = null; } $this->setShowSideNav(true); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => $page_title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $e_phame_title = null; $e_title = null; $errors = array(); if ($this->isPostEdit()) { $post = id(new PhamePost())->loadOneWhere('phid = %s', $this->getPostPHID()); if (empty($post)) { return new Aphront404Response(); } if ($post->getBloggerPHID() != $user->getPHID()) { return new Aphront403Response(); } $cancel_uri = $post->getViewURI($user->getUsername()); $submit_button = 'Save Changes'; $delete_button = javelin_render_tag('a', array('href' => $post->getDeleteURI(), 'class' => 'grey button', 'sigil' => 'workflow'), 'Delete Post'); $page_title = 'Edit Post'; } else { $post = id(new PhamePost())->setBloggerPHID($user->getPHID())->setVisibility(PhamePost::VISIBILITY_DRAFT); $cancel_uri = '/phame'; $submit_button = 'Create Post'; $delete_button = null; $page_title = 'Create Post'; } if ($request->isFormPost()) { $saved = true; $visibility = $request->getInt('visibility'); $comments = $request->getStr('comments_widget'); $data = array('comments_widget' => $comments); $phame_title = $request->getStr('phame_title'); $phame_title = PhabricatorSlug::normalize($phame_title); $title = $request->getStr('title'); $post->setTitle($title); $post->setPhameTitle($phame_title); $post->setBody($request->getStr('body')); $post->setVisibility($visibility); $post->setConfigData($data); // only publish once...! if ($visibility == PhamePost::VISIBILITY_PUBLISHED) { if (!$post->getDatePublished()) { $post->setDatePublished(time()); } // this is basically a cast of null to 0 if its a new post } else { if (!$post->getDatePublished()) { $post->setDatePublished(0); } } if ($phame_title == '/') { $errors[] = 'Phame title must be nonempty.'; $e_phame_title = 'Required'; } if (empty($title)) { $errors[] = 'Title must be nonempty.'; $e_title = 'Required'; } if (empty($errors)) { try { $post->save(); } catch (AphrontQueryDuplicateKeyException $e) { $saved = false; $e_phame_title = 'Not Unique'; $errors[] = 'Another post already uses this slug. ' . 'Each post must have a unique slug.'; } } else { $saved = false; } if ($saved) { $uri = new PhutilURI($post->getViewURI($user->getUsername())); return id(new AphrontRedirectResponse())->setURI($uri); } } $panel = new AphrontPanelView(); $panel->setHeader($page_title); $panel->setWidth(AphrontPanelView::WIDTH_FULL); if ($delete_button) { $panel->addButton($delete_button); } $remarkup_reference = phutil_render_tag('a', array('href' => PhabricatorEnv::getDoclink('article/Remarkup_Reference.html'), 'tabindex' => '-1', 'target' => '_blank'), 'Formatting Reference'); $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setName('title')->setValue($post->getTitle())->setID('post-title')->setError($e_title))->appendChild(id(new AphrontFormTextControl())->setLabel('Phame Title')->setName('phame_title')->setValue(rtrim($post->getPhameTitle(), '/'))->setID('post-phame-title')->setCaption('Up to 64 alphanumeric characters ' . 'with underscores for spaces. ' . 'Formatting is enforced.')->setError($e_phame_title))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body')->setValue($post->getBody())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setEnableDragAndDropFileUploads(true)->setID('post-body')->setCaption($remarkup_reference))->appendChild(id(new AphrontFormSelectControl())->setLabel('Visibility')->setName('visibility')->setValue($post->getVisibility())->setOptions(PhamePost::getVisibilityOptionsForSelect()))->appendChild(id(new AphrontFormSelectControl())->setLabel('Comments Widget')->setName('comments_widget')->setvalue($post->getCommentsWidget())->setOptions($post->getCommentsWidgetOptionsForSelect()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($submit_button)); $panel->appendChild($form); $preview_panel = '<div class="aphront-panel-preview "> <div class="phame-post-preview-header"> Post Preview </div> <div id="post-preview"> <div class="aphront-panel-preview-loading-text"> Loading preview... </div> </div> </div>'; Javelin::initBehavior('phame-post-preview', array('preview' => 'post-preview', 'body' => 'post-body', 'title' => 'post-title', 'phame_title' => 'post-phame-title', 'uri' => '/phame/post/preview/')); if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Errors saving post.')->setErrors($errors); } else { $error_view = null; } $this->setShowSideNav(true); return $this->buildStandardPageResponse(array($error_view, $panel, $preview_panel), array('title' => $page_title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $phids = $request->getArr('set_phid'); $phid = head($phids); $uri = $request->getRequestURI(); if ($phid) { $uri = $uri->alter('phid', nonempty($phid, null)); } return id(new AphrontRedirectResponse())->setURI($uri); } $query = new HeraldRuleQuery(); $content_type_map = HeraldContentTypeConfig::getContentTypeMap(); if (empty($content_type_map[$this->contentType])) { $this->contentType = head_key($content_type_map); } $content_desc = $content_type_map[$this->contentType]; $query->withContentTypes(array($this->contentType)); $is_admin_page = false; $show_author = false; $show_rule_type = false; $can_create = false; $has_author_filter = false; $author_filter_phid = null; switch ($this->ruleType) { case 'all': if (!$user->getIsAdmin()) { return new Aphront400Response(); } $is_admin_page = true; $show_rule_type = true; $show_author = true; $has_author_filter = true; $author_filter_phid = $request->getStr('phid'); if ($author_filter_phid) { $query->withAuthorPHIDs(array($author_filter_phid)); } $rule_desc = 'All'; break; case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: $query->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_GLOBAL)); $can_create = true; $rule_desc = 'Global'; break; case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: default: $this->ruleType = HeraldRuleTypeConfig::RULE_TYPE_PERSONAL; $query->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL)); $query->withAuthorPHIDs(array($user->getPHID())); $can_create = true; $rule_desc = 'Personal'; break; } $pager = new AphrontPagerView(); $pager->setURI($request->getRequestURI(), 'offset'); $pager->setOffset($request->getStr('offset')); $rules = $query->executeWithOffsetPager($pager); $need_phids = mpull($rules, 'getAuthorPHID'); $handles = $this->loadViewerHandles($need_phids); $list_view = id(new HeraldRuleListView())->setRules($rules)->setShowAuthor($show_author)->setShowRuleType($show_rule_type)->setHandles($handles)->setUser($user); $panel = new AphrontPanelView(); $panel->appendChild($list_view); $panel->appendChild($pager); $panel->setHeader("Herald: {$rule_desc} Rules for {$content_desc}"); if ($can_create) { $panel->addButton(phutil_render_tag('a', array('href' => '/herald/new/' . $this->contentType . '/' . $this->ruleType . '/', 'class' => 'green button'), 'Create New Herald Rule')); } $nav = $this->renderNav(); $nav->selectFilter('view/' . $this->contentType . '/' . $this->ruleType); if ($has_author_filter) { $nav->appendChild($this->renderAuthorFilter($author_filter_phid)); } $nav->appendChild($panel); return $this->buildStandardPageResponse($nav, array('title' => 'Herald', 'admin' => $is_admin_page)); }
public function processRequest() { $drequest = $this->getDiffusionRequest(); $request = $this->getRequest(); $user = $request->getUser(); if ($request->getStr('diff')) { return $this->buildRawDiffResponse($drequest); } $callsign = $drequest->getRepository()->getCallsign(); $content = array(); $content[] = $this->buildCrumbs(array('commit' => true)); $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(); $commit->attachCommitData($commit_data); $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'); $parent_query = DiffusionCommitParentsQuery::newFromDiffusionRequest($drequest); $headsup_panel = new AphrontHeadsupView(); $headsup_panel->setHeader('Commit Detail'); $headsup_panel->setActionList($this->renderHeadsupActionList($commit)); $headsup_panel->setProperties($this->getCommitProperties($commit, $commit_data, $parent_query->loadParents())); $headsup_panel->appendChild('<div class="diffusion-commit-message phabricator-remarkup">' . $engine->markupText($commit_data->getCommitMessage()) . '</div>'); $content[] = $headsup_panel; } $query = new PhabricatorAuditQuery(); $query->withCommitPHIDs(array($commit->getPHID())); $audit_requests = $query->execute(); $this->auditAuthorityPHIDs = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user); $content[] = $this->buildAuditTable($commit, $audit_requests); $content[] = $this->buildComments($commit); $change_query = DiffusionPathChangeQuery::newFromDiffusionRequest($drequest); $changes = $change_query->loadChanges(); $content[] = $this->buildMergesTable($commit); $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); } $owners_paths = array(); if ($this->highlightedAudits) { $packages = id(new PhabricatorOwnersPackage())->loadAllWhere('phid IN (%Ls)', mpull($this->highlightedAudits, 'getAuditorPHID')); if ($packages) { $owners_paths = id(new PhabricatorOwnersPath())->loadAllWhere('repositoryPHID = %s AND packageID IN (%Ld)', $repository->getPHID(), mpull($packages, 'getID')); } } $change_table = new DiffusionCommitChangeTableView(); $change_table->setDiffusionRequest($drequest); $change_table->setPathChanges($changes); $change_table->setOwnersPaths($owners_paths); $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()); } $pane_id = null; 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) . ")"); $change_panel->setID('differential-review-toc'); 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: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: $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; } } $references[$key] = $drequest->generateURI(array('action' => 'rendering-ref', 'path' => $changeset->getFilename())); } // TODO: Some parts of the views still rely on properties of the // DifferentialChangeset. Make the objects ephemeral to make sure we don't // accidentally save them, and then set their ID to the appropriate ID for // this application (the path IDs). $pquery = new DiffusionPathIDQuery(mpull($changesets, 'getFilename')); $path_ids = $pquery->loadPathIDs(); foreach ($changesets as $changeset) { $changeset->makeEphemeral(); $changeset->setID($path_ids[$changeset->getFilename()]); } $change_list = new DifferentialChangesetListView(); $change_list->setChangesets($changesets); $change_list->setVisibleChangesets($changesets); $change_list->setRenderingReferences($references); $change_list->setRenderURI('/diffusion/' . $callsign . '/diff/'); $change_list->setRepository($repository); $change_list->setUser($user); $change_list->setStandaloneURI('/diffusion/' . $callsign . '/diff/'); $change_list->setRawFileURIs(null, '/diffusion/' . $callsign . '/diff/?view=r'); $change_list->setInlineCommentControllerURI('/diffusion/inline/edit/' . phutil_escape_uri($commit->getPHID()) . '/'); // TODO: This is pretty awkward, unify the CSS between Diffusion and // Differential better. require_celerity_resource('differential-core-view-css'); $pane_id = celerity_generate_unique_node_id(); $add_comment_view = $this->renderAddCommentPanel($commit, $audit_requests, $pane_id); $main_pane = phutil_render_tag('div', array('class' => 'differential-primary-pane', 'id' => $pane_id), $change_list->render() . $add_comment_view); $content[] = $main_pane; } } } return $this->buildStandardPageResponse($content, array('title' => 'r' . $callsign . $commit->getCommitIdentifier())); }
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(); $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() . ' · ' . 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 { $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; if ($changes) { $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>'; } else { $change_list = '<div style="margin: 2em; color: #666; padding: 1em; background: #eee;">' . '(no changes blah blah)' . '</div>'; } $content[] = $change_list; } return $this->buildStandardPageResponse($content, array('title' => 'Diffusion')); }
public function processRequest() { $request = $this->getRequest(); $current_user = $request->getUser(); $error = null; $bad_redirect = false; $phid = $this->getClientPHID(); // if we have a phid, then we're editing $this->setIsClientEdit($phid); if ($this->isClientEdit()) { $client = id(new PhabricatorOAuthServerClient())->loadOneWhere('phid = %s', $phid); $title = 'Edit OAuth Client'; // validate the client if (empty($client)) { return new Aphront404Response(); } if ($client->getCreatorPHID() != $current_user->getPHID()) { $message = 'Access denied to edit client with id ' . $phid . '. ' . 'Only the user who created the client has permission to ' . 'edit the client.'; return id(new Aphront403Response())->setForbiddenText($message); } $submit_button = 'Save OAuth Client'; $secret = null; // new client - much simpler } else { $client = new PhabricatorOAuthServerClient(); $title = 'Create OAuth Client'; $submit_button = 'Create OAuth Client'; $secret = Filesystem::readRandomCharacters(32); } if ($request->isFormPost()) { $redirect_uri = $request->getStr('redirect_uri'); $client->setName($request->getStr('name')); $client->setRedirectURI($redirect_uri); if ($secret) { $client->setSecret($secret); } $client->setCreatorPHID($current_user->getPHID()); $uri = new PhutilURI($redirect_uri); $server = new PhabricatorOAuthServer(); if (!$server->validateRedirectURI($uri)) { $error = new AphrontErrorView(); $error->setSeverity(AphrontErrorView::SEVERITY_ERROR); $error->setTitle('Redirect URI must be a fully qualified domain name ' . 'with no fragments. See ' . 'http://tools.ietf.org/html/draft-ietf-oauth-v2-23#section-3.1.2 ' . 'for more information on the correct format.'); $bad_redirect = true; } else { $client->save(); // refresh the phid in case its a create $phid = $client->getPHID(); if ($this->isClientEdit()) { return id(new AphrontRedirectResponse())->setURI('/oauthserver/client/?edited=' . $phid); } else { return id(new AphrontRedirectResponse())->setURI('/oauthserver/client/?new=' . $phid); } } } $panel = new AphrontPanelView(); if ($this->isClientEdit()) { $delete_button = phutil_render_tag('a', array('href' => $client->getDeleteURI(), 'class' => 'grey button'), 'Delete OAuth Client'); $panel->addButton($delete_button); } $panel->setHeader($title); $form = id(new AphrontFormView())->setUser($current_user)->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($client->getName())); if ($this->isClientEdit()) { $form->appendChild(id(new AphrontFormTextControl())->setLabel('ID')->setValue($phid))->appendChild(id(new AphrontFormStaticControl())->setLabel('Secret')->setValue($client->getSecret())); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Redirect URI')->setName('redirect_uri')->setValue($client->getRedirectURI())->setError($bad_redirect)); if ($this->isClientEdit()) { $created = phabricator_datetime($client->getDateCreated(), $current_user); $updated = phabricator_datetime($client->getDateModified(), $current_user); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setValue($created))->appendChild(id(new AphrontFormStaticControl())->setLabel('Last Updated')->setValue($updated)); } $form->appendChild(id(new AphrontFormSubmitControl())->setValue($submit_button)); $panel->appendChild($form); return $this->buildStandardPageResponse(array($error, $panel), array('title' => $title)); }
public function processRequest(AphrontRequest $request) { $user = $request->getUser(); $editable = PhabricatorEnv::getEnvConfig('account.editable'); $uri = $request->getRequestURI(); $uri->setQueryParams(array()); if ($editable) { $new = $request->getStr('new'); if ($new) { return $this->returnNewAddressResponse($request, $uri, $new); } $delete = $request->getInt('delete'); if ($delete) { return $this->returnDeleteAddressResponse($request, $uri, $delete); } } $verify = $request->getInt('verify'); if ($verify) { return $this->returnVerifyAddressResponse($request, $uri, $verify); } $primary = $request->getInt('primary'); if ($primary) { return $this->returnPrimaryAddressResponse($request, $uri, $primary); } $emails = id(new PhabricatorUserEmail())->loadAllWhere('userPHID = %s ORDER BY address', $user->getPHID()); $rowc = array(); $rows = array(); foreach ($emails as $email) { $button_verify = javelin_render_tag('a', array('class' => 'button small grey', 'href' => $uri->alter('verify', $email->getID()), 'sigil' => 'workflow'), 'Verify'); $button_make_primary = javelin_render_tag('a', array('class' => 'button small grey', 'href' => $uri->alter('primary', $email->getID()), 'sigil' => 'workflow'), 'Make Primary'); $button_remove = javelin_render_tag('a', array('class' => 'button small grey', 'href' => $uri->alter('delete', $email->getID()), 'sigil' => 'workflow'), 'Remove'); $button_primary = phutil_render_tag('a', array('class' => 'button small disabled'), 'Primary'); if (!$email->getIsVerified()) { $action = $button_verify; } else { if ($email->getIsPrimary()) { $action = $button_primary; } else { $action = $button_make_primary; } } if ($email->getIsPrimary()) { $remove = $button_primary; $rowc[] = 'highlighted'; } else { $remove = $button_remove; $rowc[] = null; } $rows[] = array(phutil_escape_html($email->getAddress()), $action, $remove); } $table = new AphrontTableView($rows); $table->setHeaders(array('Email', 'Status', 'Remove')); $table->setColumnClasses(array('wide', 'action', 'action')); $table->setRowClasses($rowc); $table->setColumnVisibility(array(true, true, $editable)); $view = new AphrontPanelView(); if ($editable) { $view->addButton(javelin_render_tag('a', array('href' => $uri->alter('new', 'true'), 'class' => 'green button', 'sigil' => 'workflow'), 'Add New Address')); } $view->setHeader('Email Addresses'); $view->appendChild($table); return $view; }
private function buildTagListTable(DiffusionRequest $drequest) { $tag_limit = 15; $query = DiffusionTagListQuery::newFromDiffusionRequest($drequest); $query->setLimit($tag_limit + 1); $tags = $query->loadTags(); if (!$tags) { return null; } $more_tags = count($tags) > $tag_limit; $tags = array_slice($tags, 0, $tag_limit); $commits = id(new PhabricatorAuditCommitQuery())->withIdentifiers($drequest->getRepository()->getID(), mpull($tags, 'getCommitIdentifier'))->needCommitData(true)->execute(); $view = new DiffusionTagListView(); $view->setDiffusionRequest($drequest); $view->setTags($tags); $view->setUser($this->getRequest()->getUser()); $view->setCommits($commits); $phids = $view->getRequiredHandlePHIDs(); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $view->setHandles($handles); $panel = new AphrontPanelView(); $panel->setHeader('Tags'); if ($more_tags) { $panel->setCaption('Showing the ' . $tag_limit . ' most recent tags.'); } $panel->addButton(phutil_render_tag('a', array('href' => $drequest->generateURI(array('action' => 'tags')), 'class' => 'grey button'), "Show All Tags ยป")); $panel->appendChild($view); return $panel; }
private function renderKeyListView(AphrontRequest $request) { $user = $request->getUser(); $keys = id(new PhabricatorUserSSHKey())->loadAllWhere('userPHID = %s', $user->getPHID()); $rows = array(); foreach ($keys as $key) { $rows[] = array(phutil_render_tag('a', array('href' => $this->getPanelURI('?edit=' . $key->getID())), phutil_escape_html($key->getName())), phutil_escape_html($key->getKeyComment()), phutil_escape_html($key->getKeyType()), phabricator_date($key->getDateCreated(), $user), phabricator_time($key->getDateCreated(), $user), javelin_render_tag('a', array('href' => $this->getPanelURI('?delete=' . $key->getID()), 'class' => 'small grey button', 'sigil' => 'workflow'), 'Delete')); } $table = new AphrontTableView($rows); $table->setNoDataString("You haven't added any SSH Public Keys."); $table->setHeaders(array('Name', 'Comment', 'Type', 'Created', 'Time', '')); $table->setColumnClasses(array('wide pri', '', '', '', 'right', 'action')); $panel = new AphrontPanelView(); $panel->addButton(phutil_render_tag('a', array('href' => $this->getPanelURI('?edit=true'), 'class' => 'green button'), 'Add New Public Key')); $panel->setHeader('SSH Public Keys'); $panel->appendChild($table); return $panel; }