Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diviner/controller/DivinerFindController.php
12256 views
1
<?php
2
3
final class DivinerFindController extends DivinerController {
4
5
public function shouldAllowPublic() {
6
return true;
7
}
8
9
public function handleRequest(AphrontRequest $request) {
10
$viewer = $request->getViewer();
11
12
$book_name = $request->getStr('book');
13
$query_text = $request->getStr('name');
14
15
$book = null;
16
if ($book_name) {
17
$book = id(new DivinerBookQuery())
18
->setViewer($viewer)
19
->withNames(array($book_name))
20
->executeOne();
21
22
if (!$book) {
23
return new Aphront404Response();
24
}
25
}
26
27
$query = id(new DivinerAtomQuery())
28
->setViewer($viewer);
29
30
if ($book) {
31
$query->withBookPHIDs(array($book->getPHID()));
32
}
33
34
$context = $request->getStr('context');
35
if (strlen($context)) {
36
$query->withContexts(array($context));
37
}
38
39
$type = $request->getStr('type');
40
if (strlen($type)) {
41
$query->withTypes(array($type));
42
}
43
44
$query->withGhosts(false);
45
$query->withIsDocumentable(true);
46
47
$name_query = clone $query;
48
49
$name_query->withNames(
50
array(
51
$query_text,
52
// TODO: This could probably be more smartly normalized in the DB,
53
// but just fake it for now.
54
phutil_utf8_strtolower($query_text),
55
));
56
57
$atoms = $name_query->execute();
58
59
if (!$atoms) {
60
$title_query = clone $query;
61
$title_query->withTitles(array($query_text));
62
$atoms = $title_query->execute();
63
}
64
65
$not_found_uri = $this->getApplicationURI();
66
67
if (!$atoms) {
68
$dialog = id(new AphrontDialogView())
69
->setUser($viewer)
70
->setTitle(pht('Documentation Not Found'))
71
->appendChild(
72
pht(
73
'Unable to find the specified documentation. '.
74
'You may have followed a bad or outdated link.'))
75
->addCancelButton($not_found_uri, pht('Read More Documentation'));
76
77
return id(new AphrontDialogResponse())->setDialog($dialog);
78
}
79
80
if (count($atoms) == 1 && $request->getBool('jump')) {
81
$atom_uri = head($atoms)->getURI();
82
return id(new AphrontRedirectResponse())->setURI($atom_uri);
83
}
84
85
$list = $this->renderAtomList($atoms);
86
87
return $this->newPage()
88
->setTitle(array(pht('Find'), pht('"%s"', $query_text)))
89
->appendChild(array(
90
$list,
91
));
92
93
}
94
95
}
96
97