Path: blob/master/src/applications/diviner/controller/DivinerFindController.php
12256 views
<?php12final class DivinerFindController extends DivinerController {34public function shouldAllowPublic() {5return true;6}78public function handleRequest(AphrontRequest $request) {9$viewer = $request->getViewer();1011$book_name = $request->getStr('book');12$query_text = $request->getStr('name');1314$book = null;15if ($book_name) {16$book = id(new DivinerBookQuery())17->setViewer($viewer)18->withNames(array($book_name))19->executeOne();2021if (!$book) {22return new Aphront404Response();23}24}2526$query = id(new DivinerAtomQuery())27->setViewer($viewer);2829if ($book) {30$query->withBookPHIDs(array($book->getPHID()));31}3233$context = $request->getStr('context');34if (strlen($context)) {35$query->withContexts(array($context));36}3738$type = $request->getStr('type');39if (strlen($type)) {40$query->withTypes(array($type));41}4243$query->withGhosts(false);44$query->withIsDocumentable(true);4546$name_query = clone $query;4748$name_query->withNames(49array(50$query_text,51// TODO: This could probably be more smartly normalized in the DB,52// but just fake it for now.53phutil_utf8_strtolower($query_text),54));5556$atoms = $name_query->execute();5758if (!$atoms) {59$title_query = clone $query;60$title_query->withTitles(array($query_text));61$atoms = $title_query->execute();62}6364$not_found_uri = $this->getApplicationURI();6566if (!$atoms) {67$dialog = id(new AphrontDialogView())68->setUser($viewer)69->setTitle(pht('Documentation Not Found'))70->appendChild(71pht(72'Unable to find the specified documentation. '.73'You may have followed a bad or outdated link.'))74->addCancelButton($not_found_uri, pht('Read More Documentation'));7576return id(new AphrontDialogResponse())->setDialog($dialog);77}7879if (count($atoms) == 1 && $request->getBool('jump')) {80$atom_uri = head($atoms)->getURI();81return id(new AphrontRedirectResponse())->setURI($atom_uri);82}8384$list = $this->renderAtomList($atoms);8586return $this->newPage()87->setTitle(array(pht('Find'), pht('"%s"', $query_text)))88->appendChild(array(89$list,90));9192}9394}959697