@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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 (phutil_nonempty_string($context)) {
36 $query->withContexts(array($context));
37 }
38
39 $type = $request->getStr('type');
40 if (phutil_nonempty_string($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 if (phutil_nonempty_string($query_text)) {
62 $title_query->withTitles(array($query_text));
63 }
64 $atoms = $title_query->execute();
65 }
66
67 $not_found_uri = $this->getApplicationURI();
68
69 if (!$atoms) {
70 $dialog = id(new AphrontDialogView())
71 ->setUser($viewer)
72 ->setTitle(pht('Documentation Not Found'))
73 ->appendChild(
74 pht(
75 'Unable to find the specified documentation. '.
76 'You may have followed a bad or outdated link.'))
77 ->addCancelButton($not_found_uri, pht('Read More Documentation'));
78
79 return id(new AphrontDialogResponse())->setDialog($dialog);
80 }
81
82 if (count($atoms) == 1 && $request->getBool('jump')) {
83 $atom_uri = head($atoms)->getURI();
84 return id(new AphrontRedirectResponse())->setURI($atom_uri);
85 }
86
87 $list = $this->renderAtomList($atoms);
88
89 return $this->newPage()
90 ->setTitle(array(pht('Find'), pht('"%s"', $query_text)))
91 ->appendChild(array(
92 $list,
93 ));
94
95 }
96
97}