Page MenuHomestyx hydra

No OneTemporary

This file is larger than 256 KB, so syntax highlighting was skipped.
diff --git a/src/applications/almanac/controller/AlmanacController.php b/src/applications/almanac/controller/AlmanacController.php
index 8efae11d6a..e1a7c2a69e 100644
--- a/src/applications/almanac/controller/AlmanacController.php
+++ b/src/applications/almanac/controller/AlmanacController.php
@@ -1,201 +1,199 @@
<?php
abstract class AlmanacController
extends PhabricatorController {
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())
- ->setIconFont('fa-circle')
+ ->setIcon('fa-circle')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Builtin Property'),
'align' => 'E',
));
$icon_custom = id(new PHUIIconView())
- ->setIconFont('fa-circle-o grey')
+ ->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(
- id(new PHUIIconView())
- ->setIconFont('fa-plus'));
+ ->setIcon('fa-plus');
$header = id(new PHUIHeaderView())
->setHeader(pht('Properties'))
->addActionLink($add_button);
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
protected function addLockMessage(PHUIObjectBoxView $box, $message) {
$doc_link = phutil_tag(
'a',
array(
'href' => PhabricatorEnv::getDoclink('Almanac User Guide'),
'target' => '_blank',
),
pht('Learn More'));
$error_view = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(
array(
array($message, ' ', $doc_link),
));
$box->setInfoView($error_view);
}
}
diff --git a/src/applications/almanac/controller/AlmanacDeviceViewController.php b/src/applications/almanac/controller/AlmanacDeviceViewController.php
index e611cceb7a..c7756c5b25 100644
--- a/src/applications/almanac/controller/AlmanacDeviceViewController.php
+++ b/src/applications/almanac/controller/AlmanacDeviceViewController.php
@@ -1,255 +1,253 @@
<?php
final class AlmanacDeviceViewController
extends AlmanacDeviceController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$name = $request->getURIData('name');
$device = id(new AlmanacDeviceQuery())
->setViewer($viewer)
->withNames(array($name))
->executeOne();
if (!$device) {
return new Aphront404Response();
}
// We rebuild locks on a device when viewing the detail page, so they
// automatically get corrected if they fall out of sync.
$device->rebuildDeviceLocks();
$title = pht('Device %s', $device->getName());
$property_list = $this->buildPropertyList($device);
$action_list = $this->buildActionList($device);
$property_list->setActionList($action_list);
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($device->getName())
->setPolicyObject($device);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($property_list);
if ($device->getIsLocked()) {
$this->addLockMessage(
$box,
pht(
'This device is bound to a locked service, so it can not be '.
'edited.'));
}
$interfaces = $this->buildInterfaceList($device);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($device->getName());
$timeline = $this->buildTransactionTimeline(
$device,
new AlmanacDeviceTransactionQuery());
$timeline->setShouldTerminate(true);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild(
array(
$box,
$interfaces,
$this->buildAlmanacPropertiesTable($device),
$this->buildSSHKeysTable($device),
$this->buildServicesTable($device),
$timeline,
));
}
private function buildPropertyList(AlmanacDevice $device) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($device);
return $properties;
}
private function buildActionList(AlmanacDevice $device) {
$viewer = $this->getViewer();
$id = $device->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$device,
PhabricatorPolicyCapability::CAN_EDIT);
$actions = id(new PhabricatorActionListView())
->setUser($viewer);
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Device'))
->setHref($this->getApplicationURI("device/edit/{$id}/"))
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit));
return $actions;
}
private function buildInterfaceList(AlmanacDevice $device) {
$viewer = $this->getViewer();
$id = $device->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$device,
PhabricatorPolicyCapability::CAN_EDIT);
$interfaces = id(new AlmanacInterfaceQuery())
->setViewer($viewer)
->withDevicePHIDs(array($device->getPHID()))
->execute();
$table = id(new AlmanacInterfaceTableView())
->setUser($viewer)
->setInterfaces($interfaces)
->setCanEdit($can_edit);
$header = id(new PHUIHeaderView())
->setHeader(pht('Device Interfaces'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($this->getApplicationURI("interface/edit/?deviceID={$id}"))
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit)
->setText(pht('Add Interface'))
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-plus')));
+ ->setIcon('fa-plus'));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
private function buildSSHKeysTable(AlmanacDevice $device) {
$viewer = $this->getViewer();
$id = $device->getID();
$device_phid = $device->getPHID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$device,
PhabricatorPolicyCapability::CAN_EDIT);
$keys = id(new PhabricatorAuthSSHKeyQuery())
->setViewer($viewer)
->withObjectPHIDs(array($device_phid))
->execute();
$table = id(new PhabricatorAuthSSHKeyTableView())
->setUser($viewer)
->setKeys($keys)
->setCanEdit($can_edit)
->setShowID(true)
->setShowTrusted(true)
->setNoDataString(pht('This device has no associated SSH public keys.'));
try {
PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();
$can_generate = true;
} catch (Exception $ex) {
$can_generate = false;
}
$generate_uri = '/auth/sshkey/generate/?objectPHID='.$device_phid;
$upload_uri = '/auth/sshkey/upload/?objectPHID='.$device_phid;
$header = id(new PHUIHeaderView())
->setHeader(pht('SSH Public Keys'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($generate_uri)
->setWorkflow(true)
->setDisabled(!$can_edit || !$can_generate)
->setText(pht('Generate Keypair'))
->setIcon(
id(new PHUIIconView())
- ->setIconFont('fa-lock')))
+ ->setIcon('fa-lock')))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($upload_uri)
->setWorkflow(true)
->setDisabled(!$can_edit)
->setText(pht('Upload Public Key'))
->setIcon(
id(new PHUIIconView())
- ->setIconFont('fa-upload')));
+ ->setIcon('fa-upload')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
private function buildServicesTable(AlmanacDevice $device) {
$viewer = $this->getViewer();
// NOTE: We're loading all services so we can show hidden, locked services.
// In general, we let you know about all the things the device is bound to,
// even if you don't have permission to see their details. This is similar
// to exposing the existence of edges in other applications, with the
// addition of always letting you see that locks exist.
$services = id(new AlmanacServiceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withDevicePHIDs(array($device->getPHID()))
->execute();
$handles = $viewer->loadHandles(mpull($services, 'getPHID'));
$icon_lock = id(new PHUIIconView())
- ->setIconFont('fa-lock');
+ ->setIcon('fa-lock');
$rows = array();
foreach ($services as $service) {
$rows[] = array(
($service->getIsLocked()
? $icon_lock
: null),
$handles->renderHandle($service->getPHID()),
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No services are bound to this device.'))
->setHeaders(
array(
null,
pht('Service'),
))
->setColumnClasses(
array(
null,
'wide pri',
));
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Bound Services'))
->setTable($table);
}
}
diff --git a/src/applications/almanac/controller/AlmanacServiceViewController.php b/src/applications/almanac/controller/AlmanacServiceViewController.php
index bfeed96e2f..113722bf06 100644
--- a/src/applications/almanac/controller/AlmanacServiceViewController.php
+++ b/src/applications/almanac/controller/AlmanacServiceViewController.php
@@ -1,146 +1,144 @@
<?php
final class AlmanacServiceViewController
extends AlmanacServiceController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$name = $request->getURIData('name');
$service = id(new AlmanacServiceQuery())
->setViewer($viewer)
->withNames(array($name))
->executeOne();
if (!$service) {
return new Aphront404Response();
}
$title = pht('Service %s', $service->getName());
$property_list = $this->buildPropertyList($service);
$action_list = $this->buildActionList($service);
$property_list->setActionList($action_list);
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($service->getName())
->setPolicyObject($service);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($property_list);
$messages = $service->getServiceType()->getStatusMessages($service);
if ($messages) {
$box->setFormErrors($messages);
}
if ($service->getIsLocked()) {
$this->addLockMessage(
$box,
pht('This service is locked, and can not be edited.'));
}
$bindings = $this->buildBindingList($service);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($service->getName());
$timeline = $this->buildTransactionTimeline(
$service,
new AlmanacServiceTransactionQuery());
$timeline->setShouldTerminate(true);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild(
array(
$box,
$bindings,
$this->buildAlmanacPropertiesTable($service),
$timeline,
));
}
private function buildPropertyList(AlmanacService $service) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($service);
$properties->addProperty(
pht('Service Type'),
$service->getServiceType()->getServiceTypeShortName());
return $properties;
}
private function buildActionList(AlmanacService $service) {
$viewer = $this->getViewer();
$id = $service->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$service,
PhabricatorPolicyCapability::CAN_EDIT);
$actions = id(new PhabricatorActionListView())
->setUser($viewer);
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Service'))
->setHref($this->getApplicationURI("service/edit/{$id}/"))
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit));
return $actions;
}
private function buildBindingList(AlmanacService $service) {
$viewer = $this->getViewer();
$id = $service->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$service,
PhabricatorPolicyCapability::CAN_EDIT);
$bindings = id(new AlmanacBindingQuery())
->setViewer($viewer)
->withServicePHIDs(array($service->getPHID()))
->execute();
$table = id(new AlmanacBindingTableView())
->setNoDataString(
pht('This service has not been bound to any device interfaces yet.'))
->setUser($viewer)
->setBindings($bindings);
$header = id(new PHUIHeaderView())
->setHeader(pht('Service Bindings'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($this->getApplicationURI("binding/edit/?serviceID={$id}"))
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit)
->setText(pht('Add Binding'))
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-plus')));
+ ->setIcon('fa-plus'));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
}
diff --git a/src/applications/auth/controller/config/PhabricatorAuthListController.php b/src/applications/auth/controller/config/PhabricatorAuthListController.php
index 71aac9e185..6df32f50a5 100644
--- a/src/applications/auth/controller/config/PhabricatorAuthListController.php
+++ b/src/applications/auth/controller/config/PhabricatorAuthListController.php
@@ -1,190 +1,188 @@
<?php
final class PhabricatorAuthListController
extends PhabricatorAuthProviderConfigController {
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$configs = id(new PhabricatorAuthProviderConfigQuery())
->setViewer($viewer)
->execute();
$list = new PHUIObjectItemListView();
$can_manage = $this->hasApplicationCapability(
AuthManageProvidersCapability::CAPABILITY);
foreach ($configs as $config) {
$item = new PHUIObjectItemView();
$id = $config->getID();
$edit_uri = $this->getApplicationURI('config/edit/'.$id.'/');
$enable_uri = $this->getApplicationURI('config/enable/'.$id.'/');
$disable_uri = $this->getApplicationURI('config/disable/'.$id.'/');
$provider = $config->getProvider();
if ($provider) {
$name = $provider->getProviderName();
} else {
$name = $config->getProviderType().' ('.$config->getProviderClass().')';
}
$item->setHeader($name);
if ($provider) {
$item->setHref($edit_uri);
} else {
$item->addAttribute(pht('Provider Implementation Missing!'));
}
$domain = null;
if ($provider) {
$domain = $provider->getProviderDomain();
if ($domain !== 'self') {
$item->addAttribute($domain);
}
}
if ($config->getShouldAllowRegistration()) {
$item->addAttribute(pht('Allows Registration'));
} else {
$item->addAttribute(pht('Does Not Allow Registration'));
}
if ($config->getIsEnabled()) {
$item->setState(PHUIObjectItemView::STATE_SUCCESS);
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setHref($disable_uri)
->setDisabled(!$can_manage)
->addSigil('workflow'));
} else {
$item->setState(PHUIObjectItemView::STATE_FAIL);
$item->addIcon('fa-times grey', pht('Disabled'));
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-plus')
->setHref($enable_uri)
->setDisabled(!$can_manage)
->addSigil('workflow'));
}
$list->addItem($item);
}
$list->setNoDataString(
pht(
'%s You have not added authentication providers yet. Use "%s" to add '.
'a provider, which will let users register new Phabricator accounts '.
'and log in.',
phutil_tag(
'strong',
array(),
pht('No Providers Configured:')),
phutil_tag(
'a',
array(
'href' => $this->getApplicationURI('config/new/'),
),
pht('Add Authentication Provider'))));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Auth Providers'));
$domains_key = 'auth.email-domains';
$domains_link = $this->renderConfigLink($domains_key);
$domains_value = PhabricatorEnv::getEnvConfig($domains_key);
$approval_key = 'auth.require-approval';
$approval_link = $this->renderConfigLink($approval_key);
$approval_value = PhabricatorEnv::getEnvConfig($approval_key);
$issues = array();
if ($domains_value) {
$issues[] = pht(
'Phabricator is configured with an email domain whitelist (in %s), so '.
'only users with a verified email address at one of these %s '.
'allowed domain(s) will be able to register an account: %s',
$domains_link,
phutil_count($domains_value),
phutil_tag('strong', array(), implode(', ', $domains_value)));
} else {
$issues[] = pht(
'Anyone who can browse to this Phabricator install will be able to '.
'register an account. To add email domain restrictions, configure '.
'%s.',
$domains_link);
}
if ($approval_value) {
$issues[] = pht(
'Administrative approvals are enabled (in %s), so all new users must '.
'have their accounts approved by an administrator.',
$approval_link);
} else {
$issues[] = pht(
'Administrative approvals are disabled, so users who register will '.
'be able to use their accounts immediately. To enable approvals, '.
'configure %s.',
$approval_link);
}
if (!$domains_value && !$approval_value) {
$severity = PHUIInfoView::SEVERITY_WARNING;
$issues[] = pht(
'You can safely ignore this warning if the install itself has '.
'access controls (for example, it is deployed on a VPN) or if all of '.
'the configured providers have access controls (for example, they are '.
'all private LDAP or OAuth servers).');
} else {
$severity = PHUIInfoView::SEVERITY_NOTICE;
}
$warning = id(new PHUIInfoView())
->setSeverity($severity)
->setErrors($issues);
- $image = id(new PHUIIconView())
- ->setIconFont('fa-plus');
$button = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::SIMPLE)
->setHref($this->getApplicationURI('config/new/'))
- ->setIcon($image)
+ ->setIcon('fa-plus')
->setDisabled(!$can_manage)
->setText(pht('Add Provider'));
$header = id(new PHUIHeaderView())
->setHeader(pht('Authentication Providers'))
->addActionLink($button);
$list->setFlush(true);
$list = id(new PHUIObjectBoxView())
->setHeader($header)
->setInfoView($warning)
->appendChild($list);
return $this->buildApplicationPage(
array(
$crumbs,
$list,
),
array(
'title' => pht('Authentication Providers'),
));
}
private function renderConfigLink($key) {
return phutil_tag(
'a',
array(
'href' => '/config/edit/'.$key.'/',
'target' => '_blank',
),
$key);
}
}
diff --git a/src/applications/auth/data/PhabricatorAuthInviteAction.php b/src/applications/auth/data/PhabricatorAuthInviteAction.php
index 10b625642a..8b6b61aa30 100644
--- a/src/applications/auth/data/PhabricatorAuthInviteAction.php
+++ b/src/applications/auth/data/PhabricatorAuthInviteAction.php
@@ -1,210 +1,210 @@
<?php
final class PhabricatorAuthInviteAction extends Phobject {
private $rawInput;
private $emailAddress;
private $userPHID;
private $issues = array();
private $action;
const ACTION_SEND = 'invite.send';
const ACTION_ERROR = 'invite.error';
const ACTION_IGNORE = 'invite.ignore';
const ISSUE_PARSE = 'invite.parse';
const ISSUE_DUPLICATE = 'invite.duplicate';
const ISSUE_UNVERIFIED = 'invite.unverified';
const ISSUE_VERIFIED = 'invite.verified';
const ISSUE_INVITED = 'invite.invited';
const ISSUE_ACCEPTED = 'invite.accepted';
public function getRawInput() {
return $this->rawInput;
}
public function getEmailAddress() {
return $this->emailAddress;
}
public function getUserPHID() {
return $this->userPHID;
}
public function getIssues() {
return $this->issues;
}
public function setAction($action) {
$this->action = $action;
return $this;
}
public function getAction() {
return $this->action;
}
public function willSend() {
return ($this->action == self::ACTION_SEND);
}
public function getShortNameForIssue($issue) {
$map = array(
self::ISSUE_PARSE => pht('Not a Valid Email Address'),
self::ISSUE_DUPLICATE => pht('Address Duplicated in Input'),
self::ISSUE_UNVERIFIED => pht('Unverified User Email'),
self::ISSUE_VERIFIED => pht('Verified User Email'),
self::ISSUE_INVITED => pht('Previously Invited'),
self::ISSUE_ACCEPTED => pht('Already Accepted Invite'),
);
return idx($map, $issue);
}
public function getShortNameForAction($action) {
$map = array(
self::ACTION_SEND => pht('Will Send Invite'),
self::ACTION_ERROR => pht('Address Error'),
self::ACTION_IGNORE => pht('Will Ignore Address'),
);
return idx($map, $action);
}
public function getIconForAction($action) {
switch ($action) {
case self::ACTION_SEND:
$icon = 'fa-envelope-o';
$color = 'green';
break;
case self::ACTION_IGNORE:
$icon = 'fa-ban';
$color = 'grey';
break;
case self::ACTION_ERROR:
$icon = 'fa-exclamation-triangle';
$color = 'red';
break;
}
return id(new PHUIIconView())
- ->setIconFont("{$icon} {$color}");
+ ->setIcon("{$icon} {$color}");
}
public static function newActionListFromAddresses(
PhabricatorUser $viewer,
array $addresses) {
$results = array();
foreach ($addresses as $address) {
$result = new PhabricatorAuthInviteAction();
$result->rawInput = $address;
$email = new PhutilEmailAddress($address);
$result->emailAddress = phutil_utf8_strtolower($email->getAddress());
if (!preg_match('/^\S+@\S+\.\S+\z/', $result->emailAddress)) {
$result->issues[] = self::ISSUE_PARSE;
}
$results[] = $result;
}
// Identify duplicates.
$address_groups = mgroup($results, 'getEmailAddress');
foreach ($address_groups as $address => $group) {
if (count($group) > 1) {
foreach ($group as $action) {
$action->issues[] = self::ISSUE_DUPLICATE;
}
}
}
// Identify addresses which are already in the system.
$addresses = mpull($results, 'getEmailAddress');
$email_objects = id(new PhabricatorUserEmail())->loadAllWhere(
'address IN (%Ls)',
$addresses);
$email_map = array();
foreach ($email_objects as $email_object) {
$address_key = phutil_utf8_strtolower($email_object->getAddress());
$email_map[$address_key] = $email_object;
}
// Identify outstanding invites.
$invites = id(new PhabricatorAuthInviteQuery())
->setViewer($viewer)
->withEmailAddresses($addresses)
->execute();
$invite_map = mpull($invites, null, 'getEmailAddress');
foreach ($results as $action) {
$email = idx($email_map, $action->getEmailAddress());
if ($email) {
if ($email->getUserPHID()) {
$action->userPHID = $email->getUserPHID();
if ($email->getIsVerified()) {
$action->issues[] = self::ISSUE_VERIFIED;
} else {
$action->issues[] = self::ISSUE_UNVERIFIED;
}
}
}
$invite = idx($invite_map, $action->getEmailAddress());
if ($invite) {
if ($invite->getAcceptedByPHID()) {
$action->issues[] = self::ISSUE_ACCEPTED;
if (!$action->userPHID) {
// This could be different from the user who is currently attached
// to the email address if the address was removed or added to a
// different account later. Only show it if the address was
// removed, since the current status is more up-to-date otherwise.
$action->userPHID = $invite->getAcceptedByPHID();
}
} else {
$action->issues[] = self::ISSUE_INVITED;
}
}
}
foreach ($results as $result) {
foreach ($result->getIssues() as $issue) {
switch ($issue) {
case self::ISSUE_PARSE:
$result->action = self::ACTION_ERROR;
break;
case self::ISSUE_ACCEPTED:
case self::ISSUE_VERIFIED:
$result->action = self::ACTION_IGNORE;
break;
}
}
if (!$result->action) {
$result->action = self::ACTION_SEND;
}
}
return $results;
}
public function sendInvite(PhabricatorUser $actor, $template) {
if (!$this->willSend()) {
throw new Exception(pht('Invite action is not a send action!'));
}
if (!preg_match('/{\$INVITE_URI}/', $template)) {
throw new Exception(pht('Invite template does not include invite URI!'));
}
PhabricatorWorker::scheduleTask(
'PhabricatorAuthInviteWorker',
array(
'address' => $this->getEmailAddress(),
'template' => $template,
'authorPHID' => $actor->getPHID(),
));
}
}
diff --git a/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php b/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php
index ee7f5756ae..e19a35fce6 100644
--- a/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php
+++ b/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php
@@ -1,110 +1,110 @@
<?php
final class PhabricatorAuthSSHKeyTableView extends AphrontView {
private $keys;
private $canEdit;
private $noDataString;
private $showTrusted;
private $showID;
public function setNoDataString($no_data_string) {
$this->noDataString = $no_data_string;
return $this;
}
public function setCanEdit($can_edit) {
$this->canEdit = $can_edit;
return $this;
}
public function setShowTrusted($show_trusted) {
$this->showTrusted = $show_trusted;
return $this;
}
public function setShowID($show_id) {
$this->showID = $show_id;
return $this;
}
public function setKeys(array $keys) {
assert_instances_of($keys, 'PhabricatorAuthSSHKey');
$this->keys = $keys;
return $this;
}
public function render() {
$keys = $this->keys;
$viewer = $this->getUser();
if ($this->canEdit) {
$delete_class = 'small grey button';
} else {
$delete_class = 'small grey button disabled';
}
$trusted_icon = id(new PHUIIconView())
- ->setIconFont('fa-star blue');
+ ->setIcon('fa-star blue');
$untrusted_icon = id(new PHUIIconView())
- ->setIconFont('fa-times grey');
+ ->setIcon('fa-times grey');
$rows = array();
foreach ($keys as $key) {
$rows[] = array(
$key->getID(),
javelin_tag(
'a',
array(
'href' => '/auth/sshkey/edit/'.$key->getID().'/',
'sigil' => 'workflow',
),
$key->getName()),
$key->getIsTrusted() ? $trusted_icon : $untrusted_icon,
$key->getKeyComment(),
$key->getKeyType(),
phabricator_datetime($key->getDateCreated(), $viewer),
javelin_tag(
'a',
array(
'href' => '/auth/sshkey/delete/'.$key->getID().'/',
'class' => $delete_class,
'sigil' => 'workflow',
),
pht('Delete')),
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString($this->noDataString)
->setHeaders(
array(
pht('ID'),
pht('Name'),
pht('Trusted'),
pht('Comment'),
pht('Type'),
pht('Added'),
null,
))
->setColumnVisibility(
array(
$this->showID,
true,
$this->showTrusted,
))
->setColumnClasses(
array(
'',
'wide pri',
'center',
'',
'',
'right',
'action',
));
return $table;
}
}
diff --git a/src/applications/base/controller/PhabricatorController.php b/src/applications/base/controller/PhabricatorController.php
index a1720bb5d5..1fe68abab3 100644
--- a/src/applications/base/controller/PhabricatorController.php
+++ b/src/applications/base/controller/PhabricatorController.php
@@ -1,590 +1,590 @@
<?php
abstract class PhabricatorController extends AphrontController {
private $handles;
public function shouldRequireLogin() {
return true;
}
public function shouldRequireAdmin() {
return false;
}
public function shouldRequireEnabledUser() {
return true;
}
public function shouldAllowPublic() {
return false;
}
public function shouldAllowPartialSessions() {
return false;
}
public function shouldRequireEmailVerification() {
return PhabricatorUserEmail::isEmailVerificationRequired();
}
public function shouldAllowRestrictedParameter($parameter_name) {
return false;
}
public function shouldRequireMultiFactorEnrollment() {
if (!$this->shouldRequireLogin()) {
return false;
}
if (!$this->shouldRequireEnabledUser()) {
return false;
}
if ($this->shouldAllowPartialSessions()) {
return false;
}
$user = $this->getRequest()->getUser();
if (!$user->getIsStandardUser()) {
return false;
}
return PhabricatorEnv::getEnvConfig('security.require-multi-factor-auth');
}
public function shouldAllowLegallyNonCompliantUsers() {
return false;
}
public function isGlobalDragAndDropUploadEnabled() {
return false;
}
public function willBeginExecution() {
$request = $this->getRequest();
if ($request->getUser()) {
// NOTE: Unit tests can set a user explicitly. Normal requests are not
// permitted to do this.
PhabricatorTestCase::assertExecutingUnitTests();
$user = $request->getUser();
} else {
$user = new PhabricatorUser();
$session_engine = new PhabricatorAuthSessionEngine();
$phsid = $request->getCookie(PhabricatorCookies::COOKIE_SESSION);
if (strlen($phsid)) {
$session_user = $session_engine->loadUserForSession(
PhabricatorAuthSession::TYPE_WEB,
$phsid);
if ($session_user) {
$user = $session_user;
}
} else {
// If the client doesn't have a session token, generate an anonymous
// session. This is used to provide CSRF protection to logged-out users.
$phsid = $session_engine->establishSession(
PhabricatorAuthSession::TYPE_WEB,
null,
$partial = false);
// This may be a resource request, in which case we just don't set
// the cookie.
if ($request->canSetCookies()) {
$request->setCookie(PhabricatorCookies::COOKIE_SESSION, $phsid);
}
}
if (!$user->isLoggedIn()) {
$user->attachAlternateCSRFString(PhabricatorHash::digest($phsid));
}
$request->setUser($user);
}
PhabricatorEnv::setLocaleCode($user->getTranslation());
$preferences = $user->loadPreferences();
if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
$dark_console = PhabricatorUserPreferences::PREFERENCE_DARK_CONSOLE;
if ($preferences->getPreference($dark_console) ||
PhabricatorEnv::getEnvConfig('darkconsole.always-on')) {
$console = new DarkConsoleCore();
$request->getApplicationConfiguration()->setConsole($console);
}
}
// NOTE: We want to set up the user first so we can render a real page
// here, but fire this before any real logic.
$restricted = array(
'code',
);
foreach ($restricted as $parameter) {
if ($request->getExists($parameter)) {
if (!$this->shouldAllowRestrictedParameter($parameter)) {
throw new Exception(
pht(
'Request includes restricted parameter "%s", but this '.
'controller ("%s") does not whitelist it. Refusing to '.
'serve this request because it might be part of a redirection '.
'attack.',
$parameter,
get_class($this)));
}
}
}
if ($this->shouldRequireEnabledUser()) {
if ($user->isLoggedIn() && !$user->getIsApproved()) {
$controller = new PhabricatorAuthNeedsApprovalController();
return $this->delegateToController($controller);
}
if ($user->getIsDisabled()) {
$controller = new PhabricatorDisabledUserController();
return $this->delegateToController($controller);
}
}
$auth_class = 'PhabricatorAuthApplication';
$auth_application = PhabricatorApplication::getByClass($auth_class);
// Require partial sessions to finish login before doing anything.
if (!$this->shouldAllowPartialSessions()) {
if ($user->hasSession() &&
$user->getSession()->getIsPartial()) {
$login_controller = new PhabricatorAuthFinishController();
$this->setCurrentApplication($auth_application);
return $this->delegateToController($login_controller);
}
}
// Check if the user needs to configure MFA.
$need_mfa = $this->shouldRequireMultiFactorEnrollment();
$have_mfa = $user->getIsEnrolledInMultiFactor();
if ($need_mfa && !$have_mfa) {
// Check if the cache is just out of date. Otherwise, roadblock the user
// and require MFA enrollment.
$user->updateMultiFactorEnrollment();
if (!$user->getIsEnrolledInMultiFactor()) {
$mfa_controller = new PhabricatorAuthNeedsMultiFactorController();
$this->setCurrentApplication($auth_application);
return $this->delegateToController($mfa_controller);
}
}
if ($this->shouldRequireLogin()) {
// This actually means we need either:
// - a valid user, or a public controller; and
// - permission to see the application; and
// - permission to see at least one Space if spaces are configured.
$allow_public = $this->shouldAllowPublic() &&
PhabricatorEnv::getEnvConfig('policy.allow-public');
// If this controller isn't public, and the user isn't logged in, require
// login.
if (!$allow_public && !$user->isLoggedIn()) {
$login_controller = new PhabricatorAuthStartController();
$this->setCurrentApplication($auth_application);
return $this->delegateToController($login_controller);
}
if ($user->isLoggedIn()) {
if ($this->shouldRequireEmailVerification()) {
if (!$user->getIsEmailVerified()) {
$controller = new PhabricatorMustVerifyEmailController();
$this->setCurrentApplication($auth_application);
return $this->delegateToController($controller);
}
}
}
// If Spaces are configured, require that the user have access to at
// least one. If we don't do this, they'll get confusing error messages
// later on.
$spaces = PhabricatorSpacesNamespaceQuery::getSpacesExist();
if ($spaces) {
$viewer_spaces = PhabricatorSpacesNamespaceQuery::getViewerSpaces(
$user);
if (!$viewer_spaces) {
$controller = new PhabricatorSpacesNoAccessController();
return $this->delegateToController($controller);
}
}
// If the user doesn't have access to the application, don't let them use
// any of its controllers. We query the application in order to generate
// a policy exception if the viewer doesn't have permission.
$application = $this->getCurrentApplication();
if ($application) {
id(new PhabricatorApplicationQuery())
->setViewer($user)
->withPHIDs(array($application->getPHID()))
->executeOne();
}
}
if (!$this->shouldAllowLegallyNonCompliantUsers()) {
$legalpad_class = 'PhabricatorLegalpadApplication';
$legalpad = id(new PhabricatorApplicationQuery())
->setViewer($user)
->withClasses(array($legalpad_class))
->withInstalled(true)
->execute();
$legalpad = head($legalpad);
$doc_query = id(new LegalpadDocumentQuery())
->setViewer($user)
->withSignatureRequired(1)
->needViewerSignatures(true);
if ($user->hasSession() &&
!$user->getSession()->getIsPartial() &&
!$user->getSession()->getSignedLegalpadDocuments() &&
$user->isLoggedIn() &&
$legalpad) {
$sign_docs = $doc_query->execute();
$must_sign_docs = array();
foreach ($sign_docs as $sign_doc) {
if (!$sign_doc->getUserSignature($user->getPHID())) {
$must_sign_docs[] = $sign_doc;
}
}
if ($must_sign_docs) {
$controller = new LegalpadDocumentSignController();
$this->getRequest()->setURIMap(array(
'id' => head($must_sign_docs)->getID(),
));
$this->setCurrentApplication($legalpad);
return $this->delegateToController($controller);
} else {
$engine = id(new PhabricatorAuthSessionEngine())
->signLegalpadDocuments($user, $sign_docs);
}
}
}
// NOTE: We do this last so that users get a login page instead of a 403
// if they need to login.
if ($this->shouldRequireAdmin() && !$user->getIsAdmin()) {
return new Aphront403Response();
}
}
public function getApplicationURI($path = '') {
if (!$this->getCurrentApplication()) {
throw new Exception(pht('No application!'));
}
return $this->getCurrentApplication()->getApplicationURI($path);
}
public function willSendResponse(AphrontResponse $response) {
$request = $this->getRequest();
if ($response instanceof AphrontDialogResponse) {
if (!$request->isAjax() && !$request->isQuicksand()) {
$dialog = $response->getDialog();
$title = $dialog->getTitle();
$short = $dialog->getShortTitle();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(coalesce($short, $title));
$page_content = array(
$crumbs,
$response->buildResponseString(),
);
$view = id(new PhabricatorStandardPageView())
->setRequest($request)
->setController($this)
->setDeviceReady(true)
->setTitle($title)
->appendChild($page_content);
$response = id(new AphrontWebpageResponse())
->setContent($view->render())
->setHTTPResponseCode($response->getHTTPResponseCode());
} else {
$response->getDialog()->setIsStandalone(true);
return id(new AphrontAjaxResponse())
->setContent(array(
'dialog' => $response->buildResponseString(),
));
}
} else if ($response instanceof AphrontRedirectResponse) {
if ($request->isAjax() || $request->isQuicksand()) {
return id(new AphrontAjaxResponse())
->setContent(
array(
'redirect' => $response->getURI(),
));
}
}
return $response;
}
/**
* WARNING: Do not call this in new code.
*
* @deprecated See "Handles Technical Documentation".
*/
protected function loadViewerHandles(array $phids) {
return id(new PhabricatorHandleQuery())
->setViewer($this->getRequest()->getUser())
->withPHIDs($phids)
->execute();
}
public function buildApplicationMenu() {
return null;
}
protected function buildApplicationCrumbs() {
$crumbs = array();
$application = $this->getCurrentApplication();
if ($application) {
$icon = $application->getFontIcon();
if (!$icon) {
$icon = 'fa-puzzle';
}
$crumbs[] = id(new PHUICrumbView())
->setHref($this->getApplicationURI())
->setName($application->getName())
->setIcon($icon);
}
$view = new PHUICrumbsView();
foreach ($crumbs as $crumb) {
$view->addCrumb($crumb);
}
return $view;
}
protected function hasApplicationCapability($capability) {
return PhabricatorPolicyFilter::hasCapability(
$this->getRequest()->getUser(),
$this->getCurrentApplication(),
$capability);
}
protected function requireApplicationCapability($capability) {
PhabricatorPolicyFilter::requireCapability(
$this->getRequest()->getUser(),
$this->getCurrentApplication(),
$capability);
}
protected function explainApplicationCapability(
$capability,
$positive_message,
$negative_message) {
$can_act = $this->hasApplicationCapability($capability);
if ($can_act) {
$message = $positive_message;
$icon_name = 'fa-play-circle-o lightgreytext';
} else {
$message = $negative_message;
$icon_name = 'fa-lock';
}
$icon = id(new PHUIIconView())
- ->setIconFont($icon_name);
+ ->setIcon($icon_name);
require_celerity_resource('policy-css');
$phid = $this->getCurrentApplication()->getPHID();
$explain_uri = "/policy/explain/{$phid}/{$capability}/";
$message = phutil_tag(
'div',
array(
'class' => 'policy-capability-explanation',
),
array(
$icon,
javelin_tag(
'a',
array(
'href' => $explain_uri,
'sigil' => 'workflow',
),
$message),
));
return array($can_act, $message);
}
public function getDefaultResourceSource() {
return 'phabricator';
}
/**
* Create a new @{class:AphrontDialogView} with defaults filled in.
*
* @return AphrontDialogView New dialog.
*/
public function newDialog() {
$submit_uri = new PhutilURI($this->getRequest()->getRequestURI());
$submit_uri = $submit_uri->getPath();
return id(new AphrontDialogView())
->setUser($this->getRequest()->getUser())
->setSubmitURI($submit_uri);
}
public function newPage() {
$page = id(new PhabricatorStandardPageView())
->setRequest($this->getRequest())
->setController($this)
->setDeviceReady(true);
$application = $this->getCurrentApplication();
if ($application) {
$page->setApplicationName($application->getName());
if ($application->getTitleGlyph()) {
$page->setGlyph($application->getTitleGlyph());
}
}
$viewer = $this->getRequest()->getUser();
if ($viewer) {
$page->setUser($viewer);
}
return $page;
}
public function newApplicationMenu() {
return id(new PHUIApplicationMenuView())
->setViewer($this->getRequest()->getUser());
}
protected function buildTransactionTimeline(
PhabricatorApplicationTransactionInterface $object,
PhabricatorApplicationTransactionQuery $query,
PhabricatorMarkupEngine $engine = null,
$render_data = array()) {
$viewer = $this->getRequest()->getUser();
$xaction = $object->getApplicationTransactionTemplate();
$view = $xaction->getApplicationTransactionViewObject();
$pager = id(new AphrontCursorPagerView())
->readFromRequest($this->getRequest())
->setURI(new PhutilURI(
'/transactions/showolder/'.$object->getPHID().'/'));
$xactions = $query
->setViewer($viewer)
->withObjectPHIDs(array($object->getPHID()))
->needComments(true)
->executeWithCursorPager($pager);
$xactions = array_reverse($xactions);
if ($engine) {
foreach ($xactions as $xaction) {
if ($xaction->getComment()) {
$engine->addObject(
$xaction->getComment(),
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
}
}
$engine->process();
$view->setMarkupEngine($engine);
}
$timeline = $view
->setUser($viewer)
->setObjectPHID($object->getPHID())
->setTransactions($xactions)
->setPager($pager)
->setRenderData($render_data)
->setQuoteTargetID($this->getRequest()->getStr('quoteTargetID'))
->setQuoteRef($this->getRequest()->getStr('quoteRef'));
$object->willRenderTimeline($timeline, $this->getRequest());
return $timeline;
}
public function buildApplicationCrumbsForEditEngine() {
// TODO: This is kind of gross, I'm bascially just making this public so
// I can use it in EditEngine. We could do this without making it public
// by using controller delegation, or make it properly public.
return $this->buildApplicationCrumbs();
}
/* -( Deprecated )--------------------------------------------------------- */
/**
* DEPRECATED. Use @{method:newPage}.
*/
public function buildStandardPageView() {
return $this->newPage();
}
/**
* DEPRECATED. Use @{method:newPage}.
*/
public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView();
$page->appendChild($view);
return $page->produceAphrontResponse();
}
/**
* DEPRECATED. Use @{method:newPage}.
*/
public function buildApplicationPage($view, array $options) {
$page = $this->newPage();
$title = PhabricatorEnv::getEnvConfig('phabricator.serious-business') ?
'Phabricator' :
pht('Bacon Ice Cream for Breakfast');
$page->setTitle(idx($options, 'title', $title));
if (idx($options, 'class')) {
$page->addClass($options['class']);
}
if (!($view instanceof AphrontSideNavFilterView)) {
$nav = new AphrontSideNavFilterView();
$nav->appendChild($view);
$view = $nav;
}
$page->appendChild($view);
$object_phids = idx($options, 'pageObjects', array());
if ($object_phids) {
$page->setPageObjectPHIDs($object_phids);
}
if (!idx($options, 'device', true)) {
$page->setDeviceReady(false);
}
$page->setShowFooter(idx($options, 'showFooter', true));
$page->setShowChrome(idx($options, 'chrome', true));
return $page->produceAphrontResponse();
}
}
diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
index 43386fe0d6..f423860a3b 100644
--- a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
+++ b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php
@@ -1,383 +1,381 @@
<?php
final class PhabricatorCalendarEventViewController
extends PhabricatorCalendarController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$sequence = $request->getURIData('sequence');
$timeline = null;
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$event) {
return new Aphront404Response();
}
if ($sequence) {
$result = $this->getEventAtIndexForGhostPHID(
$viewer,
$event->getPHID(),
$sequence);
if ($result) {
$parent_event = $event;
$event = $result;
$event->attachParentEvent($parent_event);
return id(new AphrontRedirectResponse())
->setURI('/E'.$result->getID());
} else if ($sequence && $event->getIsRecurring()) {
$parent_event = $event;
$event = $event->generateNthGhost($sequence, $viewer);
$event->attachParentEvent($parent_event);
} else if ($sequence) {
return new Aphront404Response();
}
$title = $event->getMonogram().' ('.$sequence.')';
$page_title = $title.' '.$event->getName();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, '/'.$event->getMonogram().'/'.$sequence);
} else {
$title = 'E'.$event->getID();
$page_title = $title.' '.$event->getName();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, '/E'.$event->getID());
}
if (!$event->getIsGhostEvent()) {
$timeline = $this->buildTransactionTimeline(
$event,
new PhabricatorCalendarEventTransactionQuery());
}
$header = $this->buildHeaderView($event);
$actions = $this->buildActionView($event);
$properties = $this->buildPropertyView($event);
$properties->setActionList($actions);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$add_comment_header = $is_serious
? pht('Add Comment')
: pht('Add To Plate');
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $event->getPHID());
if ($sequence) {
$comment_uri = $this->getApplicationURI(
'/event/comment/'.$event->getID().'/'.$sequence.'/');
} else {
$comment_uri = $this->getApplicationURI(
'/event/comment/'.$event->getID().'/');
}
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($event->getPHID())
->setDraft($draft)
->setHeaderText($add_comment_header)
->setAction($comment_uri)
->setSubmitButtonName(pht('Add Comment'));
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$timeline,
$add_comment_form,
),
array(
'title' => $page_title,
'pageObjects' => array($event->getPHID()),
));
}
private function buildHeaderView(PhabricatorCalendarEvent $event) {
$viewer = $this->getRequest()->getUser();
$id = $event->getID();
$is_cancelled = $event->getIsCancelled();
$icon = $is_cancelled ? ('fa-times') : ('fa-calendar');
$color = $is_cancelled ? ('grey') : ('green');
$status = $is_cancelled ? pht('Cancelled') : pht('Active');
$invite_status = $event->getUserInviteStatus($viewer->getPHID());
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
$is_invite_pending = ($invite_status == $status_invited);
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($event->getName())
->setStatus($icon, $color, $status)
->setPolicyObject($event);
if ($is_invite_pending) {
$decline_button = id(new PHUIButtonView())
->setTag('a')
- ->setIcon(id(new PHUIIconView())
- ->setIconFont('fa-times grey'))
+ ->setIcon('fa-times grey')
->setHref($this->getApplicationURI("/event/decline/{$id}/"))
->setWorkflow(true)
->setText(pht('Decline'));
$accept_button = id(new PHUIButtonView())
->setTag('a')
- ->setIcon(id(new PHUIIconView())
- ->setIconFont('fa-check green'))
+ ->setIcon('fa-check green')
->setHref($this->getApplicationURI("/event/accept/{$id}/"))
->setWorkflow(true)
->setText(pht('Accept'));
$header->addActionLink($decline_button)
->addActionLink($accept_button);
}
return $header;
}
private function buildActionView(PhabricatorCalendarEvent $event) {
$viewer = $this->getRequest()->getUser();
$id = $event->getID();
$is_cancelled = $event->getIsCancelled();
$is_attending = $event->getIsUserAttending($viewer->getPHID());
$actions = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($event);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$event,
PhabricatorPolicyCapability::CAN_EDIT);
$edit_label = false;
$edit_uri = false;
if ($event->getIsGhostEvent()) {
$index = $event->getSequenceIndex();
$edit_label = pht('Edit This Instance');
$edit_uri = "event/edit/{$id}/{$index}/";
} else if ($event->getIsRecurrenceException()) {
$edit_label = pht('Edit This Instance');
$edit_uri = "event/edit/{$id}/";
} else {
$edit_label = pht('Edit');
$edit_uri = "event/edit/{$id}/";
}
if ($edit_label && $edit_uri) {
$actions->addAction(
id(new PhabricatorActionView())
->setName($edit_label)
->setIcon('fa-pencil')
->setHref($this->getApplicationURI($edit_uri))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
}
if ($is_attending) {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Decline Event'))
->setIcon('fa-user-times')
->setHref($this->getApplicationURI("event/join/{$id}/"))
->setWorkflow(true));
} else {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Join Event'))
->setIcon('fa-user-plus')
->setHref($this->getApplicationURI("event/join/{$id}/"))
->setWorkflow(true));
}
$cancel_uri = $this->getApplicationURI("event/cancel/{$id}/");
if ($event->getIsGhostEvent()) {
$index = $event->getSequenceIndex();
$can_reinstate = $event->getIsParentCancelled();
$cancel_label = pht('Cancel This Instance');
$reinstate_label = pht('Reinstate This Instance');
$cancel_disabled = (!$can_edit || $can_reinstate);
$cancel_uri = $this->getApplicationURI("event/cancel/{$id}/{$index}/");
} else if ($event->getIsRecurrenceException()) {
$can_reinstate = $event->getIsParentCancelled();
$cancel_label = pht('Cancel This Instance');
$reinstate_label = pht('Reinstate This Instance');
$cancel_disabled = (!$can_edit || $can_reinstate);
} else if ($event->getIsRecurrenceParent()) {
$cancel_label = pht('Cancel Recurrence');
$reinstate_label = pht('Reinstate Recurrence');
$cancel_disabled = !$can_edit;
} else {
$cancel_label = pht('Cancel Event');
$reinstate_label = pht('Reinstate Event');
$cancel_disabled = !$can_edit;
}
if ($is_cancelled) {
$actions->addAction(
id(new PhabricatorActionView())
->setName($reinstate_label)
->setIcon('fa-plus')
->setHref($cancel_uri)
->setDisabled($cancel_disabled)
->setWorkflow(true));
} else {
$actions->addAction(
id(new PhabricatorActionView())
->setName($cancel_label)
->setIcon('fa-times')
->setHref($cancel_uri)
->setDisabled($cancel_disabled)
->setWorkflow(true));
}
return $actions;
}
private function buildPropertyView(PhabricatorCalendarEvent $event) {
$viewer = $this->getRequest()->getUser();
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($event);
if ($event->getIsAllDay()) {
$date_start = phabricator_date($event->getDateFrom(), $viewer);
$date_end = phabricator_date($event->getDateTo(), $viewer);
if ($date_start == $date_end) {
$properties->addProperty(
pht('Time'),
phabricator_date($event->getDateFrom(), $viewer));
} else {
$properties->addProperty(
pht('Starts'),
phabricator_date($event->getDateFrom(), $viewer));
$properties->addProperty(
pht('Ends'),
phabricator_date($event->getDateTo(), $viewer));
}
} else {
$properties->addProperty(
pht('Starts'),
phabricator_datetime($event->getDateFrom(), $viewer));
$properties->addProperty(
pht('Ends'),
phabricator_datetime($event->getDateTo(), $viewer));
}
if ($event->getIsRecurring()) {
$properties->addProperty(
pht('Recurs'),
ucwords(idx($event->getRecurrenceFrequency(), 'rule')));
if ($event->getRecurrenceEndDate()) {
$properties->addProperty(
pht('Recurrence Ends'),
phabricator_datetime($event->getRecurrenceEndDate(), $viewer));
}
if ($event->getInstanceOfEventPHID()) {
$properties->addProperty(
pht('Recurrence of Event'),
pht('%s of %s',
$event->getSequenceIndex(),
$viewer->renderHandle($event->getInstanceOfEventPHID())->render()));
}
}
$properties->addProperty(
pht('Host'),
$viewer->renderHandle($event->getUserPHID()));
$invitees = $event->getInvitees();
foreach ($invitees as $key => $invitee) {
if ($invitee->isUninvited()) {
unset($invitees[$key]);
}
}
if ($invitees) {
$invitee_list = new PHUIStatusListView();
$icon_invited = PHUIStatusItemView::ICON_OPEN;
$icon_attending = PHUIStatusItemView::ICON_ACCEPT;
$icon_declined = PHUIStatusItemView::ICON_REJECT;
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
$status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
$status_declined = PhabricatorCalendarEventInvitee::STATUS_DECLINED;
$icon_map = array(
$status_invited => $icon_invited,
$status_attending => $icon_attending,
$status_declined => $icon_declined,
);
$icon_color_map = array(
$status_invited => null,
$status_attending => 'green',
$status_declined => 'red',
);
foreach ($invitees as $invitee) {
$item = new PHUIStatusItemView();
$invitee_phid = $invitee->getInviteePHID();
$status = $invitee->getStatus();
$target = $viewer->renderHandle($invitee_phid);
$icon = $icon_map[$status];
$icon_color = $icon_color_map[$status];
$item->setIcon($icon, $icon_color)
->setTarget($target);
$invitee_list->addItem($item);
}
} else {
$invitee_list = phutil_tag(
'em',
array(),
pht('None'));
}
$properties->addProperty(
pht('Invitees'),
$invitee_list);
$properties->invokeWillRenderEvent();
$properties->addProperty(
pht('Icon'),
id(new PhabricatorCalendarIconSet())
->getIconLabel($event->getIcon()));
if (strlen($event->getDescription())) {
$description = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($event->getDescription()),
'default',
$viewer);
$properties->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$properties->addTextContent($description);
}
return $properties;
}
}
diff --git a/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php b/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php
index 8084356ced..fe505ecf60 100644
--- a/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php
+++ b/src/applications/chatlog/controller/PhabricatorChatLogChannelLogController.php
@@ -1,324 +1,324 @@
<?php
final class PhabricatorChatLogChannelLogController
extends PhabricatorChatLogController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('channelID');
$uri = clone $request->getRequestURI();
$uri->setQueryParams(array());
$pager = new AphrontCursorPagerView();
$pager->setURI($uri);
$pager->setPageSize(250);
$query = id(new PhabricatorChatLogQuery())
->setViewer($viewer)
->withChannelIDs(array($id));
$channel = id(new PhabricatorChatLogChannelQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$channel) {
return new Aphront404Response();
}
list($after, $before, $map) = $this->getPagingParameters($request, $query);
$pager->setAfterID($after);
$pager->setBeforeID($before);
$logs = $query->executeWithCursorPager($pager);
// Show chat logs oldest-first.
$logs = array_reverse($logs);
// Divide all the logs into blocks, where a block is the same author saying
// several things in a row. A block ends when another user speaks, or when
// two minutes pass without the author speaking.
$blocks = array();
$block = null;
$last_author = null;
$last_epoch = null;
foreach ($logs as $log) {
$this_author = $log->getAuthor();
$this_epoch = $log->getEpoch();
// Decide whether we should start a new block or not.
$new_block = ($this_author !== $last_author) ||
($this_epoch - (60 * 2) > $last_epoch);
if ($new_block) {
if ($block) {
$blocks[] = $block;
}
$block = array(
'id' => $log->getID(),
'epoch' => $this_epoch,
'author' => $this_author,
'logs' => array($log),
);
} else {
$block['logs'][] = $log;
}
$last_author = $this_author;
$last_epoch = $this_epoch;
}
if ($block) {
$blocks[] = $block;
}
// Figure out CSS classes for the blocks. We alternate colors between
// lines, and highlight the entire block which contains the target ID or
// date, if applicable.
foreach ($blocks as $key => $block) {
$classes = array();
if ($key % 2) {
$classes[] = 'alternate';
}
$ids = mpull($block['logs'], 'getID', 'getID');
if (array_intersect_key($ids, $map)) {
$classes[] = 'highlight';
}
$blocks[$key]['class'] = $classes ? implode(' ', $classes) : null;
}
require_celerity_resource('phabricator-chatlog-css');
$out = array();
foreach ($blocks as $block) {
$author = $block['author'];
$author = id(new PhutilUTF8StringTruncator())
->setMaximumGlyphs(18)
->truncateString($author);
$author = phutil_tag('td', array('class' => 'author'), $author);
$href = $uri->alter('at', $block['id']);
$timestamp = $block['epoch'];
$timestamp = phabricator_datetime($timestamp, $viewer);
$timestamp = phutil_tag(
'a',
array(
'href' => $href,
'class' => 'timestamp',
),
$timestamp);
$message = mpull($block['logs'], 'getMessage');
$message = implode("\n", $message);
$message = phutil_tag(
'td',
array(
'class' => 'message',
),
array(
$timestamp,
$message,
));
$out[] = phutil_tag(
'tr',
array(
'class' => $block['class'],
),
array(
$author,
$message,
));
}
$links = array();
$first_uri = $pager->getFirstPageURI();
if ($first_uri) {
$links[] = phutil_tag(
'a',
array(
'href' => $first_uri,
),
"\xC2\xAB ".pht('Newest'));
}
$prev_uri = $pager->getPrevPageURI();
if ($prev_uri) {
$links[] = phutil_tag(
'a',
array(
'href' => $prev_uri,
),
"\xE2\x80\xB9 ".pht('Newer'));
}
$next_uri = $pager->getNextPageURI();
if ($next_uri) {
$links[] = phutil_tag(
'a',
array(
'href' => $next_uri,
),
pht('Older')." \xE2\x80\xBA");
}
$pager_bottom = phutil_tag(
'div',
array('class' => 'phabricator-chat-log-pager-bottom'),
$links);
$crumbs = $this
->buildApplicationCrumbs()
->addTextCrumb($channel->getChannelName(), $uri);
$form = id(new AphrontFormView())
->setUser($viewer)
->setMethod('GET')
->setAction($uri)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Date'))
->setName('date')
->setValue($request->getStr('date')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Jump')));
$table = phutil_tag(
'table',
array(
'class' => 'phabricator-chat-log',
),
$out);
$log = phutil_tag(
'div',
array(
'class' => 'phabricator-chat-log-panel',
),
$table);
$jump_link = id(new PHUIButtonView())
->setTag('a')
->setHref('#latest')
->setText(pht('Jump to Bottom'))
- ->setIconFont('fa-arrow-circle-down');
+ ->setIcon('fa-arrow-circle-down');
$jump_target = phutil_tag(
'div',
array(
'id' => 'latest',
));
$content = phutil_tag(
'div',
array(
'class' => 'phabricator-chat-log-wrap',
),
array(
$log,
$jump_target,
$pager_bottom,
));
$header = id(new PHUIHeaderView())
->setHeader($channel->getChannelName())
->setSubHeader($channel->getServiceName())
->addActionLink($jump_link);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setCollapsed(true)
->appendChild($content);
$box->setShowHide(
pht('Search Dates'),
pht('Hide Dates'),
$form,
'#');
return $this->buildApplicationPage(
array(
$crumbs,
$box,
),
array(
'title' => pht('Channel Log'),
));
}
/**
* From request parameters, figure out where we should jump to in the log.
* We jump to either a date or log ID, but load a few lines of context before
* it so the user can see the nearby conversation.
*/
private function getPagingParameters(
AphrontRequest $request,
PhabricatorChatLogQuery $query) {
$viewer = $request->getViewer();
$at_id = $request->getInt('at');
$at_date = $request->getStr('date');
$context_log = null;
$map = array();
$query = clone $query;
$query->setLimit(8);
if ($at_id) {
// Jump to the log in question, and load a few lines of context before
// it.
$context_logs = $query
->setAfterID($at_id)
->execute();
$context_log = last($context_logs);
$map = array(
$at_id => true,
);
} else if ($at_date) {
$timestamp = PhabricatorTime::parseLocalTime($at_date, $viewer);
if ($timestamp) {
$context_logs = $query
->withMaximumEpoch($timestamp)
->execute();
$context_log = last($context_logs);
$target_log = head($context_logs);
if ($target_log) {
$map = array(
$target_log->getID() => true,
);
}
}
}
if ($context_log) {
$after = null;
$before = $context_log->getID() - 1;
} else {
$after = $request->getInt('after');
$before = $request->getInt('before');
}
return array($after, $before, $map);
}
}
diff --git a/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php b/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php
index 7f1adf1c1a..f5d203c772 100644
--- a/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php
+++ b/src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php
@@ -1,204 +1,204 @@
<?php
final class PhabricatorConduitLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Conduit Logs');
}
public function getApplicationClassName() {
return 'PhabricatorConduitApplication';
}
public function newQuery() {
return new PhabricatorConduitLogQuery();
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['callerPHIDs']) {
$query->withCallerPHIDs($map['callerPHIDs']);
}
if ($map['methods']) {
$query->withMethods($map['methods']);
}
if ($map['statuses']) {
$query->withMethodStatuses($map['statuses']);
}
return $query;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorUsersSearchField())
->setKey('callerPHIDs')
->setLabel(pht('Methods'))
->setAliases(array('caller', 'callers'))
->setDescription(pht('Find calls by specific users.')),
id(new PhabricatorSearchStringListField())
->setKey('methods')
->setLabel(pht('Methods'))
->setDescription(pht('Find calls to specific methods.')),
id(new PhabricatorSearchCheckboxesField())
->setKey('statuses')
->setLabel(pht('Method Status'))
->setAliases(array('status'))
->setDescription(
pht('Find calls to stable, unstable, or deprecated methods.'))
->setOptions(ConduitAPIMethod::getMethodStatusMap()),
);
}
protected function getURI($path) {
return '/conduit/log/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
$viewer = $this->requireViewer();
if ($viewer->isLoggedIn()) {
$names['viewer'] = pht('My Calls');
$names['viewerdeprecated'] = pht('My Deprecated Calls');
}
$names['all'] = pht('All Call Logs');
$names['deprecated'] = pht('Deprecated Call Logs');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
$viewer = $this->requireViewer();
$viewer_phid = $viewer->getPHID();
$deprecated = array(
ConduitAPIMethod::METHOD_STATUS_DEPRECATED,
);
switch ($query_key) {
case 'viewer':
return $query
->setParameter('callerPHIDs', array($viewer_phid));
case 'viewerdeprecated':
return $query
->setParameter('callerPHIDs', array($viewer_phid))
->setParameter('statuses', $deprecated);
case 'deprecated':
return $query
->setParameter('statuses', $deprecated);
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $logs,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($logs, 'PhabricatorConduitMethodCallLog');
$viewer = $this->requireViewer();
$methods = id(new PhabricatorConduitMethodQuery())
->setViewer($viewer)
->execute();
$methods = mpull($methods, null, 'getAPIMethodName');
Javelin::initBehavior('phabricator-tooltips');
$viewer = $this->requireViewer();
$rows = array();
foreach ($logs as $log) {
$caller_phid = $log->getCallerPHID();
if ($caller_phid) {
$caller = $viewer->renderHandle($caller_phid);
} else {
$caller = null;
}
$method = idx($methods, $log->getMethod());
if ($method) {
$method_status = $method->getMethodStatus();
} else {
$method_status = null;
}
switch ($method_status) {
case ConduitAPIMethod::METHOD_STATUS_STABLE:
$status = null;
break;
case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
$status = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle yellow')
+ ->setIcon('fa-exclamation-triangle yellow')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Unstable'),
));
break;
case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
$status = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle red')
+ ->setIcon('fa-exclamation-triangle red')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Deprecated'),
));
break;
default:
$status = id(new PHUIIconView())
- ->setIconFont('fa-question-circle')
+ ->setIcon('fa-question-circle')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Unknown ("%s")', $status),
));
break;
}
$rows[] = array(
$status,
$log->getMethod(),
$caller,
$log->getError(),
pht('%s us', new PhutilNumber($log->getDuration())),
phabricator_datetime($log->getDateCreated(), $viewer),
);
}
$table = id(new AphrontTableView($rows))
->setHeaders(
array(
null,
pht('Method'),
pht('Caller'),
pht('Error'),
pht('Duration'),
pht('Date'),
))
->setColumnClasses(
array(
null,
'pri',
null,
'wide right',
null,
null,
));
return id(new PhabricatorApplicationSearchResultView())
->setTable($table)
->setNoDataString(pht('No matching calls in log.'));
}
}
diff --git a/src/applications/conduit/settings/PhabricatorConduitTokensSettingsPanel.php b/src/applications/conduit/settings/PhabricatorConduitTokensSettingsPanel.php
index b41e689d37..6f315783cc 100644
--- a/src/applications/conduit/settings/PhabricatorConduitTokensSettingsPanel.php
+++ b/src/applications/conduit/settings/PhabricatorConduitTokensSettingsPanel.php
@@ -1,120 +1,116 @@
<?php
final class PhabricatorConduitTokensSettingsPanel
extends PhabricatorSettingsPanel {
public function isEditableByAdministrators() {
return true;
}
public function getPanelKey() {
return 'apitokens';
}
public function getPanelName() {
return pht('Conduit API Tokens');
}
public function getPanelGroup() {
return pht('Sessions and Logs');
}
public function isEnabled() {
if ($this->getUser()->getIsMailingList()) {
return false;
}
return true;
}
public function processRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$user = $this->getUser();
$tokens = id(new PhabricatorConduitTokenQuery())
->setViewer($viewer)
->withObjectPHIDs(array($user->getPHID()))
->withExpired(false)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->execute();
$rows = array();
foreach ($tokens as $token) {
$rows[] = array(
javelin_tag(
'a',
array(
'href' => '/conduit/token/edit/'.$token->getID().'/',
'sigil' => 'workflow',
),
$token->getPublicTokenName()),
PhabricatorConduitToken::getTokenTypeName($token->getTokenType()),
phabricator_datetime($token->getDateCreated(), $viewer),
($token->getExpires()
? phabricator_datetime($token->getExpires(), $viewer)
: pht('Never')),
javelin_tag(
'a',
array(
'class' => 'button small grey',
'href' => '/conduit/token/terminate/'.$token->getID().'/',
'sigil' => 'workflow',
),
pht('Terminate')),
);
}
$table = new AphrontTableView($rows);
$table->setNoDataString(pht("You don't have any active API tokens."));
$table->setHeaders(
array(
pht('Token'),
pht('Type'),
pht('Created'),
pht('Expires'),
null,
));
$table->setColumnClasses(
array(
'wide pri',
'',
'right',
'right',
'action',
));
- $generate_icon = id(new PHUIIconView())
- ->setIconFont('fa-plus');
$generate_button = id(new PHUIButtonView())
->setText(pht('Generate API Token'))
->setHref('/conduit/token/edit/?objectPHID='.$user->getPHID())
->setTag('a')
->setWorkflow(true)
- ->setIcon($generate_icon);
+ ->setIcon('fa-plus');
- $terminate_icon = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle');
$terminate_button = id(new PHUIButtonView())
->setText(pht('Terminate All Tokens'))
->setHref('/conduit/token/terminate/?objectPHID='.$user->getPHID())
->setTag('a')
->setWorkflow(true)
- ->setIcon($terminate_icon);
+ ->setIcon('fa-exclamation-triangle');
$header = id(new PHUIHeaderView())
->setHeader(pht('Active API Tokens'))
->addActionLink($generate_button)
->addActionLink($terminate_button);
$panel = id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
return $panel;
}
}
diff --git a/src/applications/config/controller/PhabricatorConfigCacheController.php b/src/applications/config/controller/PhabricatorConfigCacheController.php
index 90c1b3a2fd..67fbf6e120 100644
--- a/src/applications/config/controller/PhabricatorConfigCacheController.php
+++ b/src/applications/config/controller/PhabricatorConfigCacheController.php
@@ -1,186 +1,183 @@
<?php
final class PhabricatorConfigCacheController
extends PhabricatorConfigController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$nav = $this->buildSideNavView();
$nav->selectFilter('cache/');
$title = pht('Cache Status');
$crumbs = $this
->buildApplicationCrumbs()
->addTextCrumb(pht('Cache Status'));
$code_box = $this->renderCodeBox();
$data_box = $this->renderDataBox();
$nav->appendChild(
array(
$crumbs,
$code_box,
$data_box,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
));
}
private function renderCodeBox() {
$cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();
$properties = id(new PHUIPropertyListView());
$this->renderCommonProperties($properties, $cache);
- $purge_icon = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle');
-
$purge_button = id(new PHUIButtonView())
->setText(pht('Purge Caches'))
->setHref('/config/cache/purge/')
->setTag('a')
->setWorkflow(true)
- ->setIcon($purge_icon);
+ ->setIcon('fa-exclamation-triangle');
$header = id(new PHUIHeaderView())
->setHeader(pht('Opcode Cache'))
->addActionLink($purge_button);
return id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
}
private function renderDataBox() {
$cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
$properties = id(new PHUIPropertyListView());
$this->renderCommonProperties($properties, $cache);
$table = null;
if ($cache->getName() !== null) {
$total_memory = $cache->getTotalMemory();
$summary = $cache->getCacheSummary();
$summary = isort($summary, 'total');
$summary = array_reverse($summary, true);
$rows = array();
foreach ($summary as $key => $info) {
$rows[] = array(
$key,
pht('%s', new PhutilNumber($info['count'])),
phutil_format_bytes($info['max']),
phutil_format_bytes($info['total']),
sprintf('%.1f%%', (100 * ($info['total'] / $total_memory))),
);
}
$table = id(new AphrontTableView($rows))
->setHeaders(
array(
pht('Pattern'),
pht('Count'),
pht('Largest'),
pht('Total'),
pht('Usage'),
))
->setColumnClasses(
array(
'wide',
'n',
'n',
'n',
'n',
));
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Data Cache'))
->addPropertyList($properties)
->setTable($table);
}
private function renderCommonProperties(
PHUIPropertyListView $properties,
PhabricatorCacheSpec $cache) {
if ($cache->getName() !== null) {
$name = $this->renderYes($cache->getName());
} else {
$name = $this->renderNo(pht('None'));
}
$properties->addProperty(pht('Cache'), $name);
if ($cache->getIsEnabled()) {
$enabled = $this->renderYes(pht('Enabled'));
} else {
$enabled = $this->renderNo(pht('Not Enabled'));
}
$properties->addProperty(pht('Enabled'), $enabled);
$version = $cache->getVersion();
if ($version) {
$properties->addProperty(pht('Version'), $this->renderInfo($version));
}
if ($cache->getName() === null) {
return;
}
$mem_total = $cache->getTotalMemory();
$mem_used = $cache->getUsedMemory();
if ($mem_total) {
$percent = 100 * ($mem_used / $mem_total);
$properties->addProperty(
pht('Memory Usage'),
pht(
'%s of %s',
phutil_tag('strong', array(), sprintf('%.1f%%', $percent)),
phutil_format_bytes($mem_total)));
}
$entry_count = $cache->getEntryCount();
if ($entry_count !== null) {
$properties->addProperty(
pht('Cache Entries'),
pht('%s', new PhutilNumber($entry_count)));
}
}
private function renderYes($info) {
return array(
- id(new PHUIIconView())->setIconFont('fa-check', 'green'),
+ id(new PHUIIconView())->setIcon('fa-check', 'green'),
' ',
$info,
);
}
private function renderNo($info) {
return array(
- id(new PHUIIconView())->setIconFont('fa-times-circle', 'red'),
+ id(new PHUIIconView())->setIcon('fa-times-circle', 'red'),
' ',
$info,
);
}
private function renderInfo($info) {
return array(
- id(new PHUIIconView())->setIconFont('fa-info-circle', 'grey'),
+ id(new PHUIIconView())->setIcon('fa-info-circle', 'grey'),
' ',
$info,
);
}
}
diff --git a/src/applications/config/controller/PhabricatorConfigDatabaseController.php b/src/applications/config/controller/PhabricatorConfigDatabaseController.php
index ccd18367b2..225312a52f 100644
--- a/src/applications/config/controller/PhabricatorConfigDatabaseController.php
+++ b/src/applications/config/controller/PhabricatorConfigDatabaseController.php
@@ -1,81 +1,79 @@
<?php
abstract class PhabricatorConfigDatabaseController
extends PhabricatorConfigController {
protected function buildSchemaQuery() {
$conf = PhabricatorEnv::newObjectFromConfig(
'mysql.configuration-provider',
array($dao = null, 'w'));
$api = id(new PhabricatorStorageManagementAPI())
->setUser($conf->getUser())
->setHost($conf->getHost())
->setPort($conf->getPort())
->setNamespace(PhabricatorLiskDAO::getDefaultStorageNamespace())
->setPassword($conf->getPassword());
$query = id(new PhabricatorConfigSchemaQuery())
->setAPI($api);
return $query;
}
protected function renderIcon($status) {
switch ($status) {
case PhabricatorConfigStorageSchema::STATUS_OKAY:
$icon = 'fa-check-circle green';
break;
case PhabricatorConfigStorageSchema::STATUS_WARN:
$icon = 'fa-exclamation-circle yellow';
break;
case PhabricatorConfigStorageSchema::STATUS_FAIL:
default:
$icon = 'fa-times-circle red';
break;
}
return id(new PHUIIconView())
- ->setIconFont($icon);
+ ->setIcon($icon);
}
protected function renderAttr($attr, $issue) {
if ($issue) {
return phutil_tag(
'span',
array(
'style' => 'color: #aa0000;',
),
$attr);
} else {
return $attr;
}
}
protected function renderBoolean($value) {
if ($value === null) {
return '';
} else if ($value === true) {
return pht('Yes');
} else {
return pht('No');
}
}
protected function buildHeaderWithDocumentationLink($title) {
$doc_link = PhabricatorEnv::getDoclink('Managing Storage Adjustments');
return id(new PHUIHeaderView())
->setHeader($title)
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-book'))
+ ->setIcon('fa-book')
->setHref($doc_link)
->setText(pht('Learn More')));
}
}
diff --git a/src/applications/config/controller/PhabricatorConfigWelcomeController.php b/src/applications/config/controller/PhabricatorConfigWelcomeController.php
index 11e07b96c0..e2d868082a 100644
--- a/src/applications/config/controller/PhabricatorConfigWelcomeController.php
+++ b/src/applications/config/controller/PhabricatorConfigWelcomeController.php
@@ -1,411 +1,411 @@
<?php
final class PhabricatorConfigWelcomeController
extends PhabricatorConfigController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$nav = $this->buildSideNavView();
$nav->selectFilter('welcome/');
$title = pht('Welcome');
$crumbs = $this
->buildApplicationCrumbs()
->addTextCrumb(pht('Welcome'));
$nav->setCrumbs($crumbs);
$nav->appendChild($this->buildWelcomeScreen($request));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
));
}
public function buildWelcomeScreen(AphrontRequest $request) {
$viewer = $request->getUser();
$this->requireResource('config-welcome-css');
$content = pht(
"=== Install Phabricator ===\n\n".
"You have successfully installed Phabricator. This screen will guide ".
"you through configuration and orientation. ".
"These steps are optional, and you can go through them in any order. ".
"If you want to get back to this screen later on, you can find it in ".
"the **Config** application under **Welcome Screen**.");
$setup = array();
$setup[] = $this->newItem(
$request,
'fa-check-square-o green',
$content);
$issues_resolved = !PhabricatorSetupCheck::getOpenSetupIssueKeys();
$setup_href = PhabricatorEnv::getURI('/config/issue/');
if ($issues_resolved) {
$content = pht(
"=== Resolve Setup Issues ===\n\n".
"You've resolved (or ignored) all outstanding setup issues. ".
"You can review issues in the **Config** application, under ".
"**[[ %s | Setup Issues ]]**.",
$setup_href);
$icon = 'fa-check-square-o green';
} else {
$content = pht(
"=== Resolve Setup Issues ===\n\n".
"You have some unresolved setup issues to take care of. Click ".
"the link in the yellow banner at the top of the screen to see ".
"them, or find them in the **Config** application under ".
"**[[ %s | Setup Issues ]]**. ".
"Although most setup issues should be resolved, sometimes an issue ".
"is not applicable to an install. ".
"If you don't intend to fix a setup issue (or don't want to fix ".
"it for now), you can use the \"Ignore\" action to mark it as ".
"something you don't plan to deal with.",
$setup_href);
$icon = 'fa-warning red';
}
$setup[] = $this->newItem(
$request,
$icon,
$content);
$configs = id(new PhabricatorAuthProviderConfigQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->execute();
$auth_href = PhabricatorEnv::getURI('/auth/');
$have_auth = (bool)$configs;
if ($have_auth) {
$content = pht(
"=== Login and Registration ===\n\n".
"You've configured at least one authentication provider, so users ".
"can register or log in. ".
"To configure more providers or adjust settings, use the ".
"**[[ %s | Auth Application ]]**.",
$auth_href);
$icon = 'fa-check-square-o green';
} else {
$content = pht(
"=== Login and Registration ===\n\n".
"You haven't configured any authentication providers yet. ".
"Authentication providers allow users to register accounts and ".
"log in to Phabricator. You can configure Phabricator to accept ".
"credentials like username and password, LDAP, or Google OAuth. ".
"You can configure authentication using the ".
"**[[ %s | Auth Application ]]**.",
$auth_href);
$icon = 'fa-warning red';
}
$setup[] = $this->newItem(
$request,
$icon,
$content);
$config_href = PhabricatorEnv::getURI('/config/');
// Just load any config value at all; if one exists the install has figured
// out how to configure things.
$have_config = (bool)id(new PhabricatorConfigEntry())->loadAllWhere(
'1 = 1 LIMIT 1');
if ($have_config) {
$content = pht(
"=== Configure Phabricator Settings ===\n\n".
"You've configured at least one setting from the web interface. ".
"To configure more settings later, use the ".
"**[[ %s | Config Application ]]**.",
$config_href);
$icon = 'fa-check-square-o green';
} else {
$content = pht(
"=== Configure Phabricator Settings ===\n\n".
'Many aspects of Phabricator are configurable. To explore and '.
'adjust settings, use the **[[ %s | Config Application ]]**.',
$config_href);
$icon = 'fa-info-circle';
}
$setup[] = $this->newItem(
$request,
$icon,
$content);
$settings_href = PhabricatorEnv::getURI('/settings/');
$prefs = $viewer->loadPreferences()->getPreferences();
$have_settings = !empty($prefs);
if ($have_settings) {
$content = pht(
"=== Adjust Account Settings ===\n\n".
"You've adjusted at least one setting on your account. ".
"To make more adjustments, visit the ".
"**[[ %s | Settings Application ]]**.",
$settings_href);
$icon = 'fa-check-square-o green';
} else {
$content = pht(
"=== Adjust Account Settings ===\n\n".
'You can configure settings for your account by clicking the '.
'wrench icon in the main menu bar, or visiting the '.
'**[[ %s | Settings Application ]]** directly.',
$settings_href);
$icon = 'fa-info-circle';
}
$setup[] = $this->newItem(
$request,
$icon,
$content);
$dashboard_href = PhabricatorEnv::getURI('/dashboard/');
$have_dashboard = (bool)PhabricatorDashboardInstall::getDashboard(
$viewer,
PhabricatorHomeApplication::DASHBOARD_DEFAULT,
'PhabricatorHomeApplication');
if ($have_dashboard) {
$content = pht(
"=== Customize Home Page ===\n\n".
"You've installed a default dashboard to replace this welcome screen ".
"on the home page. ".
"You can still visit the welcome screen here at any time if you ".
"have steps you want to complete later, or if you feel lonely. ".
"If you've changed your mind about the dashboard you installed, ".
"you can install a different default dashboard with the ".
"**[[ %s | Dashboards Application ]]**.",
$dashboard_href);
$icon = 'fa-check-square-o green';
} else {
$content = pht(
"=== Customize Home Page ===\n\n".
"When you're done setting things up, you can create a custom ".
"dashboard and install it. Your dashboard will replace this ".
"welcome screen on the Phabricator home page. ".
"Dashboards can show users the information that's most important to ".
"your organization. You can configure them to display things like: ".
"a custom welcome message, a feed of recent activity, or a list of ".
"open tasks, waiting reviews, recent commits, and so on. ".
"After you install a default dashboard, it will replace this page. ".
"You can find this page later by visiting the **Config** ".
"application, under **Welcome Page**. ".
"To get started building a dashboard, use the ".
"**[[ %s | Dashboards Application ]]**. ",
$dashboard_href);
$icon = 'fa-info-circle';
}
$setup[] = $this->newItem(
$request,
$icon,
$content);
$apps_href = PhabricatorEnv::getURI('/applications/');
$content = pht(
"=== Explore Applications ===\n\n".
"Phabricator is a large suite of applications that work together to ".
"help you develop software, manage tasks, and communicate. A few of ".
"the most commonly used applications are pinned to the left navigation ".
"bar by default.\n\n".
"To explore all of the Phabricator applications, adjust settings, or ".
"uninstall applications you don't plan to use, visit the ".
"**[[ %s | Applications Application ]]**. You can also click the ".
"**Applications** button in the left navigation menu, or search for an ".
"application by name in the main menu bar. ",
$apps_href);
$explore = array();
$explore[] = $this->newItem(
$request,
'fa-globe',
$content);
// TODO: Restore some sort of "Support" link here, but just nuke it for
// now as we figure stuff out.
$differential_uri = PhabricatorEnv::getURI('/differential/');
$differential_create_uri = PhabricatorEnv::getURI(
'/differential/diff/create/');
$differential_all_uri = PhabricatorEnv::getURI('/differential/query/all/');
$differential_user_guide = PhabricatorEnv::getDoclink(
'Differential User Guide');
$differential_vs_uri = PhabricatorEnv::getDoclink(
'User Guide: Review vs Audit');
$quick = array();
$quick[] = $this->newItem(
$request,
'fa-gear',
pht(
"=== Quick Start: Code Review ===\n\n".
"Review code with **[[ %s | Differential ]]**. ".
"Engineers can use Differential to share, review, and approve ".
"changes to source code. ".
"To get started with code review:\n\n".
" - **[[ %s | Create a Revision ]]** //(Copy and paste a diff from ".
" the command line into the web UI to quickly get a feel for ".
" review.)//\n".
" - **[[ %s | View All Revisions ]]**\n\n".
"For more information, see these articles in the documentation:\n\n".
" - **[[ %s | Differential User Guide ]]**, for a general overview ".
" of Differential.\n".
" - **[[ %s | User Guide: Review vs Audit ]]**, for a discussion ".
" of different code review workflows.",
$differential_uri,
$differential_create_uri,
$differential_all_uri,
$differential_user_guide,
$differential_vs_uri));
$maniphest_uri = PhabricatorEnv::getURI('/maniphest/');
$maniphest_create_uri = PhabricatorEnv::getURI('/maniphest/task/edit/');
$maniphest_all_uri = PhabricatorEnv::getURI('/maniphest/query/all/');
$quick[] = $this->newItem(
$request,
'fa-anchor',
pht(
"=== Quick Start: Bugs and Tasks ===\n\n".
"Track bugs and tasks in Phabricator with ".
"**[[ %s | Maniphest ]]**. ".
"Users in all roles can use Maniphest to manage current and ".
"planned work and to track bugs and issues. ".
"To get started with bugs and tasks:\n\n".
" - **[[ %s | Create a Task ]]**\n".
" - **[[ %s | View All Tasks ]]**\n",
$maniphest_uri,
$maniphest_create_uri,
$maniphest_all_uri));
$pholio_uri = PhabricatorEnv::getURI('/pholio/');
$pholio_create_uri = PhabricatorEnv::getURI('/pholio/new/');
$pholio_all_uri = PhabricatorEnv::getURI('/pholio/query/all/');
$quick[] = $this->newItem(
$request,
'fa-camera-retro',
pht(
"=== Quick Start: Design Review ===\n\n".
"Review proposed designs with **[[ %s | Pholio ]]**. ".
"Designers can use Pholio to share images of what they're working on ".
"and show off things they've made. ".
"To get started with design review:\n\n".
" - **[[ %s | Create a Mock ]]**\n".
" - **[[ %s | View All Mocks ]]**",
$pholio_uri,
$pholio_create_uri,
$pholio_all_uri));
$diffusion_uri = PhabricatorEnv::getURI('/diffusion/');
$diffusion_create_uri = PhabricatorEnv::getURI('/diffusion/create/');
$diffusion_all_uri = PhabricatorEnv::getURI('/diffusion/query/all/');
$diffusion_user_guide = PhabricatorEnv::getDoclink('Diffusion User Guide');
$diffusion_setup_guide = PhabricatorEnv::getDoclink(
'Diffusion User Guide: Repository Hosting');
$quick[] = $this->newItem(
$request,
'fa-code',
pht(
"=== Quick Start: Repositories ===\n\n".
"Manage and browse source code repositories with ".
"**[[ %s | Diffusion ]]**. ".
"Engineers can use Diffusion to browse and audit source code. ".
"You can configure Phabricator to host repositories, or have it ".
"track existing repositories hosted elsewhere (like GitHub, ".
"Bitbucket, or an internal server). ".
"To get started with repositories:\n\n".
" - **[[ %s | Create a New Repository ]]**\n".
" - **[[ %s | View All Repositories ]]**\n\n".
"For more information, see these articles in the documentation:\n\n".
" - **[[ %s | Diffusion User Guide ]]**, for a general overview of ".
" Diffusion.\n".
" - **[[ %s | Diffusion User Guide: Repository Hosting ]]**, ".
" for instructions on configuring repository hosting.\n\n".
"Phabricator supports Git, Mercurial and Subversion.",
$diffusion_uri,
$diffusion_create_uri,
$diffusion_all_uri,
$diffusion_user_guide,
$diffusion_setup_guide));
$header = id(new PHUIHeaderView())
->setHeader(pht('Welcome to Phabricator'));
$setup_header = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())
->setContent(pht('=Setup and Configuration')),
'default',
$viewer);
$explore_header = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())
->setContent(pht('=Explore Phabricator')),
'default',
$viewer);
$quick_header = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())
->setContent(pht('=Quick Start Guides')),
'default',
$viewer);
return id(new PHUIDocumentView())
->setHeader($header)
->setFluid(true)
->appendChild($setup_header)
->appendChild($setup)
->appendChild($explore_header)
->appendChild($explore)
->appendChild($quick_header)
->appendChild($quick);
}
private function newItem(AphrontRequest $request, $icon, $content) {
$viewer = $request->getUser();
$icon = id(new PHUIIconView())
- ->setIconFont($icon.' fa-2x');
+ ->setIcon($icon.' fa-2x');
$content = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($content),
'default',
$viewer);
$icon = phutil_tag(
'div',
array(
'class' => 'config-welcome-icon',
),
$icon);
$content = phutil_tag(
'div',
array(
'class' => 'config-welcome-content',
),
$content);
$view = phutil_tag(
'div',
array(
'class' => 'config-welcome-box grouped',
),
array(
$icon,
$content,
));
return $view;
}
}
diff --git a/src/applications/config/module/PhabricatorConfigPHIDModule.php b/src/applications/config/module/PhabricatorConfigPHIDModule.php
index 4c5c09f9c3..0a1eaf7b3f 100644
--- a/src/applications/config/module/PhabricatorConfigPHIDModule.php
+++ b/src/applications/config/module/PhabricatorConfigPHIDModule.php
@@ -1,79 +1,79 @@
<?php
final class PhabricatorConfigPHIDModule extends PhabricatorConfigModule {
public function getModuleKey() {
return 'phid';
}
public function getModuleName() {
return pht('PHID Types');
}
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())->setIconFont($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())->setIconFont($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);
}
}
diff --git a/src/applications/conpherence/controller/ConpherenceWidgetController.php b/src/applications/conpherence/controller/ConpherenceWidgetController.php
index 0408896a16..e6707577e9 100644
--- a/src/applications/conpherence/controller/ConpherenceWidgetController.php
+++ b/src/applications/conpherence/controller/ConpherenceWidgetController.php
@@ -1,205 +1,205 @@
<?php
final class ConpherenceWidgetController extends ConpherenceController {
private $userPreferences;
public function setUserPreferences(PhabricatorUserPreferences $pref) {
$this->userPreferences = $pref;
return $this;
}
public function getUserPreferences() {
return $this->userPreferences;
}
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest();
$user = $request->getUser();
$conpherence_id = $request->getURIData('id');
if (!$conpherence_id) {
return new Aphront404Response();
}
$conpherence = id(new ConpherenceThreadQuery())
->setViewer($user)
->withIDs(array($conpherence_id))
->needWidgetData(true)
->executeOne();
if (!$conpherence) {
return new Aphront404Response();
}
$this->setConpherence($conpherence);
$this->setUserPreferences($user->loadPreferences());
switch ($request->getStr('widget')) {
case 'widgets-people':
$content = $this->renderPeopleWidgetPaneContent();
break;
case 'widgets-settings':
$content = $this->renderSettingsWidgetPaneContent();
break;
default:
$widgets = $this->renderWidgetPaneContent();
$content = $widgets;
break;
}
return id(new AphrontAjaxResponse())->setContent($content);
}
private function renderWidgetPaneContent() {
$conpherence = $this->getConpherence();
$widgets = array();
$new_icon = id(new PHUIIconView())
- ->setIconFont('fa-plus')
+ ->setIcon('fa-plus')
->setHref($this->getWidgetURI())
->setMetadata(array('widget' => null))
->addSigil('conpherence-widget-adder');
$header = javelin_tag(
'a',
array(
'href' => '#',
'sigil' => 'widgets-selector',
),
pht('Participants'));
$widgets[] = phutil_tag(
'div',
array(
'class' => 'widgets-header',
),
id(new PHUIHeaderView())
->setHeader($header)
->addActionIcon($new_icon));
$user = $this->getRequest()->getUser();
// now the widget bodies
$widgets[] = javelin_tag(
'div',
array(
'class' => 'widgets-body',
'id' => 'widgets-people',
'sigil' => 'widgets-people',
),
$this->renderPeopleWidgetPaneContent());
$widgets[] = phutil_tag(
'div',
array(
'class' => 'widgets-body',
'id' => 'widgets-settings',
'style' => 'display: none',
),
$this->renderSettingsWidgetPaneContent());
$widgets[] = phutil_tag(
'div',
array(
'class' => 'widgets-body',
'id' => 'widgets-edit',
'style' => 'display: none',
));
// without this implosion we get "," between each element in our widgets
// array
return array('widgets' => phutil_implode_html('', $widgets));
}
private function renderPeopleWidgetPaneContent() {
return id(new ConpherencePeopleWidgetView())
->setUser($this->getViewer())
->setConpherence($this->getConpherence())
->setUpdateURI($this->getWidgetURI());
}
private function renderSettingsWidgetPaneContent() {
$viewer = $this->getViewer();
$conpherence = $this->getConpherence();
$participant = $conpherence->getParticipantIfExists($viewer->getPHID());
if (!$participant) {
$can_join = PhabricatorPolicyFilter::hasCapability(
$viewer,
$conpherence,
PhabricatorPolicyCapability::CAN_JOIN);
if ($can_join) {
$text = pht(
'Notification settings are available after joining the room.');
} else if ($viewer->isLoggedIn()) {
$text = pht(
'Notification settings not applicable to rooms you can not join.');
} else {
$text = pht(
'Notification settings are available after logging in and joining '.
'the room.');
}
return phutil_tag(
'div',
array(
'class' => 'no-settings',
),
$text);
}
$default = ConpherenceSettings::EMAIL_ALWAYS;
$preference = $this->getUserPreferences();
if ($preference) {
$default = $preference->getPreference(
PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS,
ConpherenceSettings::EMAIL_ALWAYS);
}
$settings = $participant->getSettings();
$notifications = idx(
$settings,
'notifications',
$default);
$options = id(new AphrontFormRadioButtonControl())
->addButton(
ConpherenceSettings::EMAIL_ALWAYS,
ConpherenceSettings::getHumanString(
ConpherenceSettings::EMAIL_ALWAYS),
'')
->addButton(
ConpherenceSettings::NOTIFICATIONS_ONLY,
ConpherenceSettings::getHumanString(
ConpherenceSettings::NOTIFICATIONS_ONLY),
'')
->setName('notifications')
->setValue($notifications);
$layout = array(
$options,
phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'action',
'value' => 'notifications',
)),
phutil_tag(
'button',
array(
'type' => 'submit',
'class' => 'notifications-update',
),
pht('Save')),
);
return phabricator_form(
$viewer,
array(
'method' => 'POST',
'action' => $this->getWidgetURI(),
'sigil' => 'notifications-update',
),
$layout);
}
private function getWidgetURI() {
$conpherence = $this->getConpherence();
return $this->getApplicationURI('update/'.$conpherence->getID().'/');
}
}
diff --git a/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php b/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php
index 95c5bd592a..92e5da59b1 100644
--- a/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php
+++ b/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php
@@ -1,426 +1,426 @@
<?php
final class ConpherenceThreadSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Rooms');
}
public function getApplicationClassName() {
return 'PhabricatorConpherenceApplication';
}
public function newQuery() {
return id(new ConpherenceThreadQuery())
->needParticipantCache(true);
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorUsersSearchField())
->setLabel(pht('Participants'))
->setKey('participants')
->setAliases(array('participant')),
id(new PhabricatorSearchTextField())
->setLabel(pht('Contains Words'))
->setKey('fulltext'),
);
}
protected function getDefaultFieldOrder() {
return array(
'participants',
'...',
);
}
protected function shouldShowOrderField() {
return false;
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if ($map['participants']) {
$query->withParticipantPHIDs($map['participants']);
}
if ($map['fulltext']) {
$query->withFulltext($map['fulltext']);
}
return $query;
}
protected function getURI($path) {
return '/conpherence/search/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
if ($this->requireViewer()->isLoggedIn()) {
$names['participant'] = pht('Joined Rooms');
}
$names['all'] = pht('All Rooms');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'participant':
return $query->setParameter(
'participants',
array($this->requireViewer()->getPHID()));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function getRequiredHandlePHIDsForResultList(
array $conpherences,
PhabricatorSavedQuery $query) {
$recent = mpull($conpherences, 'getRecentParticipantPHIDs');
return array_unique(array_mergev($recent));
}
protected function renderResultList(
array $conpherences,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($conpherences, 'ConpherenceThread');
$viewer = $this->requireViewer();
$policy_objects = ConpherenceThread::loadViewPolicyObjects(
$viewer,
$conpherences);
$engines = array();
$fulltext = $query->getParameter('fulltext');
if (strlen($fulltext) && $conpherences) {
$context = $this->loadContextMessages($conpherences, $fulltext);
$author_phids = array();
foreach ($context as $phid => $messages) {
$conpherence = $conpherences[$phid];
$engine = id(new PhabricatorMarkupEngine())
->setViewer($viewer)
->setContextObject($conpherence);
foreach ($messages as $group) {
foreach ($group as $message) {
$xaction = $message['xaction'];
if ($xaction) {
$author_phids[] = $xaction->getAuthorPHID();
$engine->addObject(
$xaction->getComment(),
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
}
}
}
$engine->process();
$engines[$phid] = $engine;
}
$handles = $viewer->loadHandles($author_phids);
$handles = iterator_to_array($handles);
} else {
$context = array();
}
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($conpherences as $conpherence_phid => $conpherence) {
$created = phabricator_date($conpherence->getDateCreated(), $viewer);
$title = $conpherence->getDisplayTitle($viewer);
$monogram = $conpherence->getMonogram();
$icon_name = $conpherence->getPolicyIconName($policy_objects);
$icon = id(new PHUIIconView())
- ->setIconFont($icon_name);
+ ->setIcon($icon_name);
$item = id(new PHUIObjectItemView())
->setObjectName($conpherence->getMonogram())
->setHeader($title)
->setHref('/'.$conpherence->getMonogram())
->setObject($conpherence)
->addIcon('none', $created)
->addIcon(
'none',
pht('Messages: %d', $conpherence->getMessageCount()))
->addAttribute(
array(
$icon,
' ',
pht(
'Last updated %s',
phabricator_datetime($conpherence->getDateModified(), $viewer)),
));
$messages = idx($context, $conpherence_phid);
if ($messages) {
foreach ($messages as $group) {
$rows = array();
foreach ($group as $message) {
$xaction = $message['xaction'];
if (!$xaction) {
continue;
}
$view = id(new ConpherenceTransactionView())
->setUser($viewer)
->setHandles($handles)
->setMarkupEngine($engines[$conpherence_phid])
->setConpherenceThread($conpherence)
->setConpherenceTransaction($xaction)
->setFullDisplay(false)
->addClass('conpherence-fulltext-result');
if ($message['match']) {
$view->addClass('conpherence-fulltext-match');
}
$rows[] = $view;
}
$box = id(new PHUIBoxView())
->appendChild($rows)
->addClass('conpherence-fulltext-results');
$item->appendChild($box);
}
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No threads found.'));
return $result;
}
private function loadContextMessages(array $threads, $fulltext) {
$phids = mpull($threads, 'getPHID');
// We want to load a few messages for each thread in the result list, to
// show some of the actual content hits to help the user find what they
// are looking for.
// This method is trying to batch this lookup in most cases, so we do
// between one and "a handful" of queries instead of one per thread in
// most cases. To do this:
//
// - Load a big block of results for all of the threads.
// - If we didn't get a full block back, we have everything that matches
// the query. Sort it out and exit.
// - Otherwise, some threads had a ton of hits, so we might not be
// getting everything we want (we could be getting back 1,000 hits for
// the first thread). Remove any threads which we have enough results
// for and try again.
// - Repeat until we have everything or every thread has enough results.
//
// In the worst case, we could end up degrading to one query per thread,
// but this is incredibly unlikely on real data.
// Size of the result blocks we're going to load.
$limit = 1000;
// Number of messages we want for each thread.
$want = 3;
$need = $phids;
$hits = array();
while ($need) {
$rows = id(new ConpherenceFulltextQuery())
->withThreadPHIDs($need)
->withFulltext($fulltext)
->setLimit($limit)
->execute();
foreach ($rows as $row) {
$hits[$row['threadPHID']][] = $row;
}
if (count($rows) < $limit) {
break;
}
foreach ($need as $key => $phid) {
if (count($hits[$phid]) >= $want) {
unset($need[$key]);
}
}
}
// Now that we have all the fulltext matches, throw away any extras that we
// aren't going to render so we don't need to do lookups on them.
foreach ($hits as $phid => $rows) {
if (count($rows) > $want) {
$hits[$phid] = array_slice($rows, 0, $want);
}
}
// For each fulltext match, we want to render a message before and after
// the match to give it some context. We already know the transactions
// before each match because the rows have a "previousTransactionPHID",
// but we need to do one more query to figure out the transactions after
// each match.
// Collect the transactions we want to find the next transactions for.
$after = array();
foreach ($hits as $phid => $rows) {
foreach ($rows as $row) {
$after[] = $row['transactionPHID'];
}
}
// Look up the next transactions.
if ($after) {
$after_rows = id(new ConpherenceFulltextQuery())
->withPreviousTransactionPHIDs($after)
->execute();
} else {
$after_rows = array();
}
// Build maps from PHIDs to the previous and next PHIDs.
$prev_map = array();
$next_map = array();
foreach ($after_rows as $row) {
$next_map[$row['previousTransactionPHID']] = $row['transactionPHID'];
}
foreach ($hits as $phid => $rows) {
foreach ($rows as $row) {
$prev = $row['previousTransactionPHID'];
if ($prev) {
$prev_map[$row['transactionPHID']] = $prev;
$next_map[$prev] = $row['transactionPHID'];
}
}
}
// Now we're going to collect the actual transaction PHIDs, in order, that
// we want to show for each thread.
$groups = array();
foreach ($hits as $thread_phid => $rows) {
$rows = ipull($rows, null, 'transactionPHID');
$done = array();
foreach ($rows as $phid => $row) {
if (isset($done[$phid])) {
continue;
}
$done[$phid] = true;
$group = array();
// Walk backward, finding all the previous results. We can just keep
// going until we run out of results because we've only loaded things
// that we want to show.
$prev = $phid;
while (true) {
if (!isset($prev_map[$prev])) {
// No previous transaction, so we're done.
break;
}
$prev = $prev_map[$prev];
if (isset($rows[$prev])) {
$match = true;
$done[$prev] = true;
} else {
$match = false;
}
$group[] = array(
'phid' => $prev,
'match' => $match,
);
}
if (count($group) > 1) {
$group = array_reverse($group);
}
$group[] = array(
'phid' => $phid,
'match' => true,
);
$next = $phid;
while (true) {
if (!isset($next_map[$next])) {
break;
}
$next = $next_map[$next];
if (isset($rows[$next])) {
$match = true;
$done[$next] = true;
} else {
$match = false;
}
$group[] = array(
'phid' => $next,
'match' => $match,
);
}
$groups[$thread_phid][] = $group;
}
}
// Load all the actual transactions we need.
$xaction_phids = array();
foreach ($groups as $thread_phid => $group) {
foreach ($group as $list) {
foreach ($list as $item) {
$xaction_phids[] = $item['phid'];
}
}
}
if ($xaction_phids) {
$xactions = id(new ConpherenceTransactionQuery())
->setViewer($this->requireViewer())
->withPHIDs($xaction_phids)
->needComments(true)
->execute();
$xactions = mpull($xactions, null, 'getPHID');
} else {
$xactions = array();
}
foreach ($groups as $thread_phid => $group) {
foreach ($group as $key => $list) {
foreach ($list as $lkey => $item) {
$xaction = idx($xactions, $item['phid']);
if ($xaction->shouldHide()) {
continue;
}
$groups[$thread_phid][$key][$lkey]['xaction'] = $xaction;
}
}
}
// TODO: Sort the groups chronologically?
return $groups;
}
}
diff --git a/src/applications/conpherence/view/ConpherenceDurableColumnView.php b/src/applications/conpherence/view/ConpherenceDurableColumnView.php
index b371e86c5b..d892eaf62b 100644
--- a/src/applications/conpherence/view/ConpherenceDurableColumnView.php
+++ b/src/applications/conpherence/view/ConpherenceDurableColumnView.php
@@ -1,520 +1,518 @@
<?php
final class ConpherenceDurableColumnView extends AphrontTagView {
private $conpherences = array();
private $draft;
private $selectedConpherence;
private $transactions;
private $visible;
private $initialLoad = false;
private $policyObjects;
private $quicksandConfig = array();
public function setConpherences(array $conpherences) {
assert_instances_of($conpherences, 'ConpherenceThread');
$this->conpherences = $conpherences;
return $this;
}
public function getConpherences() {
return $this->conpherences;
}
public function setDraft(PhabricatorDraft $draft) {
$this->draft = $draft;
return $this;
}
public function getDraft() {
return $this->draft;
}
public function setSelectedConpherence(
ConpherenceThread $conpherence = null) {
$this->selectedConpherence = $conpherence;
return $this;
}
public function getSelectedConpherence() {
return $this->selectedConpherence;
}
public function setTransactions(array $transactions) {
assert_instances_of($transactions, 'ConpherenceTransaction');
$this->transactions = $transactions;
return $this;
}
public function getTransactions() {
return $this->transactions;
}
public function setVisible($visible) {
$this->visible = $visible;
return $this;
}
public function getVisible() {
return $this->visible;
}
public function setInitialLoad($bool) {
$this->initialLoad = $bool;
return $this;
}
public function getInitialLoad() {
return $this->initialLoad;
}
public function setPolicyObjects(array $objects) {
assert_instances_of($objects, 'PhabricatorPolicy');
$this->policyObjects = $objects;
return $this;
}
public function getPolicyObjects() {
return $this->policyObjects;
}
public function setQuicksandConfig(array $config) {
$this->quicksandConfig = $config;
return $this;
}
public function getQuicksandConfig() {
return $this->quicksandConfig;
}
protected function getTagAttributes() {
if ($this->getVisible()) {
$style = null;
} else {
$style = 'display: none;';
}
$classes = array('conpherence-durable-column');
if ($this->getInitialLoad()) {
$classes[] = 'loading';
}
return array(
'id' => 'conpherence-durable-column',
'class' => implode(' ', $classes),
'style' => $style,
'sigil' => 'conpherence-durable-column',
);
}
protected function getTagContent() {
$column_key = PhabricatorUserPreferences::PREFERENCE_CONPHERENCE_COLUMN;
Javelin::initBehavior(
'durable-column',
array(
'visible' => $this->getVisible(),
'settingsURI' => '/settings/adjust/?key='.$column_key,
'quicksandConfig' => $this->getQuicksandConfig(),
));
$policy_objects = ConpherenceThread::loadViewPolicyObjects(
$this->getUser(),
$this->getConpherences());
$this->setPolicyObjects($policy_objects);
$classes = array();
$classes[] = 'conpherence-durable-column-header';
$classes[] = 'phabricator-main-menu-background';
$classes[] = 'sprite-main-header';
$loading_mask = phutil_tag(
'div',
array(
'class' => 'loading-mask',
),
'');
$header = phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
$this->buildHeader());
$icon_bar = phutil_tag(
'div',
array(
'class' => 'conpherence-durable-column-icon-bar',
),
$this->buildIconBar());
$transactions = $this->buildTransactions();
$content = javelin_tag(
'div',
array(
'class' => 'conpherence-durable-column-main',
'sigil' => 'conpherence-durable-column-main',
),
phutil_tag(
'div',
array(
'id' => 'conpherence-durable-column-content',
'class' => 'conpherence-durable-column-frame',
),
javelin_tag(
'div',
array(
'class' => 'conpherence-durable-column-transactions',
'sigil' => 'conpherence-durable-column-transactions',
),
$transactions)));
$input = $this->buildTextInput();
$footer = phutil_tag(
'div',
array(
'class' => 'conpherence-durable-column-footer',
),
array(
$this->buildSendButton(),
phutil_tag(
'div',
array(
'class' => 'conpherence-durable-column-status',
),
$this->buildStatusText()),
));
return array(
$loading_mask,
$header,
javelin_tag(
'div',
array(
'class' => 'conpherence-durable-column-body',
'sigil' => 'conpherence-durable-column-body',
),
array(
$icon_bar,
$content,
$input,
$footer,
)),
);
}
private function getPolicyIcon(
ConpherenceThread $conpherence,
array $policy_objects) {
assert_instances_of($policy_objects, 'PhabricatorPolicy');
$icon = $conpherence->getPolicyIconName($policy_objects);
$icon = id(new PHUIIconView())
->addClass('mmr')
- ->setIconFont($icon);
+ ->setIcon($icon);
return $icon;
}
private function buildIconBar() {
$icons = array();
$selected_conpherence = $this->getSelectedConpherence();
$conpherences = $this->getConpherences();
foreach ($conpherences as $conpherence) {
$classes = array('conpherence-durable-column-thread-icon');
if ($selected_conpherence->getID() == $conpherence->getID()) {
$classes[] = 'selected';
}
$data = $conpherence->getDisplayData($this->getUser());
$icon = $this->getPolicyIcon($conpherence, $this->getPolicyObjects());
$thread_title = phutil_tag(
'span',
array(),
array(
$icon,
$data['title'],
));
$image = $data['image'];
Javelin::initBehavior('phabricator-tooltips');
$icons[] =
javelin_tag(
'a',
array(
'href' => '/conpherence/columnview/',
'class' => implode(' ', $classes),
'sigil' => 'conpherence-durable-column-thread-icon has-tooltip',
'meta' => array(
'threadID' => $conpherence->getID(),
'threadTitle' => hsprintf('%s', $thread_title),
'tip' => $data['title'],
'align' => 'S',
),
),
phutil_tag(
'span',
array(
'style' => 'background-image: url('.$image.')',
),
''));
}
$icons[] = $this->buildSearchButton();
return $icons;
}
private function buildSearchButton() {
return phutil_tag(
'div',
array(
'class' => 'conpherence-durable-column-search-button',
),
id(new PHUIButtonBarView())
->addButton(
id(new PHUIButtonView())
->setTag('a')
->setHref('/conpherence/search/')
->setColor(PHUIButtonView::GREY)
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-search'))));
+ ->setIcon('fa-search')));
}
private function buildHeader() {
$conpherence = $this->getSelectedConpherence();
if (!$conpherence) {
$header = null;
$settings_button = null;
$settings_menu = null;
} else {
$bubble_id = celerity_generate_unique_node_id();
$dropdown_id = celerity_generate_unique_node_id();
$settings_list = new PHUIListView();
$header_actions = $this->getHeaderActionsConfig($conpherence);
foreach ($header_actions as $action) {
$settings_list->addMenuItem(
id(new PHUIListItemView())
->setHref($action['href'])
->setName($action['name'])
->setIcon($action['icon'])
->setDisabled($action['disabled'])
->addSigil('conpherence-durable-column-header-action')
->setMetadata(array(
'action' => $action['key'],
)));
}
$settings_menu = phutil_tag(
'div',
array(
'id' => $dropdown_id,
'class' => 'phabricator-main-menu-dropdown phui-list-sidenav '.
'conpherence-settings-dropdown',
'sigil' => 'phabricator-notification-menu',
'style' => 'display: none',
),
$settings_list);
Javelin::initBehavior(
'aphlict-dropdown',
array(
'bubbleID' => $bubble_id,
'dropdownID' => $dropdown_id,
'local' => true,
'containerDivID' => 'conpherence-durable-column',
));
$item = id(new PHUIListItemView())
->setName(pht('Room Actions'))
->setIcon('fa-bars')
->addClass('core-menu-item')
->addSigil('conpherence-settings-menu')
->setID($bubble_id)
->setHref('#')
->setAural(pht('Room Actions'))
->setOrder(300);
$settings_button = id(new PHUIListView())
->addMenuItem($item)
->addClass('phabricator-dark-menu')
->addClass('phabricator-application-menu');
$data = $conpherence->getDisplayData($this->getUser());
$header = phutil_tag(
'span',
array(),
array(
$this->getPolicyIcon($conpherence, $this->getPolicyObjects()),
$data['title'],
));
}
return
phutil_tag(
'div',
array(
'class' => 'conpherence-durable-column-header',
),
array(
javelin_tag(
'div',
array(
'sigil' => 'conpherence-durable-column-header-text',
'class' => 'conpherence-durable-column-header-text',
),
$header),
$settings_button,
$settings_menu,
));
}
private function getHeaderActionsConfig(ConpherenceThread $conpherence) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$this->getUser(),
$conpherence,
PhabricatorPolicyCapability::CAN_EDIT);
return array(
array(
'name' => pht('Add Participants'),
'disabled' => !$can_edit,
'href' => '/conpherence/update/'.$conpherence->getID().'/',
'icon' => 'fa-plus',
'key' => ConpherenceUpdateActions::ADD_PERSON,
),
array(
'name' => pht('Edit Room'),
'disabled' => !$can_edit,
'href' => '/conpherence/update/'.$conpherence->getID().'/?nopic',
'icon' => 'fa-pencil',
'key' => ConpherenceUpdateActions::METADATA,
),
array(
'name' => pht('View in Conpherence'),
'disabled' => false,
'href' => '/'.$conpherence->getMonogram(),
'icon' => 'fa-comments',
'key' => 'go_conpherence',
),
array(
'name' => pht('Hide Column'),
'disabled' => false,
'href' => '#',
'icon' => 'fa-times',
'key' => 'hide_column',
),
);
}
private function buildTransactions() {
$conpherence = $this->getSelectedConpherence();
if (!$conpherence) {
if (!$this->getVisible() || $this->getInitialLoad()) {
return pht('Loading...');
}
return array(
phutil_tag(
'div',
array(
'class' => 'mmb',
),
pht('You are not in any rooms yet.')),
javelin_tag(
'a',
array(
'href' => '/conpherence/new/',
'class' => 'button grey',
'sigil' => 'workflow',
),
pht('Create a Room')),
);
}
$data = ConpherenceTransactionRenderer::renderTransactions(
$this->getUser(),
$conpherence,
$full_display = false);
$messages = ConpherenceTransactionRenderer::renderMessagePaneContent(
$data['transactions'],
$data['oldest_transaction_id'],
$data['newest_transaction_id']);
return $messages;
}
private function buildTextInput() {
$conpherence = $this->getSelectedConpherence();
if (!$conpherence) {
return null;
}
$draft = $this->getDraft();
$draft_value = null;
if ($draft) {
$draft_value = $draft->getDraft();
}
$textarea_id = celerity_generate_unique_node_id();
$textarea = javelin_tag(
'textarea',
array(
'id' => $textarea_id,
'name' => 'text',
'class' => 'conpherence-durable-column-textarea',
'sigil' => 'conpherence-durable-column-textarea',
'placeholder' => pht('Send a message...'),
),
$draft_value);
Javelin::initBehavior(
'aphront-drag-and-drop-textarea',
array(
'target' => $textarea_id,
'activatedClass' => 'aphront-textarea-drag-and-drop',
'uri' => '/file/dropupload/',
));
$id = $conpherence->getID();
return phabricator_form(
$this->getUser(),
array(
'method' => 'POST',
'action' => '/conpherence/update/'.$id.'/',
'sigil' => 'conpherence-message-form',
),
array(
$textarea,
phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'action',
'value' => ConpherenceUpdateActions::MESSAGE,
)),
));
}
private function buildStatusText() {
return null;
}
private function buildSendButton() {
$conpherence = $this->getSelectedConpherence();
if (!$conpherence) {
return null;
}
return javelin_tag(
'button',
array(
'class' => 'grey',
'sigil' => 'conpherence-send-message',
),
pht('Send'));
}
}
diff --git a/src/applications/conpherence/view/ConpherencePeopleWidgetView.php b/src/applications/conpherence/view/ConpherencePeopleWidgetView.php
index a10a9756c7..8bcff0dad6 100644
--- a/src/applications/conpherence/view/ConpherencePeopleWidgetView.php
+++ b/src/applications/conpherence/view/ConpherencePeopleWidgetView.php
@@ -1,65 +1,65 @@
<?php
final class ConpherencePeopleWidgetView extends ConpherenceWidgetView {
public function render() {
$conpherence = $this->getConpherence();
$widget_data = $conpherence->getWidgetData();
$user = $this->getUser();
$conpherence = $this->getConpherence();
$participants = $conpherence->getParticipants();
$handles = $conpherence->getHandles();
$head_handles = array_select_keys($handles, array($user->getPHID()));
$handle_list = mpull($handles, 'getName');
natcasesort($handle_list);
$handles = mpull($handles, null, 'getName');
$handles = array_select_keys($handles, $handle_list);
$head_handles = mpull($head_handles, null, 'getName');
$handles = $head_handles + $handles;
$body = array();
foreach ($handles as $handle) {
$user_phid = $handle->getPHID();
$remove_html = '';
if ($user_phid == $user->getPHID()) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-times lightbluetext');
+ ->setIcon('fa-times lightbluetext');
$remove_html = javelin_tag(
'a',
array(
'class' => 'remove',
'sigil' => 'remove-person',
'meta' => array(
'remove_person' => $user_phid,
'action' => 'remove_person',
),
),
$icon);
}
$body[] = phutil_tag(
'div',
array(
'class' => 'person-entry grouped',
),
array(
phutil_tag(
'a',
array(
'class' => 'pic',
'href' => $handle->getURI(),
),
phutil_tag(
'img',
array(
'src' => $handle->getImageURI(),
),
'')),
$handle->renderLink(),
$remove_html,
));
}
return $body;
}
}
diff --git a/src/applications/conpherence/view/ConpherenceThreadListView.php b/src/applications/conpherence/view/ConpherenceThreadListView.php
index 668e6f9558..40262c765b 100644
--- a/src/applications/conpherence/view/ConpherenceThreadListView.php
+++ b/src/applications/conpherence/view/ConpherenceThreadListView.php
@@ -1,224 +1,224 @@
<?php
final class ConpherenceThreadListView extends AphrontView {
const SEE_MORE_LIMIT = 15;
private $baseURI;
private $threads;
public function setThreads(array $threads) {
assert_instances_of($threads, 'ConpherenceThread');
$this->threads = $threads;
return $this;
}
public function setBaseURI($base_uri) {
$this->baseURI = $base_uri;
return $this;
}
public function render() {
require_celerity_resource('conpherence-menu-css');
$menu = id(new PHUIListView())
->addClass('conpherence-menu')
->setID('conpherence-menu');
$policy_objects = ConpherenceThread::loadViewPolicyObjects(
$this->getUser(),
$this->threads);
$this->addRoomsToMenu($menu, $this->threads, $policy_objects);
return $menu;
}
public function renderSingleThread(
ConpherenceThread $thread,
array $policy_objects) {
assert_instances_of($policy_objects, 'PhabricatorPolicy');
return $this->renderThread($thread, $policy_objects);
}
private function renderThreadItem(
ConpherenceThread $thread,
array $policy_objects) {
return id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_CUSTOM)
->setName($this->renderThread($thread, $policy_objects));
}
private function renderThread(
ConpherenceThread $thread,
array $policy_objects) {
$user = $this->getUser();
$uri = '/'.$thread->getMonogram();
$data = $thread->getDisplayData($user);
$icon = id(new PHUIIconView())
->addClass('msr')
- ->setIconFont($thread->getPolicyIconName($policy_objects));
+ ->setIcon($thread->getPolicyIconName($policy_objects));
$title = phutil_tag(
'span',
array(),
array(
$icon,
$data['title'],
));
$subtitle = $data['subtitle'];
$unread_count = $data['unread_count'];
$epoch = $data['epoch'];
$image = $data['image'];
$dom_id = $thread->getPHID().'-nav-item';
$glyph_pref = PhabricatorUserPreferences::PREFERENCE_TITLES;
$preferences = $user->loadPreferences();
if ($preferences->getPreference($glyph_pref) == 'glyph') {
$glyph = id(new PhabricatorConpherenceApplication())
->getTitleGlyph().' ';
} else {
$glyph = null;
}
return id(new ConpherenceMenuItemView())
->setUser($user)
->setTitle($title)
->setSubtitle($subtitle)
->setHref($uri)
->setEpoch($epoch)
->setImageURI($image)
->setUnreadCount($unread_count)
->setID($thread->getPHID().'-nav-item')
->addSigil('conpherence-menu-click')
->setMetadata(
array(
'title' => $glyph.$data['title'],
'id' => $dom_id,
'threadID' => $thread->getID(),
));
}
private function addRoomsToMenu(
PHUIListView $menu,
array $rooms,
array $policy_objects) {
$header = $this->renderMenuItemHeader(
pht('Rooms'),
'conpherence-room-list-header');
$header->appendChild(
id(new PHUIIconView())
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setHref('/conpherence/search/')
->setText(pht('Search')));
$menu->addMenuItem($header);
if (empty($rooms)) {
$join_item = id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LINK)
->setHref('/conpherence/search/')
->setName(pht('Join a Room'));
$menu->addMenuItem($join_item);
$create_item = id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LINK)
->setHref('/conpherence/new/')
->setWorkflow(true)
->setName(pht('Create a Room'));
$menu->addMenuItem($create_item);
return $menu;
}
$this->addThreadsToMenu($menu, $rooms, $policy_objects);
return $menu;
}
private function addThreadsToMenu(
PHUIListView $menu,
array $threads,
array $policy_objects) {
// If we have self::SEE_MORE_LIMIT or less, we can just render
// all the threads at once. Otherwise, we render a "See more"
// UI element, which toggles a show / hide on the remaining rooms
$show_threads = $threads;
$more_threads = array();
if (count($threads) > self::SEE_MORE_LIMIT) {
$show_threads = array_slice($threads, 0, self::SEE_MORE_LIMIT);
$more_threads = array_slice($threads, self::SEE_MORE_LIMIT);
}
foreach ($show_threads as $thread) {
$item = $this->renderThreadItem($thread, $policy_objects);
$menu->addMenuItem($item);
}
if ($more_threads) {
$search_uri = '/conpherence/search/query/participant/';
$sigil = 'more-room';
$more_item = id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LINK)
->setHref($search_uri)
->addSigil('conpherence-menu-see-more')
->setMetadata(array('moreSigil' => $sigil))
->setName(pht('See More'));
$menu->addMenuItem($more_item);
$show_more_threads = $more_threads;
$even_more_threads = array();
if (count($more_threads) > self::SEE_MORE_LIMIT) {
$show_more_threads = array_slice(
$more_threads,
0,
self::SEE_MORE_LIMIT);
$even_more_threads = array_slice(
$more_threads,
self::SEE_MORE_LIMIT);
}
foreach ($show_more_threads as $thread) {
$item = $this->renderThreadItem($thread, $policy_objects)
->addSigil($sigil)
->addClass('hidden');
$menu->addMenuItem($item);
}
if ($even_more_threads) {
// kick them to application search here
$even_more_item = id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LINK)
->setHref($search_uri)
->addSigil($sigil)
->addClass('hidden')
->setName(pht('See More'));
$menu->addMenuItem($even_more_item);
}
}
return $menu;
}
private function renderMenuItemHeader($title, $class = null) {
$item = id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LABEL)
->setName($title)
->addClass($class);
return $item;
}
private function getNoRoomsMenuItem() {
$message = phutil_tag(
'div',
array(
'class' => 'no-conpherences-menu-item',
),
pht('No Rooms'));
return id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_CUSTOM)
->setName($message);
}
}
diff --git a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
index c660583203..57877783bb 100644
--- a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
+++ b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
@@ -1,309 +1,309 @@
<?php
final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
const HEADER_MODE_NORMAL = 'normal';
const HEADER_MODE_NONE = 'none';
const HEADER_MODE_EDIT = 'edit';
private $panel;
private $viewer;
private $enableAsyncRendering;
private $parentPanelPHIDs;
private $headerMode = self::HEADER_MODE_NORMAL;
private $dashboardID;
public function setDashboardID($id) {
$this->dashboardID = $id;
return $this;
}
public function getDashboardID() {
return $this->dashboardID;
}
public function setHeaderMode($header_mode) {
$this->headerMode = $header_mode;
return $this;
}
public function getHeaderMode() {
return $this->headerMode;
}
/**
* Allow the engine to render the panel via Ajax.
*/
public function setEnableAsyncRendering($enable) {
$this->enableAsyncRendering = $enable;
return $this;
}
public function setParentPanelPHIDs(array $parents) {
$this->parentPanelPHIDs = $parents;
return $this;
}
public function getParentPanelPHIDs() {
return $this->parentPanelPHIDs;
}
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function setPanel(PhabricatorDashboardPanel $panel) {
$this->panel = $panel;
return $this;
}
public function getPanel() {
return $this->panel;
}
public function renderPanel() {
$panel = $this->getPanel();
$viewer = $this->getViewer();
if (!$panel) {
return $this->renderErrorPanel(
pht('Missing Panel'),
pht('This panel does not exist.'));
}
$panel_type = $panel->getImplementation();
if (!$panel_type) {
return $this->renderErrorPanel(
$panel->getName(),
pht(
'This panel has type "%s", but that panel type is not known to '.
'Phabricator.',
$panel->getPanelType()));
}
try {
$this->detectRenderingCycle($panel);
if ($this->enableAsyncRendering) {
if ($panel_type->shouldRenderAsync()) {
return $this->renderAsyncPanel();
}
}
return $this->renderNormalPanel($viewer, $panel, $this);
} catch (Exception $ex) {
return $this->renderErrorPanel(
$panel->getName(),
pht(
'%s: %s',
phutil_tag('strong', array(), get_class($ex)),
$ex->getMessage()));
}
}
private function renderNormalPanel() {
$panel = $this->getPanel();
$panel_type = $panel->getImplementation();
$content = $panel_type->renderPanelContent(
$this->getViewer(),
$panel,
$this);
$header = $this->renderPanelHeader();
return $this->renderPanelDiv(
$content,
$header);
}
private function renderAsyncPanel() {
$panel = $this->getPanel();
$panel_id = celerity_generate_unique_node_id();
$dashboard_id = $this->getDashboardID();
Javelin::initBehavior(
'dashboard-async-panel',
array(
'panelID' => $panel_id,
'parentPanelPHIDs' => $this->getParentPanelPHIDs(),
'headerMode' => $this->getHeaderMode(),
'dashboardID' => $dashboard_id,
'uri' => '/dashboard/panel/render/'.$panel->getID().'/',
));
$header = $this->renderPanelHeader();
$content = id(new PHUIPropertyListView())
->addTextContent(pht('Loading...'));
return $this->renderPanelDiv(
$content,
$header,
$panel_id);
}
private function renderErrorPanel($title, $body) {
switch ($this->getHeaderMode()) {
case self::HEADER_MODE_NONE:
$header = null;
break;
case self::HEADER_MODE_EDIT:
$header = id(new PHUIHeaderView())
->setHeader($title);
$header = $this->addPanelHeaderActions($header);
break;
case self::HEADER_MODE_NORMAL:
default:
$header = id(new PHUIHeaderView())
->setHeader($title);
break;
}
$icon = id(new PHUIIconView())
- ->setIconFont('fa-warning red msr');
+ ->setIcon('fa-warning red msr');
$content = id(new PHUIBoxView())
->addClass('dashboard-box')
->appendChild($icon)
->appendChild($body);
return $this->renderPanelDiv(
$content,
$header);
}
private function renderPanelDiv(
$content,
$header = null,
$id = null) {
require_celerity_resource('phabricator-dashboard-css');
$panel = $this->getPanel();
if (!$id) {
$id = celerity_generate_unique_node_id();
}
$box = new PHUIObjectBoxView();
$interface = 'PhabricatorApplicationSearchResultView';
if ($content instanceof $interface) {
if ($content->getObjectList()) {
$box->setObjectList($content->getObjectList());
}
if ($content->getTable()) {
$box->setTable($content->getTable());
}
if ($content->getContent()) {
$box->appendChild($content->getContent());
}
} else {
$box->appendChild($content);
}
$box->setHeader($header)
->setID($id)
->addSigil('dashboard-panel')
->setMetadata(array('objectPHID' => $panel->getPHID()));
return phutil_tag_div('dashboard-pane', $box);
}
private function renderPanelHeader() {
$panel = $this->getPanel();
switch ($this->getHeaderMode()) {
case self::HEADER_MODE_NONE:
$header = null;
break;
case self::HEADER_MODE_EDIT:
$header = id(new PHUIHeaderView())
->setHeader($panel->getName());
$header = $this->addPanelHeaderActions($header);
break;
case self::HEADER_MODE_NORMAL:
default:
$header = id(new PHUIHeaderView())
->setHeader($panel->getName());
$panel_type = $panel->getImplementation();
$header = $panel_type->adjustPanelHeader(
$this->getViewer(),
$panel,
$this,
$header);
break;
}
return $header;
}
private function addPanelHeaderActions(
PHUIHeaderView $header) {
$panel = $this->getPanel();
$dashboard_id = $this->getDashboardID();
$edit_uri = id(new PhutilURI(
'/dashboard/panel/edit/'.$panel->getID().'/'));
if ($dashboard_id) {
$edit_uri->setQueryParam('dashboardID', $dashboard_id);
}
$action_edit = id(new PHUIIconView())
- ->setIconFont('fa-pencil')
+ ->setIcon('fa-pencil')
->setWorkflow(true)
->setHref((string)$edit_uri);
$header->addActionIcon($action_edit);
if ($dashboard_id) {
$uri = id(new PhutilURI(
'/dashboard/removepanel/'.$dashboard_id.'/'))
->setQueryParam('panelPHID', $panel->getPHID());
$action_remove = id(new PHUIIconView())
- ->setIconFont('fa-trash-o')
+ ->setIcon('fa-trash-o')
->setHref((string)$uri)
->setWorkflow(true);
$header->addActionIcon($action_remove);
}
return $header;
}
/**
* Detect graph cycles in panels, and deeply nested panels.
*
* This method throws if the current rendering stack is too deep or contains
* a cycle. This can happen if you embed layout panels inside each other,
* build a big stack of panels, or embed a panel in remarkup inside another
* panel. Generally, all of this stuff is ridiculous and we just want to
* shut it down.
*
* @param PhabricatorDashboardPanel Panel being rendered.
* @return void
*/
private function detectRenderingCycle(PhabricatorDashboardPanel $panel) {
if ($this->parentPanelPHIDs === null) {
throw new PhutilInvalidStateException('setParentPanelPHIDs');
}
$max_depth = 4;
if (count($this->parentPanelPHIDs) >= $max_depth) {
throw new Exception(
pht(
'To render more than %s levels of panels nested inside other '.
'panels, purchase a subscription to Phabricator Gold.',
new PhutilNumber($max_depth)));
}
if (in_array($panel->getPHID(), $this->parentPanelPHIDs)) {
throw new Exception(
pht(
'You awake in a twisting maze of mirrors, all alike. '.
'You are likely to be eaten by a graph cycle. '.
'Should you escape alive, you resolve to be more careful about '.
'putting dashboard panels inside themselves.'));
}
}
}
diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php
index 181d2c8bca..92195aa8f5 100644
--- a/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php
+++ b/src/applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php
@@ -1,148 +1,148 @@
<?php
final class PhabricatorDashboardQueryPanelType
extends PhabricatorDashboardPanelType {
public function getPanelTypeKey() {
return 'query';
}
public function getPanelTypeName() {
return pht('Query Panel');
}
public function getPanelTypeDescription() {
return pht(
'Show results of a search query, like the most recently filed tasks or '.
'revisions you need to review.');
}
public function getFieldSpecifications() {
return array(
'class' => array(
'name' => pht('Search For'),
'type' => 'search.application',
),
'key' => array(
'name' => pht('Query'),
'type' => 'search.query',
'control.application' => 'class',
),
'limit' => array(
'name' => pht('Limit'),
'caption' => pht('Leave this blank for the default number of items.'),
'type' => 'text',
),
);
}
public function initializeFieldsFromRequest(
PhabricatorDashboardPanel $panel,
PhabricatorCustomFieldList $field_list,
AphrontRequest $request) {
$map = array();
if (strlen($request->getStr('engine'))) {
$map['class'] = $request->getStr('engine');
}
if (strlen($request->getStr('query'))) {
$map['key'] = $request->getStr('query');
}
$full_map = array();
foreach ($map as $key => $value) {
$full_map["std:dashboard:core:{$key}"] = $value;
}
foreach ($field_list->getFields() as $field) {
$field_key = $field->getFieldKey();
if (isset($full_map[$field_key])) {
$field->setValueFromStorage($full_map[$field_key]);
}
}
}
public function renderPanelContent(
PhabricatorUser $viewer,
PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine) {
$engine = $this->getSearchEngine($panel);
$engine->setViewer($viewer);
$engine->setContext(PhabricatorApplicationSearchEngine::CONTEXT_PANEL);
$key = $panel->getProperty('key');
if ($engine->isBuiltinQuery($key)) {
$saved = $engine->buildSavedQueryFromBuiltin($key);
} else {
$saved = id(new PhabricatorSavedQueryQuery())
->setViewer($viewer)
->withEngineClassNames(array(get_class($engine)))
->withQueryKeys(array($key))
->executeOne();
}
if (!$saved) {
throw new Exception(
pht(
'Query "%s" is unknown to application search engine "%s"!',
$key,
get_class($engine)));
}
$query = $engine->buildQueryFromSavedQuery($saved);
$pager = $engine->newPagerForSavedQuery($saved);
if ($panel->getProperty('limit')) {
$limit = (int)$panel->getProperty('limit');
if ($pager->getPageSize() !== 0xFFFF) {
$pager->setPageSize($limit);
}
}
$results = $engine->executeQuery($query, $pager);
return $engine->renderResults($results, $saved);
}
public function adjustPanelHeader(
PhabricatorUser $viewer,
PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine,
PHUIHeaderView $header) {
$search_engine = $this->getSearchEngine($panel);
$key = $panel->getProperty('key');
$href = $search_engine->getQueryResultsPageURI($key);
$icon = id(new PHUIIconView())
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setHref($href);
$header->addActionIcon($icon);
return $header;
}
private function getSearchEngine(PhabricatorDashboardPanel $panel) {
$class = $panel->getProperty('class');
$engine = PhabricatorApplicationSearchEngine::getEngineByClassName($class);
if (!$engine) {
throw new Exception(
pht(
'The application search engine "%s" is not known to Phabricator!',
$class));
}
if (!$engine->canUseInPanelContext()) {
throw new Exception(
pht(
'Application search engines of class "%s" can not be used to build '.
'dashboard panels.',
$class));
}
return $engine;
}
}
diff --git a/src/applications/differential/constants/DifferentialRevisionStatus.php b/src/applications/differential/constants/DifferentialRevisionStatus.php
index 087e577a78..50bc903c40 100644
--- a/src/applications/differential/constants/DifferentialRevisionStatus.php
+++ b/src/applications/differential/constants/DifferentialRevisionStatus.php
@@ -1,114 +1,114 @@
<?php
/**
* NOTE: you probably want {@class:ArcanistDifferentialRevisionStatus}.
* This class just contains a mapping for color within the Differential
* application.
*/
final class DifferentialRevisionStatus extends Phobject {
const COLOR_STATUS_DEFAULT = 'status';
const COLOR_STATUS_DARK = 'status-dark';
const COLOR_STATUS_GREEN = 'status-green';
const COLOR_STATUS_RED = 'status-red';
public static function getRevisionStatusColor($status) {
$default = self::COLOR_STATUS_DEFAULT;
$map = array(
ArcanistDifferentialRevisionStatus::NEEDS_REVIEW =>
self::COLOR_STATUS_DEFAULT,
ArcanistDifferentialRevisionStatus::NEEDS_REVISION =>
self::COLOR_STATUS_RED,
ArcanistDifferentialRevisionStatus::CHANGES_PLANNED =>
self::COLOR_STATUS_RED,
ArcanistDifferentialRevisionStatus::ACCEPTED =>
self::COLOR_STATUS_GREEN,
ArcanistDifferentialRevisionStatus::CLOSED =>
self::COLOR_STATUS_DARK,
ArcanistDifferentialRevisionStatus::ABANDONED =>
self::COLOR_STATUS_DARK,
ArcanistDifferentialRevisionStatus::IN_PREPARATION =>
self::COLOR_STATUS_DARK,
);
return idx($map, $status, $default);
}
public static function getRevisionStatusIcon($status) {
$default = 'fa-square-o bluegrey';
$map = array(
ArcanistDifferentialRevisionStatus::NEEDS_REVIEW =>
'fa-square-o bluegrey',
ArcanistDifferentialRevisionStatus::NEEDS_REVISION =>
'fa-refresh red',
ArcanistDifferentialRevisionStatus::CHANGES_PLANNED =>
'fa-headphones red',
ArcanistDifferentialRevisionStatus::ACCEPTED =>
'fa-check green',
ArcanistDifferentialRevisionStatus::CLOSED =>
'fa-check-square-o',
ArcanistDifferentialRevisionStatus::ABANDONED =>
'fa-check-square-o',
ArcanistDifferentialRevisionStatus::IN_PREPARATION =>
'fa-question-circle blue',
);
return idx($map, $status, $default);
}
public static function renderFullDescription($status) {
$color = self::getRevisionStatusColor($status);
$status_name =
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($status);
$img = id(new PHUIIconView())
- ->setIconFont(self::getRevisionStatusIcon($status));
+ ->setIcon(self::getRevisionStatusIcon($status));
$tag = phutil_tag(
'span',
array(
'class' => 'phui-header-status phui-header-'.$color,
),
array(
$img,
$status_name,
));
return $tag;
}
public static function getClosedStatuses() {
$statuses = array(
ArcanistDifferentialRevisionStatus::CLOSED,
ArcanistDifferentialRevisionStatus::ABANDONED,
);
if (PhabricatorEnv::getEnvConfig('differential.close-on-accept')) {
$statuses[] = ArcanistDifferentialRevisionStatus::ACCEPTED;
}
return $statuses;
}
public static function getOpenStatuses() {
return array_diff(self::getAllStatuses(), self::getClosedStatuses());
}
public static function getAllStatuses() {
return array(
ArcanistDifferentialRevisionStatus::NEEDS_REVIEW,
ArcanistDifferentialRevisionStatus::NEEDS_REVISION,
ArcanistDifferentialRevisionStatus::CHANGES_PLANNED,
ArcanistDifferentialRevisionStatus::ACCEPTED,
ArcanistDifferentialRevisionStatus::CLOSED,
ArcanistDifferentialRevisionStatus::ABANDONED,
ArcanistDifferentialRevisionStatus::IN_PREPARATION,
);
}
public static function isClosedStatus($status) {
return in_array($status, self::getClosedStatuses());
}
}
diff --git a/src/applications/differential/view/DifferentialChangesetDetailView.php b/src/applications/differential/view/DifferentialChangesetDetailView.php
index 918a49e6a7..6fb35a23d5 100644
--- a/src/applications/differential/view/DifferentialChangesetDetailView.php
+++ b/src/applications/differential/view/DifferentialChangesetDetailView.php
@@ -1,260 +1,260 @@
<?php
final class DifferentialChangesetDetailView extends AphrontView {
private $changeset;
private $buttons = array();
private $editable;
private $symbolIndex;
private $id;
private $vsChangesetID;
private $renderURI;
private $whitespace;
private $renderingRef;
private $autoload;
private $loaded;
private $renderer;
public function setAutoload($autoload) {
$this->autoload = $autoload;
return $this;
}
public function getAutoload() {
return $this->autoload;
}
public function setLoaded($loaded) {
$this->loaded = $loaded;
return $this;
}
public function getLoaded() {
return $this->loaded;
}
public function setRenderingRef($rendering_ref) {
$this->renderingRef = $rendering_ref;
return $this;
}
public function getRenderingRef() {
return $this->renderingRef;
}
public function setWhitespace($whitespace) {
$this->whitespace = $whitespace;
return $this;
}
public function getWhitespace() {
return $this->whitespace;
}
public function setRenderURI($render_uri) {
$this->renderURI = $render_uri;
return $this;
}
public function getRenderURI() {
return $this->renderURI;
}
public function setChangeset($changeset) {
$this->changeset = $changeset;
return $this;
}
public function addButton($button) {
$this->buttons[] = $button;
return $this;
}
public function setEditable($editable) {
$this->editable = $editable;
return $this;
}
public function setSymbolIndex($symbol_index) {
$this->symbolIndex = $symbol_index;
return $this;
}
public function setRenderer($renderer) {
$this->renderer = $renderer;
return $this;
}
public function getRenderer() {
return $this->renderer;
}
public function getID() {
if (!$this->id) {
$this->id = celerity_generate_unique_node_id();
}
return $this->id;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function setVsChangesetID($vs_changeset_id) {
$this->vsChangesetID = $vs_changeset_id;
return $this;
}
public function getVsChangesetID() {
return $this->vsChangesetID;
}
public function getFileIcon($filename) {
$path_info = pathinfo($filename);
$extension = idx($path_info, 'extension');
switch ($extension) {
case 'psd':
case 'ai':
$icon = 'fa-eye';
break;
case 'conf':
$icon = 'fa-wrench';
break;
case 'wav':
case 'mp3':
case 'aiff':
$icon = 'fa-file-sound-o';
break;
case 'm4v':
case 'mov':
$icon = 'fa-file-movie-o';
break;
case 'sql':
case 'db':
$icon = 'fa-database';
break;
case 'xls':
case 'csv':
$icon = 'fa-file-excel-o';
break;
case 'ics':
$icon = 'fa-calendar';
break;
case 'zip':
case 'tar':
case 'bz':
case 'tgz':
case 'gz':
$icon = 'fa-file-archive-o';
break;
case 'png':
case 'jpg':
case 'bmp':
case 'gif':
$icon = 'fa-file-picture-o';
break;
case 'txt':
$icon = 'fa-file-text-o';
break;
case 'doc':
case 'docx':
$icon = 'fa-file-word-o';
break;
case 'pdf':
$icon = 'fa-file-pdf-o';
break;
default:
$icon = 'fa-file-code-o';
break;
}
return $icon;
}
public function render() {
$this->requireResource('differential-changeset-view-css');
$this->requireResource('syntax-highlighting-css');
Javelin::initBehavior('phabricator-oncopy', array());
$changeset = $this->changeset;
$class = 'differential-changeset';
if (!$this->editable) {
$class .= ' differential-changeset-immutable';
}
$buttons = null;
if ($this->buttons) {
$buttons = phutil_tag(
'div',
array(
'class' => 'differential-changeset-buttons',
),
$this->buttons);
}
$id = $this->getID();
if ($this->symbolIndex) {
Javelin::initBehavior(
'repository-crossreference',
array(
'container' => $id,
) + $this->symbolIndex);
}
$display_filename = $changeset->getDisplayFilename();
$display_icon = $this->getFileIcon($display_filename);
$icon = id(new PHUIIconView())
- ->setIconFont($display_icon);
+ ->setIcon($display_icon);
$renderer = DifferentialChangesetHTMLRenderer::getHTMLRendererByKey(
$this->getRenderer());
return javelin_tag(
'div',
array(
'sigil' => 'differential-changeset',
'meta' => array(
'left' => nonempty(
$this->getVsChangesetID(),
$this->changeset->getID()),
'right' => $this->changeset->getID(),
'renderURI' => $this->getRenderURI(),
'whitespace' => $this->getWhitespace(),
'highlight' => null,
'renderer' => $this->getRenderer(),
'ref' => $this->getRenderingRef(),
'autoload' => $this->getAutoload(),
'loaded' => $this->getLoaded(),
'undoTemplates' => $renderer->renderUndoTemplates(),
),
'class' => $class,
'id' => $id,
),
array(
id(new PhabricatorAnchorView())
->setAnchorName($changeset->getAnchorName())
->setNavigationMarker(true)
->render(),
$buttons,
phutil_tag('h1',
array(
'class' => 'differential-file-icon-header',
),
array(
$icon,
$display_filename,
)),
javelin_tag(
'div',
array(
'class' => 'changeset-view-content',
'sigil' => 'changeset-view-content',
),
$this->renderChildren()),
));
}
}
diff --git a/src/applications/differential/view/DifferentialChangesetFileTreeSideNavBuilder.php b/src/applications/differential/view/DifferentialChangesetFileTreeSideNavBuilder.php
index c8cb8c2370..14050e942c 100644
--- a/src/applications/differential/view/DifferentialChangesetFileTreeSideNavBuilder.php
+++ b/src/applications/differential/view/DifferentialChangesetFileTreeSideNavBuilder.php
@@ -1,137 +1,137 @@
<?php
final class DifferentialChangesetFileTreeSideNavBuilder extends Phobject {
private $title;
private $baseURI;
private $anchorName;
private $collapsed = false;
public function setAnchorName($anchor_name) {
$this->anchorName = $anchor_name;
return $this;
}
public function getAnchorName() {
return $this->anchorName;
}
public function setBaseURI(PhutilURI $base_uri) {
$this->baseURI = $base_uri;
return $this;
}
public function getBaseURI() {
return $this->baseURI;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function setCollapsed($collapsed) {
$this->collapsed = $collapsed;
return $this;
}
public function build(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI($this->getBaseURI());
$nav->setFlexible(true);
$nav->setCollapsed($this->collapsed);
$anchor = $this->getAnchorName();
$tree = new PhutilFileTree();
foreach ($changesets as $changeset) {
try {
$tree->addPath($changeset->getFilename(), $changeset);
} catch (Exception $ex) {
// TODO: See T1702. When viewing the versus diff of diffs, we may
// have files with the same filename. For example, if you have a setup
// like this in SVN:
//
// a/
// README
// b/
// README
//
// ...and you run "arc diff" once from a/, and again from b/, you'll
// get two diffs with path README. However, in the versus diff view we
// will compute their absolute repository paths and detect that they
// aren't really the same file. This is correct, but causes us to
// throw when inserting them.
//
// We should probably compute the smallest unique path for each file
// and show these as "a/README" and "b/README" when diffed against
// one another. However, we get this wrong in a lot of places (the
// other TOC shows two "README" files, and we generate the same anchor
// hash for both) so I'm just stopping the bleeding until we can get
// a proper fix in place.
}
}
require_celerity_resource('phabricator-filetree-view-css');
$filetree = array();
$path = $tree;
while (($path = $path->getNextNode())) {
$data = $path->getData();
$name = $path->getName();
$style = 'padding-left: '.(2 + (3 * $path->getDepth())).'px';
$href = null;
if ($data) {
$href = '#'.$data->getAnchorName();
$title = $name;
$icon = id(new PHUIIconView())
- ->setIconFont('fa-file-text-o bluetext');
+ ->setIcon('fa-file-text-o bluetext');
} else {
$name .= '/';
$title = $path->getFullPath().'/';
$icon = id(new PHUIIconView())
- ->setIconFont('fa-folder-open blue');
+ ->setIcon('fa-folder-open blue');
}
$name_element = phutil_tag(
'span',
array(
'class' => 'phabricator-filetree-name',
),
$name);
$filetree[] = javelin_tag(
$href ? 'a' : 'span',
array(
'href' => $href,
'style' => $style,
'title' => $title,
'class' => 'phabricator-filetree-item',
),
array($icon, $name_element));
}
$tree->destroy();
$filetree = phutil_tag(
'div',
array(
'class' => 'phabricator-filetree',
),
$filetree);
Javelin::initBehavior('phabricator-file-tree', array());
$nav->addLabel(pht('Changed Files'));
$nav->addCustomBlock($filetree);
$nav->setActive(true);
$nav->selectFilter(null);
return $nav;
}
}
diff --git a/src/applications/differential/view/DifferentialRevisionListView.php b/src/applications/differential/view/DifferentialRevisionListView.php
index b722633c0d..2c14bbc4a5 100644
--- a/src/applications/differential/view/DifferentialRevisionListView.php
+++ b/src/applications/differential/view/DifferentialRevisionListView.php
@@ -1,212 +1,212 @@
<?php
/**
* Render a table of Differential revisions.
*/
final class DifferentialRevisionListView extends AphrontView {
private $revisions;
private $handles;
private $highlightAge;
private $header;
private $noDataString;
private $noBox;
public function setNoDataString($no_data_string) {
$this->noDataString = $no_data_string;
return $this;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setRevisions(array $revisions) {
assert_instances_of($revisions, 'DifferentialRevision');
$this->revisions = $revisions;
return $this;
}
public function setHighlightAge($bool) {
$this->highlightAge = $bool;
return $this;
}
public function setNoBox($box) {
$this->noBox = $box;
return $this;
}
public function getRequiredHandlePHIDs() {
$phids = array();
foreach ($this->revisions as $revision) {
$phids[] = array($revision->getAuthorPHID());
// TODO: Switch to getReviewerStatus(), but not all callers pass us
// revisions with this data loaded.
$phids[] = $revision->getReviewers();
}
return array_mergev($phids);
}
public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles;
return $this;
}
public function render() {
$user = $this->user;
if (!$user) {
throw new PhutilInvalidStateException('setUser');
}
$fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh');
if ($fresh) {
$fresh = PhabricatorCalendarHoliday::getNthBusinessDay(
time(),
-$fresh);
}
$stale = PhabricatorEnv::getEnvConfig('differential.days-stale');
if ($stale) {
$stale = PhabricatorCalendarHoliday::getNthBusinessDay(
time(),
-$stale);
}
$this->initBehavior('phabricator-tooltips', array());
$this->requireResource('aphront-tooltip-css');
$list = new PHUIObjectItemListView();
foreach ($this->revisions as $revision) {
$item = id(new PHUIObjectItemView())
->setUser($user);
$icons = array();
$phid = $revision->getPHID();
$flag = $revision->getFlag($user);
if ($flag) {
$flag_class = PhabricatorFlagColor::getCSSClass($flag->getColor());
$icons['flag'] = phutil_tag(
'div',
array(
'class' => 'phabricator-flag-icon '.$flag_class,
),
'');
}
if ($revision->getDrafts($user)) {
$icons['draft'] = true;
}
$modified = $revision->getDateModified();
$status = $revision->getStatus();
$show_age = ($fresh || $stale) &&
$this->highlightAge &&
!$revision->isClosed();
if ($stale && $modified < $stale) {
$object_age = PHUIObjectItemView::AGE_OLD;
} else if ($fresh && $modified < $fresh) {
$object_age = PHUIObjectItemView::AGE_STALE;
} else {
$object_age = PHUIObjectItemView::AGE_FRESH;
}
$status_name =
ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($status);
if (isset($icons['flag'])) {
$item->addHeadIcon($icons['flag']);
}
$item->setObjectName('D'.$revision->getID());
$item->setHeader($revision->getTitle());
$item->setHref('/D'.$revision->getID());
if (isset($icons['draft'])) {
$draft = id(new PHUIIconView())
- ->setIconFont('fa-comment yellow')
+ ->setIcon('fa-comment yellow')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Unsubmitted Comments'),
));
$item->addAttribute($draft);
}
/* Most things 'Need Review', so accept it's the default */
if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {
$item->addAttribute($status_name);
}
// Author
$author_handle = $this->handles[$revision->getAuthorPHID()];
$item->addByline(pht('Author: %s', $author_handle->renderLink()));
$reviewers = array();
// TODO: As above, this should be based on `getReviewerStatus()`.
foreach ($revision->getReviewers() as $reviewer) {
$reviewers[] = $this->handles[$reviewer]->renderLink();
}
if (!$reviewers) {
$reviewers = phutil_tag('em', array(), pht('None'));
} else {
$reviewers = phutil_implode_html(', ', $reviewers);
}
$item->addAttribute(pht('Reviewers: %s', $reviewers));
$item->setEpoch($revision->getDateModified(), $object_age);
switch ($status) {
case ArcanistDifferentialRevisionStatus::NEEDS_REVIEW:
$item->setStatusIcon('fa-code grey', pht('Needs Review'));
break;
case ArcanistDifferentialRevisionStatus::NEEDS_REVISION:
$item->setStatusIcon('fa-refresh red', pht('Needs Revision'));
break;
case ArcanistDifferentialRevisionStatus::CHANGES_PLANNED:
$item->setStatusIcon('fa-headphones red', pht('Changes Planned'));
break;
case ArcanistDifferentialRevisionStatus::ACCEPTED:
$item->setStatusIcon('fa-check green', pht('Accepted'));
break;
case ArcanistDifferentialRevisionStatus::CLOSED:
$item->setDisabled(true);
$item->setStatusIcon('fa-check-square-o black', pht('Closed'));
break;
case ArcanistDifferentialRevisionStatus::ABANDONED:
$item->setDisabled(true);
$item->setStatusIcon('fa-plane black', pht('Abandoned'));
break;
}
$list->addItem($item);
}
$list->setNoDataString($this->noDataString);
if ($this->header && !$this->noBox) {
$list->setFlush(true);
$list = id(new PHUIObjectBoxView())
->setObjectList($list);
if ($this->header instanceof PHUIHeaderView) {
$list->setHeader($this->header);
} else {
$list->setHeaderText($this->header);
}
} else {
$list->setHeader($this->header);
}
return $list;
}
}
diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php
index 7f55f94d71..4058dcca26 100644
--- a/src/applications/diffusion/controller/DiffusionBrowseController.php
+++ b/src/applications/diffusion/controller/DiffusionBrowseController.php
@@ -1,1872 +1,1868 @@
<?php
final class DiffusionBrowseController extends DiffusionController {
private $lintCommit;
private $lintMessages;
private $coverage;
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
$drequest = $this->getDiffusionRequest();
// Figure out if we're browsing a directory, a file, or a search result
// list.
$grep = $request->getStr('grep');
$find = $request->getStr('find');
if (strlen($grep) || strlen($find)) {
return $this->browseSearch();
}
$pager = id(new PHUIPagerView())
->readFromRequest($request);
$results = DiffusionBrowseResultSet::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.browsequery',
array(
'path' => $drequest->getPath(),
'commit' => $drequest->getStableCommit(),
'offset' => $pager->getOffset(),
'limit' => $pager->getPageSize() + 1,
)));
$reason = $results->getReasonForEmptyResultSet();
$is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE);
if ($is_file) {
return $this->browseFile($results);
} else {
$paths = $results->getPaths();
$paths = $pager->sliceResults($paths);
$results->setPaths($paths);
return $this->browseDirectory($results, $pager);
}
}
private function browseSearch() {
$drequest = $this->getDiffusionRequest();
$actions = $this->buildActionView($drequest);
$properties = $this->buildPropertyView($drequest, $actions);
$object_box = id(new PHUIObjectBoxView())
->setHeader($this->buildHeaderView($drequest))
->addPropertyList($properties);
$content = array();
$content[] = $object_box;
$content[] = $this->renderSearchForm($collapsed = false);
$content[] = $this->renderSearchResults();
$crumbs = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
return $this->newPage()
->setTitle(
array(
nonempty(basename($drequest->getPath()), '/'),
$drequest->getRepository()->getDisplayName(),
))
->setCrumbs($crumbs)
->appendChild($content);
}
private function browseFile() {
$viewer = $this->getViewer();
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$before = $request->getStr('before');
if ($before) {
return $this->buildBeforeResponse($before);
}
$path = $drequest->getPath();
$preferences = $viewer->loadPreferences();
$show_blame = $request->getBool(
'blame',
$preferences->getPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
false));
$show_color = $request->getBool(
'color',
$preferences->getPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
true));
$view = $request->getStr('view');
if ($request->isFormPost() && $view != 'raw' && $viewer->isLoggedIn()) {
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
$show_blame);
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
$show_color);
$preferences->save();
$uri = $request->getRequestURI()
->alter('blame', null)
->alter('color', null);
return id(new AphrontRedirectResponse())->setURI($uri);
}
// We need the blame information if blame is on and we're building plain
// text, or blame is on and this is an Ajax request. If blame is on and
// this is a colorized request, we don't show blame at first (we ajax it
// in afterward) so we don't need to query for it.
$needs_blame = ($show_blame && !$show_color) ||
($show_blame && $request->isAjax());
$params = array(
'commit' => $drequest->getCommit(),
'path' => $drequest->getPath(),
);
$byte_limit = null;
if ($view !== 'raw') {
$byte_limit = PhabricatorFileStorageEngine::getChunkThreshold();
$time_limit = 10;
$params += array(
'timeout' => $time_limit,
'byteLimit' => $byte_limit,
);
}
$response = $this->callConduitWithDiffusionRequest(
'diffusion.filecontentquery',
$params);
$hit_byte_limit = $response['tooHuge'];
$hit_time_limit = $response['tooSlow'];
$file_phid = $response['filePHID'];
if ($hit_byte_limit) {
$corpus = $this->buildErrorCorpus(
pht(
'This file is larger than %s byte(s), and too large to display '.
'in the web UI.',
phutil_format_bytes($byte_limit)));
} else if ($hit_time_limit) {
$corpus = $this->buildErrorCorpus(
pht(
'This file took too long to load from the repository (more than '.
'%s second(s)).',
new PhutilNumber($time_limit)));
} else {
$file = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withPHIDs(array($file_phid))
->executeOne();
if (!$file) {
throw new Exception(pht('Failed to load content file!'));
}
if ($view === 'raw') {
return $file->getRedirectResponse();
}
$data = $file->loadFileData();
if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) {
$file_uri = $file->getBestURI();
if ($file->isViewableImage()) {
$corpus = $this->buildImageCorpus($file_uri);
} else {
$corpus = $this->buildBinaryCorpus($file_uri, $data);
}
} else {
$this->loadLintMessages();
$this->coverage = $drequest->loadCoverage();
// Build the content of the file.
$corpus = $this->buildCorpus(
$show_blame,
$show_color,
$data,
$needs_blame,
$drequest,
$path,
$data);
}
}
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())->setContent($corpus);
}
require_celerity_resource('diffusion-source-css');
// Render the page.
$view = $this->buildActionView($drequest);
$action_list = $this->enrichActionView(
$view,
$drequest,
$show_blame,
$show_color);
$properties = $this->buildPropertyView($drequest, $action_list);
$object_box = id(new PHUIObjectBoxView())
->setHeader($this->buildHeaderView($drequest))
->addPropertyList($properties);
$content = array();
$content[] = $object_box;
$follow = $request->getStr('follow');
if ($follow) {
$notice = new PHUIInfoView();
$notice->setSeverity(PHUIInfoView::SEVERITY_WARNING);
$notice->setTitle(pht('Unable to Continue'));
switch ($follow) {
case 'first':
$notice->appendChild(
pht(
'Unable to continue tracing the history of this file because '.
'this commit is the first commit in the repository.'));
break;
case 'created':
$notice->appendChild(
pht(
'Unable to continue tracing the history of this file because '.
'this commit created the file.'));
break;
}
$content[] = $notice;
}
$renamed = $request->getStr('renamed');
if ($renamed) {
$notice = new PHUIInfoView();
$notice->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$notice->setTitle(pht('File Renamed'));
$notice->appendChild(
pht(
'File history passes through a rename from "%s" to "%s".',
$drequest->getPath(),
$renamed));
$content[] = $notice;
}
$content[] = $corpus;
$content[] = $this->buildOpenRevisions();
$crumbs = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
$basename = basename($this->getDiffusionRequest()->getPath());
return $this->newPage()
->setTitle(
array(
$basename,
$repository->getDisplayName(),
))
->setCrumbs($crumbs)
->appendChild($content);
}
public function browseDirectory(
DiffusionBrowseResultSet $results,
PHUIPagerView $pager) {
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$reason = $results->getReasonForEmptyResultSet();
$content = array();
$actions = $this->buildActionView($drequest);
$properties = $this->buildPropertyView($drequest, $actions);
$object_box = id(new PHUIObjectBoxView())
->setHeader($this->buildHeaderView($drequest))
->addPropertyList($properties);
$content[] = $object_box;
$content[] = $this->renderSearchForm($collapsed = true);
if (!$results->isValidResults()) {
$empty_result = new DiffusionEmptyResultView();
$empty_result->setDiffusionRequest($drequest);
$empty_result->setDiffusionBrowseResultSet($results);
$empty_result->setView($request->getStr('view'));
$content[] = $empty_result;
} else {
$phids = array();
foreach ($results->getPaths() as $result) {
$data = $result->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
}
}
$phids = array_keys($phids);
$handles = $this->loadViewerHandles($phids);
$browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles);
$browse_table->setPaths($results->getPaths());
$browse_table->setUser($request->getUser());
$browse_panel = new PHUIObjectBoxView();
$browse_panel->setHeaderText($drequest->getPath(), '/');
$browse_panel->setTable($browse_table);
$content[] = $browse_panel;
}
$content[] = $this->buildOpenRevisions();
$content[] = $this->renderDirectoryReadme($results);
$crumbs = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'browse',
));
$pager_box = $this->renderTablePagerBox($pager);
return $this->newPage()
->setTitle(
array(
nonempty(basename($drequest->getPath()), '/'),
$repository->getDisplayName(),
))
->setCrumbs($crumbs)
->appendChild(
array(
$content,
$pager_box,
));
}
private function renderSearchResults() {
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$results = array();
$pager = id(new PHUIPagerView())
->readFromRequest($request);
$search_mode = null;
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$results = array();
break;
default:
if (strlen($this->getRequest()->getStr('grep'))) {
$search_mode = 'grep';
$query_string = $request->getStr('grep');
$results = $this->callConduitWithDiffusionRequest(
'diffusion.searchquery',
array(
'grep' => $query_string,
'commit' => $drequest->getStableCommit(),
'path' => $drequest->getPath(),
'limit' => $pager->getPageSize() + 1,
'offset' => $pager->getOffset(),
));
} else { // Filename search.
$search_mode = 'find';
$query_string = $request->getStr('find');
$results = $this->callConduitWithDiffusionRequest(
'diffusion.querypaths',
array(
'pattern' => $query_string,
'commit' => $drequest->getStableCommit(),
'path' => $drequest->getPath(),
'limit' => $pager->getPageSize() + 1,
'offset' => $pager->getOffset(),
));
}
break;
}
$results = $pager->sliceResults($results);
if ($search_mode == 'grep') {
$table = $this->renderGrepResults($results, $query_string);
$header = pht(
'File content matching "%s" under "%s"',
$query_string,
nonempty($drequest->getPath(), '/'));
} else {
$table = $this->renderFindResults($results);
$header = pht(
'Paths matching "%s" under "%s"',
$query_string,
nonempty($drequest->getPath(), '/'));
}
$box = id(new PHUIObjectBoxView())
->setHeaderText($header)
->setTable($table);
$pager_box = $this->renderTablePagerBox($pager);
return array($box, $pager_box);
}
private function renderGrepResults(array $results, $pattern) {
$drequest = $this->getDiffusionRequest();
require_celerity_resource('phabricator-search-results-css');
$rows = array();
foreach ($results as $result) {
list($path, $line, $string) = $result;
$href = $drequest->generateURI(array(
'action' => 'browse',
'path' => $path,
'line' => $line,
));
$matches = null;
$count = @preg_match_all(
'('.$pattern.')u',
$string,
$matches,
PREG_OFFSET_CAPTURE);
if (!$count) {
$output = ltrim($string);
} else {
$output = array();
$cursor = 0;
$length = strlen($string);
foreach ($matches[0] as $match) {
$offset = $match[1];
if ($cursor != $offset) {
$output[] = array(
'text' => substr($string, $cursor, $offset),
'highlight' => false,
);
}
$output[] = array(
'text' => $match[0],
'highlight' => true,
);
$cursor = $offset + strlen($match[0]);
}
if ($cursor != $length) {
$output[] = array(
'text' => substr($string, $cursor),
'highlight' => false,
);
}
if ($output) {
$output[0]['text'] = ltrim($output[0]['text']);
}
foreach ($output as $key => $segment) {
if ($segment['highlight']) {
$output[$key] = phutil_tag('strong', array(), $segment['text']);
} else {
$output[$key] = $segment['text'];
}
}
}
$string = phutil_tag(
'pre',
array('class' => 'PhabricatorMonospaced phui-source-fragment'),
$output);
$path = Filesystem::readablePath($path, $drequest->getPath());
$rows[] = array(
phutil_tag('a', array('href' => $href), $path),
$line,
$string,
);
}
$table = id(new AphrontTableView($rows))
->setClassName('remarkup-code')
->setHeaders(array(pht('Path'), pht('Line'), pht('String')))
->setColumnClasses(array('', 'n', 'wide'))
->setNoDataString(
pht(
'The pattern you searched for was not found in the content of any '.
'files.'));
return $table;
}
private function renderFindResults(array $results) {
$drequest = $this->getDiffusionRequest();
$rows = array();
foreach ($results as $result) {
$href = $drequest->generateURI(array(
'action' => 'browse',
'path' => $result,
));
$readable = Filesystem::readablePath($result, $drequest->getPath());
$rows[] = array(
phutil_tag('a', array('href' => $href), $readable),
);
}
$table = id(new AphrontTableView($rows))
->setHeaders(array(pht('Path')))
->setColumnClasses(array('wide'))
->setNoDataString(
pht(
'The pattern you searched for did not match the names of any '.
'files.'));
return $table;
}
private function loadLintMessages() {
$drequest = $this->getDiffusionRequest();
$branch = $drequest->loadBranch();
if (!$branch || !$branch->getLintCommit()) {
return;
}
$this->lintCommit = $branch->getLintCommit();
$conn = id(new PhabricatorRepository())->establishConnection('r');
$where = '';
if ($drequest->getLint()) {
$where = qsprintf(
$conn,
'AND code = %s',
$drequest->getLint());
}
$this->lintMessages = queryfx_all(
$conn,
'SELECT * FROM %T WHERE branchID = %d %Q AND path = %s',
PhabricatorRepository::TABLE_LINTMESSAGE,
$branch->getID(),
$where,
'/'.$drequest->getPath());
}
private function buildCorpus(
$show_blame,
$show_color,
$file_corpus,
$needs_blame,
DiffusionRequest $drequest,
$path,
$data) {
$viewer = $this->getViewer();
$blame_timeout = 15;
$blame_failed = false;
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
$blame_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
$can_highlight = (strlen($file_corpus) <= $highlight_limit);
$can_blame = (strlen($file_corpus) <= $blame_limit);
if ($needs_blame && $can_blame) {
$blame = $this->loadBlame($path, $drequest->getCommit(), $blame_timeout);
list($blame_list, $blame_commits) = $blame;
if ($blame_list === null) {
$blame_failed = true;
$blame_list = array();
}
} else {
$blame_list = array();
$blame_commits = array();
}
if (!$show_color) {
$corpus = $this->renderPlaintextCorpus(
$file_corpus,
$blame_list,
$blame_commits,
$show_blame);
} else {
if ($can_highlight) {
require_celerity_resource('syntax-highlighting-css');
$highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename(
$path,
$file_corpus);
$lines = phutil_split_lines($highlighted);
} else {
$lines = phutil_split_lines($file_corpus);
}
$rows = $this->buildDisplayRows(
$lines,
$blame_list,
$blame_commits,
$show_blame,
$show_color);
$corpus_table = javelin_tag(
'table',
array(
'class' => 'diffusion-source remarkup-code PhabricatorMonospaced',
'sigil' => 'phabricator-source',
),
$rows);
if ($this->getRequest()->isAjax()) {
return $corpus_table;
}
$id = celerity_generate_unique_node_id();
$repo = $drequest->getRepository();
$symbol_repos = nonempty($repo->getSymbolSources(), array());
$symbol_repos[] = $repo->getPHID();
$lang = last(explode('.', $drequest->getPath()));
$repo_languages = $repo->getSymbolLanguages();
$repo_languages = nonempty($repo_languages, array());
$repo_languages = array_fill_keys($repo_languages, true);
$needs_symbols = true;
if ($repo_languages && $symbol_repos) {
$have_symbols = id(new DiffusionSymbolQuery())
->existsSymbolsInRepository($repo->getPHID());
if (!$have_symbols) {
$needs_symbols = false;
}
}
if ($needs_symbols && $repo_languages) {
$needs_symbols = isset($repo_languages[$lang]);
}
if ($needs_symbols) {
Javelin::initBehavior(
'repository-crossreference',
array(
'container' => $id,
'lang' => $lang,
'repositories' => $symbol_repos,
));
}
$corpus = phutil_tag(
'div',
array(
'id' => $id,
),
$corpus_table);
Javelin::initBehavior('load-blame', array('id' => $id));
}
$edit = $this->renderEditButton();
$file = $this->renderFileButton();
$header = id(new PHUIHeaderView())
->setHeader(pht('File Contents'))
->addActionLink($edit)
->addActionLink($file);
$corpus = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($corpus)
->setCollapsed(true);
$messages = array();
if (!$can_highlight) {
$messages[] = pht(
'This file is larger than %s, so syntax highlighting is disabled '.
'by default.',
phutil_format_bytes($highlight_limit));
}
if ($show_blame && !$can_blame) {
$messages[] = pht(
'This file is larger than %s, so blame is disabled.',
phutil_format_bytes($blame_limit));
}
if ($blame_failed) {
$messages[] = pht(
'Failed to load blame information for this file in %s second(s).',
new PhutilNumber($blame_timeout));
}
if ($messages) {
$corpus->setInfoView(
id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors($messages));
}
return $corpus;
}
private function enrichActionView(
PhabricatorActionListView $view,
DiffusionRequest $drequest,
$show_blame,
$show_color) {
$viewer = $this->getRequest()->getUser();
$base_uri = $this->getRequest()->getRequestURI();
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Show Last Change'))
->setHref(
$drequest->generateURI(
array(
'action' => 'change',
)))
->setIcon('fa-backward'));
if ($show_blame) {
$blame_text = pht('Disable Blame');
$blame_icon = 'fa-exclamation-circle lightgreytext';
$blame_value = 0;
} else {
$blame_text = pht('Enable Blame');
$blame_icon = 'fa-exclamation-circle';
$blame_value = 1;
}
$view->addAction(
id(new PhabricatorActionView())
->setName($blame_text)
->setHref($base_uri->alter('blame', $blame_value))
->setIcon($blame_icon)
->setUser($viewer)
->setRenderAsForm($viewer->isLoggedIn()));
if ($show_color) {
$highlight_text = pht('Disable Highlighting');
$highlight_icon = 'fa-star-o grey';
$highlight_value = 0;
} else {
$highlight_text = pht('Enable Highlighting');
$highlight_icon = 'fa-star';
$highlight_value = 1;
}
$view->addAction(
id(new PhabricatorActionView())
->setName($highlight_text)
->setHref($base_uri->alter('color', $highlight_value))
->setIcon($highlight_icon)
->setUser($viewer)
->setRenderAsForm($viewer->isLoggedIn()));
$href = null;
if ($this->getRequest()->getStr('lint') !== null) {
$lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages));
$href = $base_uri->alter('lint', null);
} else if ($this->lintCommit === null) {
$lint_text = pht('Lint not Available');
} else {
$lint_text = pht(
'Show %d Lint Message(s)',
count($this->lintMessages));
$href = $this->getDiffusionRequest()->generateURI(array(
'action' => 'browse',
'commit' => $this->lintCommit,
))->alter('lint', '');
}
$view->addAction(
id(new PhabricatorActionView())
->setName($lint_text)
->setHref($href)
->setIcon('fa-exclamation-triangle')
->setDisabled(!$href));
return $view;
}
private function renderEditButton() {
$request = $this->getRequest();
$user = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$path = $drequest->getPath();
$line = nonempty((int)$drequest->getLine(), 1);
$editor_link = $user->loadEditorLink($path, $line, $repository);
$template = $user->loadEditorLink($path, '%l', $repository);
- $icon_edit = id(new PHUIIconView())
- ->setIconFont('fa-pencil');
$button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Open in Editor'))
->setHref($editor_link)
- ->setIcon($icon_edit)
+ ->setIcon('fa-pencil')
->setID('editor_link')
->setMetadata(array('link_template' => $template))
->setDisabled(!$editor_link);
return $button;
}
private function renderFileButton($file_uri = null) {
$base_uri = $this->getRequest()->getRequestURI();
if ($file_uri) {
$text = pht('Download Raw File');
$href = $file_uri;
$icon = 'fa-download';
} else {
$text = pht('View Raw File');
$href = $base_uri->alter('view', 'raw');
$icon = 'fa-file-text';
}
- $iconview = id(new PHUIIconView())
- ->setIconFont($icon);
$button = id(new PHUIButtonView())
->setTag('a')
->setText($text)
->setHref($href)
- ->setIcon($iconview);
+ ->setIcon($icon);
return $button;
}
private function buildDisplayRows(
array $lines,
array $blame_list,
array $blame_commits,
$show_color,
$show_blame) {
$request = $this->getRequest();
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$revision_map = array();
$revisions = array();
if ($blame_commits) {
$commit_map = mpull($blame_commits, 'getCommitIdentifier', 'getPHID');
$revision_ids = id(new DifferentialRevision())
->loadIDsByCommitPHIDs(array_keys($commit_map));
if ($revision_ids) {
$revisions = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withIDs($revision_ids)
->execute();
$revisions = mpull($revisions, null, 'getID');
}
foreach ($revision_ids as $commit_phid => $revision_id) {
$revision_map[$commit_map[$commit_phid]] = $revision_id;
}
}
$phids = array();
foreach ($blame_commits as $commit) {
$author_phid = $commit->getAuthorPHID();
if ($author_phid === null) {
continue;
}
$phids[$author_phid] = $author_phid;
}
foreach ($revisions as $revision) {
$author_phid = $revision->getAuthorPHID();
if ($author_phid === null) {
continue;
}
$phids[$author_phid] = $author_phid;
}
$handles = $viewer->loadHandles($phids);
$colors = array();
if ($blame_commits) {
$epochs = array();
foreach ($blame_commits as $identifier => $commit) {
$epochs[$identifier] = $commit->getEpoch();
}
$epoch_list = array_filter($epochs);
$epoch_list = array_unique($epoch_list);
$epoch_list = array_values($epoch_list);
$epoch_min = min($epoch_list);
$epoch_max = max($epoch_list);
$epoch_range = ($epoch_max - $epoch_min) + 1;
foreach ($blame_commits as $identifier => $commit) {
$epoch = $epochs[$identifier];
if (!$epoch) {
$color = '#ffffdd'; // Warning color, missing data.
} else {
$color_ratio = ($epoch - $epoch_min) / $epoch_range;
$color_value = 0xE6 * (1.0 - $color_ratio);
$color = sprintf(
'#%02x%02x%02x',
$color_value,
0xF6,
$color_value);
}
$colors[$identifier] = $color;
}
}
$display = array();
$last_identifier = null;
$last_color = null;
foreach ($lines as $line_index => $line) {
$color = '#f6f6f6';
$duplicate = false;
if (isset($blame_list[$line_index])) {
$identifier = $blame_list[$line_index];
if (isset($colors[$identifier])) {
$color = $colors[$identifier];
}
if ($identifier === $last_identifier) {
$duplicate = true;
} else {
$last_identifier = $identifier;
}
}
$display[$line_index] = array(
'data' => $line,
'target' => false,
'highlighted' => false,
'color' => $color,
'duplicate' => $duplicate,
);
}
$line_arr = array();
$line_str = $drequest->getLine();
$ranges = explode(',', $line_str);
foreach ($ranges as $range) {
if (strpos($range, '-') !== false) {
list($min, $max) = explode('-', $range, 2);
$line_arr[] = array(
'min' => min($min, $max),
'max' => max($min, $max),
);
} else if (strlen($range)) {
$line_arr[] = array(
'min' => $range,
'max' => $range,
);
}
}
// Mark the first highlighted line as the target line.
if ($line_arr) {
$target_line = $line_arr[0]['min'];
if (isset($display[$target_line - 1])) {
$display[$target_line - 1]['target'] = true;
}
}
// Mark all other highlighted lines as highlighted.
foreach ($line_arr as $range) {
for ($ii = $range['min']; $ii <= $range['max']; $ii++) {
if (isset($display[$ii - 1])) {
$display[$ii - 1]['highlighted'] = true;
}
}
}
$engine = null;
$inlines = array();
if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) {
$engine = new PhabricatorMarkupEngine();
$engine->setViewer($viewer);
foreach ($this->lintMessages as $message) {
$inline = id(new PhabricatorAuditInlineComment())
->setSyntheticAuthor(
ArcanistLintSeverity::getStringForSeverity($message['severity']).
' '.$message['code'].' ('.$message['name'].')')
->setLineNumber($message['line'])
->setContent($message['description']);
$inlines[$message['line']][] = $inline;
$engine->addObject(
$inline,
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
}
$engine->process();
require_celerity_resource('differential-changeset-view-css');
}
$rows = $this->renderInlines(
idx($inlines, 0, array()),
$show_blame,
(bool)$this->coverage,
$engine);
// NOTE: We're doing this manually because rendering is otherwise
// dominated by URI generation for very large files.
$line_base = (string)$drequest->generateURI(
array(
'action' => 'browse',
'stable' => true,
));
require_celerity_resource('aphront-tooltip-css');
Javelin::initBehavior('phabricator-oncopy');
Javelin::initBehavior('phabricator-tooltips');
Javelin::initBehavior('phabricator-line-linker');
// Render these once, since they tend to get repeated many times in large
// blame outputs.
$commit_links = $this->renderCommitLinks($blame_commits, $handles);
$revision_links = $this->renderRevisionLinks($revisions, $handles);
$skip_text = pht('Skip Past This Commit');
foreach ($display as $line_index => $line) {
$row = array();
$line_number = $line_index + 1;
$line_href = $line_base.'$'.$line_number;
if (isset($blame_list[$line_index])) {
$identifier = $blame_list[$line_index];
} else {
$identifier = null;
}
$revision_link = null;
$commit_link = null;
$before_link = null;
$style = null;
if ($identifier && !$line['duplicate']) {
$style = 'background: '.$line['color'].';';
if (isset($commit_links[$identifier])) {
$commit_link = $commit_links[$identifier];
}
if (isset($revision_map[$identifier])) {
$revision_id = $revision_map[$identifier];
if (isset($revision_links[$revision_id])) {
$revision_link = $revision_links[$revision_id];
}
}
$skip_href = $line_href.'?before='.$identifier.'&view=blame';
$before_link = javelin_tag(
'a',
array(
'href' => $skip_href,
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $skip_text,
'align' => 'E',
'size' => 300,
),
),
"\xC2\xAB");
}
$row[] = phutil_tag(
'th',
array(
'class' => 'diffusion-blame-link',
),
$before_link);
$object_links = array();
$object_links[] = $commit_link;
if ($revision_link) {
$object_links[] = phutil_tag('span', array(), '/');
$object_links[] = $revision_link;
}
$row[] = phutil_tag(
'th',
array(
'class' => 'diffusion-rev-link',
),
$object_links);
$line_link = phutil_tag(
'a',
array(
'href' => $line_href,
'style' => $style,
),
$line_number);
$row[] = javelin_tag(
'th',
array(
'class' => 'diffusion-line-link',
'sigil' => 'phabricator-source-line',
'style' => $style,
),
$line_link);
if ($line['target']) {
Javelin::initBehavior(
'diffusion-jump-to',
array(
'target' => 'scroll_target',
));
$anchor_text = phutil_tag(
'a',
array(
'id' => 'scroll_target',
),
'');
} else {
$anchor_text = null;
}
$row[] = phutil_tag(
'td',
array(
),
array(
$anchor_text,
// NOTE: See phabricator-oncopy behavior.
"\xE2\x80\x8B",
// TODO: [HTML] Not ideal.
phutil_safe_html(str_replace("\t", ' ', $line['data'])),
));
if ($this->coverage) {
require_celerity_resource('differential-changeset-view-css');
$cov_index = $line['line'] - 1;
if (isset($this->coverage[$cov_index])) {
$cov_class = $this->coverage[$cov_index];
} else {
$cov_class = 'N';
}
$row[] = phutil_tag(
'td',
array(
'class' => 'cov cov-'.$cov_class,
),
'');
}
$rows[] = phutil_tag(
'tr',
array(
'class' => ($line['highlighted'] ?
'phabricator-source-highlight' :
null),
),
$row);
$cur_inlines = $this->renderInlines(
idx($inlines, $line_number, array()),
$show_blame,
$this->coverage,
$engine);
foreach ($cur_inlines as $cur_inline) {
$rows[] = $cur_inline;
}
}
return $rows;
}
private function renderInlines(
array $inlines,
$show_blame,
$has_coverage,
$engine) {
$rows = array();
foreach ($inlines as $inline) {
// TODO: This should use modern scaffolding code.
$inline_view = id(new PHUIDiffInlineCommentDetailView())
->setUser($this->getViewer())
->setMarkupEngine($engine)
->setInlineComment($inline)
->render();
$row = array_fill(0, ($show_blame ? 3 : 1), phutil_tag('th'));
$row[] = phutil_tag('td', array(), $inline_view);
if ($has_coverage) {
$row[] = phutil_tag(
'td',
array(
'class' => 'cov cov-I',
));
}
$rows[] = phutil_tag('tr', array('class' => 'inline'), $row);
}
return $rows;
}
private function buildImageCorpus($file_uri) {
$properties = new PHUIPropertyListView();
$properties->addImageContent(
phutil_tag(
'img',
array(
'src' => $file_uri,
)));
$file = $this->renderFileButton($file_uri);
$header = id(new PHUIHeaderView())
->setHeader(pht('Image'))
->addActionLink($file);
return id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
}
private function buildBinaryCorpus($file_uri, $data) {
$size = new PhutilNumber(strlen($data));
$text = pht('This is a binary file. It is %s byte(s) in length.', $size);
$text = id(new PHUIBoxView())
->addPadding(PHUI::PADDING_LARGE)
->appendChild($text);
$file = $this->renderFileButton($file_uri);
$header = id(new PHUIHeaderView())
->setHeader(pht('Details'))
->addActionLink($file);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($text);
return $box;
}
private function buildErrorCorpus($message) {
$text = id(new PHUIBoxView())
->addPadding(PHUI::PADDING_LARGE)
->appendChild($message);
$header = id(new PHUIHeaderView())
->setHeader(pht('Details'));
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($text);
return $box;
}
private function buildBeforeResponse($before) {
$request = $this->getRequest();
$drequest = $this->getDiffusionRequest();
// NOTE: We need to get the grandparent so we can capture filename changes
// in the parent.
$parent = $this->loadParentCommitOf($before);
$old_filename = null;
$was_created = false;
if ($parent) {
$grandparent = $this->loadParentCommitOf($parent);
if ($grandparent) {
$rename_query = new DiffusionRenameHistoryQuery();
$rename_query->setRequest($drequest);
$rename_query->setOldCommit($grandparent);
$rename_query->setViewer($request->getUser());
$old_filename = $rename_query->loadOldFilename();
$was_created = $rename_query->getWasCreated();
}
}
$follow = null;
if ($was_created) {
// If the file was created in history, that means older commits won't
// have it. Since we know it existed at 'before', it must have been
// created then; jump there.
$target_commit = $before;
$follow = 'created';
} else if ($parent) {
// If we found a parent, jump to it. This is the normal case.
$target_commit = $parent;
} else {
// If there's no parent, this was probably created in the initial commit?
// And the "was_created" check will fail because we can't identify the
// grandparent. Keep the user at 'before'.
$target_commit = $before;
$follow = 'first';
}
$path = $drequest->getPath();
$renamed = null;
if ($old_filename !== null &&
$old_filename !== '/'.$path) {
$renamed = $path;
$path = $old_filename;
}
$line = null;
// If there's a follow error, drop the line so the user sees the message.
if (!$follow) {
$line = $this->getBeforeLineNumber($target_commit);
}
$before_uri = $drequest->generateURI(
array(
'action' => 'browse',
'commit' => $target_commit,
'line' => $line,
'path' => $path,
));
$before_uri->setQueryParams($request->getRequestURI()->getQueryParams());
$before_uri = $before_uri->alter('before', null);
$before_uri = $before_uri->alter('renamed', $renamed);
$before_uri = $before_uri->alter('follow', $follow);
return id(new AphrontRedirectResponse())->setURI($before_uri);
}
private function getBeforeLineNumber($target_commit) {
$drequest = $this->getDiffusionRequest();
$line = $drequest->getLine();
if (!$line) {
return null;
}
$raw_diff = $this->callConduitWithDiffusionRequest(
'diffusion.rawdiffquery',
array(
'commit' => $drequest->getCommit(),
'path' => $drequest->getPath(),
'againstCommit' => $target_commit,
));
$old_line = 0;
$new_line = 0;
foreach (explode("\n", $raw_diff) as $text) {
if ($text[0] == '-' || $text[0] == ' ') {
$old_line++;
}
if ($text[0] == '+' || $text[0] == ' ') {
$new_line++;
}
if ($new_line == $line) {
return $old_line;
}
}
// We didn't find the target line.
return $line;
}
private function loadParentCommitOf($commit) {
$drequest = $this->getDiffusionRequest();
$user = $this->getRequest()->getUser();
$before_req = DiffusionRequest::newFromDictionary(
array(
'user' => $user,
'repository' => $drequest->getRepository(),
'commit' => $commit,
));
$parents = DiffusionQuery::callConduitWithDiffusionRequest(
$user,
$before_req,
'diffusion.commitparentsquery',
array(
'commit' => $commit,
));
return head($parents);
}
private function renderRevisionTooltip(
DifferentialRevision $revision,
$handles) {
$viewer = $this->getRequest()->getUser();
$date = phabricator_date($revision->getDateModified(), $viewer);
$id = $revision->getID();
$title = $revision->getTitle();
$header = "D{$id} {$title}";
$author = $handles[$revision->getAuthorPHID()]->getName();
return "{$header}\n{$date} \xC2\xB7 {$author}";
}
private function renderCommitTooltip(
PhabricatorRepositoryCommit $commit,
$author) {
$viewer = $this->getRequest()->getUser();
$date = phabricator_date($commit->getEpoch(), $viewer);
$summary = trim($commit->getSummary());
return "{$summary}\n{$date} \xC2\xB7 {$author}";
}
protected function renderSearchForm($collapsed) {
$drequest = $this->getDiffusionRequest();
$forms = array();
$form = id(new AphrontFormView())
->setUser($this->getRequest()->getUser())
->setMethod('GET');
switch ($drequest->getRepository()->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$forms[] = id(clone $form)
->appendChild(pht('Search is not available in Subversion.'));
break;
default:
$forms[] = id(clone $form)
->appendChild(
id(new AphrontFormTextWithSubmitControl())
->setLabel(pht('File Name'))
->setSubmitLabel(pht('Search File Names'))
->setName('find')
->setValue($this->getRequest()->getStr('find')));
$forms[] = id(clone $form)
->appendChild(
id(new AphrontFormTextWithSubmitControl())
->setLabel(pht('Pattern'))
->setSubmitLabel(pht('Grep File Content'))
->setName('grep')
->setValue($this->getRequest()->getStr('grep')));
break;
}
$filter = new AphrontListFilterView();
$filter->appendChild($forms);
if ($collapsed) {
$filter->setCollapsed(
pht('Show Search'),
pht('Hide Search'),
pht('Search for file names or content in this directory.'),
'#');
}
$filter = id(new PHUIBoxView())
->addClass('mlt mlb')
->appendChild($filter);
return $filter;
}
protected function markupText($text) {
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
$engine->setConfig('viewer', $this->getRequest()->getUser());
$text = $engine->markupText($text);
$text = phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$text);
return $text;
}
protected function buildHeaderView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($this->renderPathLinks($drequest, $mode = 'browse'))
->setPolicyObject($drequest->getRepository());
return $header;
}
protected function buildActionView(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$view = id(new PhabricatorActionListView())
->setUser($viewer);
$history_uri = $drequest->generateURI(
array(
'action' => 'history',
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setHref($history_uri)
->setIcon('fa-list'));
$behind_head = $drequest->getSymbolicCommit();
$head_uri = $drequest->generateURI(
array(
'commit' => '',
'action' => 'browse',
));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Jump to HEAD'))
->setHref($head_uri)
->setIcon('fa-home')
->setDisabled(!$behind_head));
return $view;
}
protected function buildPropertyView(
DiffusionRequest $drequest,
PhabricatorActionListView $actions) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setActionList($actions);
$stable_commit = $drequest->getStableCommit();
$view->addProperty(
pht('Commit'),
phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'commit',
'commit' => $stable_commit,
)),
),
$drequest->getRepository()->formatCommitName($stable_commit)));
if ($drequest->getSymbolicType() == 'tag') {
$symbolic = $drequest->getSymbolicCommit();
$view->addProperty(pht('Tag'), $symbolic);
$tags = $this->callConduitWithDiffusionRequest(
'diffusion.tagsquery',
array(
'names' => array($symbolic),
'needMessages' => true,
));
$tags = DiffusionRepositoryTag::newFromConduit($tags);
$tags = mpull($tags, null, 'getName');
$tag = idx($tags, $symbolic);
if ($tag && strlen($tag->getMessage())) {
$view->addSectionHeader(
pht('Tag Content'), 'fa-tag');
$view->addTextContent($this->markupText($tag->getMessage()));
}
}
$repository = $drequest->getRepository();
$owners = 'PhabricatorOwnersApplication';
if (PhabricatorApplication::isClassInstalled($owners)) {
$package_query = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withControl(
$repository->getPHID(),
array(
$drequest->getPath(),
));
$package_query->execute();
$packages = $package_query->getControllingPackagesForPath(
$repository->getPHID(),
$drequest->getPath());
if ($packages) {
$ownership = id(new PHUIStatusListView())
->setUser($viewer);
foreach ($packages as $package) {
$icon = 'fa-list-alt';
$color = 'grey';
$item = id(new PHUIStatusItemView())
->setIcon($icon, $color)
->setTarget($viewer->renderHandle($package->getPHID()));
$ownership->addItem($item);
}
} else {
$ownership = phutil_tag('em', array(), pht('None'));
}
$view->addProperty(pht('Packages'), $ownership);
}
return $view;
}
private function buildOpenRevisions() {
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$path = $drequest->getPath();
$path_map = id(new DiffusionPathIDQuery(array($path)))->loadPathIDs();
$path_id = idx($path_map, $path);
if (!$path_id) {
return null;
}
$recent = (PhabricatorTime::getNow() - phutil_units('30 days in seconds'));
$revisions = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withPath($repository->getID(), $path_id)
->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
->withUpdatedEpochBetween($recent, null)
->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED)
->setLimit(10)
->needRelationships(true)
->needFlags(true)
->needDrafts(true)
->execute();
if (!$revisions) {
return null;
}
$header = id(new PHUIHeaderView())
->setHeader(pht('Open Revisions'))
->setSubheader(
pht('Recently updated open revisions affecting this file.'));
$view = id(new DifferentialRevisionListView())
->setHeader($header)
->setRevisions($revisions)
->setUser($viewer);
$phids = $view->getRequiredHandlePHIDs();
$handles = $this->loadViewerHandles($phids);
$view->setHandles($handles);
return $view;
}
private function loadBlame($path, $commit, $timeout) {
$blame = $this->callConduitWithDiffusionRequest(
'diffusion.blame',
array(
'commit' => $commit,
'paths' => array($path),
'timeout' => $timeout,
));
$identifiers = idx($blame, $path, null);
if ($identifiers) {
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepository($repository)
->withIdentifiers($identifiers)
// TODO: We only fetch this to improve author display behavior, but
// shouldn't really need to?
->needCommitData(true)
->execute();
$commits = mpull($commits, null, 'getCommitIdentifier');
} else {
$commits = array();
}
return array($identifiers, $commits);
}
private function renderCommitLinks(array $commits, $handles) {
$links = array();
foreach ($commits as $identifier => $commit) {
$tooltip = $this->renderCommitTooltip(
$commit,
$commit->renderAuthorShortName($handles));
$commit_link = javelin_tag(
'a',
array(
'href' => $commit->getURI(),
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $tooltip,
'align' => 'E',
'size' => 600,
),
),
$commit->getLocalName());
$links[$identifier] = $commit_link;
}
return $links;
}
private function renderRevisionLinks(array $revisions, $handles) {
$links = array();
foreach ($revisions as $revision) {
$revision_id = $revision->getID();
$tooltip = $this->renderRevisionTooltip($revision, $handles);
$revision_link = javelin_tag(
'a',
array(
'href' => '/'.$revision->getMonogram(),
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $tooltip,
'align' => 'E',
'size' => 600,
),
),
$revision->getMonogram());
$links[$revision_id] = $revision_link;
}
return $links;
}
private function renderPlaintextCorpus(
$file_corpus,
array $blame_list,
array $blame_commits,
$show_blame) {
$viewer = $this->getViewer();
if (!$show_blame) {
$corpus = $file_corpus;
} else {
$author_phids = array();
foreach ($blame_commits as $commit) {
$author_phid = $commit->getAuthorPHID();
if ($author_phid === null) {
continue;
}
$author_phids[$author_phid] = $author_phid;
}
if ($author_phids) {
$handles = $viewer->loadHandles($author_phids);
} else {
$handles = array();
}
$authors = array();
$names = array();
foreach ($blame_commits as $identifier => $commit) {
$author = $commit->renderAuthorShortName($handles);
$name = $commit->getLocalName();
$authors[$identifier] = $author;
$names[$identifier] = $name;
}
$lines = phutil_split_lines($file_corpus);
$rows = array();
foreach ($lines as $line_number => $line) {
$commit_name = null;
$author = null;
if (isset($blame_list[$line_number])) {
$identifier = $blame_list[$line_number];
if (isset($names[$identifier])) {
$commit_name = $names[$identifier];
}
if (isset($authors[$identifier])) {
$author = $authors[$identifier];
}
}
$rows[] = sprintf(
'%-10s %-20s %s',
$commit_name,
$author,
$line);
}
$corpus = implode('', $rows);
}
return phutil_tag(
'textarea',
array(
'style' => 'border: none; width: 100%; height: 80em; '.
'font-family: monospace',
),
$corpus);
}
}
diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php
index 218a8e3d44..efa3104a92 100644
--- a/src/applications/diffusion/controller/DiffusionCommitController.php
+++ b/src/applications/diffusion/controller/DiffusionCommitController.php
@@ -1,1236 +1,1234 @@
<?php
final class DiffusionCommitController extends DiffusionController {
const CHANGES_LIMIT = 100;
private $auditAuthorityPHIDs;
private $highlightedAudits;
private $commitParents;
private $commitRefs;
private $commitMerges;
private $commitErrors;
private $commitExists;
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
$drequest = $this->getDiffusionRequest();
$user = $request->getUser();
if ($request->getStr('diff')) {
return $this->buildRawDiffResponse($drequest);
}
$repository = $drequest->getRepository();
$content = array();
$commit = id(new DiffusionCommitQuery())
->setViewer($request->getUser())
->withRepository($repository)
->withIdentifiers(array($drequest->getCommit()))
->needCommitData(true)
->needAuditRequests(true)
->executeOne();
$crumbs = $this->buildCrumbs(array(
'commit' => true,
));
if (!$commit) {
if (!$this->getCommitExists()) {
return new Aphront404Response();
}
$error = id(new PHUIInfoView())
->setTitle(pht('Commit Still Parsing'))
->appendChild(
pht(
'Failed to load the commit because the commit has not been '.
'parsed yet.'));
return $this->buildApplicationPage(
array(
$crumbs,
$error,
),
array(
'title' => pht('Commit Still Parsing'),
));
}
$audit_requests = $commit->getAudits();
$this->auditAuthorityPHIDs =
PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user);
$commit_data = $commit->getCommitData();
$is_foreign = $commit_data->getCommitDetail('foreign-svn-stub');
if ($is_foreign) {
$subpath = $commit_data->getCommitDetail('svn-subpath');
$error_panel = new PHUIInfoView();
$error_panel->setTitle(pht('Commit Not Tracked'));
$error_panel->setSeverity(PHUIInfoView::SEVERITY_WARNING);
$error_panel->appendChild(
pht(
"This Diffusion repository is configured to track only one ".
"subdirectory of the entire Subversion repository, and this commit ".
"didn't affect the tracked subdirectory ('%s'), so no ".
"information is available.",
$subpath));
$content[] = $error_panel;
} else {
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
$engine->setConfig('viewer', $user);
require_celerity_resource('phabricator-remarkup-css');
$headsup_view = id(new PHUIHeaderView())
->setHeader(nonempty($commit->getSummary(), pht('Commit Detail')));
$headsup_actions = $this->renderHeadsupActionList($commit, $repository);
$commit_properties = $this->loadCommitProperties(
$commit,
$commit_data,
$audit_requests);
$property_list = id(new PHUIPropertyListView())
->setHasKeyboardShortcuts(true)
->setUser($user)
->setObject($commit);
foreach ($commit_properties as $key => $value) {
$property_list->addProperty($key, $value);
}
$message = $commit_data->getCommitMessage();
$revision = $commit->getCommitIdentifier();
$message = $this->linkBugtraq($message);
$message = $engine->markupText($message);
$property_list->invokeWillRenderEvent();
$property_list->setActionList($headsup_actions);
$detail_list = new PHUIPropertyListView();
$detail_list->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$detail_list->addTextContent(
phutil_tag(
'div',
array(
'class' => 'diffusion-commit-message phabricator-remarkup',
),
$message));
$headsup_view->setTall(true);
$object_box = id(new PHUIObjectBoxView())
->setHeader($headsup_view)
->setFormErrors($this->getCommitErrors())
->addPropertyList($property_list)
->addPropertyList($detail_list);
$content[] = $object_box;
}
$content[] = $this->buildComments($commit);
$hard_limit = 1000;
if ($commit->isImported()) {
$change_query = DiffusionPathChangeQuery::newFromDiffusionRequest(
$drequest);
$change_query->setLimit($hard_limit + 1);
$changes = $change_query->loadChanges();
} else {
$changes = array();
}
$was_limited = (count($changes) > $hard_limit);
if ($was_limited) {
$changes = array_slice($changes, 0, $hard_limit);
}
$content[] = $this->buildMergesTable($commit);
$highlighted_audits = $commit->getAuthorityAudits(
$user,
$this->auditAuthorityPHIDs);
$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,
$commit->getMonogram());
}
$show_changesets = false;
if ($bad_commit) {
$content[] = $this->renderStatusMessage(
pht('Bad Commit'),
$bad_commit['description']);
} else if ($is_foreign) {
// Don't render anything else.
} else if (!$commit->isImported()) {
$content[] = $this->renderStatusMessage(
pht('Still Importing...'),
pht(
'This commit is still importing. Changes will be visible once '.
'the import finishes.'));
} else if (!count($changes)) {
$content[] = $this->renderStatusMessage(
pht('Empty Commit'),
pht(
'This commit is empty and does not affect any paths.'));
} else if ($was_limited) {
$content[] = $this->renderStatusMessage(
pht('Enormous Commit'),
pht(
'This commit is enormous, and affects more than %d files. '.
'Changes are not shown.',
$hard_limit));
} else if (!$this->getCommitExists()) {
$content[] = $this->renderStatusMessage(
pht('Commit No Longer Exists'),
pht('This commit no longer exists in the repository.'));
} else {
$show_changesets = true;
// The user has clicked "Show All Changes", and we should show all the
// changes inline even if there are more than the soft limit.
$show_all_details = $request->getBool('show_all');
$change_panel = new PHUIObjectBoxView();
$header = new PHUIHeaderView();
$header->setHeader(pht('Changes (%s)', new PhutilNumber($count)));
$change_panel->setID('toc');
if ($count > self::CHANGES_LIMIT && !$show_all_details) {
- $icon = id(new PHUIIconView())
- ->setIconFont('fa-files-o');
$button = id(new PHUIButtonView())
->setText(pht('Show All Changes'))
->setHref('?show_all=true')
->setTag('a')
- ->setIcon($icon);
+ ->setIcon('fa-files-o');
$warning_view = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setTitle(pht('Very Large Commit'))
->appendChild(
pht('This commit is very large. Load each file individually.'));
$change_panel->setInfoView($warning_view);
$header->addActionLink($button);
}
$changesets = DiffusionPathChange::convertToDifferentialChangesets(
$user,
$changes);
// TODO: This table and panel shouldn't really be separate, but we need
// to clean up the "Load All Files" interaction first.
$change_table = $this->buildTableOfContents(
$changesets);
$change_panel->setTable($change_table);
$change_panel->setHeader($header);
$content[] = $change_panel;
$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(pht('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).
$path_ids = array_flip(mpull($changes, 'getPath'));
foreach ($changesets as $changeset) {
$changeset->makeEphemeral();
$changeset->setID($path_ids[$changeset->getFilename()]);
}
if ($count <= self::CHANGES_LIMIT || $show_all_details) {
$visible_changesets = $changesets;
} else {
$visible_changesets = array();
$inlines = PhabricatorAuditInlineComment::loadDraftAndPublishedComments(
$user,
$commit->getPHID());
$path_ids = mpull($inlines, null, 'getPathID');
foreach ($changesets as $key => $changeset) {
if (array_key_exists($changeset->getID(), $path_ids)) {
$visible_changesets[$key] = $changeset;
}
}
}
$change_list_title = $commit->getDisplayName();
$change_list = new DifferentialChangesetListView();
$change_list->setTitle($change_list_title);
$change_list->setChangesets($changesets);
$change_list->setVisibleChangesets($visible_changesets);
$change_list->setRenderingReferences($references);
$change_list->setRenderURI(
$repository->getPathURI('diff/'));
$change_list->setRepository($repository);
$change_list->setUser($user);
// TODO: Try to setBranch() to something reasonable here?
$change_list->setStandaloneURI(
$repository->getPathURI('diff/'));
$change_list->setRawFileURIs(
// TODO: Implement this, somewhat tricky if there's an octopus merge
// or whatever?
null,
$repository->getPathURI('diff/?view=r'));
$change_list->setInlineCommentControllerURI(
'/diffusion/inline/edit/'.phutil_escape_uri($commit->getPHID()).'/');
$content[] = $change_list->render();
}
$content[] = $this->renderAddCommentPanel($commit, $audit_requests);
$prefs = $user->loadPreferences();
$pref_filetree = PhabricatorUserPreferences::PREFERENCE_DIFF_FILETREE;
$pref_collapse = PhabricatorUserPreferences::PREFERENCE_NAV_COLLAPSED;
$show_filetree = $prefs->getPreference($pref_filetree);
$collapsed = $prefs->getPreference($pref_collapse);
if ($show_changesets && $show_filetree) {
$nav = id(new DifferentialChangesetFileTreeSideNavBuilder())
->setTitle($commit->getDisplayName())
->setBaseURI(new PhutilURI($commit->getURI()))
->build($changesets)
->setCrumbs($crumbs)
->setCollapsed((bool)$collapsed)
->appendChild($content);
$content = $nav;
} else {
$content = array($crumbs, $content);
}
return $this->buildApplicationPage(
$content,
array(
'title' => $commit->getDisplayName(),
'pageObjects' => array($commit->getPHID()),
));
}
private function loadCommitProperties(
PhabricatorRepositoryCommit $commit,
PhabricatorRepositoryCommitData $data,
array $audit_requests) {
$viewer = $this->getRequest()->getUser();
$commit_phid = $commit->getPHID();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs(array($commit_phid))
->withEdgeTypes(array(
DiffusionCommitHasTaskEdgeType::EDGECONST,
DiffusionCommitHasRevisionEdgeType::EDGECONST,
DiffusionCommitRevertsCommitEdgeType::EDGECONST,
DiffusionCommitRevertedByCommitEdgeType::EDGECONST,
));
$edges = $edge_query->execute();
$task_phids = array_keys(
$edges[$commit_phid][DiffusionCommitHasTaskEdgeType::EDGECONST]);
$revision_phid = key(
$edges[$commit_phid][DiffusionCommitHasRevisionEdgeType::EDGECONST]);
$reverts_phids = array_keys(
$edges[$commit_phid][DiffusionCommitRevertsCommitEdgeType::EDGECONST]);
$reverted_by_phids = array_keys(
$edges[$commit_phid][DiffusionCommitRevertedByCommitEdgeType::EDGECONST]);
$phids = $edge_query->getDestinationPHIDs(array($commit_phid));
if ($data->getCommitDetail('authorPHID')) {
$phids[] = $data->getCommitDetail('authorPHID');
}
if ($data->getCommitDetail('reviewerPHID')) {
$phids[] = $data->getCommitDetail('reviewerPHID');
}
if ($data->getCommitDetail('committerPHID')) {
$phids[] = $data->getCommitDetail('committerPHID');
}
// NOTE: We should never normally have more than a single push log, but
// it can occur naturally if a commit is pushed, then the branch it was
// on is deleted, then the commit is pushed again (or through other similar
// chains of events). This should be rare, but does not indicate a bug
// or data issue.
// NOTE: We never query push logs in SVN because the commiter is always
// the pusher and the commit time is always the push time; the push log
// is redundant and we save a query by skipping it.
$push_logs = array();
if ($repository->isHosted() && !$repository->isSVN()) {
$push_logs = id(new PhabricatorRepositoryPushLogQuery())
->setViewer($viewer)
->withRepositoryPHIDs(array($repository->getPHID()))
->withNewRefs(array($commit->getCommitIdentifier()))
->withRefTypes(array(PhabricatorRepositoryPushLog::REFTYPE_COMMIT))
->execute();
foreach ($push_logs as $log) {
$phids[] = $log->getPusherPHID();
}
}
$handles = array();
if ($phids) {
$handles = $this->loadViewerHandles($phids);
}
$props = array();
if ($commit->getAuditStatus()) {
$status = PhabricatorAuditCommitStatusConstants::getStatusName(
$commit->getAuditStatus());
$tag = id(new PHUITagView())
->setType(PHUITagView::TYPE_STATE)
->setName($status);
switch ($commit->getAuditStatus()) {
case PhabricatorAuditCommitStatusConstants::NEEDS_AUDIT:
$tag->setBackgroundColor(PHUITagView::COLOR_ORANGE);
break;
case PhabricatorAuditCommitStatusConstants::CONCERN_RAISED:
$tag->setBackgroundColor(PHUITagView::COLOR_RED);
break;
case PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED:
$tag->setBackgroundColor(PHUITagView::COLOR_BLUE);
break;
case PhabricatorAuditCommitStatusConstants::FULLY_AUDITED:
$tag->setBackgroundColor(PHUITagView::COLOR_GREEN);
break;
}
$props['Status'] = $tag;
}
if ($audit_requests) {
$user_requests = array();
$other_requests = array();
foreach ($audit_requests as $audit_request) {
if ($audit_request->isUser()) {
$user_requests[] = $audit_request;
} else {
$other_requests[] = $audit_request;
}
}
if ($user_requests) {
$props['Auditors'] = $this->renderAuditStatusView(
$user_requests);
}
if ($other_requests) {
$props['Project/Package Auditors'] = $this->renderAuditStatusView(
$other_requests);
}
}
$author_phid = $data->getCommitDetail('authorPHID');
$author_name = $data->getAuthorName();
if (!$repository->isSVN()) {
$authored_info = id(new PHUIStatusItemView());
$author_epoch = $data->getCommitDetail('authorEpoch');
if ($author_epoch !== null) {
$authored_info->setNote(
phabricator_datetime($author_epoch, $viewer));
}
if ($author_phid) {
$authored_info->setTarget($handles[$author_phid]->renderLink());
} else if (strlen($author_name)) {
$authored_info->setTarget($author_name);
}
$props['Authored'] = id(new PHUIStatusListView())
->addItem($authored_info);
}
$committed_info = id(new PHUIStatusItemView())
->setNote(phabricator_datetime($commit->getEpoch(), $viewer));
$committer_phid = $data->getCommitDetail('committerPHID');
$committer_name = $data->getCommitDetail('committer');
if ($committer_phid) {
$committed_info->setTarget($handles[$committer_phid]->renderLink());
} else if (strlen($committer_name)) {
$committed_info->setTarget($committer_name);
} else if ($author_phid) {
$committed_info->setTarget($handles[$author_phid]->renderLink());
} else if (strlen($author_name)) {
$committed_info->setTarget($author_name);
}
$props['Committed'] = id(new PHUIStatusListView())
->addItem($committed_info);
if ($push_logs) {
$pushed_list = new PHUIStatusListView();
foreach ($push_logs as $push_log) {
$pushed_item = id(new PHUIStatusItemView())
->setTarget($handles[$push_log->getPusherPHID()]->renderLink())
->setNote(phabricator_datetime($push_log->getEpoch(), $viewer));
$pushed_list->addItem($pushed_item);
}
$props['Pushed'] = $pushed_list;
}
$reviewer_phid = $data->getCommitDetail('reviewerPHID');
if ($reviewer_phid) {
$props['Reviewer'] = $handles[$reviewer_phid]->renderLink();
}
if ($revision_phid) {
$props['Differential Revision'] = $handles[$revision_phid]->renderLink();
}
$parents = $this->getCommitParents();
if ($parents) {
$props['Parents'] = $viewer->renderHandleList(mpull($parents, 'getPHID'));
}
if ($this->getCommitExists()) {
$props['Branches'] = phutil_tag(
'span',
array(
'id' => 'commit-branches',
),
pht('Unknown'));
$props['Tags'] = phutil_tag(
'span',
array(
'id' => 'commit-tags',
),
pht('Unknown'));
$identifier = $commit->getCommitIdentifier();
$root = $repository->getPathURI("commit/{$identifier}");
Javelin::initBehavior(
'diffusion-commit-branches',
array(
$root.'/branches/' => 'commit-branches',
$root.'/tags/' => 'commit-tags',
));
}
$refs = $this->getCommitRefs();
if ($refs) {
$ref_links = array();
foreach ($refs as $ref_data) {
$ref_links[] = phutil_tag(
'a',
array(
'href' => $ref_data['href'],
),
$ref_data['ref']);
}
$props['References'] = phutil_implode_html(', ', $ref_links);
}
if ($reverts_phids) {
$props[pht('Reverts')] = $viewer->renderHandleList($reverts_phids);
}
if ($reverted_by_phids) {
$props[pht('Reverted By')] = $viewer->renderHandleList(
$reverted_by_phids);
}
if ($task_phids) {
$task_list = array();
foreach ($task_phids as $phid) {
$task_list[] = $handles[$phid]->renderLink();
}
$task_list = phutil_implode_html(phutil_tag('br'), $task_list);
$props['Tasks'] = $task_list;
}
return $props;
}
private function buildComments(PhabricatorRepositoryCommit $commit) {
$timeline = $this->buildTransactionTimeline(
$commit,
new PhabricatorAuditTransactionQuery());
$commit->willRenderTimeline($timeline, $this->getRequest());
return $timeline;
}
private function renderAddCommentPanel(
PhabricatorRepositoryCommit $commit,
array $audit_requests) {
assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
$request = $this->getRequest();
$user = $request->getUser();
if (!$user->isLoggedIn()) {
return id(new PhabricatorApplicationTransactionCommentView())
->setUser($user)
->setRequestURI($request->getRequestURI());
}
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$pane_id = celerity_generate_unique_node_id();
Javelin::initBehavior(
'differential-keyboard-navigation',
array(
'haunt' => $pane_id,
));
$draft = id(new PhabricatorDraft())->loadOneWhere(
'authorPHID = %s AND draftKey = %s',
$user->getPHID(),
'diffusion-audit-'.$commit->getID());
if ($draft) {
$draft = $draft->getDraft();
} else {
$draft = null;
}
$actions = $this->getAuditActions($commit, $audit_requests);
$mailable_source = new PhabricatorMetaMTAMailableDatasource();
$auditor_source = new DiffusionAuditorDatasource();
$form = id(new AphrontFormView())
->setUser($user)
->setAction('/audit/addcomment/')
->addHiddenInput('commit', $commit->getPHID())
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Action'))
->setName('action')
->setID('audit-action')
->setOptions($actions))
->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel(pht('Add Auditors'))
->setName('auditors')
->setControlID('add-auditors')
->setControlStyle('display: none')
->setID('add-auditors-tokenizer')
->setDisableBehavior(true)
->setDatasource($auditor_source))
->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel(pht('Add CCs'))
->setName('ccs')
->setControlID('add-ccs')
->setControlStyle('display: none')
->setID('add-ccs-tokenizer')
->setDisableBehavior(true)
->setDatasource($mailable_source))
->appendChild(
id(new PhabricatorRemarkupControl())
->setLabel(pht('Comments'))
->setName('content')
->setValue($draft)
->setID('audit-content')
->setUser($user))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Submit')));
$header = new PHUIHeaderView();
$header->setHeader(
$is_serious ? pht('Audit Commit') : pht('Creative Accounting'));
Javelin::initBehavior(
'differential-add-reviewers-and-ccs',
array(
'dynamic' => array(
'add-auditors-tokenizer' => array(
'actions' => array('add_auditors' => 1),
'src' => $auditor_source->getDatasourceURI(),
'row' => 'add-auditors',
'placeholder' => $auditor_source->getPlaceholderText(),
),
'add-ccs-tokenizer' => array(
'actions' => array('add_ccs' => 1),
'src' => $mailable_source->getDatasourceURI(),
'row' => 'add-ccs',
'placeholder' => $mailable_source->getPlaceholderText(),
),
),
'select' => 'audit-action',
));
Javelin::initBehavior('differential-feedback-preview', array(
'uri' => '/audit/preview/'.$commit->getID().'/',
'preview' => 'audit-preview',
'content' => 'audit-content',
'action' => 'audit-action',
'previewTokenizers' => array(
'auditors' => 'add-auditors-tokenizer',
'ccs' => 'add-ccs-tokenizer',
),
'inline' => 'inline-comment-preview',
'inlineuri' => '/diffusion/inline/preview/'.$commit->getPHID().'/',
));
$loading = phutil_tag_div(
'aphront-panel-preview-loading-text',
pht('Loading preview...'));
$preview_panel = phutil_tag_div(
'aphront-panel-preview aphront-panel-flush',
array(
phutil_tag('div', array('id' => 'audit-preview'), $loading),
phutil_tag('div', array('id' => 'inline-comment-preview')),
));
// TODO: This is pretty awkward, unify the CSS between Diffusion and
// Differential better.
require_celerity_resource('differential-core-view-css');
$anchor = id(new PhabricatorAnchorView())
->setAnchorName('comment')
->setNavigationMarker(true)
->render();
$comment_box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($form);
return phutil_tag(
'div',
array(
'id' => $pane_id,
),
phutil_tag_div(
'differential-add-comment-panel',
array($anchor, $comment_box, $preview_panel)));
}
/**
* Return a map of available audit actions for rendering into a <select />.
* This shows the user valid actions, and does not show nonsense/invalid
* actions (like closing an already-closed commit, or resigning from a commit
* you have no association with).
*/
private function getAuditActions(
PhabricatorRepositoryCommit $commit,
array $audit_requests) {
assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
$user = $this->getRequest()->getUser();
$user_is_author = ($commit->getAuthorPHID() == $user->getPHID());
$user_request = null;
foreach ($audit_requests as $audit_request) {
if ($audit_request->getAuditorPHID() == $user->getPHID()) {
$user_request = $audit_request;
break;
}
}
$actions = array();
$actions[PhabricatorAuditActionConstants::COMMENT] = true;
$actions[PhabricatorAuditActionConstants::ADD_CCS] = true;
$actions[PhabricatorAuditActionConstants::ADD_AUDITORS] = true;
// We allow you to accept your own commits. A use case here is that you
// notice an issue with your own commit and "Raise Concern" as an indicator
// to other auditors that you're on top of the issue, then later resolve it
// and "Accept". You can not accept on behalf of projects or packages,
// however.
$actions[PhabricatorAuditActionConstants::ACCEPT] = true;
$actions[PhabricatorAuditActionConstants::CONCERN] = true;
// To resign, a user must have authority on some request and not be the
// commit's author.
if (!$user_is_author) {
$may_resign = false;
$authority_map = array_fill_keys($this->auditAuthorityPHIDs, true);
foreach ($audit_requests as $request) {
if (empty($authority_map[$request->getAuditorPHID()])) {
continue;
}
$may_resign = true;
break;
}
// If the user has already resigned, don't show "Resign...".
$status_resigned = PhabricatorAuditStatusConstants::RESIGNED;
if ($user_request) {
if ($user_request->getAuditStatus() == $status_resigned) {
$may_resign = false;
}
}
if ($may_resign) {
$actions[PhabricatorAuditActionConstants::RESIGN] = true;
}
}
$status_concern = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED;
$concern_raised = ($commit->getAuditStatus() == $status_concern);
$can_close_option = PhabricatorEnv::getEnvConfig(
'audit.can-author-close-audit');
if ($can_close_option && $user_is_author && $concern_raised) {
$actions[PhabricatorAuditActionConstants::CLOSE] = true;
}
foreach ($actions as $constant => $ignored) {
$actions[$constant] =
PhabricatorAuditActionConstants::getActionName($constant);
}
return $actions;
}
private function buildMergesTable(PhabricatorRepositoryCommit $commit) {
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$merges = $this->getCommitMerges();
if (!$merges) {
return null;
}
$limit = $this->getMergeDisplayLimit();
$caption = null;
if (count($merges) > $limit) {
$merges = array_slice($merges, 0, $limit);
$caption = new PHUIInfoView();
$caption->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$caption->appendChild(
pht(
'This commit merges a very large number of changes. '.
'Only the first %s are shown.',
new PhutilNumber($limit)));
}
$history_table = id(new DiffusionHistoryTableView())
->setUser($viewer)
->setDiffusionRequest($drequest)
->setHistory($merges);
$history_table->loadRevisions();
$panel = new PHUIObjectBoxView();
$panel->setHeaderText(pht('Merged Changes'));
$panel->setTable($history_table);
if ($caption) {
$panel->setInfoView($caption);
}
return $panel;
}
private function renderHeadsupActionList(
PhabricatorRepositoryCommit $commit,
PhabricatorRepository $repository) {
$request = $this->getRequest();
$user = $request->getUser();
$actions = id(new PhabricatorActionListView())
->setUser($user)
->setObject($commit);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$user,
$commit,
PhabricatorPolicyCapability::CAN_EDIT);
$identifier = $commit->getCommitIdentifier();
$uri = $repository->getPathURI("commit/{$identifier}/edit/");
$action = id(new PhabricatorActionView())
->setName(pht('Edit Commit'))
->setHref($uri)
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$actions->addAction($action);
require_celerity_resource('phabricator-object-selector-css');
require_celerity_resource('javelin-behavior-phabricator-object-selector');
$maniphest = 'PhabricatorManiphestApplication';
if (PhabricatorApplication::isClassInstalled($maniphest)) {
$action = id(new PhabricatorActionView())
->setName(pht('Edit Maniphest Tasks'))
->setIcon('fa-anchor')
->setHref('/search/attach/'.$commit->getPHID().'/TASK/edge/')
->setWorkflow(true)
->setDisabled(!$can_edit);
$actions->addAction($action);
}
$action = id(new PhabricatorActionView())
->setName(pht('Download Raw Diff'))
->setHref($request->getRequestURI()->alter('diff', true))
->setIcon('fa-download');
$actions->addAction($action);
return $actions;
}
private function buildRawDiffResponse(DiffusionRequest $drequest) {
$raw_diff = $this->callConduitWithDiffusionRequest(
'diffusion.rawdiffquery',
array(
'commit' => $drequest->getCommit(),
'path' => $drequest->getPath(),
));
$file = PhabricatorFile::buildFromFileDataOrHash(
$raw_diff,
array(
'name' => $drequest->getCommit().'.diff',
'ttl' => (60 * 60 * 24),
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
));
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$file->attachToObject($drequest->getRepository()->getPHID());
unset($unguarded);
return $file->getRedirectResponse();
}
private function renderAuditStatusView(array $audit_requests) {
assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
$viewer = $this->getViewer();
$authority_map = array_fill_keys($this->auditAuthorityPHIDs, true);
$view = new PHUIStatusListView();
foreach ($audit_requests as $request) {
$code = $request->getAuditStatus();
$item = new PHUIStatusItemView();
$item->setIcon(
PhabricatorAuditStatusConstants::getStatusIcon($code),
PhabricatorAuditStatusConstants::getStatusColor($code),
PhabricatorAuditStatusConstants::getStatusName($code));
$note = array();
foreach ($request->getAuditReasons() as $reason) {
$note[] = phutil_tag('div', array(), $reason);
}
$item->setNote($note);
$auditor_phid = $request->getAuditorPHID();
$target = $viewer->renderHandle($auditor_phid);
$item->setTarget($target);
if (isset($authority_map[$auditor_phid])) {
$item->setHighlighted(true);
}
$view->addItem($item);
}
return $view;
}
private function linkBugtraq($corpus) {
$url = PhabricatorEnv::getEnvConfig('bugtraq.url');
if (!strlen($url)) {
return $corpus;
}
$regexes = PhabricatorEnv::getEnvConfig('bugtraq.logregex');
if (!$regexes) {
return $corpus;
}
$parser = id(new PhutilBugtraqParser())
->setBugtraqPattern("[[ {$url} | %BUGID% ]]")
->setBugtraqCaptureExpression(array_shift($regexes));
$select = array_shift($regexes);
if ($select) {
$parser->setBugtraqSelectExpression($select);
}
return $parser->processCorpus($corpus);
}
private function buildTableOfContents(array $changesets) {
$drequest = $this->getDiffusionRequest();
$viewer = $this->getViewer();
$toc_view = id(new PHUIDiffTableOfContentsListView())
->setUser($viewer);
// TODO: This is hacky, we just want access to the linkX() methods on
// DiffusionView.
$diffusion_view = id(new DiffusionEmptyResultView())
->setDiffusionRequest($drequest);
$have_owners = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorOwnersApplication',
$viewer);
if (!$changesets) {
$have_owners = false;
}
if ($have_owners) {
if ($viewer->getPHID()) {
$packages = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withAuthorityPHIDs(array($viewer->getPHID()))
->execute();
$toc_view->setAuthorityPackages($packages);
}
$repository = $drequest->getRepository();
$repository_phid = $repository->getPHID();
$control_query = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer)
->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE))
->withControl($repository_phid, mpull($changesets, 'getFilename'));
$control_query->execute();
}
foreach ($changesets as $changeset_id => $changeset) {
$path = $changeset->getFilename();
$anchor = substr(md5($path), 0, 8);
$history_link = $diffusion_view->linkHistory($path);
$browse_link = $diffusion_view->linkBrowse(
$path,
array(
'type' => $changeset->getFileType(),
));
$item = id(new PHUIDiffTableOfContentsItemView())
->setChangeset($changeset)
->setAnchor($anchor)
->setContext(
array(
$history_link,
' ',
$browse_link,
));
if ($have_owners) {
$packages = $control_query->getControllingPackagesForPath(
$repository_phid,
$changeset->getFilename());
$item->setPackages($packages);
}
$toc_view->addItem($item);
}
return $toc_view;
}
private function loadCommitState() {
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$commit = $drequest->getCommit();
// TODO: We could use futures here and resolve these calls in parallel.
$exceptions = array();
try {
$parent_refs = $this->callConduitWithDiffusionRequest(
'diffusion.commitparentsquery',
array(
'commit' => $commit,
));
if ($parent_refs) {
$parents = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepository($repository)
->withIdentifiers($parent_refs)
->execute();
} else {
$parents = array();
}
$this->commitParents = $parents;
} catch (Exception $ex) {
$this->commitParents = false;
$exceptions[] = $ex;
}
$merge_limit = $this->getMergeDisplayLimit();
try {
if ($repository->isSVN()) {
$this->commitMerges = array();
} else {
$merges = $this->callConduitWithDiffusionRequest(
'diffusion.mergedcommitsquery',
array(
'commit' => $commit,
'limit' => $merge_limit + 1,
));
$this->commitMerges = DiffusionPathChange::newFromConduit($merges);
}
} catch (Exception $ex) {
$this->commitMerges = false;
$exceptions[] = $ex;
}
try {
if ($repository->isGit()) {
$refs = $this->callConduitWithDiffusionRequest(
'diffusion.refsquery',
array(
'commit' => $commit,
));
} else {
$refs = array();
}
$this->commitRefs = $refs;
} catch (Exception $ex) {
$this->commitRefs = false;
$exceptions[] = $ex;
}
if ($exceptions) {
$exists = $this->callConduitWithDiffusionRequest(
'diffusion.existsquery',
array(
'commit' => $commit,
));
if ($exists) {
$this->commitExists = true;
foreach ($exceptions as $exception) {
$this->commitErrors[] = $exception->getMessage();
}
} else {
$this->commitExists = false;
$this->commitErrors[] = pht(
'This commit no longer exists in the repository. It may have '.
'been part of a branch which was deleted.');
}
} else {
$this->commitExists = true;
$this->commitErrors = array();
}
}
private function getMergeDisplayLimit() {
return 50;
}
private function getCommitExists() {
if ($this->commitExists === null) {
$this->loadCommitState();
}
return $this->commitExists;
}
private function getCommitParents() {
if ($this->commitParents === null) {
$this->loadCommitState();
}
return $this->commitParents;
}
private function getCommitRefs() {
if ($this->commitRefs === null) {
$this->loadCommitState();
}
return $this->commitRefs;
}
private function getCommitMerges() {
if ($this->commitMerges === null) {
$this->loadCommitState();
}
return $this->commitMerges;
}
private function getCommitErrors() {
if ($this->commitErrors === null) {
$this->loadCommitState();
}
return $this->commitErrors;
}
}
diff --git a/src/applications/diffusion/controller/DiffusionRepositoryController.php b/src/applications/diffusion/controller/DiffusionRepositoryController.php
index 9fc948d19a..18989818b6 100644
--- a/src/applications/diffusion/controller/DiffusionRepositoryController.php
+++ b/src/applications/diffusion/controller/DiffusionRepositoryController.php
@@ -1,758 +1,752 @@
<?php
final class DiffusionRepositoryController extends DiffusionController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$content = array();
$crumbs = $this->buildCrumbs();
$content[] = $this->buildPropertiesTable($drequest->getRepository());
// Before we do any work, make sure we're looking at a some content: we're
// on a valid branch, and the repository is not empty.
$page_has_content = false;
$empty_title = null;
$empty_message = null;
// If this VCS supports branches, check that the selected branch actually
// exists.
if ($drequest->supportsBranches()) {
// NOTE: Mercurial may have multiple branch heads with the same name.
$ref_cursors = id(new PhabricatorRepositoryRefCursorQuery())
->setViewer($viewer)
->withRepositoryPHIDs(array($repository->getPHID()))
->withRefTypes(array(PhabricatorRepositoryRefCursor::TYPE_BRANCH))
->withRefNames(array($drequest->getBranch()))
->execute();
if ($ref_cursors) {
// This is a valid branch, so we necessarily have some content.
$page_has_content = true;
} else {
$empty_title = pht('No Such Branch');
$empty_message = pht(
'There is no branch named "%s" in this repository.',
$drequest->getBranch());
}
}
// If we didn't find any branches, check if there are any commits at all.
// This can tailor the message for empty repositories.
if (!$page_has_content) {
$any_commit = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withRepository($repository)
->setLimit(1)
->execute();
if ($any_commit) {
if (!$drequest->supportsBranches()) {
$page_has_content = true;
}
} else {
$empty_title = pht('Empty Repository');
$empty_message = pht('This repository does not have any commits yet.');
}
}
if ($page_has_content) {
$content[] = $this->buildNormalContent($drequest);
} else {
$content[] = id(new PHUIInfoView())
->setTitle($empty_title)
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(array($empty_message));
}
return $this->newPage()
->setTitle(
array(
$repository->getName(),
$repository->getDisplayName(),
))
->setCrumbs($crumbs)
->appendChild($content);
}
private function buildNormalContent(DiffusionRequest $drequest) {
$request = $this->getRequest();
$repository = $drequest->getRepository();
$phids = array();
$content = array();
try {
$history_results = $this->callConduitWithDiffusionRequest(
'diffusion.historyquery',
array(
'commit' => $drequest->getCommit(),
'path' => $drequest->getPath(),
'offset' => 0,
'limit' => 15,
));
$history = DiffusionPathChange::newFromConduit(
$history_results['pathChanges']);
foreach ($history as $item) {
$data = $item->getCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
if ($data->getCommitDetail('committerPHID')) {
$phids[$data->getCommitDetail('committerPHID')] = true;
}
}
}
$history_exception = null;
} catch (Exception $ex) {
$history_results = null;
$history = null;
$history_exception = $ex;
}
$browse_pager = id(new PHUIPagerView())
->readFromRequest($request);
try {
$browse_results = DiffusionBrowseResultSet::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.browsequery',
array(
'path' => $drequest->getPath(),
'commit' => $drequest->getCommit(),
'limit' => $browse_pager->getPageSize() + 1,
)));
$browse_paths = $browse_results->getPaths();
$browse_paths = $browse_pager->sliceResults($browse_paths);
foreach ($browse_paths as $item) {
$data = $item->getLastCommitData();
if ($data) {
if ($data->getCommitDetail('authorPHID')) {
$phids[$data->getCommitDetail('authorPHID')] = true;
}
if ($data->getCommitDetail('committerPHID')) {
$phids[$data->getCommitDetail('committerPHID')] = true;
}
}
}
$browse_exception = null;
} catch (Exception $ex) {
$browse_results = null;
$browse_paths = null;
$browse_exception = $ex;
}
$phids = array_keys($phids);
$handles = $this->loadViewerHandles($phids);
if ($browse_results) {
$readme = $this->renderDirectoryReadme($browse_results);
} else {
$readme = null;
}
$content[] = $this->buildBrowseTable(
$browse_results,
$browse_paths,
$browse_exception,
$handles,
$browse_pager);
$content[] = $this->buildHistoryTable(
$history_results,
$history,
$history_exception);
try {
$content[] = $this->buildTagListTable($drequest);
} catch (Exception $ex) {
if (!$repository->isImporting()) {
$content[] = $this->renderStatusMessage(
pht('Unable to Load Tags'),
$ex->getMessage());
}
}
try {
$content[] = $this->buildBranchListTable($drequest);
} catch (Exception $ex) {
if (!$repository->isImporting()) {
$content[] = $this->renderStatusMessage(
pht('Unable to Load Branches'),
$ex->getMessage());
}
}
if ($readme) {
$content[] = $readme;
}
return $content;
}
private function buildPropertiesTable(PhabricatorRepository $repository) {
$user = $this->getRequest()->getUser();
$header = id(new PHUIHeaderView())
->setHeader($repository->getName())
->setUser($user)
->setPolicyObject($repository);
if (!$repository->isTracked()) {
$header->setStatus('fa-ban', 'dark', pht('Inactive'));
} else if ($repository->isImporting()) {
$ratio = $repository->loadImportProgress();
$percentage = sprintf('%.2f%%', 100 * $ratio);
$header->setStatus(
'fa-clock-o',
'indigo',
pht('Importing (%s)...', $percentage));
} else {
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
}
$actions = $this->buildActionList($repository);
$view = id(new PHUIPropertyListView())
->setObject($repository)
->setUser($user);
if ($repository->isHosted()) {
$ssh_uri = $repository->getSSHCloneURIObject();
if ($ssh_uri) {
$clone_uri = $this->renderCloneCommand(
$repository,
$ssh_uri,
$repository->getServeOverSSH(),
'/settings/panel/ssh/');
$view->addProperty(
$repository->isSVN()
? pht('Checkout (SSH)')
: pht('Clone (SSH)'),
$clone_uri);
}
$http_uri = $repository->getHTTPCloneURIObject();
if ($http_uri) {
$clone_uri = $this->renderCloneCommand(
$repository,
$http_uri,
$repository->getServeOverHTTP(),
PhabricatorEnv::getEnvConfig('diffusion.allow-http-auth')
? '/settings/panel/vcspassword/'
: null);
$view->addProperty(
$repository->isSVN()
? pht('Checkout (HTTP)')
: pht('Clone (HTTP)'),
$clone_uri);
}
} else {
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$view->addProperty(
pht('Clone'),
$this->renderCloneCommand(
$repository,
$repository->getPublicCloneURI()));
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
$view->addProperty(
pht('Checkout'),
$this->renderCloneCommand(
$repository,
$repository->getPublicCloneURI()));
break;
}
}
$view->invokeWillRenderEvent();
$description = $repository->getDetail('description');
if (strlen($description)) {
$description = PhabricatorMarkupEngine::renderOneObject(
$repository,
'description',
$user);
$view->addSectionHeader(
pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description);
}
$view->setActionList($actions);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($view);
$info = null;
$drequest = $this->getDiffusionRequest();
// Try to load alternatives. This may fail for repositories which have not
// cloned yet. If it does, just ignore it and continue.
try {
$alternatives = $drequest->getRefAlternatives();
} catch (ConduitClientException $ex) {
$alternatives = array();
}
if ($alternatives) {
$message = array(
pht(
'The ref "%s" is ambiguous in this repository.',
$drequest->getBranch()),
' ',
phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'refs',
)),
),
pht('View Alternatives')),
);
$messages = array($message);
$info = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(array($message));
$box->setInfoView($info);
}
return $box;
}
private function buildBranchListTable(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
if ($drequest->getBranch() === null) {
return null;
}
$limit = 15;
$branches = $this->callConduitWithDiffusionRequest(
'diffusion.branchquery',
array(
'closed' => false,
'limit' => $limit + 1,
));
if (!$branches) {
return null;
}
$more_branches = (count($branches) > $limit);
$branches = array_slice($branches, 0, $limit);
$branches = DiffusionRepositoryRef::loadAllFromDictionaries($branches);
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIdentifiers(mpull($branches, 'getCommitIdentifier'))
->withRepository($drequest->getRepository())
->execute();
$table = id(new DiffusionBranchTableView())
->setUser($viewer)
->setDiffusionRequest($drequest)
->setBranches($branches)
->setCommits($commits);
$panel = new PHUIObjectBoxView();
$header = new PHUIHeaderView();
$header->setHeader(pht('Branches'));
if ($more_branches) {
$header->setSubHeader(pht('Showing %d branches.', $limit));
}
- $icon = id(new PHUIIconView())
- ->setIconFont('fa-code-fork');
-
$button = new PHUIButtonView();
$button->setText(pht('Show All Branches'));
$button->setTag('a');
- $button->setIcon($icon);
+ $button->setIcon('fa-code-fork');
$button->setHref($drequest->generateURI(
array(
'action' => 'branches',
)));
$header->addActionLink($button);
$panel->setHeader($header);
$panel->setTable($table);
return $panel;
}
private function buildTagListTable(DiffusionRequest $drequest) {
$viewer = $this->getRequest()->getUser();
$repository = $drequest->getRepository();
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
// no tags in SVN
return null;
}
$tag_limit = 15;
$tags = array();
$tags = DiffusionRepositoryTag::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.tagsquery',
array(
// On the home page, we want to find tags on any branch.
'commit' => null,
'limit' => $tag_limit + 1,
)));
if (!$tags) {
return null;
}
$more_tags = (count($tags) > $tag_limit);
$tags = array_slice($tags, 0, $tag_limit);
$commits = id(new DiffusionCommitQuery())
->setViewer($viewer)
->withIdentifiers(mpull($tags, 'getCommitIdentifier'))
->withRepository($repository)
->needCommitData(true)
->execute();
$view = id(new DiffusionTagListView())
->setUser($viewer)
->setDiffusionRequest($drequest)
->setTags($tags)
->setCommits($commits);
$phids = $view->getRequiredHandlePHIDs();
$handles = $this->loadViewerHandles($phids);
$view->setHandles($handles);
$panel = new PHUIObjectBoxView();
$header = new PHUIHeaderView();
$header->setHeader(pht('Tags'));
if ($more_tags) {
$header->setSubHeader(
pht('Showing the %d most recent tags.', $tag_limit));
}
- $icon = id(new PHUIIconView())
- ->setIconFont('fa-tag');
-
$button = new PHUIButtonView();
$button->setText(pht('Show All Tags'));
$button->setTag('a');
- $button->setIcon($icon);
+ $button->setIcon('fa-tag');
$button->setHref($drequest->generateURI(
array(
'action' => 'tags',
)));
$header->addActionLink($button);
$panel->setHeader($header);
$panel->setTable($view);
return $panel;
}
private function buildActionList(PhabricatorRepository $repository) {
$viewer = $this->getRequest()->getUser();
$edit_uri = $repository->getPathURI('edit/');
$view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($repository);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$repository,
PhabricatorPolicyCapability::CAN_EDIT);
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Repository'))
->setIcon('fa-pencil')
->setHref($edit_uri)
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit));
if ($repository->isHosted()) {
$push_uri = $this->getApplicationURI(
'pushlog/?repositories='.$repository->getMonogram());
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('View Push Logs'))
->setIcon('fa-list-alt')
->setHref($push_uri));
}
return $view;
}
private function buildHistoryTable(
$history_results,
$history,
$history_exception) {
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
if ($history_exception) {
if ($repository->isImporting()) {
return $this->renderStatusMessage(
pht('Still Importing...'),
pht(
'This repository is still importing. History is not yet '.
'available.'));
} else {
return $this->renderStatusMessage(
pht('Unable to Retrieve History'),
$history_exception->getMessage());
}
}
$history_table = id(new DiffusionHistoryTableView())
->setUser($viewer)
->setDiffusionRequest($drequest)
->setHistory($history);
// TODO: Super sketchy.
$history_table->loadRevisions();
if ($history_results) {
$history_table->setParents($history_results['parents']);
}
$history_table->setIsHead(true);
$icon = id(new PHUIIconView())
- ->setIconFont('fa-list-alt');
+ ->setIcon('fa-list-alt');
$button = id(new PHUIButtonView())
->setText(pht('View Full History'))
->setHref($drequest->generateURI(
array(
'action' => 'history',
)))
->setTag('a')
->setIcon($icon);
$panel = new PHUIObjectBoxView();
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Commits'))
->addActionLink($button);
$panel->setHeader($header);
$panel->setTable($history_table);
return $panel;
}
private function buildBrowseTable(
$browse_results,
$browse_paths,
$browse_exception,
array $handles,
PHUIPagerView $pager) {
require_celerity_resource('diffusion-icons-css');
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
if ($browse_exception) {
if ($repository->isImporting()) {
// The history table renders a useful message.
return null;
} else {
return $this->renderStatusMessage(
pht('Unable to Retrieve Paths'),
$browse_exception->getMessage());
}
}
$browse_table = id(new DiffusionBrowseTableView())
->setUser($viewer)
->setDiffusionRequest($drequest)
->setHandles($handles);
if ($browse_paths) {
$browse_table->setPaths($browse_paths);
} else {
$browse_table->setPaths(array());
}
$browse_uri = $drequest->generateURI(array('action' => 'browse'));
$browse_panel = new PHUIObjectBoxView();
$header = id(new PHUIHeaderView())
->setHeader(pht('Repository'));
$icon = id(new PHUIIconView())
- ->setIconFont('fa-folder-open');
+ ->setIcon('fa-folder-open');
$button = new PHUIButtonView();
$button->setText(pht('Browse Repository'));
$button->setTag('a');
$button->setIcon($icon);
$button->setHref($browse_uri);
$header->addActionLink($button);
$browse_panel->setHeader($header);
$locate_panel = null;
if ($repository->canUsePathTree()) {
Javelin::initBehavior(
'diffusion-locate-file',
array(
'controlID' => 'locate-control',
'inputID' => 'locate-input',
'browseBaseURI' => (string)$drequest->generateURI(
array(
'action' => 'browse',
)),
'uri' => (string)$drequest->generateURI(
array(
'action' => 'pathtree',
)),
));
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormTypeaheadControl())
->setHardpointID('locate-control')
->setID('locate-input')
->setLabel(pht('Locate File')));
$form_box = id(new PHUIBoxView())
->appendChild($form->buildLayoutView());
$locate_panel = id(new PHUIObjectBoxView())
->setHeaderText('Locate File')
->appendChild($form_box);
}
$browse_panel->setTable($browse_table);
$pager->setURI($browse_uri, 'offset');
if ($pager->willShowPagingControls()) {
$pager_box = $this->renderTablePagerBox($pager);
} else {
$pager_box = null;
}
return array(
$locate_panel,
$browse_panel,
$pager_box,
);
}
private function renderCloneCommand(
PhabricatorRepository $repository,
$uri,
$serve_mode = null,
$manage_uri = null) {
require_celerity_resource('diffusion-icons-css');
Javelin::initBehavior('select-on-click');
switch ($repository->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
$command = csprintf(
'git clone %R',
$uri);
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
$command = csprintf(
'hg clone %R',
$uri);
break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
if ($repository->isHosted()) {
$command = csprintf(
'svn checkout %R %R',
$uri,
$repository->getCloneName());
} else {
$command = csprintf(
'svn checkout %R',
$uri);
}
break;
}
$input = javelin_tag(
'input',
array(
'type' => 'text',
'value' => (string)$command,
'class' => 'diffusion-clone-uri',
'sigil' => 'select-on-click',
'readonly' => 'true',
));
$extras = array();
if ($serve_mode) {
if ($serve_mode === PhabricatorRepository::SERVE_READONLY) {
$extras[] = pht('(Read Only)');
}
}
if ($manage_uri) {
if ($this->getRequest()->getUser()->isLoggedIn()) {
$extras[] = phutil_tag(
'a',
array(
'href' => $manage_uri,
),
pht('Manage Credentials'));
}
}
if ($extras) {
$extras = phutil_implode_html(' ', $extras);
$extras = phutil_tag(
'div',
array(
'class' => 'diffusion-clone-extras',
),
$extras);
}
return array($input, $extras);
}
}
diff --git a/src/applications/diffusion/view/DiffusionBranchTableView.php b/src/applications/diffusion/view/DiffusionBranchTableView.php
index 0f4594e576..462f296bcb 100644
--- a/src/applications/diffusion/view/DiffusionBranchTableView.php
+++ b/src/applications/diffusion/view/DiffusionBranchTableView.php
@@ -1,165 +1,165 @@
<?php
final class DiffusionBranchTableView extends DiffusionView {
private $branches;
private $commits = array();
public function setBranches(array $branches) {
assert_instances_of($branches, 'DiffusionRepositoryRef');
$this->branches = $branches;
return $this;
}
public function setCommits(array $commits) {
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
$this->commits = mpull($commits, null, 'getCommitIdentifier');
return $this;
}
public function render() {
$drequest = $this->getDiffusionRequest();
$current_branch = $drequest->getBranch();
$repository = $drequest->getRepository();
$commits = $this->commits;
$viewer = $this->getUser();
$buildables = $this->loadBuildables($commits);
$have_builds = false;
$can_close_branches = ($repository->isHg());
Javelin::initBehavior('phabricator-tooltips');
$doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: Autoclose');
$rows = array();
$rowc = array();
foreach ($this->branches as $branch) {
$commit = idx($commits, $branch->getCommitIdentifier());
if ($commit) {
$details = $commit->getSummary();
$datetime = phabricator_datetime($commit->getEpoch(), $viewer);
$buildable = idx($buildables, $commit->getPHID());
if ($buildable) {
$build_status = $this->renderBuildable($buildable);
$have_builds = true;
} else {
$build_status = null;
}
} else {
$datetime = null;
$details = null;
$build_status = null;
}
switch ($repository->shouldSkipAutocloseBranch($branch->getShortName())) {
case PhabricatorRepository::BECAUSE_REPOSITORY_IMPORTING:
$icon = 'fa-times bluegrey';
$tip = pht('Repository Importing');
break;
case PhabricatorRepository::BECAUSE_AUTOCLOSE_DISABLED:
$icon = 'fa-times bluegrey';
$tip = pht('Repository Autoclose Disabled');
break;
case PhabricatorRepository::BECAUSE_BRANCH_UNTRACKED:
$icon = 'fa-times bluegrey';
$tip = pht('Branch Untracked');
break;
case PhabricatorRepository::BECAUSE_BRANCH_NOT_AUTOCLOSE:
$icon = 'fa-times bluegrey';
$tip = pht('Branch Autoclose Disabled');
break;
case null:
$icon = 'fa-check bluegrey';
$tip = pht('Autoclose Enabled');
break;
default:
$icon = 'fa-question';
$tip = pht('Status Unknown');
break;
}
$status_icon = id(new PHUIIconView())
- ->setIconFont($icon)
+ ->setIcon($icon)
->addSigil('has-tooltip')
->setHref($doc_href)
->setMetadata(
array(
'tip' => $tip,
'size' => 200,
));
$fields = $branch->getRawFields();
$closed = idx($fields, 'closed');
if ($closed) {
$status = pht('Closed');
} else {
$status = pht('Open');
}
$rows[] = array(
$this->linkBranchHistory($branch->getShortName()),
phutil_tag(
'a',
array(
'href' => $drequest->generateURI(
array(
'action' => 'browse',
'branch' => $branch->getShortName(),
)),
),
$branch->getShortName()),
self::linkCommit(
$drequest->getRepository(),
$branch->getCommitIdentifier()),
$build_status,
$status,
AphrontTableView::renderSingleDisplayLine($details),
$status_icon,
$datetime,
);
if ($branch->getShortName() == $current_branch) {
$rowc[] = 'highlighted';
} else {
$rowc[] = null;
}
}
$view = new AphrontTableView($rows);
$view->setHeaders(
array(
null,
pht('Branch'),
pht('Head'),
null,
pht('State'),
pht('Details'),
null,
pht('Committed'),
));
$view->setColumnClasses(
array(
'',
'pri',
'',
'icon',
'',
'wide',
'',
'',
));
$view->setColumnVisibility(
array(
true,
true,
true,
$have_builds,
$can_close_branches,
));
$view->setRowClasses($rowc);
return $view->render();
}
}
diff --git a/src/applications/diffusion/view/DiffusionView.php b/src/applications/diffusion/view/DiffusionView.php
index 74de704dc3..331c172866 100644
--- a/src/applications/diffusion/view/DiffusionView.php
+++ b/src/applications/diffusion/view/DiffusionView.php
@@ -1,232 +1,232 @@
<?php
abstract class DiffusionView extends AphrontView {
private $diffusionRequest;
final public function setDiffusionRequest(DiffusionRequest $request) {
$this->diffusionRequest = $request;
return $this;
}
final public function getDiffusionRequest() {
return $this->diffusionRequest;
}
final public function linkHistory($path) {
$href = $this->getDiffusionRequest()->generateURI(
array(
'action' => 'history',
'path' => $path,
));
return $this->renderHistoryLink($href);
}
final public function linkBranchHistory($branch) {
$href = $this->getDiffusionRequest()->generateURI(
array(
'action' => 'history',
'branch' => $branch,
));
return $this->renderHistoryLink($href);
}
final public function linkTagHistory($tag) {
$href = $this->getDiffusionRequest()->generateURI(
array(
'action' => 'history',
'commit' => $tag,
));
return $this->renderHistoryLink($href);
}
private function renderHistoryLink($href) {
return javelin_tag(
'a',
array(
'href' => $href,
'class' => 'diffusion-link-icon',
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => pht('History'),
'align' => 'E',
),
),
- id(new PHUIIconView())->setIconFont('fa-history bluegrey'));
+ id(new PHUIIconView())->setIcon('fa-history bluegrey'));
}
final public function linkBrowse($path, array $details = array()) {
require_celerity_resource('diffusion-icons-css');
Javelin::initBehavior('phabricator-tooltips');
$file_type = idx($details, 'type');
unset($details['type']);
$display_name = idx($details, 'name');
unset($details['name']);
if (strlen($display_name)) {
$display_name = phutil_tag(
'span',
array(
'class' => 'diffusion-browse-name',
),
$display_name);
}
if (isset($details['external'])) {
$href = id(new PhutilURI('/diffusion/external/'))
->setQueryParams(
array(
'uri' => idx($details, 'external'),
'id' => idx($details, 'hash'),
));
$tip = pht('Browse External');
} else {
$href = $this->getDiffusionRequest()->generateURI(
$details + array(
'action' => 'browse',
'path' => $path,
));
$tip = pht('Browse');
}
$icon = DifferentialChangeType::getIconForFileType($file_type);
- $icon_view = id(new PHUIIconView())->setIconFont("{$icon} blue");
+ $icon_view = id(new PHUIIconView())->setIcon($icon);
// If we're rendering a file or directory name, don't show the tooltip.
if ($display_name !== null) {
$sigil = null;
$meta = null;
} else {
$sigil = 'has-tooltip';
$meta = array(
'tip' => $tip,
'align' => 'E',
);
}
return javelin_tag(
'a',
array(
'href' => $href,
'class' => 'diffusion-link-icon',
'sigil' => $sigil,
'meta' => $meta,
),
array(
$icon_view,
$display_name,
));
}
final public static function linkCommit(
PhabricatorRepository $repository,
$commit,
$summary = '') {
$commit_name = $repository->formatCommitName($commit, $local = true);
if (strlen($summary)) {
$commit_name .= ': '.$summary;
}
return phutil_tag(
'a',
array(
'href' => $repository->getCommitURI($commit),
),
$commit_name);
}
final public static function linkRevision($id) {
if (!$id) {
return null;
}
return phutil_tag(
'a',
array(
'href' => "/D{$id}",
),
"D{$id}");
}
final public static function renderName($name) {
$email = new PhutilEmailAddress($name);
if ($email->getDisplayName() && $email->getDomainName()) {
Javelin::initBehavior('phabricator-tooltips', array());
require_celerity_resource('aphront-tooltip-css');
return javelin_tag(
'span',
array(
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $email->getAddress(),
'align' => 'E',
'size' => 'auto',
),
),
$email->getDisplayName());
}
return hsprintf('%s', $name);
}
final protected function renderBuildable(HarbormasterBuildable $buildable) {
$status = $buildable->getBuildableStatus();
$icon = HarbormasterBuildable::getBuildableStatusIcon($status);
$color = HarbormasterBuildable::getBuildableStatusColor($status);
$name = HarbormasterBuildable::getBuildableStatusName($status);
$icon_view = id(new PHUIIconView())
- ->setIconFont($icon.' '.$color);
+ ->setIcon($icon.' '.$color);
$tooltip_view = javelin_tag(
'span',
array(
'sigil' => 'has-tooltip',
'meta' => array('tip' => $name),
),
$icon_view);
Javelin::initBehavior('phabricator-tooltips');
return phutil_tag(
'a',
array('href' => '/'.$buildable->getMonogram()),
$tooltip_view);
}
final protected function loadBuildables(array $commits) {
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
if (!$commits) {
return array();
}
$viewer = $this->getUser();
$harbormaster_app = 'PhabricatorHarbormasterApplication';
$have_harbormaster = PhabricatorApplication::isClassInstalledForViewer(
$harbormaster_app,
$viewer);
if ($have_harbormaster) {
$buildables = id(new HarbormasterBuildableQuery())
->setViewer($viewer)
->withBuildablePHIDs(mpull($commits, 'getPHID'))
->withManualBuildables(false)
->execute();
$buildables = mpull($buildables, null, 'getBuildablePHID');
} else {
$buildables = array();
}
return $buildables;
}
}
diff --git a/src/applications/diviner/controller/DivinerBookController.php b/src/applications/diviner/controller/DivinerBookController.php
index ebaf559775..0c84955b2f 100644
--- a/src/applications/diviner/controller/DivinerBookController.php
+++ b/src/applications/diviner/controller/DivinerBookController.php
@@ -1,140 +1,140 @@
<?php
final class DivinerBookController extends DivinerController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$book_name = $request->getURIData('book');
$book = id(new DivinerBookQuery())
->setViewer($viewer)
->withNames(array($book_name))
->needRepositories(true)
->executeOne();
if (!$book) {
return new Aphront404Response();
}
$actions = $this->buildActionView($viewer, $book);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
$crumbs->addTextCrumb(
$book->getShortTitle(),
'/book/'.$book->getName().'/');
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
- ->setIconFont('fa-bars')
+ ->setIcon('fa-bars')
->addClass('phui-mobile-menu')
->setDropdownMenu($actions);
$header = id(new PHUIHeaderView())
->setHeader($book->getTitle())
->setUser($viewer)
->setPolicyObject($book)
->setEpoch($book->getDateModified())
->addActionLink($action_button);
// TODO: This could probably look better.
if ($book->getRepositoryPHID()) {
$header->addTag(
id(new PHUITagView())
->setType(PHUITagView::TYPE_STATE)
->setBackgroundColor(PHUITagView::COLOR_BLUE)
->setName($book->getRepository()->getMonogram()));
}
$document = new PHUIDocumentViewPro();
$document->setHeader($header);
$document->addClass('diviner-view');
$atoms = id(new DivinerAtomQuery())
->setViewer($viewer)
->withBookPHIDs(array($book->getPHID()))
->withGhosts(false)
->withIsDocumentable(true)
->execute();
$atoms = msort($atoms, 'getSortKey');
$group_spec = $book->getConfig('groups');
if (!is_array($group_spec)) {
$group_spec = array();
}
$groups = mgroup($atoms, 'getGroupName');
$groups = array_select_keys($groups, array_keys($group_spec)) + $groups;
if (isset($groups[''])) {
$no_group = $groups[''];
unset($groups['']);
$groups[''] = $no_group;
}
$out = array();
foreach ($groups as $group => $atoms) {
$group_name = $book->getGroupName($group);
if (!strlen($group_name)) {
$group_name = pht('Free Radicals');
}
$section = id(new DivinerSectionView())
->setHeader($group_name);
$section->addContent($this->renderAtomList($atoms));
$out[] = $section;
}
$preface = $book->getPreface();
$preface_view = null;
if (strlen($preface)) {
$preface_view =
PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($preface),
'default',
$viewer);
}
$document->appendChild($preface_view);
$document->appendChild($out);
return $this->buildApplicationPage(
array(
$crumbs,
$document,
),
array(
'title' => $book->getTitle(),
));
}
private function buildActionView(
PhabricatorUser $user,
DivinerLiveBook $book) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$user,
$book,
PhabricatorPolicyCapability::CAN_EDIT);
$action_view = id(new PhabricatorActionListView())
->setUser($user)
->setObject($book);
$action_view->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Book'))
->setIcon('fa-pencil')
->setHref('/book/'.$book->getName().'/edit/')
->setDisabled(!$can_edit));
return $action_view;
}
}
diff --git a/src/applications/diviner/controller/DivinerMainController.php b/src/applications/diviner/controller/DivinerMainController.php
index 3050199c8a..97149778c1 100644
--- a/src/applications/diviner/controller/DivinerMainController.php
+++ b/src/applications/diviner/controller/DivinerMainController.php
@@ -1,84 +1,81 @@
<?php
final class DivinerMainController extends DivinerController {
public function shouldAllowPublic() {
return true;
}
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'));
- $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);
+ ->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 = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($text),
'default',
$viewer);
$document->appendChild($text);
}
return $this->buildApplicationPage(
array(
$crumbs,
$document,
),
array(
'title' => pht('Documentation Books'),
));
}
}
diff --git a/src/applications/drydock/controller/DrydockBlueprintViewController.php b/src/applications/drydock/controller/DrydockBlueprintViewController.php
index 2566c69840..b23b869fd4 100644
--- a/src/applications/drydock/controller/DrydockBlueprintViewController.php
+++ b/src/applications/drydock/controller/DrydockBlueprintViewController.php
@@ -1,246 +1,246 @@
<?php
final class DrydockBlueprintViewController extends DrydockBlueprintController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$blueprint = id(new DrydockBlueprintQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$blueprint) {
return new Aphront404Response();
}
$title = $blueprint->getBlueprintName();
$header = id(new PHUIHeaderView())
->setHeader($title)
->setUser($viewer)
->setPolicyObject($blueprint);
if ($blueprint->getIsDisabled()) {
$header->setStatus('fa-ban', 'red', pht('Disabled'));
} else {
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
}
$actions = $this->buildActionListView($blueprint);
$properties = $this->buildPropertyListView($blueprint, $actions);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID()));
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
$field_list = PhabricatorCustomField::getObjectFields(
$blueprint,
PhabricatorCustomField::ROLE_VIEW);
$field_list
->setViewer($viewer)
->readFieldsFromStorage($blueprint);
$field_list->appendFieldsToPropertyList(
$blueprint,
$viewer,
$properties);
$resource_box = $this->buildResourceBox($blueprint);
$authorizations_box = $this->buildAuthorizationsBox($blueprint);
$timeline = $this->buildTransactionTimeline(
$blueprint,
new DrydockBlueprintTransactionQuery());
$timeline->setShouldTerminate(true);
$log_query = id(new DrydockLogQuery())
->withBlueprintPHIDs(array($blueprint->getPHID()));
$log_box = $this->buildLogBox(
$log_query,
$this->getApplicationURI("blueprint/{$id}/logs/query/all/"));
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
$resource_box,
$authorizations_box,
$log_box,
$timeline,
),
array(
'title' => $title,
));
}
private function buildActionListView(DrydockBlueprint $blueprint) {
$viewer = $this->getViewer();
$id = $blueprint->getID();
$view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($blueprint);
$edit_uri = $this->getApplicationURI("blueprint/edit/{$id}/");
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$blueprint,
PhabricatorPolicyCapability::CAN_EDIT);
$view->addAction(
id(new PhabricatorActionView())
->setHref($edit_uri)
->setName(pht('Edit Blueprint'))
->setIcon('fa-pencil')
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit));
if (!$blueprint->getIsDisabled()) {
$disable_name = pht('Disable Blueprint');
$disable_icon = 'fa-ban';
$disable_uri = $this->getApplicationURI("blueprint/{$id}/disable/");
} else {
$disable_name = pht('Enable Blueprint');
$disable_icon = 'fa-check';
$disable_uri = $this->getApplicationURI("blueprint/{$id}/enable/");
}
$view->addAction(
id(new PhabricatorActionView())
->setHref($disable_uri)
->setName($disable_name)
->setIcon($disable_icon)
->setWorkflow(true)
->setDisabled(!$can_edit));
return $view;
}
private function buildPropertyListView(
DrydockBlueprint $blueprint,
PhabricatorActionListView $actions) {
$view = new PHUIPropertyListView();
$view->setActionList($actions);
$view->addProperty(
pht('Type'),
$blueprint->getImplementation()->getBlueprintName());
return $view;
}
private function buildResourceBox(DrydockBlueprint $blueprint) {
$viewer = $this->getViewer();
$resources = id(new DrydockResourceQuery())
->setViewer($viewer)
->withBlueprintPHIDs(array($blueprint->getPHID()))
->withStatuses(
array(
DrydockResourceStatus::STATUS_PENDING,
DrydockResourceStatus::STATUS_ACTIVE,
))
->setLimit(100)
->execute();
$resource_list = id(new DrydockResourceListView())
->setUser($viewer)
->setResources($resources)
->render()
->setNoDataString(pht('This blueprint has no active resources.'));
$id = $blueprint->getID();
$resources_uri = "blueprint/{$id}/resources/query/all/";
$resources_uri = $this->getApplicationURI($resources_uri);
$resource_header = id(new PHUIHeaderView())
->setHeader(pht('Active Resources'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($resources_uri)
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setText(pht('View All')));
return id(new PHUIObjectBoxView())
->setHeader($resource_header)
->setObjectList($resource_list);
}
private function buildAuthorizationsBox(DrydockBlueprint $blueprint) {
$viewer = $this->getViewer();
$limit = 25;
// If there are pending authorizations against this blueprint, make sure
// we show them first.
$pending_authorizations = id(new DrydockAuthorizationQuery())
->setViewer($viewer)
->withBlueprintPHIDs(array($blueprint->getPHID()))
->withObjectStates(
array(
DrydockAuthorization::OBJECTAUTH_ACTIVE,
))
->withBlueprintStates(
array(
DrydockAuthorization::BLUEPRINTAUTH_REQUESTED,
))
->setLimit($limit)
->execute();
$all_authorizations = id(new DrydockAuthorizationQuery())
->setViewer($viewer)
->withBlueprintPHIDs(array($blueprint->getPHID()))
->withObjectStates(
array(
DrydockAuthorization::OBJECTAUTH_ACTIVE,
))
->withBlueprintStates(
array(
DrydockAuthorization::BLUEPRINTAUTH_REQUESTED,
DrydockAuthorization::BLUEPRINTAUTH_AUTHORIZED,
))
->setLimit($limit)
->execute();
$authorizations =
mpull($pending_authorizations, null, 'getPHID') +
mpull($all_authorizations, null, 'getPHID');
$authorization_list = id(new DrydockAuthorizationListView())
->setUser($viewer)
->setAuthorizations($authorizations)
->setNoDataString(
pht('No objects have active authorizations to use this blueprint.'));
$id = $blueprint->getID();
$authorizations_uri = "blueprint/{$id}/authorizations/query/all/";
$authorizations_uri = $this->getApplicationURI($authorizations_uri);
$authorizations_header = id(new PHUIHeaderView())
->setHeader(pht('Active Authorizations'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($authorizations_uri)
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setText(pht('View All')));
return id(new PHUIObjectBoxView())
->setHeader($authorizations_header)
->setObjectList($authorization_list);
}
}
diff --git a/src/applications/drydock/controller/DrydockController.php b/src/applications/drydock/controller/DrydockController.php
index ddb6788fb6..17b8d34916 100644
--- a/src/applications/drydock/controller/DrydockController.php
+++ b/src/applications/drydock/controller/DrydockController.php
@@ -1,109 +1,109 @@
<?php
abstract class DrydockController extends PhabricatorController {
protected function buildLocksTab($owner_phid) {
$locks = DrydockSlotLock::loadLocks($owner_phid);
$rows = array();
foreach ($locks as $lock) {
$rows[] = array(
$lock->getID(),
$lock->getLockKey(),
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No slot locks held.'))
->setHeaders(
array(
pht('ID'),
pht('Lock Key'),
))
->setColumnClasses(
array(
null,
'wide',
));
return id(new PHUIPropertyListView())
->addRawContent($table);
}
protected function buildCommandsTab($target_phid) {
$viewer = $this->getViewer();
$commands = id(new DrydockCommandQuery())
->setViewer($viewer)
->withTargetPHIDs(array($target_phid))
->execute();
$consumed_yes = id(new PHUIIconView())
- ->setIconFont('fa-check green');
+ ->setIcon('fa-check green');
$consumed_no = id(new PHUIIconView())
- ->setIconFont('fa-clock-o grey');
+ ->setIcon('fa-clock-o grey');
$rows = array();
foreach ($commands as $command) {
$rows[] = array(
$command->getID(),
$viewer->renderHandle($command->getAuthorPHID()),
$command->getCommand(),
($command->getIsConsumed()
? $consumed_yes
: $consumed_no),
phabricator_datetime($command->getDateCreated(), $viewer),
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No commands issued.'))
->setHeaders(
array(
pht('ID'),
pht('From'),
pht('Command'),
null,
pht('Date'),
))
->setColumnClasses(
array(
null,
null,
'wide',
null,
null,
));
return id(new PHUIPropertyListView())
->addRawContent($table);
}
protected function buildLogBox(DrydockLogQuery $query, $all_uri) {
$viewer = $this->getViewer();
$logs = $query
->setViewer($viewer)
->setLimit(100)
->execute();
$log_table = id(new DrydockLogListView())
->setUser($viewer)
->setLogs($logs)
->render();
$log_header = id(new PHUIHeaderView())
->setHeader(pht('Logs'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($all_uri)
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setText(pht('View All')));
return id(new PHUIObjectBoxView())
->setHeader($log_header)
->setTable($log_table);
}
}
diff --git a/src/applications/drydock/controller/DrydockResourceViewController.php b/src/applications/drydock/controller/DrydockResourceViewController.php
index d392796f57..61319fbdbc 100644
--- a/src/applications/drydock/controller/DrydockResourceViewController.php
+++ b/src/applications/drydock/controller/DrydockResourceViewController.php
@@ -1,185 +1,185 @@
<?php
final class DrydockResourceViewController extends DrydockResourceController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$resource = id(new DrydockResourceQuery())
->setViewer($viewer)
->withIDs(array($id))
->needUnconsumedCommands(true)
->executeOne();
if (!$resource) {
return new Aphront404Response();
}
$title = pht(
'Resource %s %s',
$resource->getID(),
$resource->getResourceName());
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setPolicyObject($resource)
->setHeader($title);
if ($resource->isReleasing()) {
$header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing'));
}
$actions = $this->buildActionListView($resource);
$properties = $this->buildPropertyListView($resource, $actions);
$id = $resource->getID();
$resource_uri = $this->getApplicationURI("resource/{$id}/");
$log_query = id(new DrydockLogQuery())
->withResourcePHIDs(array($resource->getPHID()));
$log_box = $this->buildLogBox(
$log_query,
$this->getApplicationURI("resource/{$id}/logs/query/all/"));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Resource %d', $resource->getID()));
$locks = $this->buildLocksTab($resource->getPHID());
$commands = $this->buildCommandsTab($resource->getPHID());
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties, pht('Properties'))
->addPropertyList($locks, pht('Slot Locks'))
->addPropertyList($commands, pht('Commands'));
$lease_box = $this->buildLeaseBox($resource);
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
$lease_box,
$log_box,
),
array(
'title' => $title,
));
}
private function buildActionListView(DrydockResource $resource) {
$viewer = $this->getViewer();
$view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($resource);
$can_release = $resource->canRelease();
if ($resource->isReleasing()) {
$can_release = false;
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$resource,
PhabricatorPolicyCapability::CAN_EDIT);
$uri = '/resource/'.$resource->getID().'/release/';
$uri = $this->getApplicationURI($uri);
$view->addAction(
id(new PhabricatorActionView())
->setHref($uri)
->setName(pht('Release Resource'))
->setIcon('fa-times')
->setWorkflow(true)
->setDisabled(!$can_release || !$can_edit));
return $view;
}
private function buildPropertyListView(
DrydockResource $resource,
PhabricatorActionListView $actions) {
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())
->setActionList($actions);
$status = $resource->getStatus();
$status = DrydockResourceStatus::getNameForStatus($status);
$view->addProperty(
pht('Status'),
$status);
$until = $resource->getUntil();
if ($until) {
$until_display = phabricator_datetime($until, $viewer);
} else {
$until_display = phutil_tag('em', array(), pht('Never'));
}
$view->addProperty(pht('Expires'), $until_display);
$view->addProperty(
pht('Resource Type'),
$resource->getType());
$view->addProperty(
pht('Blueprint'),
$viewer->renderHandle($resource->getBlueprintPHID()));
$attributes = $resource->getAttributes();
if ($attributes) {
$view->addSectionHeader(
pht('Attributes'), 'fa-list-ul');
foreach ($attributes as $key => $value) {
$view->addProperty($key, $value);
}
}
return $view;
}
private function buildLeaseBox(DrydockResource $resource) {
$viewer = $this->getViewer();
$leases = id(new DrydockLeaseQuery())
->setViewer($viewer)
->withResourcePHIDs(array($resource->getPHID()))
->withStatuses(
array(
DrydockLeaseStatus::STATUS_PENDING,
DrydockLeaseStatus::STATUS_ACQUIRED,
DrydockLeaseStatus::STATUS_ACTIVE,
))
->setLimit(100)
->execute();
$id = $resource->getID();
$leases_uri = "resource/{$id}/leases/query/all/";
$leases_uri = $this->getApplicationURI($leases_uri);
$lease_header = id(new PHUIHeaderView())
->setHeader(pht('Active Leases'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($leases_uri)
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setText(pht('View All')));
$lease_list = id(new DrydockLeaseListView())
->setUser($viewer)
->setLeases($leases)
->render()
->setNoDataString(pht('This resource has no active leases.'));
return id(new PHUIObjectBoxView())
->setHeader($lease_header)
->setObjectList($lease_list);
}
}
diff --git a/src/applications/drydock/view/DrydockLogListView.php b/src/applications/drydock/view/DrydockLogListView.php
index 4e1fe664cd..845457f9bc 100644
--- a/src/applications/drydock/view/DrydockLogListView.php
+++ b/src/applications/drydock/view/DrydockLogListView.php
@@ -1,107 +1,107 @@
<?php
final class DrydockLogListView extends AphrontView {
private $logs;
public function setLogs(array $logs) {
assert_instances_of($logs, 'DrydockLog');
$this->logs = $logs;
return $this;
}
public function render() {
$logs = $this->logs;
$viewer = $this->getUser();
$view = new PHUIObjectItemListView();
$types = DrydockLogType::getAllLogTypes();
$rows = array();
foreach ($logs as $log) {
$blueprint_phid = $log->getBlueprintPHID();
if ($blueprint_phid) {
$blueprint = $viewer->renderHandle($blueprint_phid);
} else {
$blueprint = null;
}
$resource_phid = $log->getResourcePHID();
if ($resource_phid) {
$resource = $viewer->renderHandle($resource_phid);
} else {
$resource = null;
}
$lease_phid = $log->getLeasePHID();
if ($lease_phid) {
$lease = $viewer->renderHandle($lease_phid);
} else {
$lease = null;
}
if ($log->isComplete()) {
$type_key = $log->getType();
if (isset($types[$type_key])) {
$type_object = id(clone $types[$type_key])
->setLog($log)
->setViewer($viewer);
$log_data = $log->getData();
$type = $type_object->getLogTypeName();
$icon = $type_object->getLogTypeIcon($log_data);
$data = $type_object->renderLog($log_data);
} else {
$type = pht('<Unknown: %s>', $type_key);
$data = null;
$icon = 'fa-question-circle red';
}
} else {
$type = phutil_tag('em', array(), pht('Restricted'));
$data = phutil_tag(
'em',
array(),
pht('You do not have permission to view this log event.'));
$icon = 'fa-lock grey';
}
$rows[] = array(
$blueprint,
$resource,
$lease,
- id(new PHUIIconView())->setIconFont($icon),
+ id(new PHUIIconView())->setIcon($icon),
$type,
$data,
phabricator_datetime($log->getEpoch(), $viewer),
);
}
$table = id(new AphrontTableView($rows))
->setDeviceReadyTable(true)
->setHeaders(
array(
pht('Blueprint'),
pht('Resource'),
pht('Lease'),
null,
pht('Type'),
pht('Data'),
pht('Date'),
))
->setColumnClasses(
array(
'',
'',
'',
'icon',
'',
'wide',
'',
));
return $table;
}
}
diff --git a/src/applications/files/controller/PhabricatorFileComposeController.php b/src/applications/files/controller/PhabricatorFileComposeController.php
index f589617696..1eaafdbad0 100644
--- a/src/applications/files/controller/PhabricatorFileComposeController.php
+++ b/src/applications/files/controller/PhabricatorFileComposeController.php
@@ -1,222 +1,222 @@
<?php
final class PhabricatorFileComposeController
extends PhabricatorFileController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$color_map = PhabricatorFilesComposeIconBuiltinFile::getAllColors();
$icon_map = $this->getIconMap();
if ($request->isFormPost()) {
$project_phid = $request->getStr('projectPHID');
if ($project_phid) {
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withPHIDs(array($project_phid))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
}
$icon = $request->getStr('icon');
$color = $request->getStr('color');
$composer = id(new PhabricatorFilesComposeIconBuiltinFile())
->setIcon($icon)
->setColor($color);
$data = $composer->loadBuiltinFileData();
$file = PhabricatorFile::buildFromFileDataOrHash(
$data,
array(
'name' => $composer->getBuiltinDisplayName(),
'profile' => true,
'canCDN' => true,
));
if ($project_phid) {
$edit_uri = '/project/manage/'.$project->getID().'/';
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorProjectTransaction::TYPE_IMAGE)
->setNewValue($file->getPHID());
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true);
$editor->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri);
} else {
$content = array(
'phid' => $file->getPHID(),
);
return id(new AphrontAjaxResponse())->setContent($content);
}
}
$value_color = head_key($color_map);
$value_icon = head_key($icon_map);
require_celerity_resource('people-profile-css');
$buttons = array();
foreach ($color_map as $color => $info) {
$quip = idx($info, 'quip');
$buttons[] = javelin_tag(
'button',
array(
'class' => 'grey profile-image-button',
'sigil' => 'has-tooltip compose-select-color',
'style' => 'margin: 0 8px 8px 0',
'meta' => array(
'color' => $color,
'tip' => $quip,
),
),
id(new PHUIIconView())
->addClass('compose-background-'.$color));
}
$icons = array();
foreach ($icon_map as $icon => $spec) {
$quip = idx($spec, 'quip');
$icons[] = javelin_tag(
'button',
array(
'class' => 'grey profile-image-button',
'sigil' => 'has-tooltip compose-select-icon',
'style' => 'margin: 0 8px 8px 0',
'meta' => array(
'icon' => $icon,
'tip' => $quip,
),
),
id(new PHUIIconView())
- ->setIconFont($icon)
+ ->setIcon($icon)
->addClass('compose-icon-bg'));
}
$dialog_id = celerity_generate_unique_node_id();
$color_input_id = celerity_generate_unique_node_id();
$icon_input_id = celerity_generate_unique_node_id();
$preview_id = celerity_generate_unique_node_id();
$preview = id(new PHUIIconView())
->setID($preview_id)
->addClass('compose-background-'.$value_color)
- ->setIconFont($value_icon)
+ ->setIcon($value_icon)
->addClass('compose-icon-bg');
$color_input = javelin_tag(
'input',
array(
'type' => 'hidden',
'name' => 'color',
'value' => $value_color,
'id' => $color_input_id,
));
$icon_input = javelin_tag(
'input',
array(
'type' => 'hidden',
'name' => 'icon',
'value' => $value_icon,
'id' => $icon_input_id,
));
Javelin::initBehavior('phabricator-tooltips');
Javelin::initBehavior(
'icon-composer',
array(
'dialogID' => $dialog_id,
'colorInputID' => $color_input_id,
'iconInputID' => $icon_input_id,
'previewID' => $preview_id,
'defaultColor' => $value_color,
'defaultIcon' => $value_icon,
));
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setFormID($dialog_id)
->setClass('compose-dialog')
->setTitle(pht('Compose Image'))
->appendChild(
phutil_tag(
'div',
array(
'class' => 'compose-header',
),
pht('Choose Background Color')))
->appendChild($buttons)
->appendChild(
phutil_tag(
'div',
array(
'class' => 'compose-header',
),
pht('Choose Icon')))
->appendChild($icons)
->appendChild(
phutil_tag(
'div',
array(
'class' => 'compose-header',
),
pht('Preview')))
->appendChild($preview)
->appendChild($color_input)
->appendChild($icon_input)
->addCancelButton('/')
->addSubmitButton(pht('Save Image'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function getIconMap() {
$icon_map = PhabricatorFilesComposeIconBuiltinFile::getAllIcons();
$first = array(
'fa-briefcase',
'fa-tags',
'fa-folder',
'fa-group',
'fa-bug',
'fa-trash-o',
'fa-calendar',
'fa-flag-checkered',
'fa-envelope',
'fa-truck',
'fa-lock',
'fa-umbrella',
'fa-cloud',
'fa-building',
'fa-credit-card',
'fa-flask',
);
$icon_map = array_select_keys($icon_map, $first) + $icon_map;
return $icon_map;
}
}
diff --git a/src/applications/files/controller/PhabricatorFileIconSetSelectController.php b/src/applications/files/controller/PhabricatorFileIconSetSelectController.php
index ed7d18a5ee..1bd14d29d0 100644
--- a/src/applications/files/controller/PhabricatorFileIconSetSelectController.php
+++ b/src/applications/files/controller/PhabricatorFileIconSetSelectController.php
@@ -1,98 +1,98 @@
<?php
final class PhabricatorFileIconSetSelectController
extends PhabricatorFileController {
public function handleRequest(AphrontRequest $request) {
$key = $request->getURIData('key');
$set = PhabricatorIconSet::getIconSetByKey($key);
if (!$set) {
return new Aphront404Response();
}
$v_icon = $request->getStr('icon');
if ($request->isFormPost()) {
$icon = $set->getIcon($v_icon);
if ($icon) {
$payload = array(
'value' => $icon->getKey(),
'display' => $set->renderIconForControl($icon),
);
return id(new AphrontAjaxResponse())
->setContent($payload);
}
}
require_celerity_resource('phui-icon-set-selector-css');
Javelin::initBehavior('phabricator-tooltips');
$ii = 0;
$buttons = array();
foreach ($set->getIcons() as $icon) {
$label = $icon->getLabel();
$view = id(new PHUIIconView())
- ->setIconFont($icon->getIcon());
+ ->setIcon($icon->getIcon());
$classes = array();
$classes[] = 'icon-button';
$is_selected = ($icon->getKey() == $v_icon);
if ($is_selected) {
$classes[] = 'selected';
}
$is_disabled = $icon->getIsDisabled();
if ($is_disabled && !$is_selected) {
continue;
}
$aural = javelin_tag(
'span',
array(
'aural' => true,
),
pht('Choose "%s" Icon', $label));
$buttons[] = javelin_tag(
'button',
array(
'class' => implode(' ', $classes),
'name' => 'icon',
'value' => $icon->getKey(),
'type' => 'submit',
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $label,
),
),
array(
$aural,
$view,
));
if ((++$ii % 4) == 0) {
$buttons[] = phutil_tag('br');
}
}
$buttons = phutil_tag(
'div',
array(
'class' => 'icon-grid',
),
$buttons);
$dialog_title = $set->getSelectIconTitleText();
return $this->newDialog()
->setTitle($dialog_title)
->appendChild($buttons)
->addCancelButton('/');
}
}
diff --git a/src/applications/files/iconset/PhabricatorIconSet.php b/src/applications/files/iconset/PhabricatorIconSet.php
index ad8ac4b381..baf5422375 100644
--- a/src/applications/files/iconset/PhabricatorIconSet.php
+++ b/src/applications/files/iconset/PhabricatorIconSet.php
@@ -1,70 +1,70 @@
<?php
abstract class PhabricatorIconSet
extends Phobject {
final public function getIconSetKey() {
return $this->getPhobjectClassConstant('ICONSETKEY');
}
public function getChooseButtonText() {
return pht('Choose Icon...');
}
public function getSelectIconTitleText() {
return pht('Choose Icon');
}
public function getSelectURI() {
$key = $this->getIconSetKey();
return "/file/iconset/{$key}/select/";
}
final public function getIcons() {
$icons = $this->newIcons();
// TODO: Validate icons.
$icons = mpull($icons, null, 'getKey');
return $icons;
}
final public function getIcon($key) {
$icons = $this->getIcons();
return idx($icons, $key);
}
final public function getIconLabel($key) {
$icon = $this->getIcon($key);
if ($icon) {
return $icon->getLabel();
}
return $key;
}
final public function renderIconForControl(PhabricatorIconSetIcon $icon) {
return phutil_tag(
'span',
array(),
array(
- id(new PHUIIconView())->setIconFont($icon->getIcon()),
+ id(new PHUIIconView())->setIcon($icon->getIcon()),
' ',
$icon->getLabel(),
));
}
final public static function getIconSetByKey($key) {
$sets = self::getAllIconSets();
return idx($sets, $key);
}
final public static function getAllIconSets() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getIconSetKey')
->execute();
}
}
diff --git a/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
index 300cb79f23..f9a0807ab1 100644
--- a/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
+++ b/src/applications/harbormaster/controller/HarbormasterBuildableViewController.php
@@ -1,353 +1,353 @@
<?php
final class HarbormasterBuildableViewController
extends HarbormasterController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$buildable = id(new HarbormasterBuildableQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->needBuildableHandles(true)
->needContainerHandles(true)
->executeOne();
if (!$buildable) {
return new Aphront404Response();
}
$id = $buildable->getID();
// Pull builds and build targets.
$builds = id(new HarbormasterBuildQuery())
->setViewer($viewer)
->withBuildablePHIDs(array($buildable->getPHID()))
->needBuildTargets(true)
->execute();
list($lint, $unit) = $this->renderLintAndUnit($buildable, $builds);
$buildable->attachBuilds($builds);
$object = $buildable->getBuildableObject();
$build_list = $this->buildBuildList($buildable);
$title = pht('Buildable %d', $id);
$header = id(new PHUIHeaderView())
->setHeader($title)
->setUser($viewer)
->setPolicyObject($buildable);
$box = id(new PHUIObjectBoxView())
->setHeader($header);
$timeline = $this->buildTransactionTimeline(
$buildable,
new HarbormasterBuildableTransactionQuery());
$timeline->setShouldTerminate(true);
$actions = $this->buildActionList($buildable);
$this->buildPropertyLists($box, $buildable, $actions);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($buildable->getMonogram());
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$lint,
$unit,
$build_list,
$timeline,
),
array(
'title' => $title,
));
}
private function buildActionList(HarbormasterBuildable $buildable) {
$request = $this->getRequest();
$viewer = $request->getUser();
$id = $buildable->getID();
$list = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($buildable);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$buildable,
PhabricatorPolicyCapability::CAN_EDIT);
$can_restart = false;
$can_resume = false;
$can_pause = false;
$can_abort = false;
foreach ($buildable->getBuilds() as $build) {
if ($build->canRestartBuild()) {
$can_restart = true;
}
if ($build->canResumeBuild()) {
$can_resume = true;
}
if ($build->canPauseBuild()) {
$can_pause = true;
}
if ($build->canAbortBuild()) {
$can_abort = true;
}
}
$restart_uri = "buildable/{$id}/restart/";
$pause_uri = "buildable/{$id}/pause/";
$resume_uri = "buildable/{$id}/resume/";
$abort_uri = "buildable/{$id}/abort/";
$list->addAction(
id(new PhabricatorActionView())
->setIcon('fa-repeat')
->setName(pht('Restart All Builds'))
->setHref($this->getApplicationURI($restart_uri))
->setWorkflow(true)
->setDisabled(!$can_restart || !$can_edit));
$list->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pause')
->setName(pht('Pause All Builds'))
->setHref($this->getApplicationURI($pause_uri))
->setWorkflow(true)
->setDisabled(!$can_pause || !$can_edit));
$list->addAction(
id(new PhabricatorActionView())
->setIcon('fa-play')
->setName(pht('Resume All Builds'))
->setHref($this->getApplicationURI($resume_uri))
->setWorkflow(true)
->setDisabled(!$can_resume || !$can_edit));
$list->addAction(
id(new PhabricatorActionView())
->setIcon('fa-exclamation-triangle')
->setName(pht('Abort All Builds'))
->setHref($this->getApplicationURI($abort_uri))
->setWorkflow(true)
->setDisabled(!$can_abort || !$can_edit));
return $list;
}
private function buildPropertyLists(
PHUIObjectBoxView $box,
HarbormasterBuildable $buildable,
PhabricatorActionListView $actions) {
$request = $this->getRequest();
$viewer = $request->getUser();
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($buildable)
->setActionList($actions);
$box->addPropertyList($properties);
if ($buildable->getContainerHandle() !== null) {
$properties->addProperty(
pht('Container'),
$buildable->getContainerHandle()->renderLink());
}
$properties->addProperty(
pht('Buildable'),
$buildable->getBuildableHandle()->renderLink());
$properties->addProperty(
pht('Origin'),
$buildable->getIsManualBuildable()
? pht('Manual Buildable')
: pht('Automatic Buildable'));
}
private function buildBuildList(HarbormasterBuildable $buildable) {
$viewer = $this->getRequest()->getUser();
$build_list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($buildable->getBuilds() as $build) {
$view_uri = $this->getApplicationURI('/build/'.$build->getID().'/');
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Build %d', $build->getID()))
->setHeader($build->getName())
->setHref($view_uri);
$status = $build->getBuildStatus();
$item->setStatusIcon(
'fa-dot-circle-o '.HarbormasterBuild::getBuildStatusColor($status),
HarbormasterBuild::getBuildStatusName($status));
$item->addAttribute(HarbormasterBuild::getBuildStatusName($status));
if ($build->isRestarting()) {
$item->addIcon('fa-repeat', pht('Restarting'));
} else if ($build->isPausing()) {
$item->addIcon('fa-pause', pht('Pausing'));
} else if ($build->isResuming()) {
$item->addIcon('fa-play', pht('Resuming'));
}
$build_id = $build->getID();
$restart_uri = "build/restart/{$build_id}/buildable/";
$resume_uri = "build/resume/{$build_id}/buildable/";
$pause_uri = "build/pause/{$build_id}/buildable/";
$abort_uri = "build/abort/{$build_id}/buildable/";
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-repeat')
->setName(pht('Restart'))
->setHref($this->getApplicationURI($restart_uri))
->setWorkflow(true)
->setDisabled(!$build->canRestartBuild()));
if ($build->canResumeBuild()) {
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-play')
->setName(pht('Resume'))
->setHref($this->getApplicationURI($resume_uri))
->setWorkflow(true));
} else {
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-pause')
->setName(pht('Pause'))
->setHref($this->getApplicationURI($pause_uri))
->setWorkflow(true)
->setDisabled(!$build->canPauseBuild()));
}
$targets = $build->getBuildTargets();
if ($targets) {
$target_list = id(new PHUIStatusListView());
foreach ($targets as $target) {
$status = $target->getTargetStatus();
$icon = HarbormasterBuildTarget::getBuildTargetStatusIcon($status);
$color = HarbormasterBuildTarget::getBuildTargetStatusColor($status);
$status_name =
HarbormasterBuildTarget::getBuildTargetStatusName($status);
$name = $target->getName();
$target_list->addItem(
id(new PHUIStatusItemView())
->setIcon($icon, $color, $status_name)
->setTarget(pht('Target %d', $target->getID()))
->setNote($name));
}
$target_box = id(new PHUIBoxView())
->addPadding(PHUI::PADDING_SMALL)
->appendChild($target_list);
$item->appendChild($target_box);
}
$build_list->addItem($item);
}
$build_list->setFlush(true);
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Builds'))
->appendChild($build_list);
return $box;
}
private function renderLintAndUnit(
HarbormasterBuildable $buildable,
array $builds) {
$viewer = $this->getViewer();
$targets = array();
foreach ($builds as $build) {
foreach ($build->getBuildTargets() as $target) {
$targets[] = $target;
}
}
if (!$targets) {
return;
}
$target_phids = mpull($targets, 'getPHID');
$lint_data = id(new HarbormasterBuildLintMessage())->loadAllWhere(
'buildTargetPHID IN (%Ls)',
$target_phids);
$unit_data = id(new HarbormasterBuildUnitMessage())->loadAllWhere(
'buildTargetPHID IN (%Ls)',
$target_phids);
if ($lint_data) {
$lint_table = id(new HarbormasterLintPropertyView())
->setUser($viewer)
->setLimit(10)
->setLintMessages($lint_data);
$lint_href = $this->getApplicationURI('lint/'.$buildable->getID().'/');
$lint_header = id(new PHUIHeaderView())
->setHeader(pht('Lint Messages'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($lint_href)
- ->setIconFont('fa-list-ul')
+ ->setIcon('fa-list-ul')
->setText('View All'));
$lint = id(new PHUIObjectBoxView())
->setHeader($lint_header)
->setTable($lint_table);
} else {
$lint = null;
}
if ($unit_data) {
$unit_table = id(new HarbormasterUnitPropertyView())
->setUser($viewer)
->setLimit(25)
->setUnitMessages($unit_data);
$unit_href = $this->getApplicationURI('unit/'.$buildable->getID().'/');
$unit_header = id(new PHUIHeaderView())
->setHeader(pht('Unit Tests'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($unit_href)
- ->setIconFont('fa-list-ul')
+ ->setIcon('fa-list-ul')
->setText('View All'));
$unit = id(new PHUIObjectBoxView())
->setHeader($unit_header)
->setTable($unit_table);
} else {
$unit = null;
}
return array($lint, $unit);
}
}
diff --git a/src/applications/harbormaster/controller/HarbormasterPlanViewController.php b/src/applications/harbormaster/controller/HarbormasterPlanViewController.php
index e306eaef7c..ed1381006b 100644
--- a/src/applications/harbormaster/controller/HarbormasterPlanViewController.php
+++ b/src/applications/harbormaster/controller/HarbormasterPlanViewController.php
@@ -1,459 +1,457 @@
<?php
final class HarbormasterPlanViewController extends HarbormasterPlanController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$plan = id(new HarbormasterBuildPlanQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$plan) {
return new Aphront404Response();
}
$timeline = $this->buildTransactionTimeline(
$plan,
new HarbormasterBuildPlanTransactionQuery());
$timeline->setShouldTerminate(true);
$title = $plan->getName();
$header = id(new PHUIHeaderView())
->setHeader($plan->getName())
->setUser($viewer)
->setPolicyObject($plan);
$box = id(new PHUIObjectBoxView())
->setHeader($header);
$actions = $this->buildActionList($plan);
$this->buildPropertyLists($box, $plan, $actions);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Plan %d', $id));
list($step_list, $has_any_conflicts, $would_deadlock) =
$this->buildStepList($plan);
if ($would_deadlock) {
$box->setFormErrors(
array(
pht(
'This build plan will deadlock when executed, due to '.
'circular dependencies present in the build plan. '.
'Examine the step list and resolve the deadlock.'),
));
} else if ($has_any_conflicts) {
// A deadlocking build will also cause all the artifacts to be
// invalid, so we just skip showing this message if that's the
// case.
$box->setFormErrors(
array(
pht(
'This build plan has conflicts in one or more build steps. '.
'Examine the step list and resolve the listed errors.'),
));
}
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$step_list,
$timeline,
),
array(
'title' => $title,
));
}
private function buildStepList(HarbormasterBuildPlan $plan) {
$viewer = $this->getViewer();
$run_order = HarbormasterBuildGraph::determineDependencyExecution($plan);
$steps = id(new HarbormasterBuildStepQuery())
->setViewer($viewer)
->withBuildPlanPHIDs(array($plan->getPHID()))
->execute();
$steps = mpull($steps, null, 'getPHID');
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$plan,
PhabricatorPolicyCapability::CAN_EDIT);
$step_list = id(new PHUIObjectItemListView())
->setUser($viewer)
->setNoDataString(
pht('This build plan does not have any build steps yet.'));
$i = 1;
$last_depth = 0;
$has_any_conflicts = false;
$is_deadlocking = false;
foreach ($run_order as $run_ref) {
$step = $steps[$run_ref['node']->getPHID()];
$depth = $run_ref['depth'] + 1;
if ($last_depth !== $depth) {
$last_depth = $depth;
$i = 1;
} else {
$i++;
}
$implementation = null;
try {
$implementation = $step->getStepImplementation();
} catch (Exception $ex) {
// We can't initialize the implementation. This might be because
// it's been renamed or no longer exists.
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Step %d.%d', $depth, $i))
->setHeader(pht('Unknown Implementation'))
->setStatusIcon('fa-warning red')
->addAttribute(pht(
'This step has an invalid implementation (%s).',
$step->getClassName()));
$step_list->addItem($item);
continue;
}
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Step %d.%d', $depth, $i))
->setHeader($step->getName());
$item->addAttribute($implementation->getDescription());
$step_id = $step->getID();
$view_uri = $this->getApplicationURI("step/view/{$step_id}/");
$item->setHref($view_uri);
$depends = $step->getStepImplementation()->getDependencies($step);
$inputs = $step->getStepImplementation()->getArtifactInputs();
$outputs = $step->getStepImplementation()->getArtifactOutputs();
$has_conflicts = false;
if ($depends || $inputs || $outputs) {
$available_artifacts =
HarbormasterBuildStepImplementation::getAvailableArtifacts(
$plan,
$step,
null);
$available_artifacts = ipull($available_artifacts, 'type');
list($depends_ui, $has_conflicts) = $this->buildDependsOnList(
$depends,
pht('Depends On'),
$steps);
list($inputs_ui, $has_conflicts) = $this->buildArtifactList(
$inputs,
'in',
pht('Input Artifacts'),
$available_artifacts);
list($outputs_ui) = $this->buildArtifactList(
$outputs,
'out',
pht('Output Artifacts'),
array());
$item->appendChild(
phutil_tag(
'div',
array(
'class' => 'harbormaster-artifact-io',
),
array(
$depends_ui,
$inputs_ui,
$outputs_ui,
)));
}
if ($has_conflicts) {
$has_any_conflicts = true;
$item->setStatusIcon('fa-warning red');
}
if ($run_ref['cycle']) {
$is_deadlocking = true;
}
if ($is_deadlocking) {
$item->setStatusIcon('fa-warning red');
}
$step_list->addItem($item);
}
$step_list->setFlush(true);
$plan_id = $plan->getID();
$header = id(new PHUIHeaderView())
->setHeader(pht('Build Steps'))
->addActionLink(
id(new PHUIButtonView())
->setText(pht('Add Build Step'))
->setHref($this->getApplicationURI("step/add/{$plan_id}/"))
->setTag('a')
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-plus'))
+ ->setIcon('fa-plus')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$step_box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($step_list);
return array($step_box, $has_any_conflicts, $is_deadlocking);
}
private function buildActionList(HarbormasterBuildPlan $plan) {
$viewer = $this->getViewer();
$id = $plan->getID();
$list = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($plan);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$plan,
PhabricatorPolicyCapability::CAN_EDIT);
$list->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Plan'))
->setHref($this->getApplicationURI("plan/edit/{$id}/"))
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit)
->setIcon('fa-pencil'));
if ($plan->isDisabled()) {
$list->addAction(
id(new PhabricatorActionView())
->setName(pht('Enable Plan'))
->setHref($this->getApplicationURI("plan/disable/{$id}/"))
->setWorkflow(true)
->setDisabled(!$can_edit)
->setIcon('fa-check'));
} else {
$list->addAction(
id(new PhabricatorActionView())
->setName(pht('Disable Plan'))
->setHref($this->getApplicationURI("plan/disable/{$id}/"))
->setWorkflow(true)
->setDisabled(!$can_edit)
->setIcon('fa-ban'));
}
$can_run = ($can_edit && $plan->canRunManually());
$list->addAction(
id(new PhabricatorActionView())
->setName(pht('Run Plan Manually'))
->setHref($this->getApplicationURI("plan/run/{$id}/"))
->setWorkflow(true)
->setDisabled(!$can_run)
->setIcon('fa-play-circle'));
return $list;
}
private function buildPropertyLists(
PHUIObjectBoxView $box,
HarbormasterBuildPlan $plan,
PhabricatorActionListView $actions) {
$request = $this->getRequest();
$viewer = $request->getUser();
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($plan)
->setActionList($actions);
$box->addPropertyList($properties);
$properties->addProperty(
pht('Created'),
phabricator_datetime($plan->getDateCreated(), $viewer));
}
private function buildArtifactList(
array $artifacts,
$kind,
$name,
array $available_artifacts) {
$has_conflicts = false;
if (!$artifacts) {
return array(null, $has_conflicts);
}
$this->requireResource('harbormaster-css');
$header = phutil_tag(
'div',
array(
'class' => 'harbormaster-artifact-summary-header',
),
$name);
$is_input = ($kind == 'in');
$list = new PHUIStatusListView();
foreach ($artifacts as $artifact) {
$error = null;
$key = idx($artifact, 'key');
if (!strlen($key)) {
$bound = phutil_tag('em', array(), pht('(null)'));
if ($is_input) {
// This is an unbound input. For now, all inputs are always required.
$icon = PHUIStatusItemView::ICON_WARNING;
$color = 'red';
$icon_label = pht('Required Input');
$has_conflicts = true;
$error = pht('This input is required, but not configured.');
} else {
// This is an unnamed output. Outputs do not necessarily need to be
// named.
$icon = PHUIStatusItemView::ICON_OPEN;
$color = 'bluegrey';
$icon_label = pht('Unused Output');
}
} else {
$bound = phutil_tag('strong', array(), $key);
if ($is_input) {
if (isset($available_artifacts[$key])) {
if ($available_artifacts[$key] == idx($artifact, 'type')) {
$icon = PHUIStatusItemView::ICON_ACCEPT;
$color = 'green';
$icon_label = pht('Valid Input');
} else {
$icon = PHUIStatusItemView::ICON_WARNING;
$color = 'red';
$icon_label = pht('Bad Input Type');
$has_conflicts = true;
$error = pht(
'This input is bound to the wrong artifact type. It is bound '.
'to a "%s" artifact, but should be bound to a "%s" artifact.',
$available_artifacts[$key],
idx($artifact, 'type'));
}
} else {
$icon = PHUIStatusItemView::ICON_QUESTION;
$color = 'red';
$icon_label = pht('Unknown Input');
$has_conflicts = true;
$error = pht(
'This input is bound to an artifact ("%s") which does not exist '.
'at this stage in the build process.',
$key);
}
} else {
$icon = PHUIStatusItemView::ICON_DOWN;
$color = 'green';
$icon_label = pht('Valid Output');
}
}
if ($error) {
$note = array(
phutil_tag('strong', array(), pht('ERROR:')),
' ',
$error,
);
} else {
$note = $bound;
}
$list->addItem(
id(new PHUIStatusItemView())
->setIcon($icon, $color, $icon_label)
->setTarget($artifact['name'])
->setNote($note));
}
$ui = array(
$header,
$list,
);
return array($ui, $has_conflicts);
}
private function buildDependsOnList(
array $step_phids,
$name,
array $steps) {
$has_conflicts = false;
if (count($step_phids) === 0) {
return null;
}
$this->requireResource('harbormaster-css');
$steps = mpull($steps, null, 'getPHID');
$header = phutil_tag(
'div',
array(
'class' => 'harbormaster-artifact-summary-header',
),
$name);
$list = new PHUIStatusListView();
foreach ($step_phids as $step_phid) {
$error = null;
if (idx($steps, $step_phid) === null) {
$icon = PHUIStatusItemView::ICON_WARNING;
$color = 'red';
$icon_label = pht('Missing Dependency');
$has_conflicts = true;
$error = pht(
"This dependency specifies a build step which doesn't exist.");
} else {
$bound = phutil_tag(
'strong',
array(),
idx($steps, $step_phid)->getName());
$icon = PHUIStatusItemView::ICON_ACCEPT;
$color = 'green';
$icon_label = pht('Valid Input');
}
if ($error) {
$note = array(
phutil_tag('strong', array(), pht('ERROR:')),
' ',
$error,
);
} else {
$note = $bound;
}
$list->addItem(
id(new PHUIStatusItemView())
->setIcon($icon, $color, $icon_label)
->setTarget(pht('Build Step'))
->setNote($note));
}
$ui = array(
$header,
$list,
);
return array($ui, $has_conflicts);
}
}
diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php
index c7239438c6..bd6d4953da 100644
--- a/src/applications/herald/adapter/HeraldAdapter.php
+++ b/src/applications/herald/adapter/HeraldAdapter.php
@@ -1,1092 +1,1092 @@
<?php
abstract class HeraldAdapter extends Phobject {
const CONDITION_CONTAINS = 'contains';
const CONDITION_NOT_CONTAINS = '!contains';
const CONDITION_IS = 'is';
const CONDITION_IS_NOT = '!is';
const CONDITION_IS_ANY = 'isany';
const CONDITION_IS_NOT_ANY = '!isany';
const CONDITION_INCLUDE_ALL = 'all';
const CONDITION_INCLUDE_ANY = 'any';
const CONDITION_INCLUDE_NONE = 'none';
const CONDITION_IS_ME = 'me';
const CONDITION_IS_NOT_ME = '!me';
const CONDITION_REGEXP = 'regexp';
const CONDITION_RULE = 'conditions';
const CONDITION_NOT_RULE = '!conditions';
const CONDITION_EXISTS = 'exists';
const CONDITION_NOT_EXISTS = '!exists';
const CONDITION_UNCONDITIONALLY = 'unconditionally';
const CONDITION_NEVER = 'never';
const CONDITION_REGEXP_PAIR = 'regexp-pair';
const CONDITION_HAS_BIT = 'bit';
const CONDITION_NOT_BIT = '!bit';
const CONDITION_IS_TRUE = 'true';
const CONDITION_IS_FALSE = 'false';
private $contentSource;
private $isNewObject;
private $applicationEmail;
private $appliedTransactions = array();
private $queuedTransactions = array();
private $emailPHIDs = array();
private $forcedEmailPHIDs = array();
private $fieldMap;
private $actionMap;
private $edgeCache = array();
public function getEmailPHIDs() {
return array_values($this->emailPHIDs);
}
public function getForcedEmailPHIDs() {
return array_values($this->forcedEmailPHIDs);
}
public function addEmailPHID($phid, $force) {
$this->emailPHIDs[$phid] = $phid;
if ($force) {
$this->forcedEmailPHIDs[$phid] = $phid;
}
return $this;
}
public function setContentSource(PhabricatorContentSource $content_source) {
$this->contentSource = $content_source;
return $this;
}
public function getContentSource() {
return $this->contentSource;
}
public function getIsNewObject() {
if (is_bool($this->isNewObject)) {
return $this->isNewObject;
}
throw new Exception(
pht(
'You must %s to a boolean first!',
'setIsNewObject()'));
}
public function setIsNewObject($new) {
$this->isNewObject = (bool)$new;
return $this;
}
public function supportsApplicationEmail() {
return false;
}
public function setApplicationEmail(
PhabricatorMetaMTAApplicationEmail $email) {
$this->applicationEmail = $email;
return $this;
}
public function getApplicationEmail() {
return $this->applicationEmail;
}
public function getPHID() {
return $this->getObject()->getPHID();
}
abstract public function getHeraldName();
public function getHeraldField($field_key) {
return $this->requireFieldImplementation($field_key)
->getHeraldFieldValue($this->getObject());
}
public function applyHeraldEffects(array $effects) {
assert_instances_of($effects, 'HeraldEffect');
$result = array();
foreach ($effects as $effect) {
$result[] = $this->applyStandardEffect($effect);
}
return $result;
}
public function isAvailableToUser(PhabricatorUser $viewer) {
$applications = id(new PhabricatorApplicationQuery())
->setViewer($viewer)
->withInstalled(true)
->withClasses(array($this->getAdapterApplicationClass()))
->execute();
return !empty($applications);
}
/**
* Set the list of transactions which just took effect.
*
* These transactions are set by @{class:PhabricatorApplicationEditor}
* automatically, before it invokes Herald.
*
* @param list<PhabricatorApplicationTransaction> List of transactions.
* @return this
*/
final public function setAppliedTransactions(array $xactions) {
assert_instances_of($xactions, 'PhabricatorApplicationTransaction');
$this->appliedTransactions = $xactions;
return $this;
}
/**
* Get a list of transactions which just took effect.
*
* When an object is edited normally, transactions are applied and then
* Herald executes. You can call this method to examine the transactions
* if you want to react to them.
*
* @return list<PhabricatorApplicationTransaction> List of transactions.
*/
final public function getAppliedTransactions() {
return $this->appliedTransactions;
}
public function queueTransaction($transaction) {
$this->queuedTransactions[] = $transaction;
}
public function getQueuedTransactions() {
return $this->queuedTransactions;
}
public function newTransaction() {
$object = $this->newObject();
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
throw new Exception(
pht(
'Unable to build a new transaction for adapter object; it does '.
'not implement "%s".',
'PhabricatorApplicationTransactionInterface'));
}
return $object->getApplicationTransactionTemplate();
}
/**
* NOTE: You generally should not override this; it exists to support legacy
* adapters which had hard-coded content types.
*/
public function getAdapterContentType() {
return get_class($this);
}
abstract public function getAdapterContentName();
abstract public function getAdapterContentDescription();
abstract public function getAdapterApplicationClass();
abstract public function getObject();
/**
* Return a new characteristic object for this adapter.
*
* The adapter will use this object to test for interfaces, generate
* transactions, and interact with custom fields.
*
* Adapters must return an object from this method to enable custom
* field rules and various implicit actions.
*
* Normally, you'll return an empty version of the adapted object:
*
* return new ApplicationObject();
*
* @return null|object Template object.
*/
protected function newObject() {
return null;
}
public function supportsRuleType($rule_type) {
return false;
}
public function canTriggerOnObject($object) {
return false;
}
public function explainValidTriggerObjects() {
return pht('This adapter can not trigger on objects.');
}
public function getTriggerObjectPHIDs() {
return array($this->getPHID());
}
public function getAdapterSortKey() {
return sprintf(
'%08d%s',
$this->getAdapterSortOrder(),
$this->getAdapterContentName());
}
public function getAdapterSortOrder() {
return 1000;
}
/* -( Fields )------------------------------------------------------------- */
private function getFieldImplementationMap() {
if ($this->fieldMap === null) {
// We can't use PhutilClassMapQuery here because field expansion
// depends on the adapter and object.
$object = $this->getObject();
$map = array();
$all = HeraldField::getAllFields();
foreach ($all as $key => $field) {
$field = id(clone $field)->setAdapter($this);
if (!$field->supportsObject($object)) {
continue;
}
$subfields = $field->getFieldsForObject($object);
foreach ($subfields as $subkey => $subfield) {
if (isset($map[$subkey])) {
throw new Exception(
pht(
'Two HeraldFields (of classes "%s" and "%s") have the same '.
'field key ("%s") after expansion for an object of class '.
'"%s" inside adapter "%s". Each field must have a unique '.
'field key.',
get_class($subfield),
get_class($map[$subkey]),
$subkey,
get_class($object),
get_class($this)));
}
$subfield = id(clone $subfield)->setAdapter($this);
$map[$subkey] = $subfield;
}
}
$this->fieldMap = $map;
}
return $this->fieldMap;
}
private function getFieldImplementation($key) {
return idx($this->getFieldImplementationMap(), $key);
}
public function getFields() {
return array_keys($this->getFieldImplementationMap());
}
public function getFieldNameMap() {
return mpull($this->getFieldImplementationMap(), 'getHeraldFieldName');
}
public function getFieldGroupKey($field_key) {
$field = $this->getFieldImplementation($field_key);
if (!$field) {
return null;
}
return $field->getFieldGroupKey();
}
/* -( Conditions )--------------------------------------------------------- */
public function getConditionNameMap() {
return array(
self::CONDITION_CONTAINS => pht('contains'),
self::CONDITION_NOT_CONTAINS => pht('does not contain'),
self::CONDITION_IS => pht('is'),
self::CONDITION_IS_NOT => pht('is not'),
self::CONDITION_IS_ANY => pht('is any of'),
self::CONDITION_IS_TRUE => pht('is true'),
self::CONDITION_IS_FALSE => pht('is false'),
self::CONDITION_IS_NOT_ANY => pht('is not any of'),
self::CONDITION_INCLUDE_ALL => pht('include all of'),
self::CONDITION_INCLUDE_ANY => pht('include any of'),
self::CONDITION_INCLUDE_NONE => pht('do not include'),
self::CONDITION_IS_ME => pht('is myself'),
self::CONDITION_IS_NOT_ME => pht('is not myself'),
self::CONDITION_REGEXP => pht('matches regexp'),
self::CONDITION_RULE => pht('matches:'),
self::CONDITION_NOT_RULE => pht('does not match:'),
self::CONDITION_EXISTS => pht('exists'),
self::CONDITION_NOT_EXISTS => pht('does not exist'),
self::CONDITION_UNCONDITIONALLY => '', // don't show anything!
self::CONDITION_NEVER => '', // don't show anything!
self::CONDITION_REGEXP_PAIR => pht('matches regexp pair'),
self::CONDITION_HAS_BIT => pht('has bit'),
self::CONDITION_NOT_BIT => pht('lacks bit'),
);
}
public function getConditionsForField($field) {
return $this->requireFieldImplementation($field)
->getHeraldFieldConditions();
}
private function requireFieldImplementation($field_key) {
$field = $this->getFieldImplementation($field_key);
if (!$field) {
throw new Exception(
pht(
'No field with key "%s" is available to Herald adapter "%s".',
$field_key,
get_class($this)));
}
return $field;
}
public function doesConditionMatch(
HeraldEngine $engine,
HeraldRule $rule,
HeraldCondition $condition,
$field_value) {
$condition_type = $condition->getFieldCondition();
$condition_value = $condition->getValue();
switch ($condition_type) {
case self::CONDITION_CONTAINS:
// "Contains" can take an array of strings, as in "Any changed
// filename" for diffs.
foreach ((array)$field_value as $value) {
if (stripos($value, $condition_value) !== false) {
return true;
}
}
return false;
case self::CONDITION_NOT_CONTAINS:
return (stripos($field_value, $condition_value) === false);
case self::CONDITION_IS:
return ($field_value == $condition_value);
case self::CONDITION_IS_NOT:
return ($field_value != $condition_value);
case self::CONDITION_IS_ME:
return ($field_value == $rule->getAuthorPHID());
case self::CONDITION_IS_NOT_ME:
return ($field_value != $rule->getAuthorPHID());
case self::CONDITION_IS_ANY:
if (!is_array($condition_value)) {
throw new HeraldInvalidConditionException(
pht('Expected condition value to be an array.'));
}
$condition_value = array_fuse($condition_value);
return isset($condition_value[$field_value]);
case self::CONDITION_IS_NOT_ANY:
if (!is_array($condition_value)) {
throw new HeraldInvalidConditionException(
pht('Expected condition value to be an array.'));
}
$condition_value = array_fuse($condition_value);
return !isset($condition_value[$field_value]);
case self::CONDITION_INCLUDE_ALL:
if (!is_array($field_value)) {
throw new HeraldInvalidConditionException(
pht('Object produced non-array value!'));
}
if (!is_array($condition_value)) {
throw new HeraldInvalidConditionException(
pht('Expected condition value to be an array.'));
}
$have = array_select_keys(array_fuse($field_value), $condition_value);
return (count($have) == count($condition_value));
case self::CONDITION_INCLUDE_ANY:
return (bool)array_select_keys(
array_fuse($field_value),
$condition_value);
case self::CONDITION_INCLUDE_NONE:
return !array_select_keys(
array_fuse($field_value),
$condition_value);
case self::CONDITION_EXISTS:
case self::CONDITION_IS_TRUE:
return (bool)$field_value;
case self::CONDITION_NOT_EXISTS:
case self::CONDITION_IS_FALSE:
return !$field_value;
case self::CONDITION_UNCONDITIONALLY:
return (bool)$field_value;
case self::CONDITION_NEVER:
return false;
case self::CONDITION_REGEXP:
foreach ((array)$field_value as $value) {
// We add the 'S' flag because we use the regexp multiple times.
// It shouldn't cause any troubles if the flag is already there
// - /.*/S is evaluated same as /.*/SS.
$result = @preg_match($condition_value.'S', $value);
if ($result === false) {
throw new HeraldInvalidConditionException(
pht('Regular expression is not valid!'));
}
if ($result) {
return true;
}
}
return false;
case self::CONDITION_REGEXP_PAIR:
// Match a JSON-encoded pair of regular expressions against a
// dictionary. The first regexp must match the dictionary key, and the
// second regexp must match the dictionary value. If any key/value pair
// in the dictionary matches both regexps, the condition is satisfied.
$regexp_pair = null;
try {
$regexp_pair = phutil_json_decode($condition_value);
} catch (PhutilJSONParserException $ex) {
throw new HeraldInvalidConditionException(
pht('Regular expression pair is not valid JSON!'));
}
if (count($regexp_pair) != 2) {
throw new HeraldInvalidConditionException(
pht('Regular expression pair is not a pair!'));
}
$key_regexp = array_shift($regexp_pair);
$value_regexp = array_shift($regexp_pair);
foreach ((array)$field_value as $key => $value) {
$key_matches = @preg_match($key_regexp, $key);
if ($key_matches === false) {
throw new HeraldInvalidConditionException(
pht('First regular expression is invalid!'));
}
if ($key_matches) {
$value_matches = @preg_match($value_regexp, $value);
if ($value_matches === false) {
throw new HeraldInvalidConditionException(
pht('Second regular expression is invalid!'));
}
if ($value_matches) {
return true;
}
}
}
return false;
case self::CONDITION_RULE:
case self::CONDITION_NOT_RULE:
$rule = $engine->getRule($condition_value);
if (!$rule) {
throw new HeraldInvalidConditionException(
pht('Condition references a rule which does not exist!'));
}
$is_not = ($condition_type == self::CONDITION_NOT_RULE);
$result = $engine->doesRuleMatch($rule, $this);
if ($is_not) {
$result = !$result;
}
return $result;
case self::CONDITION_HAS_BIT:
return (($condition_value & $field_value) === (int)$condition_value);
case self::CONDITION_NOT_BIT:
return (($condition_value & $field_value) !== (int)$condition_value);
default:
throw new HeraldInvalidConditionException(
pht("Unknown condition '%s'.", $condition_type));
}
}
public function willSaveCondition(HeraldCondition $condition) {
$condition_type = $condition->getFieldCondition();
$condition_value = $condition->getValue();
switch ($condition_type) {
case self::CONDITION_REGEXP:
$ok = @preg_match($condition_value, '');
if ($ok === false) {
throw new HeraldInvalidConditionException(
pht(
'The regular expression "%s" is not valid. Regular expressions '.
'must have enclosing characters (e.g. "@/path/to/file@", not '.
'"/path/to/file") and be syntactically correct.',
$condition_value));
}
break;
case self::CONDITION_REGEXP_PAIR:
$json = null;
try {
$json = phutil_json_decode($condition_value);
} catch (PhutilJSONParserException $ex) {
throw new HeraldInvalidConditionException(
pht(
'The regular expression pair "%s" is not valid JSON. Enter a '.
'valid JSON array with two elements.',
$condition_value));
}
if (count($json) != 2) {
throw new HeraldInvalidConditionException(
pht(
'The regular expression pair "%s" must have exactly two '.
'elements.',
$condition_value));
}
$key_regexp = array_shift($json);
$val_regexp = array_shift($json);
$key_ok = @preg_match($key_regexp, '');
if ($key_ok === false) {
throw new HeraldInvalidConditionException(
pht(
'The first regexp in the regexp pair, "%s", is not a valid '.
'regexp.',
$key_regexp));
}
$val_ok = @preg_match($val_regexp, '');
if ($val_ok === false) {
throw new HeraldInvalidConditionException(
pht(
'The second regexp in the regexp pair, "%s", is not a valid '.
'regexp.',
$val_regexp));
}
break;
case self::CONDITION_CONTAINS:
case self::CONDITION_NOT_CONTAINS:
case self::CONDITION_IS:
case self::CONDITION_IS_NOT:
case self::CONDITION_IS_ANY:
case self::CONDITION_IS_NOT_ANY:
case self::CONDITION_INCLUDE_ALL:
case self::CONDITION_INCLUDE_ANY:
case self::CONDITION_INCLUDE_NONE:
case self::CONDITION_IS_ME:
case self::CONDITION_IS_NOT_ME:
case self::CONDITION_RULE:
case self::CONDITION_NOT_RULE:
case self::CONDITION_EXISTS:
case self::CONDITION_NOT_EXISTS:
case self::CONDITION_UNCONDITIONALLY:
case self::CONDITION_NEVER:
case self::CONDITION_HAS_BIT:
case self::CONDITION_NOT_BIT:
case self::CONDITION_IS_TRUE:
case self::CONDITION_IS_FALSE:
// No explicit validation for these types, although there probably
// should be in some cases.
break;
default:
throw new HeraldInvalidConditionException(
pht(
'Unknown condition "%s"!',
$condition_type));
}
}
/* -( Actions )------------------------------------------------------------ */
private function getActionImplementationMap() {
if ($this->actionMap === null) {
// We can't use PhutilClassMapQuery here because action expansion
// depends on the adapter and object.
$object = $this->getObject();
$map = array();
$all = HeraldAction::getAllActions();
foreach ($all as $key => $action) {
$action = id(clone $action)->setAdapter($this);
if (!$action->supportsObject($object)) {
continue;
}
$subactions = $action->getActionsForObject($object);
foreach ($subactions as $subkey => $subaction) {
if (isset($map[$subkey])) {
throw new Exception(
pht(
'Two HeraldActions (of classes "%s" and "%s") have the same '.
'action key ("%s") after expansion for an object of class '.
'"%s" inside adapter "%s". Each action must have a unique '.
'action key.',
get_class($subaction),
get_class($map[$subkey]),
$subkey,
get_class($object),
get_class($this)));
}
$subaction = id(clone $subaction)->setAdapter($this);
$map[$subkey] = $subaction;
}
}
$this->actionMap = $map;
}
return $this->actionMap;
}
private function requireActionImplementation($action_key) {
$action = $this->getActionImplementation($action_key);
if (!$action) {
throw new Exception(
pht(
'No action with key "%s" is available to Herald adapter "%s".',
$action_key,
get_class($this)));
}
return $action;
}
private function getActionsForRuleType($rule_type) {
$actions = $this->getActionImplementationMap();
foreach ($actions as $key => $action) {
if (!$action->supportsRuleType($rule_type)) {
unset($actions[$key]);
}
}
return $actions;
}
public function getActionImplementation($key) {
return idx($this->getActionImplementationMap(), $key);
}
public function getActionKeys() {
return array_keys($this->getActionImplementationMap());
}
public function getActionGroupKey($action_key) {
$action = $this->getActionImplementation($action_key);
if (!$action) {
return null;
}
return $action->getActionGroupKey();
}
public function getActions($rule_type) {
$actions = array();
foreach ($this->getActionsForRuleType($rule_type) as $key => $action) {
$actions[] = $key;
}
return $actions;
}
public function getActionNameMap($rule_type) {
$map = array();
foreach ($this->getActionsForRuleType($rule_type) as $key => $action) {
$map[$key] = $action->getHeraldActionName();
}
return $map;
}
public function willSaveAction(
HeraldRule $rule,
HeraldActionRecord $action) {
$impl = $this->requireActionImplementation($action->getAction());
$target = $action->getTarget();
$target = $impl->willSaveActionValue($target);
$action->setTarget($target);
}
/* -( Values )------------------------------------------------------------- */
public function getValueTypeForFieldAndCondition($field, $condition) {
return $this->requireFieldImplementation($field)
->getHeraldFieldValueType($condition);
}
public function getValueTypeForAction($action, $rule_type) {
$impl = $this->requireActionImplementation($action);
return $impl->getHeraldActionValueType();
}
private function buildTokenizerFieldValue(
PhabricatorTypeaheadDatasource $datasource) {
$key = 'action.'.get_class($datasource);
return id(new HeraldTokenizerFieldValue())
->setKey($key)
->setDatasource($datasource);
}
/* -( Repetition )--------------------------------------------------------- */
public function getRepetitionOptions() {
return array(
HeraldRepetitionPolicyConfig::EVERY,
);
}
abstract protected function initializeNewAdapter();
/**
* Does this adapter's event fire only once?
*
* Single use adapters (like pre-commit and diff adapters) only fire once,
* so fields like "Is new object" don't make sense to apply to their content.
*
* @return bool
*/
public function isSingleEventAdapter() {
return false;
}
public static function getAllAdapters() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getAdapterContentType')
->setSortMethod('getAdapterSortKey')
->execute();
}
public static function getAdapterForContentType($content_type) {
$adapters = self::getAllAdapters();
foreach ($adapters as $adapter) {
if ($adapter->getAdapterContentType() == $content_type) {
$adapter = id(clone $adapter);
$adapter->initializeNewAdapter();
return $adapter;
}
}
throw new Exception(
pht(
'No adapter exists for Herald content type "%s".',
$content_type));
}
public static function getEnabledAdapterMap(PhabricatorUser $viewer) {
$map = array();
$adapters = self::getAllAdapters();
foreach ($adapters as $adapter) {
if (!$adapter->isAvailableToUser($viewer)) {
continue;
}
$type = $adapter->getAdapterContentType();
$name = $adapter->getAdapterContentName();
$map[$type] = $name;
}
return $map;
}
public function getEditorValueForCondition(
PhabricatorUser $viewer,
HeraldCondition $condition) {
$field = $this->requireFieldImplementation($condition->getFieldName());
return $field->getEditorValue(
$viewer,
$condition->getFieldCondition(),
$condition->getValue());
}
public function getEditorValueForAction(
PhabricatorUser $viewer,
HeraldActionRecord $action_record) {
$action = $this->requireActionImplementation($action_record->getAction());
return $action->getEditorValue(
$viewer,
$action_record->getTarget());
}
public function renderRuleAsText(
HeraldRule $rule,
PhabricatorHandleList $handles,
PhabricatorUser $viewer) {
require_celerity_resource('herald-css');
$icon = id(new PHUIIconView())
- ->setIconFont('fa-chevron-circle-right lightgreytext')
+ ->setIcon('fa-chevron-circle-right lightgreytext')
->addClass('herald-list-icon');
if ($rule->getMustMatchAll()) {
$match_text = pht('When all of these conditions are met:');
} else {
$match_text = pht('When any of these conditions are met:');
}
$match_title = phutil_tag(
'p',
array(
'class' => 'herald-list-description',
),
$match_text);
$match_list = array();
foreach ($rule->getConditions() as $condition) {
$match_list[] = phutil_tag(
'div',
array(
'class' => 'herald-list-item',
),
array(
$icon,
$this->renderConditionAsText($condition, $handles, $viewer),
));
}
$integer_code_for_every = HeraldRepetitionPolicyConfig::toInt(
HeraldRepetitionPolicyConfig::EVERY);
if ($rule->getRepetitionPolicy() == $integer_code_for_every) {
$action_text =
pht('Take these actions every time this rule matches:');
} else {
$action_text =
pht('Take these actions the first time this rule matches:');
}
$action_title = phutil_tag(
'p',
array(
'class' => 'herald-list-description',
),
$action_text);
$action_list = array();
foreach ($rule->getActions() as $action) {
$action_list[] = phutil_tag(
'div',
array(
'class' => 'herald-list-item',
),
array(
$icon,
$this->renderActionAsText($viewer, $action, $handles),
));
}
return array(
$match_title,
$match_list,
$action_title,
$action_list,
);
}
private function renderConditionAsText(
HeraldCondition $condition,
PhabricatorHandleList $handles,
PhabricatorUser $viewer) {
$field_type = $condition->getFieldName();
$field = $this->getFieldImplementation($field_type);
if (!$field) {
return pht('Unknown Field: "%s"', $field_type);
}
$field_name = $field->getHeraldFieldName();
$condition_type = $condition->getFieldCondition();
$condition_name = idx($this->getConditionNameMap(), $condition_type);
$value = $this->renderConditionValueAsText($condition, $handles, $viewer);
return array(
$field_name,
' ',
$condition_name,
' ',
$value,
);
}
private function renderActionAsText(
PhabricatorUser $viewer,
HeraldActionRecord $action,
PhabricatorHandleList $handles) {
$impl = $this->getActionImplementation($action->getAction());
if ($impl) {
$impl->setViewer($viewer);
$value = $action->getTarget();
return $impl->renderActionDescription($value);
}
$rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL;
$action_type = $action->getAction();
$default = pht('(Unknown Action "%s") equals', $action_type);
$action_name = idx(
$this->getActionNameMap($rule_global),
$action_type,
$default);
$target = $this->renderActionTargetAsText($action, $handles);
return hsprintf(' %s %s', $action_name, $target);
}
private function renderConditionValueAsText(
HeraldCondition $condition,
PhabricatorHandleList $handles,
PhabricatorUser $viewer) {
$field = $this->requireFieldImplementation($condition->getFieldName());
return $field->renderConditionValue(
$viewer,
$condition->getFieldCondition(),
$condition->getValue());
}
private function renderActionTargetAsText(
HeraldActionRecord $action,
PhabricatorHandleList $handles) {
// TODO: This should be driven through HeraldAction.
$target = $action->getTarget();
if (!is_array($target)) {
$target = array($target);
}
foreach ($target as $index => $val) {
switch ($action->getAction()) {
default:
$handle = $handles->getHandleIfExists($val);
if ($handle) {
$target[$index] = $handle->renderLink();
}
break;
}
}
$target = phutil_implode_html(', ', $target);
return $target;
}
/**
* Given a @{class:HeraldRule}, this function extracts all the phids that
* we'll want to load as handles later.
*
* This function performs a somewhat hacky approach to figuring out what
* is and is not a phid - try to get the phid type and if the type is
* *not* unknown assume its a valid phid.
*
* Don't try this at home. Use more strongly typed data at home.
*
* Think of the children.
*/
public static function getHandlePHIDs(HeraldRule $rule) {
$phids = array($rule->getAuthorPHID());
foreach ($rule->getConditions() as $condition) {
$value = $condition->getValue();
if (!is_array($value)) {
$value = array($value);
}
foreach ($value as $val) {
if (phid_get_type($val) !=
PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) {
$phids[] = $val;
}
}
}
foreach ($rule->getActions() as $action) {
$target = $action->getTarget();
if (!is_array($target)) {
$target = array($target);
}
foreach ($target as $val) {
if (phid_get_type($val) !=
PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) {
$phids[] = $val;
}
}
}
if ($rule->isObjectRule()) {
$phids[] = $rule->getTriggerObjectPHID();
}
return $phids;
}
/* -( Applying Effects )--------------------------------------------------- */
/**
* @task apply
*/
protected function applyStandardEffect(HeraldEffect $effect) {
$action = $effect->getAction();
$rule_type = $effect->getRule()->getRuleType();
$impl = $this->getActionImplementation($action);
if (!$impl) {
return new HeraldApplyTranscript(
$effect,
false,
array(
array(
HeraldAction::DO_STANDARD_INVALID_ACTION,
$action,
),
));
}
if (!$impl->supportsRuleType($rule_type)) {
return new HeraldApplyTranscript(
$effect,
false,
array(
array(
HeraldAction::DO_STANDARD_WRONG_RULE_TYPE,
$rule_type,
),
));
}
$impl->applyEffect($this->getObject(), $effect);
return $impl->getApplyTranscript($effect);
}
public function loadEdgePHIDs($type) {
if (!isset($this->edgeCache[$type])) {
$phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$this->getObject()->getPHID(),
$type);
$this->edgeCache[$type] = array_fuse($phids);
}
return $this->edgeCache[$type];
}
}
diff --git a/src/applications/home/controller/PhabricatorHomeMainController.php b/src/applications/home/controller/PhabricatorHomeMainController.php
index 9d604cf0d6..1b8557fc7f 100644
--- a/src/applications/home/controller/PhabricatorHomeMainController.php
+++ b/src/applications/home/controller/PhabricatorHomeMainController.php
@@ -1,422 +1,422 @@
<?php
final class PhabricatorHomeMainController extends PhabricatorHomeController {
private $minipanels = array();
public function shouldAllowPublic() {
return true;
}
public function isGlobalDragAndDropUploadEnabled() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$user = $request->getUser();
$dashboard = PhabricatorDashboardInstall::getDashboard(
$user,
$user->getPHID(),
get_class($this->getCurrentApplication()));
if (!$dashboard) {
$dashboard = PhabricatorDashboardInstall::getDashboard(
$user,
PhabricatorHomeApplication::DASHBOARD_DEFAULT,
get_class($this->getCurrentApplication()));
}
if ($dashboard) {
$content = id(new PhabricatorDashboardRenderingEngine())
->setViewer($user)
->setDashboard($dashboard)
->renderDashboard();
} else {
$project_query = new PhabricatorProjectQuery();
$project_query->setViewer($user);
$project_query->withMemberPHIDs(array($user->getPHID()));
$projects = $project_query->execute();
$content = $this->buildMainResponse($projects);
}
if (!$request->getURIData('only')) {
$nav = $this->buildNav();
$nav->appendChild(
array(
$content,
id(new PhabricatorGlobalUploadTargetView())->setUser($user),
));
$content = $nav;
}
return $this->buildApplicationPage(
$content,
array(
'title' => 'Phabricator',
));
}
private function buildMainResponse(array $projects) {
assert_instances_of($projects, 'PhabricatorProject');
$viewer = $this->getRequest()->getUser();
$has_maniphest = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorManiphestApplication',
$viewer);
$has_audit = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorAuditApplication',
$viewer);
$has_differential = PhabricatorApplication::isClassInstalledForViewer(
'PhabricatorDifferentialApplication',
$viewer);
if ($has_maniphest) {
$unbreak_panel = $this->buildUnbreakNowPanel();
$triage_panel = $this->buildNeedsTriagePanel($projects);
$tasks_panel = $this->buildTasksPanel();
} else {
$unbreak_panel = null;
$triage_panel = null;
$tasks_panel = null;
}
if ($has_audit) {
$audit_panel = $this->buildAuditPanel();
$commit_panel = $this->buildCommitPanel();
} else {
$audit_panel = null;
$commit_panel = null;
}
if (PhabricatorEnv::getEnvConfig('welcome.html') !== null) {
$welcome_panel = $this->buildWelcomePanel();
} else {
$welcome_panel = null;
}
if ($has_differential) {
$revision_panel = $this->buildRevisionPanel();
} else {
$revision_panel = null;
}
$home = phutil_tag(
'div',
array(
'class' => 'homepage-panel',
),
array(
$welcome_panel,
$unbreak_panel,
$triage_panel,
$revision_panel,
$tasks_panel,
$audit_panel,
$commit_panel,
$this->minipanels,
));
return $home;
}
private function buildUnbreakNowPanel() {
$unbreak_now = PhabricatorEnv::getEnvConfig(
'maniphest.priorities.unbreak-now');
if (!$unbreak_now) {
return null;
}
$user = $this->getRequest()->getUser();
$task_query = id(new ManiphestTaskQuery())
->setViewer($user)
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
->withPriorities(array($unbreak_now))
->needProjectPHIDs(true)
->setLimit(10);
$tasks = $task_query->execute();
if (!$tasks) {
return $this->renderMiniPanel(
pht('No "Unbreak Now!" Tasks'),
pht('Nothing appears to be critically broken right now.'));
}
$href = urisprintf(
'/maniphest/?statuses=open()&priorities=%s#R',
$unbreak_now);
$title = pht('Unbreak Now!');
$panel = new PHUIObjectBoxView();
$panel->setHeader($this->renderSectionHeader($title, $href));
$panel->setObjectList($this->buildTaskListView($tasks));
return $panel;
}
private function buildNeedsTriagePanel(array $projects) {
assert_instances_of($projects, 'PhabricatorProject');
$needs_triage = PhabricatorEnv::getEnvConfig(
'maniphest.priorities.needs-triage');
if (!$needs_triage) {
return null;
}
$user = $this->getRequest()->getUser();
if (!$user->isLoggedIn()) {
return null;
}
if ($projects) {
$task_query = id(new ManiphestTaskQuery())
->setViewer($user)
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
->withPriorities(array($needs_triage))
->withEdgeLogicPHIDs(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
PhabricatorQueryConstraint::OPERATOR_OR,
mpull($projects, 'getPHID'))
->needProjectPHIDs(true)
->setLimit(10);
$tasks = $task_query->execute();
} else {
$tasks = array();
}
if (!$tasks) {
return $this->renderMiniPanel(
pht('No "Needs Triage" Tasks'),
pht('No tasks tagged with projects you are a member of need triage.'));
}
$title = pht('Needs Triage');
$href = urisprintf(
'/maniphest/?statuses=open()&priorities=%s&projects=projects(%s)#R',
$needs_triage,
$user->getPHID());
$panel = new PHUIObjectBoxView();
$panel->setHeader($this->renderSectionHeader($title, $href));
$panel->setObjectList($this->buildTaskListView($tasks));
return $panel;
}
private function buildRevisionPanel() {
$user = $this->getRequest()->getUser();
$user_phid = $user->getPHID();
$revision_query = id(new DifferentialRevisionQuery())
->setViewer($user)
->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
->withResponsibleUsers(array($user_phid))
->needRelationships(true)
->needFlags(true)
->needDrafts(true);
$revisions = $revision_query->execute();
list($blocking, $active) = DifferentialRevisionQuery::splitResponsible(
$revisions,
array($user_phid));
if (!$blocking && !$active) {
return $this->renderMiniPanel(
pht('No Waiting Revisions'),
pht('No revisions are waiting on you.'));
}
$title = pht('Revisions Waiting on You');
$href = '/differential';
$panel = new PHUIObjectBoxView();
$panel->setHeader($this->renderSectionHeader($title, $href));
$revision_view = id(new DifferentialRevisionListView())
->setHighlightAge(true)
->setRevisions(array_merge($blocking, $active))
->setUser($user);
$phids = array_merge(
array($user_phid),
$revision_view->getRequiredHandlePHIDs());
$handles = $this->loadViewerHandles($phids);
$revision_view->setHandles($handles);
$list_view = $revision_view->render();
$panel->setObjectList($list_view);
return $panel;
}
private function buildWelcomePanel() {
$panel = new PHUIObjectBoxView();
$panel->setHeaderText(pht('Welcome'));
$panel->appendChild(
phutil_safe_html(
PhabricatorEnv::getEnvConfig('welcome.html')));
return $panel;
}
private function buildTasksPanel() {
$user = $this->getRequest()->getUser();
$user_phid = $user->getPHID();
$task_query = id(new ManiphestTaskQuery())
->setViewer($user)
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
->setGroupBy(ManiphestTaskQuery::GROUP_PRIORITY)
->withOwners(array($user_phid))
->needProjectPHIDs(true)
->setLimit(10);
$tasks = $task_query->execute();
if (!$tasks) {
return $this->renderMiniPanel(
pht('No Assigned Tasks'),
pht('You have no assigned tasks.'));
}
$title = pht('Assigned Tasks');
$href = '/maniphest/query/assigned/';
$panel = new PHUIObjectBoxView();
$panel->setHeader($this->renderSectionHeader($title, $href));
$panel->setObjectList($this->buildTaskListView($tasks));
return $panel;
}
private function buildTaskListView(array $tasks) {
assert_instances_of($tasks, 'ManiphestTask');
$user = $this->getRequest()->getUser();
$phids = array_merge(
array_filter(mpull($tasks, 'getOwnerPHID')),
array_mergev(mpull($tasks, 'getProjectPHIDs')));
$handles = $this->loadViewerHandles($phids);
$view = new ManiphestTaskListView();
$view->setTasks($tasks);
$view->setUser($user);
$view->setHandles($handles);
return $view;
}
private function renderSectionHeader($title, $href) {
$title = phutil_tag(
'a',
array(
'href' => $href,
),
$title);
$icon = id(new PHUIIconView())
- ->setIconFont('fa-search')
+ ->setIcon('fa-search')
->setHref($href);
$header = id(new PHUIHeaderView())
->setHeader($title)
->addActionIcon($icon);
return $header;
}
private function renderMiniPanel($title, $body) {
$panel = new PHUIInfoView();
$panel->setSeverity(PHUIInfoView::SEVERITY_NODATA);
$panel->appendChild(
phutil_tag(
'p',
array(
),
array(
phutil_tag('strong', array(), $title.': '),
$body,
)));
$this->minipanels[] = $panel;
}
public function buildAuditPanel() {
$request = $this->getRequest();
$user = $request->getUser();
$phids = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user);
$query = id(new DiffusionCommitQuery())
->setViewer($user)
->withNeedsAuditByPHIDs($phids)
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_OPEN)
->needAuditRequests(true)
->needCommitData(true)
->setLimit(10);
$commits = $query->execute();
if (!$commits) {
return $this->renderMinipanel(
pht('No Audits'),
pht('No commits are waiting for you to audit them.'));
}
$view = id(new PhabricatorAuditListView())
->setCommits($commits)
->setUser($user);
$phids = $view->getRequiredHandlePHIDs();
$handles = $this->loadViewerHandles($phids);
$view->setHandles($handles);
$title = pht('Audits');
$href = '/audit/';
$panel = new PHUIObjectBoxView();
$panel->setHeader($this->renderSectionHeader($title, $href));
$panel->setObjectList($view);
return $panel;
}
public function buildCommitPanel() {
$request = $this->getRequest();
$user = $request->getUser();
$phids = array($user->getPHID());
$query = id(new DiffusionCommitQuery())
->setViewer($user)
->withAuthorPHIDs($phids)
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN)
->needCommitData(true)
->needAuditRequests(true)
->setLimit(10);
$commits = $query->execute();
if (!$commits) {
return $this->renderMinipanel(
pht('No Problem Commits'),
pht('No one has raised concerns with your commits.'));
}
$view = id(new PhabricatorAuditListView())
->setCommits($commits)
->setUser($user);
$phids = $view->getRequiredHandlePHIDs();
$handles = $this->loadViewerHandles($phids);
$view->setHandles($handles);
$title = pht('Problem Commits');
$href = '/audit/';
$panel = new PHUIObjectBoxView();
$panel->setHeader($this->renderSectionHeader($title, $href));
$panel->setObjectList($view);
return $panel;
}
}
diff --git a/src/applications/legalpad/controller/LegalpadDocumentSignController.php b/src/applications/legalpad/controller/LegalpadDocumentSignController.php
index ac24efbb5a..2221ae4499 100644
--- a/src/applications/legalpad/controller/LegalpadDocumentSignController.php
+++ b/src/applications/legalpad/controller/LegalpadDocumentSignController.php
@@ -1,703 +1,701 @@
<?php
final class LegalpadDocumentSignController extends LegalpadController {
public function shouldAllowPublic() {
return true;
}
public function shouldAllowLegallyNonCompliantUsers() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$document = id(new LegalpadDocumentQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->needDocumentBodies(true)
->executeOne();
if (!$document) {
return new Aphront404Response();
}
$information = $this->readSignerInformation(
$document,
$request);
if ($information instanceof AphrontResponse) {
return $information;
}
list($signer_phid, $signature_data) = $information;
$signature = null;
$type_individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
$is_individual = ($document->getSignatureType() == $type_individual);
switch ($document->getSignatureType()) {
case LegalpadDocument::SIGNATURE_TYPE_NONE:
// nothing to sign means this should be true
$has_signed = true;
// this is a status UI element
$signed_status = null;
break;
case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL:
if ($signer_phid) {
// TODO: This is odd and should probably be adjusted after
// grey/external accounts work better, but use the omnipotent
// viewer to check for a signature so we can pick up
// anonymous/grey signatures.
$signature = id(new LegalpadDocumentSignatureQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withDocumentPHIDs(array($document->getPHID()))
->withSignerPHIDs(array($signer_phid))
->executeOne();
if ($signature && !$viewer->isLoggedIn()) {
return $this->newDialog()
->setTitle(pht('Already Signed'))
->appendParagraph(pht('You have already signed this document!'))
->addCancelButton('/'.$document->getMonogram(), pht('Okay'));
}
}
$signed_status = null;
if (!$signature) {
$has_signed = false;
$signature = id(new LegalpadDocumentSignature())
->setSignerPHID($signer_phid)
->setDocumentPHID($document->getPHID())
->setDocumentVersion($document->getVersions());
// If the user is logged in, show a notice that they haven't signed.
// If they aren't logged in, we can't be as sure, so don't show
// anything.
if ($viewer->isLoggedIn()) {
$signed_status = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(
array(
pht('You have not signed this document yet.'),
));
}
} else {
$has_signed = true;
$signature_data = $signature->getSignatureData();
// In this case, we know they've signed.
$signed_at = $signature->getDateCreated();
if ($signature->getIsExemption()) {
$exemption_phid = $signature->getExemptionPHID();
$handles = $this->loadViewerHandles(array($exemption_phid));
$exemption_handle = $handles[$exemption_phid];
$signed_text = pht(
'You do not need to sign this document. '.
'%s added a signature exemption for you on %s.',
$exemption_handle->renderLink(),
phabricator_datetime($signed_at, $viewer));
} else {
$signed_text = pht(
'You signed this document on %s.',
phabricator_datetime($signed_at, $viewer));
}
$signed_status = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->setErrors(array($signed_text));
}
$field_errors = array(
'name' => true,
'email' => true,
'agree' => true,
);
$signature->setSignatureData($signature_data);
break;
case LegalpadDocument::SIGNATURE_TYPE_CORPORATION:
$signature = id(new LegalpadDocumentSignature())
->setDocumentPHID($document->getPHID())
->setDocumentVersion($document->getVersions());
if ($viewer->isLoggedIn()) {
$has_signed = false;
$signed_status = null;
} else {
// This just hides the form.
$has_signed = true;
$login_text = pht(
'This document requires a corporate signatory. You must log in to '.
'accept this document on behalf of a company you represent.');
$signed_status = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(array($login_text));
}
$field_errors = array(
'name' => true,
'address' => true,
'contact.name' => true,
'email' => true,
);
$signature->setSignatureData($signature_data);
break;
}
$errors = array();
if ($request->isFormOrHisecPost() && !$has_signed) {
// Require two-factor auth to sign legal documents.
if ($viewer->isLoggedIn()) {
$engine = new PhabricatorAuthSessionEngine();
$engine->requireHighSecuritySession(
$viewer,
$request,
'/'.$document->getMonogram());
}
list($form_data, $errors, $field_errors) = $this->readSignatureForm(
$document,
$request);
$signature_data = $form_data + $signature_data;
$signature->setSignatureData($signature_data);
$signature->setSignatureType($document->getSignatureType());
$signature->setSignerName((string)idx($signature_data, 'name'));
$signature->setSignerEmail((string)idx($signature_data, 'email'));
$agree = $request->getExists('agree');
if (!$agree) {
$errors[] = pht(
'You must check "I agree to the terms laid forth above."');
$field_errors['agree'] = pht('Required');
}
if ($viewer->isLoggedIn() && $is_individual) {
$verified = LegalpadDocumentSignature::VERIFIED;
} else {
$verified = LegalpadDocumentSignature::UNVERIFIED;
}
$signature->setVerified($verified);
if (!$errors) {
$signature->save();
// If the viewer is logged in, signing for themselves, send them to
// the document page, which will show that they have signed the
// document. Unless of course they were required to sign the
// document to use Phabricator; in that case try really hard to
// re-direct them to where they wanted to go.
//
// Otherwise, send them to a completion page.
if ($viewer->isLoggedIn() && $is_individual) {
$next_uri = '/'.$document->getMonogram();
if ($document->getRequireSignature()) {
$request_uri = $request->getRequestURI();
$next_uri = (string)$request_uri;
}
} else {
$this->sendVerifySignatureEmail(
$document,
$signature);
$next_uri = $this->getApplicationURI('done/');
}
return id(new AphrontRedirectResponse())->setURI($next_uri);
}
}
$document_body = $document->getDocumentBody();
$engine = id(new PhabricatorMarkupEngine())
->setViewer($viewer);
$engine->addObject(
$document_body,
LegalpadDocumentBody::MARKUP_FIELD_TEXT);
$engine->process();
$document_markup = $engine->getOutput(
$document_body,
LegalpadDocumentBody::MARKUP_FIELD_TEXT);
$title = $document_body->getTitle();
$manage_uri = $this->getApplicationURI('view/'.$document->getID().'/');
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$document,
PhabricatorPolicyCapability::CAN_EDIT);
// Use the last content update as the modified date. We don't want to
// show that a document like a TOS was "updated" by an incidental change
// to a field like the preamble or privacy settings which does not acutally
// affect the content of the agreement.
$content_updated = $document_body->getDateCreated();
// NOTE: We're avoiding `setPolicyObject()` here so we don't pick up
// extra UI elements that are unnecessary and clutter the signature page.
// These details are available on the "Manage" page.
$header = id(new PHUIHeaderView())
->setHeader($title)
->setUser($viewer)
->setEpoch($content_updated)
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-pencil'))
+ ->setIcon('fa-pencil')
->setText(pht('Manage'))
->setHref($manage_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$preamble_box = null;
if (strlen($document->getPreamble())) {
$preamble_text = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent(
$document->getPreamble()),
'default',
$viewer);
// NOTE: We're avoiding `setObject()` here so we don't pick up extra UI
// elements like "Subscribers". This information is available on the
// "Manage" page, but just clutters up the "Signature" page.
$preamble = id(new PHUIPropertyListView())
->setUser($viewer)
->addSectionHeader(pht('Preamble'))
->addTextContent($preamble_text);
$preamble_box = new PHUIPropertyGroupView();
$preamble_box->addPropertyList($preamble);
}
$content = id(new PHUIDocumentViewPro())
->addClass('legalpad')
->setHeader($header)
->appendChild(
array(
$signed_status,
$preamble_box,
$document_markup,
));
$signature_box = null;
if (!$has_signed) {
$error_view = null;
if ($errors) {
$error_view = id(new PHUIInfoView())
->setErrors($errors);
}
$signature_form = $this->buildSignatureForm(
$document,
$signature,
$field_errors);
switch ($document->getSignatureType()) {
default:
break;
case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL:
case LegalpadDocument::SIGNATURE_TYPE_CORPORATION:
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Agree and Sign Document'))
->setForm($signature_form);
if ($error_view) {
$box->setInfoView($error_view);
}
$signature_box = phutil_tag_div('phui-document-view-pro-box', $box);
break;
}
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
$crumbs->addTextCrumb($document->getMonogram());
return $this->buildApplicationPage(
array(
$crumbs,
$content,
$signature_box,
),
array(
'title' => $title,
'pageObjects' => array($document->getPHID()),
));
}
private function readSignerInformation(
LegalpadDocument $document,
AphrontRequest $request) {
$viewer = $request->getUser();
$signer_phid = null;
$signature_data = array();
switch ($document->getSignatureType()) {
case LegalpadDocument::SIGNATURE_TYPE_NONE:
break;
case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL:
if ($viewer->isLoggedIn()) {
$signer_phid = $viewer->getPHID();
$signature_data = array(
'name' => $viewer->getRealName(),
'email' => $viewer->loadPrimaryEmailAddress(),
);
} else if ($request->isFormPost()) {
$email = new PhutilEmailAddress($request->getStr('email'));
if (strlen($email->getDomainName())) {
$email_obj = id(new PhabricatorUserEmail())
->loadOneWhere('address = %s', $email->getAddress());
if ($email_obj) {
return $this->signInResponse();
}
$external_account = id(new PhabricatorExternalAccountQuery())
->setViewer($viewer)
->withAccountTypes(array('email'))
->withAccountDomains(array($email->getDomainName()))
->withAccountIDs(array($email->getAddress()))
->loadOneOrCreate();
if ($external_account->getUserPHID()) {
return $this->signInResponse();
}
$signer_phid = $external_account->getPHID();
}
}
break;
case LegalpadDocument::SIGNATURE_TYPE_CORPORATION:
$signer_phid = $viewer->getPHID();
if ($signer_phid) {
$signature_data = array(
'contact.name' => $viewer->getRealName(),
'email' => $viewer->loadPrimaryEmailAddress(),
'actorPHID' => $viewer->getPHID(),
);
}
break;
}
return array($signer_phid, $signature_data);
}
private function buildSignatureForm(
LegalpadDocument $document,
LegalpadDocumentSignature $signature,
array $errors) {
$viewer = $this->getRequest()->getUser();
$data = $signature->getSignatureData();
$form = id(new AphrontFormView())
->setUser($viewer);
$signature_type = $document->getSignatureType();
switch ($signature_type) {
case LegalpadDocument::SIGNATURE_TYPE_NONE:
// bail out of here quick
return;
case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL:
$this->buildIndividualSignatureForm(
$form,
$document,
$signature,
$errors);
break;
case LegalpadDocument::SIGNATURE_TYPE_CORPORATION:
$this->buildCorporateSignatureForm(
$form,
$document,
$signature,
$errors);
break;
default:
throw new Exception(
pht(
'This document has an unknown signature type ("%s").',
$signature_type));
}
$form
->appendChild(
id(new AphrontFormCheckboxControl())
->setError(idx($errors, 'agree', null))
->addCheckbox(
'agree',
'agree',
pht('I agree to the terms laid forth above.'),
false));
if ($document->getRequireSignature()) {
$cancel_uri = '/logout/';
$cancel_text = pht('Log Out');
} else {
$cancel_uri = $this->getApplicationURI();
$cancel_text = pht('Cancel');
}
$form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Sign Document'))
->addCancelButton($cancel_uri, $cancel_text));
return $form;
}
private function buildIndividualSignatureForm(
AphrontFormView $form,
LegalpadDocument $document,
LegalpadDocumentSignature $signature,
array $errors) {
$data = $signature->getSignatureData();
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name'))
->setValue(idx($data, 'name', ''))
->setName('name')
->setError(idx($errors, 'name', null)));
$viewer = $this->getRequest()->getUser();
if (!$viewer->isLoggedIn()) {
$form->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Email'))
->setValue(idx($data, 'email', ''))
->setName('email')
->setError(idx($errors, 'email', null)));
}
return $form;
}
private function buildCorporateSignatureForm(
AphrontFormView $form,
LegalpadDocument $document,
LegalpadDocumentSignature $signature,
array $errors) {
$data = $signature->getSignatureData();
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Company Name'))
->setValue(idx($data, 'name', ''))
->setName('name')
->setError(idx($errors, 'name', null)))
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel(pht('Company Address'))
->setValue(idx($data, 'address', ''))
->setName('address')
->setError(idx($errors, 'address', null)))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Contact Name'))
->setValue(idx($data, 'contact.name', ''))
->setName('contact.name')
->setError(idx($errors, 'contact.name', null)))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Contact Email'))
->setValue(idx($data, 'email', ''))
->setName('email')
->setError(idx($errors, 'email', null)));
return $form;
}
private function readSignatureForm(
LegalpadDocument $document,
AphrontRequest $request) {
$signature_type = $document->getSignatureType();
switch ($signature_type) {
case LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL:
$result = $this->readIndividualSignatureForm(
$document,
$request);
break;
case LegalpadDocument::SIGNATURE_TYPE_CORPORATION:
$result = $this->readCorporateSignatureForm(
$document,
$request);
break;
default:
throw new Exception(
pht(
'This document has an unknown signature type ("%s").',
$signature_type));
}
return $result;
}
private function readIndividualSignatureForm(
LegalpadDocument $document,
AphrontRequest $request) {
$signature_data = array();
$errors = array();
$field_errors = array();
$name = $request->getStr('name');
if (!strlen($name)) {
$field_errors['name'] = pht('Required');
$errors[] = pht('Name field is required.');
} else {
$field_errors['name'] = null;
}
$signature_data['name'] = $name;
$viewer = $request->getUser();
if ($viewer->isLoggedIn()) {
$email = $viewer->loadPrimaryEmailAddress();
} else {
$email = $request->getStr('email');
$addr_obj = null;
if (!strlen($email)) {
$field_errors['email'] = pht('Required');
$errors[] = pht('Email field is required.');
} else {
$addr_obj = new PhutilEmailAddress($email);
$domain = $addr_obj->getDomainName();
if (!$domain) {
$field_errors['email'] = pht('Invalid');
$errors[] = pht('A valid email is required.');
} else {
$field_errors['email'] = null;
}
}
}
$signature_data['email'] = $email;
return array($signature_data, $errors, $field_errors);
}
private function readCorporateSignatureForm(
LegalpadDocument $document,
AphrontRequest $request) {
$viewer = $request->getUser();
if (!$viewer->isLoggedIn()) {
throw new Exception(
pht(
'You can not sign a document on behalf of a corporation unless '.
'you are logged in.'));
}
$signature_data = array();
$errors = array();
$field_errors = array();
$name = $request->getStr('name');
if (!strlen($name)) {
$field_errors['name'] = pht('Required');
$errors[] = pht('Company name is required.');
} else {
$field_errors['name'] = null;
}
$signature_data['name'] = $name;
$address = $request->getStr('address');
if (!strlen($address)) {
$field_errors['address'] = pht('Required');
$errors[] = pht('Company address is required.');
} else {
$field_errors['address'] = null;
}
$signature_data['address'] = $address;
$contact_name = $request->getStr('contact.name');
if (!strlen($contact_name)) {
$field_errors['contact.name'] = pht('Required');
$errors[] = pht('Contact name is required.');
} else {
$field_errors['contact.name'] = null;
}
$signature_data['contact.name'] = $contact_name;
$email = $request->getStr('email');
$addr_obj = null;
if (!strlen($email)) {
$field_errors['email'] = pht('Required');
$errors[] = pht('Contact email is required.');
} else {
$addr_obj = new PhutilEmailAddress($email);
$domain = $addr_obj->getDomainName();
if (!$domain) {
$field_errors['email'] = pht('Invalid');
$errors[] = pht('A valid email is required.');
} else {
$field_errors['email'] = null;
}
}
$signature_data['email'] = $email;
return array($signature_data, $errors, $field_errors);
}
private function sendVerifySignatureEmail(
LegalpadDocument $doc,
LegalpadDocumentSignature $signature) {
$signature_data = $signature->getSignatureData();
$email = new PhutilEmailAddress($signature_data['email']);
$doc_name = $doc->getTitle();
$doc_link = PhabricatorEnv::getProductionURI('/'.$doc->getMonogram());
$path = $this->getApplicationURI(sprintf(
'/verify/%s/',
$signature->getSecretKey()));
$link = PhabricatorEnv::getProductionURI($path);
$name = idx($signature_data, 'name');
$body = pht(
"%s:\n\n".
"This email address was used to sign a Legalpad document ".
"in Phabricator:\n\n".
" %s\n\n".
"Please verify you own this email address and accept the ".
"agreement by clicking this link:\n\n".
" %s\n\n".
"Your signature is not valid until you complete this ".
"verification step.\n\nYou can review the document here:\n\n".
" %s\n",
$name,
$doc_name,
$link,
$doc_link);
id(new PhabricatorMetaMTAMail())
->addRawTos(array($email->getAddress()))
->setSubject(pht('[Legalpad] Signature Verification'))
->setForceDelivery(true)
->setBody($body)
->setRelatedPHID($signature->getDocumentPHID())
->saveAndSend();
}
private function signInResponse() {
return id(new Aphront403Response())
->setForbiddenText(
pht(
'The email address specified is associated with an account. '.
'Please login to that account and sign this document again.'));
}
}
diff --git a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
index 2d94b23193..5e562a06c7 100644
--- a/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
+++ b/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
@@ -1,239 +1,239 @@
<?php
final class LegalpadDocumentSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Legalpad Documents');
}
public function getApplicationClassName() {
return 'PhabricatorLegalpadApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'creatorPHIDs',
$this->readUsersFromRequest($request, 'creators'));
$saved->setParameter(
'contributorPHIDs',
$this->readUsersFromRequest($request, 'contributors'));
$saved->setParameter(
'withViewerSignature',
$request->getBool('withViewerSignature'));
$saved->setParameter('createdStart', $request->getStr('createdStart'));
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new LegalpadDocumentQuery())
->needViewerSignatures(true);
$creator_phids = $saved->getParameter('creatorPHIDs', array());
if ($creator_phids) {
$query->withCreatorPHIDs($creator_phids);
}
$contributor_phids = $saved->getParameter('contributorPHIDs', array());
if ($contributor_phids) {
$query->withContributorPHIDs($contributor_phids);
}
if ($saved->getParameter('withViewerSignature')) {
$viewer_phid = $this->requireViewer()->getPHID();
if ($viewer_phid) {
$query->withSignerPHIDs(array($viewer_phid));
}
}
$start = $this->parseDateTime($saved->getParameter('createdStart'));
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
if ($start) {
$query->withDateCreatedAfter($start);
}
if ($end) {
$query->withDateCreatedBefore($end);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$creator_phids = $saved_query->getParameter('creatorPHIDs', array());
$contributor_phids = $saved_query->getParameter(
'contributorPHIDs', array());
$viewer_signature = $saved_query->getParameter('withViewerSignature');
if (!$this->requireViewer()->getPHID()) {
$viewer_signature = false;
}
$form
->appendChild(
id(new AphrontFormCheckboxControl())
->addCheckbox(
'withViewerSignature',
1,
pht('Show only documents I have signed.'),
$viewer_signature)
->setDisabled(!$this->requireViewer()->getPHID()))
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setName('creators')
->setLabel(pht('Creators'))
->setValue($creator_phids))
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setName('contributors')
->setLabel(pht('Contributors'))
->setValue($contributor_phids));
$this->buildDateRange(
$form,
$saved_query,
'createdStart',
pht('Created After'),
'createdEnd',
pht('Created Before'));
}
protected function getURI($path) {
return '/legalpad/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
if ($this->requireViewer()->isLoggedIn()) {
$names['signed'] = pht('Signed Documents');
}
$names['all'] = pht('All Documents');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'signed':
return $query
->setParameter('withViewerSignature', true);
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function getRequiredHandlePHIDsForResultList(
array $documents,
PhabricatorSavedQuery $query) {
return array();
}
protected function renderResultList(
array $documents,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($documents, 'LegalpadDocument');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($documents as $document) {
$last_updated = phabricator_date($document->getDateModified(), $viewer);
$title = $document->getTitle();
$item = id(new PHUIObjectItemView())
->setObjectName($document->getMonogram())
->setHeader($title)
->setHref('/'.$document->getMonogram())
->setObject($document);
$no_signatures = LegalpadDocument::SIGNATURE_TYPE_NONE;
if ($document->getSignatureType() == $no_signatures) {
$item->addIcon('none', pht('Not Signable'));
} else {
$type_name = $document->getSignatureTypeName();
$type_icon = $document->getSignatureTypeIcon();
$item->addIcon($type_icon, $type_name);
if ($viewer->getPHID()) {
$signature = $document->getUserSignature($viewer->getPHID());
} else {
$signature = null;
}
if ($signature) {
$item->addAttribute(
array(
- id(new PHUIIconView())->setIconFont('fa-check-square-o', 'green'),
+ id(new PHUIIconView())->setIcon('fa-check-square-o', 'green'),
' ',
pht(
'Signed on %s',
phabricator_date($signature->getDateCreated(), $viewer)),
));
} else {
$item->addAttribute(
array(
- id(new PHUIIconView())->setIconFont('fa-square-o', 'grey'),
+ id(new PHUIIconView())->setIcon('fa-square-o', 'grey'),
' ',
pht('Not Signed'),
));
}
}
$item->addIcon(
'fa-pencil grey',
pht('Version %d (%s)', $document->getVersions(), $last_updated));
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No documents found.'));
return $result;
}
protected function getNewUserBody() {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Document'))
->setHref('/legalpad/create/')
->setColor(PHUIButtonView::GREEN);
$icon = $this->getApplication()->getFontIcon();
$app_name = $this->getApplication()->getName();
$view = id(new PHUIBigInfoView())
->setIcon($icon)
->setTitle(pht('Welcome to %s', $app_name))
->setDescription(
pht('Create documents and track signatures. Can also be re-used in '.
'other areas of Phabricator, like CLAs.'))
->addAction($create_button);
return $view;
}
}
diff --git a/src/applications/legalpad/query/LegalpadDocumentSignatureSearchEngine.php b/src/applications/legalpad/query/LegalpadDocumentSignatureSearchEngine.php
index 6967a21a98..9df8d2478d 100644
--- a/src/applications/legalpad/query/LegalpadDocumentSignatureSearchEngine.php
+++ b/src/applications/legalpad/query/LegalpadDocumentSignatureSearchEngine.php
@@ -1,315 +1,315 @@
<?php
final class LegalpadDocumentSignatureSearchEngine
extends PhabricatorApplicationSearchEngine {
private $document;
public function getResultTypeDescription() {
return pht('Legalpad Signatures');
}
public function getApplicationClassName() {
return 'PhabricatorLegalpadApplication';
}
public function setDocument(LegalpadDocument $document) {
$this->document = $document;
return $this;
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'signerPHIDs',
$this->readUsersFromRequest($request, 'signers'));
$saved->setParameter(
'documentPHIDs',
$this->readPHIDsFromRequest(
$request,
'documents',
array(
PhabricatorLegalpadDocumentPHIDType::TYPECONST,
)));
$saved->setParameter('nameContains', $request->getStr('nameContains'));
$saved->setParameter('emailContains', $request->getStr('emailContains'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new LegalpadDocumentSignatureQuery());
$signer_phids = $saved->getParameter('signerPHIDs', array());
if ($signer_phids) {
$query->withSignerPHIDs($signer_phids);
}
if ($this->document) {
$query->withDocumentPHIDs(array($this->document->getPHID()));
} else {
$document_phids = $saved->getParameter('documentPHIDs', array());
if ($document_phids) {
$query->withDocumentPHIDs($document_phids);
}
}
$name_contains = $saved->getParameter('nameContains');
if (strlen($name_contains)) {
$query->withNameContains($name_contains);
}
$email_contains = $saved->getParameter('emailContains');
if (strlen($email_contains)) {
$query->withEmailContains($email_contains);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$document_phids = $saved_query->getParameter('documentPHIDs', array());
$signer_phids = $saved_query->getParameter('signerPHIDs', array());
if (!$this->document) {
$form
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new LegalpadDocumentDatasource())
->setName('documents')
->setLabel(pht('Documents'))
->setValue($document_phids));
}
$name_contains = $saved_query->getParameter('nameContains', '');
$email_contains = $saved_query->getParameter('emailContains', '');
$form
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setName('signers')
->setLabel(pht('Signers'))
->setValue($signer_phids))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name Contains'))
->setName('nameContains')
->setValue($name_contains))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Email Contains'))
->setName('emailContains')
->setValue($email_contains));
}
protected function getURI($path) {
if ($this->document) {
return '/legalpad/signatures/'.$this->document->getID().'/'.$path;
} else {
return '/legalpad/signatures/'.$path;
}
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Signatures'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function getRequiredHandlePHIDsForResultList(
array $signatures,
PhabricatorSavedQuery $query) {
return array_merge(
mpull($signatures, 'getSignerPHID'),
mpull($signatures, 'getDocumentPHID'));
}
protected function renderResultList(
array $signatures,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($signatures, 'LegalpadDocumentSignature');
$viewer = $this->requireViewer();
Javelin::initBehavior('phabricator-tooltips');
$sig_good = $this->renderIcon(
'fa-check',
null,
pht('Verified, Current'));
$sig_corp = $this->renderIcon(
'fa-building-o',
null,
pht('Verified, Corporate'));
$sig_old = $this->renderIcon(
'fa-clock-o',
'orange',
pht('Signed Older Version'));
$sig_unverified = $this->renderIcon(
'fa-envelope',
'red',
pht('Unverified Email'));
$sig_exemption = $this->renderIcon(
'fa-asterisk',
'indigo',
pht('Exemption'));
id(new PHUIIconView())
- ->setIconFont('fa-envelope', 'red')
+ ->setIcon('fa-envelope', 'red')
->addSigil('has-tooltip')
->setMetadata(array('tip' => pht('Unverified Email')));
$type_corporate = LegalpadDocument::SIGNATURE_TYPE_CORPORATION;
$rows = array();
foreach ($signatures as $signature) {
$name = $signature->getSignerName();
$email = $signature->getSignerEmail();
$document = $signature->getDocument();
if ($signature->getIsExemption()) {
$sig_icon = $sig_exemption;
} else if (!$signature->isVerified()) {
$sig_icon = $sig_unverified;
} else if ($signature->getDocumentVersion() != $document->getVersions()) {
$sig_icon = $sig_old;
} else if ($signature->getSignatureType() == $type_corporate) {
$sig_icon = $sig_corp;
} else {
$sig_icon = $sig_good;
}
$signature_href = $this->getApplicationURI(
'signature/'.$signature->getID().'/');
$sig_icon = javelin_tag(
'a',
array(
'href' => $signature_href,
'sigil' => 'workflow',
),
$sig_icon);
$signer_phid = $signature->getSignerPHID();
$rows[] = array(
$sig_icon,
$handles[$document->getPHID()]->renderLink(),
$signer_phid
? $handles[$signer_phid]->renderLink()
: null,
$name,
phutil_tag(
'a',
array(
'href' => 'mailto:'.$email,
),
$email),
phabricator_datetime($signature->getDateCreated(), $viewer),
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No signatures match the query.'))
->setHeaders(
array(
'',
pht('Document'),
pht('Account'),
pht('Name'),
pht('Email'),
pht('Signed'),
))
->setColumnVisibility(
array(
true,
// Only show the "Document" column if we aren't scoped to a
// particular document.
!$this->document,
))
->setColumnClasses(
array(
'',
'',
'',
'',
'wide',
'right',
));
$button = null;
if ($this->document) {
$document_id = $this->document->getID();
$button = id(new PHUIButtonView())
->setText(pht('Add Exemption'))
->setTag('a')
->setHref($this->getApplicationURI('addsignature/'.$document_id.'/'))
->setWorkflow(true)
- ->setIcon(id(new PHUIIconView())->setIconFont('fa-pencil'));
+ ->setIcon('fa-pencil');
}
if (!$this->document) {
$table->setNotice(
pht('NOTE: You can only see your own signatures and signatures on '.
'documents you have permission to edit.'));
}
$result = new PhabricatorApplicationSearchResultView();
$result->setTable($table);
if ($button) {
$result->addAction($button);
}
return $result;
}
private function renderIcon($icon, $color, $title) {
Javelin::initBehavior('phabricator-tooltips');
return array(
id(new PHUIIconView())
- ->setIconFont($icon, $color)
+ ->setIcon($icon, $color)
->addSigil('has-tooltip')
->setMetadata(array('tip' => $title)),
javelin_tag(
'span',
array(
'aural' => true,
),
$title),
);
}
}
diff --git a/src/applications/macro/markup/PhabricatorIconRemarkupRule.php b/src/applications/macro/markup/PhabricatorIconRemarkupRule.php
index acd87d4136..fe0c4f60b2 100644
--- a/src/applications/macro/markup/PhabricatorIconRemarkupRule.php
+++ b/src/applications/macro/markup/PhabricatorIconRemarkupRule.php
@@ -1,88 +1,88 @@
<?php
final class PhabricatorIconRemarkupRule extends PhutilRemarkupRule {
public function getPriority() {
return 200.0;
}
public function apply($text) {
return preg_replace_callback(
'@{icon\b((?:[^}\\\\]+|\\\\.)*)}@m',
array($this, 'markupIcon'),
$text);
}
public function markupIcon(array $matches) {
$engine = $this->getEngine();
$text_mode = $engine->isTextMode();
$mail_mode = $engine->isHTMLMailMode();
if (!$this->isFlatText($matches[0]) || $text_mode || $mail_mode) {
return $matches[0];
}
$extra = idx($matches, 1);
// We allow various forms, like these:
//
// {icon}
// {icon camera}
// {icon,camera}
// {icon camera color=red}
// {icon, camera, color=red}
$extra = ltrim($extra, ", \n");
$extra = preg_split('/[\s,]+/', $extra, 2);
// Choose some arbitrary default icon so that previews render in a mostly
// reasonable way as you're typing the syntax.
$icon = idx($extra, 0, 'paw');
$defaults = array(
'color' => null,
'spin' => false,
);
$options = idx($extra, 1, '');
$parser = new PhutilSimpleOptions();
$options = $parser->parse($options) + $defaults;
// NOTE: We're validating icon and color names to prevent users from
// adding arbitrary CSS classes to the document. Although this probably
// isn't dangerous, it's safer to validate.
static $icon_names;
if (!$icon_names) {
$icon_names = array_fuse(PHUIIconView::getFontIcons());
}
static $color_names;
if (!$color_names) {
$color_names = array_fuse(PHUIIconView::getFontIconColors());
}
if (empty($icon_names['fa-'.$icon])) {
$icon = 'paw';
}
$color = $options['color'];
if (empty($color_names[$color])) {
$color = null;
}
$classes = array();
$classes[] = $color;
$spin = $options['spin'];
if ($spin) {
$classes[] = 'ph-spin';
}
$icon_view = id(new PHUIIconView())
- ->setIconFont('fa-'.$icon, implode(' ', $classes));
+ ->setIcon('fa-'.$icon, implode(' ', $classes));
return $this->getEngine()->storeText($icon_view);
}
}
diff --git a/src/applications/maniphest/constants/ManiphestTaskStatus.php b/src/applications/maniphest/constants/ManiphestTaskStatus.php
index 5efc2ea56c..ab99f212e5 100644
--- a/src/applications/maniphest/constants/ManiphestTaskStatus.php
+++ b/src/applications/maniphest/constants/ManiphestTaskStatus.php
@@ -1,360 +1,360 @@
<?php
/**
* @task validate Configuration Validation
*/
final class ManiphestTaskStatus extends ManiphestConstants {
const STATUS_OPEN = 'open';
const STATUS_CLOSED_RESOLVED = 'resolved';
const STATUS_CLOSED_WONTFIX = 'wontfix';
const STATUS_CLOSED_INVALID = 'invalid';
const STATUS_CLOSED_DUPLICATE = 'duplicate';
const STATUS_CLOSED_SPITE = 'spite';
const SPECIAL_DEFAULT = 'default';
const SPECIAL_CLOSED = 'closed';
const SPECIAL_DUPLICATE = 'duplicate';
private static function getStatusConfig() {
return PhabricatorEnv::getEnvConfig('maniphest.statuses');
}
private static function getEnabledStatusMap() {
$spec = self::getStatusConfig();
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
foreach ($spec as $const => $status) {
if ($is_serious && !empty($status['silly'])) {
unset($spec[$const]);
continue;
}
}
return $spec;
}
public static function getTaskStatusMap() {
return ipull(self::getEnabledStatusMap(), 'name');
}
/**
* Get the statuses and their command keywords.
*
* @return map Statuses to lists of command keywords.
*/
public static function getTaskStatusKeywordsMap() {
$map = self::getEnabledStatusMap();
foreach ($map as $key => $spec) {
$words = idx($spec, 'keywords', array());
if (!is_array($words)) {
$words = array($words);
}
// For statuses, we include the status name because it's usually
// at least somewhat meaningful.
$words[] = $key;
foreach ($words as $word_key => $word) {
$words[$word_key] = phutil_utf8_strtolower($word);
}
$words = array_unique($words);
$map[$key] = $words;
}
return $map;
}
public static function getTaskStatusName($status) {
return self::getStatusAttribute($status, 'name', pht('Unknown Status'));
}
public static function getTaskStatusFullName($status) {
$name = self::getStatusAttribute($status, 'name.full');
if ($name !== null) {
return $name;
}
return self::getStatusAttribute($status, 'name', pht('Unknown Status'));
}
public static function renderFullDescription($status) {
if (self::isOpenStatus($status)) {
$color = 'status';
$icon_color = 'bluegrey';
} else {
$color = 'status-dark';
$icon_color = '';
}
$icon = self::getStatusIcon($status);
$img = id(new PHUIIconView())
- ->setIconFont($icon.' '.$icon_color);
+ ->setIcon($icon.' '.$icon_color);
$tag = phutil_tag(
'span',
array(
'class' => 'phui-header-status phui-header-'.$color,
),
array(
$img,
self::getTaskStatusFullName($status),
));
return $tag;
}
private static function getSpecialStatus($special) {
foreach (self::getStatusConfig() as $const => $status) {
if (idx($status, 'special') == $special) {
return $const;
}
}
return null;
}
public static function getDefaultStatus() {
return self::getSpecialStatus(self::SPECIAL_DEFAULT);
}
public static function getDefaultClosedStatus() {
return self::getSpecialStatus(self::SPECIAL_CLOSED);
}
public static function getDuplicateStatus() {
return self::getSpecialStatus(self::SPECIAL_DUPLICATE);
}
public static function getOpenStatusConstants() {
$result = array();
foreach (self::getEnabledStatusMap() as $const => $status) {
if (empty($status['closed'])) {
$result[] = $const;
}
}
return $result;
}
public static function getClosedStatusConstants() {
$all = array_keys(self::getTaskStatusMap());
$open = self::getOpenStatusConstants();
return array_diff($all, $open);
}
public static function isOpenStatus($status) {
foreach (self::getOpenStatusConstants() as $constant) {
if ($status == $constant) {
return true;
}
}
return false;
}
public static function isClosedStatus($status) {
return !self::isOpenStatus($status);
}
public static function getStatusActionName($status) {
return self::getStatusAttribute($status, 'name.action');
}
public static function getStatusColor($status) {
return self::getStatusAttribute($status, 'transaction.color');
}
public static function isDisabledStatus($status) {
return self::getStatusAttribute($status, 'disabled');
}
public static function getStatusIcon($status) {
$icon = self::getStatusAttribute($status, 'transaction.icon');
if ($icon) {
return $icon;
}
if (self::isOpenStatus($status)) {
return 'fa-exclamation-circle';
} else {
return 'fa-check-square-o';
}
}
public static function getStatusPrefixMap() {
$map = array();
foreach (self::getEnabledStatusMap() as $const => $status) {
foreach (idx($status, 'prefixes', array()) as $prefix) {
$map[$prefix] = $const;
}
}
$map += array(
'ref' => null,
'refs' => null,
'references' => null,
'cf.' => null,
);
return $map;
}
public static function getStatusSuffixMap() {
$map = array();
foreach (self::getEnabledStatusMap() as $const => $status) {
foreach (idx($status, 'suffixes', array()) as $prefix) {
$map[$prefix] = $const;
}
}
return $map;
}
private static function getStatusAttribute($status, $key, $default = null) {
$config = self::getStatusConfig();
$spec = idx($config, $status);
if ($spec) {
return idx($spec, $key, $default);
}
return $default;
}
/* -( Configuration Validation )------------------------------------------- */
/**
* @task validate
*/
public static function isValidStatusConstant($constant) {
if (strlen($constant) > 12) {
return false;
}
if (!preg_match('/^[a-z0-9]+\z/', $constant)) {
return false;
}
return true;
}
/**
* @task validate
*/
public static function validateConfiguration(array $config) {
foreach ($config as $key => $value) {
if (!self::isValidStatusConstant($key)) {
throw new Exception(
pht(
'Key "%s" is not a valid status constant. Status constants must '.
'be 1-12 characters long and contain only lowercase letters (a-z) '.
'and digits (0-9). For example, "%s" or "%s" are reasonable '.
'choices.',
$key,
'open',
'closed'));
}
if (!is_array($value)) {
throw new Exception(
pht(
'Value for key "%s" should be a dictionary.',
$key));
}
PhutilTypeSpec::checkMap(
$value,
array(
'name' => 'string',
'name.full' => 'optional string',
'name.action' => 'optional string',
'closed' => 'optional bool',
'special' => 'optional string',
'transaction.icon' => 'optional string',
'transaction.color' => 'optional string',
'silly' => 'optional bool',
'prefixes' => 'optional list<string>',
'suffixes' => 'optional list<string>',
'keywords' => 'optional list<string>',
'disabled' => 'optional bool',
));
}
$special_map = array();
foreach ($config as $key => $value) {
$special = idx($value, 'special');
if (!$special) {
continue;
}
if (isset($special_map[$special])) {
throw new Exception(
pht(
'Configuration has two statuses both marked with the special '.
'attribute "%s" ("%s" and "%s"). There should be only one.',
$special,
$special_map[$special],
$key));
}
switch ($special) {
case self::SPECIAL_DEFAULT:
if (!empty($value['closed'])) {
throw new Exception(
pht(
'Status "%s" is marked as default, but it is a closed '.
'status. The default status should be an open status.',
$key));
}
break;
case self::SPECIAL_CLOSED:
if (empty($value['closed'])) {
throw new Exception(
pht(
'Status "%s" is marked as the default status for closing '.
'tasks, but is not a closed status. It should be a closed '.
'status.',
$key));
}
break;
case self::SPECIAL_DUPLICATE:
if (empty($value['closed'])) {
throw new Exception(
pht(
'Status "%s" is marked as the status for closing tasks as '.
'duplicates, but it is not a closed status. It should '.
'be a closed status.',
$key));
}
break;
}
$special_map[$special] = $key;
}
// NOTE: We're not explicitly validating that we have at least one open
// and one closed status, because the DEFAULT and CLOSED specials imply
// that to be true. If those change in the future, that might become a
// reasonable thing to validate.
$required = array(
self::SPECIAL_DEFAULT,
self::SPECIAL_CLOSED,
self::SPECIAL_DUPLICATE,
);
foreach ($required as $required_special) {
if (!isset($special_map[$required_special])) {
throw new Exception(
pht(
'Configuration defines no task status with special attribute '.
'"%s", but you must specify a status which fills this special '.
'role.',
$required_special));
}
}
}
}
diff --git a/src/applications/metamta/applicationpanel/PhabricatorMetaMTAApplicationEmailPanel.php b/src/applications/metamta/applicationpanel/PhabricatorMetaMTAApplicationEmailPanel.php
index ba03603071..1899ac1be1 100644
--- a/src/applications/metamta/applicationpanel/PhabricatorMetaMTAApplicationEmailPanel.php
+++ b/src/applications/metamta/applicationpanel/PhabricatorMetaMTAApplicationEmailPanel.php
@@ -1,407 +1,405 @@
<?php
final class PhabricatorMetaMTAApplicationEmailPanel
extends PhabricatorApplicationConfigurationPanel {
public function getPanelKey() {
return 'email';
}
public function shouldShowForApplication(
PhabricatorApplication $application) {
return $application->supportsEmailIntegration();
}
public function buildConfigurationPagePanel() {
$viewer = $this->getViewer();
$application = $this->getApplication();
$table = $this->buildEmailTable($is_edit = false, null);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$application,
PhabricatorPolicyCapability::CAN_EDIT);
$header = id(new PHUIHeaderView())
->setHeader(pht('Application Emails'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setText(pht('Edit Application Emails'))
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-pencil'))
+ ->setIcon('fa-pencil')
->setHref($this->getPanelURI())
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
return $box;
}
public function handlePanelRequest(
AphrontRequest $request,
PhabricatorController $controller) {
$viewer = $request->getViewer();
$application = $this->getApplication();
$path = $request->getURIData('path');
if (strlen($path)) {
return new Aphront404Response();
}
$uri = $request->getRequestURI();
$uri->setQueryParams(array());
$new = $request->getStr('new');
$edit = $request->getInt('edit');
$delete = $request->getInt('delete');
if ($new) {
return $this->returnNewAddressResponse($request, $uri, $application);
}
if ($edit) {
return $this->returnEditAddressResponse($request, $uri, $edit);
}
if ($delete) {
return $this->returnDeleteAddressResponse($request, $uri, $delete);
}
$table = $this->buildEmailTable(
$is_edit = true,
$request->getInt('id'));
$form = id(new AphrontFormView())
->setUser($viewer);
$crumbs = $controller->buildPanelCrumbs($this);
$crumbs->addTextCrumb(pht('Edit Application Emails'));
$header = id(new PHUIHeaderView())
->setHeader(pht('Edit Application Emails: %s', $application->getName()))
->setSubheader($application->getAppEmailBlurb());
$icon = id(new PHUIIconView())
- ->setIconFont('fa-plus');
+ ->setIcon('fa-plus');
$button = new PHUIButtonView();
$button->setText(pht('Add New Address'));
$button->setTag('a');
$button->setHref($uri->alter('new', 'true'));
$button->setIcon($icon);
$button->addSigil('workflow');
$header->addActionLink($button);
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
$title = $application->getName();
return $controller->buildPanelPage(
$this,
array(
$crumbs,
$object_box,
),
array(
'title' => $title,
));
}
private function returnNewAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
PhabricatorApplication $application) {
$viewer = $request->getUser();
$email_object =
PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail($viewer)
->setApplicationPHID($application->getPHID());
return $this->returnSaveAddressResponse(
$request,
$uri,
$email_object,
$is_new = true);
}
private function returnEditAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
$email_object_id) {
$viewer = $request->getUser();
$email_object = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer($viewer)
->withIDs(array($email_object_id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$email_object) {
return new Aphront404Response();
}
return $this->returnSaveAddressResponse(
$request,
$uri,
$email_object,
$is_new = false);
}
private function returnSaveAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
PhabricatorMetaMTAApplicationEmail $email_object,
$is_new) {
$viewer = $request->getUser();
$config_default =
PhabricatorMetaMTAApplicationEmail::CONFIG_DEFAULT_AUTHOR;
$e_email = true;
$v_email = $email_object->getAddress();
$e_space = null;
$v_space = $email_object->getSpacePHID();
$v_default = $email_object->getConfigValue($config_default);
$validation_exception = null;
if ($request->isDialogFormPost()) {
$e_email = null;
$v_email = trim($request->getStr('email'));
$v_space = $request->getStr('spacePHID');
$v_default = $request->getArr($config_default);
$v_default = nonempty(head($v_default), null);
$type_address =
PhabricatorMetaMTAApplicationEmailTransaction::TYPE_ADDRESS;
$type_space = PhabricatorTransactions::TYPE_SPACE;
$type_config =
PhabricatorMetaMTAApplicationEmailTransaction::TYPE_CONFIG;
$key_config = PhabricatorMetaMTAApplicationEmailTransaction::KEY_CONFIG;
$xactions = array();
$xactions[] = id(new PhabricatorMetaMTAApplicationEmailTransaction())
->setTransactionType($type_address)
->setNewValue($v_email);
$xactions[] = id(new PhabricatorMetaMTAApplicationEmailTransaction())
->setTransactionType($type_space)
->setNewValue($v_space);
$xactions[] = id(new PhabricatorMetaMTAApplicationEmailTransaction())
->setTransactionType($type_config)
->setMetadataValue($key_config, $config_default)
->setNewValue($v_default);
$editor = id(new PhabricatorMetaMTAApplicationEmailEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
try {
$editor->applyTransactions($email_object, $xactions);
return id(new AphrontRedirectResponse())->setURI(
$uri->alter('highlight', $email_object->getID()));
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$e_email = $ex->getShortMessage($type_address);
$e_space = $ex->getShortMessage($type_space);
}
}
if ($v_default) {
$v_default = array($v_default);
} else {
$v_default = array();
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Email'))
->setName('email')
->setValue($v_email)
->setError($e_email));
if (PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
$form->appendControl(
id(new AphrontFormSelectControl())
->setLabel(pht('Space'))
->setName('spacePHID')
->setValue($v_space)
->setError($e_space)
->setOptions(
PhabricatorSpacesNamespaceQuery::getSpaceOptionsForViewer(
$viewer,
$v_space)));
}
$form
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setLabel(pht('Default Author'))
->setName($config_default)
->setLimit(1)
->setValue($v_default)
->setCaption(pht(
'Used if the "From:" address does not map to a known account.')));
if ($is_new) {
$title = pht('New Address');
} else {
$title = pht('Edit Address');
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle($title)
->setValidationException($validation_exception)
->appendForm($form)
->addSubmitButton(pht('Save'))
->addCancelButton($uri);
if ($is_new) {
$dialog->addHiddenInput('new', 'true');
}
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function returnDeleteAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
$email_object_id) {
$viewer = $this->getViewer();
$email_object = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer($viewer)
->withIDs(array($email_object_id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$email_object) {
return new Aphront404Response();
}
if ($request->isDialogFormPost()) {
$engine = new PhabricatorDestructionEngine();
$engine->destroyObject($email_object);
return id(new AphrontRedirectResponse())->setURI($uri);
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('delete', $email_object_id)
->setTitle(pht('Delete Address'))
->appendParagraph(pht(
'Are you sure you want to delete this email address?'))
->addSubmitButton(pht('Delete'))
->addCancelButton($uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function buildEmailTable($is_edit, $highlight) {
$viewer = $this->getViewer();
$application = $this->getApplication();
$uri = new PhutilURI($this->getPanelURI());
$emails = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer($viewer)
->withApplicationPHIDs(array($application->getPHID()))
->execute();
$rowc = array();
$rows = array();
foreach ($emails as $email) {
$button_edit = javelin_tag(
'a',
array(
'class' => 'button small grey',
'href' => $uri->alter('edit', $email->getID()),
'sigil' => 'workflow',
),
pht('Edit'));
$button_remove = javelin_tag(
'a',
array(
'class' => 'button small grey',
'href' => $uri->alter('delete', $email->getID()),
'sigil' => 'workflow',
),
pht('Delete'));
if ($highlight == $email->getID()) {
$rowc[] = 'highlighted';
} else {
$rowc[] = null;
}
$space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID($email);
if ($space_phid) {
$email_space = $viewer->renderHandle($space_phid);
} else {
$email_space = null;
}
$rows[] = array(
$email_space,
$email->getAddress(),
$button_edit,
$button_remove,
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No application emails created yet.'));
$table->setHeaders(
array(
pht('Space'),
pht('Email'),
pht('Edit'),
pht('Delete'),
));
$table->setColumnClasses(
array(
'',
'wide',
'action',
'action',
));
$table->setRowClasses($rowc);
$table->setColumnVisibility(
array(
PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer),
true,
$is_edit,
$is_edit,
));
return $table;
}
}
diff --git a/src/applications/notification/controller/PhabricatorNotificationStatusController.php b/src/applications/notification/controller/PhabricatorNotificationStatusController.php
index e889c7af5e..eb79a3a8c5 100644
--- a/src/applications/notification/controller/PhabricatorNotificationStatusController.php
+++ b/src/applications/notification/controller/PhabricatorNotificationStatusController.php
@@ -1,85 +1,85 @@
<?php
final class PhabricatorNotificationStatusController
extends PhabricatorNotificationController {
public function handleRequest(AphrontRequest $request) {
try {
$status = PhabricatorNotificationClient::getServerStatus();
$status = $this->renderServerStatus($status);
} catch (Exception $ex) {
$status = new PHUIInfoView();
$status->setTitle(pht('Notification Server Issue'));
$status->appendChild(hsprintf(
'%s<br /><br />'.
'<strong>%s</strong> %s',
pht(
'Unable to determine server status. This probably means the server '.
'is not in great shape. The specific issue encountered was:'),
get_class($ex),
phutil_escape_html_newlines($ex->getMessage())));
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Status'));
return $this->buildApplicationPage(
array(
$crumbs,
$status,
),
array(
'title' => pht('Notification Server Status'),
'device' => false,
));
}
private function renderServerStatus(array $status) {
$rows = array();
foreach ($status as $key => $value) {
switch ($key) {
case 'uptime':
$value /= 1000;
$value = phutil_format_relative_time_detailed($value);
break;
case 'log':
case 'instance':
break;
default:
$value = number_format($value);
break;
}
$rows[] = array($key, $value);
}
$table = new AphrontTableView($rows);
$table->setColumnClasses(
array(
'header',
'wide',
));
$test_icon = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle');
+ ->setIcon('fa-exclamation-triangle');
$test_button = id(new PHUIButtonView())
->setTag('a')
->setWorkflow(true)
->setText(pht('Send Test Notification'))
->setHref($this->getApplicationURI('test/'))
->setIcon($test_icon);
$header = id(new PHUIHeaderView())
->setHeader(pht('Notification Server Status'))
->addActionLink($test_button);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($table);
return $box;
}
}
diff --git a/src/applications/notification/query/PhabricatorNotificationSearchEngine.php b/src/applications/notification/query/PhabricatorNotificationSearchEngine.php
index 8d62372dc3..11b935eb50 100644
--- a/src/applications/notification/query/PhabricatorNotificationSearchEngine.php
+++ b/src/applications/notification/query/PhabricatorNotificationSearchEngine.php
@@ -1,141 +1,141 @@
<?php
final class PhabricatorNotificationSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Notifications');
}
public function getApplicationClassName() {
return 'PhabricatorNotificationsApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'unread',
$this->readBoolFromRequest($request, 'unread'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorNotificationQuery())
->withUserPHIDs(array($this->requireViewer()->getPHID()));
if ($saved->getParameter('unread')) {
$query->withUnread(true);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved) {
$unread = $saved->getParameter('unread');
$form->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel(pht('Unread'))
->addCheckbox(
'unread',
1,
pht('Show only unread notifications.'),
$unread));
}
protected function getURI($path) {
return '/notification/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Notifications'),
'unread' => pht('Unread Notifications'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'unread':
return $query->setParameter('unread', true);
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $notifications,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($notifications, 'PhabricatorFeedStory');
$viewer = $this->requireViewer();
$image = id(new PHUIIconView())
- ->setIconFont('fa-eye-slash');
+ ->setIcon('fa-eye-slash');
$button = id(new PHUIButtonView())
->setTag('a')
->addSigil('workflow')
->setColor(PHUIButtonView::SIMPLE)
->setIcon($image)
->setText(pht('Mark All Read'));
switch ($query->getQueryKey()) {
case 'unread':
$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;
}
$clear_uri = id(new PhutilURI('/notification/clear/'));
if ($notifications) {
$builder = id(new PhabricatorNotificationBuilder($notifications))
->setUser($viewer);
$view = $builder->buildView();
$clear_uri->setQueryParam(
'chronoKey',
head($notifications)->getChronologicalKey());
} else {
$view = phutil_tag_div(
'phabricator-notification no-notifications',
$no_data);
$button->setDisabled(true);
}
$button->setHref((string)$clear_uri);
$view = id(new PHUIBoxView())
->addPadding(PHUI::PADDING_MEDIUM)
->addClass('phabricator-notification-list')
->appendChild($view);
$result = new PhabricatorApplicationSearchResultView();
$result->addAction($button);
$result->setContent($view);
return $result;
}
public function shouldUseOffsetPaging() {
return true;
}
}
diff --git a/src/applications/people/controller/PhabricatorPeopleProfileManageController.php b/src/applications/people/controller/PhabricatorPeopleProfileManageController.php
index aca259abb0..0a2e4fd612 100644
--- a/src/applications/people/controller/PhabricatorPeopleProfileManageController.php
+++ b/src/applications/people/controller/PhabricatorPeopleProfileManageController.php
@@ -1,185 +1,185 @@
<?php
final class PhabricatorPeopleProfileManageController
extends PhabricatorPeopleProfileController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withIDs(array($id))
->needProfile(true)
->needProfileImage(true)
->executeOne();
if (!$user) {
return new Aphront404Response();
}
$this->setUser($user);
$profile = $user->loadUserProfile();
$picture = $user->getProfileImageURI();
$profile_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());
$profile_icon = id(new PHUIIconView())
- ->setIconFont($profile_icon);
+ ->setIcon($profile_icon);
$profile_title = $profile->getDisplayTitle();
$header = id(new PHUIHeaderView())
->setHeader($user->getFullName())
->setSubheader(array($profile_icon, $profile_title))
->setImage($picture);
$actions = $this->buildActionList($user);
$properties = $this->buildPropertyView($user);
$properties->setActionList($actions);
$name = $user->getUsername();
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
$nav = $this->getProfileMenu();
$nav->selectFilter(PhabricatorPeopleProfilePanelEngine::PANEL_MANAGE);
$timeline = $this->buildTransactionTimeline(
$user,
new PhabricatorPeopleTransactionQuery());
$timeline->setShouldTerminate(true);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Manage'));
return $this->newPage()
->setTitle(
array(
pht('Manage User'),
$user->getUsername(),
))
->setNavigation($nav)
->setCrumbs($crumbs)
->appendChild(
array(
$object_box,
$timeline,
));
}
private function buildPropertyView(PhabricatorUser $user) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($user);
return $view;
}
private function buildActionList(PhabricatorUser $user) {
$viewer = $this->getViewer();
$actions = id(new PhabricatorActionListView())
->setUser($viewer);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$user,
PhabricatorPolicyCapability::CAN_EDIT);
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Profile'))
->setHref($this->getApplicationURI('editprofile/'.$user->getID().'/'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-picture-o')
->setName(pht('Edit Profile Picture'))
->setHref($this->getApplicationURI('picture/'.$user->getID().'/'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-wrench')
->setName(pht('Edit Settings'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref('/settings/'.$user->getID().'/'));
if ($user->getIsAdmin()) {
$empower_icon = 'fa-arrow-circle-o-down';
$empower_name = pht('Remove Administrator');
} else {
$empower_icon = 'fa-arrow-circle-o-up';
$empower_name = pht('Make Administrator');
}
$is_admin = $viewer->getIsAdmin();
$is_self = ($user->getPHID() === $viewer->getPHID());
$can_admin = ($is_admin && !$is_self);
$actions->addAction(
id(new PhabricatorActionView())
->setIcon($empower_icon)
->setName($empower_name)
->setDisabled(!$can_admin)
->setWorkflow(true)
->setHref($this->getApplicationURI('empower/'.$user->getID().'/')));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-tag')
->setName(pht('Change Username'))
->setDisabled(!$is_admin)
->setWorkflow(true)
->setHref($this->getApplicationURI('rename/'.$user->getID().'/')));
if ($user->getIsDisabled()) {
$disable_icon = 'fa-check-circle-o';
$disable_name = pht('Enable User');
} else {
$disable_icon = 'fa-ban';
$disable_name = pht('Disable User');
}
$actions->addAction(
id(new PhabricatorActionView())
->setIcon($disable_icon)
->setName($disable_name)
->setDisabled(!$can_admin)
->setWorkflow(true)
->setHref($this->getApplicationURI('disable/'.$user->getID().'/')));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-times')
->setName(pht('Delete User'))
->setDisabled(!$can_admin)
->setWorkflow(true)
->setHref($this->getApplicationURI('delete/'.$user->getID().'/')));
$can_welcome = ($is_admin && $user->canEstablishWebSessions());
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-envelope')
->setName(pht('Send Welcome Email'))
->setWorkflow(true)
->setDisabled(!$can_welcome)
->setHref($this->getApplicationURI('welcome/'.$user->getID().'/')));
return $actions;
}
}
diff --git a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php
index 90ad86bfef..1453ab7d71 100644
--- a/src/applications/people/controller/PhabricatorPeopleProfileViewController.php
+++ b/src/applications/people/controller/PhabricatorPeopleProfileViewController.php
@@ -1,187 +1,187 @@
<?php
final class PhabricatorPeopleProfileViewController
extends PhabricatorPeopleProfileController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$username = $request->getURIData('username');
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withUsernames(array($username))
->needBadges(true)
->needProfileImage(true)
->needAvailability(true)
->executeOne();
if (!$user) {
return new Aphront404Response();
}
$this->setUser($user);
$profile = $user->loadUserProfile();
$picture = $user->getProfileImageURI();
$profile_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon());
$profile_icon = id(new PHUIIconView())
- ->setIconFont($profile_icon);
+ ->setIcon($profile_icon);
$profile_title = $profile->getDisplayTitle();
$header = id(new PHUIHeaderView())
->setHeader($user->getFullName())
->setSubheader(array($profile_icon, $profile_title))
->setImage($picture)
->setProfileHeader(true);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$user,
PhabricatorPolicyCapability::CAN_EDIT);
if ($can_edit) {
$id = $user->getID();
$header->setImageEditURL($this->getApplicationURI("picture/{$id}/"));
}
$properties = $this->buildPropertyView($user);
$name = $user->getUsername();
$feed = $this->buildPeopleFeed($user, $viewer);
$feed = phutil_tag_div('project-view-feed', $feed);
$badges = $this->buildBadgesView($user);
if ($badges) {
$columns = id(new PHUITwoColumnView())
->addClass('project-view-badges')
->setMainColumn(
array(
$properties,
$feed,
))
->setSideColumn(
array(
$badges,
));
} else {
$columns = array($properties, $feed);
}
$nav = $this->getProfileMenu();
$nav->selectFilter(PhabricatorPeopleProfilePanelEngine::PANEL_PROFILE);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
require_celerity_resource('project-view-css');
$home = phutil_tag(
'div',
array(
'class' => 'project-view-home',
),
array(
$header,
$columns,
));
return $this->newPage()
->setTitle($user->getUsername())
->setNavigation($nav)
->setCrumbs($crumbs)
->appendChild(
array(
$home,
));
}
private function buildPropertyView(
PhabricatorUser $user) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($user);
$field_list = PhabricatorCustomField::getObjectFields(
$user,
PhabricatorCustomField::ROLE_VIEW);
$field_list->appendFieldsToPropertyList($user, $viewer, $view);
if ($view->isEmpty()) {
return null;
}
$view = id(new PHUIBoxView())
->setColor(PHUIBoxView::GREY)
->appendChild($view)
->addClass('project-view-properties');
return $view;
}
private function buildBadgesView(
PhabricatorUser $user) {
$viewer = $this->getViewer();
$class = 'PhabricatorBadgesApplication';
$box = null;
if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
$badge_phids = $user->getBadgePHIDs();
if ($badge_phids) {
$badges = id(new PhabricatorBadgesQuery())
->setViewer($viewer)
->withPHIDs($badge_phids)
->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE))
->execute();
$flex = new PHUIBadgeBoxView();
foreach ($badges as $badge) {
$item = id(new PHUIBadgeView())
->setIcon($badge->getIcon())
->setHeader($badge->getName())
->setSubhead($badge->getFlavor())
->setQuality($badge->getQuality());
$flex->addItem($item);
}
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Badges'))
->appendChild($flex)
->setBackground(PHUIBoxView::GREY);
}
}
return $box;
}
private function buildPeopleFeed(
PhabricatorUser $user,
$viewer) {
$query = new PhabricatorFeedQuery();
$query->setFilterPHIDs(
array(
$user->getPHID(),
));
$query->setLimit(100);
$query->setViewer($viewer);
$stories = $query->execute();
$builder = new PhabricatorFeedBuilder($stories);
$builder->setUser($viewer);
$builder->setShowHovercards(true);
$builder->setNoDataString(pht('To begin on such a grand journey, '.
'requires but just a single step.'));
$view = $builder->buildView();
return $view->render();
}
}
diff --git a/src/applications/phame/controller/PhameHomeController.php b/src/applications/phame/controller/PhameHomeController.php
index 4028f98e50..b9c7fc76d8 100644
--- a/src/applications/phame/controller/PhameHomeController.php
+++ b/src/applications/phame/controller/PhameHomeController.php
@@ -1,163 +1,163 @@
<?php
final class PhameHomeController extends PhamePostController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$blogs = id(new PhameBlogQuery())
->setViewer($viewer)
->withStatuses(array(PhameBlog::STATUS_ACTIVE))
->needProfileImage(true)
->execute();
$post_list = null;
if ($blogs) {
$blog_phids = mpull($blogs, 'getPHID');
$pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$posts = id(new PhamePostQuery())
->setViewer($viewer)
->withBlogPHIDs($blog_phids)
->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->executeWithCursorPager($pager);
if ($posts) {
$post_list = id(new PhamePostListView())
->setPosts($posts)
->setViewer($viewer)
->showBlog(true);
} else {
$post_list = id(new PHUIBigInfoView())
->setIcon('fa-star')
->setTitle('No Visible Posts')
->setDescription(
pht('There aren\'t any visible blog posts.'));
}
} else {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Blog'))
->setHref('/phame/blog/new/')
->setColor(PHUIButtonView::GREEN);
$post_list = id(new PHUIBigInfoView())
->setIcon('fa-star')
->setTitle('Welcome to Phame')
->setDescription(
pht('There aren\'t any visible blog posts.'))
->addAction($create_button);
}
$actions = $this->renderActions($viewer);
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
- ->setIconFont('fa-bars')
+ ->setIcon('fa-bars')
->addClass('phui-mobile-menu')
->setDropdownMenu($actions);
$title = pht('Recent Posts');
$header = id(new PHUIHeaderView())
->setHeader($title)
->addActionLink($action_button);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
$crumbs->addTextCrumb(
pht('Recent Posts'),
$this->getApplicationURI('post/'));
$page = id(new PHUIDocumentViewPro())
->setHeader($header)
->appendChild($post_list);
$blog_list = id(new PhameBlogListView())
->setBlogs($blogs)
->setViewer($viewer);
$draft_list = null;
if ($viewer->isLoggedIn() && $blogs) {
$drafts = id(new PhamePostQuery())
->setViewer($viewer)
->withBloggerPHIDs(array($viewer->getPHID()))
->withBlogPHIDs(mpull($blogs, 'getPHID'))
->withVisibility(PhameConstants::VISIBILITY_DRAFT)
->setLimit(5)
->execute();
$draft_list = id(new PhameDraftListView())
->setPosts($drafts)
->setBlogs($blogs)
->setViewer($viewer);
}
$phame_view = id(new PHUITwoColumnView())
->setMainColumn(array(
$page,
))
->setSideColumn(array(
$blog_list,
$draft_list,
))
->setDisplay(PHUITwoColumnView::DISPLAY_LEFT)
->addClass('phame-home-view');
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild(
array(
$phame_view,
));
}
private function renderActions($viewer) {
$actions = id(new PhabricatorActionListView())
->setUser($viewer);
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setHref($this->getApplicationURI('post/query/draft/'))
->setName(pht('My Drafts')));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil-square-o')
->setHref($this->getApplicationURI('post/'))
->setName(pht('All Posts')));
return $actions;
}
private function renderBlogs($viewer, $blogs) {}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$can_create = $this->hasApplicationCapability(
PhameBlogCreateCapability::CAPABILITY);
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('New Blog'))
->setHref($this->getApplicationURI('/blog/new/'))
->setIcon('fa-plus-square')
->setDisabled(!$can_create)
->setWorkflow(!$can_create));
return $crumbs;
}
}
diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php
index c387152019..60972c57b8 100644
--- a/src/applications/phame/controller/blog/PhameBlogViewController.php
+++ b/src/applications/phame/controller/blog/PhameBlogViewController.php
@@ -1,165 +1,165 @@
<?php
final class PhameBlogViewController extends PhameLiveController {
public function handleRequest(AphrontRequest $request) {
$response = $this->setupLiveEnvironment();
if ($response) {
return $response;
}
$viewer = $this->getViewer();
$blog = $this->getBlog();
$is_live = $this->getIsLive();
$is_external = $this->getIsExternal();
$pager = id(new AphrontCursorPagerView())
->readFromRequest($request);
$post_query = id(new PhamePostQuery())
->setViewer($viewer)
->withBlogPHIDs(array($blog->getPHID()));
if ($is_live) {
$post_query->withVisibility(PhameConstants::VISIBILITY_PUBLISHED);
}
$posts = $post_query->executeWithCursorPager($pager);
$header = id(new PHUIHeaderView())
->setHeader($blog->getName())
->setUser($viewer);
if (!$is_external) {
if ($blog->isArchived()) {
$header_icon = 'fa-ban';
$header_name = pht('Archived');
$header_color = 'dark';
} else {
$header_icon = 'fa-check';
$header_name = pht('Active');
$header_color = 'bluegrey';
}
$header->setStatus($header_icon, $header_color, $header_name);
$actions = $this->renderActions($blog);
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
- ->setIconFont('fa-bars')
+ ->setIcon('fa-bars')
->addClass('phui-mobile-menu')
->setDropdownMenu($actions);
$header->addActionLink($action_button);
$header->setPolicyObject($blog);
}
if ($posts) {
$post_list = id(new PhamePostListView())
->setPosts($posts)
->setViewer($viewer)
->setIsExternal($is_external)
->setIsLive($is_live)
->setNodata(pht('This blog has no visible posts.'));
} else {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Write a Post'))
->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
->setColor(PHUIButtonView::GREEN);
$post_list = id(new PHUIBigInfoView())
->setIcon('fa-star')
->setTitle($blog->getName())
->setDescription(
pht('No one has written any blog posts yet.'));
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$blog,
PhabricatorPolicyCapability::CAN_EDIT);
if ($can_edit) {
$post_list->addAction($create_button);
}
}
$page = id(new PHUIDocumentViewPro())
->setHeader($header)
->appendChild($post_list);
$description = null;
if (strlen($blog->getDescription())) {
$description = new PHUIRemarkupView(
$viewer,
$blog->getDescription());
} else {
$description = phutil_tag('em', array(), pht('No description.'));
}
$about = id(new PhameDescriptionView())
->setTitle(pht('About %s', $blog->getName()))
->setDescription($description)
->setImage($blog->getProfileImageURI());
$crumbs = $this->buildApplicationCrumbs();
$page = $this->newPage()
->setTitle($blog->getName())
->setPageObjectPHIDs(array($blog->getPHID()))
->setCrumbs($crumbs)
->appendChild(
array(
$page,
$about,
));
if ($is_live) {
$page
->setShowChrome(false)
->setShowFooter(false);
}
return $page;
}
private function renderActions(PhameBlog $blog) {
$viewer = $this->getViewer();
$actions = id(new PhabricatorActionListView())
->setObject($blog)
->setUser($viewer);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$blog,
PhabricatorPolicyCapability::CAN_EDIT);
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-plus')
->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
->setName(pht('Write Post'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$actions->addAction(
id(new PhabricatorActionView())
->setUser($viewer)
->setIcon('fa-globe')
->setHref($blog->getLiveURI())
->setName(pht('View Live')));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setHref($this->getApplicationURI('blog/manage/'.$blog->getID().'/'))
->setName(pht('Manage Blog')));
return $actions;
}
}
diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php
index 6a0ceace4f..68c9f22082 100644
--- a/src/applications/phame/controller/post/PhamePostViewController.php
+++ b/src/applications/phame/controller/post/PhamePostViewController.php
@@ -1,268 +1,268 @@
<?php
final class PhamePostViewController
extends PhameLiveController {
public function handleRequest(AphrontRequest $request) {
$response = $this->setupLiveEnvironment();
if ($response) {
return $response;
}
$viewer = $request->getViewer();
$moved = $request->getStr('moved');
$post = $this->getPost();
$blog = $this->getBlog();
$is_live = $this->getIsLive();
$is_external = $this->getIsExternal();
$header = id(new PHUIHeaderView())
->setHeader($post->getTitle())
->setUser($viewer);
if (!$is_external) {
$actions = $this->renderActions($post);
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
- ->setIconFont('fa-bars')
+ ->setIcon('fa-bars')
->addClass('phui-mobile-menu')
->setDropdownMenu($actions);
$header->setPolicyObject($post);
$header->addActionLink($action_button);
}
$document = id(new PHUIDocumentViewPro())
->setHeader($header);
if ($moved) {
$document->appendChild(
id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild(pht('Post moved successfully.')));
}
if ($post->isDraft()) {
$document->appendChild(
id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->setTitle(pht('Draft Post'))
->appendChild(
pht('Only you can see this draft until you publish it. '.
'Use "Publish" to publish this post.')));
}
if (!$post->getBlog()) {
$document->appendChild(
id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setTitle(pht('Not On A Blog'))
->appendChild(
pht('This post is not associated with a blog (the blog may have '.
'been deleted). Use "Move Post" to move it to a new blog.')));
}
$engine = id(new PhabricatorMarkupEngine())
->setViewer($viewer)
->addObject($post, PhamePost::MARKUP_FIELD_BODY)
->process();
$document->appendChild(
phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup',
),
$engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY)));
$blogger = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withPHIDs(array($post->getBloggerPHID()))
->needProfileImage(true)
->executeOne();
$blogger_profile = $blogger->loadUserProfile();
$author = phutil_tag(
'a',
array(
'href' => '/p/'.$blogger->getUsername().'/',
),
$blogger->getUsername());
$date = phabricator_datetime($post->getDatePublished(), $viewer);
if ($post->isDraft()) {
$subtitle = pht('Unpublished draft by %s.', $author);
} else {
$subtitle = pht('Written by %s on %s.', $author, $date);
}
$about = id(new PhameDescriptionView())
->setTitle($subtitle)
->setDescription($blogger_profile->getTitle())
->setImage($blogger->getProfileImageURI())
->setImageHref('/p/'.$blogger->getUsername());
$timeline = $this->buildTransactionTimeline(
$post,
id(new PhamePostTransactionQuery())
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)));
$timeline = phutil_tag_div('phui-document-view-pro-box', $timeline);
if ($is_external) {
$add_comment = null;
} else {
$add_comment = $this->buildCommentForm($post);
$add_comment = phutil_tag_div('mlb mlt', $add_comment);
}
list($prev, $next) = $this->loadAdjacentPosts($post);
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($post);
$next_view = new PhameNextPostView();
if ($next) {
$next_view->setNext($next->getTitle(), $next->getViewURI());
}
if ($prev) {
$next_view->setPrevious($prev->getTitle(), $prev->getViewURI());
}
$document->setFoot($next_view);
$crumbs = $this->buildApplicationCrumbs();
$page = $this->newPage()
->setTitle($post->getTitle())
->setPageObjectPHIDs(array($post->getPHID()))
->setCrumbs($crumbs)
->appendChild(
array(
$document,
$about,
$properties,
$timeline,
$add_comment,
));
if ($is_live) {
$page
->setShowChrome(false)
->setShowFooter(false);
}
return $page;
}
private function renderActions(PhamePost $post) {
$viewer = $this->getViewer();
$actions = id(new PhabricatorActionListView())
->setObject($post)
->setUser($viewer);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$post,
PhabricatorPolicyCapability::CAN_EDIT);
$id = $post->getID();
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setHref($this->getApplicationURI('post/edit/'.$id.'/'))
->setName(pht('Edit Post'))
->setDisabled(!$can_edit));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-arrows')
->setHref($this->getApplicationURI('post/move/'.$id.'/'))
->setName(pht('Move Post'))
->setDisabled(!$can_edit)
->setWorkflow(true));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-history')
->setHref($this->getApplicationURI('post/history/'.$id.'/'))
->setName(pht('View History')));
if ($post->isDraft()) {
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-eye')
->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
->setName(pht('Publish'))
->setDisabled(!$can_edit)
->setWorkflow(true));
} else {
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-eye-slash')
->setHref($this->getApplicationURI('post/unpublish/'.$id.'/'))
->setName(pht('Unpublish'))
->setDisabled(!$can_edit)
->setWorkflow(true));
}
if ($post->isDraft()) {
$live_name = pht('Preview');
} else {
$live_name = pht('View Live');
}
$actions->addAction(
id(new PhabricatorActionView())
->setUser($viewer)
->setIcon('fa-globe')
->setHref($post->getLiveURI())
->setName($live_name));
return $actions;
}
private function buildCommentForm(PhamePost $post) {
$viewer = $this->getViewer();
$draft = PhabricatorDraft::newFromUserAndKey(
$viewer, $post->getPHID());
$box = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($post->getPHID())
->setDraft($draft)
->setHeaderText(pht('Add Comment'))
->setAction($this->getApplicationURI('post/comment/'.$post->getID().'/'))
->setSubmitButtonName(pht('Add Comment'));
return phutil_tag_div('phui-document-view-pro-box', $box);
}
private function loadAdjacentPosts(PhamePost $post) {
$viewer = $this->getViewer();
$query = id(new PhamePostQuery())
->setViewer($viewer)
->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->withBlogPHIDs(array($post->getBlog()->getPHID()))
->setLimit(1);
$prev = id(clone $query)
->setAfterID($post->getID())
->execute();
$next = id(clone $query)
->setBeforeID($post->getID())
->execute();
return array(head($prev), head($next));
}
}
diff --git a/src/applications/phame/view/PhameBlogListView.php b/src/applications/phame/view/PhameBlogListView.php
index ae936442b0..f2149b8cfb 100644
--- a/src/applications/phame/view/PhameBlogListView.php
+++ b/src/applications/phame/view/PhameBlogListView.php
@@ -1,100 +1,100 @@
<?php
final class PhameBlogListView extends AphrontTagView {
private $blogs;
private $viewer;
public function setBlogs($blogs) {
assert_instances_of($blogs, 'PhameBlog');
$this->blogs = $blogs;
return $this;
}
public function setViewer($viewer) {
$this->viewer = $viewer;
return $this;
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phame-blog-list';
return array('class' => implode(' ', $classes));
}
protected function getTagContent() {
require_celerity_resource('phame-css');
$list = array();
foreach ($this->blogs as $blog) {
$image_uri = $blog->getProfileImageURI();
$image = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-image',
'style' => 'background-image: url('.$image_uri.');',
'href' => $blog->getViewURI(),
));
$title = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-title',
'href' => $blog->getViewURI(),
),
$blog->getName());
$icon = id(new PHUIIconView())
- ->setIconFont('fa-plus-square')
+ ->setIcon('fa-plus-square')
->addClass('phame-blog-list-icon');
$add_new = phutil_tag(
'a',
array(
'href' => '/phame/post/edit/?blog='.$blog->getID(),
'class' => 'phame-blog-list-new-post',
),
$icon);
$list[] = phutil_tag(
'div',
array(
'class' => 'phame-blog-list-item',
),
array(
$image,
$title,
$add_new,
));
}
if (empty($list)) {
$list = phutil_tag(
'a',
array(
'href' => '/phame/blog/new/',
),
pht('Create a Blog'));
}
$header = phutil_tag(
'h4',
array(
'class' => 'phame-blog-list-header',
),
phutil_tag(
'a',
array(
'href' => '/phame/blog/',
),
pht('Blogs')));
return id(new PHUIBoxView())
->appendChild($header)
->appendChild($list)
->addClass('pl')
->setColor(PHUIBoxView::BLUE);
}
}
diff --git a/src/applications/phame/view/PhameDraftListView.php b/src/applications/phame/view/PhameDraftListView.php
index 68bb56cabf..87c5a6d7b5 100644
--- a/src/applications/phame/view/PhameDraftListView.php
+++ b/src/applications/phame/view/PhameDraftListView.php
@@ -1,102 +1,102 @@
<?php
final class PhameDraftListView extends AphrontTagView {
private $posts;
private $blogs;
private $viewer;
public function setPosts($posts) {
assert_instances_of($posts, 'PhamePost');
$this->posts = $posts;
return $this;
}
public function setBlogs($blogs) {
assert_instances_of($blogs, 'PhameBlog');
$this->blogs = $blogs;
return $this;
}
public function setViewer($viewer) {
$this->viewer = $viewer;
return $this;
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phame-blog-list';
return array('class' => implode(' ', $classes));
}
protected function getTagContent() {
require_celerity_resource('phame-css');
$list = array();
foreach ($this->posts as $post) {
$blog = $post->getBlog();
$image_uri = $blog->getProfileImageURI();
$image = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-image',
'style' => 'background-image: url('.$image_uri.');',
'href' => $blog->getViewURI(),
));
$title = phutil_tag(
'a',
array(
'class' => 'phame-blog-list-title',
'href' => $post->getViewURI(),
),
$post->getTitle());
$icon = id(new PHUIIconView())
- ->setIconFont('fa-pencil-square-o')
+ ->setIcon('fa-pencil-square-o')
->addClass('phame-blog-list-icon');
$edit = phutil_tag(
'a',
array(
'href' => '/phame/post/edit/'.$post->getID().'/',
'class' => 'phame-blog-list-new-post',
),
$icon);
$list[] = phutil_tag(
'div',
array(
'class' => 'phame-blog-list-item',
),
array(
$image,
$title,
$edit,
));
}
if (empty($list)) {
$list = pht('You have no draft posts.');
}
$header = phutil_tag(
'h4',
array(
'class' => 'phame-blog-list-header',
),
phutil_tag(
'a',
array(
'href' => '/phame/post/query/draft/',
),
pht('Drafts')));
return id(new PHUIBoxView())
->appendChild($header)
->appendChild($list)
->addClass('pl')
->setColor(PHUIBoxView::BLUE);
}
}
diff --git a/src/applications/phame/view/PhameNextPostView.php b/src/applications/phame/view/PhameNextPostView.php
index 87f4f7aa1a..beabcd6d72 100644
--- a/src/applications/phame/view/PhameNextPostView.php
+++ b/src/applications/phame/view/PhameNextPostView.php
@@ -1,113 +1,113 @@
<?php
final class PhameNextPostView extends AphrontTagView {
private $nextTitle;
private $nextHref;
private $previousTitle;
private $previousHref;
public function setNext($title, $href) {
$this->nextTitle = $title;
$this->nextHref = $href;
return $this;
}
public function setPrevious($title, $href) {
$this->previousTitle = $title;
$this->previousHref = $href;
return $this;
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phame-next-post-view';
$classes[] = 'grouped';
return array('class' => implode(' ', $classes));
}
protected function getTagContent() {
require_celerity_resource('phame-css');
$p_icon = id(new PHUIIconView())
- ->setIconFont('fa-angle-left');
+ ->setIcon('fa-angle-left');
$previous_icon = phutil_tag(
'div',
array(
'class' => 'phame-previous-arrow',
),
$p_icon);
$previous_text = phutil_tag(
'div',
array(
'class' => 'phame-previous-header',
),
pht('Previous Post'));
$previous_title = phutil_tag(
'div',
array(
'class' => 'phame-previous-title',
),
$this->previousTitle);
$previous = null;
if ($this->previousHref) {
$previous = phutil_tag(
'a',
array(
'class' => 'phame-previous',
'href' => $this->previousHref,
),
array(
$previous_icon,
$previous_text,
$previous_title,
));
}
$n_icon = id(new PHUIIconView())
- ->setIconFont('fa-angle-right');
+ ->setIcon('fa-angle-right');
$next_icon = phutil_tag(
'div',
array(
'class' => 'phame-next-arrow',
),
$n_icon);
$next_text = phutil_tag(
'div',
array(
'class' => 'phame-next-header',
),
pht('Next Post'));
$next_title = phutil_tag(
'div',
array(
'class' => 'phame-next-title',
),
$this->nextTitle);
$next = null;
if ($this->nextHref) {
$next = phutil_tag(
'a',
array(
'class' => 'phame-next',
'href' => $this->nextHref,
),
array(
$next_icon,
$next_text,
$next_title,
));
}
return array($previous, $next);
}
}
diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php
index e7245e3d02..e49094e311 100644
--- a/src/applications/phid/PhabricatorObjectHandle.php
+++ b/src/applications/phid/PhabricatorObjectHandle.php
@@ -1,367 +1,367 @@
<?php
final class PhabricatorObjectHandle
extends Phobject
implements PhabricatorPolicyInterface {
const AVAILABILITY_FULL = 'full';
const AVAILABILITY_NONE = 'none';
const AVAILABILITY_PARTIAL = 'partial';
const AVAILABILITY_DISABLED = 'disabled';
const STATUS_OPEN = 'open';
const STATUS_CLOSED = 'closed';
private $uri;
private $phid;
private $type;
private $name;
private $fullName;
private $title;
private $imageURI;
private $icon;
private $tagColor;
private $timestamp;
private $status = self::STATUS_OPEN;
private $availability = self::AVAILABILITY_FULL;
private $complete;
private $objectName;
private $policyFiltered;
private $subtitle;
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function getIcon() {
if ($this->getPolicyFiltered()) {
return 'fa-lock';
}
if ($this->icon) {
return $this->icon;
}
return $this->getTypeIcon();
}
public function setSubtitle($subtitle) {
$this->subtitle = $subtitle;
return $this;
}
public function getSubtitle() {
return $this->subtitle;
}
public function setTagColor($color) {
static $colors;
if (!$colors) {
$colors = array_fuse(array_keys(PHUITagView::getShadeMap()));
}
if (isset($colors[$color])) {
$this->tagColor = $color;
}
return $this;
}
public function getTagColor() {
if ($this->getPolicyFiltered()) {
return 'disabled';
}
if ($this->tagColor) {
return $this->tagColor;
}
return 'blue';
}
public function getIconColor() {
if ($this->tagColor) {
return $this->tagColor;
}
return null;
}
public function getTypeIcon() {
if ($this->getPHIDType()) {
return $this->getPHIDType()->getTypeIcon();
}
return null;
}
public function setPolicyFiltered($policy_filered) {
$this->policyFiltered = $policy_filered;
return $this;
}
public function getPolicyFiltered() {
return $this->policyFiltered;
}
public function setObjectName($object_name) {
$this->objectName = $object_name;
return $this;
}
public function getObjectName() {
if (!$this->objectName) {
return $this->getName();
}
return $this->objectName;
}
public function setURI($uri) {
$this->uri = $uri;
return $this;
}
public function getURI() {
return $this->uri;
}
public function setPHID($phid) {
$this->phid = $phid;
return $this;
}
public function getPHID() {
return $this->phid;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
if ($this->name === null) {
if ($this->getPolicyFiltered()) {
return pht('Restricted %s', $this->getTypeName());
} else {
return pht('Unknown Object (%s)', $this->getTypeName());
}
}
return $this->name;
}
public function setAvailability($availability) {
$this->availability = $availability;
return $this;
}
public function getAvailability() {
return $this->availability;
}
public function isDisabled() {
return ($this->getAvailability() == self::AVAILABILITY_DISABLED);
}
public function setStatus($status) {
$this->status = $status;
return $this;
}
public function getStatus() {
return $this->status;
}
public function setFullName($full_name) {
$this->fullName = $full_name;
return $this;
}
public function getFullName() {
if ($this->fullName !== null) {
return $this->fullName;
}
return $this->getName();
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function setType($type) {
$this->type = $type;
return $this;
}
public function getType() {
return $this->type;
}
public function setImageURI($uri) {
$this->imageURI = $uri;
return $this;
}
public function getImageURI() {
return $this->imageURI;
}
public function setTimestamp($timestamp) {
$this->timestamp = $timestamp;
return $this;
}
public function getTimestamp() {
return $this->timestamp;
}
public function getTypeName() {
if ($this->getPHIDType()) {
return $this->getPHIDType()->getTypeName();
}
return $this->getType();
}
/**
* Set whether or not the underlying object is complete. See
* @{method:isComplete} for an explanation of what it means to be complete.
*
* @param bool True if the handle represents a complete object.
* @return this
*/
public function setComplete($complete) {
$this->complete = $complete;
return $this;
}
/**
* Determine if the handle represents an object which was completely loaded
* (i.e., the underlying object exists) vs an object which could not be
* completely loaded (e.g., the type or data for the PHID could not be
* identified or located).
*
* Basically, @{class:PhabricatorHandleQuery} gives you back a handle for
* any PHID you give it, but it gives you a complete handle only for valid
* PHIDs.
*
* @return bool True if the handle represents a complete object.
*/
public function isComplete() {
return $this->complete;
}
public function renderLink($name = null) {
return $this->renderLinkWithAttributes($name, array());
}
public function renderHovercardLink($name = null) {
Javelin::initBehavior('phabricator-hovercards');
$attributes = array(
'sigil' => 'hovercard',
'meta' => array(
'hoverPHID' => $this->getPHID(),
),
);
return $this->renderLinkWithAttributes($name, $attributes);
}
private function renderLinkWithAttributes($name, array $attributes) {
if ($name === null) {
$name = $this->getLinkName();
}
$classes = array();
$classes[] = 'phui-handle';
$title = $this->title;
if ($this->status != self::STATUS_OPEN) {
$classes[] = 'handle-status-'.$this->status;
}
if ($this->availability != self::AVAILABILITY_FULL) {
$classes[] = 'handle-availability-'.$this->availability;
}
if ($this->getType() == PhabricatorPeopleUserPHIDType::TYPECONST) {
$classes[] = 'phui-link-person';
}
$uri = $this->getURI();
$icon = null;
if ($this->getPolicyFiltered()) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-lock lightgreytext');
+ ->setIcon('fa-lock lightgreytext');
}
$attributes = $attributes + array(
'href' => $uri,
'class' => implode(' ', $classes),
'title' => $title,
);
return javelin_tag(
$uri ? 'a' : 'span',
$attributes,
array($icon, $name));
}
public function renderTag() {
return id(new PHUITagView())
->setType(PHUITagView::TYPE_OBJECT)
->setShade($this->getTagColor())
->setIcon($this->getIcon())
->setHref($this->getURI())
->setName($this->getLinkName());
}
public function getLinkName() {
switch ($this->getType()) {
case PhabricatorPeopleUserPHIDType::TYPECONST:
$name = $this->getName();
break;
default:
$name = $this->getFullName();
break;
}
return $name;
}
protected function getPHIDType() {
$types = PhabricatorPHIDType::getAllTypes();
return idx($types, $this->getType());
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_PUBLIC;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
// NOTE: Handles are always visible, they just don't get populated with
// data if the user can't see the underlying object.
return true;
}
public function describeAutomaticCapability($capability) {
return null;
}
}
diff --git a/src/applications/pholio/view/PholioMockImagesView.php b/src/applications/pholio/view/PholioMockImagesView.php
index 8430ada3d4..d50dfb3b3a 100644
--- a/src/applications/pholio/view/PholioMockImagesView.php
+++ b/src/applications/pholio/view/PholioMockImagesView.php
@@ -1,228 +1,228 @@
<?php
final class PholioMockImagesView extends AphrontView {
private $mock;
private $imageID;
private $requestURI;
private $commentFormID;
private $panelID;
private $viewportID;
private $behaviorConfig;
public function setCommentFormID($comment_form_id) {
$this->commentFormID = $comment_form_id;
return $this;
}
public function getCommentFormID() {
return $this->commentFormID;
}
public function setRequestURI(PhutilURI $request_uri) {
$this->requestURI = $request_uri;
return $this;
}
public function getRequestURI() {
return $this->requestURI;
}
public function setImageID($image_id) {
$this->imageID = $image_id;
return $this;
}
public function getImageID() {
return $this->imageID;
}
public function setMock(PholioMock $mock) {
$this->mock = $mock;
return $this;
}
public function getMock() {
return $this->mock;
}
public function __construct() {
$this->panelID = celerity_generate_unique_node_id();
$this->viewportID = celerity_generate_unique_node_id();
}
public function getBehaviorConfig() {
if (!$this->getMock()) {
throw new PhutilInvalidStateException('setMock');
}
if ($this->behaviorConfig === null) {
$this->behaviorConfig = $this->calculateBehaviorConfig();
}
return $this->behaviorConfig;
}
private function calculateBehaviorConfig() {
$mock = $this->getMock();
// TODO: We could maybe do a better job with tailoring this, which is the
// image shown on the review stage.
$viewer = $this->getUser();
$default = PhabricatorFile::loadBuiltin($viewer, 'image-100x100.png');
$engine = id(new PhabricatorMarkupEngine())
->setViewer($this->getUser());
foreach ($mock->getAllImages() as $image) {
$engine->addObject($image, 'default');
}
$engine->process();
$images = array();
$current_set = 0;
foreach ($mock->getAllImages() as $image) {
$file = $image->getFile();
$metadata = $file->getMetadata();
$x = idx($metadata, PhabricatorFile::METADATA_IMAGE_WIDTH);
$y = idx($metadata, PhabricatorFile::METADATA_IMAGE_HEIGHT);
$is_obs = (bool)$image->getIsObsolete();
if (!$is_obs) {
$current_set++;
}
$history_uri = '/pholio/image/history/'.$image->getID().'/';
$images[] = array(
'id' => $image->getID(),
'fullURI' => $file->getBestURI(),
'stageURI' => ($file->isViewableImage()
? $file->getBestURI()
: $default->getBestURI()),
'pageURI' => $this->getImagePageURI($image, $mock),
'downloadURI' => $file->getDownloadURI(),
'historyURI' => $history_uri,
'width' => $x,
'height' => $y,
'title' => $image->getName(),
'descriptionMarkup' => $engine->getOutput($image, 'default'),
'isObsolete' => (bool)$image->getIsObsolete(),
'isImage' => $file->isViewableImage(),
'isViewable' => $file->isViewableInBrowser(),
);
}
$ids = mpull($mock->getImages(), 'getID');
if ($this->imageID && isset($ids[$this->imageID])) {
$selected_id = $this->imageID;
} else {
$selected_id = head_key($ids);
}
$navsequence = array();
foreach ($mock->getImages() as $image) {
$navsequence[] = $image->getID();
}
$full_icon = array(
javelin_tag('span', array('aural' => true), pht('View Raw File')),
- id(new PHUIIconView())->setIconFont('fa-file-image-o'),
+ id(new PHUIIconView())->setIcon('fa-file-image-o'),
);
$download_icon = array(
javelin_tag('span', array('aural' => true), pht('Download File')),
- id(new PHUIIconView())->setIconFont('fa-download'),
+ id(new PHUIIconView())->setIcon('fa-download'),
);
$login_uri = id(new PhutilURI('/login/'))
->setQueryParam('next', (string)$this->getRequestURI());
$config = array(
'mockID' => $mock->getID(),
'panelID' => $this->panelID,
'viewportID' => $this->viewportID,
'commentFormID' => $this->getCommentFormID(),
'images' => $images,
'selectedID' => $selected_id,
'loggedIn' => $this->getUser()->isLoggedIn(),
'logInLink' => (string)$login_uri,
'navsequence' => $navsequence,
'fullIcon' => hsprintf('%s', $full_icon),
'downloadIcon' => hsprintf('%s', $download_icon),
'currentSetSize' => $current_set,
);
return $config;
}
public function render() {
if (!$this->getMock()) {
throw new PhutilInvalidStateException('setMock');
}
$mock = $this->getMock();
require_celerity_resource('javelin-behavior-pholio-mock-view');
$panel_id = $this->panelID;
$viewport_id = $this->viewportID;
$config = $this->getBehaviorConfig();
Javelin::initBehavior(
'pholio-mock-view',
$this->getBehaviorConfig());
$mockview = '';
$mock_wrapper = javelin_tag(
'div',
array(
'id' => $this->viewportID,
'sigil' => 'mock-viewport',
'class' => 'pholio-mock-image-viewport',
),
'');
$image_header = javelin_tag(
'div',
array(
'id' => 'mock-image-header',
'class' => 'pholio-mock-image-header',
),
'');
$mock_wrapper = javelin_tag(
'div',
array(
'id' => $this->panelID,
'sigil' => 'mock-panel touchable',
'class' => 'pholio-mock-image-panel',
),
array(
$image_header,
$mock_wrapper,
));
$inline_comments_holder = javelin_tag(
'div',
array(
'id' => 'mock-image-description',
'sigil' => 'mock-image-description',
'class' => 'mock-image-description',
),
'');
$mockview[] = phutil_tag(
'div',
array(
'class' => 'pholio-mock-image-container',
'id' => 'pholio-mock-image-container',
),
array($mock_wrapper, $inline_comments_holder));
return $mockview;
}
private function getImagePageURI(PholioImage $image, PholioMock $mock) {
$uri = '/M'.$mock->getID().'/'.$image->getID().'/';
return $uri;
}
}
diff --git a/src/applications/pholio/view/PholioTransactionView.php b/src/applications/pholio/view/PholioTransactionView.php
index 7fad6bff9a..92624feec6 100644
--- a/src/applications/pholio/view/PholioTransactionView.php
+++ b/src/applications/pholio/view/PholioTransactionView.php
@@ -1,140 +1,140 @@
<?php
final class PholioTransactionView
extends PhabricatorApplicationTransactionView {
private $mock;
public function setMock($mock) {
$this->mock = $mock;
return $this;
}
public function getMock() {
return $this->mock;
}
protected function shouldGroupTransactions(
PhabricatorApplicationTransaction $u,
PhabricatorApplicationTransaction $v) {
if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
// Don't group transactions by different authors.
return false;
}
if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
// Don't group if transactions happened more than 60s apart.
return false;
}
switch ($u->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
case PholioTransaction::TYPE_INLINE:
break;
default:
return false;
}
switch ($v->getTransactionType()) {
case PholioTransaction::TYPE_INLINE:
return true;
}
return parent::shouldGroupTransactions($u, $v);
}
protected function renderTransactionContent(
PhabricatorApplicationTransaction $xaction) {
$out = array();
$group = $xaction->getTransactionGroup();
if ($xaction->getTransactionType() == PholioTransaction::TYPE_INLINE) {
array_unshift($group, $xaction);
} else {
$out[] = parent::renderTransactionContent($xaction);
}
if (!$group) {
return $out;
}
$inlines = array();
foreach ($group as $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransaction::TYPE_INLINE:
$inlines[] = $xaction;
break;
default:
throw new Exception(pht('Unknown grouped transaction type!'));
}
}
if ($inlines) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-comment bluegrey msr');
+ ->setIcon('fa-comment bluegrey msr');
$header = phutil_tag(
'div',
array(
'class' => 'phabricator-transaction-subheader',
),
array($icon, pht('Inline Comments')));
$out[] = $header;
foreach ($inlines as $inline) {
if (!$inline->getComment()) {
continue;
}
$out[] = $this->renderInlineContent($inline);
}
}
return $out;
}
private function renderInlineContent(PholioTransaction $inline) {
$comment = $inline->getComment();
$mock = $this->getMock();
$images = $mock->getAllImages();
$images = mpull($images, null, 'getID');
$image = idx($images, $comment->getImageID());
if (!$image) {
throw new Exception(pht('No image attached!'));
}
$file = $image->getFile();
if (!$file->isViewableImage()) {
throw new Exception(pht('File is not viewable.'));
}
$image_uri = $file->getBestURI();
$thumb = id(new PHUIImageMaskView())
->addClass('mrl')
->setImage($image_uri)
->setDisplayHeight(100)
->setDisplayWidth(200)
->withMask(true)
->centerViewOnPoint(
$comment->getX(), $comment->getY(),
$comment->getHeight(), $comment->getWidth());
$link = phutil_tag(
'a',
array(
'href' => '#',
'class' => 'pholio-transaction-inline-image-anchor',
),
$thumb);
$inline_comment = parent::renderTransactionContent($inline);
return phutil_tag(
'div',
array('class' => 'pholio-transaction-inline-comment'),
array($link, $inline_comment));
}
}
diff --git a/src/applications/phortune/controller/PhortuneAccountListController.php b/src/applications/phortune/controller/PhortuneAccountListController.php
index 0de082fa01..9b095186cc 100644
--- a/src/applications/phortune/controller/PhortuneAccountListController.php
+++ b/src/applications/phortune/controller/PhortuneAccountListController.php
@@ -1,103 +1,99 @@
<?php
final class PhortuneAccountListController extends PhortuneController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$accounts = id(new PhortuneAccountQuery())
->setViewer($viewer)
->withMemberPHIDs(array($viewer->getPHID()))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->execute();
$merchants = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withMemberPHIDs(array($viewer->getPHID()))
->execute();
$title = pht('Accounts');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Accounts'));
$payment_list = id(new PHUIObjectItemListView())
->setUser($viewer)
->setNoDataString(
pht(
'You are not a member of any payment accounts. Payment '.
'accounts are used to make purchases.'));
foreach ($accounts as $account) {
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Account %d', $account->getID()))
->setHeader($account->getName())
->setHref($this->getApplicationURI($account->getID().'/'))
->setObject($account);
$payment_list->addItem($item);
}
$payment_header = id(new PHUIHeaderView())
->setHeader(pht('Payment Accounts'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($this->getApplicationURI('account/edit/'))
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-plus'))
+ ->setIcon('fa-plus')
->setText(pht('Create Account')));
$payment_box = id(new PHUIObjectBoxView())
->setHeader($payment_header)
->setObjectList($payment_list);
$merchant_list = id(new PHUIObjectItemListView())
->setUser($viewer)
->setNoDataString(
pht(
'You do not control any merchant accounts. Merchant accounts are '.
'used to receive payments.'));
foreach ($merchants as $merchant) {
$item = id(new PHUIObjectItemView())
->setObjectName(pht('Merchant %d', $merchant->getID()))
->setHeader($merchant->getName())
->setHref($this->getApplicationURI('/merchant/'.$merchant->getID().'/'))
->setObject($merchant);
$merchant_list->addItem($item);
}
$merchant_header = id(new PHUIHeaderView())
->setHeader(pht('Merchant Accounts'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($this->getApplicationURI('merchant/'))
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-list'))
+ ->setIcon('fa-list')
->setText(pht('View All Merchants')));
$merchant_box = id(new PHUIObjectBoxView())
->setHeader($merchant_header)
->setObjectList($merchant_list);
return $this->buildApplicationPage(
array(
$crumbs,
$payment_box,
$merchant_box,
),
array(
'title' => $title,
));
}
}
diff --git a/src/applications/phortune/controller/PhortuneAccountViewController.php b/src/applications/phortune/controller/PhortuneAccountViewController.php
index b5387b935e..001db3bebc 100644
--- a/src/applications/phortune/controller/PhortuneAccountViewController.php
+++ b/src/applications/phortune/controller/PhortuneAccountViewController.php
@@ -1,390 +1,386 @@
<?php
final class PhortuneAccountViewController extends PhortuneController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
// TODO: Currently, you must be able to edit an account to view the detail
// page, because the account must be broadly visible so merchants can
// process orders but merchants should not be able to see all the details
// of an account. Ideally this page should be visible to merchants, too,
// just with less information.
$can_edit = true;
$account = id(new PhortuneAccountQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('accountID')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$account) {
return new Aphront404Response();
}
$title = $account->getName();
$invoices = id(new PhortuneCartQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->needPurchases(true)
->withInvoices(true)
->execute();
$crumbs = $this->buildApplicationCrumbs();
$this->addAccountCrumb($crumbs, $account, $link = false);
$header = id(new PHUIHeaderView())
->setHeader($title);
$edit_uri = $this->getApplicationURI('account/edit/'.$account->getID().'/');
$actions = id(new PhabricatorActionListView())
->setUser($viewer)
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Account'))
->setIcon('fa-pencil')
->setHref($edit_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$properties = id(new PHUIPropertyListView())
->setObject($account)
->setUser($viewer);
$properties->addProperty(
pht('Members'),
$viewer->renderHandleList($account->getMemberPHIDs()));
$status_items = $this->getStatusItemsForAccount($account, $invoices);
$status_view = new PHUIStatusListView();
foreach ($status_items as $item) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(
idx($item, 'icon'),
idx($item, 'color'),
idx($item, 'label'))
->setTarget(idx($item, 'target'))
->setNote(idx($item, 'note')));
}
$properties->addProperty(
pht('Status'),
$status_view);
$properties->setActionList($actions);
$invoices = $this->buildInvoicesSection($account, $invoices);
$purchase_history = $this->buildPurchaseHistorySection($account);
$charge_history = $this->buildChargeHistorySection($account);
$subscriptions = $this->buildSubscriptionsSection($account);
$payment_methods = $this->buildPaymentMethodsSection($account);
$timeline = $this->buildTransactionTimeline(
$account,
new PhortuneAccountTransactionQuery());
$timeline->setShouldTerminate(true);
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
$invoices,
$purchase_history,
$charge_history,
$subscriptions,
$payment_methods,
$timeline,
),
array(
'title' => $title,
));
}
private function buildPaymentMethodsSection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$account,
PhabricatorPolicyCapability::CAN_EDIT);
$id = $account->getID();
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Methods'));
$list = id(new PHUIObjectItemListView())
->setUser($viewer)
->setFlush(true)
->setNoDataString(
pht('No payment methods associated with this account.'));
$methods = id(new PhortunePaymentMethodQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->withStatuses(
array(
PhortunePaymentMethod::STATUS_ACTIVE,
))
->execute();
foreach ($methods as $method) {
$id = $method->getID();
$item = new PHUIObjectItemView();
$item->setHeader($method->getFullDisplayName());
switch ($method->getStatus()) {
case PhortunePaymentMethod::STATUS_ACTIVE:
$item->setStatusIcon('fa-check green');
$disable_uri = $this->getApplicationURI('card/'.$id.'/disable/');
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setHref($disable_uri)
->setDisabled(!$can_edit)
->setWorkflow(true));
break;
case PhortunePaymentMethod::STATUS_DISABLED:
$item->setStatusIcon('fa-ban lightbluetext');
$item->setDisabled(true);
break;
}
$provider = $method->buildPaymentProvider();
$item->addAttribute($provider->getPaymentMethodProviderDescription());
$edit_uri = $this->getApplicationURI('card/'.$id.'/edit/');
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-pencil')
->setHref($edit_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$list->addItem($item);
}
return id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($list);
}
private function buildInvoicesSection(
PhortuneAccount $account,
array $carts) {
$request = $this->getRequest();
$viewer = $request->getUser();
$phids = array();
foreach ($carts as $cart) {
$phids[] = $cart->getPHID();
$phids[] = $cart->getMerchantPHID();
foreach ($cart->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$table = id(new PhortuneOrderTableView())
->setNoDataString(pht('You have no unpaid invoices.'))
->setIsInvoices(true)
->setUser($viewer)
->setCarts($carts)
->setHandles($handles);
$header = id(new PHUIHeaderView())
->setHeader(pht('Invoices Due'));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
private function buildPurchaseHistorySection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$carts = id(new PhortuneCartQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->needPurchases(true)
->withStatuses(
array(
PhortuneCart::STATUS_PURCHASING,
PhortuneCart::STATUS_CHARGED,
PhortuneCart::STATUS_HOLD,
PhortuneCart::STATUS_REVIEW,
PhortuneCart::STATUS_PURCHASED,
))
->setLimit(10)
->execute();
$phids = array();
foreach ($carts as $cart) {
$phids[] = $cart->getPHID();
foreach ($cart->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$orders_uri = $this->getApplicationURI($account->getID().'/order/');
$table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($carts)
->setHandles($handles);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Orders'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-list'))
+ ->setIcon('fa-list')
->setHref($orders_uri)
->setText(pht('View All Orders')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
private function buildChargeHistorySection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$charges = id(new PhortuneChargeQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->needCarts(true)
->setLimit(10)
->execute();
$phids = array();
foreach ($charges as $charge) {
$phids[] = $charge->getProviderPHID();
$phids[] = $charge->getCartPHID();
$phids[] = $charge->getMerchantPHID();
$phids[] = $charge->getPaymentMethodPHID();
}
$handles = $this->loadViewerHandles($phids);
$charges_uri = $this->getApplicationURI($account->getID().'/charge/');
$table = id(new PhortuneChargeTableView())
->setUser($viewer)
->setCharges($charges)
->setHandles($handles);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Charges'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-list'))
+ ->setIcon('fa-list')
->setHref($charges_uri)
->setText(pht('View All Charges')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
private function buildSubscriptionsSection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$subscriptions = id(new PhortuneSubscriptionQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->setLimit(10)
->execute();
$subscriptions_uri = $this->getApplicationURI(
$account->getID().'/subscription/');
$handles = $this->loadViewerHandles(mpull($subscriptions, 'getPHID'));
$table = id(new PhortuneSubscriptionTableView())
->setUser($viewer)
->setHandles($handles)
->setSubscriptions($subscriptions);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Subscriptions'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon(
id(new PHUIIconView())
- ->setIconFont('fa-list'))
+ ->setIcon('fa-list'))
->setHref($subscriptions_uri)
->setText(pht('View All Subscriptions')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PHUIListItemView())
->setIcon('fa-exchange')
->setHref($this->getApplicationURI('account/'))
->setName(pht('Switch Accounts')));
return $crumbs;
}
private function getStatusItemsForAccount(
PhortuneAccount $account,
array $invoices) {
assert_instances_of($invoices, 'PhortuneCart');
$items = array();
if ($invoices) {
$items[] = array(
'icon' => PHUIStatusItemView::ICON_WARNING,
'color' => 'yellow',
'target' => pht('Invoices'),
'note' => pht('You have %d unpaid invoice(s).', count($invoices)),
);
} else {
$items[] = array(
'icon' => PHUIStatusItemView::ICON_ACCEPT,
'color' => 'green',
'target' => pht('Invoices'),
'note' => pht('This account has no unpaid invoices.'),
);
}
// TODO: If a payment method has expired or is expiring soon, we should
// add a status check for it.
return $items;
}
}
diff --git a/src/applications/phortune/controller/PhortuneCartViewController.php b/src/applications/phortune/controller/PhortuneCartViewController.php
index 67f7c3df01..3beaa657c6 100644
--- a/src/applications/phortune/controller/PhortuneCartViewController.php
+++ b/src/applications/phortune/controller/PhortuneCartViewController.php
@@ -1,323 +1,322 @@
<?php
final class PhortuneCartViewController
extends PhortuneCartController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$authority = $this->loadMerchantAuthority();
$query = id(new PhortuneCartQuery())
->setViewer($viewer)
->withIDs(array($id))
->needPurchases(true);
if ($authority) {
$query->withMerchantPHIDs(array($authority->getPHID()));
}
$cart = $query->executeOne();
if (!$cart) {
return new Aphront404Response();
}
$cart_table = $this->buildCartContentTable($cart);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$cart,
PhabricatorPolicyCapability::CAN_EDIT);
$errors = array();
$error_view = null;
$resume_uri = null;
switch ($cart->getStatus()) {
case PhortuneCart::STATUS_READY:
if ($authority && $cart->getIsInvoice()) {
// We arrived here by following the ad-hoc invoice workflow, and
// are acting with merchant authority.
$checkout_uri = PhabricatorEnv::getURI($cart->getCheckoutURI());
$invoice_message = array(
pht(
'Manual invoices do not automatically notify recipients yet. '.
'Send the payer this checkout link:'),
' ',
phutil_tag(
'a',
array(
'href' => $checkout_uri,
),
$checkout_uri),
);
$error_view = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(array($invoice_message));
}
break;
case PhortuneCart::STATUS_PURCHASING:
if ($can_edit) {
$resume_uri = $cart->getMetadataValue('provider.checkoutURI');
if ($resume_uri) {
$errors[] = pht(
'The checkout process has been started, but not yet completed. '.
'You can continue checking out by clicking %s, or cancel the '.
'order, or contact the merchant for assistance.',
phutil_tag('strong', array(), pht('Continue Checkout')));
} else {
$errors[] = pht(
'The checkout process has been started, but an error occurred. '.
'You can cancel the order or contact the merchant for '.
'assistance.');
}
}
break;
case PhortuneCart::STATUS_CHARGED:
if ($can_edit) {
$errors[] = pht(
'You have been charged, but processing could not be completed. '.
'You can cancel your order, or contact the merchant for '.
'assistance.');
}
break;
case PhortuneCart::STATUS_HOLD:
if ($can_edit) {
$errors[] = pht(
'Payment for this order is on hold. You can click %s to check '.
'for updates, cancel the order, or contact the merchant for '.
'assistance.',
phutil_tag('strong', array(), pht('Update Status')));
}
break;
case PhortuneCart::STATUS_REVIEW:
if ($authority) {
$errors[] = pht(
'This order has been flagged for manual review. Review the order '.
'and choose %s to accept it or %s to reject it.',
phutil_tag('strong', array(), pht('Accept Order')),
phutil_tag('strong', array(), pht('Refund Order')));
} else if ($can_edit) {
$errors[] = pht(
'This order requires manual processing and will complete once '.
'the merchant accepts it.');
}
break;
case PhortuneCart::STATUS_PURCHASED:
$error_view = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild(pht('This purchase has been completed.'));
break;
}
$properties = $this->buildPropertyListView($cart);
$actions = $this->buildActionListView(
$cart,
$can_edit,
$authority,
$resume_uri);
$properties->setActionList($actions);
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader(pht('Order Detail'));
if ($cart->getStatus() == PhortuneCart::STATUS_PURCHASED) {
$done_uri = $cart->getDoneURI();
if ($done_uri) {
$header->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref($done_uri)
- ->setIcon(id(new PHUIIconView())
- ->setIconFont('fa-check-square green'))
+ ->setIcon('fa-check-square green')
->setText($cart->getDoneActionName()));
}
}
$cart_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties)
->setTable($cart_table);
if ($errors) {
$cart_box->setFormErrors($errors);
} else if ($error_view) {
$cart_box->setInfoView($error_view);
}
$description = $this->renderCartDescription($cart);
$charges = id(new PhortuneChargeQuery())
->setViewer($viewer)
->withCartPHIDs(array($cart->getPHID()))
->needCarts(true)
->execute();
$phids = array();
foreach ($charges as $charge) {
$phids[] = $charge->getProviderPHID();
$phids[] = $charge->getCartPHID();
$phids[] = $charge->getMerchantPHID();
$phids[] = $charge->getPaymentMethodPHID();
}
$handles = $this->loadViewerHandles($phids);
$charges_table = id(new PhortuneChargeTableView())
->setUser($viewer)
->setHandles($handles)
->setCharges($charges)
->setShowOrder(false);
$charges = id(new PHUIObjectBoxView())
->setHeaderText(pht('Charges'))
->setTable($charges_table);
$account = $cart->getAccount();
$crumbs = $this->buildApplicationCrumbs();
if ($authority) {
$this->addMerchantCrumb($crumbs, $authority);
} else {
$this->addAccountCrumb($crumbs, $cart->getAccount());
}
$crumbs->addTextCrumb(pht('Cart %d', $cart->getID()));
$timeline = $this->buildTransactionTimeline(
$cart,
new PhortuneCartTransactionQuery());
$timeline
->setShouldTerminate(true);
return $this->buildApplicationPage(
array(
$crumbs,
$cart_box,
$description,
$charges,
$timeline,
),
array(
'title' => pht('Cart'),
));
}
private function buildPropertyListView(PhortuneCart $cart) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($cart);
$handles = $this->loadViewerHandles(
array(
$cart->getAccountPHID(),
$cart->getAuthorPHID(),
$cart->getMerchantPHID(),
));
$view->addProperty(
pht('Order Name'),
$cart->getName());
$view->addProperty(
pht('Account'),
$handles[$cart->getAccountPHID()]->renderLink());
$view->addProperty(
pht('Authorized By'),
$handles[$cart->getAuthorPHID()]->renderLink());
$view->addProperty(
pht('Merchant'),
$handles[$cart->getMerchantPHID()]->renderLink());
$view->addProperty(
pht('Status'),
PhortuneCart::getNameForStatus($cart->getStatus()));
$view->addProperty(
pht('Updated'),
phabricator_datetime($cart->getDateModified(), $viewer));
return $view;
}
private function buildActionListView(
PhortuneCart $cart,
$can_edit,
$authority,
$resume_uri) {
$viewer = $this->getRequest()->getUser();
$id = $cart->getID();
$view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($cart);
$can_cancel = ($can_edit && $cart->canCancelOrder());
if ($authority) {
$prefix = 'merchant/'.$authority->getID().'/';
} else {
$prefix = '';
}
$cancel_uri = $this->getApplicationURI("{$prefix}cart/{$id}/cancel/");
$refund_uri = $this->getApplicationURI("{$prefix}cart/{$id}/refund/");
$update_uri = $this->getApplicationURI("{$prefix}cart/{$id}/update/");
$accept_uri = $this->getApplicationURI("{$prefix}cart/{$id}/accept/");
$print_uri = $this->getApplicationURI("{$prefix}cart/{$id}/?__print__=1");
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Cancel Order'))
->setIcon('fa-times')
->setDisabled(!$can_cancel)
->setWorkflow(true)
->setHref($cancel_uri));
if ($authority) {
if ($cart->getStatus() == PhortuneCart::STATUS_REVIEW) {
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Accept Order'))
->setIcon('fa-check')
->setWorkflow(true)
->setHref($accept_uri));
}
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Refund Order'))
->setIcon('fa-reply')
->setWorkflow(true)
->setHref($refund_uri));
}
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Update Status'))
->setIcon('fa-refresh')
->setHref($update_uri));
if ($can_edit && $resume_uri) {
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Continue Checkout'))
->setIcon('fa-shopping-cart')
->setHref($resume_uri));
}
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Printable Version'))
->setHref($print_uri)
->setOpenInNewWindow(true)
->setIcon('fa-print'));
return $view;
}
}
diff --git a/src/applications/phortune/controller/PhortuneMerchantViewController.php b/src/applications/phortune/controller/PhortuneMerchantViewController.php
index 4bedbd9e9c..55bb136dab 100644
--- a/src/applications/phortune/controller/PhortuneMerchantViewController.php
+++ b/src/applications/phortune/controller/PhortuneMerchantViewController.php
@@ -1,294 +1,294 @@
<?php
final class PhortuneMerchantViewController
extends PhortuneMerchantController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$merchant) {
return new Aphront404Response();
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($merchant->getName());
$title = pht(
'Merchant %d %s',
$merchant->getID(),
$merchant->getName());
$header = id(new PHUIHeaderView())
->setHeader($merchant->getName())
->setUser($viewer)
->setPolicyObject($merchant);
$providers = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->execute();
$properties = $this->buildPropertyListView($merchant, $providers);
$actions = $this->buildActionListView($merchant);
$properties->setActionList($actions);
$provider_list = $this->buildProviderList(
$merchant,
$providers);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
$timeline = $this->buildTransactionTimeline(
$merchant,
new PhortuneMerchantTransactionQuery());
$timeline->setShouldTerminate(true);
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$provider_list,
$timeline,
),
array(
'title' => $title,
));
}
private function buildPropertyListView(
PhortuneMerchant $merchant,
array $providers) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($merchant);
$status_view = new PHUIStatusListView();
$have_any = false;
$any_test = false;
foreach ($providers as $provider_config) {
$provider = $provider_config->buildProvider();
if ($provider->isEnabled()) {
$have_any = true;
}
if (!$provider->isAcceptingLivePayments()) {
$any_test = true;
}
}
if ($have_any) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')
->setTarget(pht('Accepts Payments'))
->setNote(pht('This merchant can accept payments.')));
if ($any_test) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow')
->setTarget(pht('Test Mode'))
->setNote(pht('This merchant is accepting test payments.')));
} else {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_ACCEPT, 'green')
->setTarget(pht('Live Mode'))
->setNote(pht('This merchant is accepting live payments.')));
}
} else if ($providers) {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_REJECT, 'red')
->setTarget(pht('No Enabled Providers'))
->setNote(
pht(
'All of the payment providers for this merchant are '.
'disabled.')));
} else {
$status_view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'yellow')
->setTarget(pht('No Providers'))
->setNote(
pht(
'This merchant does not have any payment providers configured '.
'yet, so it can not accept payments. Add a provider.')));
}
$view->addProperty(pht('Status'), $status_view);
$view->addProperty(
pht('Members'),
$viewer->renderHandleList($merchant->getMemberPHIDs()));
$view->invokeWillRenderEvent();
$description = $merchant->getDescription();
if (strlen($description)) {
$description = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($description),
'default',
$viewer);
$view->addSectionHeader(
pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description);
}
return $view;
}
private function buildActionListView(PhortuneMerchant $merchant) {
$viewer = $this->getRequest()->getUser();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($merchant);
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Merchant'))
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($this->getApplicationURI("merchant/edit/{$id}/")));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('View Orders'))
->setIcon('fa-shopping-cart')
->setHref($this->getApplicationURI("merchant/orders/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('View Subscriptions'))
->setIcon('fa-moon-o')
->setHref($this->getApplicationURI("merchant/{$id}/subscription/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$view->addAction(
id(new PhabricatorActionView())
->setName(pht('New Invoice'))
->setIcon('fa-fax')
->setHref($this->getApplicationURI("merchant/{$id}/invoice/new/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
return $view;
}
private function buildProviderList(
PhortuneMerchant $merchant,
array $providers) {
$viewer = $this->getRequest()->getUser();
$id = $merchant->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$merchant,
PhabricatorPolicyCapability::CAN_EDIT);
$provider_list = id(new PHUIObjectItemListView())
->setFlush(true)
->setNoDataString(pht('This merchant has no payment providers.'));
foreach ($providers as $provider_config) {
$provider = $provider_config->buildProvider();
$provider_id = $provider_config->getID();
$item = id(new PHUIObjectItemView())
->setHeader($provider->getName());
if ($provider->isEnabled()) {
if ($provider->isAcceptingLivePayments()) {
$item->setStatusIcon('fa-check green');
} else {
$item->setStatusIcon('fa-warning yellow');
$item->addIcon('fa-exclamation-triangle', pht('Test Mode'));
}
$item->addAttribute($provider->getConfigureProvidesDescription());
} else {
// Don't show disabled providers to users who can't manage the merchant
// account.
if (!$can_edit) {
continue;
}
$item->setDisabled(true);
$item->addAttribute(
phutil_tag('em', array(), pht('This payment provider is disabled.')));
}
if ($can_edit) {
$edit_uri = $this->getApplicationURI(
"/provider/edit/{$provider_id}/");
$disable_uri = $this->getApplicationURI(
"/provider/disable/{$provider_id}/");
if ($provider->isEnabled()) {
$disable_icon = 'fa-times';
$disable_name = pht('Disable');
} else {
$disable_icon = 'fa-check';
$disable_name = pht('Enable');
}
$item->addAction(
id(new PHUIListItemView())
->setIcon($disable_icon)
->setHref($disable_uri)
->setName($disable_name)
->setWorkflow(true));
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-pencil')
->setHref($edit_uri)
->setName(pht('Edit')));
}
$provider_list->addItem($item);
}
$add_action = id(new PHUIButtonView())
->setTag('a')
->setHref($this->getApplicationURI('provider/edit/?merchantID='.$id))
->setText(pht('Add Payment Provider'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
- ->setIcon(id(new PHUIIconView())->setIconFont('fa-plus'));
+ ->setIcon('fa-plus');
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Providers'))
->addActionLink($add_action);
return id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($provider_list);
}
}
diff --git a/src/applications/phortune/controller/PhortuneSubscriptionViewController.php b/src/applications/phortune/controller/PhortuneSubscriptionViewController.php
index 8804499056..8ecc97c301 100644
--- a/src/applications/phortune/controller/PhortuneSubscriptionViewController.php
+++ b/src/applications/phortune/controller/PhortuneSubscriptionViewController.php
@@ -1,207 +1,205 @@
<?php
final class PhortuneSubscriptionViewController extends PhortuneController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$authority = $this->loadMerchantAuthority();
$subscription_query = id(new PhortuneSubscriptionQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->needTriggers(true);
if ($authority) {
$subscription_query->withMerchantPHIDs(array($authority->getPHID()));
}
$subscription = $subscription_query->executeOne();
if (!$subscription) {
return new Aphront404Response();
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$subscription,
PhabricatorPolicyCapability::CAN_EDIT);
$merchant = $subscription->getMerchant();
$account = $subscription->getAccount();
$account_id = $account->getID();
$subscription_id = $subscription->getID();
$title = $subscription->getSubscriptionFullName();
$header = id(new PHUIHeaderView())
->setHeader($title);
$actions = id(new PhabricatorActionListView())
->setUser($viewer);
$edit_uri = $subscription->getEditURI();
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Subscription'))
->setHref($edit_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$crumbs = $this->buildApplicationCrumbs();
if ($authority) {
$this->addMerchantCrumb($crumbs, $merchant);
} else {
$this->addAccountCrumb($crumbs, $account);
}
$crumbs->addTextCrumb($subscription->getSubscriptionCrumbName());
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setActionList($actions);
$next_invoice = $subscription->getTrigger()->getNextEventPrediction();
$properties->addProperty(
pht('Next Invoice'),
phabricator_datetime($next_invoice, $viewer));
$default_method = $subscription->getDefaultPaymentMethodPHID();
if ($default_method) {
$handles = $this->loadViewerHandles(array($default_method));
$autopay_method = $handles[$default_method]->renderLink();
} else {
$autopay_method = phutil_tag(
'em',
array(),
pht('No Autopay Method Configured'));
}
$properties->addProperty(
pht('Autopay With'),
$autopay_method);
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
$due_box = $this->buildDueInvoices($subscription, $authority);
$invoice_box = $this->buildPastInvoices($subscription, $authority);
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
$due_box,
$invoice_box,
),
array(
'title' => $title,
));
}
private function buildDueInvoices(
PhortuneSubscription $subscription,
$authority) {
$viewer = $this->getViewer();
$invoices = id(new PhortuneCartQuery())
->setViewer($viewer)
->withSubscriptionPHIDs(array($subscription->getPHID()))
->needPurchases(true)
->withInvoices(true)
->execute();
$phids = array();
foreach ($invoices as $invoice) {
$phids[] = $invoice->getPHID();
$phids[] = $invoice->getMerchantPHID();
foreach ($invoice->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$invoice_table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($invoices)
->setIsInvoices(true)
->setIsMerchantView((bool)$authority)
->setHandles($handles);
$invoice_header = id(new PHUIHeaderView())
->setHeader(pht('Invoices Due'));
return id(new PHUIObjectBoxView())
->setHeader($invoice_header)
->appendChild($invoice_table);
}
private function buildPastInvoices(
PhortuneSubscription $subscription,
$authority) {
$viewer = $this->getViewer();
$invoices = id(new PhortuneCartQuery())
->setViewer($viewer)
->withSubscriptionPHIDs(array($subscription->getPHID()))
->needPurchases(true)
->withStatuses(
array(
PhortuneCart::STATUS_PURCHASING,
PhortuneCart::STATUS_CHARGED,
PhortuneCart::STATUS_HOLD,
PhortuneCart::STATUS_REVIEW,
PhortuneCart::STATUS_PURCHASED,
))
->setLimit(50)
->execute();
$phids = array();
foreach ($invoices as $invoice) {
$phids[] = $invoice->getPHID();
foreach ($invoice->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$invoice_table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($invoices)
->setHandles($handles);
$account = $subscription->getAccount();
$merchant = $subscription->getMerchant();
$account_id = $account->getID();
$merchant_id = $merchant->getID();
$subscription_id = $subscription->getID();
if ($authority) {
$invoices_uri = $this->getApplicationURI(
"merchant/{$merchant_id}/subscription/order/{$subscription_id}/");
} else {
$invoices_uri = $this->getApplicationURI(
"{$account_id}/subscription/order/{$subscription_id}/");
}
$invoice_header = id(new PHUIHeaderView())
->setHeader(pht('Past Invoices'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-list'))
+ ->setIcon('fa-list')
->setHref($invoices_uri)
->setText(pht('View All Invoices')));
return id(new PHUIObjectBoxView())
->setHeader($invoice_header)
->appendChild($invoice_table);
}
}
diff --git a/src/applications/phortune/view/PhortuneCreditCardForm.php b/src/applications/phortune/view/PhortuneCreditCardForm.php
index 6e4e2af38b..afd64075ea 100644
--- a/src/applications/phortune/view/PhortuneCreditCardForm.php
+++ b/src/applications/phortune/view/PhortuneCreditCardForm.php
@@ -1,122 +1,122 @@
<?php
final class PhortuneCreditCardForm extends Phobject {
private $formID;
private $scripts = array();
private $user;
private $errors = array();
private $cardNumberError;
private $cardCVCError;
private $cardExpirationError;
private $securityAssurance;
public function setSecurityAssurance($security_assurance) {
$this->securityAssurance = $security_assurance;
return $this;
}
public function getSecurityAssurance() {
return $this->securityAssurance;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
public function setErrors(array $errors) {
$this->errors = $errors;
return $this;
}
public function addScript($script_uri) {
$this->scripts[] = $script_uri;
return $this;
}
public function getFormID() {
if (!$this->formID) {
$this->formID = celerity_generate_unique_node_id();
}
return $this->formID;
}
public function buildForm() {
$form_id = $this->getFormID();
require_celerity_resource('phortune-credit-card-form-css');
require_celerity_resource('phortune-credit-card-form');
require_celerity_resource('aphront-tooltip-css');
Javelin::initBehavior('phabricator-tooltips');
$form = new AphrontFormView();
foreach ($this->scripts as $script) {
$form->appendChild(
phutil_tag(
'script',
array(
'type' => 'text/javascript',
'src' => $script,
)));
}
$errors = $this->errors;
$e_number = isset($errors[PhortuneErrCode::ERR_CC_INVALID_NUMBER])
? pht('Invalid')
: null;
$e_cvc = isset($errors[PhortuneErrCode::ERR_CC_INVALID_CVC])
? pht('Invalid')
: null;
$e_expiry = isset($errors[PhortuneErrCode::ERR_CC_INVALID_EXPIRY])
? pht('Invalid')
: null;
$form
->setID($form_id)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Card Number'))
->setDisableAutocomplete(true)
->setSigil('number-input')
->setError($e_number))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('CVC'))
->setDisableAutocomplete(true)
->addClass('aphront-form-cvc-input')
->setSigil('cvc-input')
->setError($e_cvc))
->appendChild(
id(new PhortuneMonthYearExpiryControl())
->setLabel(pht('Expiration'))
->setUser($this->user)
->setError($e_expiry));
$assurance = $this->getSecurityAssurance();
if ($assurance) {
$assurance = phutil_tag(
'div',
array(
'class' => 'phortune-security-assurance',
),
array(
id(new PHUIIconView())
- ->setIconFont('fa-lock grey'),
+ ->setIcon('fa-lock grey'),
' ',
$assurance,
));
$form->appendChild(
id(new AphrontFormMarkupControl())
->setValue($assurance));
}
return $form;
}
}
diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php
index d7db7f6548..7d98e9ed3b 100644
--- a/src/applications/phriction/controller/PhrictionDocumentController.php
+++ b/src/applications/phriction/controller/PhrictionDocumentController.php
@@ -1,488 +1,488 @@
<?php
final class PhrictionDocumentController
extends PhrictionController {
private $slug;
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$this->slug = $request->getURIData('slug');
$slug = PhabricatorSlug::normalize($this->slug);
if ($slug != $this->slug) {
$uri = PhrictionDocument::getSlugURI($slug);
// Canonicalize pages to their one true URI.
return id(new AphrontRedirectResponse())->setURI($uri);
}
require_celerity_resource('phriction-document-css');
$document = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withSlugs(array($slug))
->executeOne();
$version_note = null;
$core_content = '';
$move_notice = '';
$properties = null;
$content = null;
$toc = null;
if (!$document) {
$document = PhrictionDocument::initializeNewDocument($viewer, $slug);
if ($slug == '/') {
$title = pht('Welcome to Phriction');
$subtitle = pht('Phriction is a simple and easy to use wiki for '.
'keeping track of documents and their changes.');
$page_title = pht('Welcome');
$create_text = pht('Edit this Document');
} else {
$title = pht('No Document Here');
$subtitle = pht('There is no document here, but you may create it.');
$page_title = pht('Page Not Found');
$create_text = pht('Create this Document');
}
$create_uri = '/phriction/edit/?slug='.$slug;
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText($create_text)
->setHref($create_uri)
->setColor(PHUIButtonView::GREEN);
$core_content = id(new PHUIBigInfoView())
->setIcon('fa-book')
->setTitle($title)
->setDescription($subtitle)
->addAction($create_button);
} else {
$version = $request->getInt('v');
if ($version) {
$content = id(new PhrictionContent())->loadOneWhere(
'documentID = %d AND version = %d',
$document->getID(),
$version);
if (!$content) {
return new Aphront404Response();
}
if ($content->getID() != $document->getContentID()) {
$vdate = phabricator_datetime($content->getDateCreated(), $viewer);
$version_note = new PHUIInfoView();
$version_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$version_note->appendChild(
pht('You are viewing an older version of this document, as it '.
'appeared on %s.', $vdate));
}
} else {
$content = id(new PhrictionContent())->load($document->getContentID());
}
$page_title = $content->getTitle();
$properties = $this
->buildPropertyListView($document, $content, $slug);
$doc_status = $document->getStatus();
$current_status = $content->getChangeType();
if ($current_status == PhrictionChangeType::CHANGE_EDIT ||
$current_status == PhrictionChangeType::CHANGE_MOVE_HERE) {
$core_content = $content->renderContent($viewer);
$toc = $this->getToc($content);
} else if ($current_status == PhrictionChangeType::CHANGE_DELETE) {
$notice = new PHUIInfoView();
$notice->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$notice->setTitle(pht('Document Deleted'));
$notice->appendChild(
pht('This document has been deleted. You can edit it to put new '.
'content here, or use history to revert to an earlier version.'));
$core_content = $notice->render();
} else if ($current_status == PhrictionChangeType::CHANGE_STUB) {
$notice = new PHUIInfoView();
$notice->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$notice->setTitle(pht('Empty Document'));
$notice->appendChild(
pht('This document is empty. You can edit it to put some proper '.
'content here.'));
$core_content = $notice->render();
} else if ($current_status == PhrictionChangeType::CHANGE_MOVE_AWAY) {
$new_doc_id = $content->getChangeRef();
$slug_uri = null;
// If the new document exists and the viewer can see it, provide a link
// to it. Otherwise, render a generic message.
$new_docs = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withIDs(array($new_doc_id))
->execute();
if ($new_docs) {
$new_doc = head($new_docs);
$slug_uri = PhrictionDocument::getSlugURI($new_doc->getSlug());
}
$notice = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
if ($slug_uri) {
$notice->appendChild(
phutil_tag(
'p',
array(),
pht(
'This document has been moved to %s. You can edit it to put '.
'new content here, or use history to revert to an earlier '.
'version.',
phutil_tag('a', array('href' => $slug_uri), $slug_uri))));
} else {
$notice->appendChild(
phutil_tag(
'p',
array(),
pht(
'This document has been moved. You can edit it to put new '.
'contne here, or use history to revert to an earlier '.
'version.')));
}
$core_content = $notice->render();
} else {
throw new Exception(pht("Unknown document status '%s'!", $doc_status));
}
$move_notice = null;
if ($current_status == PhrictionChangeType::CHANGE_MOVE_HERE) {
$from_doc_id = $content->getChangeRef();
$slug_uri = null;
// If the old document exists and is visible, provide a link to it.
$from_docs = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withIDs(array($from_doc_id))
->execute();
if ($from_docs) {
$from_doc = head($from_docs);
$slug_uri = PhrictionDocument::getSlugURI($from_doc->getSlug());
}
$move_notice = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
if ($slug_uri) {
$move_notice->appendChild(
pht(
'This document was moved from %s.',
phutil_tag('a', array('href' => $slug_uri), $slug_uri)));
} else {
// Render this for consistency, even though it's a bit silly.
$move_notice->appendChild(
pht('This document was moved from elsewhere.'));
}
}
}
$children = $this->renderDocumentChildren($slug);
$actions = $this->buildActionView($viewer, $document);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
$crumb_views = $this->renderBreadcrumbs($slug);
foreach ($crumb_views as $view) {
$crumbs->addCrumb($view);
}
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
- ->setIconFont('fa-bars')
+ ->setIcon('fa-bars')
->addClass('phui-mobile-menu')
->setDropdownMenu($actions);
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setPolicyObject($document)
->setHeader($page_title)
->addActionLink($action_button);
if ($content) {
$header->setEpoch($content->getDateCreated());
}
$prop_list = null;
if ($properties) {
$prop_list = new PHUIPropertyGroupView();
$prop_list->addPropertyList($properties);
}
$page_content = id(new PHUIDocumentViewPro())
->setHeader($header)
->setToc($toc)
->appendChild(
array(
$version_note,
$move_notice,
$core_content,
));
return $this->buildApplicationPage(
array(
$crumbs->render(),
$page_content,
$prop_list,
$children,
),
array(
'pageObjects' => array($document->getPHID()),
'title' => $page_title,
));
}
private function buildPropertyListView(
PhrictionDocument $document,
PhrictionContent $content,
$slug) {
$viewer = $this->getRequest()->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($document);
$view->addProperty(
pht('Last Author'),
$viewer->renderHandle($content->getAuthorPHID()));
return $view;
}
private function buildActionView(
PhabricatorUser $viewer,
PhrictionDocument $document) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$document,
PhabricatorPolicyCapability::CAN_EDIT);
$slug = PhabricatorSlug::normalize($this->slug);
$action_view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($document);
if (!$document->getID()) {
return $action_view->addAction(
id(new PhabricatorActionView())
->setName(pht('Create This Document'))
->setIcon('fa-plus-square')
->setHref('/phriction/edit/?slug='.$slug));
}
$action_view->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Document'))
->setDisabled(!$can_edit)
->setIcon('fa-pencil')
->setHref('/phriction/edit/'.$document->getID().'/'));
if ($document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS) {
$action_view->addAction(
id(new PhabricatorActionView())
->setName(pht('Move Document'))
->setDisabled(!$can_edit)
->setIcon('fa-arrows')
->setHref('/phriction/move/'.$document->getID().'/')
->setWorkflow(true));
$action_view->addAction(
id(new PhabricatorActionView())
->setName(pht('Delete Document'))
->setDisabled(!$can_edit)
->setIcon('fa-times')
->setHref('/phriction/delete/'.$document->getID().'/')
->setWorkflow(true));
}
return
$action_view->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setIcon('fa-list')
->setHref(PhrictionDocument::getSlugURI($slug, 'history')));
}
private function renderDocumentChildren($slug) {
$d_child = PhabricatorSlug::getDepth($slug) + 1;
$d_grandchild = PhabricatorSlug::getDepth($slug) + 2;
$limit = 250;
$query = id(new PhrictionDocumentQuery())
->setViewer($this->getRequest()->getUser())
->withDepths(array($d_child, $d_grandchild))
->withSlugPrefix($slug == '/' ? '' : $slug)
->withStatuses(array(
PhrictionDocumentStatus::STATUS_EXISTS,
PhrictionDocumentStatus::STATUS_STUB,
))
->setLimit($limit)
->setOrder(PhrictionDocumentQuery::ORDER_HIERARCHY)
->needContent(true);
$children = $query->execute();
if (!$children) {
return;
}
// We're going to render in one of three modes to try to accommodate
// different information scales:
//
// - If we found fewer than $limit rows, we know we have all the children
// and grandchildren and there aren't all that many. We can just render
// everything.
// - If we found $limit rows but the results included some grandchildren,
// we just throw them out and render only the children, as we know we
// have them all.
// - If we found $limit rows and the results have no grandchildren, we
// have a ton of children. Render them and then let the user know that
// this is not an exhaustive list.
if (count($children) == $limit) {
$more_children = true;
foreach ($children as $child) {
if ($child->getDepth() == $d_grandchild) {
$more_children = false;
}
}
$show_grandchildren = false;
} else {
$show_grandchildren = true;
$more_children = false;
}
$children_dicts = array();
$grandchildren_dicts = array();
foreach ($children as $key => $child) {
$child_dict = array(
'slug' => $child->getSlug(),
'depth' => $child->getDepth(),
'title' => $child->getContent()->getTitle(),
);
if ($child->getDepth() == $d_child) {
$children_dicts[] = $child_dict;
continue;
} else {
unset($children[$key]);
if ($show_grandchildren) {
$ancestors = PhabricatorSlug::getAncestry($child->getSlug());
$grandchildren_dicts[end($ancestors)][] = $child_dict;
}
}
}
// Fill in any missing children.
$known_slugs = mpull($children, null, 'getSlug');
foreach ($grandchildren_dicts as $slug => $ignored) {
if (empty($known_slugs[$slug])) {
$children_dicts[] = array(
'slug' => $slug,
'depth' => $d_child,
'title' => PhabricatorSlug::getDefaultTitle($slug),
'empty' => true,
);
}
}
$children_dicts = isort($children_dicts, 'title');
$list = array();
foreach ($children_dicts as $child) {
$list[] = hsprintf('<li class="remarkup-list-item">');
$list[] = $this->renderChildDocumentLink($child);
$grand = idx($grandchildren_dicts, $child['slug'], array());
if ($grand) {
$list[] = hsprintf('<ul class="remarkup-list">');
foreach ($grand as $grandchild) {
$list[] = hsprintf('<li class="remarkup-list-item">');
$list[] = $this->renderChildDocumentLink($grandchild);
$list[] = hsprintf('</li>');
}
$list[] = hsprintf('</ul>');
}
$list[] = hsprintf('</li>');
}
if ($more_children) {
$list[] = phutil_tag(
'li',
array(
'class' => 'remarkup-list-item',
),
pht('More...'));
}
$header = id(new PHUIHeaderView())
->setHeader(pht('Document Hierarchy'));
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild(phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup mlt mlb',
),
phutil_tag(
'ul',
array(
'class' => 'remarkup-list',
),
$list)));
return phutil_tag_div('phui-document-view-pro-box', $box);
}
private function renderChildDocumentLink(array $info) {
$title = nonempty($info['title'], pht('(Untitled Document)'));
$item = phutil_tag(
'a',
array(
'href' => PhrictionDocument::getSlugURI($info['slug']),
),
$title);
if (isset($info['empty'])) {
$item = phutil_tag('em', array(), $item);
}
return $item;
}
protected function getDocumentSlug() {
return $this->slug;
}
protected function getToc(PhrictionContent $content) {
$toc = $content->getRenderedTableOfContents();
if ($toc) {
$toc = phutil_tag_div('phui-document-toc-content', array(
phutil_tag_div(
'phui-document-toc-header',
pht('Contents')),
$toc,
));
}
return $toc;
}
}
diff --git a/src/applications/policy/storage/PhabricatorPolicy.php b/src/applications/policy/storage/PhabricatorPolicy.php
index 93afb35dc9..f2bfb8ce48 100644
--- a/src/applications/policy/storage/PhabricatorPolicy.php
+++ b/src/applications/policy/storage/PhabricatorPolicy.php
@@ -1,460 +1,460 @@
<?php
final class PhabricatorPolicy
extends PhabricatorPolicyDAO
implements
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface {
const ACTION_ALLOW = 'allow';
const ACTION_DENY = 'deny';
private $name;
private $shortName;
private $type;
private $href;
private $workflow;
private $icon;
protected $rules = array();
protected $defaultAction = self::ACTION_DENY;
private $ruleObjects = self::ATTACHABLE;
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'rules' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
'defaultAction' => 'text32',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
'phid' => array(
'columns' => array('phid'),
'unique' => true,
),
),
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPolicyPHIDTypePolicy::TYPECONST);
}
public static function newFromPolicyAndHandle(
$policy_identifier,
PhabricatorObjectHandle $handle = null) {
$is_global = PhabricatorPolicyQuery::isGlobalPolicy($policy_identifier);
if ($is_global) {
return PhabricatorPolicyQuery::getGlobalPolicy($policy_identifier);
}
$policy = PhabricatorPolicyQuery::getObjectPolicy($policy_identifier);
if ($policy) {
return $policy;
}
if (!$handle) {
throw new Exception(
pht(
"Policy identifier is an object PHID ('%s'), but no object handle ".
"was provided. A handle must be provided for object policies.",
$policy_identifier));
}
$handle_phid = $handle->getPHID();
if ($policy_identifier != $handle_phid) {
throw new Exception(
pht(
"Policy identifier is an object PHID ('%s'), but the provided ".
"handle has a different PHID ('%s'). The handle must correspond ".
"to the policy identifier.",
$policy_identifier,
$handle_phid));
}
$policy = id(new PhabricatorPolicy())
->setPHID($policy_identifier)
->setHref($handle->getURI());
$phid_type = phid_get_type($policy_identifier);
switch ($phid_type) {
case PhabricatorProjectProjectPHIDType::TYPECONST:
$policy->setType(PhabricatorPolicyType::TYPE_PROJECT);
$policy->setName($handle->getName());
break;
case PhabricatorPeopleUserPHIDType::TYPECONST:
$policy->setType(PhabricatorPolicyType::TYPE_USER);
$policy->setName($handle->getFullName());
break;
case PhabricatorPolicyPHIDTypePolicy::TYPECONST:
// TODO: This creates a weird handle-based version of a rule policy.
// It behaves correctly, but can't be applied since it doesn't have
// any rules. It is used to render transactions, and might need some
// cleanup.
break;
default:
$policy->setType(PhabricatorPolicyType::TYPE_MASKED);
$policy->setName($handle->getFullName());
break;
}
$policy->makeEphemeral();
return $policy;
}
public function setType($type) {
$this->type = $type;
return $this;
}
public function getType() {
if (!$this->type) {
return PhabricatorPolicyType::TYPE_CUSTOM;
}
return $this->type;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
if (!$this->name) {
return pht('Custom Policy');
}
return $this->name;
}
public function setShortName($short_name) {
$this->shortName = $short_name;
return $this;
}
public function getShortName() {
if ($this->shortName) {
return $this->shortName;
}
return $this->getName();
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function getHref() {
return $this->href;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function getWorkflow() {
return $this->workflow;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function getIcon() {
if ($this->icon) {
return $this->icon;
}
switch ($this->getType()) {
case PhabricatorPolicyType::TYPE_GLOBAL:
static $map = array(
PhabricatorPolicies::POLICY_PUBLIC => 'fa-globe',
PhabricatorPolicies::POLICY_USER => 'fa-users',
PhabricatorPolicies::POLICY_ADMIN => 'fa-eye',
PhabricatorPolicies::POLICY_NOONE => 'fa-ban',
);
return idx($map, $this->getPHID(), 'fa-question-circle');
case PhabricatorPolicyType::TYPE_USER:
return 'fa-user';
case PhabricatorPolicyType::TYPE_PROJECT:
return 'fa-briefcase';
case PhabricatorPolicyType::TYPE_CUSTOM:
case PhabricatorPolicyType::TYPE_MASKED:
return 'fa-certificate';
default:
return 'fa-question-circle';
}
}
public function getSortKey() {
return sprintf(
'%02d%s',
PhabricatorPolicyType::getPolicyTypeOrder($this->getType()),
$this->getSortName());
}
private function getSortName() {
if ($this->getType() == PhabricatorPolicyType::TYPE_GLOBAL) {
static $map = array(
PhabricatorPolicies::POLICY_PUBLIC => 0,
PhabricatorPolicies::POLICY_USER => 1,
PhabricatorPolicies::POLICY_ADMIN => 2,
PhabricatorPolicies::POLICY_NOONE => 3,
);
return idx($map, $this->getPHID());
}
return $this->getName();
}
public static function getPolicyExplanation(
PhabricatorUser $viewer,
$policy) {
$rule = PhabricatorPolicyQuery::getObjectPolicyRule($policy);
if ($rule) {
return $rule->getPolicyExplanation();
}
switch ($policy) {
case PhabricatorPolicies::POLICY_PUBLIC:
return pht('This object is public.');
case PhabricatorPolicies::POLICY_USER:
return pht('Logged in users can take this action.');
case PhabricatorPolicies::POLICY_ADMIN:
return pht('Administrators can take this action.');
case PhabricatorPolicies::POLICY_NOONE:
return pht('By default, no one can take this action.');
default:
$handle = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(array($policy))
->executeOne();
$type = phid_get_type($policy);
if ($type == PhabricatorProjectProjectPHIDType::TYPECONST) {
return pht(
'Members of the project "%s" can take this action.',
$handle->getFullName());
} else if ($type == PhabricatorPeopleUserPHIDType::TYPECONST) {
return pht(
'%s can take this action.',
$handle->getFullName());
} else if ($type == PhabricatorPolicyPHIDTypePolicy::TYPECONST) {
return pht(
'This object has a custom policy controlling who can take this '.
'action.');
} else {
return pht(
'This object has an unknown or invalid policy setting ("%s").',
$policy);
}
}
}
public function getFullName() {
switch ($this->getType()) {
case PhabricatorPolicyType::TYPE_PROJECT:
return pht('Project: %s', $this->getName());
case PhabricatorPolicyType::TYPE_MASKED:
return pht('Other: %s', $this->getName());
default:
return $this->getName();
}
}
public function renderDescription($icon = false) {
$img = null;
if ($icon) {
$img = id(new PHUIIconView())
- ->setIconFont($this->getIcon());
+ ->setIcon($this->getIcon());
}
if ($this->getHref()) {
$desc = javelin_tag(
'a',
array(
'href' => $this->getHref(),
'class' => 'policy-link',
'sigil' => $this->getWorkflow() ? 'workflow' : null,
),
array(
$img,
$this->getName(),
));
} else {
if ($img) {
$desc = array($img, $this->getName());
} else {
$desc = $this->getName();
}
}
switch ($this->getType()) {
case PhabricatorPolicyType::TYPE_PROJECT:
return pht('%s (Project)', $desc);
case PhabricatorPolicyType::TYPE_CUSTOM:
return $desc;
case PhabricatorPolicyType::TYPE_MASKED:
return pht(
'%s (You do not have permission to view policy details.)',
$desc);
default:
return $desc;
}
}
/**
* Return a list of custom rule classes (concrete subclasses of
* @{class:PhabricatorPolicyRule}) this policy uses.
*
* @return list<string> List of class names.
*/
public function getCustomRuleClasses() {
$classes = array();
foreach ($this->getRules() as $rule) {
if (!is_array($rule)) {
// This rule is invalid. We'll reject it later, but don't need to
// extract anything from it for now.
continue;
}
$class = idx($rule, 'rule');
try {
if (class_exists($class)) {
$classes[$class] = $class;
}
} catch (Exception $ex) {
continue;
}
}
return array_keys($classes);
}
/**
* Return a list of all values used by a given rule class to implement this
* policy. This is used to bulk load data (like project memberships) in order
* to apply policy filters efficiently.
*
* @param string Policy rule classname.
* @return list<wild> List of values used in this policy.
*/
public function getCustomRuleValues($rule_class) {
$values = array();
foreach ($this->getRules() as $rule) {
if ($rule['rule'] == $rule_class) {
$values[] = $rule['value'];
}
}
return $values;
}
public function attachRuleObjects(array $objects) {
$this->ruleObjects = $objects;
return $this;
}
public function getRuleObjects() {
return $this->assertAttached($this->ruleObjects);
}
/**
* Return `true` if this policy is stronger (more restrictive) than some
* other policy.
*
* Because policies are complicated, determining which policies are
* "stronger" is not trivial. This method uses a very coarse working
* definition of policy strength which is cheap to compute, unambiguous,
* and intuitive in the common cases.
*
* This method returns `true` if the //class// of this policy is stronger
* than the other policy, even if the policies are (or might be) the same in
* practice. For example, "Members of Project X" is considered a stronger
* policy than "All Users", even though "Project X" might (in some rare
* cases) contain every user.
*
* Generally, the ordering here is:
*
* - Public
* - All Users
* - (Everything Else)
* - No One
*
* In the "everything else" bucket, we can't make any broad claims about
* which policy is stronger (and we especially can't make those claims
* cheaply).
*
* Even if we fully evaluated each policy, the two policies might be
* "Members of X" and "Members of Y", each of which permits access to some
* set of unique users. In this case, neither is strictly stronger than
* the other.
*
* @param PhabricatorPolicy Other policy.
* @return bool `true` if this policy is more restrictive than the other
* policy.
*/
public function isStrongerThan(PhabricatorPolicy $other) {
$this_policy = $this->getPHID();
$other_policy = $other->getPHID();
$strengths = array(
PhabricatorPolicies::POLICY_PUBLIC => -2,
PhabricatorPolicies::POLICY_USER => -1,
// (Default policies have strength 0.)
PhabricatorPolicies::POLICY_NOONE => 1,
);
$this_strength = idx($strengths, $this->getPHID(), 0);
$other_strength = idx($strengths, $other->getPHID(), 0);
return ($this_strength > $other_strength);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
// NOTE: We implement policies only so we can comply with the interface.
// The actual query skips them, as enforcing policies on policies seems
// perilous and isn't currently required by the application.
return PhabricatorPolicies::POLICY_PUBLIC;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
public function describeAutomaticCapability($capability) {
return null;
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->delete();
}
}
diff --git a/src/applications/ponder/view/PonderAnswerView.php b/src/applications/ponder/view/PonderAnswerView.php
index 3951aa84a7..c0e90f7eca 100644
--- a/src/applications/ponder/view/PonderAnswerView.php
+++ b/src/applications/ponder/view/PonderAnswerView.php
@@ -1,211 +1,211 @@
<?php
final class PonderAnswerView extends AphrontTagView {
private $answer;
private $transactions;
private $timeline;
private $handle;
public function setAnswer($answer) {
$this->answer = $answer;
return $this;
}
public function setTransactions($transactions) {
$this->transactions = $transactions;
return $this;
}
public function setTimeline($timeline) {
$this->timeline = $timeline;
return $this;
}
public function setHandle($handle) {
$this->handle = $handle;
return $this;
}
protected function getTagAttributes() {
return array(
'class' => 'ponder-answer-view',
);
}
protected function getTagContent() {
require_celerity_resource('ponder-view-css');
$answer = $this->answer;
$viewer = $this->getUser();
$status = $answer->getStatus();
$author_phid = $answer->getAuthorPHID();
$actions = $this->buildAnswerActions();
$handle = $this->handle;
$id = $answer->getID();
if ($status == PonderAnswerStatus::ANSWER_STATUS_HIDDEN) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$answer,
PhabricatorPolicyCapability::CAN_EDIT);
$message = array();
$message[] = phutil_tag(
'em',
array(),
pht('This answer has been hidden.'));
if ($can_edit) {
$message[] = phutil_tag(
'a',
array(
'href' => "/ponder/answer/edit/{$id}/",
),
pht('Edit Answer'));
}
$message = phutil_implode_html(' ', $message);
return id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
->appendChild($message);
}
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
- ->setIconFont('fa-bars')
+ ->setIcon('fa-bars')
->setDropdownMenu($actions);
$header_name = phutil_tag(
'a',
array(
'href' => $handle->getURI(),
),
$handle->getName());
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setEpoch($answer->getDateModified())
->setHeader($header_name)
->addActionLink($action_button)
->setImage($handle->getImageURI())
->setImageURL($handle->getURI());
$content = phutil_tag(
'div',
array(
'class' => 'phabricator-remarkup mlt mlb msr msl',
),
PhabricatorMarkupEngine::renderOneObject(
$answer,
$answer->getMarkupField(),
$viewer));
$anchor = id(new PhabricatorAnchorView())
->setAnchorName("A$id");
$content_id = celerity_generate_unique_node_id();
$footer = id(new PonderFooterView())
->setContentID($content_id)
->setCount(count($this->transactions));
$votes = $answer->getVoteCount();
$vote_class = null;
if ($votes > 0) {
$vote_class = 'ponder-footer-action-helpful';
}
$icon = id(new PHUIIconView())
- ->setIconFont('fa-thumbs-up msr');
+ ->setIcon('fa-thumbs-up msr');
$helpful = phutil_tag(
'span',
array(
'class' => 'ponder-footer-action '.$vote_class,
),
array($icon, $votes));
$footer->addAction($helpful);
$answer_view = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($anchor)
->appendChild($content)
->appendChild($footer);
$comment_view = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($answer->getPHID())
->setShowPreview(false)
->setHeaderText(pht('Answer Comment'))
->setAction("/ponder/answer/comment/{$id}/")
->setSubmitButtonName(pht('Comment'));
$hidden_view = phutil_tag(
'div',
array(
'id' => $content_id,
'style' => 'display: none;',
),
array(
$this->timeline,
$comment_view,
));
return array(
$answer_view,
$hidden_view,
);
}
private function buildAnswerActions() {
$viewer = $this->getUser();
$answer = $this->answer;
$id = $answer->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$answer,
PhabricatorPolicyCapability::CAN_EDIT);
$view = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($answer);
$user_marked = $answer->getUserVote();
$can_vote = $viewer->isLoggedIn();
if ($user_marked) {
$helpful_uri = "/ponder/answer/helpful/remove/{$id}/";
$helpful_icon = 'fa-times';
$helpful_text = pht('Remove Helpful');
} else {
$helpful_uri = "/ponder/answer/helpful/add/{$id}/";
$helpful_icon = 'fa-thumbs-up';
$helpful_text = pht('Mark as Helpful');
}
$view->addAction(
id(new PhabricatorActionView())
->setIcon($helpful_icon)
->setName($helpful_text)
->setHref($helpful_uri)
->setRenderAsForm(true)
->setDisabled(!$can_vote)
->setWorkflow($can_vote));
$view->addAction(
id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setName(pht('Edit Answer'))
->setHref("/ponder/answer/edit/{$id}/")
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$view->addAction(
id(new PhabricatorActionView())
->setIcon('fa-list')
->setName(pht('View History'))
->setHref("/ponder/answer/history/{$id}/"));
return $view;
}
}
diff --git a/src/applications/ponder/view/PonderFooterView.php b/src/applications/ponder/view/PonderFooterView.php
index 26e35ec45a..be33863a9a 100644
--- a/src/applications/ponder/view/PonderFooterView.php
+++ b/src/applications/ponder/view/PonderFooterView.php
@@ -1,84 +1,84 @@
<?php
final class PonderFooterView extends AphrontTagView {
private $contentID;
private $count;
private $actions = array();
public function setContentID($content_id) {
$this->contentID = $content_id;
return $this;
}
public function setCount($count) {
$this->count = $count;
return $this;
}
public function addAction($action) {
$this->actions[] = $action;
return $this;
}
protected function getTagAttributes() {
return array(
'class' => 'ponder-footer-view',
);
}
protected function getTagContent() {
require_celerity_resource('ponder-view-css');
Javelin::initBehavior('phabricator-reveal-content');
$hide_action_id = celerity_generate_unique_node_id();
$show_action_id = celerity_generate_unique_node_id();
$content_id = $this->contentID;
if ($this->count == 0) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-comments msr');
+ ->setIcon('fa-comments msr');
$text = pht('Add a Comment');
} else {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-comments msr');
+ ->setIcon('fa-comments msr');
$text = pht('Show %d Comment(s)', new PhutilNumber($this->count));
}
$actions = array();
$hide_action = javelin_tag(
'a',
array(
'sigil' => 'reveal-content',
'class' => 'ponder-footer-action',
'id' => $hide_action_id,
'href' => '#',
'meta' => array(
'showIDs' => array($content_id, $show_action_id),
'hideIDs' => array($hide_action_id),
),
),
array($icon, $text));
$show_action = javelin_tag(
'a',
array(
'sigil' => 'reveal-content',
'style' => 'display: none;',
'class' => 'ponder-footer-action',
'id' => $show_action_id,
'href' => '#',
'meta' => array(
'showIDs' => array($hide_action_id),
'hideIDs' => array($content_id, $show_action_id),
),
),
array($icon, pht('Hide Comments')));
$actions[] = $hide_action;
$actions[] = $show_action;
return array($actions, $this->actions);
}
}
diff --git a/src/applications/project/controller/PhabricatorProjectBoardViewController.php b/src/applications/project/controller/PhabricatorProjectBoardViewController.php
index 2957ba47ed..4d83ca6fa3 100644
--- a/src/applications/project/controller/PhabricatorProjectBoardViewController.php
+++ b/src/applications/project/controller/PhabricatorProjectBoardViewController.php
@@ -1,831 +1,831 @@
<?php
final class PhabricatorProjectBoardViewController
extends PhabricatorProjectBoardController {
const BATCH_EDIT_ALL = 'all';
private $id;
private $slug;
private $handles;
private $queryKey;
private $filter;
private $sortKey;
private $showHidden;
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$response = $this->loadProject();
if ($response) {
return $response;
}
$project = $this->getProject();
$this->readRequestState();
$columns = $this->loadColumns($project);
// TODO: Expand the checks here if we add the ability
// to hide the Backlog column
if (!$columns) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
if (!$can_edit) {
$content = $this->buildNoAccessContent($project);
} else {
$content = $this->buildInitializeContent($project);
}
if ($content instanceof AphrontResponse) {
return $content;
}
$nav = $this->getProfileMenu();
$nav->selectFilter(PhabricatorProject::PANEL_WORKBOARD);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Workboard'));
return $this->newPage()
->setTitle(
array(
pht('Workboard'),
$project->getName(),
))
->setNavigation($nav)
->setCrumbs($crumbs)
->appendChild($content);
}
$board_uri = $this->getApplicationURI('board/'.$project->getID().'/');
$engine = id(new ManiphestTaskSearchEngine())
->setViewer($viewer)
->setBaseURI($board_uri)
->setIsBoardView(true);
if ($request->isFormPost()) {
$saved = $engine->buildSavedQueryFromRequest($request);
$engine->saveQuery($saved);
$filter_form = id(new AphrontFormView())
->setUser($viewer);
$engine->buildSearchForm($filter_form, $saved);
if ($engine->getErrors()) {
return $this->newDialog()
->setWidth(AphrontDialogView::WIDTH_FULL)
->setTitle(pht('Advanced Filter'))
->appendChild($filter_form->buildLayoutView())
->setErrors($engine->getErrors())
->setSubmitURI($board_uri)
->addSubmitButton(pht('Apply Filter'))
->addCancelButton($board_uri);
}
return id(new AphrontRedirectResponse())->setURI(
$this->getURIWithState(
$engine->getQueryResultsPageURI($saved->getQueryKey())));
}
$query_key = $request->getURIData('queryKey');
if (!$query_key) {
$query_key = 'open';
}
$this->queryKey = $query_key;
$custom_query = null;
if ($engine->isBuiltinQuery($query_key)) {
$saved = $engine->buildSavedQueryFromBuiltin($query_key);
} else {
$saved = id(new PhabricatorSavedQueryQuery())
->setViewer($viewer)
->withQueryKeys(array($query_key))
->executeOne();
if (!$saved) {
return new Aphront404Response();
}
$custom_query = $saved;
}
if ($request->getURIData('filter')) {
$filter_form = id(new AphrontFormView())
->setUser($viewer);
$engine->buildSearchForm($filter_form, $saved);
return $this->newDialog()
->setWidth(AphrontDialogView::WIDTH_FULL)
->setTitle(pht('Advanced Filter'))
->appendChild($filter_form->buildLayoutView())
->setSubmitURI($board_uri)
->addSubmitButton(pht('Apply Filter'))
->addCancelButton($board_uri);
}
$task_query = $engine->buildQueryFromSavedQuery($saved);
$tasks = $task_query
->withEdgeLogicPHIDs(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
PhabricatorQueryConstraint::OPERATOR_AND,
array($project->getPHID()))
->setOrder(ManiphestTaskQuery::ORDER_PRIORITY)
->setViewer($viewer)
->execute();
$tasks = mpull($tasks, null, 'getPHID');
if ($tasks) {
$positions = id(new PhabricatorProjectColumnPositionQuery())
->setViewer($viewer)
->withObjectPHIDs(mpull($tasks, 'getPHID'))
->withColumns($columns)
->execute();
$positions = mpull($positions, null, 'getObjectPHID');
} else {
$positions = array();
}
$task_map = array();
foreach ($tasks as $task) {
$task_phid = $task->getPHID();
if (empty($positions[$task_phid])) {
// This shouldn't normally be possible because we create positions on
// demand, but we might have raced as an object was removed from the
// board. Just drop the task if we don't have a position for it.
continue;
}
$position = $positions[$task_phid];
$task_map[$position->getColumnPHID()][] = $task_phid;
}
// If we're showing the board in "natural" order, sort columns by their
// column positions.
if ($this->sortKey == PhabricatorProjectColumn::ORDER_NATURAL) {
foreach ($task_map as $column_phid => $task_phids) {
$order = array();
foreach ($task_phids as $task_phid) {
if (isset($positions[$task_phid])) {
$order[$task_phid] = $positions[$task_phid]->getOrderingKey();
} else {
$order[$task_phid] = 0;
}
}
asort($order);
$task_map[$column_phid] = array_keys($order);
}
}
$task_can_edit_map = id(new PhabricatorPolicyFilter())
->setViewer($viewer)
->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))
->apply($tasks);
// If this is a batch edit, select the editable tasks in the chosen column
// and ship the user into the batch editor.
$batch_edit = $request->getStr('batch');
if ($batch_edit) {
if ($batch_edit !== self::BATCH_EDIT_ALL) {
$column_id_map = mpull($columns, null, 'getID');
$batch_column = idx($column_id_map, $batch_edit);
if (!$batch_column) {
return new Aphront404Response();
}
$batch_task_phids = idx($task_map, $batch_column->getPHID(), array());
foreach ($batch_task_phids as $key => $batch_task_phid) {
if (empty($task_can_edit_map[$batch_task_phid])) {
unset($batch_task_phids[$key]);
}
}
$batch_tasks = array_select_keys($tasks, $batch_task_phids);
} else {
$batch_tasks = $task_can_edit_map;
}
if (!$batch_tasks) {
$cancel_uri = $this->getURIWithState($board_uri);
return $this->newDialog()
->setTitle(pht('No Editable Tasks'))
->appendParagraph(
pht(
'The selected column contains no visible tasks which you '.
'have permission to edit.'))
->addCancelButton($board_uri);
}
$batch_ids = mpull($batch_tasks, 'getID');
$batch_ids = implode(',', $batch_ids);
$batch_uri = new PhutilURI('/maniphest/batch/');
$batch_uri->setQueryParam('board', $this->id);
$batch_uri->setQueryParam('batch', $batch_ids);
return id(new AphrontRedirectResponse())
->setURI($batch_uri);
}
$board_id = celerity_generate_unique_node_id();
$board = id(new PHUIWorkboardView())
->setUser($viewer)
->setID($board_id);
$behavior_config = array(
'boardID' => $board_id,
'projectPHID' => $project->getPHID(),
'moveURI' => $this->getApplicationURI('move/'.$project->getID().'/'),
'createURI' => $this->getCreateURI(),
'order' => $this->sortKey,
);
$this->initBehavior(
'project-boards',
$behavior_config);
$this->handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks);
foreach ($columns as $column) {
$task_phids = idx($task_map, $column->getPHID(), array());
$column_tasks = array_select_keys($tasks, $task_phids);
$panel = id(new PHUIWorkpanelView())
->setHeader($column->getDisplayName())
->setSubHeader($column->getDisplayType())
->addSigil('workpanel');
$header_icon = $column->getHeaderIcon();
if ($header_icon) {
$panel->setHeaderIcon($header_icon);
}
if ($column->isHidden()) {
$panel->addClass('project-panel-hidden');
}
$column_menu = $this->buildColumnMenu($project, $column);
$panel->addHeaderAction($column_menu);
$tag_id = celerity_generate_unique_node_id();
$tag_content_id = celerity_generate_unique_node_id();
$count_tag = id(new PHUITagView())
->setType(PHUITagView::TYPE_SHADE)
->setShade(PHUITagView::COLOR_BLUE)
->setID($tag_id)
->setName(phutil_tag('span', array('id' => $tag_content_id), '-'))
->setStyle('display: none');
$panel->setHeaderTag($count_tag);
$cards = id(new PHUIObjectItemListView())
->setUser($viewer)
->setFlush(true)
->setAllowEmptyList(true)
->addSigil('project-column')
->setMetadata(
array(
'columnPHID' => $column->getPHID(),
'countTagID' => $tag_id,
'countTagContentID' => $tag_content_id,
'pointLimit' => $column->getPointLimit(),
));
foreach ($column_tasks as $task) {
$owner = null;
if ($task->getOwnerPHID()) {
$owner = $this->handles[$task->getOwnerPHID()];
}
$can_edit = idx($task_can_edit_map, $task->getPHID(), false);
$cards->addItem(id(new ProjectBoardTaskCard())
->setViewer($viewer)
->setTask($task)
->setOwner($owner)
->setCanEdit($can_edit)
->getItem());
}
$panel->setCards($cards);
$board->addPanel($panel);
}
$sort_menu = $this->buildSortMenu(
$viewer,
$this->sortKey);
$filter_menu = $this->buildFilterMenu(
$viewer,
$custom_query,
$engine,
$query_key);
$manage_menu = $this->buildManageMenu($project, $this->showHidden);
$header_link = phutil_tag(
'a',
array(
'href' => $this->getApplicationURI('profile/'.$project->getID().'/'),
),
$project->getName());
$board_box = id(new PHUIBoxView())
->appendChild($board)
->addClass('project-board-wrapper');
$nav = $this->getProfileMenu();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Workboard'));
$crumbs->setBorder(true);
$crumbs->addAction($sort_menu);
$crumbs->addAction($filter_menu);
$crumbs->addAction($manage_menu);
return $this->newPage()
->setTitle(pht('%s Board', $project->getName()))
->setPageObjectPHIDs(array($project->getPHID()))
->setShowFooter(false)
->setNavigation($nav)
->setCrumbs($crumbs)
->addQuicksandConfig(
array(
'boardConfig' => $behavior_config,
))
->appendChild(
array(
$board_box,
));
}
private function readRequestState() {
$request = $this->getRequest();
$project = $this->getProject();
$this->showHidden = $request->getBool('hidden');
$this->id = $project->getID();
$sort_key = $request->getStr('order');
switch ($sort_key) {
case PhabricatorProjectColumn::ORDER_NATURAL:
case PhabricatorProjectColumn::ORDER_PRIORITY:
break;
default:
$sort_key = PhabricatorProjectColumn::DEFAULT_ORDER;
break;
}
$this->sortKey = $sort_key;
}
private function loadColumns(PhabricatorProject $project) {
$viewer = $this->getViewer();
$column_query = id(new PhabricatorProjectColumnQuery())
->setViewer($viewer)
->withProjectPHIDs(array($project->getPHID()));
if (!$this->showHidden) {
$column_query->withStatuses(
array(PhabricatorProjectColumn::STATUS_ACTIVE));
}
$columns = $column_query->execute();
$columns = mpull($columns, null, 'getSequence');
ksort($columns);
return $columns;
}
private function buildSortMenu(
PhabricatorUser $viewer,
$sort_key) {
$sort_icon = id(new PHUIIconView())
- ->setIconFont('fa-sort-amount-asc bluegrey');
+ ->setIcon('fa-sort-amount-asc bluegrey');
$named = array(
PhabricatorProjectColumn::ORDER_NATURAL => pht('Natural'),
PhabricatorProjectColumn::ORDER_PRIORITY => pht('Sort by Priority'),
);
$base_uri = $this->getURIWithState();
$items = array();
foreach ($named as $key => $name) {
$is_selected = ($key == $sort_key);
if ($is_selected) {
$active_order = $name;
}
$item = id(new PhabricatorActionView())
->setIcon('fa-sort-amount-asc')
->setSelected($is_selected)
->setName($name);
$uri = $base_uri->alter('order', $key);
$item->setHref($uri);
$items[] = $item;
}
$sort_menu = id(new PhabricatorActionListView())
->setUser($viewer);
foreach ($items as $item) {
$sort_menu->addAction($item);
}
$sort_button = id(new PHUIListItemView())
->setName(pht('Sort: %s', $active_order))
->setIcon('fa-sort-amount-asc')
->setHref('#')
->addSigil('boards-dropdown-menu')
->setMetadata(
array(
'items' => hsprintf('%s', $sort_menu),
));
return $sort_button;
}
private function buildFilterMenu(
PhabricatorUser $viewer,
$custom_query,
PhabricatorApplicationSearchEngine $engine,
$query_key) {
$named = array(
'open' => pht('Open Tasks'),
'all' => pht('All Tasks'),
);
if ($viewer->isLoggedIn()) {
$named['assigned'] = pht('Assigned to Me');
}
if ($custom_query) {
$named[$custom_query->getQueryKey()] = pht('Custom Filter');
}
$items = array();
foreach ($named as $key => $name) {
$is_selected = ($key == $query_key);
if ($is_selected) {
$active_filter = $name;
}
$is_custom = false;
if ($custom_query) {
$is_custom = ($key == $custom_query->getQueryKey());
}
$item = id(new PhabricatorActionView())
->setIcon('fa-search')
->setSelected($is_selected)
->setName($name);
if ($is_custom) {
$uri = $this->getApplicationURI(
'board/'.$this->id.'/filter/query/'.$key.'/');
$item->setWorkflow(true);
} else {
$uri = $engine->getQueryResultsPageURI($key);
}
$uri = $this->getURIWithState($uri);
$item->setHref($uri);
$items[] = $item;
}
$items[] = id(new PhabricatorActionView())
->setIcon('fa-cog')
->setHref($this->getApplicationURI('board/'.$this->id.'/filter/'))
->setWorkflow(true)
->setName(pht('Advanced Filter...'));
$filter_menu = id(new PhabricatorActionListView())
->setUser($viewer);
foreach ($items as $item) {
$filter_menu->addAction($item);
}
$filter_button = id(new PHUIListItemView())
->setName(pht('Filter: %s', $active_filter))
->setIcon('fa-search')
->setHref('#')
->addSigil('boards-dropdown-menu')
->setMetadata(
array(
'items' => hsprintf('%s', $filter_menu),
));
return $filter_button;
}
private function buildManageMenu(
PhabricatorProject $project,
$show_hidden) {
$request = $this->getRequest();
$viewer = $request->getUser();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
$manage_items = array();
$manage_items[] = id(new PhabricatorActionView())
->setIcon('fa-plus')
->setName(pht('Add Column'))
->setHref($this->getApplicationURI('board/'.$this->id.'/edit/'))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit);
$manage_items[] = id(new PhabricatorActionView())
->setIcon('fa-exchange')
->setName(pht('Reorder Columns'))
->setHref($this->getApplicationURI('board/'.$this->id.'/reorder/'))
->setDisabled(!$can_edit)
->setWorkflow(true);
if ($show_hidden) {
$hidden_uri = $this->getURIWithState()
->setQueryParam('hidden', null);
$hidden_icon = 'fa-eye-slash';
$hidden_text = pht('Hide Hidden Columns');
} else {
$hidden_uri = $this->getURIWithState()
->setQueryParam('hidden', 'true');
$hidden_icon = 'fa-eye';
$hidden_text = pht('Show Hidden Columns');
}
$manage_items[] = id(new PhabricatorActionView())
->setIcon($hidden_icon)
->setName($hidden_text)
->setHref($hidden_uri);
$batch_edit_uri = $request->getRequestURI();
$batch_edit_uri->setQueryParam('batch', self::BATCH_EDIT_ALL);
$can_batch_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
PhabricatorApplication::getByClass('PhabricatorManiphestApplication'),
ManiphestBulkEditCapability::CAPABILITY);
$manage_items[] = id(new PhabricatorActionView())
->setIcon('fa-list-ul')
->setName(pht('Batch Edit Visible Tasks...'))
->setHref($batch_edit_uri)
->setDisabled(!$can_batch_edit);
$manage_menu = id(new PhabricatorActionListView())
->setUser($viewer);
foreach ($manage_items as $item) {
$manage_menu->addAction($item);
}
$manage_button = id(new PHUIListItemView())
->setName(pht('Manage Board'))
->setIcon('fa-cog')
->setHref('#')
->addSigil('boards-dropdown-menu')
->setMetadata(
array(
'items' => hsprintf('%s', $manage_menu),
));
return $manage_button;
}
private function buildColumnMenu(
PhabricatorProject $project,
PhabricatorProjectColumn $column) {
$request = $this->getRequest();
$viewer = $request->getUser();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
$column_items = array();
$column_items[] = id(new PhabricatorActionView())
->setIcon('fa-plus')
->setName(pht('Create Task...'))
->setHref($this->getCreateURI())
->addSigil('column-add-task')
->setMetadata(
array(
'columnPHID' => $column->getPHID(),
));
$batch_edit_uri = $request->getRequestURI();
$batch_edit_uri->setQueryParam('batch', $column->getID());
$can_batch_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
PhabricatorApplication::getByClass('PhabricatorManiphestApplication'),
ManiphestBulkEditCapability::CAPABILITY);
$column_items[] = id(new PhabricatorActionView())
->setIcon('fa-list-ul')
->setName(pht('Batch Edit Tasks...'))
->setHref($batch_edit_uri)
->setDisabled(!$can_batch_edit);
$detail_uri = $this->getApplicationURI(
'board/'.$this->id.'/column/'.$column->getID().'/');
$column_items[] = id(new PhabricatorActionView())
->setIcon('fa-columns')
->setName(pht('Column Details'))
->setHref($detail_uri);
$can_hide = ($can_edit && !$column->isDefaultColumn());
$hide_uri = 'board/'.$this->id.'/hide/'.$column->getID().'/';
$hide_uri = $this->getApplicationURI($hide_uri);
$hide_uri = $this->getURIWithState($hide_uri);
if (!$column->isHidden()) {
$column_items[] = id(new PhabricatorActionView())
->setName(pht('Hide Column'))
->setIcon('fa-eye-slash')
->setHref($hide_uri)
->setDisabled(!$can_hide)
->setWorkflow(true);
} else {
$column_items[] = id(new PhabricatorActionView())
->setName(pht('Show Column'))
->setIcon('fa-eye')
->setHref($hide_uri)
->setDisabled(!$can_hide)
->setWorkflow(true);
}
$column_menu = id(new PhabricatorActionListView())
->setUser($viewer);
foreach ($column_items as $item) {
$column_menu->addAction($item);
}
$column_button = id(new PHUIIconView())
- ->setIconFont('fa-caret-down')
+ ->setIcon('fa-caret-down')
->setHref('#')
->addSigil('boards-dropdown-menu')
->setMetadata(
array(
'items' => hsprintf('%s', $column_menu),
));
return $column_button;
}
/**
* Add current state parameters (like order and the visibility of hidden
* columns) to a URI.
*
* This allows actions which toggle or adjust one piece of state to keep
* the rest of the board state persistent. If no URI is provided, this method
* starts with the request URI.
*
* @param string|null URI to add state parameters to.
* @return PhutilURI URI with state parameters.
*/
private function getURIWithState($base = null) {
if ($base === null) {
$base = $this->getRequest()->getRequestURI();
}
$base = new PhutilURI($base);
if ($this->sortKey != PhabricatorProjectColumn::DEFAULT_ORDER) {
$base->setQueryParam('order', $this->sortKey);
} else {
$base->setQueryParam('order', null);
}
$base->setQueryParam('hidden', $this->showHidden ? 'true' : null);
return $base;
}
private function getCreateURI() {
$viewer = $this->getViewer();
// TODO: This should be cleaned up, but maybe we're going to make options
// for each column or board?
$edit_config = id(new ManiphestEditEngine())
->setViewer($viewer)
->loadDefaultEditConfiguration();
if ($edit_config) {
$form_key = $edit_config->getIdentifier();
$create_uri = "/maniphest/task/edit/form/{$form_key}/";
} else {
$create_uri = '/maniphest/task/edit/';
}
return $create_uri;
}
private function buildInitializeContent(PhabricatorProject $project) {
$request = $this->getRequest();
$viewer = $this->getViewer();
$type = $request->getStr('initialize-type');
$id = $project->getID();
$profile_uri = $this->getApplicationURI("profile/{$id}/");
$board_uri = $this->getApplicationURI("board/{$id}/");
$import_uri = $this->getApplicationURI("board/{$id}/import/");
$set_default = $request->getBool('default');
if ($set_default) {
$this
->getProfilePanelEngine()
->adjustDefault(PhabricatorProject::PANEL_WORKBOARD);
}
if ($request->isFormPost()) {
if ($type == 'backlog-only') {
$column = PhabricatorProjectColumn::initializeNewColumn($viewer)
->setSequence(0)
->setProperty('isDefault', true)
->setProjectPHID($project->getPHID())
->save();
$project->setHasWorkboard(1)->save();
return id(new AphrontRedirectResponse())
->setURI($board_uri);
} else {
return id(new AphrontRedirectResponse())
->setURI($import_uri);
}
}
$new_selector = id(new AphrontFormRadioButtonControl())
->setLabel(pht('Columns'))
->setName('initialize-type')
->setValue('backlog-only')
->addButton(
'backlog-only',
pht('New Empty Board'),
pht('Create a new board with just a backlog column.'))
->addButton(
'import',
pht('Import Columns'),
pht('Import board columns from another project.'));
$default_checkbox = id(new AphrontFormCheckboxControl())
->setLabel(pht('Make Default'))
->addCheckbox(
'default',
1,
pht('Make the workboard the default view for this project.'),
true);
$form = id(new AphrontFormView())
->setUser($viewer)
->appendRemarkupInstructions(
pht('The workboard for this project has not been created yet.'))
->appendControl($new_selector)
->appendControl($default_checkbox)
->appendControl(
id(new AphrontFormSubmitControl())
->addCancelButton($profile_uri)
->setValue(pht('Create Workboard')));
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Create Workboard'))
->setForm($form);
return $box;
}
private function buildNoAccessContent(PhabricatorProject $project) {
$viewer = $this->getViewer();
$id = $project->getID();
$profile_uri = $this->getApplicationURI("profile/{$id}/");
return $this->newDialog()
->setTitle(pht('Unable to Create Workboard'))
->appendParagraph(
pht(
'The workboard for this project has not been created yet, '.
'but you do not have permission to create it. Only users '.
'who can edit this project can create a workboard for it.'))
->addCancelButton($profile_uri);
}
}
diff --git a/src/applications/project/controller/PhabricatorProjectMilestonesController.php b/src/applications/project/controller/PhabricatorProjectMilestonesController.php
index 595035bdb7..ebbe5bc2e3 100644
--- a/src/applications/project/controller/PhabricatorProjectMilestonesController.php
+++ b/src/applications/project/controller/PhabricatorProjectMilestonesController.php
@@ -1,92 +1,92 @@
<?php
final class PhabricatorProjectMilestonesController
extends PhabricatorProjectController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$response = $this->loadProject();
if ($response) {
return $response;
}
$project = $this->getProject();
$id = $project->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
$has_support = $project->supportsMilestones();
if ($has_support) {
$milestones = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withParentProjectPHIDs(array($project->getPHID()))
->needImages(true)
->withIsMilestone(true)
->setOrder('newest')
->execute();
} else {
$milestones = array();
}
$can_create = $can_edit && $has_support;
if ($project->getHasMilestones()) {
$button_text = pht('Create Next Milestone');
} else {
$button_text = pht('Add Milestones');
}
$header = id(new PHUIHeaderView())
->setHeader(pht('Milestones'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref("/project/edit/?milestone={$id}")
- ->setIconFont('fa-plus')
+ ->setIcon('fa-plus')
->setDisabled(!$can_create)
->setWorkflow(!$can_create)
->setText($button_text));
$box = id(new PHUIObjectBoxView())
->setHeader($header);
if (!$has_support) {
$no_support = pht(
'This project is a milestone. Milestones can not have their own '.
'milestones.');
$info_view = id(new PHUIInfoView())
->setErrors(array($no_support))
->setSeverity(PHUIInfoView::SEVERITY_WARNING);
$box->setInfoView($info_view);
}
$box->setObjectList(
id(new PhabricatorProjectListView())
->setUser($viewer)
->setProjects($milestones)
->renderList());
$nav = $this->getProfileMenu();
$nav->selectFilter(PhabricatorProject::PANEL_MILESTONES);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Milestones'));
return $this->newPage()
->setNavigation($nav)
->setCrumbs($crumbs)
->setTitle(array($project->getName(), pht('Milestones')))
->appendChild($box);
}
}
diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php
index 1ee02debac..c03b82b05d 100644
--- a/src/applications/project/controller/PhabricatorProjectProfileController.php
+++ b/src/applications/project/controller/PhabricatorProjectProfileController.php
@@ -1,180 +1,180 @@
<?php
final class PhabricatorProjectProfileController
extends PhabricatorProjectController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadProject();
if ($response) {
return $response;
}
$viewer = $request->getUser();
$project = $this->getProject();
$id = $project->getID();
$picture = $project->getProfileImageURI();
$header = id(new PHUIHeaderView())
->setHeader($project->getName())
->setUser($viewer)
->setPolicyObject($project)
->setImage($picture)
->setProfileHeader(true);
if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ACTIVE) {
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
} else {
$header->setStatus('fa-ban', 'red', pht('Archived'));
}
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
if ($can_edit) {
$header->setImageEditURL($this->getApplicationURI("picture/{$id}/"));
}
$properties = $this->buildPropertyListView($project);
$watch_action = $this->renderWatchAction($project);
$header->addActionLink($watch_action);
$member_list = id(new PhabricatorProjectMemberListView())
->setUser($viewer)
->setProject($project)
->setLimit(5)
->setBackground(PHUIBoxView::GREY)
->setUserPHIDs($project->getMemberPHIDs());
$watcher_list = id(new PhabricatorProjectWatcherListView())
->setUser($viewer)
->setProject($project)
->setLimit(5)
->setBackground(PHUIBoxView::GREY)
->setUserPHIDs($project->getWatcherPHIDs());
$nav = $this->getProfileMenu();
$nav->selectFilter(PhabricatorProject::PANEL_PROFILE);
$stories = id(new PhabricatorFeedQuery())
->setViewer($viewer)
->setFilterPHIDs(
array(
$project->getPHID(),
))
->setLimit(50)
->execute();
$feed = $this->renderStories($stories);
$feed = phutil_tag_div('project-view-feed', $feed);
$columns = id(new PHUITwoColumnView())
->setMainColumn(
array(
$properties,
$feed,
))
->setSideColumn(
array(
$member_list,
$watcher_list,
));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->setBorder(true);
require_celerity_resource('project-view-css');
$home = phutil_tag(
'div',
array(
'class' => 'project-view-home',
),
array(
$header,
$columns,
));
return $this->newPage()
->setNavigation($nav)
->setCrumbs($crumbs)
->setTitle($project->getName())
->setPageObjectPHIDs(array($project->getPHID()))
->appendChild(
array(
$home,
));
}
private function buildPropertyListView(
PhabricatorProject $project) {
$request = $this->getRequest();
$viewer = $request->getUser();
$view = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($project);
$field_list = PhabricatorCustomField::getObjectFields(
$project,
PhabricatorCustomField::ROLE_VIEW);
$field_list->appendFieldsToPropertyList($project, $viewer, $view);
if ($view->isEmpty()) {
return null;
}
$view = id(new PHUIBoxView())
->setColor(PHUIBoxView::GREY)
->appendChild($view)
->addClass('project-view-properties');
return $view;
}
private function renderStories(array $stories) {
assert_instances_of($stories, 'PhabricatorFeedStory');
$builder = new PhabricatorFeedBuilder($stories);
$builder->setUser($this->getRequest()->getUser());
$builder->setShowHovercards(true);
$view = $builder->buildView();
return $view;
}
private function renderWatchAction(PhabricatorProject $project) {
$viewer = $this->getViewer();
$viewer_phid = $viewer->getPHID();
$id = $project->getID();
$is_watcher = ($viewer_phid && $project->isUserWatcher($viewer_phid));
if (!$is_watcher) {
$watch_icon = 'fa-eye';
$watch_text = pht('Watch Project');
$watch_href = "/project/watch/{$id}/?via=profile";
} else {
$watch_icon = 'fa-eye-slash';
$watch_text = pht('Unwatch Project');
$watch_href = "/project/unwatch/{$id}/?via=profile";
}
$watch_icon = id(new PHUIIconView())
- ->setIconFont($watch_icon);
+ ->setIcon($watch_icon);
return id(new PHUIButtonView())
->setTag('a')
->setWorkflow(true)
->setIcon($watch_icon)
->setText($watch_text)
->setHref($watch_href);
}
}
diff --git a/src/applications/project/controller/PhabricatorProjectSubprojectsController.php b/src/applications/project/controller/PhabricatorProjectSubprojectsController.php
index e512d12a6e..a88bf7d07c 100644
--- a/src/applications/project/controller/PhabricatorProjectSubprojectsController.php
+++ b/src/applications/project/controller/PhabricatorProjectSubprojectsController.php
@@ -1,91 +1,91 @@
<?php
final class PhabricatorProjectSubprojectsController
extends PhabricatorProjectController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$response = $this->loadProject();
if ($response) {
return $response;
}
$project = $this->getProject();
$id = $project->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
$has_support = $project->supportsSubprojects();
if ($has_support) {
$subprojects = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withParentProjectPHIDs(array($project->getPHID()))
->needImages(true)
->withIsMilestone(false)
->execute();
} else {
$subprojects = array();
}
$can_create = $can_edit && $has_support;
if ($project->getHasSubprojects()) {
$button_text = pht('Create Subproject');
} else {
$button_text = pht('Add Subprojects');
}
$header = id(new PHUIHeaderView())
->setHeader(pht('Subprojects'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setHref("/project/edit/?parent={$id}")
- ->setIconFont('fa-plus')
+ ->setIcon('fa-plus')
->setDisabled(!$can_create)
->setWorkflow(!$can_create)
->setText($button_text));
$box = id(new PHUIObjectBoxView())
->setHeader($header);
if (!$has_support) {
$no_support = pht(
'This project is a milestone. Milestones can not have subprojects.');
$info_view = id(new PHUIInfoView())
->setErrors(array($no_support))
->setSeverity(PHUIInfoView::SEVERITY_WARNING);
$box->setInfoView($info_view);
}
$box->setObjectList(
id(new PhabricatorProjectListView())
->setUser($viewer)
->setProjects($subprojects)
->renderList());
$nav = $this->getProfileMenu();
$nav->selectFilter(PhabricatorProject::PANEL_SUBPROJECTS);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Subprojects'));
return $this->newPage()
->setNavigation($nav)
->setCrumbs($crumbs)
->setTitle(array($project->getName(), pht('Subprojects')))
->appendChild($box);
}
}
diff --git a/src/applications/project/query/PhabricatorProjectSearchEngine.php b/src/applications/project/query/PhabricatorProjectSearchEngine.php
index 7d533c8a11..4a29034ba6 100644
--- a/src/applications/project/query/PhabricatorProjectSearchEngine.php
+++ b/src/applications/project/query/PhabricatorProjectSearchEngine.php
@@ -1,201 +1,201 @@
<?php
final class PhabricatorProjectSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Projects');
}
public function getApplicationClassName() {
return 'PhabricatorProjectApplication';
}
public function newQuery() {
return id(new PhabricatorProjectQuery())
->needImages(true)
->withIsMilestone(false);
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name'))
->setKey('name'),
id(new PhabricatorUsersSearchField())
->setLabel(pht('Members'))
->setKey('memberPHIDs')
->setAliases(array('member', 'members')),
id(new PhabricatorSearchSelectField())
->setLabel(pht('Status'))
->setKey('status')
->setOptions($this->getStatusOptions()),
id(new PhabricatorSearchCheckboxesField())
->setLabel(pht('Icons'))
->setKey('icons')
->setOptions($this->getIconOptions()),
id(new PhabricatorSearchCheckboxesField())
->setLabel(pht('Colors'))
->setKey('colors')
->setOptions($this->getColorOptions()),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
if (strlen($map['name'])) {
$tokens = PhabricatorTypeaheadDatasource::tokenizeString($map['name']);
$query->withNameTokens($tokens);
}
if ($map['memberPHIDs']) {
$query->withMemberPHIDs($map['memberPHIDs']);
}
if ($map['status']) {
$status = idx($this->getStatusValues(), $map['status']);
if ($status) {
$query->withStatus($status);
}
}
if ($map['icons']) {
$query->withIcons($map['icons']);
}
if ($map['colors']) {
$query->withColors($map['colors']);
}
return $query;
}
protected function getURI($path) {
return '/project/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
if ($this->requireViewer()->isLoggedIn()) {
$names['joined'] = pht('Joined');
}
$names['active'] = pht('Active');
$names['all'] = pht('All');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
$viewer_phid = $this->requireViewer()->getPHID();
switch ($query_key) {
case 'all':
return $query;
case 'active':
return $query
->setParameter('status', 'active');
case 'joined':
return $query
->setParameter('memberPHIDs', array($viewer_phid))
->setParameter('status', 'active');
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
private function getStatusOptions() {
return array(
'active' => pht('Show Only Active Projects'),
'archived' => pht('Show Only Archived Projects'),
'all' => pht('Show All Projects'),
);
}
private function getStatusValues() {
return array(
'active' => PhabricatorProjectQuery::STATUS_ACTIVE,
'archived' => PhabricatorProjectQuery::STATUS_ARCHIVED,
'all' => PhabricatorProjectQuery::STATUS_ANY,
);
}
private function getIconOptions() {
$options = array();
$set = new PhabricatorProjectIconSet();
foreach ($set->getIcons() as $icon) {
if ($icon->getIsDisabled()) {
continue;
}
$options[$icon->getKey()] = array(
id(new PHUIIconView())
- ->setIconFont($icon->getIcon()),
+ ->setIcon($icon->getIcon()),
' ',
$icon->getLabel(),
);
}
return $options;
}
private function getColorOptions() {
$options = array();
foreach (PhabricatorProjectIconSet::getColorMap() as $color => $name) {
$options[$color] = array(
id(new PHUITagView())
->setType(PHUITagView::TYPE_SHADE)
->setShade($color)
->setName($name),
);
}
return $options;
}
protected function renderResultList(
array $projects,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($projects, 'PhabricatorProject');
$viewer = $this->requireViewer();
$list = id(new PhabricatorProjectListView())
->setUser($viewer)
->setProjects($projects)
->renderList();
return id(new PhabricatorApplicationSearchResultView())
->setObjectList($list)
->setNoDataString(pht('No projects found.'));
}
protected function getNewUserBody() {
$create_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Create a Project'))
->setHref('/project/edit/')
->setColor(PHUIButtonView::GREEN);
$icon = $this->getApplication()->getFontIcon();
$app_name = $this->getApplication()->getName();
$view = id(new PHUIBigInfoView())
->setIcon($icon)
->setTitle(pht('Welcome to %s', $app_name))
->setDescription(
pht('Projects are flexible storage containers used as '.
'tags, teams, projects, or anything you need to group.'))
->addAction($create_button);
return $view;
}
}
diff --git a/src/applications/project/view/PhabricatorProjectListView.php b/src/applications/project/view/PhabricatorProjectListView.php
index 87874e3594..3d6044f2b1 100644
--- a/src/applications/project/view/PhabricatorProjectListView.php
+++ b/src/applications/project/view/PhabricatorProjectListView.php
@@ -1,62 +1,62 @@
<?php
final class PhabricatorProjectListView extends AphrontView {
private $projects;
public function setProjects(array $projects) {
$this->projects = $projects;
return $this;
}
public function getProjects() {
return $this->projects;
}
public function renderList() {
$viewer = $this->getUser();
$projects = $this->getProjects();
$handles = $viewer->loadHandles(mpull($projects, 'getPHID'));
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($projects as $key => $project) {
$id = $project->getID();
$icon = $project->getDisplayIconIcon();
$color = $project->getColor();
$icon_icon = id(new PHUIIconView())
- ->setIconFont("{$icon} {$color}");
+ ->setIcon("{$icon} {$color}");
$icon_name = $project->getDisplayIconName();
$item = id(new PHUIObjectItemView())
->setHeader($project->getName())
->setHref("/project/view/{$id}/")
->setImageURI($project->getProfileImageURI())
->addAttribute(
array(
$icon_icon,
' ',
$icon_name,
));
if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED) {
$item->addIcon('delete-grey', pht('Archived'));
$item->setDisabled(true);
}
$list->addItem($item);
}
return $list;
}
public function render() {
return $this->renderList();
}
}
diff --git a/src/applications/project/view/PhabricatorProjectUserListView.php b/src/applications/project/view/PhabricatorProjectUserListView.php
index 58c9a4ae0e..715e28f944 100644
--- a/src/applications/project/view/PhabricatorProjectUserListView.php
+++ b/src/applications/project/view/PhabricatorProjectUserListView.php
@@ -1,145 +1,145 @@
<?php
abstract class PhabricatorProjectUserListView extends AphrontView {
private $project;
private $userPHIDs;
private $limit;
private $background;
public function setProject(PhabricatorProject $project) {
$this->project = $project;
return $this;
}
public function getProject() {
return $this->project;
}
public function setUserPHIDs(array $user_phids) {
$this->userPHIDs = $user_phids;
return $this;
}
public function getUserPHIDs() {
return $this->userPHIDs;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function getLimit() {
return $this->limit;
}
public function setBackground($color) {
$this->background = $color;
return $this;
}
abstract protected function canEditList();
abstract protected function getNoDataString();
abstract protected function getRemoveURI($phid);
abstract protected function getHeaderText();
public function render() {
$viewer = $this->getUser();
$project = $this->getProject();
$user_phids = $this->getUserPHIDs();
$can_edit = $this->canEditList();
$no_data = $this->getNoDataString();
$list = id(new PHUIObjectItemListView())
->setNoDataString($no_data);
$limit = $this->getLimit();
// If we're showing everything, show oldest to newest. If we're showing
// only a slice, show newest to oldest.
if (!$limit) {
$user_phids = array_reverse($user_phids);
}
$handles = $viewer->loadHandles($user_phids);
// Always put the viewer first if they are on the list.
$user_phids = array_fuse($user_phids);
$user_phids =
array_select_keys($user_phids, array($viewer->getPHID())) +
$user_phids;
if ($limit) {
$render_phids = array_slice($user_phids, 0, $limit);
} else {
$render_phids = $user_phids;
}
foreach ($render_phids as $user_phid) {
$handle = $handles[$user_phid];
$item = id(new PHUIObjectItemView())
->setHeader($handle->getFullName())
->setHref($handle->getURI())
->setImageURI($handle->getImageURI());
$icon = id(new PHUIIconView())
- ->setIconFont($handle->getIcon().' lightbluetext');
+ ->setIcon($handle->getIcon().' lightbluetext');
$subtitle = $handle->getSubtitle();
$item->addAttribute(array($icon, ' ', $subtitle));
if ($can_edit && !$limit) {
$remove_uri = $this->getRemoveURI($user_phid);
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setName(pht('Remove'))
->setHref($remove_uri)
->setWorkflow(true));
}
$list->addItem($item);
}
if ($user_phids) {
$header_text = pht(
'%s (%s)',
$this->getHeaderText(),
phutil_count($user_phids));
} else {
$header_text = $this->getHeaderText();
}
$id = $project->getID();
$header = id(new PHUIHeaderView())
->setHeader($header_text);
if ($limit) {
$header->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon(
id(new PHUIIconView())
- ->setIconFont('fa-list-ul'))
+ ->setIcon('fa-list-ul'))
->setText(pht('View All'))
->setHref("/project/members/{$id}/"));
}
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($list);
if ($this->background) {
$box->setBackground($this->background);
}
return $box;
}
}
diff --git a/src/applications/search/engine/PhabricatorProfilePanelEngine.php b/src/applications/search/engine/PhabricatorProfilePanelEngine.php
index 0910c8f74b..09307cd340 100644
--- a/src/applications/search/engine/PhabricatorProfilePanelEngine.php
+++ b/src/applications/search/engine/PhabricatorProfilePanelEngine.php
@@ -1,955 +1,955 @@
<?php
abstract class PhabricatorProfilePanelEngine extends Phobject {
private $viewer;
private $profileObject;
private $panels;
private $defaultPanel;
private $controller;
private $navigation;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function setProfileObject($profile_object) {
$this->profileObject = $profile_object;
return $this;
}
public function getProfileObject() {
return $this->profileObject;
}
public function setController(PhabricatorController $controller) {
$this->controller = $controller;
return $this;
}
public function getController() {
return $this->controller;
}
private function setDefaultPanel(
PhabricatorProfilePanelConfiguration $default_panel) {
$this->defaultPanel = $default_panel;
return $this;
}
public function getDefaultPanel() {
$this->loadPanels();
return $this->defaultPanel;
}
abstract protected function getPanelURI($path);
abstract protected function isPanelEngineConfigurable();
public function buildResponse() {
$controller = $this->getController();
$viewer = $controller->getViewer();
$this->setViewer($viewer);
$request = $controller->getRequest();
$panel_action = $request->getURIData('panelAction');
// If the engine is not configurable, don't respond to any of the editing
// or configuration routes.
if (!$this->isPanelEngineConfigurable()) {
switch ($panel_action) {
case 'view':
break;
default:
return new Aphront404Response();
}
}
$panel_id = $request->getURIData('panelID');
$panel_list = $this->loadPanels();
$selected_panel = null;
if (strlen($panel_id)) {
$panel_id_int = (int)$panel_id;
foreach ($panel_list as $panel) {
if ($panel_id_int) {
if ((int)$panel->getID() === $panel_id_int) {
$selected_panel = $panel;
break;
}
}
$builtin_key = $panel->getBuiltinKey();
if ($builtin_key === (string)$panel_id) {
$selected_panel = $panel;
break;
}
}
}
switch ($panel_action) {
case 'view':
case 'info':
case 'hide':
case 'default':
case 'builtin':
if (!$selected_panel) {
return new Aphront404Response();
}
break;
}
$navigation = $this->buildNavigation();
$navigation->selectFilter('panel.configure');
$crumbs = $controller->buildApplicationCrumbsForEditEngine();
switch ($panel_action) {
case 'view':
$content = $this->buildPanelViewContent($selected_panel);
break;
case 'configure':
$content = $this->buildPanelConfigureContent($panel_list);
$crumbs->addTextCrumb(pht('Configure Menu'));
break;
case 'reorder':
$content = $this->buildPanelReorderContent($panel_list);
break;
case 'new':
$panel_key = $request->getURIData('panelKey');
$content = $this->buildPanelNewContent($panel_key);
break;
case 'builtin':
$content = $this->buildPanelBuiltinContent($selected_panel);
break;
case 'hide':
$content = $this->buildPanelHideContent($selected_panel);
break;
case 'default':
$content = $this->buildPanelDefaultContent(
$selected_panel,
$panel_list);
break;
case 'edit':
$content = $this->buildPanelEditContent();
break;
default:
throw new Exception(
pht(
'Unsupported panel action "%s".',
$panel_action));
}
if ($content instanceof AphrontResponse) {
return $content;
}
if ($content instanceof AphrontResponseProducerInterface) {
return $content;
}
return $controller->newPage()
->setTitle(pht('Profile Stuff'))
->setNavigation($navigation)
->setCrumbs($crumbs)
->appendChild($content);
}
public function buildNavigation() {
if ($this->navigation) {
return $this->navigation;
}
$nav = id(new AphrontSideNavFilterView())
->setIsProfileMenu(true)
->setBaseURI(new PhutilURI($this->getPanelURI('')));
$panels = $this->getPanels();
foreach ($panels as $panel) {
if ($panel->isDisabled()) {
continue;
}
$items = $panel->buildNavigationMenuItems();
foreach ($items as $item) {
$this->validateNavigationMenuItem($item);
}
// If the panel produced only a single item which does not otherwise
// have a key, try to automatically assign it a reasonable key. This
// makes selecting the correct item simpler.
if (count($items) == 1) {
$item = head($items);
if ($item->getKey() === null) {
$builtin_key = $panel->getBuiltinKey();
$panel_phid = $panel->getPHID();
if ($builtin_key !== null) {
$item->setKey($builtin_key);
} else if ($panel_phid !== null) {
$item->setKey($panel_phid);
}
}
}
foreach ($items as $item) {
$nav->addMenuItem($item);
}
}
$more_items = $this->newAutomaticMenuItems($nav);
foreach ($more_items as $item) {
$nav->addMenuItem($item);
}
$nav->selectFilter(null);
$this->navigation = $nav;
return $this->navigation;
}
private function getPanels() {
if ($this->panels === null) {
$this->panels = $this->loadPanels();
}
return $this->panels;
}
private function loadPanels() {
$viewer = $this->getViewer();
$object = $this->getProfileObject();
$panels = $this->loadBuiltinProfilePanels();
$stored_panels = id(new PhabricatorProfilePanelConfigurationQuery())
->setViewer($viewer)
->withProfilePHIDs(array($object->getPHID()))
->execute();
// Merge the stored panels into the builtin panels. If a builtin panel has
// a stored version, replace the defaults with the stored changes.
foreach ($stored_panels as $stored_panel) {
$builtin_key = $stored_panel->getBuiltinKey();
if ($builtin_key !== null) {
// If this builtin actually exists, replace the builtin with the
// stored configuration. Otherwise, we're just going to drop the
// stored config: it corresponds to an out-of-date or uninstalled
// panel.
if (isset($panels[$builtin_key])) {
$panels[$builtin_key] = $stored_panel;
} else {
continue;
}
} else {
$panels[] = $stored_panel;
}
}
foreach ($panels as $panel) {
$impl = $panel->getPanel();
$impl->setViewer($viewer);
}
$panels = msort($panels, 'getSortKey');
// Normalize keys since callers shouldn't rely on this array being
// partially keyed.
$panels = array_values($panels);
// Make sure exactly one valid panel is marked as default.
$default = null;
$first = null;
foreach ($panels as $panel) {
if (!$panel->canMakeDefault()) {
continue;
}
if ($panel->isDefault()) {
$default = $panel;
break;
}
if ($first === null) {
$first = $panel;
}
}
if (!$default) {
$default = $first;
}
if ($default) {
$this->setDefaultPanel($default);
}
return $panels;
}
private function loadBuiltinProfilePanels() {
$object = $this->getProfileObject();
$builtins = $this->getBuiltinProfilePanels($object);
$panels = PhabricatorProfilePanel::getAllPanels();
$order = 1;
$map = array();
foreach ($builtins as $builtin) {
$builtin_key = $builtin->getBuiltinKey();
if (!$builtin_key) {
throw new Exception(
pht(
'Object produced a builtin panel with no builtin panel key! '.
'Builtin panels must have a unique key.'));
}
if (isset($map[$builtin_key])) {
throw new Exception(
pht(
'Object produced two panels with the same builtin key ("%s"). '.
'Each panel must have a unique builtin key.',
$builtin_key));
}
$panel_key = $builtin->getPanelKey();
$panel = idx($panels, $panel_key);
if (!$panel) {
throw new Exception(
pht(
'Builtin panel ("%s") specifies a bad panel key ("%s"); there '.
'is no corresponding panel implementation available.',
$builtin_key,
$panel_key));
}
$builtin
->setProfilePHID($object->getPHID())
->attachPanel($panel)
->attachProfileObject($object)
->setPanelOrder($order);
$map[$builtin_key] = $builtin;
$order++;
}
return $map;
}
private function validateNavigationMenuItem($item) {
if (!($item instanceof PHUIListItemView)) {
throw new Exception(
pht(
'Expected buildNavigationMenuItems() to return a list of '.
'PHUIListItemView objects, but got a surprise.'));
}
}
private function newAutomaticMenuItems(AphrontSideNavFilterView $nav) {
$items = array();
// NOTE: We're adding a spacer item for the fixed footer, so that if the
// menu taller than the page content you can still scroll down the page far
// enough to access the last item without the content being obscured by the
// fixed items.
$items[] = id(new PHUIListItemView())
->setHideInApplicationMenu(true)
->addClass('phui-profile-menu-spacer');
$collapse_id = celerity_generate_unique_node_id();
$viewer = $this->getViewer();
$collapse_key =
PhabricatorUserPreferences::PREFERENCE_PROFILE_MENU_COLLAPSED;
$preferences = $viewer->loadPreferences();
$is_collapsed = $preferences->getPreference($collapse_key, false);
if ($is_collapsed) {
$nav->addClass('phui-profile-menu-collapsed');
} else {
$nav->addClass('phui-profile-menu-expanded');
}
if ($viewer->isLoggedIn()) {
$settings_uri = '/settings/adjust/?key='.$collapse_key;
} else {
$settings_uri = null;
}
Javelin::initBehavior(
'phui-profile-menu',
array(
'menuID' => $nav->getMainID(),
'collapseID' => $collapse_id,
'isCollapsed' => (bool)$is_collapsed,
'settingsURI' => $settings_uri,
));
$collapse_icon = id(new PHUIIconCircleView())
->addClass('phui-list-item-icon')
->addClass('phui-profile-menu-visible-when-expanded')
- ->setIconFont('fa-chevron-left');
+ ->setIcon('fa-chevron-left');
$expand_icon = id(new PHUIIconCircleView())
->addClass('phui-list-item-icon')
->addClass('phui-profile-menu-visible-when-collapsed')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Expand'),
'align' => 'E',
))
- ->setIconFont('fa-chevron-right');
+ ->setIcon('fa-chevron-right');
$items[] = id(new PHUIListItemView())
->setName('Collapse')
->addIcon($collapse_icon)
->addIcon($expand_icon)
->setID($collapse_id)
->addClass('phui-profile-menu-footer')
->addClass('phui-profile-menu-footer-1')
->setHideInApplicationMenu(true)
->setHref('#');
return $items;
}
public function getConfigureURI() {
return $this->getPanelURI('configure/');
}
private function buildPanelReorderContent(array $panels) {
$viewer = $this->getViewer();
$object = $this->getProfileObject();
PhabricatorPolicyFilter::requireCapability(
$viewer,
$object,
PhabricatorPolicyCapability::CAN_EDIT);
$controller = $this->getController();
$request = $controller->getRequest();
$request->validateCSRF();
$order = $request->getStrList('order');
$by_builtin = array();
$by_id = array();
foreach ($panels as $key => $panel) {
$id = $panel->getID();
if ($id) {
$by_id[$id] = $key;
continue;
}
$builtin_key = $panel->getBuiltinKey();
if ($builtin_key) {
$by_builtin[$builtin_key] = $key;
continue;
}
}
$key_order = array();
foreach ($order as $order_item) {
if (isset($by_id[$order_item])) {
$key_order[] = $by_id[$order_item];
continue;
}
if (isset($by_builtin[$order_item])) {
$key_order[] = $by_builtin[$order_item];
continue;
}
}
$panels = array_select_keys($panels, $key_order) + $panels;
$type_order =
PhabricatorProfilePanelConfigurationTransaction::TYPE_ORDER;
$order = 1;
foreach ($panels as $panel) {
$xactions = array();
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
->setTransactionType($type_order)
->setNewValue($order);
$editor = id(new PhabricatorProfilePanelEditor())
->setContentSourceFromRequest($request)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->applyTransactions($panel, $xactions);
$order++;
}
return id(new AphrontRedirectResponse())
->setURI($this->getConfigureURI());
}
private function buildPanelConfigureContent(array $panels) {
$viewer = $this->getViewer();
$object = $this->getProfileObject();
PhabricatorPolicyFilter::requireCapability(
$viewer,
$object,
PhabricatorPolicyCapability::CAN_EDIT);
$list_id = celerity_generate_unique_node_id();
Javelin::initBehavior(
'reorder-profile-menu-items',
array(
'listID' => $list_id,
'orderURI' => $this->getPanelURI('reorder/'),
));
$list = id(new PHUIObjectItemListView())
->setID($list_id);
foreach ($panels as $panel) {
$id = $panel->getID();
$builtin_key = $panel->getBuiltinKey();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$panel,
PhabricatorPolicyCapability::CAN_EDIT);
$item = id(new PHUIObjectItemView());
$name = $panel->getDisplayName();
$type = $panel->getPanelTypeName();
if (!strlen(trim($name))) {
$name = pht('Untitled "%s" Item', $type);
}
$item->setHeader($name);
$item->addAttribute($type);
if ($can_edit) {
$item
->setGrippable(true)
->addSigil('profile-menu-item')
->setMetadata(
array(
'key' => nonempty($id, $builtin_key),
));
if ($id) {
$default_uri = $this->getPanelURI("default/{$id}/");
} else {
$default_uri = $this->getPanelURI("default/{$builtin_key}/");
}
if ($panel->isDefault()) {
$default_icon = 'fa-thumb-tack green';
$default_text = pht('Current Default');
} else if ($panel->canMakeDefault()) {
$default_icon = 'fa-thumb-tack';
$default_text = pht('Make Default');
} else {
$default_text = null;
}
if ($default_text !== null) {
$item->addAction(
id(new PHUIListItemView())
->setHref($default_uri)
->setWorkflow(true)
->setName($default_text)
->setIcon($default_icon));
}
if ($id) {
$item->setHref($this->getPanelURI("edit/{$id}/"));
$hide_uri = $this->getPanelURI("hide/{$id}/");
} else {
$item->setHref($this->getPanelURI("builtin/{$builtin_key}/"));
$hide_uri = $this->getPanelURI("hide/{$builtin_key}/");
}
if ($panel->isDisabled()) {
$hide_icon = 'fa-plus';
$hide_text = pht('Enable');
} else if ($panel->getBuiltinKey() !== null) {
$hide_icon = 'fa-times';
$hide_text = pht('Disable');
} else {
$hide_icon = 'fa-times';
$hide_text = pht('Delete');
}
$can_disable = $panel->canHidePanel();
$item->addAction(
id(new PHUIListItemView())
->setHref($hide_uri)
->setWorkflow(true)
->setDisabled(!$can_disable)
->setName($hide_text)
->setIcon($hide_icon));
}
if ($panel->isDisabled()) {
$item->setDisabled(true);
}
$list->addItem($item);
}
$action_view = id(new PhabricatorActionListView())
->setUser($viewer);
$panel_types = PhabricatorProfilePanel::getAllPanels();
$action_view->addAction(
id(new PhabricatorActionView())
->setLabel(true)
->setName(pht('Add New Menu Item...')));
foreach ($panel_types as $panel_type) {
if (!$panel_type->canAddToObject($object)) {
continue;
}
$panel_key = $panel_type->getPanelKey();
$action_view->addAction(
id(new PhabricatorActionView())
->setIcon($panel_type->getPanelTypeIcon())
->setName($panel_type->getPanelTypeName())
->setHref($this->getPanelURI("new/{$panel_key}/")));
}
$action_view->addAction(
id(new PhabricatorActionView())
->setLabel(true)
->setName(pht('Documentation')));
$doc_link = PhabricatorEnv::getDoclink('Profile Menu User Guide');
$doc_name = pht('Profile Menu User Guide');
$action_view->addAction(
id(new PhabricatorActionView())
->setIcon('fa-book')
->setHref($doc_link)
->setName($doc_name));
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Configure Menu'))
->setHref('#')
- ->setIconFont('fa-gear')
+ ->setIcon('fa-gear')
->setDropdownMenu($action_view);
$header = id(new PHUIHeaderView())
->setHeader(pht('Profile Menu Items'))
->addActionLink($action_button);
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($list);
return $box;
}
private function buildPanelNewContent($panel_key) {
$panel_types = PhabricatorProfilePanel::getAllPanels();
$panel_type = idx($panel_types, $panel_key);
if (!$panel_type) {
return new Aphront404Response();
}
$object = $this->getProfileObject();
if (!$panel_type->canAddToObject($object)) {
return new Aphront404Response();
}
$configuration =
PhabricatorProfilePanelConfiguration::initializeNewPanelConfiguration(
$object,
$panel_type);
$viewer = $this->getViewer();
PhabricatorPolicyFilter::requireCapability(
$viewer,
$configuration,
PhabricatorPolicyCapability::CAN_EDIT);
$controller = $this->getController();
return id(new PhabricatorProfilePanelEditEngine())
->setPanelEngine($this)
->setProfileObject($object)
->setNewPanelConfiguration($configuration)
->setController($controller)
->buildResponse();
}
private function buildPanelEditContent() {
$viewer = $this->getViewer();
$object = $this->getProfileObject();
$controller = $this->getController();
return id(new PhabricatorProfilePanelEditEngine())
->setPanelEngine($this)
->setProfileObject($object)
->setController($controller)
->buildResponse();
}
private function buildPanelBuiltinContent(
PhabricatorProfilePanelConfiguration $configuration) {
// If this builtin panel has already been persisted, redirect to the
// edit page.
$id = $configuration->getID();
if ($id) {
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI("edit/{$id}/"));
}
// Otherwise, act like we're creating a new panel, we're just starting
// with the builtin template.
$viewer = $this->getViewer();
PhabricatorPolicyFilter::requireCapability(
$viewer,
$configuration,
PhabricatorPolicyCapability::CAN_EDIT);
$object = $this->getProfileObject();
$controller = $this->getController();
return id(new PhabricatorProfilePanelEditEngine())
->setIsBuiltin(true)
->setPanelEngine($this)
->setProfileObject($object)
->setNewPanelConfiguration($configuration)
->setController($controller)
->buildResponse();
}
private function buildPanelHideContent(
PhabricatorProfilePanelConfiguration $configuration) {
$controller = $this->getController();
$request = $controller->getRequest();
$viewer = $this->getViewer();
PhabricatorPolicyFilter::requireCapability(
$viewer,
$configuration,
PhabricatorPolicyCapability::CAN_EDIT);
if (!$configuration->canHidePanel()) {
return $controller->newDialog()
->setTitle(pht('Mandatory Panel'))
->appendParagraph(
pht('This panel is very important, and can not be disabled.'))
->addCancelButton($this->getConfigureURI());
}
if ($configuration->getBuiltinKey() === null) {
$new_value = null;
$title = pht('Delete Menu Item');
$body = pht('Delete this menu item?');
$button = pht('Delete Menu Item');
} else if ($configuration->isDisabled()) {
$new_value = PhabricatorProfilePanelConfiguration::VISIBILITY_VISIBLE;
$title = pht('Enable Menu Item');
$body = pht(
'Enable this menu item? It will appear in the menu again.');
$button = pht('Enable Menu Item');
} else {
$new_value = PhabricatorProfilePanelConfiguration::VISIBILITY_DISABLED;
$title = pht('Disable Menu Item');
$body = pht(
'Disable this menu item? It will no longer appear in the menu, but '.
'you can re-enable it later.');
$button = pht('Disable Menu Item');
}
$v_visibility = $configuration->getVisibility();
if ($request->isFormPost()) {
if ($new_value === null) {
$configuration->delete();
} else {
$type_visibility =
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
$xactions = array();
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
->setTransactionType($type_visibility)
->setNewValue($new_value);
$editor = id(new PhabricatorProfilePanelEditor())
->setContentSourceFromRequest($request)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->applyTransactions($configuration, $xactions);
}
return id(new AphrontRedirectResponse())
->setURI($this->getConfigureURI());
}
return $controller->newDialog()
->setTitle($title)
->appendParagraph($body)
->addCancelButton($this->getConfigureURI())
->addSubmitButton($button);
}
private function buildPanelDefaultContent(
PhabricatorProfilePanelConfiguration $configuration,
array $panels) {
$controller = $this->getController();
$request = $controller->getRequest();
$viewer = $this->getViewer();
PhabricatorPolicyFilter::requireCapability(
$viewer,
$configuration,
PhabricatorPolicyCapability::CAN_EDIT);
$done_uri = $this->getConfigureURI();
if (!$configuration->canMakeDefault()) {
return $controller->newDialog()
->setTitle(pht('Not Defaultable'))
->appendParagraph(
pht(
'This item can not be set as the default item. This is usually '.
'because the item has no page of its own, or links to an '.
'external page.'))
->addCancelButton($done_uri);
}
if ($configuration->isDefault()) {
return $controller->newDialog()
->setTitle(pht('Already Default'))
->appendParagraph(
pht(
'This item is already set as the default item for this menu.'))
->addCancelButton($done_uri);
}
if ($request->isFormPost()) {
$key = $configuration->getID();
if (!$key) {
$key = $configuration->getBuiltinKey();
}
$this->adjustDefault($key);
return id(new AphrontRedirectResponse())
->setURI($done_uri);
}
return $controller->newDialog()
->setTitle(pht('Make Default'))
->appendParagraph(
pht(
'Set this item as the default for this menu? Users arriving on '.
'this page will be shown the content of this item by default.'))
->addCancelButton($done_uri)
->addSubmitButton(pht('Make Default'));
}
protected function newPanel() {
return PhabricatorProfilePanelConfiguration::initializeNewBuiltin();
}
public function adjustDefault($key) {
$controller = $this->getController();
$request = $controller->getRequest();
$viewer = $request->getViewer();
$panels = $this->loadPanels();
// To adjust the default panel, we first change any existing panels that
// are marked as defaults to "visible", then make the new default panel
// the default.
$default = array();
$visible = array();
foreach ($panels as $panel) {
$builtin_key = $panel->getBuiltinKey();
$id = $panel->getID();
$is_target =
(($builtin_key !== null) && ($builtin_key === $key)) ||
(($id !== null) && ($id === (int)$key));
if ($is_target) {
if (!$panel->isDefault()) {
$default[] = $panel;
}
} else {
if ($panel->isDefault()) {
$visible[] = $panel;
}
}
}
$type_visibility =
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
$v_visible = PhabricatorProfilePanelConfiguration::VISIBILITY_VISIBLE;
$v_default = PhabricatorProfilePanelConfiguration::VISIBILITY_DEFAULT;
$apply = array(
array($v_visible, $visible),
array($v_default, $default),
);
foreach ($apply as $group) {
list($value, $panels) = $group;
foreach ($panels as $panel) {
$xactions = array();
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
->setTransactionType($type_visibility)
->setNewValue($value);
$editor = id(new PhabricatorProfilePanelEditor())
->setContentSourceFromRequest($request)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->applyTransactions($panel, $xactions);
}
}
return $this;
}
}
diff --git a/src/applications/search/profilepanel/PhabricatorMotivatorProfilePanel.php b/src/applications/search/profilepanel/PhabricatorMotivatorProfilePanel.php
index 73668fdd41..3537520903 100644
--- a/src/applications/search/profilepanel/PhabricatorMotivatorProfilePanel.php
+++ b/src/applications/search/profilepanel/PhabricatorMotivatorProfilePanel.php
@@ -1,151 +1,151 @@
<?php
final class PhabricatorMotivatorProfilePanel
extends PhabricatorProfilePanel {
const PANELKEY = 'motivator';
public function getPanelTypeIcon() {
return 'fa-coffee';
}
public function getPanelTypeName() {
return pht('Motivator');
}
public function canAddToObject($object) {
return true;
}
public function getDisplayName(
PhabricatorProfilePanelConfiguration $config) {
$options = $this->getOptions();
$name = idx($options, $config->getPanelProperty('source'));
if ($name !== null) {
return pht('Motivator: %s', $name);
} else {
return pht('Motivator');
}
}
public function buildEditEngineFields(
PhabricatorProfilePanelConfiguration $config) {
return array(
id(new PhabricatorInstructionsEditField())
->setValue(
pht(
'Motivate your team with inspirational quotes from great minds. '.
'This panel shows a new quote every day.')),
id(new PhabricatorSelectEditField())
->setKey('source')
->setLabel(pht('Source'))
->setOptions($this->getOptions()),
);
}
private function getOptions() {
return array(
'catfacts' => pht('Cat Facts'),
);
}
protected function newNavigationMenuItems(
PhabricatorProfilePanelConfiguration $config) {
$source = $config->getPanelProperty('source');
switch ($source) {
case 'catfacts':
default:
$facts = $this->getCatFacts();
break;
}
$fact = $this->selectFact($facts);
switch ($source) {
case 'catfacts':
default:
$fact = array(
- id(new PHUIIconView())->setIconFont('fa-paw'),
+ id(new PHUIIconView())->setIcon('fa-paw'),
' ',
$fact,
);
break;
}
$fact = phutil_tag(
'div',
array(
'class' => 'phui-motivator',
),
$fact);
$item = $this->newItem()
->appendChild($fact);
return array(
$item,
);
}
private function getCatFacts() {
return array(
pht('Cats purr when they are happy, upset, or asleep.'),
pht('The first cats evolved on the savanah about 8,000 years ago.'),
pht(
'Cats have a tail, two feet, between one and three ears, and two '.
'other feet.'),
pht('Cats use their keen sense of smell to avoid feeling empathy.'),
pht('The first cats evolved in swamps about 65 years ago.'),
pht(
'You can tell how warm a cat is by examining the coloration: cooler '.
'areas are darker.'),
pht(
'Cat tails are flexible because they contain thousands of tiny '.
'bones.'),
pht(
'A cattail is a wetland plant with an appearance that resembles '.
'the tail of a cat.'),
pht(
'Cats must eat a diet rich in fish to replace the tiny bones in '.
'their tails.'),
pht('Cats are stealthy predators and nearly invisible to radar.'),
pht(
'Cats use a special type of magnetism to help them land on their '.
'feet.'),
pht(
'A cat can run seven times faster than a human, but only for a '.
'short distance.'),
pht(
'The largest recorded cat was nearly 11 inches long from nose to '.
'tail.'),
pht(
'Not all cats can retract their claws, but most of them can.'),
pht(
'In the wild, cats and racoons sometimes hunt together in packs.'),
pht(
'The Spanish word for cat is "cato". The biggest cat is called '.
'"el cato".'),
pht(
'The Japanese word for cat is "kome", which is also the word for '.
'rice. Japanese cats love to eat rice, so the two are synonymous.'),
);
}
private function selectFact(array $facts) {
// This is a simple pseudorandom number generator that avoids touching
// srand(), because it would seed it to a highly predictable value. It
// selects a new fact every day.
$seed = ((int)date('Y') * 366) + (int)date('z');
for ($ii = 0; $ii < 32; $ii++) {
$seed = ((1664525 * $seed) + 1013904223) % (1 << 31);
}
return $facts[$seed % count($facts)];
}
}
diff --git a/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php b/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php
index ff1e39577a..bc7538f6bd 100644
--- a/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php
@@ -1,159 +1,157 @@
<?php
final class PhabricatorDesktopNotificationsSettingsPanel
extends PhabricatorSettingsPanel {
public function isEnabled() {
return PhabricatorEnv::getEnvConfig('notification.enabled') &&
PhabricatorApplication::isClassInstalled(
'PhabricatorNotificationsApplication');
}
public function getPanelKey() {
return 'desktopnotifications';
}
public function getPanelName() {
return pht('Desktop Notifications');
}
public function getPanelGroup() {
return pht('Application Settings');
}
public function processRequest(AphrontRequest $request) {
$user = $request->getUser();
$preferences = $user->loadPreferences();
$pref = PhabricatorUserPreferences::PREFERENCE_DESKTOP_NOTIFICATIONS;
if ($request->isFormPost()) {
$notifications = $request->getInt($pref);
$preferences->setPreference($pref, $notifications);
$preferences->save();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?saved=true'));
}
$title = pht('Desktop Notifications');
$control_id = celerity_generate_unique_node_id();
$status_id = celerity_generate_unique_node_id();
$browser_status_id = celerity_generate_unique_node_id();
$cancel_ask = pht(
'The dialog asking for permission to send desktop notifications was '.
'closed without granting permission. Only application notifications '.
'will be sent.');
$accept_ask = pht(
'Click "Save Preference" to persist these changes.');
$reject_ask = pht(
'Permission for desktop notifications was denied. Only application '.
'notifications will be sent.');
$no_support = pht(
'This web browser does not support desktop notifications. Only '.
'application notifications will be sent for this browser regardless of '.
'this preference.');
$default_status = phutil_tag(
'span',
array(),
array(
pht('This browser has not yet granted permission to send desktop '.
'notifications for this Phabricator instance.'),
phutil_tag('br'),
phutil_tag('br'),
javelin_tag(
'button',
array(
'sigil' => 'desktop-notifications-permission-button',
'class' => 'green',
),
pht('Grant Permission')),
));
$granted_status = phutil_tag(
'span',
array(),
pht('This browser has been granted permission to send desktop '.
'notifications for this Phabricator instance.'));
$denied_status = phutil_tag(
'span',
array(),
pht('This browser has denied permission to send desktop notifications '.
'for this Phabricator instance. Consult your browser settings / '.
'documentation to figure out how to clear this setting, do so, '.
'and then re-visit this page to grant permission.'));
$status_box = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->setID($status_id)
->setIsHidden(true)
->appendChild($accept_ask);
$control_config = array(
'controlID' => $control_id,
'statusID' => $status_id,
'browserStatusID' => $browser_status_id,
'defaultMode' => 0,
'desktopMode' => 1,
'cancelAsk' => $cancel_ask,
'grantedAsk' => $accept_ask,
'deniedAsk' => $reject_ask,
'defaultStatus' => $default_status,
'deniedStatus' => $denied_status,
'grantedStatus' => $granted_status,
'noSupport' => $no_support,
);
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(
id(new AphrontFormSelectControl())
->setLabel($title)
->setControlID($control_id)
->setName($pref)
->setValue($preferences->getPreference($pref))
->setOptions(
array(
1 => pht('Send Desktop Notifications Too'),
0 => pht('Send Application Notifications Only'),
))
->setCaption(
pht(
'Should Phabricator send desktop notifications? These are sent '.
'in addition to the notifications within the Phabricator '.
'application.'))
->initBehavior(
'desktop-notifications-control',
$control_config))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save Preference')));
- $test_icon = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle');
$test_button = id(new PHUIButtonView())
->setTag('a')
->setWorkflow(true)
->setText(pht('Send Test Notification'))
->setHref('/notification/test/')
- ->setIcon($test_icon);
+ ->setIcon('fa-exclamation-triangle');
$form_box = id(new PHUIObjectBoxView())
->setHeader(
id(new PHUIHeaderView())
->setHeader(pht('Desktop Notifications'))
->addActionLink($test_button))
->setForm($form)
->setInfoView($status_box)
->setFormSaved($request->getBool('saved'));
$browser_status_box = id(new PHUIInfoView())
->setID($browser_status_id)
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->setIsHidden(true)
->appendChild($default_status);
return array(
$form_box,
$browser_status_box,
);
}
}
diff --git a/src/applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php b/src/applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php
index fa2694848d..464214dc73 100644
--- a/src/applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php
@@ -1,411 +1,408 @@
<?php
final class PhabricatorEmailAddressesSettingsPanel
extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'email';
}
public function getPanelName() {
return pht('Email Addresses');
}
public function getPanelGroup() {
return pht('Email');
}
public function isEditableByAdministrators() {
if ($this->getUser()->getIsMailingList()) {
return true;
}
return false;
}
public function processRequest(AphrontRequest $request) {
$user = $this->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_tag(
'a',
array(
'class' => 'button small grey',
'href' => $uri->alter('verify', $email->getID()),
'sigil' => 'workflow',
),
pht('Verify'));
$button_make_primary = javelin_tag(
'a',
array(
'class' => 'button small grey',
'href' => $uri->alter('primary', $email->getID()),
'sigil' => 'workflow',
),
pht('Make Primary'));
$button_remove = javelin_tag(
'a',
array(
'class' => 'button small grey',
'href' => $uri->alter('delete', $email->getID()),
'sigil' => 'workflow',
),
pht('Remove'));
$button_primary = phutil_tag(
'a',
array(
'class' => 'button small disabled',
),
pht('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(
$email->getAddress(),
$action,
$remove,
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
pht('Email'),
pht('Status'),
pht('Remove'),
));
$table->setColumnClasses(
array(
'wide',
'action',
'action',
));
$table->setRowClasses($rowc);
$table->setColumnVisibility(
array(
true,
true,
$editable,
));
$view = new PHUIObjectBoxView();
$header = new PHUIHeaderView();
$header->setHeader(pht('Email Addresses'));
if ($editable) {
- $icon = id(new PHUIIconView())
- ->setIconFont('fa-plus');
-
$button = new PHUIButtonView();
$button->setText(pht('Add New Address'));
$button->setTag('a');
$button->setHref($uri->alter('new', 'true'));
- $button->setIcon($icon);
+ $button->setIcon('fa-plus');
$button->addSigil('workflow');
$header->addActionLink($button);
}
$view->setHeader($header);
$view->setTable($table);
return $view;
}
private function returnNewAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
$new) {
$user = $this->getUser();
$viewer = $this->getViewer();
$e_email = true;
$email = null;
$errors = array();
if ($request->isDialogFormPost()) {
$email = trim($request->getStr('email'));
if ($new == 'verify') {
// The user clicked "Done" from the "an email has been sent" dialog.
return id(new AphrontReloadResponse())->setURI($uri);
}
PhabricatorSystemActionEngine::willTakeAction(
array($viewer->getPHID()),
new PhabricatorSettingsAddEmailAction(),
1);
if (!strlen($email)) {
$e_email = pht('Required');
$errors[] = pht('Email is required.');
} else if (!PhabricatorUserEmail::isValidAddress($email)) {
$e_email = pht('Invalid');
$errors[] = PhabricatorUserEmail::describeValidAddresses();
} else if (!PhabricatorUserEmail::isAllowedAddress($email)) {
$e_email = pht('Disallowed');
$errors[] = PhabricatorUserEmail::describeAllowedAddresses();
}
if ($e_email === true) {
$application_email = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withAddresses(array($email))
->executeOne();
if ($application_email) {
$e_email = pht('In Use');
$errors[] = $application_email->getInUseMessage();
}
}
if (!$errors) {
$object = id(new PhabricatorUserEmail())
->setAddress($email)
->setIsVerified(0);
// If an administrator is editing a mailing list, automatically verify
// the address.
if ($viewer->getPHID() != $user->getPHID()) {
if ($viewer->getIsAdmin()) {
$object->setIsVerified(1);
}
}
try {
id(new PhabricatorUserEditor())
->setActor($viewer)
->addEmail($user, $object);
if ($object->getIsVerified()) {
// If we autoverified the address, just reload the page.
return id(new AphrontReloadResponse())->setURI($uri);
}
$object->sendVerificationEmail($user);
$dialog = id(new AphrontDialogView())
->setUser($user)
->addHiddenInput('new', 'verify')
->setTitle(pht('Verification Email Sent'))
->appendChild(phutil_tag('p', array(), pht(
'A verification email has been sent. Click the link in the '.
'email to verify your address.')))
->setSubmitURI($uri)
->addSubmitButton(pht('Done'));
return id(new AphrontDialogResponse())->setDialog($dialog);
} catch (AphrontDuplicateKeyQueryException $ex) {
$e_email = pht('Duplicate');
$errors[] = pht('Another user already has this email.');
}
}
}
if ($errors) {
$errors = id(new PHUIInfoView())
->setErrors($errors);
}
$form = id(new PHUIFormLayoutView())
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Email'))
->setName('email')
->setValue($email)
->setCaption(PhabricatorUserEmail::describeAllowedAddresses())
->setError($e_email));
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('new', 'true')
->setTitle(pht('New Address'))
->appendChild($errors)
->appendChild($form)
->addSubmitButton(pht('Save'))
->addCancelButton($uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function returnDeleteAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
$email_id) {
$user = $this->getUser();
$viewer = $this->getViewer();
// NOTE: You can only delete your own email addresses, and you can not
// delete your primary address.
$email = id(new PhabricatorUserEmail())->loadOneWhere(
'id = %d AND userPHID = %s AND isPrimary = 0',
$email_id,
$user->getPHID());
if (!$email) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
id(new PhabricatorUserEditor())
->setActor($viewer)
->removeEmail($user, $email);
return id(new AphrontRedirectResponse())->setURI($uri);
}
$address = $email->getAddress();
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('delete', $email_id)
->setTitle(pht("Really delete address '%s'?", $address))
->appendParagraph(
pht(
'Are you sure you want to delete this address? You will no '.
'longer be able to use it to login.'))
->appendParagraph(
pht(
'Note: Removing an email address from your account will invalidate '.
'any outstanding password reset links.'))
->addSubmitButton(pht('Delete'))
->addCancelButton($uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function returnVerifyAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
$email_id) {
$user = $this->getUser();
$viewer = $this->getViewer();
// NOTE: You can only send more email for your unverified addresses.
$email = id(new PhabricatorUserEmail())->loadOneWhere(
'id = %d AND userPHID = %s AND isVerified = 0',
$email_id,
$user->getPHID());
if (!$email) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
$email->sendVerificationEmail($user);
return id(new AphrontRedirectResponse())->setURI($uri);
}
$address = $email->getAddress();
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('verify', $email_id)
->setTitle(pht('Send Another Verification Email?'))
->appendChild(phutil_tag('p', array(), pht(
'Send another copy of the verification email to %s?',
$address)))
->addSubmitButton(pht('Send Email'))
->addCancelButton($uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
private function returnPrimaryAddressResponse(
AphrontRequest $request,
PhutilURI $uri,
$email_id) {
$user = $this->getUser();
$viewer = $this->getViewer();
$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
$viewer,
$request,
$this->getPanelURI());
// NOTE: You can only make your own verified addresses primary.
$email = id(new PhabricatorUserEmail())->loadOneWhere(
'id = %d AND userPHID = %s AND isVerified = 1 AND isPrimary = 0',
$email_id,
$user->getPHID());
if (!$email) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
id(new PhabricatorUserEditor())
->setActor($viewer)
->changePrimaryEmail($user, $email);
return id(new AphrontRedirectResponse())->setURI($uri);
}
$address = $email->getAddress();
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('primary', $email_id)
->setTitle(pht('Change primary email address?'))
->appendParagraph(
pht(
'If you change your primary address, Phabricator will send all '.
'email to %s.',
$address))
->appendParagraph(
pht(
'Note: Changing your primary email address will invalidate any '.
'outstanding password reset links.'))
->addSubmitButton(pht('Change Primary Address'))
->addCancelButton($uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
diff --git a/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php b/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php
index c18c4c58d1..eabbc3ff32 100644
--- a/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php
@@ -1,196 +1,194 @@
<?php
final class PhabricatorHomePreferencesSettingsPanel
extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'home';
}
public function getPanelName() {
return pht('Home Page');
}
public function getPanelGroup() {
return pht('Application Settings');
}
public function processRequest(AphrontRequest $request) {
$user = $request->getUser();
$preferences = $user->loadPreferences();
$apps = id(new PhabricatorApplicationQuery())
->setViewer($user)
->withInstalled(true)
->withUnlisted(false)
->withLaunchable(true)
->execute();
$pinned = $preferences->getPinnedApplications($apps, $user);
$app_list = array();
foreach ($pinned as $app) {
if (isset($apps[$app])) {
$app_list[$app] = $apps[$app];
}
}
if ($request->getBool('add')) {
$options = array();
foreach ($apps as $app) {
$options[get_class($app)] = $app->getName();
}
asort($options);
unset($options['PhabricatorApplicationsApplication']);
if ($request->isFormPost()) {
$pin = $request->getStr('pin');
if (isset($options[$pin]) && !in_array($pin, $pinned)) {
$pinned[] = $pin;
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_APP_PINNED,
$pinned);
$preferences->save();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI());
}
}
$options_control = id(new AphrontFormSelectControl())
->setName('pin')
->setLabel(pht('Application'))
->setOptions($options)
->setDisabledOptions(array_keys($app_list));
$form = id(new AphrontFormView())
->setUser($user)
->addHiddenInput('add', 'true')
->appendRemarkupInstructions(
pht('Choose an application to pin to your home page.'))
->appendChild($options_control);
$dialog = id(new AphrontDialogView())
->setUser($user)
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(pht('Pin Application'))
->appendChild($form->buildLayoutView())
->addSubmitButton(pht('Pin Application'))
->addCancelButton($this->getPanelURI());
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$unpin = $request->getStr('unpin');
if ($unpin) {
$app = idx($apps, $unpin);
if ($app) {
if ($request->isFormPost()) {
$pinned = array_diff($pinned, array($unpin));
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_APP_PINNED,
$pinned);
$preferences->save();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI());
}
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht('Unpin Application'))
->appendParagraph(
pht(
'Unpin the %s application from your home page?',
phutil_tag('strong', array(), $app->getName())))
->addSubmitButton(pht('Unpin Application'))
->addCanceLButton($this->getPanelURI());
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}
$order = $request->getStrList('order');
if ($order && $request->validateCSRF()) {
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_APP_PINNED,
$order);
$preferences->save();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI());
}
$list_id = celerity_generate_unique_node_id();
$list = id(new PHUIObjectItemListView())
->setUser($user)
->setID($list_id);
Javelin::initBehavior(
'reorder-applications',
array(
'listID' => $list_id,
'panelURI' => $this->getPanelURI(),
));
foreach ($app_list as $key => $application) {
if ($key == 'PhabricatorApplicationsApplication') {
continue;
}
$icon = $application->getFontIcon();
if (!$icon) {
$icon = 'application';
}
$icon_view = javelin_tag(
'span',
array(
'class' => 'phui-icon-view phui-font-fa '.$icon,
'aural' => false,
),
'');
$item = id(new PHUIObjectItemView())
->setHeader($application->getName())
->setImageIcon($icon_view)
->addAttribute($application->getShortDescription())
->setGrippable(true);
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setHref($this->getPanelURI().'?unpin='.$key)
->setWorkflow(true));
$item->addSigil('pinned-application');
$item->setMetadata(
array(
'applicationClass' => $key,
));
$list->addItem($item);
}
$header = id(new PHUIHeaderView())
->setHeader(pht('Pinned Applications'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setText(pht('Pin Application'))
->setHref($this->getPanelURI().'?add=true')
->setWorkflow(true)
- ->setIcon(
- id(new PHUIIconView())
- ->setIconFont('fa-thumb-tack')));
+ ->setIcon('fa-thumb-tack'));
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($list);
return $box;
}
}
diff --git a/src/applications/settings/panel/PhabricatorMultiFactorSettingsPanel.php b/src/applications/settings/panel/PhabricatorMultiFactorSettingsPanel.php
index 42d5ac4330..9bcfbba3be 100644
--- a/src/applications/settings/panel/PhabricatorMultiFactorSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorMultiFactorSettingsPanel.php
@@ -1,329 +1,325 @@
<?php
final class PhabricatorMultiFactorSettingsPanel
extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'multifactor';
}
public function getPanelName() {
return pht('Multi-Factor Auth');
}
public function getPanelGroup() {
return pht('Authentication');
}
public function processRequest(AphrontRequest $request) {
if ($request->getExists('new')) {
return $this->processNew($request);
}
if ($request->getExists('edit')) {
return $this->processEdit($request);
}
if ($request->getExists('delete')) {
return $this->processDelete($request);
}
$user = $this->getUser();
$viewer = $request->getUser();
$factors = id(new PhabricatorAuthFactorConfig())->loadAllWhere(
'userPHID = %s',
$user->getPHID());
$rows = array();
$rowc = array();
$highlight_id = $request->getInt('id');
foreach ($factors as $factor) {
$impl = $factor->getImplementation();
if ($impl) {
$type = $impl->getFactorName();
} else {
$type = $factor->getFactorKey();
}
if ($factor->getID() == $highlight_id) {
$rowc[] = 'highlighted';
} else {
$rowc[] = null;
}
$rows[] = array(
javelin_tag(
'a',
array(
'href' => $this->getPanelURI('?edit='.$factor->getID()),
'sigil' => 'workflow',
),
$factor->getFactorName()),
$type,
phabricator_datetime($factor->getDateCreated(), $viewer),
javelin_tag(
'a',
array(
'href' => $this->getPanelURI('?delete='.$factor->getID()),
'sigil' => 'workflow',
'class' => 'small grey button',
),
pht('Remove')),
);
}
$table = new AphrontTableView($rows);
$table->setNoDataString(
pht("You haven't added any authentication factors to your account yet."));
$table->setHeaders(
array(
pht('Name'),
pht('Type'),
pht('Created'),
'',
));
$table->setColumnClasses(
array(
'wide pri',
'',
'right',
'action',
));
$table->setRowClasses($rowc);
$table->setDeviceVisibility(
array(
true,
false,
false,
true,
));
$panel = new PHUIObjectBoxView();
$header = new PHUIHeaderView();
$help_uri = PhabricatorEnv::getDoclink(
'User Guide: Multi-Factor Authentication');
- $help_icon = id(new PHUIIconView())
- ->setIconFont('fa-info-circle');
$help_button = id(new PHUIButtonView())
->setText(pht('Help'))
->setHref($help_uri)
->setTag('a')
- ->setIcon($help_icon);
+ ->setIcon('fa-info-circle');
- $create_icon = id(new PHUIIconView())
- ->setIconFont('fa-plus');
$create_button = id(new PHUIButtonView())
->setText(pht('Add Authentication Factor'))
->setHref($this->getPanelURI('?new=true'))
->setTag('a')
->setWorkflow(true)
- ->setIcon($create_icon);
+ ->setIcon('fa-plus');
$header->setHeader(pht('Authentication Factors'));
$header->addActionLink($help_button);
$header->addActionLink($create_button);
$panel->setHeader($header);
$panel->setTable($table);
return $panel;
}
private function processNew(AphrontRequest $request) {
$viewer = $request->getUser();
$user = $this->getUser();
$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
$viewer,
$request,
$this->getPanelURI());
$factors = PhabricatorAuthFactor::getAllFactors();
$form = id(new AphrontFormView())
->setUser($viewer);
$type = $request->getStr('type');
if (empty($factors[$type]) || !$request->isFormPost()) {
$factor = null;
} else {
$factor = $factors[$type];
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('new', true);
if ($factor === null) {
$choice_control = id(new AphrontFormRadioButtonControl())
->setName('type')
->setValue(key($factors));
foreach ($factors as $available_factor) {
$choice_control->addButton(
$available_factor->getFactorKey(),
$available_factor->getFactorName(),
$available_factor->getFactorDescription());
}
$dialog->appendParagraph(
pht(
'Adding an additional authentication factor improves the security '.
'of your account. Choose the type of factor to add:'));
$form
->appendChild($choice_control);
} else {
$dialog->addHiddenInput('type', $type);
$config = $factor->processAddFactorForm(
$form,
$request,
$user);
if ($config) {
$config->save();
$log = PhabricatorUserLog::initializeNewLog(
$viewer,
$user->getPHID(),
PhabricatorUserLog::ACTION_MULTI_ADD);
$log->save();
$user->updateMultiFactorEnrollment();
// Terminate other sessions so they must log in and survive the
// multi-factor auth check.
id(new PhabricatorAuthSessionEngine())->terminateLoginSessions(
$user,
$request->getCookie(PhabricatorCookies::COOKIE_SESSION));
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?id='.$config->getID()));
}
}
$dialog
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(pht('Add Authentication Factor'))
->appendChild($form->buildLayoutView())
->addSubmitButton(pht('Continue'))
->addCancelButton($this->getPanelURI());
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
private function processEdit(AphrontRequest $request) {
$viewer = $request->getUser();
$user = $this->getUser();
$factor = id(new PhabricatorAuthFactorConfig())->loadOneWhere(
'id = %d AND userPHID = %s',
$request->getInt('edit'),
$user->getPHID());
if (!$factor) {
return new Aphront404Response();
}
$e_name = true;
$errors = array();
if ($request->isFormPost()) {
$name = $request->getStr('name');
if (!strlen($name)) {
$e_name = pht('Required');
$errors[] = pht(
'Authentication factors must have a name to identify them.');
}
if (!$errors) {
$factor->setFactorName($name);
$factor->save();
$user->updateMultiFactorEnrollment();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?id='.$factor->getID()));
}
} else {
$name = $factor->getFactorName();
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Name'))
->setValue($name)
->setError($e_name));
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('edit', $factor->getID())
->setTitle(pht('Edit Authentication Factor'))
->setErrors($errors)
->appendChild($form->buildLayoutView())
->addSubmitButton(pht('Save'))
->addCancelButton($this->getPanelURI());
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
private function processDelete(AphrontRequest $request) {
$viewer = $request->getUser();
$user = $this->getUser();
$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
$viewer,
$request,
$this->getPanelURI());
$factor = id(new PhabricatorAuthFactorConfig())->loadOneWhere(
'id = %d AND userPHID = %s',
$request->getInt('delete'),
$user->getPHID());
if (!$factor) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
$factor->delete();
$log = PhabricatorUserLog::initializeNewLog(
$viewer,
$user->getPHID(),
PhabricatorUserLog::ACTION_MULTI_REMOVE);
$log->save();
$user->updateMultiFactorEnrollment();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI());
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->addHiddenInput('delete', $factor->getID())
->setTitle(pht('Delete Authentication Factor'))
->appendParagraph(
pht(
'Really remove the authentication factor %s from your account?',
phutil_tag('strong', array(), $factor->getFactorName())))
->addSubmitButton(pht('Remove Factor'))
->addCancelButton($this->getPanelURI());
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
}
diff --git a/src/applications/settings/panel/PhabricatorSSHKeysSettingsPanel.php b/src/applications/settings/panel/PhabricatorSSHKeysSettingsPanel.php
index 2fa05914ec..0faf620041 100644
--- a/src/applications/settings/panel/PhabricatorSSHKeysSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorSSHKeysSettingsPanel.php
@@ -1,83 +1,79 @@
<?php
final class PhabricatorSSHKeysSettingsPanel extends PhabricatorSettingsPanel {
public function isEditableByAdministrators() {
return true;
}
public function getPanelKey() {
return 'ssh';
}
public function getPanelName() {
return pht('SSH Public Keys');
}
public function getPanelGroup() {
return pht('Authentication');
}
public function isEnabled() {
if ($this->getUser()->getIsMailingList()) {
return false;
}
return true;
}
public function processRequest(AphrontRequest $request) {
$user = $this->getUser();
$viewer = $request->getUser();
$keys = id(new PhabricatorAuthSSHKeyQuery())
->setViewer($viewer)
->withObjectPHIDs(array($user->getPHID()))
->execute();
$table = id(new PhabricatorAuthSSHKeyTableView())
->setUser($viewer)
->setKeys($keys)
->setCanEdit(true)
->setNoDataString(pht("You haven't added any SSH Public Keys."));
$panel = new PHUIObjectBoxView();
$header = new PHUIHeaderView();
- $upload_icon = id(new PHUIIconView())
- ->setIconFont('fa-upload');
$upload_button = id(new PHUIButtonView())
->setText(pht('Upload Public Key'))
->setHref('/auth/sshkey/upload/?objectPHID='.$user->getPHID())
->setWorkflow(true)
->setTag('a')
- ->setIcon($upload_icon);
+ ->setIcon('fa-upload');
try {
PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();
$can_generate = true;
} catch (Exception $ex) {
$can_generate = false;
}
- $generate_icon = id(new PHUIIconView())
- ->setIconFont('fa-lock');
$generate_button = id(new PHUIButtonView())
->setText(pht('Generate Keypair'))
->setHref('/auth/sshkey/generate/?objectPHID='.$user->getPHID())
->setTag('a')
->setWorkflow(true)
->setDisabled(!$can_generate)
- ->setIcon($generate_icon);
+ ->setIcon('fa-lock');
$header->setHeader(pht('SSH Public Keys'));
$header->addActionLink($generate_button);
$header->addActionLink($upload_button);
$panel->setHeader($header);
$panel->setTable($table);
return $panel;
}
}
diff --git a/src/applications/settings/panel/PhabricatorSessionsSettingsPanel.php b/src/applications/settings/panel/PhabricatorSessionsSettingsPanel.php
index 8bb6653471..2d38e76225 100644
--- a/src/applications/settings/panel/PhabricatorSessionsSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorSessionsSettingsPanel.php
@@ -1,149 +1,144 @@
<?php
final class PhabricatorSessionsSettingsPanel extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'sessions';
}
public function getPanelName() {
return pht('Sessions');
}
public function getPanelGroup() {
return pht('Sessions and Logs');
}
public function isEnabled() {
return true;
}
public function processRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$accounts = id(new PhabricatorExternalAccountQuery())
->setViewer($viewer)
->withUserPHIDs(array($viewer->getPHID()))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->execute();
$identity_phids = mpull($accounts, 'getPHID');
$identity_phids[] = $viewer->getPHID();
$sessions = id(new PhabricatorAuthSessionQuery())
->setViewer($viewer)
->withIdentityPHIDs($identity_phids)
->execute();
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($identity_phids)
->execute();
$current_key = PhabricatorHash::digest(
$request->getCookie(PhabricatorCookies::COOKIE_SESSION));
$rows = array();
$rowc = array();
foreach ($sessions as $session) {
$is_current = phutil_hashes_are_identical(
$session->getSessionKey(),
$current_key);
if ($is_current) {
$rowc[] = 'highlighted';
$button = phutil_tag(
'a',
array(
'class' => 'small grey button disabled',
),
pht('Current'));
} else {
$rowc[] = null;
$button = javelin_tag(
'a',
array(
'href' => '/auth/session/terminate/'.$session->getID().'/',
'class' => 'small grey button',
'sigil' => 'workflow',
),
pht('Terminate'));
}
$hisec = ($session->getHighSecurityUntil() - time());
$rows[] = array(
$handles[$session->getUserPHID()]->renderLink(),
substr($session->getSessionKey(), 0, 6),
$session->getType(),
($hisec > 0)
? phutil_format_relative_time($hisec)
: null,
phabricator_datetime($session->getSessionStart(), $viewer),
phabricator_date($session->getSessionExpires(), $viewer),
$button,
);
}
$table = new AphrontTableView($rows);
$table->setNoDataString(pht("You don't have any active sessions."));
$table->setRowClasses($rowc);
$table->setHeaders(
array(
pht('Identity'),
pht('Session'),
pht('Type'),
pht('HiSec'),
pht('Created'),
pht('Expires'),
pht(''),
));
$table->setColumnClasses(
array(
'wide',
'n',
'',
'right',
'right',
'right',
'action',
));
-
- $terminate_icon = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle');
$terminate_button = id(new PHUIButtonView())
->setText(pht('Terminate All Sessions'))
->setHref('/auth/session/terminate/all/')
->setTag('a')
->setWorkflow(true)
- ->setIcon($terminate_icon);
+ ->setIcon('fa-exclamation-triangle');
$header = id(new PHUIHeaderView())
->setHeader(pht('Active Login Sessions'))
->addActionLink($terminate_button);
$hisec = ($viewer->getSession()->getHighSecurityUntil() - time());
if ($hisec > 0) {
- $hisec_icon = id(new PHUIIconView())
- ->setIconFont('fa-lock');
$hisec_button = id(new PHUIButtonView())
->setText(pht('Leave High Security'))
->setHref('/auth/session/downgrade/')
->setTag('a')
->setWorkflow(true)
- ->setIcon($hisec_icon);
+ ->setIcon('fa-lock');
$header->addActionLink($hisec_button);
}
$panel = id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
return $panel;
}
}
diff --git a/src/applications/settings/panel/PhabricatorTokensSettingsPanel.php b/src/applications/settings/panel/PhabricatorTokensSettingsPanel.php
index 9c20e1235f..a92026333a 100644
--- a/src/applications/settings/panel/PhabricatorTokensSettingsPanel.php
+++ b/src/applications/settings/panel/PhabricatorTokensSettingsPanel.php
@@ -1,99 +1,96 @@
<?php
final class PhabricatorTokensSettingsPanel extends PhabricatorSettingsPanel {
public function getPanelKey() {
return 'tokens';
}
public function getPanelName() {
return pht('Temporary Tokens');
}
public function getPanelGroup() {
return pht('Sessions and Logs');
}
public function isEnabled() {
return true;
}
public function processRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$tokens = id(new PhabricatorAuthTemporaryTokenQuery())
->setViewer($viewer)
->withObjectPHIDs(array($viewer->getPHID()))
->execute();
$rows = array();
foreach ($tokens as $token) {
if ($token->isRevocable()) {
$button = javelin_tag(
'a',
array(
'href' => '/auth/token/revoke/'.$token->getID().'/',
'class' => 'small grey button',
'sigil' => 'workflow',
),
pht('Revoke'));
} else {
$button = javelin_tag(
'a',
array(
'class' => 'small grey button disabled',
),
pht('Revoke'));
}
if ($token->getTokenExpires() >= time()) {
$expiry = phabricator_datetime($token->getTokenExpires(), $viewer);
} else {
$expiry = pht('Expired');
}
$rows[] = array(
$token->getTokenReadableTypeName(),
$expiry,
$button,
);
}
$table = new AphrontTableView($rows);
$table->setNoDataString(pht("You don't have any active tokens."));
$table->setHeaders(
array(
pht('Type'),
pht('Expires'),
pht(''),
));
$table->setColumnClasses(
array(
'wide',
'right',
'action',
));
-
- $terminate_icon = id(new PHUIIconView())
- ->setIconFont('fa-exclamation-triangle');
$terminate_button = id(new PHUIButtonView())
->setText(pht('Revoke All'))
->setHref('/auth/token/revoke/all/')
->setTag('a')
->setWorkflow(true)
- ->setIcon($terminate_icon);
+ ->setIcon('fa-exclamation-triangle');
$header = id(new PHUIHeaderView())
->setHeader(pht('Temporary Tokens'))
->addActionLink($terminate_button);
$panel = id(new PHUIObjectBoxView())
->setHeader($header)
->setTable($table);
return $panel;
}
}
diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
index 6808ed2af5..553bfa3e10 100644
--- a/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
+++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionValueController.php
@@ -1,145 +1,145 @@
<?php
final class PhabricatorApplicationTransactionValueController
extends PhabricatorApplicationTransactionController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$phid = $request->getURIData('phid');
$type = $request->getURIData('value');
$xaction = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(array($phid))
->executeOne();
if (!$xaction) {
return new Aphront404Response();
}
// For now, this pathway only supports policy transactions
// to show the details of custom policies. If / when this pathway
// supports more transaction types, rendering coding should be moved
// into PhabricatorTransactions e.g. feed rendering code.
// TODO: This should be some kind of "hey do you support this?" thing on
// the transactions themselves.
switch ($xaction->getTransactionType()) {
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_JOIN_POLICY:
case PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY:
break;
default:
return new Aphront404Response();
break;
}
if ($type == 'old') {
$value = $xaction->getOldValue();
} else {
$value = $xaction->getNewValue();
}
$policy = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->withPHIDs(array($value))
->executeOne();
if (!$policy) {
return new Aphront404Response();
}
if ($policy->getType() != PhabricatorPolicyType::TYPE_CUSTOM) {
return new Aphront404Response();
}
$rule_objects = array();
foreach ($policy->getCustomRuleClasses() as $class) {
$rule_objects[$class] = newv($class, array());
}
$policy->attachRuleObjects($rule_objects);
$this->requireResource('policy-transaction-detail-css');
$cancel_uri = $this->guessCancelURI($viewer, $xaction);
return $this->newDialog()
->setTitle($policy->getFullName())
->setWidth(AphrontDialogView::WIDTH_FORM)
->appendChild($this->renderPolicyDetails($policy, $rule_objects))
->addCancelButton($cancel_uri, pht('Close'));
}
private function extractPHIDs(
PhabricatorPolicy $policy,
array $rule_objects) {
$phids = array();
foreach ($policy->getRules() as $rule) {
$rule_object = $rule_objects[$rule['rule']];
$phids[] =
$rule_object->getRequiredHandlePHIDsForSummary($rule['value']);
}
return array_filter(array_mergev($phids));
}
private function renderPolicyDetails(
PhabricatorPolicy $policy,
array $rule_objects) {
$details = array();
$details[] = phutil_tag(
'p',
array(
'class' => 'policy-transaction-detail-intro',
),
pht('These rules are processed in order:'));
foreach ($policy->getRules() as $index => $rule) {
$rule_object = $rule_objects[$rule['rule']];
if ($rule['action'] == 'allow') {
$icon = 'fa-check-circle green';
} else {
$icon = 'fa-minus-circle red';
}
$icon = id(new PHUIIconView())
- ->setIconFont($icon)
+ ->setIcon($icon)
->setText(
ucfirst($rule['action']).' '.$rule_object->getRuleDescription());
$handle_phids = $rule_object->getRequiredHandlePHIDsForSummary(
$rule['value']);
if ($handle_phids) {
$value = $this->getViewer()
->renderHandleList($handle_phids)
->setAsInline(true);
} else {
$value = $rule['value'];
}
$details[] = phutil_tag('div',
array(
'class' => 'policy-transaction-detail-row',
),
array(
$icon,
$value,
));
}
$details[] = phutil_tag(
'p',
array(
'class' => 'policy-transaction-detail-end',
),
pht(
'If no rules match, %s all other users.',
phutil_tag('b',
array(),
$policy->getDefaultAction())));
return $details;
}
}
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php
index 0fb96e7e19..9efc3c4100 100644
--- a/src/applications/transactions/editengine/PhabricatorEditEngine.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php
@@ -1,1887 +1,1887 @@
<?php
/**
* @task fields Managing Fields
* @task text Display Text
* @task config Edit Engine Configuration
* @task uri Managing URIs
* @task load Creating and Loading Objects
* @task web Responding to Web Requests
* @task edit Responding to Edit Requests
* @task http Responding to HTTP Parameter Requests
* @task conduit Responding to Conduit Requests
*/
abstract class PhabricatorEditEngine
extends Phobject
implements PhabricatorPolicyInterface {
const EDITENGINECONFIG_DEFAULT = 'default';
private $viewer;
private $controller;
private $isCreate;
private $editEngineConfiguration;
private $contextParameters = array();
final public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
final public function getViewer() {
return $this->viewer;
}
final public function setController(PhabricatorController $controller) {
$this->controller = $controller;
$this->setViewer($controller->getViewer());
return $this;
}
final public function getController() {
return $this->controller;
}
final public function getEngineKey() {
return $this->getPhobjectClassConstant('ENGINECONST', 64);
}
final public function getApplication() {
$app_class = $this->getEngineApplicationClass();
return PhabricatorApplication::getByClass($app_class);
}
final public function addContextParameter($key) {
$this->contextParameters[] = $key;
return $this;
}
public function isEngineConfigurable() {
return true;
}
/* -( Managing Fields )---------------------------------------------------- */
abstract public function getEngineApplicationClass();
abstract protected function buildCustomEditFields($object);
public function getFieldsForConfig(
PhabricatorEditEngineConfiguration $config) {
$object = $this->newEditableObject();
$this->editEngineConfiguration = $config;
// This is mostly making sure that we fill in default values.
$this->setIsCreate(true);
return $this->buildEditFields($object);
}
final protected function buildEditFields($object) {
$viewer = $this->getViewer();
$fields = $this->buildCustomEditFields($object);
foreach ($fields as $field) {
$field
->setViewer($viewer)
->setObject($object);
}
$fields = mpull($fields, null, 'getKey');
$extensions = PhabricatorEditEngineExtension::getAllEnabledExtensions();
foreach ($extensions as $extension) {
$extension->setViewer($viewer);
if (!$extension->supportsObject($this, $object)) {
continue;
}
$extension_fields = $extension->buildCustomEditFields($this, $object);
// TODO: Validate this in more detail with a more tailored error.
assert_instances_of($extension_fields, 'PhabricatorEditField');
foreach ($extension_fields as $field) {
$field
->setViewer($viewer)
->setObject($object);
}
$extension_fields = mpull($extension_fields, null, 'getKey');
foreach ($extension_fields as $key => $field) {
$fields[$key] = $field;
}
}
$config = $this->getEditEngineConfiguration();
$fields = $this->willConfigureFields($object, $fields);
$fields = $config->applyConfigurationToFields($this, $object, $fields);
return $fields;
}
protected function willConfigureFields($object, array $fields) {
return $fields;
}
/* -( Display Text )------------------------------------------------------- */
/**
* @task text
*/
abstract public function getEngineName();
/**
* @task text
*/
abstract protected function getObjectCreateTitleText($object);
/**
* @task text
*/
protected function getFormHeaderText($object) {
$config = $this->getEditEngineConfiguration();
return $config->getName();
}
/**
* @task text
*/
abstract protected function getObjectEditTitleText($object);
/**
* @task text
*/
abstract protected function getObjectCreateShortText();
/**
* @task text
*/
abstract protected function getObjectEditShortText($object);
/**
* @task text
*/
protected function getObjectCreateButtonText($object) {
return $this->getObjectCreateTitleText($object);
}
/**
* @task text
*/
protected function getObjectEditButtonText($object) {
return pht('Save Changes');
}
/**
* @task text
*/
protected function getCommentViewSeriousHeaderText($object) {
return pht('Take Action');
}
/**
* @task text
*/
protected function getCommentViewSeriousButtonText($object) {
return pht('Submit');
}
/**
* @task text
*/
protected function getCommentViewHeaderText($object) {
return $this->getCommentViewSeriousHeaderText($object);
}
/**
* @task text
*/
protected function getCommentViewButtonText($object) {
return $this->getCommentViewSeriousButtonText($object);
}
/**
* @task text
*/
protected function getQuickCreateMenuHeaderText() {
return $this->getObjectCreateShortText();
}
/**
* Return a human-readable header describing what this engine is used to do,
* like "Configure Maniphest Task Forms".
*
* @return string Human-readable description of the engine.
* @task text
*/
abstract public function getSummaryHeader();
/**
* Return a human-readable summary of what this engine is used to do.
*
* @return string Human-readable description of the engine.
* @task text
*/
abstract public function getSummaryText();
/* -( Edit Engine Configuration )------------------------------------------ */
protected function supportsEditEngineConfiguration() {
return true;
}
final protected function getEditEngineConfiguration() {
return $this->editEngineConfiguration;
}
private function newConfigurationQuery() {
return id(new PhabricatorEditEngineConfigurationQuery())
->setViewer($this->getViewer())
->withEngineKeys(array($this->getEngineKey()));
}
private function loadEditEngineConfigurationWithQuery(
PhabricatorEditEngineConfigurationQuery $query,
$sort_method) {
if ($sort_method) {
$results = $query->execute();
$results = msort($results, $sort_method);
$result = head($results);
} else {
$result = $query->executeOne();
}
if (!$result) {
return null;
}
$this->editEngineConfiguration = $result;
return $result;
}
private function loadEditEngineConfigurationWithIdentifier($identifier) {
$query = $this->newConfigurationQuery()
->withIdentifiers(array($identifier));
return $this->loadEditEngineConfigurationWithQuery($query, null);
}
private function loadDefaultConfiguration() {
$query = $this->newConfigurationQuery()
->withIdentifiers(
array(
self::EDITENGINECONFIG_DEFAULT,
))
->withIgnoreDatabaseConfigurations(true);
return $this->loadEditEngineConfigurationWithQuery($query, null);
}
private function loadDefaultCreateConfiguration() {
$query = $this->newConfigurationQuery()
->withIsDefault(true)
->withIsDisabled(false);
return $this->loadEditEngineConfigurationWithQuery(
$query,
'getCreateSortKey');
}
public function loadDefaultEditConfiguration() {
$query = $this->newConfigurationQuery()
->withIsEdit(true)
->withIsDisabled(false);
return $this->loadEditEngineConfigurationWithQuery(
$query,
'getEditSortKey');
}
final public function getBuiltinEngineConfigurations() {
$configurations = $this->newBuiltinEngineConfigurations();
if (!$configurations) {
throw new Exception(
pht(
'EditEngine ("%s") returned no builtin engine configurations, but '.
'an edit engine must have at least one configuration.',
get_class($this)));
}
assert_instances_of($configurations, 'PhabricatorEditEngineConfiguration');
$has_default = false;
foreach ($configurations as $config) {
if ($config->getBuiltinKey() == self::EDITENGINECONFIG_DEFAULT) {
$has_default = true;
}
}
if (!$has_default) {
$first = head($configurations);
if (!$first->getBuiltinKey()) {
$first
->setBuiltinKey(self::EDITENGINECONFIG_DEFAULT)
->setIsDefault(true)
->setIsEdit(true);
if (!strlen($first->getName())) {
$first->setName($this->getObjectCreateShortText());
}
} else {
throw new Exception(
pht(
'EditEngine ("%s") returned builtin engine configurations, '.
'but none are marked as default and the first configuration has '.
'a different builtin key already. Mark a builtin as default or '.
'omit the key from the first configuration',
get_class($this)));
}
}
$builtins = array();
foreach ($configurations as $key => $config) {
$builtin_key = $config->getBuiltinKey();
if ($builtin_key === null) {
throw new Exception(
pht(
'EditEngine ("%s") returned builtin engine configurations, '.
'but one (with key "%s") is missing a builtin key. Provide a '.
'builtin key for each configuration (you can omit it from the '.
'first configuration in the list to automatically assign the '.
'default key).',
get_class($this),
$key));
}
if (isset($builtins[$builtin_key])) {
throw new Exception(
pht(
'EditEngine ("%s") returned builtin engine configurations, '.
'but at least two specify the same builtin key ("%s"). Engines '.
'must have unique builtin keys.',
get_class($this),
$builtin_key));
}
$builtins[$builtin_key] = $config;
}
return $builtins;
}
protected function newBuiltinEngineConfigurations() {
return array(
$this->newConfiguration(),
);
}
final protected function newConfiguration() {
return PhabricatorEditEngineConfiguration::initializeNewConfiguration(
$this->getViewer(),
$this);
}
/* -( Managing URIs )------------------------------------------------------ */
/**
* @task uri
*/
abstract protected function getObjectViewURI($object);
/**
* @task uri
*/
protected function getObjectCreateCancelURI($object) {
return $this->getApplication()->getApplicationURI();
}
/**
* @task uri
*/
protected function getEditorURI() {
return $this->getApplication()->getApplicationURI('edit/');
}
/**
* @task uri
*/
protected function getObjectEditCancelURI($object) {
return $this->getObjectViewURI($object);
}
/**
* @task uri
*/
public function getEditURI($object = null, $path = null) {
$parts = array();
$parts[] = $this->getEditorURI();
if ($object && $object->getID()) {
$parts[] = $object->getID().'/';
}
if ($path !== null) {
$parts[] = $path;
}
return implode('', $parts);
}
/* -( Creating and Loading Objects )--------------------------------------- */
/**
* Initialize a new object for creation.
*
* @return object Newly initialized object.
* @task load
*/
abstract protected function newEditableObject();
/**
* Build an empty query for objects.
*
* @return PhabricatorPolicyAwareQuery Query.
* @task load
*/
abstract protected function newObjectQuery();
/**
* Test if this workflow is creating a new object or editing an existing one.
*
* @return bool True if a new object is being created.
* @task load
*/
final public function getIsCreate() {
return $this->isCreate;
}
/**
* Flag this workflow as a create or edit.
*
* @param bool True if this is a create workflow.
* @return this
* @task load
*/
private function setIsCreate($is_create) {
$this->isCreate = $is_create;
return $this;
}
/**
* Try to load an object by ID, PHID, or monogram. This is done primarily
* to make Conduit a little easier to use.
*
* @param wild ID, PHID, or monogram.
* @param list<const> List of required capability constants, or omit for
* defaults.
* @return object Corresponding editable object.
* @task load
*/
private function newObjectFromIdentifier(
$identifier,
array $capabilities = array()) {
if (is_int($identifier) || ctype_digit($identifier)) {
$object = $this->newObjectFromID($identifier, $capabilities);
if (!$object) {
throw new Exception(
pht(
'No object exists with ID "%s".',
$identifier));
}
return $object;
}
$type_unknown = PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN;
if (phid_get_type($identifier) != $type_unknown) {
$object = $this->newObjectFromPHID($identifier, $capabilities);
if (!$object) {
throw new Exception(
pht(
'No object exists with PHID "%s".',
$identifier));
}
return $object;
}
$target = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->withNames(array($identifier))
->executeOne();
if (!$target) {
throw new Exception(
pht(
'Monogram "%s" does not identify a valid object.',
$identifier));
}
$expect = $this->newEditableObject();
$expect_class = get_class($expect);
$target_class = get_class($target);
if ($expect_class !== $target_class) {
throw new Exception(
pht(
'Monogram "%s" identifies an object of the wrong type. Loaded '.
'object has class "%s", but this editor operates on objects of '.
'type "%s".',
$identifier,
$target_class,
$expect_class));
}
// Load the object by PHID using this engine's standard query. This makes
// sure it's really valid, goes through standard policy check logic, and
// picks up any `need...()` clauses we want it to load with.
$object = $this->newObjectFromPHID($target->getPHID(), $capabilities);
if (!$object) {
throw new Exception(
pht(
'Failed to reload object identified by monogram "%s" when '.
'querying by PHID.',
$identifier));
}
return $object;
}
/**
* Load an object by ID.
*
* @param int Object ID.
* @param list<const> List of required capability constants, or omit for
* defaults.
* @return object|null Object, or null if no such object exists.
* @task load
*/
private function newObjectFromID($id, array $capabilities = array()) {
$query = $this->newObjectQuery()
->withIDs(array($id));
return $this->newObjectFromQuery($query, $capabilities);
}
/**
* Load an object by PHID.
*
* @param phid Object PHID.
* @param list<const> List of required capability constants, or omit for
* defaults.
* @return object|null Object, or null if no such object exists.
* @task load
*/
private function newObjectFromPHID($phid, array $capabilities = array()) {
$query = $this->newObjectQuery()
->withPHIDs(array($phid));
return $this->newObjectFromQuery($query, $capabilities);
}
/**
* Load an object given a configured query.
*
* @param PhabricatorPolicyAwareQuery Configured query.
* @param list<const> List of required capabilitiy constants, or omit for
* defaults.
* @return object|null Object, or null if no such object exists.
* @task load
*/
private function newObjectFromQuery(
PhabricatorPolicyAwareQuery $query,
array $capabilities = array()) {
$viewer = $this->getViewer();
if (!$capabilities) {
$capabilities = array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
$object = $query
->setViewer($viewer)
->requireCapabilities($capabilities)
->executeOne();
if (!$object) {
return null;
}
return $object;
}
/**
* Verify that an object is appropriate for editing.
*
* @param wild Loaded value.
* @return void
* @task load
*/
private function validateObject($object) {
if (!$object || !is_object($object)) {
throw new Exception(
pht(
'EditEngine "%s" created or loaded an invalid object: object must '.
'actually be an object, but is of some other type ("%s").',
get_class($this),
gettype($object)));
}
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
throw new Exception(
pht(
'EditEngine "%s" created or loaded an invalid object: object (of '.
'class "%s") must implement "%s", but does not.',
get_class($this),
get_class($object),
'PhabricatorApplicationTransactionInterface'));
}
}
/* -( Responding to Web Requests )----------------------------------------- */
final public function buildResponse() {
$viewer = $this->getViewer();
$controller = $this->getController();
$request = $controller->getRequest();
$action = $request->getURIData('editAction');
$capabilities = array();
$use_default = false;
$require_create = true;
switch ($action) {
case 'comment':
$capabilities = array(
PhabricatorPolicyCapability::CAN_VIEW,
);
$use_default = true;
break;
case 'parameters':
$use_default = true;
break;
case 'nodefault':
case 'nocreate':
case 'nomanage':
$require_create = false;
break;
default:
break;
}
$id = $request->getURIData('id');
if ($id) {
$this->setIsCreate(false);
$object = $this->newObjectFromID($id, $capabilities);
if (!$object) {
return new Aphront404Response();
}
} else {
// Make sure the viewer has permission to create new objects of
// this type if we're going to create a new object.
if ($require_create) {
$this->requireCreateCapability();
}
$this->setIsCreate(true);
$object = $this->newEditableObject();
}
$this->validateObject($object);
if ($use_default) {
$config = $this->loadDefaultConfiguration();
if (!$config) {
return new Aphront404Response();
}
} else {
$form_key = $request->getURIData('formKey');
if (strlen($form_key)) {
$config = $this->loadEditEngineConfigurationWithIdentifier($form_key);
if (!$config) {
return new Aphront404Response();
}
if ($id && !$config->getIsEdit()) {
return $this->buildNotEditFormRespose($object, $config);
}
} else {
if ($id) {
$config = $this->loadDefaultEditConfiguration();
if (!$config) {
return $this->buildNoEditResponse($object);
}
} else {
$config = $this->loadDefaultCreateConfiguration();
if (!$config) {
return $this->buildNoCreateResponse($object);
}
}
}
}
if ($config->getIsDisabled()) {
return $this->buildDisabledFormResponse($object, $config);
}
switch ($action) {
case 'parameters':
return $this->buildParametersResponse($object);
case 'nodefault':
return $this->buildNoDefaultResponse($object);
case 'nocreate':
return $this->buildNoCreateResponse($object);
case 'nomanage':
return $this->buildNoManageResponse($object);
case 'comment':
return $this->buildCommentResponse($object);
default:
return $this->buildEditResponse($object);
}
}
private function buildCrumbs($object, $final = false) {
$controller = $this->getcontroller();
$crumbs = $controller->buildApplicationCrumbsForEditEngine();
if ($this->getIsCreate()) {
$create_text = $this->getObjectCreateShortText();
if ($final) {
$crumbs->addTextCrumb($create_text);
} else {
$edit_uri = $this->getEditURI($object);
$crumbs->addTextCrumb($create_text, $edit_uri);
}
} else {
$crumbs->addTextCrumb(
$this->getObjectEditShortText($object),
$this->getObjectViewURI($object));
$edit_text = pht('Edit');
if ($final) {
$crumbs->addTextCrumb($edit_text);
} else {
$edit_uri = $this->getEditURI($object);
$crumbs->addTextCrumb($edit_text, $edit_uri);
}
}
return $crumbs;
}
private function buildEditResponse($object) {
$viewer = $this->getViewer();
$controller = $this->getController();
$request = $controller->getRequest();
$fields = $this->buildEditFields($object);
$template = $object->getApplicationTransactionTemplate();
$validation_exception = null;
if ($request->isFormPost()) {
$submit_fields = $fields;
foreach ($submit_fields as $key => $field) {
if (!$field->shouldGenerateTransactionsFromSubmit()) {
unset($submit_fields[$key]);
continue;
}
}
// Before we read the submitted values, store a copy of what we would
// use if the form was empty so we can figure out which transactions are
// just setting things to their default values for the current form.
$defaults = array();
foreach ($submit_fields as $key => $field) {
$defaults[$key] = $field->getValueForTransaction();
}
foreach ($submit_fields as $key => $field) {
$field->setIsSubmittedForm(true);
if (!$field->shouldReadValueFromSubmit()) {
continue;
}
$field->readValueFromSubmit($request);
}
$xactions = array();
if ($this->getIsCreate()) {
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_CREATE);
}
foreach ($submit_fields as $key => $field) {
$field_value = $field->getValueForTransaction();
$type_xactions = $field->generateTransactions(
clone $template,
array(
'value' => $field_value,
));
foreach ($type_xactions as $type_xaction) {
$default = $defaults[$key];
if ($default === $field->getValueForTransaction()) {
$type_xaction->setIsDefaultTransaction(true);
}
$xactions[] = $type_xaction;
}
}
$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
try {
$editor->applyTransactions($object, $xactions);
return $this->newEditResponse($request, $object, $xactions);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
foreach ($fields as $field) {
$xaction_type = $field->getTransactionType();
if ($xaction_type === null) {
continue;
}
$message = $ex->getShortMessage($xaction_type);
if ($message === null) {
continue;
}
$field->setControlError($message);
}
}
} else {
if ($this->getIsCreate()) {
$template = $request->getStr('template');
if (strlen($template)) {
$template_object = $this->newObjectFromIdentifier(
$template,
array(
PhabricatorPolicyCapability::CAN_VIEW,
));
if (!$template_object) {
return new Aphront404Response();
}
} else {
$template_object = null;
}
if ($template_object) {
$copy_fields = $this->buildEditFields($template_object);
$copy_fields = mpull($copy_fields, null, 'getKey');
foreach ($copy_fields as $copy_key => $copy_field) {
if (!$copy_field->getIsCopyable()) {
unset($copy_fields[$copy_key]);
}
}
} else {
$copy_fields = array();
}
foreach ($fields as $field) {
if (!$field->shouldReadValueFromRequest()) {
continue;
}
$field_key = $field->getKey();
if (isset($copy_fields[$field_key])) {
$field->readValueFromField($copy_fields[$field_key]);
}
$field->readValueFromRequest($request);
}
}
}
$action_button = $this->buildEditFormActionButton($object);
if ($this->getIsCreate()) {
$header_text = $this->getFormHeaderText($object);
} else {
$header_text = $this->getObjectEditTitleText($object);
}
$show_preview = !$request->isAjax();
if ($show_preview) {
$previews = array();
foreach ($fields as $field) {
$preview = $field->getPreviewPanel();
if (!$preview) {
continue;
}
$control_id = $field->getControlID();
$preview
->setControlID($control_id)
->setPreviewURI('/transactions/remarkuppreview/');
$previews[] = $preview;
}
} else {
$previews = array();
}
$form = $this->buildEditForm($object, $fields);
if ($request->isAjax()) {
if ($this->getIsCreate()) {
$cancel_uri = $this->getObjectCreateCancelURI($object);
$submit_button = $this->getObjectCreateButtonText($object);
} else {
$cancel_uri = $this->getObjectEditCancelURI($object);
$submit_button = $this->getObjectEditButtonText($object);
}
return $this->getController()
->newDialog()
->setWidth(AphrontDialogView::WIDTH_FULL)
->setTitle($header_text)
->setValidationException($validation_exception)
->appendForm($form)
->addCancelButton($cancel_uri)
->addSubmitButton($submit_button);
}
$header = id(new PHUIHeaderView())
->setHeader($header_text);
if ($action_button) {
$header->addActionLink($action_button);
}
$crumbs = $this->buildCrumbs($object, $final = true);
$box = id(new PHUIObjectBoxView())
->setUser($viewer)
->setHeader($header)
->setValidationException($validation_exception)
->appendChild($form);
return $controller->newPage()
->setTitle($header_text)
->setCrumbs($crumbs)
->appendChild($box)
->appendChild($previews);
}
protected function newEditResponse(
AphrontRequest $request,
$object,
array $xactions) {
return id(new AphrontRedirectResponse())
->setURI($this->getObjectViewURI($object));
}
private function buildEditForm($object, array $fields) {
$viewer = $this->getViewer();
$controller = $this->getController();
$request = $controller->getRequest();
$form = id(new AphrontFormView())
->setUser($viewer);
foreach ($this->contextParameters as $param) {
$form->addHiddenInput($param, $request->getStr($param));
}
foreach ($fields as $field) {
$field->appendToForm($form);
}
if ($this->getIsCreate()) {
$cancel_uri = $this->getObjectCreateCancelURI($object);
$submit_button = $this->getObjectCreateButtonText($object);
} else {
$cancel_uri = $this->getObjectEditCancelURI($object);
$submit_button = $this->getObjectEditButtonText($object);
}
if (!$request->isAjax()) {
$form->appendControl(
id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri)
->setValue($submit_button));
}
return $form;
}
private function buildEditFormActionButton($object) {
if (!$this->isEngineConfigurable()) {
return null;
}
$viewer = $this->getViewer();
$action_view = id(new PhabricatorActionListView())
->setUser($viewer);
foreach ($this->buildEditFormActions($object) as $action) {
$action_view->addAction($action);
}
$action_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Configure Form'))
->setHref('#')
- ->setIconFont('fa-gear')
+ ->setIcon('fa-gear')
->setDropdownMenu($action_view);
return $action_button;
}
private function buildEditFormActions($object) {
$actions = array();
if ($this->supportsEditEngineConfiguration()) {
$engine_key = $this->getEngineKey();
$config = $this->getEditEngineConfiguration();
$can_manage = PhabricatorPolicyFilter::hasCapability(
$this->getViewer(),
$config,
PhabricatorPolicyCapability::CAN_EDIT);
if ($can_manage) {
$manage_uri = $config->getURI();
} else {
$manage_uri = $this->getEditURI(null, 'nomanage/');
}
$view_uri = "/transactions/editengine/{$engine_key}/";
$actions[] = id(new PhabricatorActionView())
->setLabel(true)
->setName(pht('Configuration'));
$actions[] = id(new PhabricatorActionView())
->setName(pht('View Form Configurations'))
->setIcon('fa-list-ul')
->setHref($view_uri);
$actions[] = id(new PhabricatorActionView())
->setName(pht('Edit Form Configuration'))
->setIcon('fa-pencil')
->setHref($manage_uri)
->setDisabled(!$can_manage)
->setWorkflow(!$can_manage);
}
$actions[] = id(new PhabricatorActionView())
->setLabel(true)
->setName(pht('Documentation'));
$actions[] = id(new PhabricatorActionView())
->setName(pht('Using HTTP Parameters'))
->setIcon('fa-book')
->setHref($this->getEditURI($object, 'parameters/'));
$doc_href = PhabricatorEnv::getDoclink('User Guide: Customizing Forms');
$actions[] = id(new PhabricatorActionView())
->setName(pht('User Guide: Customizing Forms'))
->setIcon('fa-book')
->setHref($doc_href);
return $actions;
}
final public function addActionToCrumbs(PHUICrumbsView $crumbs) {
$viewer = $this->getViewer();
$can_create = $this->hasCreateCapability();
if ($can_create) {
$configs = $this->loadUsableConfigurationsForCreate();
} else {
$configs = array();
}
$dropdown = null;
$disabled = false;
$workflow = false;
$menu_icon = 'fa-plus-square';
if (!$configs) {
if ($viewer->isLoggedIn()) {
$disabled = true;
} else {
// If the viewer isn't logged in, assume they'll get hit with a login
// dialog and are likely able to create objects after they log in.
$disabled = false;
}
$workflow = true;
if ($can_create) {
$create_uri = $this->getEditURI(null, 'nodefault/');
} else {
$create_uri = $this->getEditURI(null, 'nocreate/');
}
} else {
$config = head($configs);
$form_key = $config->getIdentifier();
$create_uri = $this->getEditURI(null, "form/{$form_key}/");
if (count($configs) > 1) {
$menu_icon = 'fa-caret-square-o-down';
$dropdown = id(new PhabricatorActionListView())
->setUser($viewer);
foreach ($configs as $config) {
$form_key = $config->getIdentifier();
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
$item_icon = 'fa-plus';
$dropdown->addAction(
id(new PhabricatorActionView())
->setName($config->getDisplayName())
->setIcon($item_icon)
->setHref($config_uri));
}
}
}
$action = id(new PHUIListItemView())
->setName($this->getObjectCreateShortText())
->setHref($create_uri)
->setIcon($menu_icon)
->setWorkflow($workflow)
->setDisabled($disabled);
if ($dropdown) {
$action->setDropdownMenu($dropdown);
}
$crumbs->addAction($action);
}
final public function buildEditEngineCommentView($object) {
$config = $this->loadDefaultEditConfiguration();
if (!$config) {
// TODO: This just nukes the entire comment form if you don't have access
// to any edit forms. We might want to tailor this UX a bit.
return id(new PhabricatorApplicationTransactionCommentView())
->setNoPermission(true);
}
$viewer = $this->getViewer();
$object_phid = $object->getPHID();
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
if ($is_serious) {
$header_text = $this->getCommentViewSeriousHeaderText($object);
$button_text = $this->getCommentViewSeriousButtonText($object);
} else {
$header_text = $this->getCommentViewHeaderText($object);
$button_text = $this->getCommentViewButtonText($object);
}
$comment_uri = $this->getEditURI($object, 'comment/');
$view = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($object_phid)
->setHeaderText($header_text)
->setAction($comment_uri)
->setSubmitButtonName($button_text);
$draft = PhabricatorVersionedDraft::loadDraft(
$object_phid,
$viewer->getPHID());
if ($draft) {
$view->setVersionedDraft($draft);
}
$view->setCurrentVersion($this->loadDraftVersion($object));
$fields = $this->buildEditFields($object);
$comment_actions = array();
foreach ($fields as $field) {
if (!$field->shouldGenerateTransactionsFromComment()) {
continue;
}
$comment_action = $field->getCommentAction();
if (!$comment_action) {
continue;
}
$key = $comment_action->getKey();
// TODO: Validate these better.
$comment_actions[$key] = $comment_action;
}
$view->setCommentActions($comment_actions);
return $view;
}
protected function loadDraftVersion($object) {
$viewer = $this->getViewer();
if (!$viewer->isLoggedIn()) {
return null;
}
$template = $object->getApplicationTransactionTemplate();
$conn_r = $template->establishConnection('r');
// Find the most recent transaction the user has written. We'll use this
// as a version number to make sure that out-of-date drafts get discarded.
$result = queryfx_one(
$conn_r,
'SELECT id AS version FROM %T
WHERE objectPHID = %s AND authorPHID = %s
ORDER BY id DESC LIMIT 1',
$template->getTableName(),
$object->getPHID(),
$viewer->getPHID());
if ($result) {
return (int)$result['version'];
} else {
return null;
}
}
/* -( Responding to HTTP Parameter Requests )------------------------------ */
/**
* Respond to a request for documentation on HTTP parameters.
*
* @param object Editable object.
* @return AphrontResponse Response object.
* @task http
*/
private function buildParametersResponse($object) {
$controller = $this->getController();
$viewer = $this->getViewer();
$request = $controller->getRequest();
$fields = $this->buildEditFields($object);
$crumbs = $this->buildCrumbs($object);
$crumbs->addTextCrumb(pht('HTTP Parameters'));
$crumbs->setBorder(true);
$header_text = pht(
'HTTP Parameters: %s',
$this->getObjectCreateShortText());
$header = id(new PHUIHeaderView())
->setHeader($header_text);
$help_view = id(new PhabricatorApplicationEditHTTPParameterHelpView())
->setUser($viewer)
->setFields($fields);
$document = id(new PHUIDocumentViewPro())
->setUser($viewer)
->setHeader($header)
->appendChild($help_view);
return $controller->newPage()
->setTitle(pht('HTTP Parameters'))
->setCrumbs($crumbs)
->appendChild($document);
}
private function buildError($object, $title, $body) {
$cancel_uri = $this->getObjectCreateCancelURI($object);
return $this->getController()
->newDialog()
->setTitle($title)
->appendParagraph($body)
->addCancelButton($cancel_uri);
}
private function buildNoDefaultResponse($object) {
return $this->buildError(
$object,
pht('No Default Create Forms'),
pht(
'This application is not configured with any forms for creating '.
'objects that are visible to you and enabled.'));
}
private function buildNoCreateResponse($object) {
return $this->buildError(
$object,
pht('No Create Permission'),
pht('You do not have permission to create these objects.'));
}
private function buildNoManageResponse($object) {
return $this->buildError(
$object,
pht('No Manage Permission'),
pht(
'You do not have permission to configure forms for this '.
'application.'));
}
private function buildNoEditResponse($object) {
return $this->buildError(
$object,
pht('No Edit Forms'),
pht(
'You do not have access to any forms which are enabled and marked '.
'as edit forms.'));
}
private function buildNotEditFormRespose($object, $config) {
return $this->buildError(
$object,
pht('Not an Edit Form'),
pht(
'This form ("%s") is not marked as an edit form, so '.
'it can not be used to edit objects.',
$config->getName()));
}
private function buildDisabledFormResponse($object, $config) {
return $this->buildError(
$object,
pht('Form Disabled'),
pht(
'This form ("%s") has been disabled, so it can not be used.',
$config->getName()));
}
private function buildCommentResponse($object) {
$viewer = $this->getViewer();
if ($this->getIsCreate()) {
return new Aphront404Response();
}
$controller = $this->getController();
$request = $controller->getRequest();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$config = $this->loadDefaultEditConfiguration();
if (!$config) {
return new Aphront404Response();
}
$fields = $this->buildEditFields($object);
$is_preview = $request->isPreviewRequest();
$view_uri = $this->getObjectViewURI($object);
$template = $object->getApplicationTransactionTemplate();
$comment_template = $template->getApplicationTransactionCommentObject();
$comment_text = $request->getStr('comment');
$actions = $request->getStr('editengine.actions');
if ($actions) {
$actions = phutil_json_decode($actions);
}
if ($is_preview) {
$version_key = PhabricatorVersionedDraft::KEY_VERSION;
$request_version = $request->getInt($version_key);
$current_version = $this->loadDraftVersion($object);
if ($request_version >= $current_version) {
$draft = PhabricatorVersionedDraft::loadOrCreateDraft(
$object->getPHID(),
$viewer->getPHID(),
$current_version);
$draft
->setProperty('comment', $comment_text)
->setProperty('actions', $actions)
->save();
}
}
$xactions = array();
if ($actions) {
$action_map = array();
foreach ($actions as $action) {
$type = idx($action, 'type');
if (!$type) {
continue;
}
if (empty($fields[$type])) {
continue;
}
$action_map[$type] = $action;
}
foreach ($action_map as $type => $action) {
$field = $fields[$type];
if (!$field->shouldGenerateTransactionsFromComment()) {
continue;
}
if (array_key_exists('initialValue', $action)) {
$field->setInitialValue($action['initialValue']);
}
$field->readValueFromComment(idx($action, 'value'));
$type_xactions = $field->generateTransactions(
clone $template,
array(
'value' => $field->getValueForTransaction(),
));
foreach ($type_xactions as $type_xaction) {
$xactions[] = $type_xaction;
}
}
}
if (strlen($comment_text) || !$xactions) {
$xactions[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(clone $comment_template)
->setContent($comment_text));
}
$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setContinueOnNoEffect($request->isContinueRequest())
->setContinueOnMissingFields(true)
->setContentSourceFromRequest($request)
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($object, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($view_uri)
->setException($ex);
}
if (!$is_preview) {
PhabricatorVersionedDraft::purgeDrafts(
$object->getPHID(),
$viewer->getPHID(),
$this->loadDraftVersion($object));
}
if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview);
} else {
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
}
/* -( Conduit )------------------------------------------------------------ */
/**
* Respond to a Conduit edit request.
*
* This method accepts a list of transactions to apply to an object, and
* either edits an existing object or creates a new one.
*
* @task conduit
*/
final public function buildConduitResponse(ConduitAPIRequest $request) {
$viewer = $this->getViewer();
$config = $this->loadDefaultConfiguration();
if (!$config) {
throw new Exception(
pht(
'Unable to load configuration for this EditEngine ("%s").',
get_class($this)));
}
$identifier = $request->getValue('objectIdentifier');
if ($identifier) {
$this->setIsCreate(false);
$object = $this->newObjectFromIdentifier($identifier);
} else {
$this->requireCreateCapability();
$this->setIsCreate(true);
$object = $this->newEditableObject();
}
$this->validateObject($object);
$fields = $this->buildEditFields($object);
$types = $this->getConduitEditTypesFromFields($fields);
$template = $object->getApplicationTransactionTemplate();
$xactions = $this->getConduitTransactions($request, $types, $template);
$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->setContinueOnNoEffect(true);
if (!$this->getIsCreate()) {
$editor->setContinueOnMissingFields(true);
}
$xactions = $editor->applyTransactions($object, $xactions);
$xactions_struct = array();
foreach ($xactions as $xaction) {
$xactions_struct[] = array(
'phid' => $xaction->getPHID(),
);
}
return array(
'object' => array(
'id' => $object->getID(),
'phid' => $object->getPHID(),
),
'transactions' => $xactions_struct,
);
}
/**
* Generate transactions which can be applied from edit actions in a Conduit
* request.
*
* @param ConduitAPIRequest The request.
* @param list<PhabricatorEditType> Supported edit types.
* @param PhabricatorApplicationTransaction Template transaction.
* @return list<PhabricatorApplicationTransaction> Generated transactions.
* @task conduit
*/
private function getConduitTransactions(
ConduitAPIRequest $request,
array $types,
PhabricatorApplicationTransaction $template) {
$viewer = $request->getUser();
$transactions_key = 'transactions';
$xactions = $request->getValue($transactions_key);
if (!is_array($xactions)) {
throw new Exception(
pht(
'Parameter "%s" is not a list of transactions.',
$transactions_key));
}
foreach ($xactions as $key => $xaction) {
if (!is_array($xaction)) {
throw new Exception(
pht(
'Parameter "%s" must contain a list of transaction descriptions, '.
'but item with key "%s" is not a dictionary.',
$transactions_key,
$key));
}
if (!array_key_exists('type', $xaction)) {
throw new Exception(
pht(
'Parameter "%s" must contain a list of transaction descriptions, '.
'but item with key "%s" is missing a "type" field. Each '.
'transaction must have a type field.',
$transactions_key,
$key));
}
$type = $xaction['type'];
if (empty($types[$type])) {
throw new Exception(
pht(
'Transaction with key "%s" has invalid type "%s". This type is '.
'not recognized. Valid types are: %s.',
$key,
$type,
implode(', ', array_keys($types))));
}
}
$results = array();
if ($this->getIsCreate()) {
$results[] = id(clone $template)
->setTransactionType(PhabricatorTransactions::TYPE_CREATE);
}
foreach ($xactions as $xaction) {
$type = $types[$xaction['type']];
// Let the parameter type interpret the value. This allows you to
// use usernames in list<user> fields, for example.
$parameter_type = $type->getConduitParameterType();
$parameter_type->setViewer($viewer);
try {
$xaction['value'] = $parameter_type->getValue($xaction, 'value');
} catch (Exception $ex) {
throw new PhutilProxyException(
pht(
'Exception when processing transaction of type "%s".',
$xaction['type']),
$ex);
}
$type_xactions = $type->generateTransactions(
clone $template,
$xaction);
foreach ($type_xactions as $type_xaction) {
$results[] = $type_xaction;
}
}
return $results;
}
/**
* @return map<string, PhabricatorEditType>
* @task conduit
*/
private function getConduitEditTypesFromFields(array $fields) {
$types = array();
foreach ($fields as $field) {
$field_types = $field->getConduitEditTypes();
if ($field_types === null) {
continue;
}
foreach ($field_types as $field_type) {
$field_type->setField($field);
$types[$field_type->getEditType()] = $field_type;
}
}
return $types;
}
public function getConduitEditTypes() {
$config = $this->loadDefaultConfiguration();
if (!$config) {
return array();
}
$object = $this->newEditableObject();
$fields = $this->buildEditFields($object);
return $this->getConduitEditTypesFromFields($fields);
}
final public static function getAllEditEngines() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getEngineKey')
->execute();
}
final public static function getByKey(PhabricatorUser $viewer, $key) {
return id(new PhabricatorEditEngineQuery())
->setViewer($viewer)
->withEngineKeys(array($key))
->executeOne();
}
public function getIcon() {
$application = $this->getApplication();
return $application->getFontIcon();
}
public function loadQuickCreateItems() {
$items = array();
if (!$this->hasCreateCapability()) {
return $items;
}
$configs = $this->loadUsableConfigurationsForCreate();
if (!$configs) {
// No items to add.
} else if (count($configs) == 1) {
$config = head($configs);
$items[] = $this->newQuickCreateItem($config);
} else {
$group_name = $this->getQuickCreateMenuHeaderText();
$items[] = id(new PHUIListItemView())
->setType(PHUIListItemView::TYPE_LABEL)
->setName($group_name);
foreach ($configs as $config) {
$items[] = $this->newQuickCreateItem($config)
->setIndented(true);
}
}
return $items;
}
private function loadUsableConfigurationsForCreate() {
$viewer = $this->getViewer();
$configs = id(new PhabricatorEditEngineConfigurationQuery())
->setViewer($viewer)
->withEngineKeys(array($this->getEngineKey()))
->withIsDefault(true)
->withIsDisabled(false)
->execute();
$configs = msort($configs, 'getCreateSortKey');
return $configs;
}
private function newQuickCreateItem(
PhabricatorEditEngineConfiguration $config) {
$item_name = $config->getName();
$item_icon = $config->getIcon();
$form_key = $config->getIdentifier();
$item_uri = $this->getEditURI(null, "form/{$form_key}/");
return id(new PHUIListItemView())
->setName($item_name)
->setIcon($item_icon)
->setHref($item_uri);
}
protected function getCreateNewObjectPolicy() {
return PhabricatorPolicies::POLICY_USER;
}
private function requireCreateCapability() {
PhabricatorPolicyFilter::requireCapability(
$this->getViewer(),
$this,
PhabricatorPolicyCapability::CAN_EDIT);
}
private function hasCreateCapability() {
return PhabricatorPolicyFilter::hasCapability(
$this->getViewer(),
$this,
PhabricatorPolicyCapability::CAN_EDIT);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getPHID() {
return get_class($this);
}
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getCreateNewObjectPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
public function describeAutomaticCapability($capability) {
return null;
}
}
diff --git a/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php b/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
index 767e392248..b0abe516de 100644
--- a/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
+++ b/src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
@@ -1,319 +1,319 @@
<?php
/**
* Renders the "HTTP Parameters" help page for edit engines.
*
* This page has a ton of text and specialized rendering on it, this class
* just pulls it out of the main @{class:PhabricatorEditEngine}.
*/
final class PhabricatorApplicationEditHTTPParameterHelpView
extends AphrontView {
private $object;
private $fields;
public function setObject($object) {
$this->object = $object;
return $this;
}
public function getObject() {
return $this->object;
}
public function setFields(array $fields) {
$this->fields = $fields;
return $this;
}
public function getFields() {
return $this->fields;
}
public function render() {
$object = $this->getObject();
$fields = $this->getFields();
$uri = 'https://your.install.com/application/edit/';
// Remove fields which do not expose an HTTP parameter type.
$types = array();
foreach ($fields as $key => $field) {
if (!$field->shouldGenerateTransactionsFromSubmit()) {
unset($fields[$key]);
continue;
}
$type = $field->getHTTPParameterType();
if ($type === null) {
unset($fields[$key]);
continue;
}
$types[$type->getTypeName()] = $type;
}
$intro = pht(<<<EOTEXT
When creating objects in the web interface, you can use HTTP parameters to
prefill fields in the form. This allows you to quickly create a link to a
form with some of the fields already filled in with default values.
To prefill a form, start by finding the URI for the form you want to prefill.
Do this by navigating to the relevant application, clicking the "Create" button
for the type of object you want to create, and then copying the URI out of your
browser's address bar. It will usually look something like this:
```
%s
```
However, `your.install.com` will be the domain where your copy of Phabricator
is installed, and `application/` will be the URI for an application. Some
applications have multiple forms for creating objects or URIs that look a little
different than this example, so the URI may not look exactly like this.
To prefill the form, add properly encoded HTTP parameters to the URI. You
should end up with something like this:
```
%s?title=Platyplus&body=Ornithopter
```
If the form has `title` and `body` fields of the correct types, visiting this
link will prefill those fields with the values "Platypus" and "Ornithopter"
respectively.
The rest of this document shows which parameters you can add to this form and
how to format them.
Supported Fields
----------------
This form supports these fields:
EOTEXT
,
$uri,
$uri);
$rows = array();
foreach ($fields as $field) {
$rows[] = array(
$field->getLabel(),
head($field->getAllReadValueFromRequestKeys()),
$field->getHTTPParameterType()->getTypeName(),
$field->getDescription(),
);
}
$main_table = id(new AphrontTableView($rows))
->setHeaders(
array(
pht('Label'),
pht('Key'),
pht('Type'),
pht('Description'),
))
->setColumnClasses(
array(
'pri',
null,
null,
'wide',
));
$aliases_text = pht(<<<EOTEXT
Aliases
-------
Aliases are alternate recognized keys for a field. For example, a field with
a complex key like `examplePHIDs` might be have a simple version of that key
as an alias, like `example`.
Aliases work just like the primary key when prefilling forms. They make it
easier to remember and use HTTP parameters by providing more natural ways to do
some prefilling.
For example, if a field has `examplePHIDs` as a key but has aliases `example`
and `examples`, these three URIs will all do the same thing:
```
%s?examplePHIDs=...
%s?examples=...
%s?example=...
```
If a URI specifies multiple default values for a field, the value using the
primary key has precedence. Generally, you can not mix different aliases in
a single URI.
EOTEXT
,
$uri,
$uri,
$uri);
$rows = array();
foreach ($fields as $field) {
$aliases = array_slice($field->getAllReadValueFromRequestKeys(), 1);
if (!$aliases) {
continue;
}
$rows[] = array(
$field->getLabel(),
$field->getKey(),
implode(', ', $aliases),
);
}
$alias_table = id(new AphrontTableView($rows))
->setNoDataString(pht('This object has no fields with aliases.'))
->setHeaders(
array(
pht('Label'),
pht('Key'),
pht('Aliases'),
))
->setColumnClasses(
array(
'pri',
null,
'wide',
));
$template_text = pht(<<<EOTEXT
Template Objects
----------------
Instead of specifying each field value individually, you can specify another
object to use as a template. Some of the initial fields will be copied from the
template object.
Specify a template object with the `template` parameter. You can use an ID,
PHID, or monogram (for objects which have monograms). For example, you might
use URIs like these:
```
%s?template=123
%s?template=PHID-WXYZ-abcdef...
%s?template=T123
```
You can combine the `template` parameter with HTTP parameters: the template
object will be copied first, then any HTTP parameters will be read.
When using `template`, these fields will be copied:
EOTEXT
,
$uri,
$uri,
$uri);
- $yes = id(new PHUIIconView())->setIconFont('fa-check-circle green');
- $no = id(new PHUIIconView())->setIconFont('fa-times grey');
+ $yes = id(new PHUIIconView())->setIcon('fa-check-circle green');
+ $no = id(new PHUIIconView())->setIcon('fa-times grey');
$rows = array();
foreach ($fields as $field) {
$rows[] = array(
$field->getLabel(),
$field->getIsCopyable() ? $yes : $no,
);
}
$template_table = id(new AphrontTableView($rows))
->setNoDataString(
pht('None of the fields on this object support templating.'))
->setHeaders(
array(
pht('Field'),
pht('Will Copy'),
))
->setColumnClasses(
array(
'pri',
'wide',
));
$select_text = pht(<<<EOTEXT
Select Fields
-------------
Some fields support selection from a specific set of values. When prefilling
these fields, use the value in the **Value** column to select the appropriate
setting.
EOTEXT
);
$rows = array();
foreach ($fields as $field) {
if (!($field instanceof PhabricatorSelectEditField)) {
continue;
}
$options = $field->getOptions();
$label = $field->getLabel();
foreach ($options as $option_key => $option_value) {
if (strlen($option_key)) {
$option_display = $option_key;
} else {
$option_display = phutil_tag('em', array(), pht('<empty>'));
}
$rows[] = array(
$label,
$option_display,
$option_value,
);
$label = null;
}
}
$select_table = id(new AphrontTableView($rows))
->setNoDataString(pht('This object has no select fields.'))
->setHeaders(
array(
pht('Field'),
pht('Value'),
pht('Label'),
))
->setColumnClasses(
array(
'pri',
null,
'wide',
));
$types_text = pht(<<<EOTEXT
Field Types
-----------
Fields in this form have the types described in the table below. This table
shows how to format values for each field type.
EOTEXT
);
$types_table = id(new PhabricatorHTTPParameterTypeTableView())
->setHTTPParameterTypes($types);
return array(
$this->renderInstructions($intro),
$main_table,
$this->renderInstructions($aliases_text),
$alias_table,
$this->renderInstructions($template_text),
$template_table,
$this->renderInstructions($select_text),
$select_table,
$this->renderInstructions($types_text),
$types_table,
);
}
protected function renderInstructions($corpus) {
$viewer = $this->getUser();
return new PHUIRemarkupView($viewer, $corpus);
}
}
diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
index 9ac5b4bdb2..c20999601e 100644
--- a/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
+++ b/src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
@@ -1,343 +1,343 @@
<?php
final class PhabricatorTypeaheadModularDatasourceController
extends PhabricatorTypeaheadDatasourceController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$request = $this->getRequest();
$viewer = $request->getUser();
$query = $request->getStr('q');
$offset = $request->getInt('offset');
$select_phid = null;
$is_browse = ($request->getURIData('action') == 'browse');
$select = $request->getStr('select');
if ($select) {
$select = phutil_json_decode($select);
$query = idx($select, 'q');
$offset = idx($select, 'offset');
$select_phid = idx($select, 'phid');
}
// Default this to the query string to make debugging a little bit easier.
$raw_query = nonempty($request->getStr('raw'), $query);
// This makes form submission easier in the debug view.
$class = nonempty($request->getURIData('class'), $request->getStr('class'));
$sources = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorTypeaheadDatasource')
->execute();
if (isset($sources[$class])) {
$source = $sources[$class];
$source->setParameters($request->getRequestData());
$source->setViewer($viewer);
// NOTE: Wrapping the source in a Composite datasource ensures we perform
// application visibility checks for the viewer, so we do not need to do
// those separately.
$composite = new PhabricatorTypeaheadRuntimeCompositeDatasource();
$composite->addDatasource($source);
$hard_limit = 1000;
$limit = 100;
$composite
->setViewer($viewer)
->setQuery($query)
->setRawQuery($raw_query)
->setLimit($limit + 1);
if ($is_browse) {
if (!$composite->isBrowsable()) {
return new Aphront404Response();
}
if (($offset + $limit) >= $hard_limit) {
// Offset-based paging is intrinsically slow; hard-cap how far we're
// willing to go with it.
return new Aphront404Response();
}
$composite
->setOffset($offset);
}
$results = $composite->loadResults();
if ($is_browse) {
// If this is a request for a specific token after the user clicks
// "Select", return the token in wire format so it can be added to
// the tokenizer.
if ($select_phid !== null) {
$map = mpull($results, null, 'getPHID');
$token = idx($map, $select_phid);
if (!$token) {
return new Aphront404Response();
}
$payload = array(
'key' => $token->getPHID(),
'token' => $token->getWireFormat(),
);
return id(new AphrontAjaxResponse())->setContent($payload);
}
$format = $request->getStr('format');
switch ($format) {
case 'html':
case 'dialog':
// These are the acceptable response formats.
break;
default:
// Return a dialog if format information is missing or invalid.
$format = 'dialog';
break;
}
$next_link = null;
if (count($results) > $limit) {
$results = array_slice($results, 0, $limit, $preserve_keys = true);
if (($offset + (2 * $limit)) < $hard_limit) {
$next_uri = id(new PhutilURI($request->getRequestURI()))
->setQueryParam('offset', $offset + $limit)
->setQueryParam('format', 'html');
$next_link = javelin_tag(
'a',
array(
'href' => $next_uri,
'class' => 'typeahead-browse-more',
'sigil' => 'typeahead-browse-more',
'mustcapture' => true,
),
pht('More Results'));
} else {
// If the user has paged through more than 1K results, don't
// offer to page any further.
$next_link = javelin_tag(
'div',
array(
'class' => 'typeahead-browse-hard-limit',
),
pht('You reach the edge of the abyss.'));
}
}
$exclude = $request->getStrList('exclude');
$exclude = array_fuse($exclude);
$select = array(
'offset' => $offset,
'q' => $query,
);
$items = array();
foreach ($results as $result) {
$token = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
$result);
// Disable already-selected tokens.
$disabled = isset($exclude[$result->getPHID()]);
$value = $select + array('phid' => $result->getPHID());
$value = json_encode($value);
$button = phutil_tag(
'button',
array(
'class' => 'small grey',
'name' => 'select',
'value' => $value,
'disabled' => $disabled ? 'disabled' : null,
),
pht('Select'));
$items[] = phutil_tag(
'div',
array(
'class' => 'typeahead-browse-item grouped',
),
array(
$token,
$button,
));
}
$markup = array(
$items,
$next_link,
);
if ($format == 'html') {
$content = array(
'markup' => hsprintf('%s', $markup),
);
return id(new AphrontAjaxResponse())->setContent($content);
}
$this->requireResource('typeahead-browse-css');
$this->initBehavior('typeahead-browse');
$input_id = celerity_generate_unique_node_id();
$frame_id = celerity_generate_unique_node_id();
$config = array(
'inputID' => $input_id,
'frameID' => $frame_id,
'uri' => (string)$request->getRequestURI(),
);
$this->initBehavior('typeahead-search', $config);
$search = javelin_tag(
'input',
array(
'type' => 'text',
'id' => $input_id,
'class' => 'typeahead-browse-input',
'autocomplete' => 'off',
'placeholder' => $source->getPlaceholderText(),
));
$frame = phutil_tag(
'div',
array(
'class' => 'typeahead-browse-frame',
'id' => $frame_id,
),
$markup);
$browser = array(
phutil_tag(
'div',
array(
'class' => 'typeahead-browse-header',
),
$search),
$frame,
);
$function_help = null;
if ($source->getAllDatasourceFunctions()) {
$reference_uri = '/typeahead/help/'.get_class($source).'/';
$reference_link = phutil_tag(
'a',
array(
'href' => $reference_uri,
'target' => '_blank',
),
pht('Reference: Advanced Functions'));
$function_help = array(
id(new PHUIIconView())
- ->setIconFont('fa-book'),
+ ->setIcon('fa-book'),
' ',
$reference_link,
);
}
return $this->newDialog()
->setWidth(AphrontDialogView::WIDTH_FORM)
->setRenderDialogAsDiv(true)
->setTitle($source->getBrowseTitle())
->appendChild($browser)
->addFooter($function_help)
->addCancelButton('/', pht('Close'));
}
} else if ($is_browse) {
return new Aphront404Response();
} else {
$results = array();
}
$content = mpull($results, 'getWireFormat');
$content = array_values($content);
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())->setContent($content);
}
// If there's a non-Ajax request to this endpoint, show results in a tabular
// format to make it easier to debug typeahead output.
foreach ($sources as $key => $source) {
// This can happen with composite or generic sources.
if (!$source->getDatasourceApplicationClass()) {
continue;
}
if (!PhabricatorApplication::isClassInstalledForViewer(
$source->getDatasourceApplicationClass(),
$viewer)) {
unset($sources[$key]);
}
}
$options = array_fuse(array_keys($sources));
asort($options);
$form = id(new AphrontFormView())
->setUser($viewer)
->setAction('/typeahead/class/')
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Source Class'))
->setName('class')
->setValue($class)
->setOptions($options))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Query'))
->setName('q')
->setValue($request->getStr('q')))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Raw Query'))
->setName('raw')
->setValue($request->getStr('raw')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Query')));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Token Query'))
->setForm($form);
$table = new AphrontTableView($content);
$table->setHeaders(
array(
pht('Name'),
pht('URI'),
pht('PHID'),
pht('Priority'),
pht('Display Name'),
pht('Display Type'),
pht('Image URI'),
pht('Priority Type'),
pht('Icon'),
pht('Closed'),
pht('Sprite'),
));
$result_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Token Results (%s)', $class))
->appendChild($table);
return $this->buildApplicationPage(
array(
$form_box,
$result_box,
),
array(
'title' => pht('Typeahead Results'),
'device' => false,
));
}
}
diff --git a/src/applications/uiexample/examples/PHUIBoxExample.php b/src/applications/uiexample/examples/PHUIBoxExample.php
index 0467a71e3b..9634520e89 100644
--- a/src/applications/uiexample/examples/PHUIBoxExample.php
+++ b/src/applications/uiexample/examples/PHUIBoxExample.php
@@ -1,133 +1,131 @@
<?php
final class PHUIBoxExample extends PhabricatorUIExample {
public function getName() {
return pht('Box');
}
public function getDescription() {
return pht("It's a fancy or non-fancy box. Put stuff in it.");
}
public function renderExample() {
$content1 = 'Asmund and Signy';
$content2 = 'The Cottager and his Cat';
$content3 = "Geirlug The King's Daughter";
$layout1 =
array(
id(new PHUIBoxView())
->appendChild($content1),
id(new PHUIBoxView())
->appendChild($content2),
id(new PHUIBoxView())
->appendChild($content3),
);
$layout2 =
array(
id(new PHUIBoxView())
->appendChild($content1)
->addMargin(PHUI::MARGIN_SMALL_LEFT),
id(new PHUIBoxView())
->appendChild($content2)
->addMargin(PHUI::MARGIN_MEDIUM_LEFT)
->addMargin(PHUI::MARGIN_MEDIUM_TOP),
id(new PHUIBoxView())
->appendChild($content3)
->addMargin(PHUI::MARGIN_LARGE_LEFT)
->addMargin(PHUI::MARGIN_LARGE_TOP),
);
$layout3 =
array(
id(new PHUIBoxView())
->appendChild($content1)
->setBorder(true)
->addPadding(PHUI::PADDING_SMALL)
->addMargin(PHUI::MARGIN_LARGE_BOTTOM),
id(new PHUIBoxView())
->appendChild($content2)
->setBorder(true)
->addPadding(PHUI::PADDING_MEDIUM)
->addMargin(PHUI::MARGIN_LARGE_BOTTOM),
id(new PHUIBoxView())
->appendChild($content3)
->setBorder(true)
->addPadding(PHUI::PADDING_LARGE)
->addMargin(PHUI::MARGIN_LARGE_BOTTOM),
);
- $image = id(new PHUIIconView())
- ->setIconFont('fa-heart');
$button = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::SIMPLE)
- ->setIcon($image)
+ ->setIcon('fa-heart')
->setText(pht('Such Wow'))
->addClass(PHUI::MARGIN_SMALL_RIGHT);
$badge1 = id(new PHUIBadgeMiniView())
->setIcon('fa-bug')
->setHeader(pht('Bugmeister'));
$badge2 = id(new PHUIBadgeMiniView())
->setIcon('fa-heart')
->setHeader(pht('Funder'))
->setQuality(PHUIBadgeView::UNCOMMON);
$header = id(new PHUIHeaderView())
->setHeader(pht('Fancy Box'))
->addActionLink($button)
->setSubheader(pht('Much Features'))
->addBadge($badge1)
->addBadge($badge2);
$obj4 = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild(id(new PHUIBoxView())
->addPadding(PHUI::PADDING_MEDIUM)
->appendChild(pht('Such Fancy, Nice Box, Many Corners.')));
$head1 = id(new PHUIHeaderView())
->setHeader(pht('Plain Box'));
$head2 = id(new PHUIHeaderView())
->setHeader(pht('Plain Box with space'));
$head3 = id(new PHUIHeaderView())
->setHeader(pht('Border Box with space'));
$head4 = id(new PHUIHeaderView())
->setHeader(pht('PHUIObjectBoxView'));
$wrap1 = id(new PHUIBoxView())
->appendChild($layout1)
->addMargin(PHUI::MARGIN_LARGE);
$wrap2 = id(new PHUIBoxView())
->appendChild($layout2)
->addMargin(PHUI::MARGIN_LARGE);
$wrap3 = id(new PHUIBoxView())
->appendChild($layout3)
->addMargin(PHUI::MARGIN_LARGE);
return phutil_tag(
'div',
array(),
array(
$head1,
$wrap1,
$head2,
$wrap2,
$head3,
$wrap3,
$head4,
$obj4,
));
}
}
diff --git a/src/applications/uiexample/examples/PHUIButtonBarExample.php b/src/applications/uiexample/examples/PHUIButtonBarExample.php
index e41234e5bd..1501770dcf 100644
--- a/src/applications/uiexample/examples/PHUIButtonBarExample.php
+++ b/src/applications/uiexample/examples/PHUIButtonBarExample.php
@@ -1,103 +1,95 @@
<?php
final class PHUIButtonBarExample extends PhabricatorUIExample {
public function getName() {
return pht('Button Bar');
}
public function getDescription() {
return pht('A minimal UI for Buttons');
}
public function renderExample() {
$request = $this->getRequest();
$user = $request->getUser();
// Icon Buttons
$icons = array(
'Go Back' => 'fa-chevron-left bluegrey',
'Choose Date' => 'fa-calendar bluegrey',
'Edit View' => 'fa-pencil bluegrey',
'Go Forward' => 'fa-chevron-right bluegrey',
);
$button_bar1 = new PHUIButtonBarView();
foreach ($icons as $text => $icon) {
- $image = id(new PHUIIconView())
- ->setIconFont($icon);
$button = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setTitle($text)
- ->setIcon($image);
+ ->setIcon($icon);
$button_bar1->addButton($button);
}
$button_bar2 = new PHUIButtonBarView();
foreach ($icons as $text => $icon) {
- $image = id(new PHUIIconView())
- ->setIconFont($icon);
$button = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::SIMPLE)
->setTitle($text)
->setText($text);
$button_bar2->addButton($button);
}
$button_bar3 = new PHUIButtonBarView();
foreach ($icons as $text => $icon) {
- $image = id(new PHUIIconView())
- ->setIconFont($icon);
$button = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::SIMPLE)
->setTitle($text)
->setTooltip($text)
- ->setIcon($image);
+ ->setIcon($icon);
$button_bar3->addButton($button);
}
$button_bar4 = new PHUIButtonBarView();
$button_bar4->setBorderless(true);
foreach ($icons as $text => $icon) {
- $image = id(new PHUIIconView())
- ->setIconFont($icon);
$button = id(new PHUIButtonView())
->setTag('a')
->setTitle($text)
->setTooltip($text)
- ->setIcon($image);
+ ->setIcon($icon);
$button_bar4->addButton($button);
}
$layout1 = id(new PHUIBoxView())
->appendChild($button_bar1)
->addClass('ml');
$layout2 = id(new PHUIBoxView())
->appendChild($button_bar2)
->addClass('mlr mll mlb');
$layout3 = id(new PHUIBoxView())
->appendChild($button_bar3)
->addClass('mlr mll mlb');
$layout4 = id(new PHUIBoxView())
->appendChild($button_bar4)
->addClass('mlr mll mlb');
$wrap1 = id(new PHUIObjectBoxView())
->setHeaderText(pht('Button Bar Example'))
->appendChild($layout1)
->appendChild($layout2)
->appendChild($layout3)
->appendChild($layout4);
return array($wrap1);
}
}
diff --git a/src/applications/uiexample/examples/PHUIButtonExample.php b/src/applications/uiexample/examples/PHUIButtonExample.php
index 06cf369ba2..ae699eb7a3 100644
--- a/src/applications/uiexample/examples/PHUIButtonExample.php
+++ b/src/applications/uiexample/examples/PHUIButtonExample.php
@@ -1,234 +1,230 @@
<?php
final class PHUIButtonExample extends PhabricatorUIExample {
public function getName() {
return pht('Buttons');
}
public function getDescription() {
return pht(
'Use %s to render buttons.',
phutil_tag('tt', array(), '&lt;button&gt;'));
}
public function renderExample() {
$request = $this->getRequest();
$user = $request->getUser();
$colors = array('', 'green', 'grey', 'disabled');
$sizes = array('', 'small');
$tags = array('a', 'button');
// phutil_tag
$column = array();
foreach ($tags as $tag) {
foreach ($colors as $color) {
foreach ($sizes as $key => $size) {
$class = implode(' ', array($color, $size));
if ($tag == 'a') {
$class .= ' button';
}
$column[$key][] = phutil_tag(
$tag,
array(
'class' => $class,
),
phutil_utf8_ucwords($size.' '.$color.' '.$tag));
$column[$key][] = hsprintf('<br /><br />');
}
}
}
$column3 = array();
foreach ($colors as $color) {
$caret = phutil_tag('span', array('class' => 'caret'), '');
$column3[] = phutil_tag(
'a',
array(
'class' => $color.' button dropdown',
),
array(
phutil_utf8_ucwords($color.' Dropdown'),
$caret,
));
$column3[] = hsprintf('<br /><br />');
}
$layout1 = id(new AphrontMultiColumnView())
->addColumn($column[0])
->addColumn($column[1])
->addColumn($column3)
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
// PHUIButtonView
$colors = array(
null,
PHUIButtonView::GREEN,
PHUIButtonView::GREY,
PHUIButtonView::DISABLED,
);
$sizes = array(null, PHUIButtonView::SMALL);
$column = array();
foreach ($colors as $color) {
foreach ($sizes as $key => $size) {
$column[$key][] = id(new PHUIButtonView())
->setColor($color)
->setSize($size)
->setTag('a')
->setText(pht('Clicky'));
$column[$key][] = hsprintf('<br /><br />');
}
}
foreach ($colors as $color) {
$column[2][] = id(new PHUIButtonView())
->setColor($color)
->setTag('button')
->setText(pht('Button'))
->setDropdown(true);
$column[2][] = hsprintf('<br /><br />');
}
$layout2 = id(new AphrontMultiColumnView())
->addColumn($column[0])
->addColumn($column[1])
->addColumn($column[2])
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
// Icon Buttons
$column = array();
$icons = array(
'Comment' => 'fa-comment',
'Give Token' => 'fa-trophy',
'Reverse Time' => 'fa-clock-o',
'Implode Earth' => 'fa-exclamation-triangle red',
);
foreach ($icons as $text => $icon) {
- $image = id(new PHUIIconView())
- ->setIconFont($icon);
$column[] = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
- ->setIcon($image)
+ ->setIcon($icon)
->setText($text)
->addClass(PHUI::MARGIN_SMALL_RIGHT);
}
$layout3 = id(new AphrontMultiColumnView())
->addColumn($column)
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
$icons = array(
'Subscribe' => 'fa-check-circle bluegrey',
'Edit' => 'fa-pencil bluegrey',
);
$colors = array(
PHUIButtonView::SIMPLE,
PHUIButtonView::SIMPLE_YELLOW,
PHUIButtonView::SIMPLE_GREY,
PHUIButtonView::SIMPLE_BLUE,
);
$column = array();
foreach ($colors as $color) {
foreach ($icons as $text => $icon) {
- $image = id(new PHUIIconView())
- ->setIconFont($icon);
$column[] = id(new PHUIButtonView())
->setTag('a')
->setColor($color)
- ->setIcon($image)
+ ->setIcon($icon)
->setText($text)
->addClass(PHUI::MARGIN_SMALL_RIGHT);
}
}
$layout4 = id(new AphrontMultiColumnView())
->addColumn($column)
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
// Baby Got Back Buttons
$column = array();
$icons = array('Asana', 'Github', 'Facebook', 'Google', 'LDAP');
foreach ($icons as $icon) {
$image = id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_LOGIN)
->setSpriteIcon($icon);
$column[] = id(new PHUIButtonView())
->setTag('a')
->setSize(PHUIButtonView::BIG)
->setColor(PHUIButtonView::GREY)
->setIcon($image)
->setText(pht('Login or Register'))
->setSubtext($icon)
->addClass(PHUI::MARGIN_MEDIUM_RIGHT);
}
$layout5 = id(new AphrontMultiColumnView())
->addColumn($column)
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
// Set it and forget it
$head1 = id(new PHUIHeaderView())
->setHeader('phutil_tag');
$head2 = id(new PHUIHeaderView())
->setHeader('PHUIButtonView');
$head3 = id(new PHUIHeaderView())
->setHeader(pht('Icon Buttons'));
$head4 = id(new PHUIHeaderView())
->setHeader(pht('Simple Buttons'));
$head5 = id(new PHUIHeaderView())
->setHeader(pht('Big Icon Buttons'));
$wrap1 = id(new PHUIBoxView())
->appendChild($layout1)
->addMargin(PHUI::MARGIN_LARGE);
$wrap2 = id(new PHUIBoxView())
->appendChild($layout2)
->addMargin(PHUI::MARGIN_LARGE);
$wrap3 = id(new PHUIBoxView())
->appendChild($layout3)
->addMargin(PHUI::MARGIN_LARGE);
$wrap4 = id(new PHUIBoxView())
->appendChild($layout4)
->addMargin(PHUI::MARGIN_LARGE);
$wrap5 = id(new PHUIBoxView())
->appendChild($layout5)
->addMargin(PHUI::MARGIN_LARGE);
return array(
$head1,
$wrap1,
$head2,
$wrap2,
$head3,
$wrap3,
$head4,
$wrap4,
$head5,
$wrap5,
);
}
}
diff --git a/src/applications/uiexample/examples/PHUIFeedStoryExample.php b/src/applications/uiexample/examples/PHUIFeedStoryExample.php
index 6731f1ce1f..375c6e42fd 100644
--- a/src/applications/uiexample/examples/PHUIFeedStoryExample.php
+++ b/src/applications/uiexample/examples/PHUIFeedStoryExample.php
@@ -1,223 +1,223 @@
<?php
final class PHUIFeedStoryExample extends PhabricatorUIExample {
public function getName() {
return pht('Feed Story');
}
public function getDescription() {
return pht(
'An outlandish exaggeration of intricate tales from around the realm');
}
public function renderExample() {
$request = $this->getRequest();
$user = $request->getUser();
/* Basic Story */
$text = hsprintf(
'<strong><a>harding (Tom Harding)</a></strong> closed <a>'.
'D12: New spacer classes for blog views</a>.');
$story1 = id(new PHUIFeedStoryView())
->setTitle($text)
->setImage(celerity_get_resource_uri('/rsrc/image/people/harding.png'))
->setImageHref('http://en.wikipedia.org/wiki/Warren_G._Harding')
->setEpoch(1)
->setAppIcon('fa-star')
->setUser($user);
/* Text Story, useful in Blogs, Ponders, Status */
$tokens = array(
'like-1',
'like-2',
'heart-1',
'heart-2',
);
$tokenview = array();
foreach ($tokens as $token) {
$tokenview[] =
id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_TOKENS)
->setSpriteIcon($token);
}
$text = hsprintf(
'<strong><a>lincoln (Honest Abe)</a></strong> wrote a '.
'new blog post.');
$story2 = id(new PHUIFeedStoryView())
->setTitle($text)
->setImage(celerity_get_resource_uri('/rsrc/image/people/lincoln.png'))
->setImageHref('http://en.wikipedia.org/wiki/Abraham_Lincoln')
->setEpoch(strtotime('November 19, 1863'))
->setAppIcon('fa-star')
->setUser($user)
->setTokenBar($tokenview)
->setPontification(
'Four score and seven years ago our fathers brought '.
'forth on this continent, a new nation, conceived in Liberty, and '.
'dedicated to the proposition that all men are created equal. '.
'Now we are engaged in a great civil war, testing whether that '.
'nation, or any nation so conceived and so dedicated, can long '.
'endure. We are met on a great battle-field of that war. We have '.
'come to dedicate a portion of that field, as a final resting '.
'place for those who here gave their lives that that nation might '.
'live. It is altogether fitting and proper that we should do this.',
'Gettysburg Address');
/* Action Story, let's give people tokens! */
$text = hsprintf(
'<strong><a>harding (Tom Harding)</a></strong> awarded '.
'<a>M10: Workboards</a> a token.');
$action1 = id(new PHUIIconView())
- ->setIconFont('fa-trophy bluegrey')
+ ->setIcon('fa-trophy bluegrey')
->setHref('#');
$token =
id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_TOKENS)
->setSpriteIcon('like-1');
$story3 = id(new PHUIFeedStoryView())
->setTitle($text)
->setImage(celerity_get_resource_uri('/rsrc/image/people/harding.png'))
->setImageHref('http://en.wikipedia.org/wiki/Warren_G._Harding')
->appendChild($token)
->setEpoch(1)
->addAction($action1)
->setAppIcon('fa-trophy')
->setUser($user);
/* Image Story, used in Pholio, Macro */
$text = hsprintf(
'<strong><a>wgharding (Warren Harding)</a></strong> '.
'asked a new question.');
$action1 = id(new PHUIIconView())
- ->setIconFont('fa-chevron-up bluegrey')
+ ->setIcon('fa-chevron-up bluegrey')
->setHref('#');
$action2 = id(new PHUIIconView())
- ->setIconFont('fa-chevron-down bluegrey')
+ ->setIcon('fa-chevron-down bluegrey')
->setHref('#');
$story4 = id(new PHUIFeedStoryView())
->setTitle($text)
->setImage(celerity_get_resource_uri('/rsrc/image/people/harding.png'))
->setImageHref('http://en.wikipedia.org/wiki/Warren_G._Harding')
->setEpoch(1)
->setAppIcon('fa-cogs')
->setPontification(
'Why does inline-block add space under my spans and anchors?')
->addAction($action1)
->addAction($action2)
->setUser($user);
/* Text Story, useful in Blogs, Ponders, Status */
$text = hsprintf(
'<strong><a>lincoln (Honest Abe)</a></strong> updated '.
'his status.');
$story5 = id(new PHUIFeedStoryView())
->setTitle($text)
->setImage(celerity_get_resource_uri('/rsrc/image/people/lincoln.png'))
->setImageHref('http://en.wikipedia.org/wiki/Abraham_Lincoln')
->setEpoch(strtotime('November 19, 1863'))
->setAppIcon('fa-rocket')
->setUser($user)
->setPontification(
'If we ever create a lightweight status app '.
'this story would be how that would be displayed.');
/* Basic "One Line" Story */
$text = hsprintf(
'<strong><a>harding (Tom Harding)</a></strong> updated <a>'.
'D12: New spacer classes for blog views</a>.');
$story6 = id(new PHUIFeedStoryView())
->setTitle($text)
->setImage(celerity_get_resource_uri('/rsrc/image/people/harding.png'))
->setImageHref('http://en.wikipedia.org/wiki/Warren_G._Harding')
->setEpoch(1)
->setAppIcon('fa-wifi')
->setUser($user);
$head1 = id(new PHUIHeaderView())
->setHeader(pht('Basic Story'));
$head2 = id(new PHUIHeaderView())
->setHeader(pht('Title / Text Story'));
$head3 = id(new PHUIHeaderView())
->setHeader(pht('Token Story'));
$head4 = id(new PHUIHeaderView())
->setHeader(pht('Action Story'));
$head5 = id(new PHUIHeaderView())
->setHeader(pht('Status Story'));
$head6 = id(new PHUIHeaderView())
->setHeader(pht('One Line Story'));
$wrap1 =
array(
id(new PHUIBoxView())
->appendChild($story1)
->addMargin(PHUI::MARGIN_MEDIUM)
->addPadding(PHUI::PADDING_SMALL),
);
$wrap2 =
array(
id(new PHUIBoxView())
->appendChild($story2)
->addMargin(PHUI::MARGIN_MEDIUM)
->addPadding(PHUI::PADDING_SMALL),
);
$wrap3 =
array(
id(new PHUIBoxView())
->appendChild($story3)
->addMargin(PHUI::MARGIN_MEDIUM)
->addPadding(PHUI::PADDING_SMALL),
);
$wrap4 =
array(
id(new PHUIBoxView())
->appendChild($story4)
->addMargin(PHUI::MARGIN_MEDIUM)
->addPadding(PHUI::PADDING_SMALL),
);
$wrap5 =
array(
id(new PHUIBoxView())
->appendChild($story5)
->addMargin(PHUI::MARGIN_MEDIUM)
->addPadding(PHUI::PADDING_SMALL),
);
$wrap6 =
array(
id(new PHUIBoxView())
->appendChild($story6)
->addMargin(PHUI::MARGIN_MEDIUM)
->addPadding(PHUI::PADDING_SMALL),
);
return phutil_tag(
'div',
array(),
array(
$head1,
$wrap1,
$head2,
$wrap2,
$head3,
$wrap3,
$head4,
$wrap4,
$head5,
$wrap5,
$head6,
$wrap6,
));
}
}
diff --git a/src/applications/uiexample/examples/PHUIIconExample.php b/src/applications/uiexample/examples/PHUIIconExample.php
index 28d957b460..ad31caba8d 100644
--- a/src/applications/uiexample/examples/PHUIIconExample.php
+++ b/src/applications/uiexample/examples/PHUIIconExample.php
@@ -1,207 +1,207 @@
<?php
final class PHUIIconExample extends PhabricatorUIExample {
public function getName() {
return pht('Icons and Images');
}
public function getDescription() {
return pht('Easily render icons or images with links and sprites.');
}
private function listTransforms() {
return array(
'ph-rotate-90',
'ph-rotate-180',
'ph-rotate-270',
'ph-flip-horizontal',
'ph-flip-vertical',
'ph-spin',
);
}
public function renderExample() {
$colors = PHUIIconView::getFontIconColors();
$colors = array_merge(array(null), $colors);
$fas = PHUIIconView::getFontIcons();
$trans = $this->listTransforms();
$cicons = array();
foreach ($colors as $color) {
$cicons[] = id(new PHUIIconView())
->addClass('phui-example-icon-transform')
- ->setIconFont('fa-tag '.$color)
+ ->setIcon('fa-tag '.$color)
->setText(pht('fa-tag %s', $color));
}
$ficons = array();
sort($fas);
foreach ($fas as $fa) {
$ficons[] = id(new PHUIIconView())
->addClass('phui-example-icon-name')
- ->setIconFont($fa)
+ ->setIcon($fa)
->setText($fa);
}
$person1 = new PHUIIconView();
$person1->setHeadSize(PHUIIconView::HEAD_MEDIUM);
$person1->setHref('http://en.wikipedia.org/wiki/George_Washington');
$person1->setImage(
celerity_get_resource_uri('/rsrc/image/people/washington.png'));
$person2 = new PHUIIconView();
$person2->setHeadSize(PHUIIconView::HEAD_MEDIUM);
$person2->setHref('http://en.wikipedia.org/wiki/Warren_G._Harding');
$person2->setImage(
celerity_get_resource_uri('/rsrc/image/people/harding.png'));
$person3 = new PHUIIconView();
$person3->setHeadSize(PHUIIconView::HEAD_MEDIUM);
$person3->setHref('http://en.wikipedia.org/wiki/William_Howard_Taft');
$person3->setImage(
celerity_get_resource_uri('/rsrc/image/people/taft.png'));
$person4 = new PHUIIconView();
$person4->setHeadSize(PHUIIconView::HEAD_SMALL);
$person4->setHref('http://en.wikipedia.org/wiki/George_Washington');
$person4->setImage(
celerity_get_resource_uri('/rsrc/image/people/washington.png'));
$person5 = new PHUIIconView();
$person5->setHeadSize(PHUIIconView::HEAD_SMALL);
$person5->setHref('http://en.wikipedia.org/wiki/Warren_G._Harding');
$person5->setImage(
celerity_get_resource_uri('/rsrc/image/people/harding.png'));
$person6 = new PHUIIconView();
$person6->setHeadSize(PHUIIconView::HEAD_SMALL);
$person6->setHref('http://en.wikipedia.org/wiki/William_Howard_Taft');
$person6->setImage(
celerity_get_resource_uri('/rsrc/image/people/taft.png'));
$tokens = array(
'like-1',
'like-2',
'heart-1',
'heart-2',
);
$tokenview = array();
foreach ($tokens as $token) {
$tokenview[] =
id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_TOKENS)
->setSpriteIcon($token);
}
$logins = array(
'Asana',
'Dropbox',
'Google',
'Github',
);
$loginview = array();
foreach ($logins as $login) {
$loginview[] =
id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_LOGIN)
->setSpriteIcon($login)
->addClass(PHUI::MARGIN_SMALL_RIGHT);
}
$circles = array('fa-pencil', 'fa-chevron-left', 'fa-chevron-right');
$circleview = array();
foreach ($circles as $circle) {
$circleview[] =
id(new PHUIIconCircleView())
- ->setIconFont($circle)
+ ->setIcon($circle)
->setHref('#')
->addClass('mmr');
}
$circles = array('fa-plus', 'fa-bars', 'fa-paw');
foreach ($circles as $circle) {
$circleview[] =
id(new PHUIIconCircleView())
- ->setIconFont($circle)
+ ->setIcon($circle)
->setSize(PHUIIconCircleView::MEDIUM)
->setHref('#')
->addClass('mmr');
}
$layout_cicons = id(new PHUIBoxView())
->appendChild($cicons)
->addMargin(PHUI::MARGIN_LARGE);
$layout_fa = id(new PHUIBoxView())
->appendChild($ficons)
->addMargin(PHUI::MARGIN_LARGE);
$layout2 = id(new PHUIBoxView())
->appendChild(array($person1, $person2, $person3))
->addMargin(PHUI::MARGIN_MEDIUM);
$layout2a = id(new PHUIBoxView())
->appendChild(array($person4, $person5, $person6))
->addMargin(PHUI::MARGIN_MEDIUM);
$layout3 = id(new PHUIBoxView())
->appendChild($tokenview)
->addMargin(PHUI::MARGIN_MEDIUM);
$layout4 = id(new PHUIBoxView())
->appendChild($circleview)
->addMargin(PHUI::MARGIN_MEDIUM);
$layout5 = id(new PHUIBoxView())
->appendChild($loginview)
->addMargin(PHUI::MARGIN_MEDIUM);
$fa_link = phutil_tag(
'a',
array(
'href' => 'http://fontawesome.io',
),
'http://fontawesome.io');
$fa_text = pht('Font Awesome by Dave Gandy - %s', $fa_link);
$fontawesome = id(new PHUIObjectBoxView())
->setHeaderText($fa_text)
->appendChild($layout_fa);
$transforms = id(new PHUIObjectBoxView())
->setHeaderText(pht('Colors and Transforms'))
->appendChild($layout_cicons);
$wrap2 = id(new PHUIObjectBoxView())
->setHeaderText(pht('People!'))
->appendChild(array($layout2, $layout2a));
$wrap3 = id(new PHUIObjectBoxView())
->setHeaderText(pht('Tokens'))
->appendChild($layout3);
$wrap4 = id(new PHUIObjectBoxView())
->setHeaderText(pht('Circles'))
->appendChild($layout4);
$wrap5 = id(new PHUIObjectBoxView())
->setHeaderText(pht('Authentication'))
->appendChild($layout5);
return phutil_tag(
'div',
array(
'class' => 'phui-icon-example',
),
array(
$fontawesome,
$transforms,
$wrap2,
$wrap3,
$wrap4,
$wrap5,
));
}
}
diff --git a/src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php b/src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php
index 2c47c744ac..b58b1764a8 100644
--- a/src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php
+++ b/src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php
@@ -1,479 +1,479 @@
<?php
final class PHUIDiffInlineCommentDetailView
extends PHUIDiffInlineCommentView {
private $inlineComment;
private $handles;
private $markupEngine;
private $editable;
private $preview;
private $allowReply;
private $renderer;
private $canMarkDone;
private $objectOwnerPHID;
public function setInlineComment(PhabricatorInlineCommentInterface $comment) {
$this->inlineComment = $comment;
return $this;
}
public function isHidden() {
return $this->inlineComment->isHidden();
}
public function setHandles(array $handles) {
assert_instances_of($handles, 'PhabricatorObjectHandle');
$this->handles = $handles;
return $this;
}
public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
$this->markupEngine = $engine;
return $this;
}
public function setEditable($editable) {
$this->editable = $editable;
return $this;
}
public function setPreview($preview) {
$this->preview = $preview;
return $this;
}
public function setAllowReply($allow_reply) {
$this->allowReply = $allow_reply;
return $this;
}
public function setRenderer($renderer) {
$this->renderer = $renderer;
return $this;
}
public function getRenderer() {
return $this->renderer;
}
public function setCanMarkDone($can_mark_done) {
$this->canMarkDone = $can_mark_done;
return $this;
}
public function getCanMarkDone() {
return $this->canMarkDone;
}
public function setObjectOwnerPHID($phid) {
$this->objectOwnerPHID = $phid;
return $this;
}
public function getObjectOwnerPHID() {
return $this->objectOwnerPHID;
}
public function getAnchorName() {
$inline = $this->inlineComment;
if ($inline->getID()) {
return 'inline-'.$inline->getID();
}
return null;
}
public function getScaffoldCellID() {
$anchor = $this->getAnchorName();
if ($anchor) {
return 'anchor-'.$anchor;
}
return null;
}
public function render() {
require_celerity_resource('phui-inline-comment-view-css');
$inline = $this->inlineComment;
$classes = array(
'differential-inline-comment',
);
$metadata = array(
'id' => $inline->getID(),
'phid' => $inline->getPHID(),
'changesetID' => $inline->getChangesetID(),
'number' => $inline->getLineNumber(),
'length' => $inline->getLineLength(),
'isNewFile' => (bool)$inline->getIsNewFile(),
'on_right' => $this->getIsOnRight(),
'original' => $inline->getContent(),
'replyToCommentPHID' => $inline->getReplyToCommentPHID(),
);
$sigil = 'differential-inline-comment';
if ($this->preview) {
$sigil = $sigil.' differential-inline-comment-preview';
}
$classes = array(
'differential-inline-comment',
);
$content = $inline->getContent();
$handles = $this->handles;
$links = array();
$is_synthetic = false;
if ($inline->getSyntheticAuthor()) {
$is_synthetic = true;
}
$draft_text = null;
if (!$is_synthetic) {
// This display is controlled by CSS
$draft_text = id(new PHUITagView())
->setType(PHUITagView::TYPE_SHADE)
->setName(pht('Unsubmitted'))
->setSlimShady(true)
->setShade(PHUITagView::COLOR_RED)
->addClass('mml inline-draft-text');
}
$ghost_tag = null;
$ghost = $inline->getIsGhost();
$ghost_id = null;
if ($ghost) {
if ($ghost['new']) {
$ghosticon = 'fa-fast-forward';
$reason = pht('View on forward revision');
} else {
$ghosticon = 'fa-fast-backward';
$reason = pht('View on previous revision');
}
$ghost_icon = id(new PHUIIconView())
- ->setIconFont($ghosticon)
+ ->setIcon($ghosticon)
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => $reason,
'size' => 300,
));
$ghost_tag = phutil_tag(
'a',
array(
'class' => 'ghost-icon',
'href' => $ghost['href'],
'target' => '_blank',
),
$ghost_icon);
$classes[] = 'inline-comment-ghost';
}
// I think this is unused
if ($inline->getHasReplies()) {
$classes[] = 'inline-comment-has-reply';
}
// I think this is unused
if ($inline->getReplyToCommentPHID()) {
$classes[] = 'inline-comment-is-reply';
}
$viewer_phid = $this->getUser()->getPHID();
$owner_phid = $this->getObjectOwnerPHID();
if ($viewer_phid) {
if ($viewer_phid == $owner_phid) {
$classes[] = 'viewer-is-object-owner';
}
}
$nextprev = null;
if (!$this->preview) {
$nextprev = new PHUIButtonBarView();
$nextprev->setBorderless(true);
$nextprev->addClass('inline-button-divider');
$up = id(new PHUIButtonView())
->setTag('a')
->setTooltip(pht('Previous'))
- ->setIconFont('fa-chevron-up')
+ ->setIcon('fa-chevron-up')
->addSigil('differential-inline-prev')
->setMustCapture(true);
$down = id(new PHUIButtonView())
->setTag('a')
->setTooltip(pht('Next'))
- ->setIconFont('fa-chevron-down')
+ ->setIcon('fa-chevron-down')
->addSigil('differential-inline-next')
->setMustCapture(true);
if ($this->canHide()) {
$hide = id(new PHUIButtonView())
->setTag('a')
->setTooltip(pht('Hide Comment'))
- ->setIconFont('fa-times')
+ ->setIcon('fa-times')
->addSigil('hide-inline')
->setMustCapture(true);
$nextprev->addButton($hide);
}
$nextprev->addButton($up);
$nextprev->addButton($down);
$action_buttons = array();
if ($this->allowReply) {
if (!$is_synthetic) {
// NOTE: No product reason why you can't reply to these, but the reply
// mechanism currently sends the inline comment ID to the server, not
// file/line information, and synthetic comments don't have an inline
// comment ID.
$action_buttons[] = id(new PHUIButtonView())
->setTag('a')
- ->setIconFont('fa-reply')
+ ->setIcon('fa-reply')
->setTooltip(pht('Reply'))
->addSigil('differential-inline-reply')
->setMustCapture(true);
}
}
}
$anchor_name = $this->getAnchorName();
if ($this->editable && !$this->preview) {
$action_buttons[] = id(new PHUIButtonView())
->setTag('a')
- ->setIconFont('fa-pencil')
+ ->setIcon('fa-pencil')
->setTooltip(pht('Edit'))
->addSigil('differential-inline-edit')
->setMustCapture(true);
$action_buttons[] = id(new PHUIButtonView())
->setTag('a')
- ->setIconFont('fa-trash-o')
+ ->setIcon('fa-trash-o')
->setTooltip(pht('Delete'))
->addSigil('differential-inline-delete')
->setMustCapture(true);
} else if ($this->preview) {
$links[] = javelin_tag(
'a',
array(
'class' => 'inline-button-divider pml msl',
'meta' => array(
'anchor' => $anchor_name,
),
'sigil' => 'differential-inline-preview-jump',
),
pht('Not Visible'));
$action_buttons[] = id(new PHUIButtonView())
->setTag('a')
->setTooltip(pht('Delete'))
- ->setIconFont('fa-trash-o')
+ ->setIcon('fa-trash-o')
->addSigil('differential-inline-delete')
->setMustCapture(true);
}
$done_button = null;
if (!$is_synthetic) {
$draft_state = false;
switch ($inline->getFixedState()) {
case PhabricatorInlineCommentInterface::STATE_DRAFT:
$is_done = ($this->getCanMarkDone());
$draft_state = true;
break;
case PhabricatorInlineCommentInterface::STATE_UNDRAFT:
$is_done = !($this->getCanMarkDone());
$draft_state = true;
break;
case PhabricatorInlineCommentInterface::STATE_DONE:
$is_done = true;
break;
default:
case PhabricatorInlineCommentInterface::STATE_UNDONE:
$is_done = false;
break;
}
// If you don't have permission to mark the comment as "Done", you also
// can not see the draft state.
if (!$this->getCanMarkDone()) {
$draft_state = false;
}
if ($is_done) {
$classes[] = 'inline-is-done';
}
if ($draft_state) {
$classes[] = 'inline-state-is-draft';
}
if ($this->getCanMarkDone()) {
$done_input = javelin_tag(
'input',
array(
'type' => 'checkbox',
'checked' => ($is_done ? 'checked' : null),
'disabled' => ($this->getCanMarkDone() ? null : 'disabled'),
'class' => 'differential-inline-done',
'sigil' => 'differential-inline-done',
));
$done_button = phutil_tag(
'label',
array(
'class' => 'differential-inline-done-label '.
($this->getCanMarkDone() ? null : 'done-is-disabled'),
),
array(
$done_input,
pht('Done'),
));
} else {
if ($is_done) {
- $icon = id(new PHUIIconView())->setIconFont('fa-check sky msr');
+ $icon = id(new PHUIIconView())->setIcon('fa-check sky msr');
$label = pht('Done');
$class = 'button-done';
} else {
$icon = null;
$label = pht('Not Done');
$class = 'button-not-done';
}
$done_button = phutil_tag(
'div',
array(
'class' => 'done-label '.$class,
),
array(
$icon,
$label,
));
}
}
$content = $this->markupEngine->getOutput(
$inline,
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY);
if ($this->preview) {
$anchor = null;
} else {
$anchor = phutil_tag(
'a',
array(
'name' => $anchor_name,
'id' => $anchor_name,
'class' => 'differential-inline-comment-anchor',
),
'');
}
if ($inline->isDraft() && !$is_synthetic) {
$classes[] = 'inline-state-is-draft';
}
if ($is_synthetic) {
$classes[] = 'differential-inline-comment-synthetic';
}
$classes = implode(' ', $classes);
$author_owner = null;
if ($is_synthetic) {
$author = $inline->getSyntheticAuthor();
} else {
$author = $handles[$inline->getAuthorPHID()]->getName();
if ($inline->getAuthorPHID() == $this->objectOwnerPHID) {
$author_owner = id(new PHUITagView())
->setType(PHUITagView::TYPE_SHADE)
->setName(pht('Author'))
->setSlimShady(true)
->setShade(PHUITagView::COLOR_YELLOW)
->addClass('mml');
}
}
$actions = null;
if ($action_buttons) {
$actions = new PHUIButtonBarView();
$actions->setBorderless(true);
$actions->addClass('inline-button-divider');
foreach ($action_buttons as $button) {
$actions->addButton($button);
}
}
$group_left = phutil_tag(
'div',
array(
'class' => 'inline-head-left',
),
array(
$author,
$author_owner,
$draft_text,
$ghost_tag,
));
$group_right = phutil_tag(
'div',
array(
'class' => 'inline-head-right',
),
array(
$anchor,
$done_button,
$links,
$actions,
$nextprev,
));
$markup = javelin_tag(
'div',
array(
'class' => $classes,
'sigil' => $sigil,
'meta' => $metadata,
),
array(
phutil_tag_div('differential-inline-comment-head grouped', array(
$group_left,
$group_right,
)),
phutil_tag_div(
'differential-inline-comment-content',
phutil_tag_div('phabricator-remarkup', $content)),
));
return $markup;
}
private function canHide() {
$inline = $this->inlineComment;
if ($inline->isDraft()) {
return false;
}
if (!$inline->getID()) {
return false;
}
$viewer = $this->getUser();
if (!$viewer->isLoggedIn()) {
return false;
}
if (!$inline->supportsHiding()) {
return false;
}
return true;
}
}
diff --git a/src/infrastructure/diff/view/PHUIDiffRevealIconView.php b/src/infrastructure/diff/view/PHUIDiffRevealIconView.php
index b2c879a8b5..284b72b2be 100644
--- a/src/infrastructure/diff/view/PHUIDiffRevealIconView.php
+++ b/src/infrastructure/diff/view/PHUIDiffRevealIconView.php
@@ -1,27 +1,27 @@
<?php
final class PHUIDiffRevealIconView extends AphrontView {
public function render() {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-comment')
+ ->setIcon('fa-comment')
->addSigil('has-tooltip')
->setMetadata(
array(
'tip' => pht('Show Hidden Comments'),
'align' => 'E',
'size' => 275,
));
return javelin_tag(
'a',
array(
'href' => '#',
'class' => 'reveal-inlines',
'sigil' => 'reveal-inlines',
'mustcapture' => true,
),
$icon);
}
}
diff --git a/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php b/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php
index 41071a69dd..86b924804f 100644
--- a/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php
+++ b/src/infrastructure/diff/view/PhabricatorInlineSummaryView.php
@@ -1,118 +1,118 @@
<?php
final class PhabricatorInlineSummaryView extends AphrontView {
private $groups = array();
public function addCommentGroup($name, array $items) {
if (!isset($this->groups[$name])) {
$this->groups[$name] = $items;
} else {
$this->groups[$name] = array_merge($this->groups[$name], $items);
}
return $this;
}
public function render() {
require_celerity_resource('inline-comment-summary-css');
return hsprintf('%s', $this->renderTable());
}
private function renderTable() {
$rows = array();
foreach ($this->groups as $group => $items) {
$has_where = false;
foreach ($items as $item) {
if (!empty($item['where'])) {
$has_where = true;
break;
}
}
$icon = id(new PHUIIconView())
- ->setIconFont('fa-file-code-o darkbluetext mmr');
+ ->setIcon('fa-file-code-o darkbluetext mmr');
$header = phutil_tag(
'th',
array(
'colspan' => 3,
'class' => 'inline-comment-summary-table-header',
),
array(
$icon,
$group,
));
$rows[] = phutil_tag('tr', array(), $header);
foreach ($items as $item) {
$line = $item['line'];
$length = $item['length'];
if ($length) {
$lines = $line."\xE2\x80\x93".($line + $length);
} else {
$lines = $line;
}
if (isset($item['href'])) {
$href = $item['href'];
$target = '_blank';
$tail = " \xE2\x86\x97";
} else {
$href = '#inline-'.$item['id'];
$target = null;
$tail = null;
}
if ($href) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-share darkbluetext mmr');
+ ->setIcon('fa-share darkbluetext mmr');
$lines = phutil_tag(
'a',
array(
'href' => $href,
'target' => $target,
'class' => 'num',
),
array(
$icon,
$lines,
$tail,
));
}
$where = idx($item, 'where');
$colspan = ($has_where ? null : 2);
$rows[] = phutil_tag(
'tr',
array(),
array(
phutil_tag('td',
array('class' => 'inline-line-number inline-table-dolumn'),
$lines),
($has_where
? phutil_tag('td',
array('class' => 'inline-which-diff inline-table-dolumn'),
$where)
: null),
phutil_tag(
'td',
array(
'class' => 'inline-summary-content inline-table-dolumn',
'colspan' => $colspan,
),
phutil_tag_div('phabricator-remarkup', $item['content'])),
));
}
}
return phutil_tag(
'table',
array(
'class' => 'phabricator-inline-summary-table',
),
phutil_implode_html("\n", $rows));
}
}
diff --git a/src/view/control/AphrontCursorPagerView.php b/src/view/control/AphrontCursorPagerView.php
index 74e8ce0e13..3574c07fa9 100644
--- a/src/view/control/AphrontCursorPagerView.php
+++ b/src/view/control/AphrontCursorPagerView.php
@@ -1,189 +1,189 @@
<?php
final class AphrontCursorPagerView extends AphrontView {
private $afterID;
private $beforeID;
private $pageSize = 100;
private $nextPageID;
private $prevPageID;
private $moreResults;
private $uri;
public function setPageSize($page_size) {
$this->pageSize = max(1, $page_size);
return $this;
}
public function getPageSize() {
return $this->pageSize;
}
public function setURI(PhutilURI $uri) {
$this->uri = $uri;
return $this;
}
public function readFromRequest(AphrontRequest $request) {
$this->uri = $request->getRequestURI();
$this->afterID = $request->getStr('after');
$this->beforeID = $request->getStr('before');
return $this;
}
public function setAfterID($after_id) {
$this->afterID = $after_id;
return $this;
}
public function getAfterID() {
return $this->afterID;
}
public function setBeforeID($before_id) {
$this->beforeID = $before_id;
return $this;
}
public function getBeforeID() {
return $this->beforeID;
}
public function setNextPageID($next_page_id) {
$this->nextPageID = $next_page_id;
return $this;
}
public function getNextPageID() {
return $this->nextPageID;
}
public function setPrevPageID($prev_page_id) {
$this->prevPageID = $prev_page_id;
return $this;
}
public function getPrevPageID() {
return $this->prevPageID;
}
public function sliceResults(array $results) {
if (count($results) > $this->getPageSize()) {
$offset = ($this->beforeID ? count($results) - $this->getPageSize() : 0);
$results = array_slice($results, $offset, $this->getPageSize(), true);
$this->moreResults = true;
}
return $results;
}
public function getHasMoreResults() {
return $this->moreResults;
}
public function willShowPagingControls() {
return $this->prevPageID ||
$this->nextPageID ||
$this->afterID ||
($this->beforeID && $this->moreResults);
}
public function getFirstPageURI() {
if (!$this->uri) {
throw new PhutilInvalidStateException('setURI');
}
if (!$this->afterID && !($this->beforeID && $this->moreResults)) {
return null;
}
return $this->uri
->alter('before', null)
->alter('after', null);
}
public function getPrevPageURI() {
if (!$this->uri) {
throw new PhutilInvalidStateException('getPrevPageURI');
}
if (!$this->prevPageID) {
return null;
}
return $this->uri
->alter('after', null)
->alter('before', $this->prevPageID);
}
public function getNextPageURI() {
if (!$this->uri) {
throw new PhutilInvalidStateException('setURI');
}
if (!$this->nextPageID) {
return null;
}
return $this->uri
->alter('after', $this->nextPageID)
->alter('before', null);
}
public function render() {
if (!$this->uri) {
throw new PhutilInvalidStateException('setURI');
}
$links = array();
$first_uri = $this->getFirstPageURI();
if ($first_uri) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-fast-backward');
+ ->setIcon('fa-fast-backward');
$links[] = id(new PHUIButtonView())
->setTag('a')
->setHref($first_uri)
->setIcon($icon)
->addClass('mml')
->setColor(PHUIButtonView::SIMPLE)
->setText(pht('First'));
}
$prev_uri = $this->getPrevPageURI();
if ($prev_uri) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-backward');
+ ->setIcon('fa-backward');
$links[] = id(new PHUIButtonView())
->setTag('a')
->setHref($prev_uri)
->setIcon($icon)
->addClass('mml')
->setColor(PHUIButtonView::SIMPLE)
->setText(pht('Prev'));
}
$next_uri = $this->getNextPageURI();
if ($next_uri) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-forward');
+ ->setIcon('fa-forward');
$links[] = id(new PHUIButtonView())
->setTag('a')
->setHref($next_uri)
->setIcon($icon, false)
->addClass('mml')
->setColor(PHUIButtonView::SIMPLE)
->setText(pht('Next'));
}
return phutil_tag(
'div',
array(
'class' => 'phui-pager-view',
),
$links);
}
}
diff --git a/src/view/control/AphrontTokenizerTemplateView.php b/src/view/control/AphrontTokenizerTemplateView.php
index 74456e84b8..facab93497 100644
--- a/src/view/control/AphrontTokenizerTemplateView.php
+++ b/src/view/control/AphrontTokenizerTemplateView.php
@@ -1,127 +1,127 @@
<?php
final class AphrontTokenizerTemplateView extends AphrontView {
private $value;
private $name;
private $id;
private $browseURI;
private $initialValue;
public function setBrowseURI($browse_uri) {
$this->browseURI = $browse_uri;
return $this;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function setValue(array $value) {
assert_instances_of($value, 'PhabricatorTypeaheadTokenView');
$this->value = $value;
return $this;
}
public function getValue() {
return $this->value;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setInitialValue(array $initial_value) {
$this->initialValue = $initial_value;
return $this;
}
public function getInitialValue() {
return $this->initialValue;
}
public function render() {
require_celerity_resource('aphront-tokenizer-control-css');
$id = $this->id;
$name = $this->getName();
$tokens = nonempty($this->getValue(), array());
$input = javelin_tag(
'input',
array(
'mustcapture' => true,
'name' => $name,
'class' => 'jx-tokenizer-input',
'sigil' => 'tokenizer-input',
'style' => 'width: 0px;',
'disabled' => 'disabled',
'type' => 'text',
));
$content = $tokens;
$content[] = $input;
$content[] = phutil_tag('div', array('style' => 'clear: both;'), '');
$container = javelin_tag(
'div',
array(
'id' => $id,
'class' => 'jx-tokenizer-container',
'sigil' => 'tokenizer-container',
),
$content);
$icon = id(new PHUIIconView())
- ->setIconFont('fa-search');
+ ->setIcon('fa-search');
$browse = id(new PHUIButtonView())
->setTag('a')
->setIcon($icon)
->addClass('tokenizer-browse-button')
->setColor(PHUIButtonView::GREY)
->addSigil('tokenizer-browse');
$classes = array();
$classes[] = 'jx-tokenizer-frame';
if ($this->browseURI) {
$classes[] = 'has-browse';
}
$initial = array();
$initial_value = $this->getInitialValue();
if ($initial_value) {
foreach ($this->getInitialValue() as $value) {
$initial[] = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => $name.'.initial[]',
'value' => $value,
));
}
}
$frame = javelin_tag(
'div',
array(
'class' => implode(' ', $classes),
'sigil' => 'tokenizer-frame',
),
array(
$container,
$browse,
$initial,
));
return $frame;
}
}
diff --git a/src/view/form/control/AphrontFormDateControl.php b/src/view/form/control/AphrontFormDateControl.php
index e08be84dc3..75398d688a 100644
--- a/src/view/form/control/AphrontFormDateControl.php
+++ b/src/view/form/control/AphrontFormDateControl.php
@@ -1,374 +1,374 @@
<?php
final class AphrontFormDateControl extends AphrontFormControl {
private $initialTime;
private $zone;
private $valueDate;
private $valueTime;
private $allowNull;
private $continueOnInvalidDate = false;
private $isTimeDisabled;
private $isDisabled;
private $endDateID;
public function setAllowNull($allow_null) {
$this->allowNull = $allow_null;
return $this;
}
public function setIsTimeDisabled($is_disabled) {
$this->isTimeDisabled = $is_disabled;
return $this;
}
public function setIsDisabled($is_datepicker_disabled) {
$this->isDisabled = $is_datepicker_disabled;
return $this;
}
public function setEndDateID($value) {
$this->endDateID = $value;
return $this;
}
const TIME_START_OF_DAY = 'start-of-day';
const TIME_END_OF_DAY = 'end-of-day';
const TIME_START_OF_BUSINESS = 'start-of-business';
const TIME_END_OF_BUSINESS = 'end-of-business';
public function setInitialTime($time) {
$this->initialTime = $time;
return $this;
}
public function readValueFromRequest(AphrontRequest $request) {
$date = $request->getStr($this->getDateInputName());
$time = $request->getStr($this->getTimeInputName());
$enabled = $request->getBool($this->getCheckboxInputName());
if ($this->allowNull && !$enabled) {
$this->setError(null);
$this->setValue(null);
return;
}
$err = $this->getError();
if ($date || $time) {
$this->valueDate = $date;
$this->valueTime = $time;
// Assume invalid.
$err = pht('Invalid');
$zone = $this->getTimezone();
try {
$datetime = new DateTime("{$date} {$time}", $zone);
$value = $datetime->format('U');
} catch (Exception $ex) {
$value = null;
}
if ($value) {
$this->setValue($value);
$err = null;
} else {
$this->setValue(null);
}
} else {
$value = $this->getInitialValue();
if ($value) {
$this->setValue($value);
} else {
$this->setValue(null);
}
}
$this->setError($err);
return $this->getValue();
}
protected function getCustomControlClass() {
return 'aphront-form-control-date';
}
public function setValue($epoch) {
if ($epoch instanceof AphrontFormDateControlValue) {
$this->continueOnInvalidDate = true;
$this->valueDate = $epoch->getValueDate();
$this->valueTime = $epoch->getValueTime();
$this->allowNull = $epoch->getOptional();
$this->isDisabled = $epoch->isDisabled();
return parent::setValue($epoch->getEpoch());
}
$result = parent::setValue($epoch);
if ($epoch === null) {
return $result;
}
$readable = $this->formatTime($epoch, 'Y!m!d!g:i A');
$readable = explode('!', $readable, 4);
$year = $readable[0];
$month = $readable[1];
$day = $readable[2];
$this->valueDate = $month.'/'.$day.'/'.$year;
$this->valueTime = $readable[3];
return $result;
}
private function getDateInputValue() {
$date_format = $this->getDateFormat();
$timezone = $this->getTimezone();
$datetime = new DateTime($this->valueDate, $timezone);
$date = $datetime->format($date_format);
return $date;
}
private function getTimeFormat() {
return $this->getUser()
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
}
private function getDateFormat() {
return $this->getUser()
->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT);
}
private function getTimeInputValue() {
return $this->valueTime;
}
private function formatTime($epoch, $fmt) {
return phabricator_format_local_time(
$epoch,
$this->user,
$fmt);
}
private function getDateInputName() {
return $this->getName().'_d';
}
private function getTimeInputName() {
return $this->getName().'_t';
}
private function getCheckboxInputName() {
return $this->getName().'_e';
}
protected function renderInput() {
$disabled = null;
if ($this->getValue() === null && !$this->continueOnInvalidDate) {
$this->setValue($this->getInitialValue());
if ($this->allowNull) {
$disabled = 'disabled';
}
}
if ($this->isDisabled) {
$disabled = 'disabled';
}
$checkbox = null;
if ($this->allowNull) {
$checkbox = javelin_tag(
'input',
array(
'type' => 'checkbox',
'name' => $this->getCheckboxInputName(),
'sigil' => 'calendar-enable',
'class' => 'aphront-form-date-enabled-input',
'value' => 1,
'checked' => ($disabled === null ? 'checked' : null),
));
}
$date_sel = javelin_tag(
'input',
array(
'autocomplete' => 'off',
'name' => $this->getDateInputName(),
'sigil' => 'date-input',
'value' => $this->getDateInputValue(),
'type' => 'text',
'class' => 'aphront-form-date-input',
),
'');
$date_div = javelin_tag(
'div',
array(
'class' => 'aphront-form-date-input-container',
),
$date_sel);
$cicon = id(new PHUIIconView())
- ->setIconFont('fa-calendar');
+ ->setIcon('fa-calendar');
$cal_icon = javelin_tag(
'a',
array(
'href' => '#',
'class' => 'calendar-button',
'sigil' => 'calendar-button',
),
$cicon);
$values = $this->getTimeTypeaheadValues();
$time_id = celerity_generate_unique_node_id();
Javelin::initBehavior('time-typeahead', array(
'startTimeID' => $time_id,
'endTimeID' => $this->endDateID,
'timeValues' => $values,
'format' => $this->getTimeFormat(),
));
$time_sel = javelin_tag(
'input',
array(
'autocomplete' => 'off',
'name' => $this->getTimeInputName(),
'sigil' => 'time-input',
'value' => $this->getTimeInputValue(),
'type' => 'text',
'class' => 'aphront-form-time-input',
),
'');
$time_div = javelin_tag(
'div',
array(
'id' => $time_id,
'class' => 'aphront-form-time-input-container',
),
$time_sel);
$preferences = $this->user->loadPreferences();
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
$week_start = $preferences->getPreference($pref_week_start, 0);
Javelin::initBehavior('fancy-datepicker', array(
'format' => $this->getDateFormat(),
'weekStart' => $week_start,
));
$classes = array();
$classes[] = 'aphront-form-date-container';
if ($disabled) {
$classes[] = 'datepicker-disabled';
}
if ($this->isTimeDisabled) {
$classes[] = 'no-time';
}
return javelin_tag(
'div',
array(
'class' => implode(' ', $classes),
'sigil' => 'phabricator-date-control',
'meta' => array(
'disabled' => (bool)$disabled,
),
'id' => $this->getID(),
),
array(
$checkbox,
$date_div,
$cal_icon,
$time_div,
));
}
private function getTimezone() {
if ($this->zone) {
return $this->zone;
}
$user = $this->getUser();
if (!$this->getUser()) {
throw new PhutilInvalidStateException('setUser');
}
$user_zone = $user->getTimezoneIdentifier();
$this->zone = new DateTimeZone($user_zone);
return $this->zone;
}
private function getInitialValue() {
$zone = $this->getTimezone();
// TODO: We could eventually allow these to be customized per install or
// per user or both, but let's wait and see.
switch ($this->initialTime) {
case self::TIME_START_OF_DAY:
default:
$time = '12:00 AM';
break;
case self::TIME_START_OF_BUSINESS:
$time = '9:00 AM';
break;
case self::TIME_END_OF_BUSINESS:
$time = '5:00 PM';
break;
case self::TIME_END_OF_DAY:
$time = '11:59 PM';
break;
}
$today = $this->formatTime(time(), 'Y-m-d');
try {
$date = new DateTime("{$today} {$time}", $zone);
$value = $date->format('U');
} catch (Exception $ex) {
$value = null;
}
return $value;
}
private function getTimeTypeaheadValues() {
$time_format = $this->getTimeFormat();
$times = array();
if ($time_format == 'g:i A') {
$am_pm_list = array('AM', 'PM');
foreach ($am_pm_list as $am_pm) {
for ($hour = 0; $hour < 12; $hour++) {
$actual_hour = ($hour == 0) ? 12 : $hour;
$times[] = $actual_hour.':00 '.$am_pm;
$times[] = $actual_hour.':30 '.$am_pm;
}
}
} else if ($time_format == 'H:i') {
for ($hour = 0; $hour < 24; $hour++) {
$written_hour = ($hour > 9) ? $hour : '0'.$hour;
$times[] = $written_hour.':00';
$times[] = $written_hour.':30';
}
}
foreach ($times as $key => $time) {
$times[$key] = array($key, $time);
}
return $times;
}
}
diff --git a/src/view/form/control/AphrontFormPolicyControl.php b/src/view/form/control/AphrontFormPolicyControl.php
index 348dc8171f..71087bfe07 100644
--- a/src/view/form/control/AphrontFormPolicyControl.php
+++ b/src/view/form/control/AphrontFormPolicyControl.php
@@ -1,362 +1,362 @@
<?php
final class AphrontFormPolicyControl extends AphrontFormControl {
private $object;
private $capability;
private $policies;
private $spacePHID;
private $templatePHIDType;
private $templateObject;
public function setPolicyObject(PhabricatorPolicyInterface $object) {
$this->object = $object;
return $this;
}
public function setPolicies(array $policies) {
assert_instances_of($policies, 'PhabricatorPolicy');
$this->policies = $policies;
return $this;
}
public function setSpacePHID($space_phid) {
$this->spacePHID = $space_phid;
return $this;
}
public function getSpacePHID() {
return $this->spacePHID;
}
public function setTemplatePHIDType($type) {
$this->templatePHIDType = $type;
return $this;
}
public function setTemplateObject($object) {
$this->templateObject = $object;
return $this;
}
public function getSerializedValue() {
return json_encode(array(
$this->getValue(),
$this->getSpacePHID(),
));
}
public function readSerializedValue($value) {
$decoded = phutil_json_decode($value);
$policy_value = $decoded[0];
$space_phid = $decoded[1];
$this->setValue($policy_value);
$this->setSpacePHID($space_phid);
return $this;
}
public function readValueFromDictionary(array $dictionary) {
// TODO: This is a little hacky but will only get us into trouble if we
// have multiple view policy controls in multiple paged form views on the
// same page, which seems unlikely.
$this->setSpacePHID(idx($dictionary, 'spacePHID'));
return parent::readValueFromDictionary($dictionary);
}
public function readValueFromRequest(AphrontRequest $request) {
// See note in readValueFromDictionary().
$this->setSpacePHID($request->getStr('spacePHID'));
return parent::readValueFromRequest($request);
}
public function setCapability($capability) {
$this->capability = $capability;
$labels = array(
PhabricatorPolicyCapability::CAN_VIEW => pht('Visible To'),
PhabricatorPolicyCapability::CAN_EDIT => pht('Editable By'),
PhabricatorPolicyCapability::CAN_JOIN => pht('Joinable By'),
);
if (isset($labels[$capability])) {
$label = $labels[$capability];
} else {
$capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
if ($capobj) {
$label = $capobj->getCapabilityName();
} else {
$label = pht('Capability "%s"', $capability);
}
}
$this->setLabel($label);
return $this;
}
protected function getCustomControlClass() {
return 'aphront-form-control-policy';
}
protected function getOptions() {
$capability = $this->capability;
$policies = $this->policies;
// Exclude object policies which don't make sense here. This primarily
// filters object policies associated from template capabilities (like
// "Default Task View Policy" being set to "Task Author") so they aren't
// made available on non-template capabilities (like "Can Bulk Edit").
foreach ($policies as $key => $policy) {
if ($policy->getType() != PhabricatorPolicyType::TYPE_OBJECT) {
continue;
}
$rule = PhabricatorPolicyQuery::getObjectPolicyRule($policy->getPHID());
if (!$rule) {
continue;
}
$target = nonempty($this->templateObject, $this->object);
if (!$rule->canApplyToObject($target)) {
unset($policies[$key]);
continue;
}
}
$options = array();
foreach ($policies as $policy) {
if ($policy->getPHID() == PhabricatorPolicies::POLICY_PUBLIC) {
// Never expose "Public" for capabilities which don't support it.
$capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
if (!$capobj || !$capobj->shouldAllowPublicPolicySetting()) {
continue;
}
}
$policy_short_name = id(new PhutilUTF8StringTruncator())
->setMaximumGlyphs(28)
->truncateString($policy->getName());
$options[$policy->getType()][$policy->getPHID()] = array(
'name' => $policy_short_name,
'full' => $policy->getName(),
'icon' => $policy->getIcon(),
);
}
// If we were passed several custom policy options, throw away the ones
// which aren't the value for this capability. For example, an object might
// have a custom view pollicy and a custom edit policy. When we render
// the selector for "Can View", we don't want to show the "Can Edit"
// custom policy -- if we did, the menu would look like this:
//
// Custom
// Custom Policy
// Custom Policy
//
// ...where one is the "view" custom policy, and one is the "edit" custom
// policy.
$type_custom = PhabricatorPolicyType::TYPE_CUSTOM;
if (!empty($options[$type_custom])) {
$options[$type_custom] = array_select_keys(
$options[$type_custom],
array($this->getValue()));
}
// If there aren't any custom policies, add a placeholder policy so we
// render a menu item. This allows the user to switch to a custom policy.
if (empty($options[$type_custom])) {
$placeholder = new PhabricatorPolicy();
$placeholder->setName(pht('Custom Policy...'));
$options[$type_custom][$this->getCustomPolicyPlaceholder()] = array(
'name' => $placeholder->getName(),
'full' => $placeholder->getName(),
'icon' => $placeholder->getIcon(),
);
}
$options = array_select_keys(
$options,
array(
PhabricatorPolicyType::TYPE_GLOBAL,
PhabricatorPolicyType::TYPE_OBJECT,
PhabricatorPolicyType::TYPE_USER,
PhabricatorPolicyType::TYPE_CUSTOM,
PhabricatorPolicyType::TYPE_PROJECT,
));
return $options;
}
protected function renderInput() {
if (!$this->object) {
throw new PhutilInvalidStateException('setPolicyObject');
}
if (!$this->capability) {
throw new PhutilInvalidStateException('setCapability');
}
$policy = $this->object->getPolicy($this->capability);
if (!$policy) {
// TODO: Make this configurable.
$policy = PhabricatorPolicies::POLICY_USER;
}
if (!$this->getValue()) {
$this->setValue($policy);
}
$control_id = celerity_generate_unique_node_id();
$input_id = celerity_generate_unique_node_id();
$caret = phutil_tag(
'span',
array(
'class' => 'caret',
));
$input = phutil_tag(
'input',
array(
'type' => 'hidden',
'id' => $input_id,
'name' => $this->getName(),
'value' => $this->getValue(),
));
$options = $this->getOptions();
$order = array();
$labels = array();
foreach ($options as $key => $values) {
$order[$key] = array_keys($values);
$labels[$key] = PhabricatorPolicyType::getPolicyTypeName($key);
}
$flat_options = array_mergev($options);
$icons = array();
foreach (igroup($flat_options, 'icon') as $icon => $ignored) {
$icons[$icon] = id(new PHUIIconView())
- ->setIconFont($icon);
+ ->setIcon($icon);
}
if ($this->templatePHIDType) {
$context_path = 'template/'.$this->templatePHIDType.'/';
} else {
$object_phid = $this->object->getPHID();
if ($object_phid) {
$context_path = 'object/'.$object_phid.'/';
} else {
$object_type = phid_get_type($this->object->generatePHID());
$context_path = 'type/'.$object_type.'/';
}
}
Javelin::initBehavior(
'policy-control',
array(
'controlID' => $control_id,
'inputID' => $input_id,
'options' => $flat_options,
'groups' => array_keys($options),
'order' => $order,
'icons' => $icons,
'labels' => $labels,
'value' => $this->getValue(),
'capability' => $this->capability,
'editURI' => '/policy/edit/'.$context_path,
'customPlaceholder' => $this->getCustomPolicyPlaceholder(),
'disabled' => $this->getDisabled(),
));
$selected = idx($flat_options, $this->getValue(), array());
$selected_icon = idx($selected, 'icon');
$selected_name = idx($selected, 'name');
$spaces_control = $this->buildSpacesControl();
return phutil_tag(
'div',
array(
),
array(
$spaces_control,
javelin_tag(
'a',
array(
'class' => 'grey button dropdown has-icon policy-control',
'href' => '#',
'mustcapture' => true,
'sigil' => 'policy-control',
'id' => $control_id,
),
array(
$caret,
javelin_tag(
'span',
array(
'sigil' => 'policy-label',
'class' => 'phui-button-text',
),
array(
idx($icons, $selected_icon),
$selected_name,
)),
)),
$input,
));
return AphrontFormSelectControl::renderSelectTag(
$this->getValue(),
$this->getOptions(),
array(
'name' => $this->getName(),
'disabled' => $this->getDisabled() ? 'disabled' : null,
'id' => $this->getID(),
));
}
private function getCustomPolicyPlaceholder() {
return 'custom:placeholder';
}
private function buildSpacesControl() {
if ($this->capability != PhabricatorPolicyCapability::CAN_VIEW) {
return null;
}
if (!($this->object instanceof PhabricatorSpacesInterface)) {
return null;
}
$viewer = $this->getUser();
if (!PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($viewer)) {
return null;
}
$space_phid = $this->getSpacePHID();
if ($space_phid === null) {
$space_phid = $viewer->getDefaultSpacePHID();
}
$select = AphrontFormSelectControl::renderSelectTag(
$space_phid,
PhabricatorSpacesNamespaceQuery::getSpaceOptionsForViewer(
$viewer,
$space_phid),
array(
'disabled' => ($this->getDisabled() ? 'disabled' : null),
'name' => 'spacePHID',
'class' => 'aphront-space-select-control-knob',
));
return $select;
}
}
diff --git a/src/view/layout/PhabricatorActionView.php b/src/view/layout/PhabricatorActionView.php
index 15ff0a0023..b89c00daf5 100644
--- a/src/view/layout/PhabricatorActionView.php
+++ b/src/view/layout/PhabricatorActionView.php
@@ -1,201 +1,201 @@
<?php
final class PhabricatorActionView extends AphrontView {
private $name;
private $icon;
private $href;
private $disabled;
private $label;
private $workflow;
private $renderAsForm;
private $download;
private $sigils = array();
private $metadata;
private $selected;
private $openInNewWindow;
public function setSelected($selected) {
$this->selected = $selected;
return $this;
}
public function getSelected() {
return $this->selected;
}
public function setMetadata($metadata) {
$this->metadata = $metadata;
return $this;
}
public function getMetadata() {
return $this->metadata;
}
public function setDownload($download) {
$this->download = $download;
return $this;
}
public function getDownload() {
return $this->download;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function addSigil($sigil) {
$this->sigils[] = $sigil;
return $this;
}
public function getHref() {
return $this->href;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function setLabel($label) {
$this->label = $label;
return $this;
}
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function setRenderAsForm($form) {
$this->renderAsForm = $form;
return $this;
}
public function setOpenInNewWindow($open_in_new_window) {
$this->openInNewWindow = $open_in_new_window;
return $this;
}
public function getOpenInNewWindow() {
return $this->openInNewWindow;
}
public function render() {
$icon = null;
if ($this->icon) {
$color = '';
if ($this->disabled) {
$color = ' grey';
}
$icon = id(new PHUIIconView())
->addClass('phabricator-action-view-icon')
- ->setIconFont($this->icon.$color);
+ ->setIcon($this->icon.$color);
}
if ($this->href) {
$sigils = array();
if ($this->workflow) {
$sigils[] = 'workflow';
}
if ($this->download) {
$sigils[] = 'download';
}
if ($this->sigils) {
$sigils = array_merge($sigils, $this->sigils);
}
$sigils = $sigils ? implode(' ', $sigils) : null;
if ($this->renderAsForm) {
if (!$this->user) {
throw new Exception(
pht(
'Call %s when rendering an action as a form.',
'setUser()'));
}
$item = javelin_tag(
'button',
array(
'class' => 'phabricator-action-view-item',
),
array($icon, $this->name));
$item = phabricator_form(
$this->user,
array(
'action' => $this->getHref(),
'method' => 'POST',
'sigil' => $sigils,
'meta' => $this->metadata,
),
$item);
} else {
if ($this->getOpenInNewWindow()) {
$target = '_blank';
} else {
$target = null;
}
$item = javelin_tag(
'a',
array(
'href' => $this->getHref(),
'class' => 'phabricator-action-view-item',
'target' => $target,
'sigil' => $sigils,
'meta' => $this->metadata,
),
array($icon, $this->name));
}
} else {
$item = phutil_tag(
'span',
array(
'class' => 'phabricator-action-view-item',
),
array($icon, $this->name));
}
$classes = array();
$classes[] = 'phabricator-action-view';
if ($this->disabled) {
$classes[] = 'phabricator-action-view-disabled';
}
if ($this->label) {
$classes[] = 'phabricator-action-view-label';
}
if ($this->selected) {
$classes[] = 'phabricator-action-view-selected';
}
return phutil_tag(
'li',
array(
'class' => implode(' ', $classes),
),
$item);
}
}
diff --git a/src/view/page/menu/PhabricatorMainMenuSearchView.php b/src/view/page/menu/PhabricatorMainMenuSearchView.php
index 76e03b4072..1af42511a8 100644
--- a/src/view/page/menu/PhabricatorMainMenuSearchView.php
+++ b/src/view/page/menu/PhabricatorMainMenuSearchView.php
@@ -1,231 +1,231 @@
<?php
final class PhabricatorMainMenuSearchView extends AphrontView {
const DEFAULT_APPLICATION_ICON = 'fa-dot-circle-o';
private $id;
private $application;
public function setApplication(PhabricatorApplication $application) {
$this->application = $application;
return $this;
}
public function getApplication() {
return $this->application;
}
public function getID() {
if (!$this->id) {
$this->id = celerity_generate_unique_node_id();
}
return $this->id;
}
public function render() {
$user = $this->user;
$target_id = celerity_generate_unique_node_id();
$search_id = $this->getID();
$button_id = celerity_generate_unique_node_id();
$selector_id = celerity_generate_unique_node_id();
$application_id = celerity_generate_unique_node_id();
$input = phutil_tag(
'input',
array(
'type' => 'text',
'name' => 'query',
'id' => $search_id,
'autocomplete' => 'off',
));
$target = javelin_tag(
'div',
array(
'id' => $target_id,
'class' => 'phabricator-main-menu-search-target',
),
'');
$search_datasource = new PhabricatorSearchDatasource();
$scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE;
Javelin::initBehavior(
'phabricator-search-typeahead',
array(
'id' => $target_id,
'input' => $search_id,
'button' => $button_id,
'selectorID' => $selector_id,
'applicationID' => $application_id,
'defaultApplicationIcon' => self::DEFAULT_APPLICATION_ICON,
'appScope' => PhabricatorSearchController::SCOPE_CURRENT_APPLICATION,
'src' => $search_datasource->getDatasourceURI(),
'limit' => 10,
'placeholder' => pht('Search'),
'scopeUpdateURI' => '/settings/adjust/?key='.$scope_key,
));
$primary_input = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'search:primary',
'value' => 'true',
));
$search_text = javelin_tag(
'span',
array(
'aural' => true,
),
pht('Search'));
$selector = $this->buildModeSelector($selector_id, $application_id);
$form = phabricator_form(
$user,
array(
'action' => '/search/',
'method' => 'POST',
),
phutil_tag_div('phabricator-main-menu-search-container', array(
$input,
phutil_tag(
'button',
array(
'id' => $button_id,
'class' => 'phui-icon-view phui-font-fa fa-search',
),
$search_text),
$selector,
$primary_input,
$target,
)));
return $form;
}
private function buildModeSelector($selector_id, $application_id) {
$viewer = $this->getUser();
$items = array();
$items[] = array(
'name' => pht('Search'),
);
$items[] = array(
'icon' => 'fa-globe',
'name' => pht('Search All Documents'),
'value' => 'all',
);
$application_value = null;
$application_icon = self::DEFAULT_APPLICATION_ICON;
$application = $this->getApplication();
if ($application) {
$application_value = get_class($application);
if ($application->getApplicationSearchDocumentTypes()) {
$application_icon = $application->getFontIcon();
}
}
$items[] = array(
'icon' => $application_icon,
'name' => pht('Search Current Application'),
'value' => PhabricatorSearchController::SCOPE_CURRENT_APPLICATION,
);
$items[] = array(
'name' => pht('Saved Queries'),
);
$engine = id(new PhabricatorSearchApplicationSearchEngine())
->setViewer($viewer);
$engine_queries = $engine->loadEnabledNamedQueries();
$query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey');
foreach ($query_map as $query_key => $query_name) {
if ($query_key == 'all') {
// Skip the builtin "All" query since it's redundant with the default
// setting.
continue;
}
$items[] = array(
'icon' => 'fa-certificate',
'name' => $query_name,
'value' => $query_key,
);
}
$items[] = array(
'name' => pht('More Options'),
);
$items[] = array(
'icon' => 'fa-search-plus',
'name' => pht('Advanced Search'),
'href' => '/search/query/advanced/',
);
$items[] = array(
'icon' => 'fa-book',
'name' => pht('User Guide: Search'),
'href' => PhabricatorEnv::getDoclink('Search User Guide'),
);
$scope_key = PhabricatorUserPreferences::PREFERENCE_SEARCH_SCOPE;
$current_value = $viewer->loadPreferences()->getPreference(
$scope_key,
'all');
$current_icon = 'fa-globe';
foreach ($items as $item) {
if (idx($item, 'value') == $current_value) {
$current_icon = $item['icon'];
break;
}
}
$selector = id(new PHUIButtonView())
->setID($selector_id)
->addClass('phabricator-main-menu-search-dropdown')
->addSigil('global-search-dropdown')
->setMetadata(
array(
'items' => $items,
'icon' => $current_icon,
'value' => $current_value,
))
->setIcon(
id(new PHUIIconView())
->addSigil('global-search-dropdown-icon')
- ->setIconFont($current_icon))
+ ->setIcon($current_icon))
->setDropdown(true);
$input = javelin_tag(
'input',
array(
'type' => 'hidden',
'sigil' => 'global-search-dropdown-input',
'name' => 'search:scope',
'value' => $current_value,
));
$application_input = javelin_tag(
'input',
array(
'type' => 'hidden',
'id' => $application_id,
'sigil' => 'global-search-dropdown-app',
'name' => 'search:application',
'value' => $application_value,
));
return array($selector, $input, $application_input);
}
}
diff --git a/src/view/phui/PHUIActionPanelView.php b/src/view/phui/PHUIActionPanelView.php
index bfe44ba13e..a81b2e5dcf 100644
--- a/src/view/phui/PHUIActionPanelView.php
+++ b/src/view/phui/PHUIActionPanelView.php
@@ -1,139 +1,139 @@
<?php
final class PHUIActionPanelView extends AphrontTagView {
private $href;
private $fontIcon;
private $header;
private $subHeader;
private $bigText;
private $state;
private $status;
const COLOR_RED = 'phui-action-panel-red';
const COLOR_ORANGE = 'phui-action-panel-orange';
const COLOR_YELLOW = 'phui-action-panel-yellow';
const COLOR_GREEN = 'phui-action-panel-green';
const COLOR_BLUE = 'phui-action-panel-blue';
const COLOR_INDIGO = 'phui-action-panel-indigo';
const COLOR_VIOLET = 'phui-action-panel-violet';
const COLOR_PINK = 'phui-action-panel-pink';
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setFontIcon($image) {
$this->fontIcon = $image;
return $this;
}
public function setBigText($text) {
$this->bigText = $text;
return $this;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setSubHeader($sub) {
$this->subHeader = $sub;
return $this;
}
public function setState($state) {
$this->state = $state;
return $this;
}
public function setStatus($text) {
$this->status = $text;
return $this;
}
protected function getTagName() {
return 'div';
}
protected function getTagAttributes() {
require_celerity_resource('phui-action-panel-css');
$classes = array();
$classes[] = 'phui-action-panel';
if ($this->state) {
$classes[] = $this->state;
}
if ($this->bigText) {
$classes[] = 'phui-action-panel-bigtext';
}
return array(
'class' => implode(' ', $classes),
);
}
protected function getTagContent() {
$icon = null;
if ($this->fontIcon) {
$fonticon = id(new PHUIIconView())
- ->setIconFont($this->fontIcon);
+ ->setIcon($this->fontIcon);
$icon = phutil_tag(
'span',
array(
'class' => 'phui-action-panel-icon',
),
$fonticon);
}
$header = null;
if ($this->header) {
$header = phutil_tag(
'span',
array(
'class' => 'phui-action-panel-header',
),
$this->header);
}
$subheader = null;
if ($this->subHeader) {
$subheader = phutil_tag(
'span',
array(
'class' => 'phui-action-panel-subheader',
),
$this->subHeader);
}
$row = phutil_tag(
'span',
array(
'class' => 'phui-action-panel-row',
),
array(
$icon,
$subheader,
));
$table = phutil_tag(
'span',
array(
'class' => 'phui-action-panel-table',
),
$row);
return phutil_tag(
'a',
array(
'href' => $this->href,
'class' => 'phui-action-panel-hitarea',
),
array($header, $table));
}
}
diff --git a/src/view/phui/PHUIBadgeMiniView.php b/src/view/phui/PHUIBadgeMiniView.php
index 92d6fd8b8b..21f455b4d6 100644
--- a/src/view/phui/PHUIBadgeMiniView.php
+++ b/src/view/phui/PHUIBadgeMiniView.php
@@ -1,71 +1,71 @@
<?php
final class PHUIBadgeMiniView extends AphrontTagView {
private $href;
private $icon;
private $quality;
private $header;
private $tipDirection;
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setQuality($quality) {
$this->quality = $quality;
return $this;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setTipDirection($direction) {
$this->tipDirection = $direction;
return $this;
}
protected function getTagName() {
if ($this->href) {
return 'a';
} else {
return 'span';
}
}
protected function getTagAttributes() {
require_celerity_resource('phui-badge-view-css');
Javelin::initBehavior('phabricator-tooltips');
$classes = array();
$classes[] = 'phui-badge-mini';
if ($this->quality) {
$classes[] = 'phui-badge-mini-'.$this->quality;
}
return array(
'class' => implode(' ', $classes),
'sigil' => 'has-tooltip',
'href' => $this->href,
'meta' => array(
'tip' => $this->header,
'align' => $this->tipDirection,
'size' => 300,
),
);
}
protected function getTagContent() {
return id(new PHUIIconView())
- ->setIconFont($this->icon);
+ ->setIcon($this->icon);
}
}
diff --git a/src/view/phui/PHUIBadgeView.php b/src/view/phui/PHUIBadgeView.php
index fb50ff80ec..7e9f310843 100644
--- a/src/view/phui/PHUIBadgeView.php
+++ b/src/view/phui/PHUIBadgeView.php
@@ -1,215 +1,215 @@
<?php
final class PHUIBadgeView extends AphrontTagView {
private $href;
private $icon;
private $quality;
private $source;
private $header;
private $subhead;
private $bylines = array();
// Yes, World of Warcraft Item Quality
const POOR = 'grey';
const COMMON = 'white';
const UNCOMMON = 'green';
const RARE = 'blue';
const EPIC = 'indigo';
const LEGENDARY = 'orange';
const HEIRLOOM = 'yellow';
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setQuality($quality) {
$this->quality = $quality;
return $this;
}
public function setSource($source) {
$this->source = $source;
return $this;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setSubhead($subhead) {
$this->subhead = $subhead;
return $this;
}
public function addByline($byline) {
$this->bylines[] = $byline;
return $this;
}
private function getQualityTitle() {
switch ($this->quality) {
case self::POOR:
return pht('Poor');
case self::COMMON:
return pht('Common');
case self::UNCOMMON:
return pht('Uncommon');
case self::RARE:
return pht('Rare');
case self::EPIC:
return pht('Epic');
case self::LEGENDARY:
return pht('Legendary');
case self::HEIRLOOM:
return pht('Heirloom');
}
}
protected function getTagName() {
return 'span';
}
protected function getTagAttributes() {
require_celerity_resource('phui-badge-view-css');
$id = celerity_generate_unique_node_id();
$classes = array();
$classes[] = 'phui-badge-view';
if ($this->quality) {
$classes[] = 'phui-badge-view-'.$this->quality;
}
return array(
'class' => implode(' ', $classes),
'sigil' => 'jx-toggle-class',
'id' => $id,
'meta' => array(
'map' => array(
$id => 'card-flipped',
),
),
);
}
protected function getTagContent() {
$icon = id(new PHUIIconView())
- ->setIconFont($this->icon);
+ ->setIcon($this->icon);
$illustration = phutil_tag_div('phui-badge-illustration', $icon);
$header = null;
if ($this->header) {
$header = phutil_tag(
($this->href) ? 'a' : 'span',
array(
'class' => 'phui-badge-view-header',
'href' => $this->href,
),
$this->header);
}
$subhead = null;
if ($this->subhead) {
$subhead = phutil_tag_div('phui-badge-view-subhead', $this->subhead);
}
$information = phutil_tag(
'div',
array(
'class' => 'phui-badge-view-information',
),
array($header, $subhead));
$quality = phutil_tag_div('phui-badge-quality', $this->getQualityTitle());
$source = phutil_tag_div('phui-badge-source', $this->source);
$bylines = array();
if ($this->bylines) {
foreach ($this->bylines as $byline) {
$bylines[] = phutil_tag_div('phui-badge-byline', $byline);
}
}
$card_front_1 = phutil_tag(
'div',
array(
'class' => 'phui-badge-inner-front',
),
array(
$illustration,
));
$card_front_2 = phutil_tag(
'div',
array(
'class' => 'phui-badge-inner-front',
),
array(
$information,
));
$back_info = phutil_tag(
'div',
array(
'class' => 'phui-badge-view-information',
),
array(
$quality,
$source,
$bylines,
));
$card_back = phutil_tag(
'div',
array(
'class' => 'phui-badge-inner-back',
),
array(
$back_info,
));
$inner_front = phutil_tag(
'div',
array(
'class' => 'phui-badge-front-view',
),
array(
$card_front_1,
$card_front_2,
));
$inner_back = phutil_tag_div('phui-badge-back-view', $card_back);
$front = phutil_tag_div('phui-badge-card-front', $inner_front);
$back = phutil_tag_div('phui-badge-card-back', $inner_back);
$card = phutil_tag(
'div',
array(
'class' => 'phui-badge-card',
),
array(
$front,
$back,
));
return phutil_tag(
'div',
array(
'class' => 'phui-badge-card-container',
),
$card);
}
}
diff --git a/src/view/phui/PHUIBigInfoView.php b/src/view/phui/PHUIBigInfoView.php
index 03e1aea196..0f5bcecfbd 100644
--- a/src/view/phui/PHUIBigInfoView.php
+++ b/src/view/phui/PHUIBigInfoView.php
@@ -1,95 +1,95 @@
<?php
final class PHUIBigInfoView extends AphrontTagView {
private $icon;
private $title;
private $description;
private $actions = array();
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setDescription($description) {
$this->description = $description;
return $this;
}
public function addAction(PHUIButtonView $button) {
$this->actions[] = $button;
return $this;
}
protected function getTagName() {
return 'div';
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phui-big-info-view';
return array(
'class' => implode(' ', $classes),
);
}
protected function getTagContent() {
require_celerity_resource('phui-big-info-view-css');
$icon = id(new PHUIIconView())
- ->setIconFont($this->icon)
+ ->setIcon($this->icon)
->addClass('phui-big-info-icon');
$icon = phutil_tag(
'div',
array(
'class' => 'phui-big-info-icon-container',
),
$icon);
$title = phutil_tag(
'div',
array(
'class' => 'phui-big-info-title',
),
$this->title);
$description = phutil_tag(
'div',
array(
'class' => 'phui-big-info-description',
),
$this->description);
$buttons = array();
foreach ($this->actions as $button) {
$buttons[] = phutil_tag(
'div',
array(
'class' => 'phui-big-info-button',
),
$button);
}
$actions = null;
if ($buttons) {
$actions = phutil_tag(
'div',
array(
'class' => 'phui-big-info-actions',
),
$buttons);
}
return array($icon, $title, $description, $actions);
}
}
diff --git a/src/view/phui/PHUIButtonView.php b/src/view/phui/PHUIButtonView.php
index 26a26a5ac4..9b9d4f0293 100644
--- a/src/view/phui/PHUIButtonView.php
+++ b/src/view/phui/PHUIButtonView.php
@@ -1,199 +1,195 @@
<?php
final class PHUIButtonView extends AphrontTagView {
const GREEN = 'green';
const GREY = 'grey';
const DISABLED = 'disabled';
const SIMPLE = 'simple';
const SIMPLE_YELLOW = 'simple simple-yellow';
const SIMPLE_GREY = 'simple simple-grey';
const SIMPLE_BLUE = 'simple simple-blue';
const SMALL = 'small';
const BIG = 'big';
private $size;
private $text;
private $subtext;
private $color;
private $tag = 'button';
private $dropdown;
private $icon;
- private $iconFont;
private $iconFirst;
private $href = null;
private $title = null;
private $disabled;
private $name;
private $tooltip;
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setText($text) {
$this->text = $text;
return $this;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setSubtext($subtext) {
$this->subtext = $subtext;
return $this;
}
public function setColor($color) {
$this->color = $color;
return $this;
}
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
}
public function setTag($tag) {
$this->tag = $tag;
return $this;
}
public function setSize($size) {
$this->size = $size;
return $this;
}
public function setDropdown($dd) {
$this->dropdown = $dd;
return $this;
}
public function setTooltip($text) {
$this->tooltip = $text;
return $this;
}
- public function setIcon(PHUIIconView $icon, $first = true) {
+ public function setIcon($icon, $first = true) {
+ if (!($icon instanceof PHUIIconView)) {
+ $icon = id(new PHUIIconView())
+ ->setIcon($icon);
+ }
$this->icon = $icon;
$this->iconFirst = $first;
return $this;
}
- public function setIconFont($icon) {
- $icon = id(new PHUIIconView())
- ->setIconFont($icon);
- $this->setIcon($icon);
- return $this;
- }
-
protected function getTagName() {
return $this->tag;
}
public function setDropdownMenu(PhabricatorActionListView $actions) {
Javelin::initBehavior('phui-dropdown-menu');
$this->addSigil('phui-dropdown-menu');
$this->setMetadata(
array(
'items' => $actions,
));
return $this;
}
protected function getTagAttributes() {
require_celerity_resource('phui-button-css');
$classes = array();
$classes[] = 'button';
if ($this->color) {
$classes[] = $this->color;
}
if ($this->size) {
$classes[] = $this->size;
}
if ($this->dropdown) {
$classes[] = 'dropdown';
}
if ($this->icon) {
$classes[] = 'has-icon';
}
if ($this->iconFirst == false) {
$classes[] = 'icon-last';
}
if ($this->disabled) {
$classes[] = 'disabled';
}
$sigil = null;
$meta = null;
if ($this->tooltip) {
Javelin::initBehavior('phabricator-tooltips');
require_celerity_resource('aphront-tooltip-css');
$sigil = 'has-tooltip';
$meta = array(
'tip' => $this->tooltip,
);
}
return array(
'class' => $classes,
'href' => $this->href,
'name' => $this->name,
'title' => $this->title,
'sigil' => $sigil,
'meta' => $meta,
);
}
protected function getTagContent() {
$icon = null;
$text = $this->text;
if ($this->icon) {
$icon = $this->icon;
$subtext = null;
if ($this->subtext) {
$subtext = phutil_tag(
'div', array('class' => 'phui-button-subtext'), $this->subtext);
}
$text = phutil_tag(
'div', array('class' => 'phui-button-text'), array($text, $subtext));
}
$caret = null;
if ($this->dropdown) {
$caret = phutil_tag('span', array('class' => 'caret'), '');
}
if ($this->iconFirst == true) {
return array($icon, $text, $caret);
} else {
return array($text, $icon);
}
}
}
diff --git a/src/view/phui/PHUICrumbView.php b/src/view/phui/PHUICrumbView.php
index 915dfbf41f..5039e17606 100644
--- a/src/view/phui/PHUICrumbView.php
+++ b/src/view/phui/PHUICrumbView.php
@@ -1,104 +1,104 @@
<?php
final class PHUICrumbView extends AphrontView {
private $name;
private $href;
private $icon;
private $isLastCrumb;
private $workflow;
private $aural;
public function setAural($aural) {
$this->aural = $aural;
return $this;
}
public function getAural() {
return $this->aural;
}
public function setWorkflow($workflow) {
$this->workflow = $workflow;
return $this;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
protected function canAppendChild() {
return false;
}
public function setIsLastCrumb($is_last_crumb) {
$this->isLastCrumb = $is_last_crumb;
return $this;
}
public function render() {
$classes = array(
'phui-crumb-view',
);
$aural = null;
if ($this->aural !== null) {
$aural = javelin_tag(
'span',
array(
'aural' => true,
),
$this->aural);
}
$icon = null;
if ($this->icon) {
$classes[] = 'phui-crumb-has-icon';
$icon = id(new PHUIIconView())
- ->setIconFont($this->icon);
+ ->setIcon($this->icon);
}
$name = phutil_tag(
'span',
array(
'class' => 'phui-crumb-name',
),
$this->name);
$divider = null;
if (!$this->isLastCrumb) {
$divider = id(new PHUIIconView())
- ->setIconFont('fa-angle-right')
+ ->setIcon('fa-angle-right')
->addClass('phui-crumb-divider')
->addClass('phui-crumb-view');
} else {
$classes[] = 'phabricator-last-crumb';
}
$tag = javelin_tag(
$this->href ? 'a' : 'span',
array(
'sigil' => $this->workflow ? 'workflow' : null,
'href' => $this->href,
'class' => implode(' ', $classes),
),
array($aural, $icon, $name));
return array($tag, $divider);
}
}
diff --git a/src/view/phui/PHUICrumbsView.php b/src/view/phui/PHUICrumbsView.php
index f8f25b389c..c85c0055d1 100644
--- a/src/view/phui/PHUICrumbsView.php
+++ b/src/view/phui/PHUICrumbsView.php
@@ -1,128 +1,128 @@
<?php
final class PHUICrumbsView extends AphrontView {
private $crumbs = array();
private $actions = array();
private $border;
protected function canAppendChild() {
return false;
}
/**
* Convenience method for adding a simple crumb with just text, or text and
* a link.
*
* @param string Text of the crumb.
* @param string? Optional href for the crumb.
* @return this
*/
public function addTextCrumb($text, $href = null) {
return $this->addCrumb(
id(new PHUICrumbView())
->setName($text)
->setHref($href));
}
public function addCrumb(PHUICrumbView $crumb) {
$this->crumbs[] = $crumb;
return $this;
}
public function addAction(PHUIListItemView $action) {
$this->actions[] = $action;
return $this;
}
public function setBorder($border) {
$this->border = $border;
return $this;
}
public function getActions() {
return $this->actions;
}
public function render() {
require_celerity_resource('phui-crumbs-view-css');
$action_view = null;
if ($this->actions) {
$actions = array();
foreach ($this->actions as $action) {
$icon = null;
if ($action->getIcon()) {
$icon_name = $action->getIcon();
if ($action->getDisabled()) {
$icon_name .= ' lightgreytext';
}
$icon = id(new PHUIIconView())
- ->setIconFont($icon_name);
+ ->setIcon($icon_name);
}
$name = phutil_tag(
'span',
array(
'class' => 'phui-crumbs-action-name',
),
$action->getName());
$action_sigils = $action->getSigils();
if ($action->getWorkflow()) {
$action_sigils[] = 'workflow';
}
$action_classes = $action->getClasses();
$action_classes[] = 'phui-crumbs-action';
if ($action->getDisabled()) {
$action_classes[] = 'phui-crumbs-action-disabled';
}
$actions[] = javelin_tag(
'a',
array(
'href' => $action->getHref(),
'class' => implode(' ', $action_classes),
'sigil' => implode(' ', $action_sigils),
'style' => $action->getStyle(),
'meta' => $action->getMetadata(),
),
array(
$icon,
$name,
));
}
$action_view = phutil_tag(
'div',
array(
'class' => 'phui-crumbs-actions',
),
$actions);
}
if ($this->crumbs) {
last($this->crumbs)->setIsLastCrumb(true);
}
$classes = array();
$classes[] = 'phui-crumbs-view';
if ($this->border) {
$classes[] = 'phui-crumbs-border';
}
return phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
array(
$action_view,
$this->crumbs,
));
}
}
diff --git a/src/view/phui/PHUIDocumentViewPro.php b/src/view/phui/PHUIDocumentViewPro.php
index dbab3ab54c..d60cd78d44 100644
--- a/src/view/phui/PHUIDocumentViewPro.php
+++ b/src/view/phui/PHUIDocumentViewPro.php
@@ -1,145 +1,145 @@
<?php
final class PHUIDocumentViewPro extends AphrontTagView {
private $header;
private $bookname;
private $bookdescription;
private $fluid;
private $toc;
private $foot;
public function setHeader(PHUIHeaderView $header) {
$header->setTall(true);
$this->header = $header;
return $this;
}
public function setBook($name, $description) {
$this->bookname = $name;
$this->bookdescription = $description;
return $this;
}
public function setFluid($fluid) {
$this->fluid = $fluid;
return $this;
}
public function setToc($toc) {
$this->toc = $toc;
return $this;
}
public function setFoot($foot) {
$this->foot = $foot;
return $this;
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phui-document-container';
if ($this->fluid) {
$classes[] = 'phui-document-fluid';
}
if ($this->foot) {
$classes[] = 'document-has-foot';
}
return array(
'class' => implode(' ', $classes),
);
}
protected function getTagContent() {
require_celerity_resource('phui-document-view-css');
require_celerity_resource('phui-document-view-pro-css');
Javelin::initBehavior('phabricator-reveal-content');
$classes = array();
$classes[] = 'phui-document-view';
$classes[] = 'phui-document-view-pro';
$book = null;
if ($this->bookname) {
$book = pht('%s (%s)', $this->bookname, $this->bookdescription);
}
$main_content = $this->renderChildren();
if ($book) {
$this->header->setSubheader($book);
}
$table_of_contents = null;
if ($this->toc) {
$toc = array();
$toc_id = celerity_generate_unique_node_id();
$toc[] = id(new PHUIButtonView())
->setTag('a')
- ->setIconFont('fa-align-left')
+ ->setIcon('fa-align-left')
->setColor(PHUIButtonView::SIMPLE)
->addClass('phui-document-toc')
->addSigil('jx-toggle-class')
->setMetaData(array(
'map' => array(
$toc_id => 'phui-document-toc-open',
),
));
$toc[] = phutil_tag(
'div',
array(
'class' => 'phui-list-sidenav phui-document-toc-list',
),
$this->toc);
$table_of_contents = phutil_tag(
'div',
array(
'class' => 'phui-document-toc-container',
'id' => $toc_id,
),
$toc);
}
$foot_content = null;
if ($this->foot) {
$foot_content = phutil_tag(
'div',
array(
'class' => 'phui-document-foot-content',
),
$this->foot);
}
$content_inner = phutil_tag(
'div',
array(
'class' => 'phui-document-inner',
),
array(
$table_of_contents,
$this->header,
$main_content,
$foot_content,
));
$content = phutil_tag(
'div',
array(
'class' => 'phui-document-content',
),
$content_inner);
return phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
$content);
}
}
diff --git a/src/view/phui/PHUIFeedStoryView.php b/src/view/phui/PHUIFeedStoryView.php
index 3c6080aa34..40b7c76290 100644
--- a/src/view/phui/PHUIFeedStoryView.php
+++ b/src/view/phui/PHUIFeedStoryView.php
@@ -1,277 +1,277 @@
<?php
final class PHUIFeedStoryView extends AphrontView {
private $title;
private $image;
private $imageHref;
private $appIcon;
private $phid;
private $epoch;
private $viewed;
private $href;
private $pontification = null;
private $tokenBar = array();
private $projects = array();
private $actions = array();
private $chronologicalKey;
private $tags;
public function setTags($tags) {
$this->tags = $tags;
return $this;
}
public function getTags() {
return $this->tags;
}
public function setChronologicalKey($chronological_key) {
$this->chronologicalKey = $chronological_key;
return $this;
}
public function getChronologicalKey() {
return $this->chronologicalKey;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function setEpoch($epoch) {
$this->epoch = $epoch;
return $this;
}
public function setImage($image) {
$this->image = $image;
return $this;
}
public function getImage() {
return $this->image;
}
public function setImageHref($image_href) {
$this->imageHref = $image_href;
return $this;
}
public function setAppIcon($icon) {
$this->appIcon = $icon;
return $this;
}
public function setViewed($viewed) {
$this->viewed = $viewed;
return $this;
}
public function getViewed() {
return $this->viewed;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setTokenBar(array $tokens) {
$this->tokenBar = $tokens;
return $this;
}
public function addProject($project) {
$this->projects[] = $project;
return $this;
}
public function addAction(PHUIIconView $action) {
$this->actions[] = $action;
return $this;
}
public function setPontification($text, $title = null) {
if ($title) {
$title = phutil_tag('h3', array(), $title);
}
$copy = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-bigtext-post',
),
array(
$title,
$text,
));
$this->appendChild($copy);
return $this;
}
public function getHref() {
return $this->href;
}
public function renderNotification($user) {
$classes = array(
'phabricator-notification',
);
if (!$this->viewed) {
$classes[] = 'phabricator-notification-unread';
}
if ($this->epoch) {
if ($user) {
$foot = phabricator_datetime($this->epoch, $user);
$foot = phutil_tag(
'span',
array(
'class' => 'phabricator-notification-date',
),
$foot);
} else {
$foot = null;
}
} else {
$foot = pht('No time specified.');
}
return javelin_tag(
'div',
array(
'class' => implode(' ', $classes),
'sigil' => 'notification',
'meta' => array(
'href' => $this->getHref(),
),
),
array($this->title, $foot));
}
public function render() {
require_celerity_resource('phui-feed-story-css');
Javelin::initBehavior('phabricator-hovercards');
$body = null;
$foot = null;
$actor = new PHUIIconView();
$actor->setImage($this->image);
$actor->addClass('phui-feed-story-actor-image');
if ($this->imageHref) {
$actor->setHref($this->imageHref);
}
if ($this->epoch) {
// TODO: This is really bad; when rendering through Conduit and via
// renderText() we don't have a user.
if ($this->user) {
$foot = phabricator_datetime($this->epoch, $this->user);
} else {
$foot = null;
}
} else {
$foot = pht('No time specified.');
}
if ($this->chronologicalKey) {
$foot = phutil_tag(
'a',
array(
'href' => '/feed/'.$this->chronologicalKey.'/',
),
$foot);
}
$icon = null;
if ($this->appIcon) {
$icon = id(new PHUIIconView())
- ->setIconFont($this->appIcon);
+ ->setIcon($this->appIcon);
}
$action_list = array();
$icons = null;
foreach ($this->actions as $action) {
$action_list[] = phutil_tag(
'li',
array(
'class' => 'phui-feed-story-action-item',
),
$action);
}
if (!empty($action_list)) {
$icons = phutil_tag(
'ul',
array(
'class' => 'phui-feed-story-action-list',
),
$action_list);
}
$head = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-head',
),
array(
$actor,
nonempty($this->title, pht('Untitled Story')),
$icons,
));
if (!empty($this->tokenBar)) {
$tokenview = phutil_tag(
'div',
array(
'class' => 'phui-feed-token-bar',
),
$this->tokenBar);
$this->appendChild($tokenview);
}
$body_content = $this->renderChildren();
if ($body_content) {
$body = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-body phabricator-remarkup',
),
$body_content);
}
$tags = null;
if ($this->tags) {
$tags = array(
" \xC2\xB7 ",
$this->tags,
);
}
$foot = phutil_tag(
'div',
array(
'class' => 'phui-feed-story-foot',
),
array(
$icon,
$foot,
$tags,
));
$classes = array('phui-feed-story');
return id(new PHUIBoxView())
->addClass(implode(' ', $classes))
->setBorder(true)
->addMargin(PHUI::MARGIN_MEDIUM_BOTTOM)
->appendChild(array($head, $body, $foot));
}
}
diff --git a/src/view/phui/PHUIHeaderView.php b/src/view/phui/PHUIHeaderView.php
index f96749bb2b..48fedd11ae 100644
--- a/src/view/phui/PHUIHeaderView.php
+++ b/src/view/phui/PHUIHeaderView.php
@@ -1,483 +1,483 @@
<?php
final class PHUIHeaderView extends AphrontTagView {
const PROPERTY_STATUS = 1;
private $header;
private $tags = array();
private $image;
private $imageURL = null;
private $imageEditURL = null;
private $subheader;
private $headerIcon;
private $noBackground;
private $bleedHeader;
private $profileHeader;
private $tall;
private $properties = array();
private $actionLinks = array();
private $buttonBar = null;
private $policyObject;
private $epoch;
private $actionIcons = array();
private $badges = array();
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setNoBackground($nada) {
$this->noBackground = $nada;
return $this;
}
public function setTall($tall) {
$this->tall = $tall;
return $this;
}
public function addTag(PHUITagView $tag) {
$this->tags[] = $tag;
return $this;
}
public function addBadge(PHUIBadgeMiniView $badge) {
$this->badges[] = $badge;
return $this;
}
public function setImage($uri) {
$this->image = $uri;
return $this;
}
public function setImageURL($url) {
$this->imageURL = $url;
return $this;
}
public function setImageEditURL($url) {
$this->imageEditURL = $url;
return $this;
}
public function setSubheader($subheader) {
$this->subheader = $subheader;
return $this;
}
public function setBleedHeader($bleed) {
$this->bleedHeader = $bleed;
return $this;
}
public function setProfileHeader($bighead) {
$this->profileHeader = $bighead;
return $this;
}
public function setHeaderIcon($icon) {
$this->headerIcon = $icon;
return $this;
}
public function setPolicyObject(PhabricatorPolicyInterface $object) {
$this->policyObject = $object;
return $this;
}
public function addProperty($property, $value) {
$this->properties[$property] = $value;
return $this;
}
public function addActionLink(PHUIButtonView $button) {
$this->actionLinks[] = $button;
return $this;
}
public function addActionIcon(PHUIIconView $action) {
$this->actionIcons[] = $action;
return $this;
}
public function setButtonBar(PHUIButtonBarView $bb) {
$this->buttonBar = $bb;
return $this;
}
public function setStatus($icon, $color, $name) {
$header_class = 'phui-header-status';
if ($color) {
$icon = $icon.' '.$color;
$header_class = $header_class.'-'.$color;
}
$img = id(new PHUIIconView())
- ->setIconFont($icon);
+ ->setIcon($icon);
$tag = phutil_tag(
'span',
array(
'class' => "phui-header-status {$header_class}",
),
array(
$img,
$name,
));
return $this->addProperty(self::PROPERTY_STATUS, $tag);
}
public function setEpoch($epoch) {
$age = time() - $epoch;
$age = floor($age / (60 * 60 * 24));
if ($age < 1) {
$when = pht('Today');
} else if ($age == 1) {
$when = pht('Yesterday');
} else {
$when = pht('%s Day(s) Ago', new PhutilNumber($age));
}
$this->setStatus('fa-clock-o bluegrey', null, pht('Updated %s', $when));
return $this;
}
protected function getTagName() {
return 'div';
}
protected function getTagAttributes() {
require_celerity_resource('phui-header-view-css');
$classes = array();
$classes[] = 'phui-header-shell';
if ($this->noBackground) {
$classes[] = 'phui-header-no-backgound';
}
if ($this->bleedHeader) {
$classes[] = 'phui-bleed-header';
}
if ($this->profileHeader) {
$classes[] = 'phui-profile-header';
}
if ($this->properties || $this->policyObject ||
$this->subheader || $this->tall) {
$classes[] = 'phui-header-tall';
}
return array(
'class' => $classes,
);
}
protected function getTagContent() {
$image = null;
if ($this->image) {
$image_href = null;
if ($this->imageURL) {
$image_href = $this->imageURL;
} else if ($this->imageEditURL) {
$image_href = $this->imageEditURL;
}
$image = phutil_tag(
'span',
array(
'class' => 'phui-header-image',
'style' => 'background-image: url('.$this->image.')',
));
if ($image_href) {
$edit_view = null;
if ($this->imageEditURL) {
$edit_view = phutil_tag(
'span',
array(
'class' => 'phui-header-image-edit',
),
pht('Edit'));
}
$image = phutil_tag(
'a',
array(
'href' => $image_href,
'class' => 'phui-header-image-href',
),
array(
$image,
$edit_view,
));
}
}
$viewer = $this->getUser();
$left = array();
$right = array();
if ($viewer) {
$left[] = id(new PHUISpacesNamespaceContextView())
->setUser($viewer)
->setObject($this->policyObject);
}
if ($this->actionLinks) {
$actions = array();
foreach ($this->actionLinks as $button) {
$button->setColor(PHUIButtonView::GREY);
$button->addClass(PHUI::MARGIN_SMALL_LEFT);
$button->addClass('phui-header-action-link');
$actions[] = $button;
}
$right[] = phutil_tag(
'div',
array(
'class' => 'phui-header-action-links',
),
$actions);
}
if ($this->buttonBar) {
$right[] = phutil_tag(
'div',
array(
'class' => 'phui-header-action-links',
),
$this->buttonBar);
}
if ($this->actionIcons || $this->tags) {
$action_list = array();
if ($this->actionIcons) {
foreach ($this->actionIcons as $icon) {
$action_list[] = phutil_tag(
'li',
array(
'class' => 'phui-header-action-icon',
),
$icon);
}
}
if ($this->tags) {
$action_list[] = phutil_tag(
'li',
array(
'class' => 'phui-header-action-tag',
),
array_interleave(' ', $this->tags));
}
$right[] = phutil_tag(
'ul',
array(
'class' => 'phui-header-action-list',
),
$action_list);
}
if ($this->headerIcon) {
$icon = id(new PHUIIconView())
- ->setIconFont($this->headerIcon);
+ ->setIcon($this->headerIcon);
$left[] = $icon;
}
$left[] = phutil_tag(
'span',
array(
'class' => 'phui-header-header',
),
$this->header);
if ($this->subheader || $this->badges) {
$badges = null;
if ($this->badges) {
$badges = new PHUIBadgeBoxView();
$badges->addItems($this->badges);
$badges->setCollapsed(true);
}
$left[] = phutil_tag(
'div',
array(
'class' => 'phui-header-subheader',
),
array(
$badges,
$this->subheader,
));
}
if ($this->properties || $this->policyObject) {
$property_list = array();
foreach ($this->properties as $type => $property) {
switch ($type) {
case self::PROPERTY_STATUS:
$property_list[] = $property;
break;
default:
throw new Exception(pht('Incorrect Property Passed'));
break;
}
}
if ($this->policyObject) {
$property_list[] = $this->renderPolicyProperty($this->policyObject);
}
$left[] = phutil_tag(
'div',
array(
'class' => 'phui-header-subheader',
),
$property_list);
}
// We here at @phabricator
$header_image = null;
if ($image) {
$header_image = phutil_tag(
'div',
array(
'class' => 'phui-header-col1',
),
$image);
}
// All really love
$header_left = phutil_tag(
'div',
array(
'class' => 'phui-header-col2',
),
$left);
// Tables and Pokemon.
$header_right = phutil_tag(
'div',
array(
'class' => 'phui-header-col3',
),
$right);
$header_row = phutil_tag(
'div',
array(
'class' => 'phui-header-row',
),
array(
$header_image,
$header_left,
$header_right,
));
return phutil_tag(
'h1',
array(
'class' => 'phui-header-view',
),
$header_row);
}
private function renderPolicyProperty(PhabricatorPolicyInterface $object) {
$viewer = $this->getUser();
$policies = PhabricatorPolicyQuery::loadPolicies($viewer, $object);
$view_capability = PhabricatorPolicyCapability::CAN_VIEW;
$policy = idx($policies, $view_capability);
if (!$policy) {
return null;
}
// If an object is in a Space with a strictly stronger (more restrictive)
// policy, we show the more restrictive policy. This better aligns the
// UI hint with the actual behavior.
// NOTE: We'll do this even if the viewer has access to only one space, and
// show them information about the existence of spaces if they click
// through.
$use_space_policy = false;
if ($object instanceof PhabricatorSpacesInterface) {
$space_phid = PhabricatorSpacesNamespaceQuery::getObjectSpacePHID(
$object);
$spaces = PhabricatorSpacesNamespaceQuery::getViewerSpaces($viewer);
$space = idx($spaces, $space_phid);
if ($space) {
$space_policies = PhabricatorPolicyQuery::loadPolicies(
$viewer,
$space);
$space_policy = idx($space_policies, $view_capability);
if ($space_policy) {
if ($space_policy->isStrongerThan($policy)) {
$policy = $space_policy;
$use_space_policy = true;
}
}
}
}
$container_classes = array();
$container_classes[] = 'policy-header-callout';
$phid = $object->getPHID();
// If we're going to show the object policy, try to determine if the object
// policy differs from the default policy. If it does, we'll call it out
// as changed.
if (!$use_space_policy) {
$default_policy = PhabricatorPolicyQuery::getDefaultPolicyForObject(
$viewer,
$object,
$view_capability);
if ($default_policy) {
if ($default_policy->getPHID() != $policy->getPHID()) {
$container_classes[] = 'policy-adjusted';
if ($default_policy->isStrongerThan($policy)) {
// The policy has strictly been weakened. For example, the
// default might be "All Users" and the current policy is "Public".
$container_classes[] = 'policy-adjusted-weaker';
} else if ($policy->isStrongerThan($default_policy)) {
// The policy has strictly been strengthened, and is now more
// restrictive than the default. For example, "All Users" has
// been replaced with "No One".
$container_classes[] = 'policy-adjusted-stronger';
} else {
// The policy has been adjusted but not strictly strengthened
// or weakened. For example, "Members of X" has been replaced with
// "Members of Y".
$container_classes[] = 'policy-adjusted-different';
}
}
}
}
$icon = id(new PHUIIconView())
- ->setIconFont($policy->getIcon().' bluegrey');
+ ->setIcon($policy->getIcon().' bluegrey');
$link = javelin_tag(
'a',
array(
'class' => 'policy-link',
'href' => '/policy/explain/'.$phid.'/'.$view_capability.'/',
'sigil' => 'workflow',
),
$policy->getShortName());
return phutil_tag(
'span',
array(
'class' => implode(' ', $container_classes),
),
array($icon, $link));
}
}
diff --git a/src/view/phui/PHUIIconCircleView.php b/src/view/phui/PHUIIconCircleView.php
index 1269c4e28c..05612c26f2 100644
--- a/src/view/phui/PHUIIconCircleView.php
+++ b/src/view/phui/PHUIIconCircleView.php
@@ -1,67 +1,67 @@
<?php
final class PHUIIconCircleView extends AphrontTagView {
private $href = null;
private $icon;
private $color;
private $size;
const SMALL = 'circle-small';
const MEDIUM = 'circle-medium';
public function setHref($href) {
$this->href = $href;
return $this;
}
- public function setIconFont($icon) {
+ public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setColor($color) {
$this->color = $color;
return $this;
}
public function setSize($size) {
$this->size = $size;
return $this;
}
protected function getTagName() {
$tag = 'span';
if ($this->href) {
$tag = 'a';
}
return $tag;
}
protected function getTagAttributes() {
require_celerity_resource('phui-icon-view-css');
$classes = array();
$classes[] = 'phui-icon-circle';
if ($this->color) {
$classes[] = 'phui-icon-circle-'.$this->color;
}
if ($this->size) {
$classes[] = $this->size;
}
return array(
'href' => $this->href,
'class' => $classes,
);
}
protected function getTagContent() {
return id(new PHUIIconView())
- ->setIconFont($this->icon)
+ ->setIcon($this->icon)
->addClass($this->color);
}
}
diff --git a/src/view/phui/PHUIIconView.php b/src/view/phui/PHUIIconView.php
index c383aff30b..02e06be9e9 100644
--- a/src/view/phui/PHUIIconView.php
+++ b/src/view/phui/PHUIIconView.php
@@ -1,768 +1,768 @@
<?php
final class PHUIIconView extends AphrontTagView {
const SPRITE_TOKENS = 'tokens';
const SPRITE_LOGIN = 'login';
const HEAD_SMALL = 'phuihead-small';
const HEAD_MEDIUM = 'phuihead-medium';
private $href = null;
private $image;
private $text;
private $headSize = null;
private $spriteIcon;
private $spriteSheet;
private $iconFont;
private $iconColor;
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setImage($image) {
$this->image = $image;
return $this;
}
public function setText($text) {
$this->text = $text;
return $this;
}
public function setHeadSize($size) {
$this->headSize = $size;
return $this;
}
public function setSpriteIcon($sprite) {
$this->spriteIcon = $sprite;
return $this;
}
public function setSpriteSheet($sheet) {
$this->spriteSheet = $sheet;
return $this;
}
- public function setIconFont($icon, $color = null) {
+ public function setIcon($icon, $color = null) {
$this->iconFont = $icon;
$this->iconColor = $color;
return $this;
}
protected function getTagName() {
$tag = 'span';
if ($this->href) {
$tag = 'a';
}
return $tag;
}
protected function getTagAttributes() {
require_celerity_resource('phui-icon-view-css');
$style = null;
$classes = array();
$classes[] = 'phui-icon-view';
if ($this->spriteIcon) {
require_celerity_resource('sprite-'.$this->spriteSheet.'-css');
$classes[] = 'sprite-'.$this->spriteSheet;
$classes[] = $this->spriteSheet.'-'.$this->spriteIcon;
} else if ($this->iconFont) {
require_celerity_resource('phui-font-icon-base-css');
require_celerity_resource('font-fontawesome');
$classes[] = 'phui-font-fa';
$classes[] = $this->iconFont;
if ($this->iconColor) {
$classes[] = $this->iconColor;
}
} else {
if ($this->headSize) {
$classes[] = $this->headSize;
}
$style = 'background-image: url('.$this->image.');';
}
if ($this->text) {
$classes[] = 'phui-icon-has-text';
$this->appendChild($this->text);
}
return array(
'href' => $this->href,
'style' => $style,
'aural' => false,
'class' => $classes,
);
}
public static function getSheetManifest($sheet) {
$root = dirname(phutil_get_library_root('phabricator'));
$path = $root.'/resources/sprite/manifest/'.$sheet.'.json';
$data = Filesystem::readFile($path);
return idx(phutil_json_decode($data), 'sprites');
}
public static function getFontIcons() {
return array(
'fa-glass',
'fa-music',
'fa-search',
'fa-envelope-o',
'fa-heart',
'fa-star',
'fa-star-o',
'fa-user',
'fa-film',
'fa-th-large',
'fa-th',
'fa-th-list',
'fa-check',
'fa-times',
'fa-search-plus',
'fa-search-minus',
'fa-power-off',
'fa-signal',
'fa-cog',
'fa-trash-o',
'fa-home',
'fa-file-o',
'fa-clock-o',
'fa-road',
'fa-download',
'fa-arrow-circle-o-down',
'fa-arrow-circle-o-up',
'fa-inbox',
'fa-play-circle-o',
'fa-repeat',
'fa-refresh',
'fa-list-alt',
'fa-lock',
'fa-flag',
'fa-headphones',
'fa-volume-off',
'fa-volume-down',
'fa-volume-up',
'fa-qrcode',
'fa-barcode',
'fa-tag',
'fa-tags',
'fa-book',
'fa-bookmark',
'fa-print',
'fa-camera',
'fa-font',
'fa-bold',
'fa-italic',
'fa-text-height',
'fa-text-width',
'fa-align-left',
'fa-align-center',
'fa-align-right',
'fa-align-justify',
'fa-list',
'fa-outdent',
'fa-indent',
'fa-video-camera',
'fa-picture-o',
'fa-pencil',
'fa-map-marker',
'fa-adjust',
'fa-tint',
'fa-pencil-square-o',
'fa-share-square-o',
'fa-check-square-o',
'fa-arrows',
'fa-step-backward',
'fa-fast-backward',
'fa-backward',
'fa-play',
'fa-pause',
'fa-stop',
'fa-forward',
'fa-fast-forward',
'fa-step-forward',
'fa-eject',
'fa-chevron-left',
'fa-chevron-right',
'fa-plus-circle',
'fa-minus-circle',
'fa-times-circle',
'fa-check-circle',
'fa-question-circle',
'fa-info-circle',
'fa-crosshairs',
'fa-times-circle-o',
'fa-check-circle-o',
'fa-ban',
'fa-arrow-left',
'fa-arrow-right',
'fa-arrow-up',
'fa-arrow-down',
'fa-share',
'fa-expand',
'fa-compress',
'fa-plus',
'fa-minus',
'fa-asterisk',
'fa-exclamation-circle',
'fa-gift',
'fa-leaf',
'fa-fire',
'fa-eye',
'fa-eye-slash',
'fa-exclamation-triangle',
'fa-plane',
'fa-calendar',
'fa-random',
'fa-comment',
'fa-magnet',
'fa-chevron-up',
'fa-chevron-down',
'fa-retweet',
'fa-shopping-cart',
'fa-folder',
'fa-folder-open',
'fa-arrows-v',
'fa-arrows-h',
'fa-bar-chart-o',
'fa-twitter-square',
'fa-facebook-square',
'fa-camera-retro',
'fa-key',
'fa-cogs',
'fa-comments',
'fa-thumbs-o-up',
'fa-thumbs-o-down',
'fa-star-half',
'fa-heart-o',
'fa-sign-out',
'fa-linkedin-square',
'fa-thumb-tack',
'fa-external-link',
'fa-sign-in',
'fa-trophy',
'fa-github-square',
'fa-upload',
'fa-lemon-o',
'fa-phone',
'fa-square-o',
'fa-bookmark-o',
'fa-phone-square',
'fa-twitter',
'fa-facebook',
'fa-github',
'fa-unlock',
'fa-credit-card',
'fa-rss',
'fa-hdd-o',
'fa-bullhorn',
'fa-bell',
'fa-certificate',
'fa-hand-o-right',
'fa-hand-o-left',
'fa-hand-o-up',
'fa-hand-o-down',
'fa-arrow-circle-left',
'fa-arrow-circle-right',
'fa-arrow-circle-up',
'fa-arrow-circle-down',
'fa-globe',
'fa-wrench',
'fa-tasks',
'fa-filter',
'fa-briefcase',
'fa-arrows-alt',
'fa-users',
'fa-link',
'fa-cloud',
'fa-flask',
'fa-scissors',
'fa-files-o',
'fa-paperclip',
'fa-floppy-o',
'fa-square',
'fa-bars',
'fa-list-ul',
'fa-list-ol',
'fa-strikethrough',
'fa-underline',
'fa-table',
'fa-magic',
'fa-truck',
'fa-pinterest',
'fa-pinterest-square',
'fa-google-plus-square',
'fa-google-plus',
'fa-money',
'fa-caret-down',
'fa-caret-up',
'fa-caret-left',
'fa-caret-right',
'fa-columns',
'fa-sort',
'fa-sort-asc',
'fa-sort-desc',
'fa-envelope',
'fa-linkedin',
'fa-undo',
'fa-gavel',
'fa-tachometer',
'fa-comment-o',
'fa-comments-o',
'fa-bolt',
'fa-sitemap',
'fa-umbrella',
'fa-clipboard',
'fa-lightbulb-o',
'fa-exchange',
'fa-cloud-download',
'fa-cloud-upload',
'fa-user-md',
'fa-stethoscope',
'fa-suitcase',
'fa-bell-o',
'fa-coffee',
'fa-cutlery',
'fa-file-text-o',
'fa-building-o',
'fa-hospital-o',
'fa-ambulance',
'fa-medkit',
'fa-fighter-jet',
'fa-beer',
'fa-h-square',
'fa-plus-square',
'fa-angle-double-left',
'fa-angle-double-right',
'fa-angle-double-up',
'fa-angle-double-down',
'fa-angle-left',
'fa-angle-right',
'fa-angle-up',
'fa-angle-down',
'fa-desktop',
'fa-laptop',
'fa-tablet',
'fa-mobile',
'fa-circle-o',
'fa-quote-left',
'fa-quote-right',
'fa-spinner',
'fa-circle',
'fa-reply',
'fa-github-alt',
'fa-folder-o',
'fa-folder-open-o',
'fa-smile-o',
'fa-frown-o',
'fa-meh-o',
'fa-gamepad',
'fa-keyboard-o',
'fa-flag-o',
'fa-flag-checkered',
'fa-terminal',
'fa-code',
'fa-reply-all',
'fa-mail-reply-all',
'fa-star-half-o',
'fa-location-arrow',
'fa-crop',
'fa-code-fork',
'fa-chain-broken',
'fa-question',
'fa-info',
'fa-exclamation',
'fa-superscript',
'fa-subscript',
'fa-eraser',
'fa-puzzle-piece',
'fa-microphone',
'fa-microphone-slash',
'fa-shield',
'fa-calendar-o',
'fa-fire-extinguisher',
'fa-rocket',
'fa-maxcdn',
'fa-chevron-circle-left',
'fa-chevron-circle-right',
'fa-chevron-circle-up',
'fa-chevron-circle-down',
'fa-html5',
'fa-css3',
'fa-anchor',
'fa-unlock-alt',
'fa-bullseye',
'fa-ellipsis-h',
'fa-ellipsis-v',
'fa-rss-square',
'fa-play-circle',
'fa-ticket',
'fa-minus-square',
'fa-minus-square-o',
'fa-level-up',
'fa-level-down',
'fa-check-square',
'fa-pencil-square',
'fa-external-link-square',
'fa-share-square',
'fa-compass',
'fa-caret-square-o-down',
'fa-caret-square-o-up',
'fa-caret-square-o-right',
'fa-eur',
'fa-gbp',
'fa-usd',
'fa-inr',
'fa-jpy',
'fa-rub',
'fa-krw',
'fa-btc',
'fa-file',
'fa-file-text',
'fa-sort-alpha-asc',
'fa-sort-alpha-desc',
'fa-sort-amount-asc',
'fa-sort-amount-desc',
'fa-sort-numeric-asc',
'fa-sort-numeric-desc',
'fa-thumbs-up',
'fa-thumbs-down',
'fa-youtube-square',
'fa-youtube',
'fa-xing',
'fa-xing-square',
'fa-youtube-play',
'fa-dropbox',
'fa-stack-overflow',
'fa-instagram',
'fa-flickr',
'fa-adn',
'fa-bitbucket',
'fa-bitbucket-square',
'fa-tumblr',
'fa-tumblr-square',
'fa-long-arrow-down',
'fa-long-arrow-up',
'fa-long-arrow-left',
'fa-long-arrow-right',
'fa-apple',
'fa-windows',
'fa-android',
'fa-linux',
'fa-dribbble',
'fa-skype',
'fa-foursquare',
'fa-trello',
'fa-female',
'fa-male',
'fa-gittip',
'fa-sun-o',
'fa-moon-o',
'fa-archive',
'fa-bug',
'fa-vk',
'fa-weibo',
'fa-renren',
'fa-pagelines',
'fa-stack-exchange',
'fa-arrow-circle-o-right',
'fa-arrow-circle-o-left',
'fa-caret-square-o-left',
'fa-dot-circle-o',
'fa-wheelchair',
'fa-vimeo-square',
'fa-try',
'fa-plus-square-o',
'fa-space-shuttle',
'fa-slack',
'fa-envelope-square',
'fa-wordpress',
'fa-openid',
'fa-institution',
'fa-bank',
'fa-university',
'fa-mortar-board',
'fa-graduation-cap',
'fa-yahoo',
'fa-google',
'fa-reddit',
'fa-reddit-square',
'fa-stumbleupon-circle',
'fa-stumbleupon',
'fa-delicious',
'fa-digg',
'fa-pied-piper-square',
'fa-pied-piper',
'fa-pied-piper-alt',
'fa-drupal',
'fa-joomla',
'fa-language',
'fa-fax',
'fa-building',
'fa-child',
'fa-paw',
'fa-spoon',
'fa-cube',
'fa-cubes',
'fa-behance',
'fa-behance-square',
'fa-steam',
'fa-steam-square',
'fa-recycle',
'fa-automobile',
'fa-car',
'fa-cab',
'fa-tree',
'fa-spotify',
'fa-deviantart',
'fa-soundcloud',
'fa-database',
'fa-file-pdf-o',
'fa-file-word-o',
'fa-file-excel-o',
'fa-file-powerpoint-o',
'fa-file-photo-o',
'fa-file-picture-o',
'fa-file-image-o',
'fa-file-zip-o',
'fa-file-archive-o',
'fa-file-sound-o',
'fa-file-movie-o',
'fa-file-code-o',
'fa-vine',
'fa-codepen',
'fa-jsfiddle',
'fa-life-bouy',
'fa-support',
'fa-life-ring',
'fa-circle-o-notch',
'fa-rebel',
'fa-empire',
'fa-git-square',
'fa-git',
'fa-hacker-news',
'fa-tencent-weibo',
'fa-qq',
'fa-wechat',
'fa-send',
'fa-paper-plane',
'fa-send-o',
'fa-paper-plane-o',
'fa-history',
'fa-circle-thin',
'fa-header',
'fa-paragraph',
'fa-sliders',
'fa-share-alt',
'fa-share-alt-square',
'fa-bomb',
'fa-soccer-ball',
'fa-futbol-o',
'fa-tty',
'fa-binoculars',
'fa-plug',
'fa-slideshare',
'fa-twitch',
'fa-yelp',
'fa-newspaper-o',
'fa-wifi',
'fa-calculator',
'fa-paypal',
'fa-google-wallet',
'fa-cc-visa',
'fa-cc-mastercard',
'fa-cc-discover',
'fa-cc-amex',
'fa-cc-paypal',
'fa-cc-stripe',
'fa-bell-slash',
'fa-bell-slash-o',
'fa-trash',
'fa-copyright',
'fa-at',
'fa-eyedropper',
'fa-paint-brush',
'fa-birthday-cake',
'fa-area-chart',
'fa-pie-chart',
'fa-line-chart',
'fa-lastfm',
'fa-lastfm-square',
'fa-toggle-off',
'fa-toggle-on',
'fa-bicycle',
'fa-bus',
'fa-ioxhost',
'fa-angellist',
'fa-cc',
'fa-shekel',
'fa-sheqel',
'fa-ils',
'fa-meanpath',
'fa-buysellads',
'fa-connectdevelop',
'fa-dashcube',
'fa-forumbee',
'fa-leanpub',
'fa-sellsy',
'fa-shirtsinbulk',
'fa-simplybuilt',
'fa-skyatlas',
'fa-cart-plus',
'fa-cart-arrow-down',
'fa-diamond',
'fa-ship',
'fa-user-secret',
'fa-motorcycle',
'fa-street-view',
'fa-heartbeat',
'fa-venus',
'fa-mars',
'fa-mercury',
'fa-transgender',
'fa-transgender-alt',
'fa-venus-double',
'fa-mars-double',
'fa-venus-mars',
'fa-mars-stroke',
'fa-mars-stroke-v',
'fa-mars-stroke-h',
'fa-neuter',
'fa-facebook-official',
'fa-pinterest-p',
'fa-whatsapp',
'fa-server',
'fa-user-plus',
'fa-user-times',
'fa-hotel',
'fa-bed',
'fa-viacoin',
'fa-train',
'fa-subway',
'fa-medium',
'fa-git',
'fa-y-combinator-square',
'fa-yc-square',
'fa-hacker-news',
'fa-yc',
'fa-y-combinator',
'fa-optin-monster',
'fa-opencart',
'fa-expeditedssl',
'fa-battery-4',
'fa-battery-full',
'fa-battery-3',
'fa-battery-three-quarters',
'fa-battery-2',
'fa-battery-half',
'fa-battery-1',
'fa-battery-quarter',
'fa-battery-0',
'fa-battery-empty',
'fa-mouse-pointer',
'fa-i-cursor',
'fa-object-group',
'fa-object-ungroup',
'fa-sticky-note',
'fa-sticky-note-o',
'fa-cc-jcb',
'fa-cc-diners-club',
'fa-clone',
'fa-balance-scale',
'fa-hourglass-o',
'fa-hourglass-1',
'fa-hourglass-start',
'fa-hourglass-2',
'fa-hourglass-half',
'fa-hourglass-3',
'fa-hourglass-end',
'fa-hourglass',
'fa-hand-grab-o',
'fa-hand-rock-o',
'fa-hand-stop-o',
'fa-hand-paper-o',
'fa-hand-scissors-o',
'fa-hand-lizard-o',
'fa-hand-spock-o',
'fa-hand-pointer-o',
'fa-hand-peace-o',
'fa-trademark',
'fa-registered',
'fa-creative-commons',
'fa-gg',
'fa-gg-circle',
'fa-tripadvisor',
'fa-odnoklassniki',
'fa-odnoklassniki-square',
'fa-get-pocket',
'fa-wikipedia-w',
'fa-safari',
'fa-chrome',
'fa-firefox',
'fa-opera',
'fa-internet-explorer',
'fa-tv',
'fa-television',
'fa-contao',
'fa-500px',
'fa-amazon',
'fa-calendar-plus-o',
'fa-calendar-minus-o',
'fa-calendar-times-o',
'fa-calendar-check-o',
'fa-industry',
'fa-map-pin',
'fa-map-signs',
'fa-map-o',
'fa-map',
'fa-commenting',
'fa-commenting-o',
'fa-houzz',
'fa-vimeo',
'fa-black-tie',
'fa-fonticons',
'fa-reddit-alien',
'fa-edge',
'fa-credit-card-alt',
'fa-codiepie:before',
'fa-modx',
'fa-fort-awesome',
'fa-usb',
'fa-product-hunt',
'fa-mixcloud',
'fa-scribd',
'fa-pause-circle',
'fa-pause-circle-o',
'fa-stop-circle',
'fa-stop-circle-o',
'fa-shopping-bag',
'fa-shopping-basket',
'fa-hashtag',
'fa-bluetooth',
'fa-bluetooth-b',
'fa-percent',
);
}
public static function getFontIconColors() {
return array(
'bluegrey',
'white',
'red',
'orange',
'yellow',
'green',
'blue',
'sky',
'indigo',
'violet',
'pink',
'lightgreytext',
'lightbluetext',
);
}
}
diff --git a/src/view/phui/PHUIListItemView.php b/src/view/phui/PHUIListItemView.php
index f0bb46fb87..33c511c9c0 100644
--- a/src/view/phui/PHUIListItemView.php
+++ b/src/view/phui/PHUIListItemView.php
@@ -1,310 +1,310 @@
<?php
final class PHUIListItemView extends AphrontTagView {
const TYPE_LINK = 'type-link';
const TYPE_SPACER = 'type-spacer';
const TYPE_LABEL = 'type-label';
const TYPE_BUTTON = 'type-button';
const TYPE_CUSTOM = 'type-custom';
const TYPE_DIVIDER = 'type-divider';
const TYPE_ICON = 'type-icon';
const STATUS_WARN = 'phui-list-item-warn';
const STATUS_FAIL = 'phui-list-item-fail';
private $name;
private $href;
private $type = self::TYPE_LINK;
private $isExternal;
private $key;
private $icon;
private $selected;
private $disabled;
private $renderNameAsTooltip;
private $statusColor;
private $order;
private $aural;
private $profileImage;
private $indented;
private $hideInApplicationMenu;
private $icons = array();
public function setHideInApplicationMenu($hide) {
$this->hideInApplicationMenu = $hide;
return $this;
}
public function getHideInApplicationMenu() {
return $this->hideInApplicationMenu;
}
public function setDropdownMenu(PhabricatorActionListView $actions) {
Javelin::initBehavior('phui-dropdown-menu');
$this->addSigil('phui-dropdown-menu');
$this->setMetadata(
array(
'items' => $actions,
));
return $this;
}
public function setAural($aural) {
$this->aural = $aural;
return $this;
}
public function getAural() {
return $this->aural;
}
public function setOrder($order) {
$this->order = $order;
return $this;
}
public function getOrder() {
return $this->order;
}
public function setRenderNameAsTooltip($render_name_as_tooltip) {
$this->renderNameAsTooltip = $render_name_as_tooltip;
return $this;
}
public function getRenderNameAsTooltip() {
return $this->renderNameAsTooltip;
}
public function setSelected($selected) {
$this->selected = $selected;
return $this;
}
public function getSelected() {
return $this->selected;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setProfileImage($image) {
$this->profileImage = $image;
return $this;
}
public function getIcon() {
return $this->icon;
}
public function setIndented($indented) {
$this->indented = $indented;
return $this;
}
public function getIndented() {
return $this->indented;
}
public function setKey($key) {
$this->key = (string)$key;
return $this;
}
public function getKey() {
return $this->key;
}
public function setType($type) {
$this->type = $type;
return $this;
}
public function getType() {
return $this->type;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function getHref() {
return $this->href;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
return $this->name;
}
public function setIsExternal($is_external) {
$this->isExternal = $is_external;
return $this;
}
public function getIsExternal() {
return $this->isExternal;
}
public function setStatusColor($color) {
$this->statusColor = $color;
return $this;
}
public function addIcon($icon) {
$this->icons[] = $icon;
return $this;
}
public function getIcons() {
return $this->icons;
}
protected function getTagName() {
return 'li';
}
protected function getTagAttributes() {
$classes = array();
$classes[] = 'phui-list-item-view';
$classes[] = 'phui-list-item-'.$this->type;
if ($this->icon) {
$classes[] = 'phui-list-item-has-icon';
}
if ($this->selected) {
$classes[] = 'phui-list-item-selected';
}
if ($this->disabled) {
$classes[] = 'phui-list-item-disabled';
}
if ($this->statusColor) {
$classes[] = $this->statusColor;
}
return array(
'class' => $classes,
);
}
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
}
public function getDisabled() {
return $this->disabled;
}
protected function getTagContent() {
$name = null;
$icon = null;
$meta = null;
$sigil = null;
if ($this->name) {
if ($this->getRenderNameAsTooltip()) {
Javelin::initBehavior('phabricator-tooltips');
$sigil = 'has-tooltip';
$meta = array(
'tip' => $this->name,
'align' => 'E',
);
} else {
$external = null;
if ($this->isExternal) {
$external = " \xE2\x86\x97";
}
// If this element has an aural representation, make any name visual
// only. This is primarily dealing with the links in the main menu like
// "Profile" and "Logout". If we don't hide the name, the mobile
// version of these elements will have two redundant names.
$classes = array();
$classes[] = 'phui-list-item-name';
if ($this->aural !== null) {
$classes[] = 'visual-only';
}
$name = phutil_tag(
'span',
array(
'class' => implode(' ', $classes),
),
array(
$this->name,
$external,
));
}
}
$aural = null;
if ($this->aural !== null) {
$aural = javelin_tag(
'span',
array(
'aural' => true,
),
$this->aural);
}
if ($this->icon) {
$icon_name = $this->icon;
if ($this->getDisabled()) {
$icon_name .= ' grey';
}
$icon = id(new PHUIIconView())
->addClass('phui-list-item-icon')
- ->setIconFont($icon_name);
+ ->setIcon($icon_name);
}
if ($this->profileImage) {
$icon = id(new PHUIIconView())
->setHeadSize(PHUIIconView::HEAD_SMALL)
->addClass('phui-list-item-icon')
->setImage($this->profileImage);
}
$classes = array();
if ($this->href) {
$classes[] = 'phui-list-item-href';
}
if ($this->indented) {
$classes[] = 'phui-list-item-indented';
}
$icons = $this->getIcons();
return javelin_tag(
$this->href ? 'a' : 'div',
array(
'href' => $this->href,
'class' => implode(' ', $classes),
'meta' => $meta,
'sigil' => $sigil,
),
array(
$aural,
$icon,
$icons,
$this->renderChildren(),
$name,
));
}
}
diff --git a/src/view/phui/PHUIObjectBoxView.php b/src/view/phui/PHUIObjectBoxView.php
index 7c2a28d75c..32440a09cf 100644
--- a/src/view/phui/PHUIObjectBoxView.php
+++ b/src/view/phui/PHUIObjectBoxView.php
@@ -1,430 +1,430 @@
<?php
final class PHUIObjectBoxView extends AphrontView {
private $headerText;
private $color;
private $background;
private $formErrors = null;
private $formSaved = false;
private $infoView;
private $form;
private $validationException;
private $header;
private $flush;
private $id;
private $sigils = array();
private $metadata;
private $actionListID;
private $objectList;
private $table;
private $collapsed = false;
private $anchor;
private $showAction;
private $hideAction;
private $showHideHref;
private $showHideContent;
private $showHideOpen;
private $tabs = array();
private $propertyLists = array();
const COLOR_RED = 'red';
const COLOR_BLUE = 'blue';
const COLOR_GREEN = 'green';
const COLOR_YELLOW = 'yellow';
public function addSigil($sigil) {
$this->sigils[] = $sigil;
return $this;
}
public function setMetadata(array $metadata) {
$this->metadata = $metadata;
return $this;
}
public function addPropertyList(
PHUIPropertyListView $property_list,
$tab = null) {
if (!($tab instanceof PHUIListItemView) &&
($tab !== null)) {
assert_stringlike($tab);
$tab = id(new PHUIListItemView())->setName($tab);
}
if ($tab) {
if ($tab->getKey()) {
$key = $tab->getKey();
} else {
$key = 'tab.default.'.spl_object_hash($tab);
$tab->setKey($key);
}
} else {
$key = 'tab.default';
}
if ($tab) {
if (empty($this->tabs[$key])) {
$tab->addSigil('phui-object-box-tab');
$tab->setMetadata(
array(
'tabKey' => $key,
));
if (!$tab->getHref()) {
$tab->setHref('#');
}
if (!$tab->getType()) {
$tab->setType(PHUIListItemView::TYPE_LINK);
}
$this->tabs[$key] = $tab;
}
}
$this->propertyLists[$key][] = $property_list;
$action_list = $property_list->getActionList();
if ($action_list) {
$this->actionListID = celerity_generate_unique_node_id();
$action_list->setId($this->actionListID);
}
return $this;
}
public function setHeaderText($text) {
$this->headerText = $text;
return $this;
}
public function setColor($color) {
$this->color = $color;
return $this;
}
public function setBackground($color) {
$this->background = $color;
return $this;
}
public function setFormErrors(array $errors, $title = null) {
if ($errors) {
$this->formErrors = id(new PHUIInfoView())
->setTitle($title)
->setErrors($errors);
}
return $this;
}
public function setFormSaved($saved, $text = null) {
if (!$text) {
$text = pht('Changes saved.');
}
if ($saved) {
$save = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild($text);
$this->formSaved = $save;
}
return $this;
}
public function setInfoView(PHUIInfoView $view) {
$this->infoView = $view;
return $this;
}
public function setForm($form) {
$this->form = $form;
return $this;
}
public function setID($id) {
$this->id = $id;
return $this;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setFlush($flush) {
$this->flush = $flush;
return $this;
}
public function setObjectList($list) {
$this->objectList = $list;
return $this;
}
public function setTable($table) {
$this->collapsed = true;
$this->table = $table;
return $this;
}
public function setCollapsed($collapsed) {
$this->collapsed = $collapsed;
return $this;
}
public function setAnchor(PhabricatorAnchorView $anchor) {
$this->anchor = $anchor;
return $this;
}
public function setShowHide($show, $hide, $content, $href, $open = false) {
$this->showAction = $show;
$this->hideAction = $hide;
$this->showHideContent = $content;
$this->showHideHref = $href;
$this->showHideOpen = $open;
return $this;
}
public function setValidationException(
PhabricatorApplicationTransactionValidationException $ex = null) {
$this->validationException = $ex;
return $this;
}
public function render() {
require_celerity_resource('phui-object-box-css');
$header = $this->header;
if ($this->headerText) {
$header = id(new PHUIHeaderView())
->setHeader($this->headerText);
}
$showhide = null;
if ($this->showAction !== null) {
if (!$header) {
$header = id(new PHUIHeaderView());
}
Javelin::initBehavior('phabricator-reveal-content');
$hide_action_id = celerity_generate_unique_node_id();
$show_action_id = celerity_generate_unique_node_id();
$content_id = celerity_generate_unique_node_id();
$hide_style = ($this->showHideOpen ? 'display: none;': null);
$show_style = ($this->showHideOpen ? null : 'display: none;');
$hide_action = id(new PHUIButtonView())
->setTag('a')
->addSigil('reveal-content')
->setID($hide_action_id)
->setStyle($hide_style)
->setHref($this->showHideHref)
->setMetaData(
array(
'hideIDs' => array($hide_action_id),
'showIDs' => array($content_id, $show_action_id),
))
->setText($this->showAction);
$show_action = id(new PHUIButtonView())
->setTag('a')
->addSigil('reveal-content')
->setStyle($show_style)
->setHref('#')
->setID($show_action_id)
->setMetaData(
array(
'hideIDs' => array($content_id, $show_action_id),
'showIDs' => array($hide_action_id),
))
->setText($this->hideAction);
$header->addActionLink($hide_action);
$header->addActionLink($show_action);
$showhide = array(
phutil_tag(
'div',
array(
'class' => 'phui-object-box-hidden-content',
'id' => $content_id,
'style' => $show_style,
),
$this->showHideContent),
);
}
if ($this->actionListID) {
$icon_id = celerity_generate_unique_node_id();
$icon = id(new PHUIIconView())
- ->setIconFont('fa-bars');
+ ->setIcon('fa-bars');
$meta = array(
'map' => array(
$this->actionListID => 'phabricator-action-list-toggle',
$icon_id => 'phuix-dropdown-open',
),
);
$mobile_menu = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Actions'))
->setHref('#')
->setIcon($icon)
->addClass('phui-mobile-menu')
->setID($icon_id)
->addSigil('jx-toggle-class')
->setMetadata($meta);
$header->addActionLink($mobile_menu);
}
$ex = $this->validationException;
$exception_errors = null;
if ($ex) {
$messages = array();
foreach ($ex->getErrors() as $error) {
$messages[] = $error->getMessage();
}
if ($messages) {
$exception_errors = id(new PHUIInfoView())
->setErrors($messages);
}
}
$tab_lists = array();
$property_lists = array();
$tab_map = array();
$default_key = 'tab.default';
// Find the selected tab, or select the first tab if none are selected.
if ($this->tabs) {
$selected_tab = null;
foreach ($this->tabs as $key => $tab) {
if ($tab->getSelected()) {
$selected_tab = $key;
break;
}
}
if ($selected_tab === null) {
head($this->tabs)->setSelected(true);
$selected_tab = head_key($this->tabs);
}
}
foreach ($this->propertyLists as $key => $list) {
$group = new PHUIPropertyGroupView();
$i = 0;
foreach ($list as $item) {
$group->addPropertyList($item);
if ($i > 0) {
$item->addClass('phui-property-list-section-noninitial');
}
$i++;
}
if ($this->tabs && $key != $default_key) {
$tab_id = celerity_generate_unique_node_id();
$tab_map[$key] = $tab_id;
if ($key === $selected_tab) {
$style = null;
} else {
$style = 'display: none';
}
$tab_lists[] = phutil_tag(
'div',
array(
'style' => $style,
'id' => $tab_id,
),
$group);
} else {
if ($this->tabs) {
$group->addClass('phui-property-group-noninitial');
}
$property_lists[] = $group;
}
}
$tabs = null;
if ($this->tabs) {
$tabs = id(new PHUIListView())
->setType(PHUIListView::NAVBAR_LIST);
foreach ($this->tabs as $tab) {
$tabs->addMenuItem($tab);
}
Javelin::initBehavior('phui-object-box-tabs');
}
$content = id(new PHUIBoxView())
->appendChild(
array(
($this->showHideOpen == false ? $this->anchor : null),
$header,
$this->infoView,
$this->formErrors,
$this->formSaved,
$exception_errors,
$this->form,
$tabs,
$tab_lists,
$showhide,
($this->showHideOpen == true ? $this->anchor : null),
$property_lists,
$this->table,
$this->renderChildren(),
))
->setBorder(true)
->setID($this->id)
->addMargin(PHUI::MARGIN_LARGE_TOP)
->addMargin(PHUI::MARGIN_LARGE_LEFT)
->addMargin(PHUI::MARGIN_LARGE_RIGHT)
->addClass('phui-object-box');
if ($this->color) {
$content->addClass('phui-object-box-'.$this->color);
}
if ($this->background) {
$content->setColor($this->background);
}
if ($this->collapsed) {
$content->addClass('phui-object-box-collapsed');
}
if ($this->tabs) {
$content->addSigil('phui-object-box');
$content->setMetadata(
array(
'tabMap' => $tab_map,
));
}
if ($this->flush) {
$content->addClass('phui-object-box-flush');
}
foreach ($this->sigils as $sigil) {
$content->addSigil($sigil);
}
if ($this->metadata !== null) {
$content->setMetadata($this->metadata);
}
if ($this->objectList) {
$content->appendChild($this->objectList);
}
return $content;
}
}
diff --git a/src/view/phui/PHUIObjectItemView.php b/src/view/phui/PHUIObjectItemView.php
index 5da85777b0..bc48351c96 100644
--- a/src/view/phui/PHUIObjectItemView.php
+++ b/src/view/phui/PHUIObjectItemView.php
@@ -1,759 +1,759 @@
<?php
final class PHUIObjectItemView extends AphrontTagView {
private $objectName;
private $header;
private $subhead;
private $href;
private $attributes = array();
private $icons = array();
private $barColor;
private $object;
private $effect;
private $statusIcon;
private $handleIcons = array();
private $bylines = array();
private $grippable;
private $actions = array();
private $headIcons = array();
private $disabled;
private $imageURI;
private $state;
private $fontIcon;
private $imageIcon;
private $titleText;
private $badge;
private $countdownNum;
private $countdownNoun;
private $launchButton;
const AGE_FRESH = 'fresh';
const AGE_STALE = 'stale';
const AGE_OLD = 'old';
const STATE_SUCCESS = 'green';
const STATE_FAIL = 'red';
const STATE_WARN = 'yellow';
const STATE_NOTE = 'blue';
const STATE_BUILD = 'sky';
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
}
public function getDisabled() {
return $this->disabled;
}
public function addHeadIcon($icon) {
$this->headIcons[] = $icon;
return $this;
}
public function setObjectName($name) {
$this->objectName = $name;
return $this;
}
public function setGrippable($grippable) {
$this->grippable = $grippable;
return $this;
}
public function getGrippable() {
return $this->grippable;
}
public function setEffect($effect) {
$this->effect = $effect;
return $this;
}
public function getEffect() {
return $this->effect;
}
public function setObject($object) {
$this->object = $object;
return $this;
}
public function getObject() {
return $this->object;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function getHref() {
return $this->href;
}
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setSubHead($subhead) {
$this->subhead = $subhead;
return $this;
}
public function setBadge(PHUIBadgeMiniView $badge) {
$this->badge = $badge;
return $this;
}
public function setCountdown($num, $noun) {
$this->countdownNum = $num;
$this->countdownNoun = $noun;
return $this;
}
public function setTitleText($title_text) {
$this->titleText = $title_text;
return $this;
}
public function getTitleText() {
return $this->titleText;
}
public function getHeader() {
return $this->header;
}
public function addByline($byline) {
$this->bylines[] = $byline;
return $this;
}
public function setImageURI($image_uri) {
$this->imageURI = $image_uri;
return $this;
}
public function getImageURI() {
return $this->imageURI;
}
public function setImageIcon($image_icon) {
$this->imageIcon = $image_icon;
return $this;
}
public function getImageIcon() {
return $this->imageIcon;
}
public function setState($state) {
$this->state = $state;
switch ($state) {
case self::STATE_SUCCESS:
$fi = 'fa-check-circle green';
break;
case self::STATE_FAIL:
$fi = 'fa-times-circle red';
break;
case self::STATE_WARN:
$fi = 'fa-exclamation-circle yellow';
break;
case self::STATE_NOTE:
$fi = 'fa-info-circle blue';
break;
case self::STATE_BUILD:
$fi = 'fa-refresh ph-spin sky';
break;
}
$this->setFontIcon($fi);
return $this;
}
public function setFontIcon($icon) {
$this->fontIcon = id(new PHUIIconView())
- ->setIconFont($icon);
+ ->setIcon($icon);
return $this;
}
public function setEpoch($epoch, $age = self::AGE_FRESH) {
$date = phabricator_datetime($epoch, $this->getUser());
$days = floor((time() - $epoch) / 60 / 60 / 24);
switch ($age) {
case self::AGE_FRESH:
$this->addIcon('none', $date);
break;
case self::AGE_STALE:
$attr = array(
'tip' => pht('Stale (%s day(s))', new PhutilNumber($days)),
'class' => 'icon-age-stale',
);
$this->addIcon('fa-clock-o yellow', $date, $attr);
break;
case self::AGE_OLD:
$attr = array(
'tip' => pht('Old (%s day(s))', new PhutilNumber($days)),
'class' => 'icon-age-old',
);
$this->addIcon('fa-clock-o red', $date, $attr);
break;
default:
throw new Exception(pht("Unknown age '%s'!", $age));
}
return $this;
}
public function addAction(PHUIListItemView $action) {
if (count($this->actions) >= 3) {
throw new Exception(pht('Limit 3 actions per item.'));
}
$this->actions[] = $action;
return $this;
}
public function addIcon($icon, $label = null, $attributes = array()) {
$this->icons[] = array(
'icon' => $icon,
'label' => $label,
'attributes' => $attributes,
);
return $this;
}
public function setStatusIcon($icon, $label = null) {
$this->statusIcon = array(
'icon' => $icon,
'label' => $label,
);
return $this;
}
public function addHandleIcon(
PhabricatorObjectHandle $handle,
$label = null) {
$this->handleIcons[] = array(
'icon' => $handle,
'label' => $label,
);
return $this;
}
public function setBarColor($bar_color) {
$this->barColor = $bar_color;
return $this;
}
public function getBarColor() {
return $this->barColor;
}
public function addAttribute($attribute) {
if (!empty($attribute)) {
$this->attributes[] = $attribute;
}
return $this;
}
public function setLaunchButton(PHUIButtonView $button) {
$button->setSize(PHUIButtonView::SMALL);
$this->launchButton = $button;
return $this;
}
protected function getTagName() {
return 'li';
}
protected function getTagAttributes() {
$item_classes = array();
$item_classes[] = 'phui-object-item';
if ($this->icons) {
$item_classes[] = 'phui-object-item-with-icons';
}
if ($this->attributes) {
$item_classes[] = 'phui-object-item-with-attrs';
}
if ($this->handleIcons) {
$item_classes[] = 'phui-object-item-with-handle-icons';
}
if ($this->barColor) {
$item_classes[] = 'phui-object-item-bar-color-'.$this->barColor;
} else {
$item_classes[] = 'phui-object-item-no-bar';
}
if ($this->actions) {
$n = count($this->actions);
$item_classes[] = 'phui-object-item-with-actions';
$item_classes[] = 'phui-object-item-with-'.$n.'-actions';
}
if ($this->disabled) {
$item_classes[] = 'phui-object-item-disabled';
}
if ($this->state) {
$item_classes[] = 'phui-object-item-state-'.$this->state;
}
switch ($this->effect) {
case 'highlighted':
$item_classes[] = 'phui-object-item-highlighted';
break;
case 'selected':
$item_classes[] = 'phui-object-item-selected';
break;
case null:
break;
default:
throw new Exception(pht('Invalid effect!'));
}
if ($this->getGrippable()) {
$item_classes[] = 'phui-object-item-grippable';
}
if ($this->getImageURI()) {
$item_classes[] = 'phui-object-item-with-image';
}
if ($this->getImageIcon()) {
$item_classes[] = 'phui-object-item-with-image-icon';
}
if ($this->fontIcon) {
$item_classes[] = 'phui-object-item-with-ficon';
}
return array(
'class' => $item_classes,
);
}
protected function getTagContent() {
$viewer = $this->getUser();
$content_classes = array();
$content_classes[] = 'phui-object-item-content';
$header_name = array();
if ($viewer) {
$header_name[] = id(new PHUISpacesNamespaceContextView())
->setUser($viewer)
->setObject($this->object);
}
if ($this->objectName) {
$header_name[] = array(
phutil_tag(
'span',
array(
'class' => 'phui-object-item-objname',
),
$this->objectName),
' ',
);
}
$title_text = null;
if ($this->titleText) {
$title_text = $this->titleText;
} else if ($this->href) {
$title_text = $this->header;
}
$header_link = phutil_tag(
$this->href ? 'a' : 'div',
array(
'href' => $this->href,
'class' => 'phui-object-item-link',
'title' => $title_text,
),
$this->header);
$header = javelin_tag(
'div',
array(
'class' => 'phui-object-item-name',
'sigil' => 'slippery',
),
array(
$this->headIcons,
$header_name,
$header_link,
));
$icons = array();
if ($this->icons) {
$icon_list = array();
foreach ($this->icons as $spec) {
$icon = $spec['icon'];
$icon = id(new PHUIIconView())
- ->setIconFont($icon)
+ ->setIcon($icon)
->addClass('phui-object-item-icon-image');
if (isset($spec['attributes']['tip'])) {
$sigil = 'has-tooltip';
$meta = array(
'tip' => $spec['attributes']['tip'],
'align' => 'W',
);
$icon->addSigil($sigil);
$icon->setMetadata($meta);
}
$label = phutil_tag(
'span',
array(
'class' => 'phui-object-item-icon-label',
),
$spec['label']);
if (isset($spec['attributes']['href'])) {
$icon_href = phutil_tag(
'a',
array('href' => $spec['attributes']['href']),
array($icon, $label));
} else {
$icon_href = array($icon, $label);
}
$classes = array();
$classes[] = 'phui-object-item-icon';
if (isset($spec['attributes']['class'])) {
$classes[] = $spec['attributes']['class'];
}
$icon_list[] = javelin_tag(
'li',
array(
'class' => implode(' ', $classes),
),
$icon_href);
}
$icons[] = phutil_tag(
'ul',
array(
'class' => 'phui-object-item-icons',
),
$icon_list);
}
if ($this->handleIcons) {
$handle_bar = array();
foreach ($this->handleIcons as $handleicon) {
$handle_bar[] =
$this->renderHandleIcon($handleicon['icon'], $handleicon['label']);
}
$icons[] = phutil_tag(
'div',
array(
'class' => 'phui-object-item-handle-icons',
),
$handle_bar);
}
$bylines = array();
if ($this->bylines) {
foreach ($this->bylines as $byline) {
$bylines[] = phutil_tag(
'div',
array(
'class' => 'phui-object-item-byline',
),
$byline);
}
$bylines = phutil_tag(
'div',
array(
'class' => 'phui-object-item-bylines',
),
$bylines);
}
$subhead = null;
if ($this->subhead) {
$subhead = phutil_tag(
'div',
array(
'class' => 'phui-object-item-subhead',
),
$this->subhead);
}
if ($icons) {
$icons = phutil_tag(
'div',
array(
'class' => 'phui-object-icon-pane',
),
$icons);
}
$attrs = null;
if ($this->attributes) {
$attrs = array();
$spacer = phutil_tag(
'span',
array(
'class' => 'phui-object-item-attribute-spacer',
),
"\xC2\xB7");
$first = true;
foreach ($this->attributes as $attribute) {
$attrs[] = phutil_tag(
'li',
array(
'class' => 'phui-object-item-attribute',
),
array(
($first ? null : $spacer),
$attribute,
));
$first = false;
}
$attrs = phutil_tag(
'ul',
array(
'class' => 'phui-object-item-attributes',
),
$attrs);
}
$status = null;
if ($this->statusIcon) {
$icon = $this->statusIcon;
$status = $this->renderStatusIcon($icon['icon'], $icon['label']);
}
$grippable = null;
if ($this->getGrippable()) {
$grippable = phutil_tag(
'div',
array(
'class' => 'phui-object-item-grip',
),
'');
}
$content = phutil_tag(
'div',
array(
'class' => implode(' ', $content_classes),
),
array(
$subhead,
$attrs,
$this->renderChildren(),
));
$image = null;
if ($this->getImageURI()) {
$image = phutil_tag(
'div',
array(
'class' => 'phui-object-item-image',
'style' => 'background-image: url('.$this->getImageURI().')',
),
'');
} else if ($this->getImageIcon()) {
$image = phutil_tag(
'div',
array(
'class' => 'phui-object-item-image-icon',
),
$this->getImageIcon());
}
$ficon = null;
if ($this->fontIcon) {
$image = phutil_tag(
'div',
array(
'class' => 'phui-object-item-ficon',
),
$this->fontIcon);
}
if ($image && $this->href) {
$image = phutil_tag(
'a',
array(
'href' => $this->href,
),
$image);
}
/* Build a fake table */
$column0 = null;
if ($status) {
$column0 = phutil_tag(
'div',
array(
'class' => 'phui-object-item-col0',
),
$status);
}
if ($this->badge) {
$column0 = phutil_tag(
'div',
array(
'class' => 'phui-object-item-col0 phui-object-item-badge',
),
$this->badge);
}
if ($this->countdownNum) {
$countdown = phutil_tag(
'div',
array(
'class' => 'phui-object-item-countdown-number',
),
array(
phutil_tag_div('', $this->countdownNum),
phutil_tag_div('', $this->countdownNoun),
));
$column0 = phutil_tag(
'div',
array(
'class' => 'phui-object-item-col0 phui-object-item-countdown',
),
$countdown);
}
$column1 = phutil_tag(
'div',
array(
'class' => 'phui-object-item-col1',
),
array(
$header,
$content,
));
$column2 = null;
if ($icons || $bylines) {
$column2 = phutil_tag(
'div',
array(
'class' => 'phui-object-item-col2',
),
array(
$icons,
$bylines,
));
}
if ($this->launchButton) {
$column2 = phutil_tag(
'div',
array(
'class' => 'phui-object-item-col2 phui-object-item-launch-button',
),
array(
$this->launchButton,
));
}
$table = phutil_tag(
'div',
array(
'class' => 'phui-object-item-table',
),
phutil_tag_div(
'phui-object-item-table-row',
array(
$column0,
$column1,
$column2,
)));
$box = phutil_tag(
'div',
array(
'class' => 'phui-object-item-content-box',
),
array(
$grippable,
$table,
));
$actions = array();
if ($this->actions) {
Javelin::initBehavior('phabricator-tooltips');
foreach (array_reverse($this->actions) as $action) {
$action->setRenderNameAsTooltip(true);
$actions[] = $action;
}
$actions = phutil_tag(
'ul',
array(
'class' => 'phui-object-item-actions',
),
$actions);
}
return phutil_tag(
'div',
array(
'class' => 'phui-object-item-frame',
),
array(
$actions,
$image,
$box,
));
}
private function renderStatusIcon($icon, $label) {
Javelin::initBehavior('phabricator-tooltips');
$icon = id(new PHUIIconView())
- ->setIconFont($icon);
+ ->setIcon($icon);
$options = array(
'class' => 'phui-object-item-status-icon',
);
if (strlen($label)) {
$options['sigil'] = 'has-tooltip';
$options['meta'] = array('tip' => $label, 'size' => 300);
}
return javelin_tag('div', $options, $icon);
}
private function renderHandleIcon(PhabricatorObjectHandle $handle, $label) {
Javelin::initBehavior('phabricator-tooltips');
$options = array(
'class' => 'phui-object-item-handle-icon',
'style' => 'background-image: url('.$handle->getImageURI().')',
);
if (strlen($label)) {
$options['sigil'] = 'has-tooltip';
$options['meta'] = array('tip' => $label);
}
return javelin_tag('span', $options, '');
}
}
diff --git a/src/view/phui/PHUIPinboardItemView.php b/src/view/phui/PHUIPinboardItemView.php
index 93e2277040..1fafefc3d6 100644
--- a/src/view/phui/PHUIPinboardItemView.php
+++ b/src/view/phui/PHUIPinboardItemView.php
@@ -1,153 +1,153 @@
<?php
final class PHUIPinboardItemView extends AphrontView {
private $imageURI;
private $uri;
private $header;
private $iconBlock = array();
private $disabled;
private $object;
private $imageWidth;
private $imageHeight;
public function setHeader($header) {
$this->header = $header;
return $this;
}
public function setURI($uri) {
$this->uri = $uri;
return $this;
}
public function setImageURI($image_uri) {
$this->imageURI = $image_uri;
return $this;
}
public function setImageSize($x, $y) {
$this->imageWidth = $x;
$this->imageHeight = $y;
return $this;
}
public function addIconCount($icon, $count) {
$this->iconBlock[] = array($icon, $count);
return $this;
}
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
}
public function setObject($object) {
$this->object = $object;
return $this;
}
public function render() {
require_celerity_resource('phui-pinboard-view-css');
$header = null;
if ($this->header) {
$header_color = null;
if ($this->disabled) {
$header_color = 'phui-pinboard-disabled';
}
$header = phutil_tag(
'div',
array(
'class' => 'phui-pinboard-item-header '.$header_color,
),
array(
id(new PHUISpacesNamespaceContextView())
->setUser($this->getUser())
->setObject($this->object),
phutil_tag(
'a',
array(
'href' => $this->uri,
),
$this->header),
));
}
$image = null;
if ($this->imageWidth) {
$image = phutil_tag(
'a',
array(
'href' => $this->uri,
'class' => 'phui-pinboard-item-image-link',
),
phutil_tag(
'img',
array(
'src' => $this->imageURI,
'width' => $this->imageWidth,
'height' => $this->imageHeight,
)));
}
$icons = array();
if ($this->iconBlock) {
$icon_list = array();
foreach ($this->iconBlock as $block) {
$icon = id(new PHUIIconView())
- ->setIconFont($block[0].' lightgreytext')
+ ->setIcon($block[0].' lightgreytext')
->addClass('phui-pinboard-icon');
$count = phutil_tag('span', array(), $block[1]);
$icon_list[] = phutil_tag(
'span',
array(
'class' => 'phui-pinboard-item-count',
),
array($icon, $count));
}
$icons = phutil_tag(
'div',
array(
'class' => 'phui-pinboard-icons',
),
$icon_list);
}
$content = $this->renderChildren();
if ($content) {
$content = phutil_tag(
'div',
array(
'class' => 'phui-pinboard-item-content',
),
$content);
}
$classes = array();
$classes[] = 'phui-pinboard-item-view';
if ($this->disabled) {
$classes[] = 'phui-pinboard-item-disabled';
}
$item = phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
array(
$image,
$header,
$content,
$icons,
));
return phutil_tag(
'li',
array(
'class' => 'phui-pinboard-list-item',
),
$item);
}
}
diff --git a/src/view/phui/PHUIPropertyListView.php b/src/view/phui/PHUIPropertyListView.php
index e498bf9a5b..0d60ed25b0 100644
--- a/src/view/phui/PHUIPropertyListView.php
+++ b/src/view/phui/PHUIPropertyListView.php
@@ -1,303 +1,303 @@
<?php
final class PHUIPropertyListView extends AphrontView {
private $parts = array();
private $hasKeyboardShortcuts;
private $object;
private $invokedWillRenderEvent;
private $actionList = null;
private $classes = array();
private $stacked;
const ICON_SUMMARY = 'fa-align-left';
const ICON_TESTPLAN = 'fa-file-text-o';
protected function canAppendChild() {
return false;
}
public function setObject($object) {
$this->object = $object;
return $this;
}
public function setActionList(PhabricatorActionListView $list) {
$this->actionList = $list;
return $this;
}
public function getActionList() {
return $this->actionList;
}
public function setStacked($stacked) {
$this->stacked = $stacked;
return $this;
}
public function addClass($class) {
$this->classes[] = $class;
return $this;
}
public function setHasKeyboardShortcuts($has_keyboard_shortcuts) {
$this->hasKeyboardShortcuts = $has_keyboard_shortcuts;
return $this;
}
public function addProperty($key, $value) {
$current = array_pop($this->parts);
if (!$current || $current['type'] != 'property') {
if ($current) {
$this->parts[] = $current;
}
$current = array(
'type' => 'property',
'list' => array(),
);
}
$current['list'][] = array(
'key' => $key,
'value' => $value,
);
$this->parts[] = $current;
return $this;
}
public function addSectionHeader($name, $icon = null) {
$this->parts[] = array(
'type' => 'section',
'name' => $name,
'icon' => $icon,
);
return $this;
}
public function addTextContent($content) {
$this->parts[] = array(
'type' => 'text',
'content' => $content,
);
return $this;
}
public function addRawContent($content) {
$this->parts[] = array(
'type' => 'raw',
'content' => $content,
);
return $this;
}
public function addImageContent($content) {
$this->parts[] = array(
'type' => 'image',
'content' => $content,
);
return $this;
}
public function invokeWillRenderEvent() {
if ($this->object && $this->getUser() && !$this->invokedWillRenderEvent) {
$event = new PhabricatorEvent(
PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES,
array(
'object' => $this->object,
'view' => $this,
));
$event->setUser($this->getUser());
PhutilEventEngine::dispatchEvent($event);
}
$this->invokedWillRenderEvent = true;
}
public function isEmpty() {
$this->invokeWillRenderEvent();
if ($this->parts) {
return false;
}
return true;
}
public function render() {
$this->invokeWillRenderEvent();
require_celerity_resource('phui-property-list-view-css');
$items = array();
$parts = $this->parts;
// If we have an action list, make sure we render a property part, even
// if there are no properties. Otherwise, the action list won't render.
if ($this->actionList) {
$this->classes[] = 'phui-property-list-has-actions';
$have_property_part = false;
foreach ($this->parts as $part) {
if ($part['type'] == 'property') {
$have_property_part = true;
break;
}
}
if (!$have_property_part) {
$parts[] = array(
'type' => 'property',
'list' => array(),
);
}
}
foreach ($parts as $part) {
$type = $part['type'];
switch ($type) {
case 'property':
$items[] = $this->renderPropertyPart($part);
break;
case 'section':
$items[] = $this->renderSectionPart($part);
break;
case 'text':
case 'image':
$items[] = $this->renderTextPart($part);
break;
case 'raw':
$items[] = $this->renderRawPart($part);
break;
default:
throw new Exception(pht("Unknown part type '%s'!", $type));
}
}
$this->classes[] = 'phui-property-list-section';
$classes = implode(' ', $this->classes);
return phutil_tag(
'div',
array(
'class' => $classes,
),
array(
$items,
));
}
private function renderPropertyPart(array $part) {
$items = array();
foreach ($part['list'] as $spec) {
$key = $spec['key'];
$value = $spec['value'];
// NOTE: We append a space to each value to improve the behavior when the
// user double-clicks a property value (like a URI) to select it. Without
// the space, the label is also selected.
$items[] = phutil_tag(
'dt',
array(
'class' => 'phui-property-list-key',
),
array($key, ' '));
$items[] = phutil_tag(
'dd',
array(
'class' => 'phui-property-list-value',
),
array($value, ' '));
}
$stacked = '';
if ($this->stacked) {
$stacked = 'phui-property-list-stacked';
}
$list = phutil_tag(
'dl',
array(
'class' => 'phui-property-list-properties',
),
$items);
$shortcuts = null;
if ($this->hasKeyboardShortcuts) {
$shortcuts = new AphrontKeyboardShortcutsAvailableView();
}
$list = phutil_tag(
'div',
array(
'class' => 'phui-property-list-properties-wrap '.$stacked,
),
array($shortcuts, $list));
$action_list = null;
if ($this->actionList) {
$action_list = phutil_tag(
'div',
array(
'class' => 'phui-property-list-actions',
),
$this->actionList);
$this->actionList = null;
}
return phutil_tag(
'div',
array(
'class' => 'phui-property-list-container grouped',
),
array($action_list, $list));
}
private function renderSectionPart(array $part) {
$name = $part['name'];
if ($part['icon']) {
$icon = id(new PHUIIconView())
- ->setIconFont($part['icon'].' bluegrey');
+ ->setIcon($part['icon'].' bluegrey');
$name = phutil_tag(
'span',
array(
'class' => 'phui-property-list-section-header-icon',
),
array($icon, $name));
}
return phutil_tag(
'div',
array(
'class' => 'phui-property-list-section-header',
),
$name);
}
private function renderTextPart(array $part) {
$classes = array();
$classes[] = 'phui-property-list-text-content';
if ($part['type'] == 'image') {
$classes[] = 'phui-property-list-image-content';
}
return phutil_tag(
'div',
array(
'class' => implode($classes, ' '),
),
$part['content']);
}
private function renderRawPart(array $part) {
$classes = array();
$classes[] = 'phui-property-list-raw-content';
return phutil_tag(
'div',
array(
'class' => implode($classes, ' '),
),
$part['content']);
}
}
diff --git a/src/view/phui/PHUIStatusItemView.php b/src/view/phui/PHUIStatusItemView.php
index b268360eef..dae7e7d472 100644
--- a/src/view/phui/PHUIStatusItemView.php
+++ b/src/view/phui/PHUIStatusItemView.php
@@ -1,111 +1,111 @@
<?php
final class PHUIStatusItemView extends AphrontTagView {
private $icon;
private $iconLabel;
private $iconColor;
private $target;
private $note;
private $highlighted;
const ICON_ACCEPT = 'fa-check-circle';
const ICON_REJECT = 'fa-times-circle';
const ICON_LEFT = 'fa-chevron-circle-left';
const ICON_RIGHT = 'fa-chevron-circle-right';
const ICON_UP = 'fa-chevron-circle-up';
const ICON_DOWN = 'fa-chevron-circle-down';
const ICON_QUESTION = 'fa-question-circle';
const ICON_WARNING = 'fa-exclamation-circle';
const ICON_INFO = 'fa-info-circle';
const ICON_ADD = 'fa-plus-circle';
const ICON_MINUS = 'fa-minus-circle';
const ICON_OPEN = 'fa-circle-o';
const ICON_CLOCK = 'fa-clock-o';
const ICON_STAR = 'fa-star';
public function setIcon($icon, $color = null, $label = null) {
$this->icon = $icon;
$this->iconLabel = $label;
$this->iconColor = $color;
return $this;
}
public function setTarget($target) {
$this->target = $target;
return $this;
}
public function setNote($note) {
$this->note = $note;
return $this;
}
public function setHighlighted($highlighted) {
$this->highlighted = $highlighted;
return $this;
}
protected function canAppendChild() {
return false;
}
protected function getTagName() {
return 'tr';
}
protected function getTagAttributes() {
$classes = array();
if ($this->highlighted) {
$classes[] = 'phui-status-item-highlighted';
}
return array(
'class' => $classes,
);
}
protected function getTagContent() {
$icon = null;
if ($this->icon) {
$icon = id(new PHUIIconView())
- ->setIconFont($this->icon.' '.$this->iconColor);
+ ->setIcon($this->icon.' '.$this->iconColor);
if ($this->iconLabel) {
Javelin::initBehavior('phabricator-tooltips');
$icon->addSigil('has-tooltip');
$icon->setMetadata(
array(
'tip' => $this->iconLabel,
'size' => 240,
));
}
}
$icon_cell = phutil_tag(
'td',
array(),
$icon);
$target_cell = phutil_tag(
'td',
array(
'class' => 'phui-status-item-target',
),
$this->target);
$note_cell = phutil_tag(
'td',
array(
'class' => 'phui-status-item-note',
),
$this->note);
return array(
$icon_cell,
$target_cell,
$note_cell,
);
}
}
diff --git a/src/view/phui/PHUITagView.php b/src/view/phui/PHUITagView.php
index 439feb77c5..8b6e6aa8d6 100644
--- a/src/view/phui/PHUITagView.php
+++ b/src/view/phui/PHUITagView.php
@@ -1,253 +1,253 @@
<?php
final class PHUITagView extends AphrontTagView {
const TYPE_PERSON = 'person';
const TYPE_OBJECT = 'object';
const TYPE_STATE = 'state';
const TYPE_SHADE = 'shade';
const COLOR_RED = 'red';
const COLOR_ORANGE = 'orange';
const COLOR_YELLOW = 'yellow';
const COLOR_BLUE = 'blue';
const COLOR_INDIGO = 'indigo';
const COLOR_VIOLET = 'violet';
const COLOR_GREEN = 'green';
const COLOR_BLACK = 'black';
const COLOR_GREY = 'grey';
const COLOR_WHITE = 'white';
const COLOR_PINK = 'pink';
const COLOR_BLUEGREY = 'bluegrey';
const COLOR_CHECKERED = 'checkered';
const COLOR_DISABLED = 'disabled';
const COLOR_OBJECT = 'object';
const COLOR_PERSON = 'person';
private $type;
private $href;
private $name;
private $phid;
private $backgroundColor;
private $dotColor;
private $closed;
private $external;
private $icon;
private $shade;
private $slimShady;
public function setType($type) {
$this->type = $type;
switch ($type) {
case self::TYPE_SHADE:
break;
case self::TYPE_OBJECT:
$this->setBackgroundColor(self::COLOR_OBJECT);
break;
case self::TYPE_PERSON:
$this->setBackgroundColor(self::COLOR_PERSON);
break;
}
return $this;
}
public function setShade($shade) {
$this->shade = $shade;
return $this;
}
public function setDotColor($dot_color) {
$this->dotColor = $dot_color;
return $this;
}
public function setBackgroundColor($background_color) {
$this->backgroundColor = $background_color;
return $this;
}
public function setPHID($phid) {
$this->phid = $phid;
return $this;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function setHref($href) {
$this->href = $href;
return $this;
}
public function setClosed($closed) {
$this->closed = $closed;
return $this;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setSlimShady($mm) {
$this->slimShady = $mm;
return $this;
}
protected function getTagName() {
return strlen($this->href) ? 'a' : 'span';
}
protected function getTagAttributes() {
require_celerity_resource('phui-tag-view-css');
$classes = array(
'phui-tag-view',
'phui-tag-type-'.$this->type,
);
if ($this->shade) {
$classes[] = 'phui-tag-shade';
$classes[] = 'phui-tag-shade-'.$this->shade;
if ($this->slimShady) {
$classes[] = 'phui-tag-shade-slim';
}
}
if ($this->icon) {
$classes[] = 'phui-tag-icon-view';
}
if ($this->phid) {
Javelin::initBehavior('phabricator-hovercards');
$attributes = array(
'href' => $this->href,
'sigil' => 'hovercard',
'meta' => array(
'hoverPHID' => $this->phid,
),
'target' => $this->external ? '_blank' : null,
);
} else {
$attributes = array(
'href' => $this->href,
'target' => $this->external ? '_blank' : null,
);
}
return $attributes + array('class' => $classes);
}
protected function getTagContent() {
if (!$this->type) {
throw new PhutilInvalidStateException('setType', 'render');
}
$color = null;
if (!$this->shade && $this->backgroundColor) {
$color = 'phui-tag-color-'.$this->backgroundColor;
}
if ($this->dotColor) {
$dotcolor = 'phui-tag-color-'.$this->dotColor;
$dot = phutil_tag(
'span',
array(
'class' => 'phui-tag-dot '.$dotcolor,
),
'');
} else {
$dot = null;
}
if ($this->icon) {
$icon = id(new PHUIIconView())
- ->setIconFont($this->icon);
+ ->setIcon($this->icon);
} else {
$icon = null;
}
$content = phutil_tag(
'span',
array(
'class' => 'phui-tag-core '.$color,
),
array($dot, $icon, $this->name));
if ($this->closed) {
$content = phutil_tag(
'span',
array(
'class' => 'phui-tag-core-closed',
),
array($icon, $content));
}
return $content;
}
public static function getTagTypes() {
return array(
self::TYPE_PERSON,
self::TYPE_OBJECT,
self::TYPE_STATE,
);
}
public static function getColors() {
return array(
self::COLOR_RED,
self::COLOR_ORANGE,
self::COLOR_YELLOW,
self::COLOR_BLUE,
self::COLOR_INDIGO,
self::COLOR_VIOLET,
self::COLOR_GREEN,
self::COLOR_BLACK,
self::COLOR_GREY,
self::COLOR_WHITE,
self::COLOR_OBJECT,
self::COLOR_PERSON,
);
}
public static function getShades() {
return array_keys(self::getShadeMap());
}
public static function getShadeMap() {
return array(
self::COLOR_RED => pht('Red'),
self::COLOR_ORANGE => pht('Orange'),
self::COLOR_YELLOW => pht('Yellow'),
self::COLOR_BLUE => pht('Blue'),
self::COLOR_INDIGO => pht('Indigo'),
self::COLOR_VIOLET => pht('Violet'),
self::COLOR_GREEN => pht('Green'),
self::COLOR_GREY => pht('Grey'),
self::COLOR_PINK => pht('Pink'),
self::COLOR_CHECKERED => pht('Checkered'),
self::COLOR_DISABLED => pht('Disabled'),
);
}
public static function getShadeName($shade) {
return idx(self::getShadeMap(), $shade, $shade);
}
public function setExternal($external) {
$this->external = $external;
return $this;
}
public function getExternal() {
return $this->external;
}
}
diff --git a/src/view/phui/PHUITimelineEventView.php b/src/view/phui/PHUITimelineEventView.php
index f9f1d4d3b4..ecd9329860 100644
--- a/src/view/phui/PHUITimelineEventView.php
+++ b/src/view/phui/PHUITimelineEventView.php
@@ -1,659 +1,659 @@
<?php
final class PHUITimelineEventView extends AphrontView {
const DELIMITER = " \xC2\xB7 ";
private $userHandle;
private $title;
private $icon;
private $color;
private $classes = array();
private $contentSource;
private $dateCreated;
private $anchor;
private $isEditable;
private $isEdited;
private $isRemovable;
private $transactionPHID;
private $isPreview;
private $eventGroup = array();
private $hideByDefault;
private $token;
private $tokenRemoved;
private $quoteTargetID;
private $isNormalComment;
private $quoteRef;
private $reallyMajorEvent;
private $hideCommentOptions = false;
private $authorPHID;
private $badges = array();
public function setAuthorPHID($author_phid) {
$this->authorPHID = $author_phid;
return $this;
}
public function getAuthorPHID() {
return $this->authorPHID;
}
public function setQuoteRef($quote_ref) {
$this->quoteRef = $quote_ref;
return $this;
}
public function getQuoteRef() {
return $this->quoteRef;
}
public function setQuoteTargetID($quote_target_id) {
$this->quoteTargetID = $quote_target_id;
return $this;
}
public function getQuoteTargetID() {
return $this->quoteTargetID;
}
public function setIsNormalComment($is_normal_comment) {
$this->isNormalComment = $is_normal_comment;
return $this;
}
public function getIsNormalComment() {
return $this->isNormalComment;
}
public function setHideByDefault($hide_by_default) {
$this->hideByDefault = $hide_by_default;
return $this;
}
public function getHideByDefault() {
return $this->hideByDefault;
}
public function setTransactionPHID($transaction_phid) {
$this->transactionPHID = $transaction_phid;
return $this;
}
public function getTransactionPHID() {
return $this->transactionPHID;
}
public function setIsEdited($is_edited) {
$this->isEdited = $is_edited;
return $this;
}
public function getIsEdited() {
return $this->isEdited;
}
public function setIsPreview($is_preview) {
$this->isPreview = $is_preview;
return $this;
}
public function getIsPreview() {
return $this->isPreview;
}
public function setIsEditable($is_editable) {
$this->isEditable = $is_editable;
return $this;
}
public function getIsEditable() {
return $this->isEditable;
}
public function setIsRemovable($is_removable) {
$this->isRemovable = $is_removable;
return $this;
}
public function getIsRemovable() {
return $this->isRemovable;
}
public function setDateCreated($date_created) {
$this->dateCreated = $date_created;
return $this;
}
public function getDateCreated() {
return $this->dateCreated;
}
public function setContentSource(PhabricatorContentSource $content_source) {
$this->contentSource = $content_source;
return $this;
}
public function getContentSource() {
return $this->contentSource;
}
public function setUserHandle(PhabricatorObjectHandle $handle) {
$this->userHandle = $handle;
return $this;
}
public function setAnchor($anchor) {
$this->anchor = $anchor;
return $this;
}
public function getAnchor() {
return $this->anchor;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function addClass($class) {
$this->classes[] = $class;
return $this;
}
public function addBadge(PHUIBadgeMiniView $badge) {
$this->badges[] = $badge;
return $this;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function setColor($color) {
$this->color = $color;
return $this;
}
public function setReallyMajorEvent($me) {
$this->reallyMajorEvent = $me;
return $this;
}
public function setHideCommentOptions($hide_comment_options) {
$this->hideCommentOptions = $hide_comment_options;
return $this;
}
public function getHideCommentOptions() {
return $this->hideCommentOptions;
}
public function setToken($token, $removed = false) {
$this->token = $token;
$this->tokenRemoved = $removed;
return $this;
}
public function getEventGroup() {
return array_merge(array($this), $this->eventGroup);
}
public function addEventToGroup(PHUITimelineEventView $event) {
$this->eventGroup[] = $event;
return $this;
}
protected function shouldRenderEventTitle() {
if ($this->title === null) {
return false;
}
return true;
}
protected function renderEventTitle($force_icon, $has_menu, $extra) {
$title = $this->title;
$title_classes = array();
$title_classes[] = 'phui-timeline-title';
$icon = null;
if ($this->icon || $force_icon) {
$title_classes[] = 'phui-timeline-title-with-icon';
}
if ($has_menu) {
$title_classes[] = 'phui-timeline-title-with-menu';
}
if ($this->icon) {
$fill_classes = array();
$fill_classes[] = 'phui-timeline-icon-fill';
if ($this->color) {
$fill_classes[] = 'phui-timeline-icon-fill-'.$this->color;
}
$icon = id(new PHUIIconView())
- ->setIconFont($this->icon.' white')
+ ->setIcon($this->icon.' white')
->addClass('phui-timeline-icon');
$icon = phutil_tag(
'span',
array(
'class' => implode(' ', $fill_classes),
),
$icon);
}
$token = null;
if ($this->token) {
$token = id(new PHUIIconView())
->addClass('phui-timeline-token')
->setSpriteSheet(PHUIIconView::SPRITE_TOKENS)
->setSpriteIcon($this->token);
if ($this->tokenRemoved) {
$token->addClass('strikethrough');
}
}
$title = phutil_tag(
'div',
array(
'class' => implode(' ', $title_classes),
),
array($icon, $token, $title, $extra));
return $title;
}
public function render() {
$events = $this->getEventGroup();
// Move events with icons first.
$icon_keys = array();
foreach ($this->getEventGroup() as $key => $event) {
if ($event->icon) {
$icon_keys[] = $key;
}
}
$events = array_select_keys($events, $icon_keys) + $events;
$force_icon = (bool)$icon_keys;
$menu = null;
$items = array();
$has_menu = false;
if (!$this->getIsPreview() && !$this->getHideCommentOptions()) {
foreach ($this->getEventGroup() as $event) {
$items[] = $event->getMenuItems($this->anchor);
if ($event->hasChildren()) {
$has_menu = true;
}
}
$items = array_mergev($items);
}
if ($items || $has_menu) {
$icon = id(new PHUIIconView())
- ->setIconFont('fa-caret-down');
+ ->setIcon('fa-caret-down');
$aural = javelin_tag(
'span',
array(
'aural' => true,
),
pht('Comment Actions'));
if ($items) {
$sigil = 'phui-dropdown-menu';
Javelin::initBehavior('phui-dropdown-menu');
} else {
$sigil = null;
}
$action_list = id(new PhabricatorActionListView())
->setUser($this->getUser());
foreach ($items as $item) {
$action_list->addAction($item);
}
$menu = javelin_tag(
$items ? 'a' : 'span',
array(
'href' => '#',
'class' => 'phui-timeline-menu',
'sigil' => $sigil,
'aria-haspopup' => 'true',
'aria-expanded' => 'false',
'meta' => array(
'items' => hsprintf('%s', $action_list),
),
),
array(
$aural,
$icon,
));
$has_menu = true;
}
// Render "extra" information (timestamp, etc).
$extra = $this->renderExtra($events);
$group_titles = array();
$group_items = array();
$group_children = array();
foreach ($events as $event) {
if ($event->shouldRenderEventTitle()) {
$group_titles[] = $event->renderEventTitle(
$force_icon,
$has_menu,
$extra);
// Don't render this information more than once.
$extra = null;
}
if ($event->hasChildren()) {
$group_children[] = $event->renderChildren();
}
}
$image_uri = $this->userHandle->getImageURI();
$wedge = phutil_tag(
'div',
array(
'class' => 'phui-timeline-wedge phui-timeline-border',
'style' => (nonempty($image_uri)) ? '' : 'display: none;',
),
'');
$image = null;
$badges = null;
if ($image_uri) {
$image = phutil_tag(
($this->userHandle->getURI()) ? 'a' : 'div',
array(
'style' => 'background-image: url('.$image_uri.')',
'class' => 'phui-timeline-image',
'href' => $this->userHandle->getURI(),
),
'');
if ($this->badges) {
$flex = new PHUIBadgeBoxView();
$flex->addItems($this->badges);
$flex->setCollapsed(true);
$badges = phutil_tag(
'div',
array(
'class' => 'phui-timeline-badges',
),
$flex);
}
}
$content_classes = array();
$content_classes[] = 'phui-timeline-content';
$classes = array();
$classes[] = 'phui-timeline-event-view';
if ($group_children) {
$classes[] = 'phui-timeline-major-event';
$content = phutil_tag(
'div',
array(
'class' => 'phui-timeline-inner-content',
),
array(
$group_titles,
$menu,
phutil_tag(
'div',
array(
'class' => 'phui-timeline-core-content',
),
$group_children),
));
} else {
$classes[] = 'phui-timeline-minor-event';
$content = $group_titles;
}
$content = phutil_tag(
'div',
array(
'class' => 'phui-timeline-group phui-timeline-border',
),
$content);
$content = phutil_tag(
'div',
array(
'class' => implode(' ', $content_classes),
),
array($image, $badges, $wedge, $content));
$outer_classes = $this->classes;
$outer_classes[] = 'phui-timeline-shell';
$color = null;
foreach ($this->getEventGroup() as $event) {
if ($event->color) {
$color = $event->color;
break;
}
}
if ($color) {
$outer_classes[] = 'phui-timeline-'.$color;
}
$sigil = null;
$meta = null;
if ($this->getTransactionPHID()) {
$sigil = 'transaction';
$meta = array(
'phid' => $this->getTransactionPHID(),
'anchor' => $this->anchor,
);
}
$major_event = null;
if ($this->reallyMajorEvent) {
$major_event = phutil_tag(
'div',
array(
'class' => 'phui-timeline-event-view '.
'phui-timeline-spacer '.
'phui-timeline-spacer-bold',
'',
));
}
return array(
javelin_tag(
'div',
array(
'class' => implode(' ', $outer_classes),
'id' => $this->anchor ? 'anchor-'.$this->anchor : null,
'sigil' => $sigil,
'meta' => $meta,
),
phutil_tag(
'div',
array(
'class' => implode(' ', $classes),
),
$content)),
$major_event,
);
}
private function renderExtra(array $events) {
$extra = array();
if ($this->getIsPreview()) {
$extra[] = pht('PREVIEW');
} else {
foreach ($events as $event) {
if ($event->getIsEdited()) {
$extra[] = pht('Edited');
break;
}
}
$source = $this->getContentSource();
if ($source) {
$extra[] = id(new PhabricatorContentSourceView())
->setContentSource($source)
->setUser($this->getUser())
->render();
}
$date_created = null;
foreach ($events as $event) {
if ($event->getDateCreated()) {
if ($date_created === null) {
$date_created = $event->getDateCreated();
} else {
$date_created = min($event->getDateCreated(), $date_created);
}
}
}
if ($date_created) {
$date = phabricator_datetime(
$date_created,
$this->getUser());
if ($this->anchor) {
Javelin::initBehavior('phabricator-watch-anchor');
$anchor = id(new PhabricatorAnchorView())
->setAnchorName($this->anchor)
->render();
$date = array(
$anchor,
phutil_tag(
'a',
array(
'href' => '#'.$this->anchor,
),
$date),
);
}
$extra[] = $date;
}
}
$extra = javelin_tag(
'span',
array(
'class' => 'phui-timeline-extra',
),
phutil_implode_html(
javelin_tag(
'span',
array(
'aural' => false,
),
self::DELIMITER),
$extra));
return $extra;
}
private function getMenuItems($anchor) {
$xaction_phid = $this->getTransactionPHID();
$items = array();
if ($this->getIsEditable()) {
$items[] = id(new PhabricatorActionView())
->setIcon('fa-pencil')
->setHref('/transactions/edit/'.$xaction_phid.'/')
->setName(pht('Edit Comment'))
->addSigil('transaction-edit')
->setMetadata(
array(
'anchor' => $anchor,
));
}
if ($this->getQuoteTargetID()) {
$ref = null;
if ($this->getQuoteRef()) {
$ref = $this->getQuoteRef();
if ($anchor) {
$ref = $ref.'#'.$anchor;
}
}
$items[] = id(new PhabricatorActionView())
->setIcon('fa-quote-left')
->setHref('#')
->setName(pht('Quote'))
->addSigil('transaction-quote')
->setMetadata(
array(
'targetID' => $this->getQuoteTargetID(),
'uri' => '/transactions/quote/'.$xaction_phid.'/',
'ref' => $ref,
));
}
if ($this->getIsNormalComment()) {
$items[] = id(new PhabricatorActionView())
->setIcon('fa-cutlery')
->setHref('/transactions/raw/'.$xaction_phid.'/')
->setName(pht('View Raw'))
->addSigil('transaction-raw')
->setMetadata(
array(
'anchor' => $anchor,
));
$content_source = $this->getContentSource();
$source_email = PhabricatorContentSource::SOURCE_EMAIL;
if ($content_source->getSource() == $source_email) {
$source_id = $content_source->getParam('id');
if ($source_id) {
$items[] = id(new PhabricatorActionView())
->setIcon('fa-envelope-o')
->setHref('/transactions/raw/'.$xaction_phid.'/?email')
->setName(pht('View Email Body'))
->addSigil('transaction-raw')
->setMetadata(
array(
'anchor' => $anchor,
));
}
}
}
if ($this->getIsRemovable()) {
$items[] = id(new PhabricatorActionView())
->setIcon('fa-times')
->setHref('/transactions/remove/'.$xaction_phid.'/')
->setName(pht('Remove Comment'))
->addSigil('transaction-remove')
->setMetadata(
array(
'anchor' => $anchor,
));
}
if ($this->getIsEdited()) {
$items[] = id(new PhabricatorActionView())
->setIcon('fa-list')
->setHref('/transactions/history/'.$xaction_phid.'/')
->setName(pht('View Edit History'))
->setWorkflow(true);
}
return $items;
}
}
diff --git a/src/view/phui/calendar/PHUICalendarDayView.php b/src/view/phui/calendar/PHUICalendarDayView.php
index dd8e5f3fb2..34299e39c3 100644
--- a/src/view/phui/calendar/PHUICalendarDayView.php
+++ b/src/view/phui/calendar/PHUICalendarDayView.php
@@ -1,485 +1,485 @@
<?php
final class PHUICalendarDayView extends AphrontView {
private $rangeStart;
private $rangeEnd;
private $day;
private $month;
private $year;
private $browseURI;
private $query;
private $events = array();
private $allDayEvents = array();
public function addEvent(AphrontCalendarEventView $event) {
$this->events[] = $event;
return $this;
}
public function setBrowseURI($browse_uri) {
$this->browseURI = $browse_uri;
return $this;
}
private function getBrowseURI() {
return $this->browseURI;
}
public function setQuery($query) {
$this->query = $query;
return $this;
}
private function getQuery() {
return $this->query;
}
public function __construct(
$range_start,
$range_end,
$year,
$month,
$day = null) {
$this->rangeStart = $range_start;
$this->rangeEnd = $range_end;
$this->day = $day;
$this->month = $month;
$this->year = $year;
}
public function render() {
require_celerity_resource('phui-calendar-day-css');
$viewer = $this->getUser();
$hours = $this->getHoursOfDay();
$js_hours = array();
$js_today_events = array();
foreach ($hours as $hour) {
$js_hours[] = array(
'hour' => $hour->format('G'),
'hour_meridian' => $hour->format('g A'),
);
}
$first_event_hour = null;
$js_today_all_day_events = array();
$all_day_events = $this->getAllDayEvents();
$day_start = $this->getDateTime();
$day_end = id(clone $day_start)->modify('+1 day');
$day_start_epoch = $day_start->format('U');
$day_end_epoch = $day_end->format('U') - 1;
foreach ($all_day_events as $all_day_event) {
$all_day_start = $all_day_event->getEpochStart();
$all_day_end = $all_day_event->getEpochEnd();
if ($all_day_start < $day_end_epoch && $all_day_end > $day_start_epoch) {
$js_today_all_day_events[] = array(
'name' => $all_day_event->getName(),
'id' => $all_day_event->getEventID(),
'viewerIsInvited' => $all_day_event->getViewerIsInvited(),
'uri' => $all_day_event->getURI(),
);
}
}
$this->events = msort($this->events, 'getEpochStart');
$first_event_hour = $this->getDateTime()->setTime(8, 0, 0);
$midnight = $this->getDateTime()->setTime(0, 0, 0);
foreach ($this->events as $event) {
if ($event->getIsAllDay()) {
continue;
}
if ($event->getEpochStart() <= $day_end_epoch &&
$event->getEpochEnd() > $day_start_epoch) {
if ($event->getEpochStart() < $midnight->format('U') &&
$event->getEpochEnd() > $midnight->format('U')) {
$first_event_hour = clone $midnight;
}
if ($event->getEpochStart() < $first_event_hour->format('U') &&
$event->getEpochStart() > $midnight->format('U')) {
$first_event_hour = PhabricatorTime::getDateTimeFromEpoch(
$event->getEpochStart(),
$viewer);
$first_event_hour->setTime($first_event_hour->format('h'), 0, 0);
}
$event_start = max($event->getEpochStart(), $day_start_epoch);
$event_end = min($event->getEpochEnd(), $day_end_epoch);
$day_duration = ($day_end_epoch - $first_event_hour->format('U')) / 60;
$top = (($event_start - $first_event_hour->format('U'))
/ ($day_end_epoch - $first_event_hour->format('U')))
* $day_duration;
$top = max(0, $top);
$height = (($event_end - $event_start)
/ ($day_end_epoch - $first_event_hour->format('U')))
* $day_duration;
$height = min($day_duration, $height);
$js_today_events[] = array(
'eventStartEpoch' => $event->getEpochStart(),
'eventEndEpoch' => $event->getEpochEnd(),
'eventName' => $event->getName(),
'eventID' => $event->getEventID(),
'viewerIsInvited' => $event->getViewerIsInvited(),
'uri' => $event->getURI(),
'offset' => '0',
'width' => '100%',
'top' => $top.'px',
'height' => $height.'px',
'canEdit' => $event->getCanEdit(),
);
}
}
$header = $this->renderDayViewHeader();
$sidebar = $this->renderSidebar();
$warnings = $this->getQueryRangeWarning();
$table_id = celerity_generate_unique_node_id();
$table_wrapper = phutil_tag(
'div',
array(
'id' => $table_id,
),
'');
Javelin::initBehavior(
'day-view',
array(
'year' => $first_event_hour->format('Y'),
'month' => $first_event_hour->format('m'),
'day' => $first_event_hour->format('d'),
'query' => $this->getQuery(),
'allDayEvents' => $js_today_all_day_events,
'todayEvents' => $js_today_events,
'hours' => $js_hours,
'firstEventHour' => $first_event_hour->format('G'),
'firstEventHourEpoch' => $first_event_hour->format('U'),
'tableID' => $table_id,
));
$table_box = id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($table_wrapper)
->setFormErrors($warnings)
->setFlush(true);
$layout = id(new AphrontMultiColumnView())
->addColumn($sidebar, 'third')
->addColumn($table_box, 'thirds phui-day-view-column')
->setFluidLayout(true)
->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM);
return phutil_tag(
'div',
array(
'class' => 'ml',
),
$layout);
}
private function getAllDayEvents() {
$all_day_events = array();
foreach ($this->events as $event) {
if ($event->getIsAllDay()) {
$all_day_events[] = $event;
}
}
$all_day_events = array_values(msort($all_day_events, 'getEpochStart'));
return $all_day_events;
}
private function getQueryRangeWarning() {
$errors = array();
$range_start_epoch = null;
$range_end_epoch = null;
if ($this->rangeStart) {
$range_start_epoch = $this->rangeStart->getEpoch();
}
if ($this->rangeEnd) {
$range_end_epoch = $this->rangeEnd->getEpoch();
}
$day_start = $this->getDateTime();
$day_end = id(clone $day_start)->modify('+1 day');
$day_start = $day_start->format('U');
$day_end = $day_end->format('U') - 1;
if (($range_start_epoch != null &&
$range_start_epoch < $day_end &&
$range_start_epoch > $day_start) ||
($range_end_epoch != null &&
$range_end_epoch < $day_end &&
$range_end_epoch > $day_start)) {
$errors[] = pht('Part of the day is out of range');
}
if (($range_end_epoch != null &&
$range_end_epoch < $day_start) ||
($range_start_epoch != null &&
$range_start_epoch > $day_end)) {
$errors[] = pht('Day is out of query range');
}
return $errors;
}
private function renderSidebar() {
$this->events = msort($this->events, 'getEpochStart');
$week_of_boxes = $this->getWeekOfBoxes();
$filled_boxes = array();
foreach ($week_of_boxes as $day_box) {
$box_start = $day_box['start'];
$box_end = id(clone $box_start)->modify('+1 day');
$box_start = $box_start->format('U');
$box_end = $box_end->format('U');
$box_events = array();
foreach ($this->events as $event) {
$event_start = $event->getEpochStart();
$event_end = $event->getEpochEnd();
if ($event_start < $box_end && $event_end > $box_start) {
$box_events[] = $event;
}
}
$filled_boxes[] = $this->renderSidebarBox(
$box_events,
$day_box['title']);
}
return $filled_boxes;
}
private function renderSidebarBox($events, $title) {
$widget = id(new PHUICalendarWidgetView())
->addClass('calendar-day-view-sidebar');
$list = id(new PHUICalendarListView())
->setUser($this->user)
->setView('day');
if (count($events) == 0) {
$list->showBlankState(true);
} else {
$sorted_events = msort($events, 'getEpochStart');
foreach ($sorted_events as $event) {
$list->addEvent($event);
}
}
$widget
->setCalendarList($list)
->setHeader($title);
return $widget;
}
private function getWeekOfBoxes() {
$sidebar_day_boxes = array();
$display_start_day = $this->getDateTime();
$display_end_day = id(clone $display_start_day)->modify('+6 day');
$box_start_time = clone $display_start_day;
$today_time = PhabricatorTime::getTodayMidnightDateTime($this->user);
$tomorrow_time = clone $today_time;
$tomorrow_time->modify('+1 day');
while ($box_start_time <= $display_end_day) {
if ($box_start_time == $today_time) {
$title = pht('Today');
} else if ($box_start_time == $tomorrow_time) {
$title = pht('Tomorrow');
} else {
$title = $box_start_time->format('l');
}
$sidebar_day_boxes[] = array(
'title' => $title,
'start' => clone $box_start_time,
);
$box_start_time->modify('+1 day');
}
return $sidebar_day_boxes;
}
private function renderDayViewHeader() {
$button_bar = null;
$uri = $this->getBrowseURI();
if ($uri) {
list($prev_year, $prev_month, $prev_day) = $this->getPrevDay();
$prev_uri = $uri.$prev_year.'/'.$prev_month.'/'.$prev_day.'/';
list($next_year, $next_month, $next_day) = $this->getNextDay();
$next_uri = $uri.$next_year.'/'.$next_month.'/'.$next_day.'/';
$button_bar = new PHUIButtonBarView();
$left_icon = id(new PHUIIconView())
- ->setIconFont('fa-chevron-left bluegrey');
+ ->setIcon('fa-chevron-left bluegrey');
$left = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($prev_uri)
->setTitle(pht('Previous Day'))
->setIcon($left_icon);
$right_icon = id(new PHUIIconView())
- ->setIconFont('fa-chevron-right bluegrey');
+ ->setIcon('fa-chevron-right bluegrey');
$right = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($next_uri)
->setTitle(pht('Next Day'))
->setIcon($right_icon);
$button_bar->addButton($left);
$button_bar->addButton($right);
}
$display_day = $this->getDateTime();
$header_text = $display_day->format('l, F j, Y');
$header = id(new PHUIHeaderView())
->setHeader($header_text);
if ($button_bar) {
$header->setButtonBar($button_bar);
}
return $header;
}
private function updateEventsFromCluster($cluster, $hourly_events) {
$cluster_size = count($cluster);
$n = 0;
foreach ($cluster as $cluster_member) {
$event_id = $cluster_member->getEventID();
$offset = (($n / $cluster_size) * 100).'%';
$width = ((1 / $cluster_size) * 100).'%';
if (isset($hourly_events[$event_id])) {
$hourly_events[$event_id]['offset'] = $offset;
$hourly_events[$event_id]['width'] = $width;
}
$n++;
}
return $hourly_events;
}
// returns DateTime of each hour in the day
private function getHoursOfDay() {
$included_datetimes = array();
$day_datetime = $this->getDateTime();
$day_epoch = $day_datetime->format('U');
$day_datetime->modify('+1 day');
$next_day_epoch = $day_datetime->format('U');
$included_time = $day_epoch;
$included_datetime = $this->getDateTime();
while ($included_time < $next_day_epoch) {
$included_datetimes[] = clone $included_datetime;
$included_datetime->modify('+1 hour');
$included_time = $included_datetime->format('U');
}
return $included_datetimes;
}
private function getPrevDay() {
$prev = $this->getDateTime();
$prev->modify('-1 day');
return array(
$prev->format('Y'),
$prev->format('m'),
$prev->format('d'),
);
}
private function getNextDay() {
$next = $this->getDateTime();
$next->modify('+1 day');
return array(
$next->format('Y'),
$next->format('m'),
$next->format('d'),
);
}
private function getDateTime() {
$user = $this->user;
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$day = $this->day;
$month = $this->month;
$year = $this->year;
$date = new DateTime("{$year}-{$month}-{$day} ", $timezone);
return $date;
}
private function findTodayClusters() {
$events = msort($this->todayEvents, 'getEpochStart');
$clusters = array();
foreach ($events as $event) {
$destination_cluster_key = null;
$event_start = $event->getEpochStart() - (30 * 60);
$event_end = $event->getEpochEnd() + (30 * 60);
foreach ($clusters as $key => $cluster) {
foreach ($cluster as $clustered_event) {
$compare_event_start = $clustered_event->getEpochStart();
$compare_event_end = $clustered_event->getEpochEnd();
if ($event_start < $compare_event_end
&& $event_end > $compare_event_start) {
$destination_cluster_key = $key;
break;
}
}
}
if ($destination_cluster_key !== null) {
$clusters[$destination_cluster_key][] = $event;
} else {
$next_cluster = array();
$next_cluster[] = $event;
$clusters[] = $next_cluster;
}
}
return $clusters;
}
}
diff --git a/src/view/phui/calendar/PHUICalendarListView.php b/src/view/phui/calendar/PHUICalendarListView.php
index 4de84ce3fd..9f9bc86a80 100644
--- a/src/view/phui/calendar/PHUICalendarListView.php
+++ b/src/view/phui/calendar/PHUICalendarListView.php
@@ -1,192 +1,192 @@
<?php
final class PHUICalendarListView extends AphrontTagView {
private $events = array();
private $blankState;
private $view;
private function getView() {
return $this->view;
}
public function setView($view) {
$this->view = $view;
return $this;
}
public function addEvent(AphrontCalendarEventView $event) {
$this->events[] = $event;
return $this;
}
public function showBlankState($state) {
$this->blankState = $state;
return $this;
}
protected function getTagName() {
return 'div';
}
protected function getTagAttributes() {
require_celerity_resource('phui-calendar-css');
require_celerity_resource('phui-calendar-list-css');
return array('class' => 'phui-calendar-event-list');
}
protected function getTagContent() {
if (!$this->blankState && empty($this->events)) {
return '';
}
$singletons = array();
$allday = false;
foreach ($this->events as $event) {
$start_epoch = $event->getEpochStart();
if ($event->getIsAllDay()) {
$timelabel = pht('All Day');
} else {
$timelabel = phabricator_time(
$event->getEpochStart(),
$this->getUser());
}
if ($event->getViewerIsInvited()) {
$icon_color = 'green';
} else {
$icon_color = null;
}
$dot = id(new PHUIIconView())
- ->setIconFont($event->getIcon(), $icon_color)
+ ->setIcon($event->getIcon(), $icon_color)
->addClass('phui-calendar-list-item-icon');
$title = phutil_tag(
'span',
array(
'class' => 'phui-calendar-list-title',
),
$this->getEventTitle($event, $allday));
$time = phutil_tag(
'span',
array(
'class' => 'phui-calendar-list-time',
),
$timelabel);
$class = 'phui-calendar-list-item';
if ($event->getViewerIsInvited()) {
$class = $class.' phui-calendar-viewer-invited';
}
if ($event->getIsAllDay()) {
$class = $class.' all-day';
}
$tip = $this->getEventTooltip($event);
$tip_align = ($this->getView() == 'day') ? 'E' : 'N';
$content = javelin_tag(
'a',
array(
'href' => $event->getURI(),
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => $tip,
'size' => 200,
'align' => $tip_align,
),
),
array(
$dot,
$time,
$title,
));
$singletons[] = phutil_tag(
'li',
array(
'class' => $class,
),
$content);
}
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 getEventTitle($event) {
$class = 'phui-calendar-item';
return phutil_tag(
'span',
array(
'class' => $class,
),
$event->getName());
}
private function getEventTooltip(AphrontCalendarEventView $event) {
$time_pref = $this->getUser()
->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
Javelin::initBehavior('phabricator-tooltips');
$start = id(AphrontFormDateControlValue::newFromEpoch(
$this->getUser(),
$event->getEpochStart()));
$end = id(AphrontFormDateControlValue::newFromEpoch(
$this->getUser(),
$event->getEpochEnd()));
$start_date = $start->getDateTime()->format('m d Y');
$end_date = $end->getDateTime()->format('m d Y');
if ($event->getIsAllDay()) {
if ($start_date == $end_date) {
$tip = pht('All day');
} else {
$tip = pht(
'All day, %s - %s',
$start->getValueAsFormat('M j, Y'),
$end->getValueAsFormat('M j, Y'));
}
} else {
if ($start->getValueDate() == $end->getValueDate()) {
$tip = pht(
'%s - %s',
$start->getValueAsFormat($time_pref),
$end->getValueAsFormat($time_pref));
} else {
$tip = pht(
'%s - %s',
$start->getValueAsFormat('M j, Y, '.$time_pref),
$end->getValueAsFormat('M j, Y, '.$time_pref));
}
}
return $tip;
}
public function getIsViewerInvitedOnList() {
foreach ($this->events as $event) {
if ($event->getViewerIsInvited()) {
return true;
}
}
return false;
}
}
diff --git a/src/view/phui/calendar/PHUICalendarMonthView.php b/src/view/phui/calendar/PHUICalendarMonthView.php
index 0308f542e5..5efa4c1059 100644
--- a/src/view/phui/calendar/PHUICalendarMonthView.php
+++ b/src/view/phui/calendar/PHUICalendarMonthView.php
@@ -1,598 +1,598 @@
<?php
final class PHUICalendarMonthView extends AphrontView {
private $rangeStart;
private $rangeEnd;
private $day;
private $month;
private $year;
private $events = array();
private $browseURI;
private $image;
private $error;
public function setBrowseURI($browse_uri) {
$this->browseURI = $browse_uri;
return $this;
}
private function getBrowseURI() {
return $this->browseURI;
}
public function addEvent(AphrontCalendarEventView $event) {
$this->events[] = $event;
return $this;
}
public function setImage($uri) {
$this->image = $uri;
return $this;
}
public function setInfoView(PHUIInfoView $error) {
$this->error = $error;
return $this;
}
public function __construct(
$range_start,
$range_end,
$month,
$year,
$day = null) {
$this->rangeStart = $range_start;
$this->rangeEnd = $range_end;
$this->day = $day;
$this->month = $month;
$this->year = $year;
}
public function render() {
if (empty($this->user)) {
throw new PhutilInvalidStateException('setUser');
}
$events = msort($this->events, 'getEpochStart');
$days = $this->getDatesInMonth();
$cell_lists = array();
require_celerity_resource('phui-calendar-month-css');
foreach ($days as $day) {
$day_number = $day->format('j');
$class = 'phui-calendar-month-day';
$weekday = $day->format('w');
$day->setTime(0, 0, 0);
$day_start_epoch = $day->format('U');
$day_end_epoch = id(clone $day)->modify('+1 day')->format('U');
$list_events = array();
$all_day_events = array();
foreach ($events as $event) {
if ($event->getEpochStart() >= $day_end_epoch) {
break;
}
if ($event->getEpochStart() < $day_end_epoch &&
$event->getEpochEnd() > $day_start_epoch) {
if ($event->getIsAllDay()) {
$all_day_events[] = $event;
} else {
$list_events[] = $event;
}
}
}
$max_daily = 15;
$counter = 0;
$list = new PHUICalendarListView();
$list->setUser($this->user);
foreach ($all_day_events as $item) {
if ($counter <= $max_daily) {
$list->addEvent($item);
}
$counter++;
}
foreach ($list_events as $item) {
if ($counter <= $max_daily) {
$list->addEvent($item);
}
$counter++;
}
$uri = $this->getBrowseURI();
$uri = $uri.$day->format('Y').'/'.
$day->format('m').'/'.
$day->format('d').'/';
$cell_lists[] = array(
'list' => $list,
'date' => $day,
'uri' => $uri,
'count' => count($all_day_events) + count($list_events),
'class' => $class,
);
}
$rows = array();
$cell_lists_by_week = array_chunk($cell_lists, 7);
foreach ($cell_lists_by_week as $week_of_cell_lists) {
$cells = array();
$max_count = $this->getMaxDailyEventsForWeek($week_of_cell_lists);
foreach ($week_of_cell_lists as $cell_list) {
$cells[] = $this->getEventListCell($cell_list, $max_count);
}
$rows[] = phutil_tag('tr', array(), $cells);
$cells = array();
foreach ($week_of_cell_lists as $cell_list) {
$cells[] = $this->getDayNumberCell($cell_list);
}
$rows[] = phutil_tag('tr', array(), $cells);
}
$header = $this->getDayNamesHeader();
$table = phutil_tag(
'table',
array('class' => 'phui-calendar-view'),
array(
$header,
$rows,
));
$warnings = $this->getQueryRangeWarning();
$box = id(new PHUIObjectBoxView())
->setHeader($this->renderCalendarHeader($this->getDateTime()))
->appendChild($table)
->setFormErrors($warnings);
if ($this->error) {
$box->setInfoView($this->error);
}
return $box;
}
private function getMaxDailyEventsForWeek($week_of_cell_lists) {
$max_count = 0;
foreach ($week_of_cell_lists as $cell_list) {
if ($cell_list['count'] > $max_count) {
$max_count = $cell_list['count'];
}
}
return $max_count;
}
private function getEventListCell($event_list, $max_count = 0) {
$list = $event_list['list'];
$class = $event_list['class'];
$uri = $event_list['uri'];
$count = $event_list['count'];
$viewer_is_invited = $list->getIsViewerInvitedOnList();
$event_count_badge = $this->getEventCountBadge($count, $viewer_is_invited);
$cell_day_secret_link = $this->getHiddenDayLink($uri, $max_count, 125);
$cell_data_div = phutil_tag(
'div',
array(
'class' => 'phui-calendar-month-cell-div',
),
array(
$cell_day_secret_link,
$event_count_badge,
$list,
));
return phutil_tag(
'td',
array(
'class' => 'phui-calendar-month-event-list '.$class,
),
$cell_data_div);
}
private function getDayNumberCell($event_list) {
$class = $event_list['class'];
$date = $event_list['date'];
$cell_day_secret_link = null;
$week_number = null;
if ($date) {
$uri = $event_list['uri'];
$cell_day_secret_link = $this->getHiddenDayLink($uri, 0, 25);
$cell_day = phutil_tag(
'a',
array(
'class' => 'phui-calendar-date-number',
'href' => $uri,
),
$date->format('j'));
if ($date->format('w') == 1) {
$week_number = phutil_tag(
'a',
array(
'class' => 'phui-calendar-week-number',
'href' => $uri,
),
$date->format('W'));
}
} else {
$cell_day = null;
}
if ($date && $date->format('j') == $this->day &&
$date->format('m') == $this->month) {
$today_class = 'phui-calendar-today-slot phui-calendar-today';
} else {
$today_class = 'phui-calendar-today-slot';
}
if ($this->isDateInCurrentWeek($date)) {
$today_class .= ' phui-calendar-this-week';
}
$last_week_day = 6;
if ($date->format('w') == $last_week_day) {
$today_class .= ' last-weekday';
}
$today_slot = phutil_tag(
'div',
array(
'class' => $today_class,
),
null);
$cell_div = phutil_tag(
'div',
array(
'class' => 'phui-calendar-month-cell-div',
),
array(
$cell_day_secret_link,
$week_number,
$cell_day,
$today_slot,
));
return phutil_tag(
'td',
array(
'class' => 'phui-calendar-date-number-container '.$class,
),
$cell_div);
}
private function isDateInCurrentWeek($date) {
list($week_start_date, $week_end_date) = $this->getThisWeekRange();
if ($date->format('U') < $week_end_date->format('U') &&
$date->format('U') >= $week_start_date->format('U')) {
return true;
}
return false;
}
private function getEventCountBadge($count, $viewer_is_invited) {
$class = 'phui-calendar-month-count-badge';
if ($viewer_is_invited) {
$class = $class.' viewer-invited-day-badge';
}
$event_count = null;
if ($count > 0) {
$event_count = phutil_tag(
'div',
array(
'class' => $class,
),
$count);
}
return phutil_tag(
'div',
array(
'class' => 'phui-calendar-month-event-count',
),
$event_count);
}
private function getHiddenDayLink($uri, $count, $max_height) {
// approximately the height of the tallest cell
$height = 18 * $count + 5;
$height = ($height > $max_height) ? $height : $max_height;
$height_style = 'height: '.$height.'px';
return phutil_tag(
'a',
array(
'class' => 'phui-calendar-month-secret-link',
'style' => $height_style,
'href' => $uri,
),
null);
}
private function getDayNamesHeader() {
list($week_start, $week_end) = $this->getWeekStartAndEnd();
$weekday_names = array(
$this->getDayHeader(pht('Sun'), pht('Sunday'), true),
$this->getDayHeader(pht('Mon'), pht('Monday')),
$this->getDayHeader(pht('Tue'), pht('Tuesday')),
$this->getDayHeader(pht('Wed'), pht('Wednesday')),
$this->getDayHeader(pht('Thu'), pht('Thursday')),
$this->getDayHeader(pht('Fri'), pht('Friday')),
$this->getDayHeader(pht('Sat'), pht('Saturday'), true),
);
$sorted_weekday_names = array();
for ($i = $week_start; $i < ($week_start + 7); $i++) {
$sorted_weekday_names[] = $weekday_names[$i % 7];
}
return phutil_tag(
'tr',
array('class' => 'phui-calendar-day-of-week-header'),
$sorted_weekday_names);
}
private function getDayHeader($short, $long, $is_weekend = false) {
$class = null;
if ($is_weekend) {
$class = 'weekend-day-header';
}
$day = array();
$day[] = phutil_tag(
'span',
array(
'class' => 'long-weekday-name',
),
$long);
$day[] = phutil_tag(
'span',
array(
'class' => 'short-weekday-name',
),
$short);
return phutil_tag(
'th',
array(
'class' => $class,
),
$day);
}
private function renderCalendarHeader(DateTime $date) {
$button_bar = null;
// check for a browseURI, which means we need "fancy" prev / next UI
$uri = $this->getBrowseURI();
if ($uri) {
list($prev_year, $prev_month) = $this->getPrevYearAndMonth();
$prev_uri = $uri.$prev_year.'/'.$prev_month.'/';
list($next_year, $next_month) = $this->getNextYearAndMonth();
$next_uri = $uri.$next_year.'/'.$next_month.'/';
$button_bar = new PHUIButtonBarView();
$left_icon = id(new PHUIIconView())
- ->setIconFont('fa-chevron-left bluegrey');
+ ->setIcon('fa-chevron-left bluegrey');
$left = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($prev_uri)
->setTitle(pht('Previous Month'))
->setIcon($left_icon);
$right_icon = id(new PHUIIconView())
- ->setIconFont('fa-chevron-right bluegrey');
+ ->setIcon('fa-chevron-right bluegrey');
$right = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY)
->setHref($next_uri)
->setTitle(pht('Next Month'))
->setIcon($right_icon);
$button_bar->addButton($left);
$button_bar->addButton($right);
}
$header = id(new PHUIHeaderView())
->setHeader($date->format('F Y'));
if ($button_bar) {
$header->setButtonBar($button_bar);
}
if ($this->image) {
$header->setImage($this->image);
}
return $header;
}
private function getQueryRangeWarning() {
$errors = array();
$range_start_epoch = null;
$range_end_epoch = null;
if ($this->rangeStart) {
$range_start_epoch = $this->rangeStart->getEpoch();
}
if ($this->rangeEnd) {
$range_end_epoch = $this->rangeEnd->getEpoch();
}
$month_start = $this->getDateTime();
$month_end = id(clone $month_start)->modify('+1 month');
$month_start = $month_start->format('U');
$month_end = $month_end->format('U') - 1;
if (($range_start_epoch != null &&
$range_start_epoch < $month_end &&
$range_start_epoch > $month_start) ||
($range_end_epoch != null &&
$range_end_epoch < $month_end &&
$range_end_epoch > $month_start)) {
$errors[] = pht('Part of the month is out of range');
}
if (($range_end_epoch != null &&
$range_end_epoch < $month_start) ||
($range_start_epoch != null &&
$range_start_epoch > $month_end)) {
$errors[] = pht('Month is out of query range');
}
return $errors;
}
private function getNextYearAndMonth() {
$next = $this->getDateTime();
$next->modify('+1 month');
return array(
$next->format('Y'),
$next->format('m'),
);
}
private function getPrevYearAndMonth() {
$prev = $this->getDateTime();
$prev->modify('-1 month');
return array(
$prev->format('Y'),
$prev->format('m'),
);
}
/**
* Return a DateTime object representing the first moment in each day in the
* month, according to the user's locale.
*
* @return list List of DateTimes, one for each day.
*/
private function getDatesInMonth() {
$user = $this->user;
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$month = $this->month;
$year = $this->year;
list($next_year, $next_month) = $this->getNextYearAndMonth();
$end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone);
list($start_of_week, $end_of_week) = $this->getWeekStartAndEnd();
$days_in_month = id(clone $end_date)->modify('-1 day')->format('d');
$first_month_day_date = new DateTime("{$year}-{$month}-01", $timezone);
$last_month_day_date = id(clone $end_date)->modify('-1 day');
$first_weekday_of_month = $first_month_day_date->format('w');
$last_weekday_of_month = $last_month_day_date->format('w');
$day_date = id(clone $first_month_day_date);
$num_days_display = $days_in_month;
if ($start_of_week !== $first_weekday_of_month) {
$interim_start_num = ($first_weekday_of_month + 7 - $start_of_week) % 7;
$num_days_display += $interim_start_num;
$day_date->modify('-'.$interim_start_num.' days');
}
if ($end_of_week !== $last_weekday_of_month) {
$interim_end_day_num = ($end_of_week - $last_weekday_of_month + 7) % 7;
$num_days_display += $interim_end_day_num;
$end_date->modify('+'.$interim_end_day_num.' days');
}
$days = array();
for ($day = 1; $day <= $num_days_display; $day++) {
$day_epoch = $day_date->format('U');
$end_epoch = $end_date->format('U');
if ($day_epoch >= $end_epoch) {
break;
} else {
$days[] = clone $day_date;
}
$day_date->modify('+1 day');
}
return $days;
}
private function getTodayMidnight() {
$viewer = $this->getUser();
$today = new DateTime('@'.time());
$today->setTimeZone($viewer->getTimeZone());
$today->setTime(0, 0, 0);
return $today;
}
private function getThisWeekRange() {
list($week_start, $week_end) = $this->getWeekStartAndEnd();
$today = $this->getTodayMidnight();
$date_weekday = $today->format('w');
$days_from_week_start = ($date_weekday + 7 - $week_start) % 7;
$days_to_week_end = 7 - $days_from_week_start;
$modify = '-'.$days_from_week_start.' days';
$week_start_date = id(clone $today)->modify($modify);
$modify = '+'.$days_to_week_end.' days';
$week_end_date = id(clone $today)->modify($modify);
return array($week_start_date, $week_end_date);
}
private function getWeekStartAndEnd() {
$preferences = $this->user->loadPreferences();
$pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY;
$week_start = $preferences->getPreference($pref_week_start, 0);
$week_end = ($week_start + 6) % 7;
return array($week_start, $week_end);
}
private function getDateTime() {
$user = $this->user;
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$month = $this->month;
$year = $this->year;
$date = new DateTime("{$year}-{$month}-01 ", $timezone);
return $date;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Wed, Apr 30, 8:01 PM (1 d, 4 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f5/89/4d608a5079f66157abca5e78a79d
Default Alt Text
(1 MB)

Event Timeline