2013-08-05 14:10:41 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorFeedSearchEngine
|
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
2014-06-12 13:22:20 -07:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
|
return pht('Feed Stories');
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 14:10:41 -07:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
|
'userPHIDs',
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 11:52:29 -07:00
|
|
|
$this->readUsersFromRequest($request, 'users'));
|
2013-08-05 14:10:41 -07:00
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
|
'projectPHIDs',
|
|
|
|
|
array_values($request->getArr('projectPHIDs')));
|
|
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
|
'viewerProjects',
|
|
|
|
|
$request->getBool('viewerProjects'));
|
|
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
|
$query = id(new PhabricatorFeedQuery());
|
|
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
|
|
|
|
|
|
$user_phids = $saved->getParameter('userPHIDs');
|
|
|
|
|
if ($user_phids) {
|
|
|
|
|
$phids[] = $user_phids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$proj_phids = $saved->getParameter('projectPHIDs');
|
|
|
|
|
if ($proj_phids) {
|
|
|
|
|
$phids[] = $proj_phids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$viewer_projects = $saved->getParameter('viewerProjects');
|
|
|
|
|
if ($viewer_projects) {
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
$projects = id(new PhabricatorProjectQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withMemberPHIDs(array($viewer->getPHID()))
|
|
|
|
|
->execute();
|
|
|
|
|
$phids[] = mpull($projects, 'getPHID');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$phids = array_mergev($phids);
|
|
|
|
|
if ($phids) {
|
|
|
|
|
$query->setFilterPHIDs($phids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
|
AphrontFormView $form,
|
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
|
|
|
|
|
$user_phids = $saved_query->getParameter('userPHIDs', array());
|
|
|
|
|
$proj_phids = $saved_query->getParameter('projectPHIDs', array());
|
|
|
|
|
|
|
|
|
|
$phids = array_merge($user_phids, $proj_phids);
|
|
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
|
->setViewer($this->requireViewer())
|
|
|
|
|
->withPHIDs($phids)
|
|
|
|
|
->execute();
|
2013-10-07 12:51:24 -07:00
|
|
|
$user_handles = array_select_keys($handles, $user_phids);
|
|
|
|
|
$proj_handles = array_select_keys($handles, $proj_phids);
|
2013-08-05 14:10:41 -07:00
|
|
|
|
|
|
|
|
$viewer_projects = $saved_query->getParameter('viewerProjects');
|
|
|
|
|
|
|
|
|
|
$form
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 11:52:29 -07:00
|
|
|
->setName('users')
|
2013-08-05 14:10:41 -07:00
|
|
|
->setLabel(pht('Include Users'))
|
2013-10-07 12:51:24 -07:00
|
|
|
->setValue($user_handles))
|
2013-08-05 14:10:41 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
|
->setDatasource('/typeahead/common/projects/')
|
|
|
|
|
->setName('projectPHIDs')
|
|
|
|
|
->setLabel(pht('Include Projects'))
|
2013-10-07 12:51:24 -07:00
|
|
|
->setValue($proj_handles))
|
2013-08-05 14:10:41 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
|
->addCheckbox(
|
|
|
|
|
'viewerProjects',
|
|
|
|
|
1,
|
|
|
|
|
pht('Include stories about projects I am a member of.'),
|
|
|
|
|
$viewer_projects));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
|
return '/feed/'.$path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBuiltinQueryNames() {
|
|
|
|
|
$names = array(
|
|
|
|
|
'all' => pht('All Stories'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
|
$names['projects'] = pht('Projects');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
|
case 'all':
|
|
|
|
|
return $query;
|
|
|
|
|
case 'projects':
|
|
|
|
|
return $query->setParameter('viewerProjects', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 08:49:32 -07:00
|
|
|
protected function renderResultList(
|
2014-05-08 08:24:47 -07:00
|
|
|
array $objects,
|
2014-05-08 08:40:59 -07:00
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
|
array $handles) {
|
2014-05-08 08:24:47 -07:00
|
|
|
|
|
|
|
|
$builder = new PhabricatorFeedBuilder($objects);
|
|
|
|
|
$builder->setShowHovercards(true);
|
|
|
|
|
$builder->setUser($this->requireViewer());
|
|
|
|
|
$view = $builder->buildView();
|
|
|
|
|
|
|
|
|
|
return phutil_tag_div('phabricator-feed-frame', $view);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 14:10:41 -07:00
|
|
|
}
|