public function render() { $messages = $this->unitMessages; $messages = msort($messages, 'getSortKey'); if ($this->limit) { $messages = array_slice($messages, 0, $this->limit); } $rows = array(); $any_duration = false; foreach ($messages as $message) { $result = $this->renderResult($message->getResult()); $duration = $message->getDuration(); if ($duration !== null) { $any_duration = true; $duration = pht('%s ms', new PhutilNumber((int) (1000 * $duration))); } $name = $message->getName(); $namespace = $message->getNamespace(); if (strlen($namespace)) { $name = $namespace . '::' . $name; } $engine = $message->getEngine(); if (strlen($engine)) { $name = $engine . ' > ' . $name; } $rows[] = array($result, $duration, $name); } $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Result'), pht('Time'), pht('Test')))->setColumnClasses(array(null, null, 'pri wide'))->setColumnVisibility(array(true, $any_duration)); return $table; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $xaction = id(new PhabricatorObjectQuery())->withPHIDs(array($this->phid))->setViewer($user)->executeOne(); if (!$xaction) { return new Aphront404Response(); } if (!$xaction->getComment()) { // You can't view history of a transaction with no comments. return new Aphront404Response(); } if ($xaction->getComment()->getIsRemoved()) { // You can't view history of a transaction with a removed comment. return new Aphront400Response(); } $comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery())->setViewer($user)->setTemplate($xaction->getApplicationTransactionCommentObject())->withTransactionPHIDs(array($xaction->getPHID()))->execute(); if (!$comments) { return new Aphront404Response(); } $comments = msort($comments, 'getCommentVersion'); $xactions = array(); foreach ($comments as $comment) { $xactions[] = id(clone $xaction)->makeEphemeral()->setCommentVersion($comment->getCommentVersion())->setContentSource($comment->getContentSource())->setDateCreated($comment->getDateCreated())->attachComment($comment); } $obj_phid = $xaction->getObjectPHID(); $obj_handle = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs(array($obj_phid))->executeOne(); $view = id(new PhabricatorApplicationTransactionView())->setUser($user)->setObjectPHID($obj_phid)->setTransactions($xactions)->setShowEditActions(false)->setHideCommentOptions(true); $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FULL)->setFlush(true)->setTitle(pht('Comment History')); $dialog->appendChild($view); $dialog->addCancelButton($obj_handle->getURI()); return id(new AphrontDialogResponse())->setDialog($dialog); }
public function renderModuleStatus(AphrontRequest $request) { $viewer = $request->getViewer(); $types = PhabricatorPHIDType::getAllTypes(); $types = msort($types, 'getTypeConstant'); $rows = array(); foreach ($types as $key => $type) { $class_name = $type->getPHIDTypeApplicationClass(); if ($class_name !== null) { $app = PhabricatorApplication::getByClass($class_name); $app_name = $app->getName(); $icon = $app->getFontIcon(); if ($icon) { $app_icon = id(new PHUIIconView())->setIcon($icon); } else { $app_icon = null; } } else { $app_name = null; $app_icon = null; } $icon = $type->getTypeIcon(); if ($icon) { $type_icon = id(new PHUIIconView())->setIcon($icon); } else { $type_icon = null; } $rows[] = array($type->getTypeConstant(), get_class($type), $app_icon, $app_name, $type_icon, $type->getTypeName()); } $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Constant'), pht('Class'), null, pht('Application'), null, pht('Name')))->setColumnClasses(array(null, 'pri', 'icon', null, 'icon', 'wide')); return id(new PHUIObjectBoxView())->setHeaderText(pht('PHID Types'))->setTable($table); }
public function handleRequest(AphrontRequest $request) { $this->requireApplicationCapability(AuthManageProvidersCapability::CAPABILITY); $request = $this->getRequest(); $viewer = $request->getUser(); $providers = PhabricatorAuthProvider::getAllBaseProviders(); $e_provider = null; $errors = array(); if ($request->isFormPost()) { $provider_string = $request->getStr('provider'); if (!strlen($provider_string)) { $e_provider = pht('Required'); $errors[] = pht('You must select an authentication provider.'); } else { $found = false; foreach ($providers as $provider) { if (get_class($provider) === $provider_string) { $found = true; break; } } if (!$found) { $e_provider = pht('Invalid'); $errors[] = pht('You must select a valid provider.'); } } if (!$errors) { return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('/config/new/' . $provider_string . '/')); } } $options = id(new AphrontFormRadioButtonControl())->setLabel(pht('Provider'))->setName('provider')->setError($e_provider); $configured = PhabricatorAuthProvider::getAllProviders(); $configured_classes = array(); foreach ($configured as $configured_provider) { $configured_classes[get_class($configured_provider)] = true; } // Sort providers by login order, and move disabled providers to the // bottom. $providers = msort($providers, 'getLoginOrder'); $providers = array_diff_key($providers, $configured_classes) + $providers; foreach ($providers as $provider) { if (isset($configured_classes[get_class($provider)])) { $disabled = true; $description = pht('This provider is already configured.'); } else { $disabled = false; $description = $provider->getDescriptionForCreate(); } $options->addButton(get_class($provider), $provider->getNameForCreate(), $description, $disabled ? 'disabled' : null, $disabled); } $form = id(new AphrontFormView())->setUser($viewer)->appendChild($options)->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($this->getApplicationURI())->setValue(pht('Continue'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Provider'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Add Provider')); $crumbs->setBorder(true); $title = pht('Add Auth Provider'); $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-plus-square'); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box)); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view); }
public function processRequest() { $items = id(new PhabricatorDirectoryItem())->loadAll(); $items = msort($items, 'getSortKey'); $categories = id(new PhabricatorDirectoryCategory())->loadAll(); $categories = msort($categories, 'getSequence'); $category_map = mpull($categories, 'getName', 'getID'); $category_map[0] = 'Free Radicals'; $items = mgroup($items, 'getCategoryID'); require_celerity_resource('phabricator-directory-css'); $content = array(); foreach ($category_map as $id => $category_name) { $category_items = idx($items, $id); if (!$category_items) { continue; } $item_markup = array(); foreach ($category_items as $item) { $item_markup[] = '<div>' . '<h2>' . phutil_render_tag('a', array('href' => $item->getHref()), phutil_escape_html($item->getName())) . '</h2>' . '<p>' . phutil_escape_html($item->getDescription()) . '</p>' . '</div>'; } $content[] = '<div class="aphront-directory-category">' . '<h1>' . phutil_escape_html($category_name) . '</h1>' . '<div class="aphront-directory-group">' . implode("\n", $item_markup) . '</div>' . '</div>'; } $content = '<div class="aphront-directory-list">' . implode("\n", $content) . '</div>'; return $this->buildStandardPageResponse($content, array('title' => 'Directory', 'tab' => 'directory')); }
public function processRequest() { $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->loadObjects(); $classes = msort($classes, 'getName'); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/'))); foreach ($classes as $class => $obj) { $name = $obj->getName(); $nav->addFilter($class, $name); } $selected = $nav->selectFilter($this->class, head_key($classes)); $example = $classes[$selected]; $example->setRequest($this->getRequest()); $result = $example->renderExample(); if ($result instanceof AphrontResponse) { // This allows examples to generate dialogs, etc., for demonstration. return $result; } require_celerity_resource('phabricator-ui-example-css'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($example->getName()); $header = id(new PHUIHeaderView())->setHeader(pht('%s (%s)', $example->getName(), get_class($example)))->setSubheader($example->getDescription())->setNoBackground(true); $nav->appendChild(array($crumbs, $header, phutil_tag('br'), $result)); return $this->buildApplicationPage($nav, array('title' => $example->getName())); }
public static function sortAndGroupInlines(array $inlines, array $changesets) { assert_instances_of($inlines, 'DifferentialTransaction'); assert_instances_of($changesets, 'DifferentialChangeset'); $changesets = mpull($changesets, null, 'getID'); $changesets = msort($changesets, 'getFilename'); // Group the changesets by file and reorder them by display order. $inline_groups = array(); foreach ($inlines as $inline) { $changeset_id = $inline->getComment()->getChangesetID(); $inline_groups[$changeset_id][] = $inline; } $inline_groups = array_select_keys($inline_groups, array_keys($changesets)); foreach ($inline_groups as $changeset_id => $group) { // Sort the group of inlines by line number. $items = array(); foreach ($group as $inline) { $comment = $inline->getComment(); $num = $comment->getLineNumber(); $len = $comment->getLineLength(); $id = $comment->getID(); $items[] = array('inline' => $inline, 'sort' => sprintf('~%010d%010d%010d', $num, $len, $id)); } $items = isort($items, 'sort'); $items = ipull($items, 'inline'); $inline_groups[$changeset_id] = $items; } return $inline_groups; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $types = PassphraseCredentialType::getAllCreateableTypes(); $types = mpull($types, null, 'getCredentialType'); $types = msort($types, 'getCredentialTypeName'); $errors = array(); $e_type = null; if ($request->isFormPost()) { $type = $request->getStr('type'); if (empty($types[$type])) { $errors[] = pht('You must choose a credential type.'); $e_type = pht('Required'); } if (!$errors) { $uri = $this->getApplicationURI('edit/?type=' . $type); return id(new AphrontRedirectResponse())->setURI($uri); } } $types_control = id(new AphrontFormRadioButtonControl())->setName('type')->setLabel(pht('Credential Type'))->setError($e_type); foreach ($types as $type) { $types_control->addButton($type->getCredentialType(), $type->getCredentialTypeName(), $type->getCredentialTypeDescription()); } $form = id(new AphrontFormView())->setUser($viewer)->appendChild($types_control)->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Continue'))->addCancelButton($this->getApplicationURI())); $title = pht('New Credential'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Create')); $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Create New Credential'))->setFormErrors($errors)->setForm($form); return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title)); }
protected function loadCommands($target_phid) { $viewer = $this->getViewer(); $commands = id(new DrydockCommandQuery())->setViewer($viewer)->withTargetPHIDs(array($target_phid))->withConsumed(false)->execute(); $commands = msort($commands, 'getID'); return $commands; }
public function renderConfigurationFooter() { $hashers = PhabricatorPasswordHasher::getAllHashers(); $hashers = msort($hashers, 'getStrength'); $hashers = array_reverse($hashers); $yes = phutil_tag('strong', array('style' => 'color: #009900'), pht('Yes')); $no = phutil_tag('strong', array('style' => 'color: #990000'), pht('Not Installed')); $best_hasher_name = null; try { $best_hasher = PhabricatorPasswordHasher::getBestHasher(); $best_hasher_name = $best_hasher->getHashName(); } catch (PhabricatorPasswordHasherUnavailableException $ex) { // There are no suitable hashers. The user might be able to enable some, // so we don't want to fatal here. We'll fatal when users try to actually // use this stuff if it isn't fixed before then. Until then, we just // don't highlight a row. In practice, at least one hasher should always // be available. } $rows = array(); $rowc = array(); foreach ($hashers as $hasher) { $is_installed = $hasher->canHashPasswords(); $rows[] = array($hasher->getHumanReadableName(), $hasher->getHashName(), $hasher->getHumanReadableStrength(), $is_installed ? $yes : $no, $is_installed ? null : $hasher->getInstallInstructions()); $rowc[] = $best_hasher_name == $hasher->getHashName() ? 'highlighted' : null; } $table = new AphrontTableView($rows); $table->setRowClasses($rowc); $table->setHeaders(array(pht('Algorithm'), pht('Name'), pht('Strength'), pht('Installed'), pht('Install Instructions'))); $table->setColumnClasses(array('', '', '', '', 'wide')); $header = id(new PHUIHeaderView())->setHeader(pht('Password Hash Algorithms'))->setSubheader(pht('Stronger algorithms are listed first. The highlighted algorithm ' . 'will be used when storing new hashes. Older hashes will be ' . 'upgraded to the best algorithm over time.')); return id(new PHUIObjectBoxView())->setHeader($header)->appendChild($table); }
private function buildPanels() { $panel_specs = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorSettingsPanel')->setConcreteOnly(true)->selectAndLoadSymbols(); $panels = array(); foreach ($panel_specs as $spec) { $class = newv($spec['name'], array()); $panels[] = $class->buildPanels(); } $panels = array_mergev($panels); $panels = mpull($panels, null, 'getPanelKey'); $result = array(); foreach ($panels as $key => $panel) { $panel->setUser($this->user); if (!$panel->isEnabled()) { continue; } if (!$this->isSelf()) { if (!$panel->isEditableByAdministrators()) { continue; } } if (!empty($result[$key])) { throw new Exception(pht("Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key]))); } $result[$key] = $panel; } $result = msort($result, 'getPanelSortKey'); if (!$result) { throw new Exception(pht('No settings panels are available.')); } return $result; }
protected function getTagContent() { if (!$this->blankState && empty($this->events)) { return ''; } $events = msort($this->events, 'getEpochStart'); $singletons = array(); $allday = false; foreach ($events as $event) { $color = $event->getColor(); if ($event->getAllDay()) { $timelabel = pht('All Day'); } else { $timelabel = phabricator_time($event->getEpochStart(), $this->getUser()); } $dot = phutil_tag('span', array('class' => 'phui-calendar-list-dot'), ''); $title = phutil_tag('span', array('class' => 'phui-calendar-list-title'), $this->renderEventLink($event, $allday)); $time = phutil_tag('span', array('class' => 'phui-calendar-list-time'), $timelabel); $singletons[] = phutil_tag('li', array('class' => 'phui-calendar-list-item phui-calendar-' . $color), array($dot, $title, $time)); } if (empty($singletons)) { $singletons[] = phutil_tag('li', array('class' => 'phui-calendar-list-item-empty'), pht('Clear sailing ahead.')); } $list = phutil_tag('ul', array('class' => 'phui-calendar-list'), $singletons); return $list; }
private function buildPanels() { $panels = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorSettingsPanel')->setExpandMethod('buildPanels')->setUniqueMethod('getPanelKey')->execute(); $result = array(); foreach ($panels as $key => $panel) { $panel->setUser($this->user); if (!$panel->isEnabled()) { continue; } if (!$this->isSelf()) { if (!$panel->isEditableByAdministrators()) { continue; } } if (!empty($result[$key])) { throw new Exception(pht("Two settings panels share the same panel key ('%s'): %s, %s.", $key, get_class($panel), get_class($result[$key]))); } $result[$key] = $panel; } $result = msort($result, 'getPanelSortKey'); if (!$result) { throw new Exception(pht('No settings panels are available.')); } return $result; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $books = id(new DivinerBookQuery())->setViewer($viewer)->execute(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setBorder(true); $crumbs->addTextCrumb(pht('Books')); $query_button = id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('query/'))->setText(pht('Advanced Search'))->setIcon('fa-search'); $header = id(new PHUIHeaderView())->setHeader(pht('Documentation Books'))->addActionLink($query_button); $document = new PHUIDocumentViewPro(); $document->setHeader($header); $document->addClass('diviner-view'); if ($books) { $books = msort($books, 'getTitle'); $list = array(); foreach ($books as $book) { $item = id(new DivinerBookItemView())->setTitle($book->getTitle())->setHref('/book/' . $book->getName() . '/')->setSubtitle($book->getPreface()); $list[] = $item; } $list = id(new PHUIBoxView())->addPadding(PHUI::PADDING_MEDIUM_TOP)->appendChild($list); $document->appendChild($list); } else { $text = pht("(NOTE) **Looking for Phabricator documentation?** " . "If you're looking for help and information about Phabricator, " . "you can [[https://secure.phabricator.com/diviner/ | " . "browse the public Phabricator documentation]] on the live site.\n\n" . "Diviner is the documentation generator used to build the " . "Phabricator documentation.\n\n" . "You haven't generated any Diviner documentation books yet, so " . "there's nothing to show here. If you'd like to generate your own " . "local copy of the Phabricator documentation and have it appear " . "here, run this command:\n\n" . " %s\n\n", 'phabricator/ $ ./bin/diviner generate'); $text = new PHUIRemarkupView($viewer, $text); $document->appendChild($text); } return $this->newPage()->setTitle(pht('Documentation Books'))->setCrumbs($crumbs)->appendChild(array($document)); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $books = id(new DivinerBookQuery())->setViewer($viewer)->execute(); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Books')); $search_icon = id(new PHUIIconView())->setIconFont('fa-search'); $query_button = id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI('query/'))->setText(pht('Advanced Search'))->setIcon($search_icon); $header = id(new PHUIHeaderView())->setHeader(pht('Documentation Books'))->addActionLink($query_button); $document = new PHUIDocumentView(); $document->setHeader($header); $document->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS); $document->addClass('diviner-view'); if ($books) { $books = msort($books, 'getTitle'); $list = array(); foreach ($books as $book) { $item = id(new DivinerBookItemView())->setTitle($book->getTitle())->setHref('/book/' . $book->getName() . '/')->setSubtitle($book->getPreface()); $list[] = $item; } $list = id(new PHUIBoxView())->addPadding(PHUI::PADDING_LARGE_LEFT)->addPadding(PHUI::PADDING_LARGE_RIGHT)->addPadding(PHUI::PADDING_SMALL_TOP)->addPadding(PHUI::PADDING_SMALL_BOTTOM)->appendChild($list); $document->appendChild($list); } else { $text = pht("(NOTE) **Looking for Phabricator documentation?** If you're looking " . "for help and information about Phabricator, you can " . "[[ https://secure.phabricator.com/diviner/ | browse the public " . "Phabricator documentation ]] on the live site.\n\n" . "Diviner is the documentation generator used to build the Phabricator " . "documentation.\n\n" . "You haven't generated any Diviner documentation books yet, so " . "there's nothing to show here. If you'd like to generate your own " . "local copy of the Phabricator documentation and have it appear " . "here, run this command:\n\n" . " phabricator/ \$ ./bin/diviner generate\n\n" . "Right now, Diviner isn't very useful for generating documentation " . "for projects other than Phabricator. If you're interested in using " . "it in your own projects, leave feedback for us on " . "[[ https://secure.phabricator.com/T4558 | T4558 ]]."); $text = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($text), 'default', $viewer); $document->appendChild($text); } return $this->buildApplicationPage(array($crumbs, $document), array('title' => pht('Documentation Books'), 'fonts' => true)); }
public function render() { $messages = $this->lintMessages; $messages = msort($messages, 'getSortKey'); if ($this->limit) { $messages = array_slice($messages, 0, $this->limit); } $rows = array(); foreach ($messages as $message) { $path = $message->getPath(); $line = $message->getLine(); $href = null; if (strlen(idx($this->pathURIMap, $path))) { $href = $this->pathURIMap[$path] . max($line, 1); } $severity = $this->renderSeverity($message->getSeverity()); $location = $path . ':' . $line; if (strlen($href)) { $location = phutil_tag('a', array('href' => $href), $location); } $rows[] = array($severity, $location, $message->getCode(), $message->getName()); } $table = id(new AphrontTableView($rows))->setHeaders(array(pht('Severity'), pht('Location'), pht('Code'), pht('Message')))->setColumnClasses(array(null, 'pri', null, 'wide')); return $table; }
public function handleRequest(AphrontRequest $request) { $id = $request->getURIData('class'); $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->loadObjects(); $classes = msort($classes, 'getName'); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/'))); foreach ($classes as $class => $obj) { $name = $obj->getName(); $nav->addFilter($class, $name); } $selected = $nav->selectFilter($id, head_key($classes)); $example = $classes[$selected]; $example->setRequest($this->getRequest()); $result = $example->renderExample(); if ($result instanceof AphrontResponse) { // This allows examples to generate dialogs, etc., for demonstration. return $result; } require_celerity_resource('phabricator-ui-example-css'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($example->getName()); $note = id(new PHUIInfoView())->setTitle(pht('%s (%s)', $example->getName(), get_class($example)))->appendChild($example->getDescription())->setSeverity(PHUIInfoView::SEVERITY_NODATA); $nav->appendChild(array($crumbs, $note, $result)); return $this->buildApplicationPage($nav, array('title' => $example->getName())); }
/** * Load the namespace which prevents use of an Almanac name, if one exists. */ public static function loadRestrictedNamespace(PhabricatorUser $viewer, $name) { // For a name like "x.y.z", produce a list of controlling namespaces like // ("z", "y.x", "x.y.z"). $names = array(); $parts = explode('.', $name); for ($ii = 0; $ii < count($parts); $ii++) { $names[] = implode('.', array_slice($parts, -($ii + 1))); } // Load all the possible controlling namespaces. $namespaces = id(new AlmanacNamespaceQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withNames($names)->execute(); if (!$namespaces) { return null; } // Find the "nearest" (longest) namespace that exists. If both // "sub.domain.com" and "domain.com" exist, we only care about the policy // on the former. $namespaces = msort($namespaces, 'getNameLength'); $namespace = last($namespaces); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $namespace, PhabricatorPolicyCapability::CAN_EDIT); if ($can_edit) { return null; } return $namespace; }
public function renderModuleStatus(AphrontRequest $request) { $viewer = $request->getViewer(); $collectors = PhabricatorGarbageCollector::getAllCollectors(); $collectors = msort($collectors, 'getCollectorConstant'); $rows = array(); $rowc = array(); foreach ($collectors as $key => $collector) { $class = null; if ($collector->hasAutomaticPolicy()) { $policy_view = phutil_tag('em', array(), pht('Automatic')); } else { $policy = $collector->getRetentionPolicy(); if ($policy === null) { $policy_view = pht('Indefinite'); } else { $days = ceil($policy / phutil_units('1 day in seconds')); $policy_view = pht('%s Day(s)', new PhutilNumber($days)); } $default = $collector->getDefaultRetentionPolicy(); if ($policy !== $default) { $class = 'highlighted'; $policy_view = phutil_tag('strong', array(), $policy_view); } } $rowc[] = $class; $rows[] = array($collector->getCollectorConstant(), $collector->getCollectorName(), $policy_view); } $table = id(new AphrontTableView($rows))->setRowClasses($rowc)->setHeaders(array(pht('Constant'), pht('Name'), pht('Retention Policy')))->setColumnClasses(array(null, 'pri wide', null)); $header = id(new PHUIHeaderView())->setHeader(pht('Garbage Collectors'))->setSubheader(pht('Collectors with custom policies are highlighted. Use ' . '%s to change retention policies.', phutil_tag('tt', array(), 'bin/garbage set-policy'))); return id(new PHUIObjectBoxView())->setHeader($header)->setTable($table); }
public function processRequest() { $classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->setConcreteOnly(true)->selectAndLoadSymbols(); $classes = ipull($classes, 'name', 'name'); foreach ($classes as $class => $ignored) { $classes[$class] = newv($class, array()); } $classes = msort($classes, 'getName'); $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/'))); foreach ($classes as $class => $obj) { $name = $obj->getName(); $nav->addFilter($class, $name); } $selected = $nav->selectFilter($this->class, head_key($classes)); require_celerity_resource('phabricator-ui-example-css'); $example = $classes[$selected]; $example->setRequest($this->getRequest()); $result = $example->renderExample(); if ($result instanceof AphrontResponse) { // This allows examples to generate dialogs, etc., for demonstration. return $result; } $nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>'); $nav->appendChild($result); return $this->buildApplicationPage($nav, array('title' => 'UI Example', 'device' => true)); }
public function getQuickMenuItems() { $viewer = $this->getViewer(); $engines = PhabricatorEditEngine::getAllEditEngines(); foreach ($engines as $key => $engine) { if (!$engine->hasQuickCreateActions()) { unset($engines[$key]); } } if (!$engines) { return array(); } $engine_keys = array_keys($engines); $configs = id(new PhabricatorEditEngineConfigurationQuery())->setViewer($viewer)->withEngineKeys($engine_keys)->withIsDefault(true)->withIsDisabled(false)->execute(); $configs = msort($configs, 'getCreateSortKey'); $configs = mgroup($configs, 'getEngineKey'); $items = array(); foreach ($engines as $key => $engine) { $engine_configs = idx($configs, $key, array()); $engine_items = $engine->newQuickCreateActions($engine_configs); foreach ($engine_items as $engine_item) { $items[] = $engine_item; } } return $items; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $applications = PhabricatorApplication::getAllInstalledApplications(); foreach ($applications as $key => $application) { if (!$application->shouldAppearInLaunchView()) { unset($applications[$key]); } } $groups = PhabricatorApplication::getApplicationGroups(); $applications = msort($applications, 'getApplicationOrder'); $applications = mgroup($applications, 'getApplicationGroup'); $applications = array_select_keys($applications, array_keys($groups)); $view = array(); foreach ($applications as $group => $application_list) { $status = array(); foreach ($application_list as $key => $application) { $status[$key] = $application->loadStatus($user); } $views = array(); foreach ($application_list as $key => $application) { $views[] = id(new PhabricatorApplicationLaunchView())->setApplication($application)->setApplicationStatus(idx($status, $key, array()))->setUser($user); } $view[] = id(new PhabricatorHeaderView())->setHeader($groups[$group]); $view[] = phutil_render_tag('div', array('class' => 'phabricator-application-list'), id(new AphrontNullView())->appendChild($views)->render()); } return $this->buildApplicationPage($view, array('title' => 'Applications', 'device' => true)); }
private function loadArcProjects() { $viewer = $this->getRequest()->getUser(); $projects = id(new PhabricatorRepositoryArcanistProjectQuery())->setViewer($viewer)->needRepositories(true)->execute(); $projects = mfilter($projects, 'getRepository'); $projects = msort($projects, 'getName'); return $projects; }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); $diff = id(new DifferentialDiffQuery())->setViewer($viewer)->withIDs(array($id))->executeOne(); if (!$diff) { return new Aphront404Response(); } if ($diff->getRevisionID()) { return id(new AphrontRedirectResponse())->setURI('/D' . $diff->getRevisionID() . '?id=' . $diff->getID()); } $diff_phid = $diff->getPHID(); $buildables = id(new HarbormasterBuildableQuery())->setViewer($viewer)->withBuildablePHIDs(array($diff_phid))->withManualBuildables(false)->needBuilds(true)->needTargets(true)->execute(); $buildables = mpull($buildables, null, 'getBuildablePHID'); $diff->attachBuildable(idx($buildables, $diff_phid)); // TODO: implement optgroup support in AphrontFormSelectControl? $select = array(); $select[] = hsprintf('<optgroup label="%s">', pht('Create New Revision')); $select[] = phutil_tag('option', array('value' => ''), pht('Create a new Revision...')); $select[] = hsprintf('</optgroup>'); $selected_id = $request->getInt('revisionID'); $revisions = $this->loadSelectableRevisions($viewer, $selected_id); if ($revisions) { $select[] = hsprintf('<optgroup label="%s">', pht('Update Existing Revision')); foreach ($revisions as $revision) { if ($selected_id == $revision->getID()) { $selected = 'selected'; } else { $selected = null; } $select[] = phutil_tag('option', array('value' => $revision->getID(), 'selected' => $selected), id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(128)->truncateString('D' . $revision->getID() . ' ' . $revision->getTitle())); } $select[] = hsprintf('</optgroup>'); } $select = phutil_tag('select', array('name' => 'revisionID'), $select); $form = id(new AphrontFormView())->setUser($request->getUser())->setAction('/differential/revision/edit/')->addHiddenInput('diffID', $diff->getID())->addHiddenInput('viaDiffView', 1)->addHiddenInput(id(new DifferentialRepositoryField())->getFieldKey(), $diff->getRepositoryPHID())->appendRemarkupInstructions(pht('Review the diff for correctness. When you are satisfied, either ' . '**create a new revision** or **update an existing revision**.'))->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Attach To'))->setValue($select))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Continue'))); $props = id(new DifferentialDiffProperty())->loadAllWhere('diffID = %d', $diff->getID()); $props = mpull($props, 'getData', 'getName'); $property_head = id(new PHUIHeaderView())->setHeader(pht('Properties')); $property_view = new PHUIPropertyListView(); $changesets = $diff->loadChangesets(); $changesets = msort($changesets, 'getSortKey'); $table_of_contents = $this->buildTableOfContents($changesets, $changesets, $diff->loadCoverageMap($viewer)); $refs = array(); foreach ($changesets as $changeset) { $refs[$changeset->getID()] = $changeset->getID(); } $details = id(new DifferentialChangesetListView())->setChangesets($changesets)->setVisibleChangesets($changesets)->setRenderingReferences($refs)->setStandaloneURI('/differential/changeset/')->setDiff($diff)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setTitle(pht('Diff %d', $diff->getID()))->setUser($request->getUser()); $title = pht('Diff %d', $diff->getID()); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); $crumbs->setBorder(true); $header = id(new PHUIHeaderView())->setHeader($title); $prop_box = id(new PHUIObjectBoxView())->setHeader($property_head)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->addPropertyList($property_view)->setForm($form); $view = id(new PHUITwoColumnView())->setHeader($header)->setMainColumn(array())->setFooter(array($prop_box, $table_of_contents, $details)); $page = $this->newPage()->setTitle(pht('Diff View'))->setCrumbs($crumbs)->appendChild($view); return $page; }
protected function buildAlmanacPropertiesTable(AlmanacPropertyInterface $object) { $viewer = $this->getViewer(); $properties = $object->getAlmanacProperties(); $this->requireResource('almanac-css'); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $object, PhabricatorPolicyCapability::CAN_EDIT); $field_list = PhabricatorCustomField::getObjectFields($object, PhabricatorCustomField::ROLE_DEFAULT); // Before reading values from the object, read defaults. $defaults = mpull($field_list->getFields(), 'getValueForStorage', 'getFieldKey'); $field_list->setViewer($viewer)->readFieldsFromStorage($object); Javelin::initBehavior('phabricator-tooltips', array()); $icon_builtin = id(new PHUIIconView())->setIcon('fa-circle')->addSigil('has-tooltip')->setMetadata(array('tip' => pht('Builtin Property'), 'align' => 'E')); $icon_custom = id(new PHUIIconView())->setIcon('fa-circle-o grey')->addSigil('has-tooltip')->setMetadata(array('tip' => pht('Custom Property'), 'align' => 'E')); $builtins = $object->getAlmanacPropertyFieldSpecifications(); // Sort fields so builtin fields appear first, then fields are ordered // alphabetically. $fields = $field_list->getFields(); $fields = msort($fields, 'getFieldKey'); $head = array(); $tail = array(); foreach ($fields as $field) { $key = $field->getFieldKey(); if (isset($builtins[$key])) { $head[$key] = $field; } else { $tail[$key] = $field; } } $fields = $head + $tail; $rows = array(); foreach ($fields as $key => $field) { $value = $field->getValueForStorage(); $is_builtin = isset($builtins[$key]); $delete_uri = $this->getApplicationURI('property/delete/'); $delete_uri = id(new PhutilURI($delete_uri))->setQueryParams(array('objectPHID' => $object->getPHID(), 'key' => $key)); $edit_uri = $this->getApplicationURI('property/edit/'); $edit_uri = id(new PhutilURI($edit_uri))->setQueryParams(array('objectPHID' => $object->getPHID(), 'key' => $key)); $delete = javelin_tag('a', array('class' => $can_edit ? 'button grey small' : 'button grey small disabled', 'sigil' => 'workflow', 'href' => $delete_uri), $is_builtin ? pht('Reset') : pht('Delete')); $default = idx($defaults, $key); $is_default = $default !== null && $default === $value; $display_value = PhabricatorConfigJSON::prettyPrintJSON($value); if ($is_default) { $display_value = phutil_tag('span', array('class' => 'almanac-default-property-value'), $display_value); } $display_key = $key; if ($can_edit) { $display_key = javelin_tag('a', array('href' => $edit_uri, 'sigil' => 'workflow'), $display_key); } $rows[] = array($is_builtin ? $icon_builtin : $icon_custom, $display_key, $display_value, $delete); } $table = id(new AphrontTableView($rows))->setNoDataString(pht('No properties.'))->setHeaders(array(null, pht('Name'), pht('Value'), null))->setColumnClasses(array(null, null, 'wide', 'action')); $phid = $object->getPHID(); $add_uri = $this->getApplicationURI("property/edit/?objectPHID={$phid}"); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $object, PhabricatorPolicyCapability::CAN_EDIT); $add_button = id(new PHUIButtonView())->setTag('a')->setHref($add_uri)->setWorkflow(true)->setDisabled(!$can_edit)->setText(pht('Add Property'))->setIcon('fa-plus'); $header = id(new PHUIHeaderView())->setHeader(pht('Properties'))->addActionLink($add_button); return id(new PHUIObjectBoxView())->setHeader($header)->setTable($table); }
function msort(&$arr, $low, $high) { if ($low < $high) { $mid = floor(($low + $high) / 2); msort($arr, $low, $mid); msort($arr, $mid + 1, $high); mergeArray($arr, $low, $mid, $high); } }
private function getAllMethods() { static $methods; if ($methods === null) { $methods = id(new PhutilSymbolLoader())->setAncestorClass('ConduitAPIMethod')->loadObjects(); $methods = msort($methods, 'getSortOrder'); } return $methods; }
public function loadResults() { $offset = $this->getOffset(); $limit = $this->getLimit(); // If the input query is a function like `members(platy`, and we can // parse the function, we strip the function off and hand the stripped // query to child sources. This makes it easier to implement function // sources in terms of real object sources. $raw_query = $this->getRawQuery(); $is_function = false; if (self::isFunctionToken($raw_query)) { $is_function = true; } $stack = $this->getFunctionStack(); $is_browse = $this->getIsBrowse(); $results = array(); foreach ($this->getUsableDatasources() as $source) { $source_stack = $stack; $source_query = $raw_query; if ($is_function) { // If this source can't handle the function, skip it. $function = $source->parseFunction($raw_query, $allow_partial = true); if (!$function) { continue; } // If this source handles the function directly, strip the function. // Otherwise, this is something like a composite source which has // some internal source which can evaluate the function, but will // perform stripping later. if ($source->shouldStripFunction($function['name'])) { $source_query = head($function['argv']); $source_stack[] = $function['name']; } } $source->setFunctionStack($source_stack)->setRawQuery($source_query)->setQuery($this->getQuery())->setViewer($this->getViewer()); if ($limit) { $source->setLimit($offset + $limit); } if ($is_browse) { $source->setIsBrowse(true); } $source_results = $source->loadResults(); $source_results = $source->didLoadResults($source_results); $results[] = $source_results; } $results = array_mergev($results); $results = msort($results, 'getSortKey'); $count = count($results); if ($offset || $limit) { if (!$limit) { $limit = count($results); } $results = array_slice($results, $offset, $limit, $preserve_keys = true); } return $results; }
public static final function loadAllFormats() { $classes = id(new PhutilSymbolLoader())->setAncestorClass(__CLASS__)->setConcreteOnly(true)->selectAndLoadSymbols(); $objects = array(); foreach ($classes as $class) { $objects[$class['name']] = newv($class['name'], array()); } $objects = msort($objects, 'getOrder'); return $objects; }
public function resetSource() { foreach ($this->getDates() as $date) { $date->setViewerTimezone($this->getViewerTimezone()); } $order = msort($this->getDates(), 'getEpoch'); $order = array_reverse($order); $this->order = $order; return $this; }