Friday, February 17, 2006

FogBugz browser search integration

FogBugz 4.0 has a handy new search URL that lets you enter a bug number to go directly to a bug, or search text to find all open cases matching your query. Wouldn't it be nice to hook this into your browser's search box? Fortunately, IE7 uses A9's OpenSearch for its search providers, and Firefox uses Mycroft.

Creating the OpenSearch provider

Create an XML file with the following text:

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>FogBugz</ShortName>

<Description>Search FogBugz</Description>
<Url type="text/html" template="http://[your-ip-goes-here]/fogbugz/default.asp?pre=preMultiSearch&amp;pg=pgList&amp;pgBack=pgSearch&amp;search=2&amp;searchFor={searchTerms}" />
</OpenSearchDescription>


Replace [your-ip-goes-here] with the appropriate address.

Put the XML file on your web server and put the following link somewhere that's publicly accessible:

<a href="#" onClick="window.external.AddSearchProvider(&quot;http://[url-to-your-directory]/FogBugzOpenSearch.xml&quot;);">Add FogBugz search provider to IE7</a>

Replace [url-to-your-directory] with the appropriate URL.

Now, when you click on the link from IE7, you'll be prompted to add a new search provider. This will make a FogBugz option available in the dropdown list of your search box:



Creating the Firefox provider

Create a file named FogBugzSearch.src in a public directory on your web server with the following text:

<search
version="7.1"
name="FogBugz"
description="Search FogBugz"
action="http://[your-ip-goes-here]/fogbugz/default.asp" searchForm="http://[your-ip-goes-here]/fogbugz/" method="GET"
>
<input name="pre=preMultiSearch&amp;pg=pgList&pgBack=pgSearch&search=2&searchFor" user=""> </search>
<browser

update="http://[url-to-your-directory]/FogBugzSearch.src"    
updateIcon="http://[url-to-your-directory]/FogBugzSearch.png"

updateCheckDays="360"

>



Fill in the blanks with the appropriate addresses and URLs.

Put the following image in the same directory:



Now to create the link. Put the following in your head element:

<script type="text/javascript">
function addEngine(name,ext,cat,type)
{
if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {

window.sidebar.addSearchEngine(
"http://[url-to-your-directory]"+name+".src",
"http://[url-to-your-directory]"+name+"."+ext, name, cat );

}
}
</script>


and the following link in your page:

<a href="javascript:addEngine('FogBugzSearch','png','General','0')">Add FogBugz search provider to Firefox</a>

Now, when you click on the link from Firefox, you'll be prompted to add a new search provider. This will make a FogBugz option available in the dropdown list of your search box: