Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first pass at adding OpenSearch support to phabricator #9

Open
wants to merge 3 commits into
base: easypost-patches
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions resources/builtin/opensearch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>phabricator</ShortName>
<Description>TITLE full site search</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">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</Image>
<Url type="text/html" template="BASE_URI?script=1&amp;query={searchTerms}"></Url>
<Url type="application/opensearchdescription+xml" rel="self" template="OPENSEARCH_URI" />
<moz:SearchForm>BASE_URI</moz:SearchForm>
</OpenSearchDescription>
1 change: 1 addition & 0 deletions src/__phutil_library_map__.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function getRoutes() {
=> 'PhabricatorSearchRelationshipController',
'source/(?P<relationshipKey>[^/]+)/(?P<sourcePHID>[^/]+)/'
=> 'PhabricatorSearchRelationshipSourceController',
),
'/' => array(
'opensearch.xml' => 'PhabricatorSearchOpensearchController'
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

final class PhabricatorSearchOpensearchController
extends PhabricatorSearchBaseController {

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');
$title = idx($logo, 'wordmarkText', 'phabricator');

$content = Filesystem::readFile(
$root.'/resources/builtin/opensearch.xml');

$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")
->setCanCDN(true)
->setCacheDurationInSeconds(60 * 60 * 24 * 7);
}
}

?>
19 changes: 18 additions & 1 deletion src/view/page/PhabricatorBarePageView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down Expand Up @@ -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'
)
);
}
}