mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-15 11:22:40 +01:00
dcc6997793
Summary: Ref T4420. Modernize users. Test Plan: - Edited "Commit Authors" on Audit search. - Edited "Created By" on calendar search. - Edited "invited" on calendar search. - Edited "To" on "New conpherence message". - Edited user on "Add user to conpherence thread". - Edited "Authors" on countdown search. - Edited "Author" on differential search. - Edited "Responsible users" on differential search. - Edited "Owner" on Diffusion lint search. - Edited "include users" on Feed search. - Edited "Authors" on file search. - Edited "Authors" on Herald rule search. - Edited a couple of user-selecting Herald fields on rules. - Edited "user" on legalpad signature exemption. - Edited "creator" on legalpad search. - Edited "contributors" on legalpad search. - Edited "signers" on legalpad signature search. - Edited "Authors" on macro search. - Edited "Reassign/claim" on task detail. - Edited "assigned to" on task edit. - Edited "assigned to", "users projects", "authors" on task search. - Edited "creators" on oauthserver. - Edited "authors" on paste search. - Edited "actors" and "users" on activity log search. - Edited "authors" on pholio search. - Edited "users" on phrequent search. - Edited "authors", "answered by" on Ponder search. - Edited "add members" on project membership editor. - Edited "members" on project search. - Edited "pushers" on releeph product edit. - Edited "requestors" on releeph request search. - Edited "pushers" on diffusion push log. - Edited "authors", "owners", "subscribers" on global search. - Edited "authors" on slowvote search. - Edited users in custom policy. - Grepped for "common/authors", no hits. - Grepped for "common/users", no (relevant) hits. - Grepped for "common/accounts", no (relevant) hits. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9885
189 lines
4.9 KiB
PHP
189 lines
4.9 KiB
PHP
<?php
|
|
|
|
final class PhabricatorFileSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
public function getResultTypeDescription() {
|
|
return pht('Files');
|
|
}
|
|
|
|
public function getApplicationClassName() {
|
|
return 'PhabricatorApplicationFiles';
|
|
}
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
$saved = new PhabricatorSavedQuery();
|
|
$saved->setParameter(
|
|
'authorPHIDs',
|
|
$this->readUsersFromRequest($request, 'authors'));
|
|
|
|
$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) {
|
|
$query = id(new PhabricatorFileQuery())
|
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
|
|
|
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) {
|
|
|
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
|
$author_handles = id(new PhabricatorHandleQuery())
|
|
->setViewer($this->requireViewer())
|
|
->withPHIDs($phids)
|
|
->execute();
|
|
|
|
$explicit = $saved_query->getParameter('explicit');
|
|
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
|
->setName('authors')
|
|
->setLabel(pht('Authors'))
|
|
->setValue($author_handles))
|
|
->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;
|
|
}
|
|
|
|
public function getBuiltinQueryNames() {
|
|
$names = array();
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
$names['authored'] = pht('Authored');
|
|
}
|
|
|
|
$names += array(
|
|
'all' => pht('All'),
|
|
);
|
|
|
|
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);
|
|
}
|
|
|
|
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)
|
|
->addIcon('none', phutil_format_bytes($file->getByteSize()));
|
|
|
|
$ttl = $file->getTTL();
|
|
if ($ttl !== null) {
|
|
$item->addIcon('blame', pht('Temporary'));
|
|
}
|
|
|
|
if (isset($highlighted_ids[$id])) {
|
|
$item->setEffect('highlighted');
|
|
}
|
|
|
|
$list_view->addItem($item);
|
|
}
|
|
|
|
$list_view->appendChild(id(new PhabricatorGlobalUploadTargetView())
|
|
->setUser($viewer));
|
|
|
|
return $list_view;
|
|
}
|
|
|
|
}
|