From 7b701383e7b9b7e208a7e1155f1f4086132fe160 Mon Sep 17 00:00:00 2001 From: James Brown Date: Tue, 29 May 2018 16:19:08 -0700 Subject: [PATCH 1/3] first pass at adding OpenSearch support to phabricator --- resources/builtin/opensearch.xml | 10 ++++++++ .../PhabricatorSearchApplication.php | 5 +++- .../PhabricatorSearchOpensearchController.php | 25 +++++++++++++++++++ src/view/page/PhabricatorBarePageView.php | 19 +++++++++++++- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 resources/builtin/opensearch.xml create mode 100644 src/applications/search/controller/PhabricatorSearchOpensearchController.php diff --git a/resources/builtin/opensearch.xml b/resources/builtin/opensearch.xml new file mode 100644 index 0000000000..9e1d8a41a3 --- /dev/null +++ b/resources/builtin/opensearch.xml @@ -0,0 +1,10 @@ + + + phab + TITLE + UTF-8 + data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAB0UlEQVRIie3Wu2sUURQG8J+ClYJiK2IRQSxUJLELPlLGKop5GSRRGwXFP0JRBFMqWMVHxMUogvioBAUbTREUxMJGRLFIYyGioLGYu3j27qy7m7UJ5MBlL+f7vvPNzLlzdliOpR4r2uBuQz96sDvlnmMWj/Dmf11UF2aw0GTNYHOnZgP4HYpO4xj60jqKG5nxwcWaDYcid7DpH9yNqAT+WCdmF9vQnQ+6w62KhoLoSYb1YyrtV+EqdmSch0E/2sxsUG0/1mX4pZSfxdu0P5Vx1qjt+0gjs0OZ2b2A9eEkXqk/nU/TnWwP/ErGGc7NdpYUmgj4xwybxOUs9y7wx0rqdUfDmyWEfQHvwueUPx3ykyk3rxgI1egtqTcNKxOhbOIshP0n/Ax3W40v6feboq8tR3fJFY0HfC7k5xN2At9D/n3glz3S+ARQf0LvBmwA5/C6pNAHRT/jab2dcRq+HkMZcW2Gn0n5H/ia9lcyzmr8CjWaDoCRQH6cYb14ga1Yj5c4nnEeBH3LI240iC60KsLZoDvShq7OtKIY0I1iA251YlaNA2rH1HXFQNib1jiuqe374GLNqtHqH/B9bGlWrN1PjP3YhT1J+8zfT4y5NmotxxKOP9ORw9t1VtuYAAAAAElFTkSuQmCC + + BASE_URI + diff --git a/src/applications/search/application/PhabricatorSearchApplication.php b/src/applications/search/application/PhabricatorSearchApplication.php index 3cf5923b9c..de0c957784 100644 --- a/src/applications/search/application/PhabricatorSearchApplication.php +++ b/src/applications/search/application/PhabricatorSearchApplication.php @@ -50,7 +50,10 @@ public function getRoutes() { => 'PhabricatorSearchRelationshipController', 'source/(?P[^/]+)/(?P[^/]+)/' => 'PhabricatorSearchRelationshipSourceController', - ), + ), + '/' => array( + 'opensearch.xml' => 'PhabricatorSearchOpensearchController' + ), ); } diff --git a/src/applications/search/controller/PhabricatorSearchOpensearchController.php b/src/applications/search/controller/PhabricatorSearchOpensearchController.php new file mode 100644 index 0000000000..41f766546f --- /dev/null +++ b/src/applications/search/controller/PhabricatorSearchOpensearchController.php @@ -0,0 +1,25 @@ +setContent($content) + ->setMimeType("application/opensearchdescription+xml"); + } +} + +?> diff --git a/src/view/page/PhabricatorBarePageView.php b/src/view/page/PhabricatorBarePageView.php index de421d9e70..ce851117b1 100644 --- a/src/view/page/PhabricatorBarePageView.php +++ b/src/view/page/PhabricatorBarePageView.php @@ -103,12 +103,15 @@ protected function getHead() { } } + $opensearch_tag = $this->opensearchLink(); + return hsprintf( - '%s%s%s%s%s', + '%s%s%s%s%s%s', $viewport_tag, $mask_icon, $favicon_links, $referrer_tag, + $opensearch_tag, $response->renderResourcesOfType('css')); } @@ -178,4 +181,18 @@ private function newFavicons() { return $favicon_links; } + private function opensearchLink() { + $logo = PhabricatorEnv::getEnvConfig('ui.logo'); + $title = idx($logo, 'wordmarkText', 'phabricator'); + + return phutil_tag( + 'link', + array( + 'rel' => 'search', + 'type' => 'application/opensearchdescription+xml', + 'title' => $title, + 'href' => '/opensearch.xml' + ) + ); + } } From 6ff6836777c2228d2ef70695c0853b3561c3d6a8 Mon Sep 17 00:00:00 2001 From: James Brown Date: Thu, 31 May 2018 22:15:18 +0000 Subject: [PATCH 2/3] fix some bugs that cropped up in testing --- resources/builtin/opensearch.xml | 8 ++++---- src/__phutil_library_map__.php | 1 + .../PhabricatorSearchOpensearchController.php | 18 +++++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/resources/builtin/opensearch.xml b/resources/builtin/opensearch.xml index 9e1d8a41a3..5ea534efe9 100644 --- a/resources/builtin/opensearch.xml +++ b/resources/builtin/opensearch.xml @@ -1,10 +1,10 @@ - - phab - TITLE + + phabricator + TITLE full site search UTF-8 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAB0UlEQVRIie3Wu2sUURQG8J+ClYJiK2IRQSxUJLELPlLGKop5GSRRGwXFP0JRBFMqWMVHxMUogvioBAUbTREUxMJGRLFIYyGioLGYu3j27qy7m7UJ5MBlL+f7vvPNzLlzdliOpR4r2uBuQz96sDvlnmMWj/Dmf11UF2aw0GTNYHOnZgP4HYpO4xj60jqKG5nxwcWaDYcid7DpH9yNqAT+WCdmF9vQnQ+6w62KhoLoSYb1YyrtV+EqdmSch0E/2sxsUG0/1mX4pZSfxdu0P5Vx1qjt+0gjs0OZ2b2A9eEkXqk/nU/TnWwP/ErGGc7NdpYUmgj4xwybxOUs9y7wx0rqdUfDmyWEfQHvwueUPx3ykyk3rxgI1egtqTcNKxOhbOIshP0n/Ax3W40v6feboq8tR3fJFY0HfC7k5xN2At9D/n3glz3S+ARQf0LvBmwA5/C6pNAHRT/jab2dcRq+HkMZcW2Gn0n5H/ia9lcyzmr8CjWaDoCRQH6cYb14ga1Yj5c4nnEeBH3LI240iC60KsLZoDvShq7OtKIY0I1iA251YlaNA2rH1HXFQNib1jiuqe374GLNqtHqH/B9bGlWrN1PjP3YhT1J+8zfT4y5NmotxxKOP9ORw9t1VtuYAAAAAElFTkSuQmCC + BASE_URI diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8ad0f6fc40..33ac113919 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4221,6 +4221,7 @@ 'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php', 'PhabricatorSearchNgrams' => 'applications/search/ngrams/PhabricatorSearchNgrams.php', 'PhabricatorSearchNgramsDestructionEngineExtension' => 'applications/search/engineextension/PhabricatorSearchNgramsDestructionEngineExtension.php', + 'PhabricatorSearchOpensearchController' => 'applications/search/controller/PhabricatorSearchOpensearchController.php', 'PhabricatorSearchOrderController' => 'applications/search/controller/PhabricatorSearchOrderController.php', 'PhabricatorSearchOrderField' => 'applications/search/field/PhabricatorSearchOrderField.php', 'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php', diff --git a/src/applications/search/controller/PhabricatorSearchOpensearchController.php b/src/applications/search/controller/PhabricatorSearchOpensearchController.php index 41f766546f..78f488e3a6 100644 --- a/src/applications/search/controller/PhabricatorSearchOpensearchController.php +++ b/src/applications/search/controller/PhabricatorSearchOpensearchController.php @@ -5,6 +5,14 @@ final class PhabricatorSearchOpensearchController const SCOPE_CURRENT_APPLICATION = 'application'; + public function shouldRequireLogin() { + return false; + } + + public function shouldAllowPartialSessions() { + return true; + } + public function handleRequest(AphrontRequest $request) { $root = dirname(phutil_get_library_root('phabricator')); $logo = PhabricatorEnv::getEnvConfig('ui.logo'); @@ -13,12 +21,16 @@ public function handleRequest(AphrontRequest $request) { $content = Filesystem::readFile( $root.'/resources/builtin/opensearch.xml'); - $content = preg_replace('/BASE_URI/', PhabricatorEnv::getURI('/search/')); - $content = preg_replace('/TITLE/', $title); + $content = preg_replace('/OPENSEARCH_URI/', PhabricatorEnv::getURI('/opensearch.xml'), $content); + $content = preg_replace('/BASE_URI/', PhabricatorEnv::getURI('/search/'), $content); + $content = preg_replace('/FAVICON_URI/', PhabricatorEnv::getURI('favicon.ico'), $content); + $content = preg_replace('/TITLE/', $title, $content); return id(new AphrontFileResponse()) ->setContent($content) - ->setMimeType("application/opensearchdescription+xml"); + ->setMimeType("application/opensearchdescription+xml") + ->setCanCDN(true) + ->setCacheDurationInSeconds(60 * 60 * 24 * 7); } } From d1af3537913194c9594b8bbe831c824852ee6b05 Mon Sep 17 00:00:00 2001 From: James Brown Date: Thu, 31 May 2018 22:17:41 +0000 Subject: [PATCH 3/3] fix indentation --- .../search/application/PhabricatorSearchApplication.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/applications/search/application/PhabricatorSearchApplication.php b/src/applications/search/application/PhabricatorSearchApplication.php index de0c957784..705caa3db8 100644 --- a/src/applications/search/application/PhabricatorSearchApplication.php +++ b/src/applications/search/application/PhabricatorSearchApplication.php @@ -51,9 +51,9 @@ public function getRoutes() { 'source/(?P[^/]+)/(?P[^/]+)/' => 'PhabricatorSearchRelationshipSourceController', ), - '/' => array( - 'opensearch.xml' => 'PhabricatorSearchOpensearchController' - ), + '/' => array( + 'opensearch.xml' => 'PhabricatorSearchOpensearchController' + ), ); }