]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - opensearch_desc.php
MediaWiki 1.14.0-scripts
[autoinstalls/mediawiki.git] / opensearch_desc.php
1 <?php
2
3 /**
4  * Generate an OpenSearch description file
5  */
6
7 require_once( dirname(__FILE__) . '/includes/WebStart.php' );
8
9 if( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
10         // Makes testing tweaks about a billion times easier
11         $ctype = 'application/xml';
12 } else {
13         $ctype = 'application/opensearchdescription+xml';
14 }
15
16 $response = $wgRequest->response();
17 $response->header( "Content-type: $ctype" );
18
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' );
24
25 print '<?xml version="1.0"?>';
26 print Xml::openElement( 'OpenSearchDescription',
27         array(
28                 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
29                 'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ) );
30
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.
34 //
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.
38 //
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 );
44
45 // By default we'll use the site favicon.
46 // Double-check if IE supports this properly?
47 print Xml::element( 'Image',
48         array(
49                 'height' => 16,
50                 'width' => 16,
51                 'type' => 'image/x-icon' ),
52         wfExpandUrl( $wgFavicon ) );
53
54 $urls = array();
55
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' );
60 $urls[] = array(
61         'type' => 'text/html',
62         'method' => 'get',
63         'template' => $searchPage->getFullURL( 'search={searchTerms}' ) );
64
65 if( $wgEnableAPI ) {
66         // JSON interface for search suggestions.
67         // Supported in Firefox 2 and later.
68         $urls[] = array(
69                 'type' => 'application/x-suggestions+json',
70                 'method' => 'get',
71                 'template' => SearchEngine::getOpenSearchTemplate() );
72 }
73
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 ) );
77
78 foreach( $urls as $attribs ) {
79         print Xml::element( 'Url', $attribs );
80 }
81
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
85 // search box.
86 print Xml::element( 'moz:SearchForm', null,
87         $searchPage->getFullUrl() );
88
89 print '</OpenSearchDescription>';