Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15331341
D13175.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D13175.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2530,6 +2530,7 @@
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
'PhabricatorSearchSpacesField' => 'applications/search/field/PhabricatorSearchSpacesField.php',
'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php',
+ 'PhabricatorSearchThreeStateField' => 'applications/search/field/PhabricatorSearchThreeStateField.php',
'PhabricatorSearchTokenizerField' => 'applications/search/field/PhabricatorSearchTokenizerField.php',
'PhabricatorSearchUsersField' => 'applications/search/field/PhabricatorSearchUsersField.php',
'PhabricatorSearchWorker' => 'applications/search/worker/PhabricatorSearchWorker.php',
@@ -6031,6 +6032,7 @@
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchSpacesField' => 'PhabricatorSearchTokenizerField',
'PhabricatorSearchStringListField' => 'PhabricatorSearchField',
+ 'PhabricatorSearchThreeStateField' => 'PhabricatorSearchField',
'PhabricatorSearchTokenizerField' => 'PhabricatorSearchField',
'PhabricatorSearchUsersField' => 'PhabricatorSearchTokenizerField',
'PhabricatorSearchWorker' => 'PhabricatorWorker',
diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php
--- a/src/applications/files/query/PhabricatorFileQuery.php
+++ b/src/applications/files/query/PhabricatorFileQuery.php
@@ -118,19 +118,7 @@
}
protected function loadPage() {
- $table = new PhabricatorFile();
- $conn_r = $table->establishConnection('r');
-
- $data = queryfx_all(
- $conn_r,
- 'SELECT f.* FROM %T f %Q %Q %Q %Q',
- $table->getTableName(),
- $this->buildJoinClause($conn_r),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
-
- $files = $table->loadAllFromArray($data);
+ $files = $this->loadStandardPage(new PhabricatorFile());
if (!$files) {
return $files;
@@ -218,49 +206,48 @@
return $files;
}
- protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
- $joins = array();
+ protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
+ $joins = parent::buildJoinClauseParts($conn);
if ($this->transforms) {
$joins[] = qsprintf(
- $conn_r,
+ $conn,
'JOIN %T t ON t.transformedPHID = f.phid',
id(new PhabricatorTransformedFile())->getTableName());
}
- return implode(' ', $joins);
+ return $joins;
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
-
- $where[] = $this->buildPagingClause($conn_r);
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'f.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'f.phid IN (%Ls)',
$this->phids);
}
if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'f.authorPHID IN (%Ls)',
$this->authorPHIDs);
}
if ($this->explicitUploads !== null) {
$where[] = qsprintf(
- $conn_r,
- 'f.isExplicitUpload = true');
+ $conn,
+ 'f.isExplicitUpload = %d',
+ (int)$this->explicitUploads);
}
if ($this->transforms !== null) {
@@ -268,70 +255,70 @@
foreach ($this->transforms as $transform) {
if ($transform['transform'] === true) {
$clauses[] = qsprintf(
- $conn_r,
+ $conn,
'(t.originalPHID = %s)',
$transform['originalPHID']);
} else {
$clauses[] = qsprintf(
- $conn_r,
+ $conn,
'(t.originalPHID = %s AND t.transform = %s)',
$transform['originalPHID'],
$transform['transform']);
}
}
- $where[] = qsprintf($conn_r, '(%Q)', implode(') OR (', $clauses));
+ $where[] = qsprintf($conn, '(%Q)', implode(') OR (', $clauses));
}
if ($this->dateCreatedAfter !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'f.dateCreated >= %d',
$this->dateCreatedAfter);
}
if ($this->dateCreatedBefore !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'f.dateCreated <= %d',
$this->dateCreatedBefore);
}
if ($this->contentHashes !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'f.contentHash IN (%Ls)',
$this->contentHashes);
}
if ($this->minLength !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'byteSize >= %d',
$this->minLength);
}
if ($this->maxLength !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'byteSize <= %d',
$this->maxLength);
}
if ($this->names !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'name in (%Ls)',
$this->names);
}
if ($this->isPartial !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'isPartial = %d',
(int)$this->isPartial);
}
- return $this->formatWhereClause($where);
+ return $where;
}
protected function getPrimaryTableAlias() {
diff --git a/src/applications/files/query/PhabricatorFileSearchEngine.php b/src/applications/files/query/PhabricatorFileSearchEngine.php
--- a/src/applications/files/query/PhabricatorFileSearchEngine.php
+++ b/src/applications/files/query/PhabricatorFileSearchEngine.php
@@ -11,76 +11,54 @@
return 'PhabricatorFilesApplication';
}
- 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'));
+ public function newResultObject() {
+ return new PhabricatorFile();
+ }
- return $saved;
+ 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')),
+ );
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
+ public function buildQueryFromParameters(array $map) {
$query = id(new PhabricatorFileQuery());
- $author_phids = $saved->getParameter('authorPHIDs', array());
- if ($author_phids) {
- $query->withAuthorPHIDs($author_phids);
+ if ($map['authorPHIDs']) {
+ $query->withAuthorPHIDs($map['authorPHIDs']);
}
- if ($saved->getParameter('explicit')) {
- $query->showOnlyExplicitUploads(true);
+ if ($map['explicit'] !== null) {
+ $query->showOnlyExplicitUploads($map['explicit']);
}
- $start = $this->parseDateTime($saved->getParameter('createdStart'));
- $end = $this->parseDateTime($saved->getParameter('createdEnd'));
-
- if ($start) {
- $query->withDateCreatedAfter($start);
+ if ($map['createdStart']) {
+ $query->withDateCreatedAfter($map['createdStart']);
}
- if ($end) {
- $query->withDateCreatedBefore($end);
+ if ($map['createdEnd']) {
+ $query->withDateCreatedBefore($map['createdEnd']);
}
return $query;
}
- public function buildSearchForm(
- AphrontFormView $form,
- PhabricatorSavedQuery $saved_query) {
-
- $author_phids = $saved_query->getParameter('authorPHIDs', array());
- $explicit = $saved_query->getParameter('explicit');
-
- $form
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setDatasource(new PhabricatorPeopleDatasource())
- ->setName('authors')
- ->setLabel(pht('Authors'))
- ->setValue($author_phids))
- ->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;
}
diff --git a/src/applications/search/field/PhabricatorSearchThreeStateField.php b/src/applications/search/field/PhabricatorSearchThreeStateField.php
new file mode 100644
--- /dev/null
+++ b/src/applications/search/field/PhabricatorSearchThreeStateField.php
@@ -0,0 +1,48 @@
+<?php
+
+final class PhabricatorSearchThreeStateField
+ extends PhabricatorSearchField {
+
+ private $options;
+
+ public function setOptions($null, $yes, $no) {
+ $this->options = array(
+ '' => $null,
+ 'true' => $yes,
+ 'false' => $no,
+ );
+ return $this;
+ }
+
+ public function getOptions() {
+ return $this->options;
+ }
+
+ protected function getDefaultValue() {
+ return null;
+ }
+
+ protected function getValueFromRequest(AphrontRequest $request, $key) {
+ if (!strlen($request->getStr($key))) {
+ return null;
+ }
+ return $request->getBool($key);
+ }
+
+ protected function newControl() {
+ return id(new AphrontFormSelectControl())
+ ->setOptions($this->getOptions());
+ }
+
+ protected function getValueForControl() {
+ $value = parent::getValueForControl();
+ if ($value === true) {
+ return 'true';
+ }
+ if ($value === false) {
+ return 'false';
+ }
+ return null;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 8, 9:05 AM (6 d, 5 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7381530
Default Alt Text
D13175.diff (10 KB)
Attached To
Mode
D13175: Convert Files to SearchFields
Attached
Detach File
Event Timeline
Log In to Comment