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