2013-05-31 19:51:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorFileSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Files');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorFilesApplication';
|
2014-05-08 19:08:37 +02:00
|
|
|
}
|
|
|
|
|
2013-05-31 19:51:05 +02:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
$saved->setParameter(
|
|
|
|
'authorPHIDs',
|
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 20:52:29 +02:00
|
|
|
$this->readUsersFromRequest($request, 'authors'));
|
2013-05-31 19:51:05 +02:00
|
|
|
|
|
|
|
$saved->setParameter('explicit', $request->getBool('explicit'));
|
|
|
|
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
|
|
|
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
2015-03-14 16:29:12 +01:00
|
|
|
$query = id(new PhabricatorFileQuery());
|
|
|
|
|
|
|
|
$author_phids = $saved->getParameter('authorPHIDs', array());
|
|
|
|
if ($author_phids) {
|
|
|
|
$query->withAuthorPHIDs($author_phids);
|
|
|
|
}
|
2013-05-31 19:51:05 +02:00
|
|
|
|
|
|
|
if ($saved->getParameter('explicit')) {
|
|
|
|
$query->showOnlyExplicitUploads(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
|
2015-03-31 23:10:55 +02:00
|
|
|
$author_phids = $saved_query->getParameter('authorPHIDs', array());
|
2013-05-31 19:51:05 +02:00
|
|
|
$explicit = $saved_query->getParameter('explicit');
|
|
|
|
|
|
|
|
$form
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2013-05-31 19:51:05 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2013-05-31 19:51:05 +02:00
|
|
|
->setName('authors')
|
|
|
|
->setLabel(pht('Authors'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($author_phids))
|
2013-05-31 19:51:05 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
->addCheckbox(
|
|
|
|
'explicit',
|
|
|
|
1,
|
|
|
|
pht('Show only manually uploaded files.'),
|
|
|
|
$explicit));
|
|
|
|
|
|
|
|
$this->buildDateRange(
|
|
|
|
$form,
|
|
|
|
$saved_query,
|
|
|
|
'createdStart',
|
|
|
|
pht('Created After'),
|
|
|
|
'createdEnd',
|
|
|
|
pht('Created Before'));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/file/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2013-05-31 19:51:05 +02:00
|
|
|
$names = array();
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
$names['authored'] = pht('Authored');
|
|
|
|
}
|
|
|
|
|
|
|
|
$names += array(
|
2014-07-23 02:03:09 +02:00
|
|
|
'all' => pht('All'),
|
2013-05-31 19:51:05 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
case 'authored':
|
|
|
|
$author_phid = array($this->requireViewer()->getPHID());
|
|
|
|
return $query
|
|
|
|
->setParameter('authorPHIDs', $author_phid)
|
|
|
|
->setParameter('explicit', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-08 19:08:37 +02:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $files,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
return mpull($files, 'getAuthorPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $files,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
|
|
|
|
assert_instances_of($files, 'PhabricatorFile');
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request) {
|
|
|
|
$highlighted_ids = $request->getStrList('h');
|
|
|
|
} else {
|
|
|
|
$highlighted_ids = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$highlighted_ids = array_fill_keys($highlighted_ids, true);
|
|
|
|
|
|
|
|
$list_view = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$id = $file->getID();
|
|
|
|
$phid = $file->getPHID();
|
|
|
|
$name = $file->getName();
|
|
|
|
$file_uri = $this->getApplicationURI("/info/{$phid}/");
|
|
|
|
|
|
|
|
$date_created = phabricator_date($file->getDateCreated(), $viewer);
|
|
|
|
$author_phid = $file->getAuthorPHID();
|
|
|
|
if ($author_phid) {
|
|
|
|
$author_link = $handles[$author_phid]->renderLink();
|
|
|
|
$uploaded = pht('Uploaded by %s on %s', $author_link, $date_created);
|
|
|
|
} else {
|
|
|
|
$uploaded = pht('Uploaded on %s', $date_created);
|
|
|
|
}
|
|
|
|
|
|
|
|
$item = id(new PHUIObjectItemView())
|
|
|
|
->setObject($file)
|
|
|
|
->setObjectName("F{$id}")
|
|
|
|
->setHeader($name)
|
|
|
|
->setHref($file_uri)
|
|
|
|
->addAttribute($uploaded)
|
2014-07-13 04:03:17 +02:00
|
|
|
->addIcon('none', phutil_format_bytes($file->getByteSize()));
|
2014-05-08 19:08:37 +02:00
|
|
|
|
|
|
|
$ttl = $file->getTTL();
|
|
|
|
if ($ttl !== null) {
|
|
|
|
$item->addIcon('blame', pht('Temporary'));
|
|
|
|
}
|
|
|
|
|
2015-03-15 19:37:05 +01:00
|
|
|
if ($file->getIsPartial()) {
|
|
|
|
$item->addIcon('fa-exclamation-triangle orange', pht('Partial'));
|
|
|
|
}
|
|
|
|
|
2014-05-08 19:08:37 +02:00
|
|
|
if (isset($highlighted_ids[$id])) {
|
|
|
|
$item->setEffect('highlighted');
|
|
|
|
}
|
|
|
|
|
|
|
|
$list_view->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
$list_view->appendChild(id(new PhabricatorGlobalUploadTargetView())
|
|
|
|
->setUser($viewer));
|
|
|
|
|
|
|
|
return $list_view;
|
|
|
|
}
|
|
|
|
|
2013-05-31 19:51:05 +02:00
|
|
|
}
|