Tweak up last commit about opensearch desc to be nicer. Cleaner message name, use...
[lhc/web/wiklou.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 require_once( dirname(__FILE__) . '/languages/Names.php' );
9 $fullName = wfMsgForContent( 'opensearch-desc' );
10 $shortName = htmlspecialchars( mb_substr( $fullName, 0, 24 ) );
11 $siteName = htmlspecialchars( $fullName );
12
13
14 $favicon = htmlspecialchars( wfExpandUrl( $wgFavicon ) );
15
16 $title = SpecialPage::getTitleFor( 'Search' );
17 $template = $title->escapeFullURL( 'search={searchTerms}' );
18
19 $suggest = htmlspecialchars($wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}');
20
21
22 $response = $wgRequest->response();
23 if( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
24 // Makes testing tweaks about a billion times easier
25 $ctype = 'application/xml';
26 } else {
27 $ctype = 'application/opensearchdescription+xml';
28 }
29 $response->header( "Content-type: $ctype" );
30
31 # Set an Expires header so that squid can cache it for a short time
32 # Short enough so that the sysadmin barely notices when $wgSitename is changed
33 $expiryTime = 600; # 10 minutes
34 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
35 $response->header( 'Cache-control: max-age=600' );
36
37 echo <<<EOT
38 <?xml version="1.0"?>
39 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
40 <ShortName>$shortName</ShortName>
41 <Description>$siteName</Description>
42 <Image height="16" width="16" type="image/x-icon">$favicon</Image>
43 <Url type="text/html" method="get" template="$template"/>
44 <Url type="application/x-suggestions+json" method="GET" template="$suggest"/>
45 </OpenSearchDescription>
46 EOT;
47
48
49 ?>