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
|
|
|
}
|
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
public function newResultObject() {
|
|
|
|
return new PhabricatorFile();
|
|
|
|
}
|
2013-05-31 19:51:05 +02:00
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
protected function buildCustomSearchFields() {
|
|
|
|
return array(
|
|
|
|
id(new PhabricatorSearchUsersField())
|
|
|
|
->setKey('authorPHIDs')
|
|
|
|
->setAliases(array('author', 'authors'))
|
|
|
|
->setLabel(pht('Authors')),
|
|
|
|
id(new PhabricatorSearchThreeStateField())
|
|
|
|
->setKey('explicit')
|
|
|
|
->setLabel(pht('Upload Source'))
|
|
|
|
->setOptions(
|
|
|
|
pht('(Show All)'),
|
|
|
|
pht('Show Only Manually Uploaded Files'),
|
|
|
|
pht('Hide Manually Uploaded Files')),
|
|
|
|
id(new PhabricatorSearchDateField())
|
|
|
|
->setKey('createdStart')
|
|
|
|
->setLabel(pht('Created After')),
|
|
|
|
id(new PhabricatorSearchDateField())
|
|
|
|
->setKey('createdEnd')
|
|
|
|
->setLabel(pht('Created Before')),
|
|
|
|
);
|
2013-05-31 19:51:05 +02:00
|
|
|
}
|
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
public function buildQueryFromParameters(array $map) {
|
2015-03-14 16:29:12 +01:00
|
|
|
$query = id(new PhabricatorFileQuery());
|
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
if ($map['authorPHIDs']) {
|
|
|
|
$query->withAuthorPHIDs($map['authorPHIDs']);
|
2015-03-14 16:29:12 +01:00
|
|
|
}
|
2013-05-31 19:51:05 +02:00
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
if ($map['explicit'] !== null) {
|
|
|
|
$query->showOnlyExplicitUploads($map['explicit']);
|
2013-05-31 19:51:05 +02:00
|
|
|
}
|
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
if ($map['createdStart']) {
|
|
|
|
$query->withDateCreatedAfter($map['createdStart']);
|
2013-05-31 19:51:05 +02:00
|
|
|
}
|
|
|
|
|
2015-06-07 16:32:09 +02:00
|
|
|
if ($map['createdEnd']) {
|
|
|
|
$query->withDateCreatedBefore($map['createdEnd']);
|
2013-05-31 19:51:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|