]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - opensearch_desc.php
MediaWiki 1.11.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 require_once( dirname(__FILE__) . '/languages/Names.php' );
9 $fullName = "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})";
10 $shortName = htmlspecialchars( mb_substr( $fullName, 0, 24 ) );
11 $siteName = htmlspecialchars( $fullName );
12
13 if ( !preg_match( '/^https?:/', $wgFavicon ) ) {
14         $favicon = htmlspecialchars( $wgServer . $wgFavicon );
15 } else {
16         $favicon = htmlspecialchars( $wgFavicon );
17 }
18
19 $title = SpecialPage::getTitleFor( 'Search' );
20 $template = $title->escapeFullURL( 'search={searchTerms}' );
21
22 $suggest = htmlspecialchars($wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}');
23
24
25 $response = $wgRequest->response();
26 $response->header( 'Content-type: application/opensearchdescription+xml' );
27
28 # Set an Expires header so that squid can cache it for a short time
29 # Short enough so that the sysadmin barely notices when $wgSitename is changed
30 $expiryTime = 300; # 5 minutes
31 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
32
33 echo <<<EOT
34 <?xml version="1.0"?>
35 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
36 <ShortName>$shortName</ShortName>
37 <Description>$siteName</Description>
38 <Image height="16" width="16" type="image/x-icon">$favicon</Image>
39 <Url type="text/html" method="get" template="$template"/>
40 <Url type="application/x-suggestions+json" method="GET" template="$suggest"/>
41 </OpenSearchDescription>
42 EOT;
43
44
45 ?>