4 * Generate an OpenSearch description file
7 require_once( dirname(__FILE__
) . '/includes/WebStart.php' );
9 if( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
10 // Makes testing tweaks about a billion times easier
11 $ctype = 'application/xml';
13 $ctype = 'application/opensearchdescription+xml';
16 $response = $wgRequest->response();
17 $response->header( "Content-type: $ctype" );
19 // Set an Expires header so that squid can cache it for a short time
20 // Short enough so that the sysadmin barely notices when $wgSitename is changed
21 $expiryTime = 600; # 10 minutes
22 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() +
$expiryTime ) . ' GMT' );
23 $response->header( 'Cache-control: max-age=600' );
25 print '<?xml version="1.0"?>';
26 print Xml
::openElement( 'OpenSearchDescription',
28 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
29 'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ) );
31 // The spec says the ShortName must be no longer than 16 characters,
32 // but 16 is *realllly* short. In practice, browsers don't appear to care
33 // when we give them a longer string, so we're no longer attempting to trim.
35 // Note: ShortName and the <link title=""> need to match; they are used as
36 // a key for identifying if the search engine has been added already, *and*
37 // as the display name presented to the end-user.
39 // Behavior seems about the same between Firefox and IE 7/8 here.
40 // 'Description' doesn't appear to be used by either.
41 $fullName = wfMsgForContent( 'opensearch-desc' );
42 print Xml
::element( 'ShortName', null, $fullName );
43 print Xml
::element( 'Description', null, $fullName );
45 // By default we'll use the site favicon.
46 // Double-check if IE supports this properly?
47 print Xml
::element( 'Image',
51 'type' => 'image/x-icon' ),
52 wfExpandUrl( $wgFavicon ) );
56 // General search template. Given an input term, this should bring up
57 // search results or a specific found page.
58 // At least Firefox and IE 7 support this.
59 $searchPage = SpecialPage
::getTitleFor( 'Search' );
61 'type' => 'text/html',
63 'template' => $searchPage->getFullURL( 'search={searchTerms}' ) );
66 // JSON interface for search suggestions.
67 // Supported in Firefox 2 and later.
69 'type' => 'application/x-suggestions+json',
71 'template' => SearchEngine
::getOpenSearchTemplate() );
74 // Allow hooks to override the suggestion URL settings in a more
75 // general way than overriding the whole search engine...
76 wfRunHooks( 'OpenSearchUrls', array( &$urls ) );
78 foreach( $urls as $attribs ) {
79 print Xml
::element( 'Url', $attribs );
82 // And for good measure, add a link to the straight search form.
83 // This is a custom format extension for Firefox, which otherwise
84 // sends you to the domain root if you hit "enter" with an empty
86 print Xml
::element( 'moz:SearchForm', null,
87 $searchPage->getFullUrl() );
89 print '</OpenSearchDescription>';