2013-05-31 10:52:25 -07:00
|
|
|
<?php
|
|
|
|
|
2014-07-23 10:03:09 +10:00
|
|
|
final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
2013-05-31 10:52:25 -07:00
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $phids;
|
2013-05-31 15:14:39 -07:00
|
|
|
private $bookPHIDs;
|
|
|
|
private $names;
|
|
|
|
private $types;
|
|
|
|
private $contexts;
|
|
|
|
private $indexes;
|
2015-06-05 07:00:41 +10:00
|
|
|
private $isDocumentable;
|
|
|
|
private $isGhost;
|
2013-08-28 09:54:39 -07:00
|
|
|
private $nodeHashes;
|
Fix Diviner links to articles by title
Summary:
Ref T988. This fixes the biggest current problem with Diviner, which is dead links to articles.
In the new Diviner, articles can have both a "name" (derived from the file name, and used in the URI) and a "title" (optional, specified explicitly). For example, we have one document with the name "feedback" and the title "Give Feedback! Get Support!".
On disk, we want to use the name for the actual file where the text lives ("feedback.diviner"). We also want to use the name in the URI, to generate a clean URI and to allow us to retitle the document slightly without breaking links to it (for example, we renamed the "Backup" document to "Backups and Migrations").
However, when displaying the article we want to use the title.
Currently, you can //only// link to the name, not the title. This is inconvenient:
- We have a bunch of existing docs which link to titles.
- It's natural/intuitive to link to titles.
- Linking to titles makes it easier/cheaper to generate documentation, because we don't need to be able to resolve things at render time.
To remedy this, allow links to target either names or titles. If we miss on a name query, we'll do a title query. This is implemented with a slug hash to allow approximately correct titles (wrong case/spacing/punctuation, e.g.) and sidestep all the UTF8/column length issues.
(In the long run, atom resolution should theoretically be more sophistiated than it is now, and we should do render-time lookups on at least some documents to catch bad links. However, this is fairly complicated and a relatively advanced feature, and I think allowing links to titles is desirable no matter what.)
Test Plan: The user documentation book now has valid links to articles when the titles and names differ.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D8407
2014-03-05 12:07:26 -08:00
|
|
|
private $titles;
|
2014-03-05 16:45:21 -08:00
|
|
|
private $nameContains;
|
2015-06-19 17:24:23 +10:00
|
|
|
private $repositoryPHIDs;
|
2013-05-31 15:14:39 -07:00
|
|
|
|
|
|
|
private $needAtoms;
|
2013-08-28 09:54:39 -07:00
|
|
|
private $needExtends;
|
2013-08-28 09:57:20 -07:00
|
|
|
private $needChildren;
|
2015-06-19 17:24:23 +10:00
|
|
|
private $needRepositories;
|
2013-05-31 10:52:25 -07:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:14:39 -07:00
|
|
|
public function withBookPHIDs(array $phids) {
|
|
|
|
$this->bookPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withTypes(array $types) {
|
|
|
|
$this->types = $types;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withNames(array $names) {
|
|
|
|
$this->names = $names;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withContexts(array $contexts) {
|
|
|
|
$this->contexts = $contexts;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withIndexes(array $indexes) {
|
|
|
|
$this->indexes = $indexes;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:54:39 -07:00
|
|
|
public function withNodeHashes(array $hashes) {
|
|
|
|
$this->nodeHashes = $hashes;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Fix Diviner links to articles by title
Summary:
Ref T988. This fixes the biggest current problem with Diviner, which is dead links to articles.
In the new Diviner, articles can have both a "name" (derived from the file name, and used in the URI) and a "title" (optional, specified explicitly). For example, we have one document with the name "feedback" and the title "Give Feedback! Get Support!".
On disk, we want to use the name for the actual file where the text lives ("feedback.diviner"). We also want to use the name in the URI, to generate a clean URI and to allow us to retitle the document slightly without breaking links to it (for example, we renamed the "Backup" document to "Backups and Migrations").
However, when displaying the article we want to use the title.
Currently, you can //only// link to the name, not the title. This is inconvenient:
- We have a bunch of existing docs which link to titles.
- It's natural/intuitive to link to titles.
- Linking to titles makes it easier/cheaper to generate documentation, because we don't need to be able to resolve things at render time.
To remedy this, allow links to target either names or titles. If we miss on a name query, we'll do a title query. This is implemented with a slug hash to allow approximately correct titles (wrong case/spacing/punctuation, e.g.) and sidestep all the UTF8/column length issues.
(In the long run, atom resolution should theoretically be more sophistiated than it is now, and we should do render-time lookups on at least some documents to catch bad links. However, this is fairly complicated and a relatively advanced feature, and I think allowing links to titles is desirable no matter what.)
Test Plan: The user documentation book now has valid links to articles when the titles and names differ.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D8407
2014-03-05 12:07:26 -08:00
|
|
|
public function withTitles($titles) {
|
|
|
|
$this->titles = $titles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-03-05 16:45:21 -08:00
|
|
|
public function withNameContains($text) {
|
|
|
|
$this->nameContains = $text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:14:39 -07:00
|
|
|
public function needAtoms($need) {
|
|
|
|
$this->needAtoms = $need;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:57:20 -07:00
|
|
|
public function needChildren($need) {
|
|
|
|
$this->needChildren = $need;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-27 03:14:00 -07:00
|
|
|
/**
|
2015-06-05 07:00:41 +10:00
|
|
|
* Include or exclude "ghosts", which are symbols which used to exist but do
|
|
|
|
* not exist currently (for example, a function which existed in an older
|
|
|
|
* version of the codebase but was deleted).
|
2013-08-27 03:14:00 -07:00
|
|
|
*
|
|
|
|
* These symbols had PHIDs assigned to them, and may have other sorts of
|
|
|
|
* metadata that we don't want to lose (like comments or flags), so we don't
|
|
|
|
* delete them outright. They might also come back in the future: the change
|
|
|
|
* which deleted the symbol might be reverted, or the documentation might
|
|
|
|
* have been generated incorrectly by accident. In these cases, we can
|
|
|
|
* restore the original data.
|
|
|
|
*
|
2015-06-05 07:00:41 +10:00
|
|
|
* @param bool
|
2013-08-27 03:14:00 -07:00
|
|
|
* @return this
|
|
|
|
*/
|
2015-06-05 07:00:41 +10:00
|
|
|
public function withGhosts($ghosts) {
|
|
|
|
$this->isGhost = $ghosts;
|
2013-08-27 03:14:00 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:54:39 -07:00
|
|
|
public function needExtends($need) {
|
|
|
|
$this->needExtends = $need;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-05 07:00:41 +10:00
|
|
|
public function withIsDocumentable($documentable) {
|
|
|
|
$this->isDocumentable = $documentable;
|
2013-06-04 11:15:34 -07:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-19 17:24:23 +10:00
|
|
|
public function withRepositoryPHIDs(array $repository_phids) {
|
|
|
|
$this->repositoryPHIDs = $repository_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function needRepositories($need_repositories) {
|
|
|
|
$this->needRepositories = $need_repositories;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-31 10:52:25 -07:00
|
|
|
protected function loadPage() {
|
|
|
|
$table = new DivinerLiveSymbol();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT * FROM %T %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function willFilterPage(array $atoms) {
|
2015-06-19 17:24:23 +10:00
|
|
|
assert_instances_of($atoms, 'DivinerLiveSymbol');
|
|
|
|
|
2013-05-31 10:52:25 -07:00
|
|
|
$books = array_unique(mpull($atoms, 'getBookPHID'));
|
|
|
|
|
|
|
|
$books = id(new DivinerBookQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs($books)
|
|
|
|
->execute();
|
|
|
|
$books = mpull($books, null, 'getPHID');
|
|
|
|
|
|
|
|
foreach ($atoms as $key => $atom) {
|
|
|
|
$book = idx($books, $atom->getBookPHID());
|
|
|
|
if (!$book) {
|
2015-06-17 07:09:53 +10:00
|
|
|
$this->didRejectResult($atom);
|
2013-05-31 10:52:25 -07:00
|
|
|
unset($atoms[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$atom->attachBook($book);
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:14:39 -07:00
|
|
|
if ($this->needAtoms) {
|
|
|
|
$atom_data = id(new DivinerLiveAtom())->loadAllWhere(
|
|
|
|
'symbolPHID IN (%Ls)',
|
|
|
|
mpull($atoms, 'getPHID'));
|
|
|
|
$atom_data = mpull($atom_data, null, 'getSymbolPHID');
|
|
|
|
|
|
|
|
foreach ($atoms as $key => $atom) {
|
|
|
|
$data = idx($atom_data, $atom->getPHID());
|
|
|
|
$atom->attachAtom($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:54:39 -07:00
|
|
|
// Load all of the symbols this symbol extends, recursively. Commonly,
|
|
|
|
// this means all the ancestor classes and interfaces it extends and
|
|
|
|
// implements.
|
|
|
|
if ($this->needExtends) {
|
|
|
|
// First, load all the matching symbols by name. This does 99% of the
|
|
|
|
// work in most cases, assuming things are named at all reasonably.
|
|
|
|
$names = array();
|
|
|
|
foreach ($atoms as $atom) {
|
2015-06-05 17:52:58 +10:00
|
|
|
if (!$atom->getAtom()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:54:39 -07:00
|
|
|
foreach ($atom->getAtom()->getExtends() as $xref) {
|
|
|
|
$names[] = $xref->getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($names) {
|
|
|
|
$xatoms = id(new DivinerAtomQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withNames($names)
|
2015-06-15 13:52:00 -07:00
|
|
|
->withGhosts(false)
|
2013-08-28 09:54:39 -07:00
|
|
|
->needExtends(true)
|
|
|
|
->needAtoms(true)
|
2013-08-28 09:57:20 -07:00
|
|
|
->needChildren($this->needChildren)
|
2013-08-28 09:54:39 -07:00
|
|
|
->execute();
|
|
|
|
$xatoms = mgroup($xatoms, 'getName', 'getType', 'getBookPHID');
|
|
|
|
} else {
|
|
|
|
$xatoms = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($atoms as $atom) {
|
2015-06-05 17:52:58 +10:00
|
|
|
$atom_lang = null;
|
|
|
|
$atom_extends = array();
|
|
|
|
|
|
|
|
if ($atom->getAtom()) {
|
|
|
|
$atom_lang = $atom->getAtom()->getLanguage();
|
|
|
|
$atom_extends = $atom->getAtom()->getExtends();
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:54:39 -07:00
|
|
|
$extends = array();
|
|
|
|
|
2015-06-05 17:52:58 +10:00
|
|
|
foreach ($atom_extends as $xref) {
|
2013-08-28 09:54:39 -07:00
|
|
|
// If there are no symbols of the matching name and type, we can't
|
|
|
|
// resolve this.
|
|
|
|
if (empty($xatoms[$xref->getName()][$xref->getType()])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we found matches in the same documentation book, prefer them
|
2015-06-23 17:26:14 -07:00
|
|
|
// over other matches. Otherwise, look at all the matches.
|
2013-08-28 09:54:39 -07:00
|
|
|
$matches = $xatoms[$xref->getName()][$xref->getType()];
|
|
|
|
if (isset($matches[$atom->getBookPHID()])) {
|
|
|
|
$maybe = $matches[$atom->getBookPHID()];
|
|
|
|
} else {
|
|
|
|
$maybe = array_mergev($matches);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$maybe) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter out matches in a different language, since, e.g., PHP
|
|
|
|
// classes can not implement JS classes.
|
|
|
|
$same_lang = array();
|
|
|
|
foreach ($maybe as $xatom) {
|
2015-06-05 17:52:58 +10:00
|
|
|
if ($xatom->getAtom()->getLanguage() == $atom_lang) {
|
2013-08-28 09:54:39 -07:00
|
|
|
$same_lang[] = $xatom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$same_lang) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have duplicates remaining, just pick the first one. There's
|
|
|
|
// nothing more we can do to figure out which is the real one.
|
|
|
|
$extends[] = head($same_lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
$atom->attachExtends($extends);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:57:20 -07:00
|
|
|
if ($this->needChildren) {
|
|
|
|
$child_hashes = $this->getAllChildHashes($atoms, $this->needExtends);
|
|
|
|
|
|
|
|
if ($child_hashes) {
|
|
|
|
$children = id(new DivinerAtomQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withNodeHashes($child_hashes)
|
|
|
|
->needAtoms($this->needAtoms)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$children = mpull($children, null, 'getNodeHash');
|
|
|
|
} else {
|
|
|
|
$children = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->attachAllChildren($atoms, $children, $this->needExtends);
|
|
|
|
}
|
|
|
|
|
2015-06-19 17:24:23 +10:00
|
|
|
if ($this->needRepositories) {
|
|
|
|
$repositories = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withPHIDs(mpull($atoms, 'getRepositoryPHID'))
|
|
|
|
->execute();
|
|
|
|
$repositories = mpull($repositories, null, 'getPHID');
|
|
|
|
|
|
|
|
foreach ($atoms as $key => $atom) {
|
|
|
|
if ($atom->getRepositoryPHID() === null) {
|
|
|
|
$atom->attachRepository(null);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository = idx($repositories, $atom->getRepositoryPHID());
|
|
|
|
|
|
|
|
if (!$repository) {
|
|
|
|
$this->didRejectResult($atom);
|
|
|
|
unset($atom[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$atom->attachRepository($repository);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-31 10:52:25 -07:00
|
|
|
return $atoms;
|
|
|
|
}
|
|
|
|
|
Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.
To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.
With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.
For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.
For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.
This causes no behavioral changes.
Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: yelirekim, hach-que, epriestley
Maniphest Tasks: T4100, T5595
Differential Revision: https://secure.phabricator.com/D12453
2015-04-18 07:08:30 -07:00
|
|
|
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2013-05-31 10:52:25 -07:00
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:14:39 -07:00
|
|
|
if ($this->bookPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'bookPHID IN (%Ls)',
|
|
|
|
$this->bookPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->types) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'type IN (%Ls)',
|
|
|
|
$this->types);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->names) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'name IN (%Ls)',
|
|
|
|
$this->names);
|
|
|
|
}
|
|
|
|
|
Fix Diviner links to articles by title
Summary:
Ref T988. This fixes the biggest current problem with Diviner, which is dead links to articles.
In the new Diviner, articles can have both a "name" (derived from the file name, and used in the URI) and a "title" (optional, specified explicitly). For example, we have one document with the name "feedback" and the title "Give Feedback! Get Support!".
On disk, we want to use the name for the actual file where the text lives ("feedback.diviner"). We also want to use the name in the URI, to generate a clean URI and to allow us to retitle the document slightly without breaking links to it (for example, we renamed the "Backup" document to "Backups and Migrations").
However, when displaying the article we want to use the title.
Currently, you can //only// link to the name, not the title. This is inconvenient:
- We have a bunch of existing docs which link to titles.
- It's natural/intuitive to link to titles.
- Linking to titles makes it easier/cheaper to generate documentation, because we don't need to be able to resolve things at render time.
To remedy this, allow links to target either names or titles. If we miss on a name query, we'll do a title query. This is implemented with a slug hash to allow approximately correct titles (wrong case/spacing/punctuation, e.g.) and sidestep all the UTF8/column length issues.
(In the long run, atom resolution should theoretically be more sophistiated than it is now, and we should do render-time lookups on at least some documents to catch bad links. However, this is fairly complicated and a relatively advanced feature, and I think allowing links to titles is desirable no matter what.)
Test Plan: The user documentation book now has valid links to articles when the titles and names differ.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D8407
2014-03-05 12:07:26 -08:00
|
|
|
if ($this->titles) {
|
|
|
|
$hashes = array();
|
2015-06-17 07:09:53 +10:00
|
|
|
|
Fix Diviner links to articles by title
Summary:
Ref T988. This fixes the biggest current problem with Diviner, which is dead links to articles.
In the new Diviner, articles can have both a "name" (derived from the file name, and used in the URI) and a "title" (optional, specified explicitly). For example, we have one document with the name "feedback" and the title "Give Feedback! Get Support!".
On disk, we want to use the name for the actual file where the text lives ("feedback.diviner"). We also want to use the name in the URI, to generate a clean URI and to allow us to retitle the document slightly without breaking links to it (for example, we renamed the "Backup" document to "Backups and Migrations").
However, when displaying the article we want to use the title.
Currently, you can //only// link to the name, not the title. This is inconvenient:
- We have a bunch of existing docs which link to titles.
- It's natural/intuitive to link to titles.
- Linking to titles makes it easier/cheaper to generate documentation, because we don't need to be able to resolve things at render time.
To remedy this, allow links to target either names or titles. If we miss on a name query, we'll do a title query. This is implemented with a slug hash to allow approximately correct titles (wrong case/spacing/punctuation, e.g.) and sidestep all the UTF8/column length issues.
(In the long run, atom resolution should theoretically be more sophistiated than it is now, and we should do render-time lookups on at least some documents to catch bad links. However, this is fairly complicated and a relatively advanced feature, and I think allowing links to titles is desirable no matter what.)
Test Plan: The user documentation book now has valid links to articles when the titles and names differ.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D8407
2014-03-05 12:07:26 -08:00
|
|
|
foreach ($this->titles as $title) {
|
|
|
|
$slug = DivinerAtomRef::normalizeTitleString($title);
|
|
|
|
$hash = PhabricatorHash::digestForIndex($slug);
|
|
|
|
$hashes[] = $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'titleSlugHash in (%Ls)',
|
|
|
|
$hashes);
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:14:39 -07:00
|
|
|
if ($this->contexts) {
|
|
|
|
$with_null = false;
|
|
|
|
$contexts = $this->contexts;
|
2015-06-17 07:09:53 +10:00
|
|
|
|
2013-05-31 15:14:39 -07:00
|
|
|
foreach ($contexts as $key => $value) {
|
|
|
|
if ($value === null) {
|
|
|
|
unset($contexts[$key]);
|
|
|
|
$with_null = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($contexts && $with_null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'context IN (%Ls) OR context IS NULL',
|
|
|
|
$contexts);
|
|
|
|
} else if ($contexts) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'context IN (%Ls)',
|
|
|
|
$contexts);
|
|
|
|
} else if ($with_null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'context IS NULL');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->indexes) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'atomIndex IN (%Ld)',
|
|
|
|
$this->indexes);
|
|
|
|
}
|
|
|
|
|
2015-06-05 07:00:41 +10:00
|
|
|
if ($this->isDocumentable !== null) {
|
2013-06-04 11:15:34 -07:00
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
2015-06-05 07:00:41 +10:00
|
|
|
'isDocumentable = %d',
|
|
|
|
(int)$this->isDocumentable);
|
2013-06-04 11:15:34 -07:00
|
|
|
}
|
|
|
|
|
2015-06-05 07:00:41 +10:00
|
|
|
if ($this->isGhost !== null) {
|
|
|
|
if ($this->isGhost) {
|
|
|
|
$where[] = qsprintf($conn_r, 'graphHash IS NULL');
|
|
|
|
} else {
|
|
|
|
$where[] = qsprintf($conn_r, 'graphHash IS NOT NULL');
|
|
|
|
}
|
2013-08-27 03:14:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-28 09:54:39 -07:00
|
|
|
if ($this->nodeHashes) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'nodeHash IN (%Ls)',
|
|
|
|
$this->nodeHashes);
|
|
|
|
}
|
|
|
|
|
2014-03-05 16:45:21 -08:00
|
|
|
if ($this->nameContains) {
|
2015-06-17 07:09:53 +10:00
|
|
|
// NOTE: This `CONVERT()` call makes queries case-insensitive, since
|
|
|
|
// the column has binary collation. Eventually, this should move into
|
2014-03-05 16:45:21 -08:00
|
|
|
// fulltext.
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'CONVERT(name USING utf8) LIKE %~',
|
|
|
|
$this->nameContains);
|
|
|
|
}
|
|
|
|
|
2015-06-19 17:24:23 +10:00
|
|
|
if ($this->repositoryPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'repositoryPHID IN (%Ls)',
|
|
|
|
$this->repositoryPHIDs);
|
|
|
|
}
|
|
|
|
|
2013-05-31 10:52:25 -07:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
2013-08-28 09:57:20 -07:00
|
|
|
/**
|
|
|
|
* Walk a list of atoms and collect all the node hashes of the atoms'
|
|
|
|
* children. When recursing, also walk up the tree and collect children of
|
|
|
|
* atoms they extend.
|
|
|
|
*
|
|
|
|
* @param list<DivinerLiveSymbol> List of symbols to collect child hashes of.
|
|
|
|
* @param bool True to collect children of extended atoms,
|
|
|
|
* as well.
|
|
|
|
* @return map<string, string> Hashes of atoms' children.
|
|
|
|
*/
|
|
|
|
private function getAllChildHashes(array $symbols, $recurse_up) {
|
|
|
|
assert_instances_of($symbols, 'DivinerLiveSymbol');
|
|
|
|
|
|
|
|
$hashes = array();
|
|
|
|
foreach ($symbols as $symbol) {
|
2015-06-05 17:52:58 +10:00
|
|
|
$child_hashes = array();
|
|
|
|
|
|
|
|
if ($symbol->getAtom()) {
|
|
|
|
$child_hashes = $symbol->getAtom()->getChildHashes();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($child_hashes as $hash) {
|
2013-08-28 09:57:20 -07:00
|
|
|
$hashes[$hash] = $hash;
|
|
|
|
}
|
2015-06-17 07:09:53 +10:00
|
|
|
|
2013-08-28 09:57:20 -07:00
|
|
|
if ($recurse_up) {
|
|
|
|
$hashes += $this->getAllChildHashes($symbol->getExtends(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $hashes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach child atoms to existing atoms. In recursive mode, also attach child
|
|
|
|
* atoms to atoms that these atoms extend.
|
|
|
|
*
|
2014-07-23 10:03:09 +10:00
|
|
|
* @param list<DivinerLiveSymbol> List of symbols to attach children to.
|
2013-08-28 09:57:20 -07:00
|
|
|
* @param map<string, DivinerLiveSymbol> Map of symbols, keyed by node hash.
|
|
|
|
* @param bool True to attach children to extended atoms, as well.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function attachAllChildren(
|
|
|
|
array $symbols,
|
|
|
|
array $children,
|
|
|
|
$recurse_up) {
|
|
|
|
|
|
|
|
assert_instances_of($symbols, 'DivinerLiveSymbol');
|
|
|
|
assert_instances_of($children, 'DivinerLiveSymbol');
|
|
|
|
|
|
|
|
foreach ($symbols as $symbol) {
|
2015-06-05 17:52:58 +10:00
|
|
|
$child_hashes = array();
|
2013-08-28 09:57:20 -07:00
|
|
|
$symbol_children = array();
|
2015-06-05 17:52:58 +10:00
|
|
|
|
|
|
|
if ($symbol->getAtom()) {
|
|
|
|
$child_hashes = $symbol->getAtom()->getChildHashes();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($child_hashes as $hash) {
|
2013-08-28 09:57:20 -07:00
|
|
|
if (isset($children[$hash])) {
|
|
|
|
$symbol_children[] = $children[$hash];
|
|
|
|
}
|
|
|
|
}
|
2015-06-17 07:09:53 +10:00
|
|
|
|
2013-08-28 09:57:20 -07:00
|
|
|
$symbol->attachChildren($symbol_children);
|
2015-06-17 07:09:53 +10:00
|
|
|
|
2013-08-28 09:57:20 -07:00
|
|
|
if ($recurse_up) {
|
|
|
|
$this->attachAllChildren($symbol->getExtends(), $children, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-21 17:20:27 -07:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorDivinerApplication';
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-21 17:20:27 -07:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:52:25 -07:00
|
|
|
}
|