diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 4e001f9964..7a7b02df22 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -17,7 +17,7 @@ celerity_register_resource_map(array( ), 'aphront-form-view-css' => array( - 'path' => '/res/51ec6383/rsrc/css/aphront/form-view.css', + 'path' => '/res/75636a53/rsrc/css/aphront/form-view.css', 'type' => 'css', 'requires' => array( diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0e23449164..4e37c3e090 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -117,11 +117,14 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list', 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail', 'PhabricatorMetaMTASendController' => 'applications/metamta/controller/send', + 'PhabricatorObjectHandle' => 'applications/phid/handle', + 'PhabricatorObjectHandleData' => 'applications/phid/handle/data', 'PhabricatorPHID' => 'applications/phid/storage/phid', 'PhabricatorPHIDAllocateController' => 'applications/phid/controller/allocate', 'PhabricatorPHIDController' => 'applications/phid/controller/base', 'PhabricatorPHIDDAO' => 'applications/phid/storage/base', 'PhabricatorPHIDListController' => 'applications/phid/controller/list', + 'PhabricatorPHIDLookupController' => 'applications/phid/controller/lookup', 'PhabricatorPHIDType' => 'applications/phid/storage/type', 'PhabricatorPHIDTypeEditController' => 'applications/phid/controller/typeedit', 'PhabricatorPHIDTypeListController' => 'applications/phid/controller/typelist', @@ -243,6 +246,7 @@ phutil_register_library_map(array( 'PhabricatorPHIDController' => 'PhabricatorController', 'PhabricatorPHIDDAO' => 'PhabricatorLiskDAO', 'PhabricatorPHIDListController' => 'PhabricatorPHIDController', + 'PhabricatorPHIDLookupController' => 'PhabricatorPHIDController', 'PhabricatorPHIDType' => 'PhabricatorPHIDDAO', 'PhabricatorPHIDTypeEditController' => 'PhabricatorPHIDController', 'PhabricatorPHIDTypeListController' => 'PhabricatorPHIDController', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index faf467307d..c61eec3dc2 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -59,7 +59,8 @@ class AphrontDefaultApplicationConfiguration '(?download)/(?[^/]+)/' => 'PhabricatorFileViewController', ), '/phid/' => array( - '$' => 'PhabricatorPHIDListController', + '$' => 'PhabricatorPHIDLookupController', + 'list/$' => 'PhabricatorPHIDListController', 'type/$' => 'PhabricatorPHIDTypeListController', 'type/edit/(?:(?\d+)/)?$' => 'PhabricatorPHIDTypeEditController', 'new/$' => 'PhabricatorPHIDAllocateController', diff --git a/src/applications/files/storage/file/PhabricatorFile.php b/src/applications/files/storage/file/PhabricatorFile.php index 37929f2509..9c3a94ce38 100644 --- a/src/applications/files/storage/file/PhabricatorFile.php +++ b/src/applications/files/storage/file/PhabricatorFile.php @@ -167,4 +167,8 @@ class PhabricatorFile extends PhabricatorFileDAO { return $data; } + public function getViewURI() { + return PhabricatorFileURI::getViewURIForPHID($this->getPHID()); + } + } diff --git a/src/applications/files/storage/file/__init__.php b/src/applications/files/storage/file/__init__.php index 26394989c8..8328a1bc7b 100644 --- a/src/applications/files/storage/file/__init__.php +++ b/src/applications/files/storage/file/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/files/storage/base'); phutil_require_module('phabricator', 'applications/files/storage/storageblob'); +phutil_require_module('phabricator', 'applications/files/uri'); phutil_require_module('phabricator', 'applications/phid/storage/phid'); phutil_require_module('phutil', 'filesystem'); diff --git a/src/applications/phid/controller/base/PhabricatorPHIDController.php b/src/applications/phid/controller/base/PhabricatorPHIDController.php index 4c190e9ab7..0b5b089234 100644 --- a/src/applications/phid/controller/base/PhabricatorPHIDController.php +++ b/src/applications/phid/controller/base/PhabricatorPHIDController.php @@ -26,9 +26,13 @@ abstract class PhabricatorPHIDController extends PhabricatorController { $page->setTitle(idx($data, 'title')); $page->setTabs( array( - 'phids' => array( + 'lookup' => array( 'href' => '/phid/', - 'name' => 'PHIDs', + 'name' => 'PHID Lookup', + ), + 'phids' => array( + 'href' => '/phid/list/', + 'name' => 'PHID List', ), 'types' => array( 'href' => '/phid/type/', diff --git a/src/applications/phid/controller/list/PhabricatorPHIDListController.php b/src/applications/phid/controller/list/PhabricatorPHIDListController.php index 33803cc4d0..8e1a0dc569 100644 --- a/src/applications/phid/controller/list/PhabricatorPHIDListController.php +++ b/src/applications/phid/controller/list/PhabricatorPHIDListController.php @@ -47,9 +47,13 @@ class PhabricatorPHIDListController $panel->setHeader('PHIDs'); $panel->setCreateButton('Allocate New PHID', '/phid/new/'); - return $this->buildStandardPageResponse($panel, array( - 'title' => 'PHIDs', - 'tab' => 'phids', + return $this->buildStandardPageResponse( + array( + $panel, + ), + array( + 'title' => 'PHIDs', + 'tab' => 'phids', )); } diff --git a/src/applications/phid/controller/lookup/PhabricatorPHIDLookupController.php b/src/applications/phid/controller/lookup/PhabricatorPHIDLookupController.php new file mode 100644 index 0000000000..0578961e6b --- /dev/null +++ b/src/applications/phid/controller/lookup/PhabricatorPHIDLookupController.php @@ -0,0 +1,111 @@ +getRequest(); + if ($request->isFormPost()) { + $phids = preg_split('/[\s,]+/', $request->getStr('phids')); + $phids = array_filter($phids); + if ($phids) { + $handles = id(new PhabricatorObjectHandleData($phids)) + ->loadHandles(); + + $rows = array(); + foreach ($handles as $handle) { + if ($handle->getURI()) { + $link = phutil_render_tag( + 'a', + array( + 'href' => $handle->getURI(), + ), + phutil_escape_html($handle->getURI())); + } else { + $link = null; + } + + $rows[] = array( + phutil_escape_html($handle->getPHID()), + phutil_escape_html($handle->getType()), + phutil_escape_html($handle->getName()), + phutil_escape_html($handle->getEmail()), + $link, + ); + } + + $table = new AphrontTableView($rows); + $table->setHeaders( + array( + 'PHID', + 'Type', + 'Name', + 'Email', + 'URI', + )); + $table->setColumnClasses( + array( + null, + null, + null, + null, + 'wide', + )); + + $panel = new AphrontPanelView(); + $panel->setHeader('PHID Handles'); + $panel->appendChild($table); + + return $this->buildStandardPageResponse( + $panel, + array( + 'title' => 'PHID Lookup Results', + )); + } + } + + $lookup_form = new AphrontFormView(); + $lookup_form + ->setAction('/phid/') + ->appendChild( + id(new AphrontFormTextAreaControl()) + ->setName('phids') +// ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) TODO + ->setCaption('Enter PHIDs separated by spaces or commas.')) + ->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue('Lookup PHIDs')); + + $lookup_panel = new AphrontPanelView(); + $lookup_panel->setHeader('Lookup PHIDs'); + $lookup_panel->appendChild($lookup_form); + $lookup_panel->setWidth(AphrontPanelView::WIDTH_WIDE); + + return $this->buildStandardPageResponse( + array( + $lookup_panel, + ), + array( + 'title' => 'PHID Lookup', + 'tab' => 'lookup', + )); + } + +} diff --git a/src/applications/phid/controller/lookup/__init__.php b/src/applications/phid/controller/lookup/__init__.php new file mode 100644 index 0000000000..b5bb6da8f4 --- /dev/null +++ b/src/applications/phid/controller/lookup/__init__.php @@ -0,0 +1,20 @@ +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() { + return $this->name; + } + + public function setType($type) { + $this->type = $type; + return $this; + } + + public function getType() { + return $this->type; + } + + public function setEmail($email) { + $this->email = $email; + return $this; + } + + public function getEmail() { + return $this->email; + } + + + +} diff --git a/src/applications/phid/handle/__init__.php b/src/applications/phid/handle/__init__.php new file mode 100644 index 0000000000..e66e9c70a0 --- /dev/null +++ b/src/applications/phid/handle/__init__.php @@ -0,0 +1,10 @@ +phids = $phids; + } + + public function loadHandles() { + + $types = array(); + foreach ($this->phids as $phid) { + $type = $this->lookupType($phid); + $types[$type][] = $phid; + } + + $handles = array(); + + foreach ($types as $type => $phids) { + switch ($type) { + case 'USER': + $class = 'PhabricatorUser'; + PhutilSymbolLoader::loadClass($class); + $object = newv($class, array()); + + $users = $object->loadAllWhere('phid IN (%Ls)', $phids); + $users = mpull($users, null, 'getPHID'); + + foreach ($phids as $phid) { + $handle = new PhabricatorObjectHandle(); + $handle->setPHID($phid); + if (empty($users[$phid])) { + $handle->setType(self::TYPE_UNKNOWN); + $handle->setName('Unknown User'); + } else { + $user = $users[$phid]; + $handle->setType($type); + $handle->setName($user->getUsername()); + $handle->setURI('/p/'.$user->getUsername().'/'); + $handle->setEmail($user->getEmail()); + } + $handles[$phid] = $handle; + } + break; + case 'FILE': + $class = 'PhabricatorFile'; + PhutilSymbolLoader::loadClass($class); + $object = newv($class, array()); + + $files = $object->loadAllWhere('phid IN (%Ls)', $phids); + $files = mpull($files, null, 'getPHID'); + + foreach ($phids as $phid) { + $handle = new PhabricatorObjectHandle(); + $handle->setPHID($phid); + if (empty($files[$phid])) { + $handle->setType(self::TYPE_UNKNOWN); + $handle->setName('Unknown File'); + } else { + $file = $files[$phid]; + $handle->setType($type); + $handle->setName($file->getName()); + $handle->setURI($file->getViewURI()); + } + $handles[$phid] = $handle; + } + break; + default: + foreach ($phids as $phid) { + $handle = new PhabricatorObjectHandle(); + $handle->setType($type); + $handle->setPHID($phid); + $handle->setName('Unknown Object'); + $handles[$phid] = $handle; + } + break; + } + } + + return $handles; + } + + private function lookupType($phid) { + $matches = null; + if (preg_match('/^PHID-([^-]{4})-/', $phid, $matches)) { + return $matches[1]; + } + return self::TYPE_UNKNOWN; + } + +} diff --git a/src/applications/phid/handle/data/__init__.php b/src/applications/phid/handle/data/__init__.php new file mode 100644 index 0000000000..b6578834e2 --- /dev/null +++ b/src/applications/phid/handle/data/__init__.php @@ -0,0 +1,15 @@ +