summaryrefslogtreecommitdiff
path: root/opensearch_desc.php
blob: b06b7feecf51617d72823837750d20ff46225271 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

/**
 * Generate an OpenSearch description file
 */

require_once( dirname(__FILE__) . '/includes/WebStart.php' );
require_once( dirname(__FILE__) . '/languages/Names.php' );
$fullName = "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})";
$shortName = htmlspecialchars( mb_substr( $fullName, 0, 24 ) );
$siteName = htmlspecialchars( $fullName );

if ( !preg_match( '/^https?:/', $wgFavicon ) ) {
	$favicon = htmlspecialchars( $wgServer . $wgFavicon );
} else {
	$favicon = htmlspecialchars( $wgFavicon );
}

$title = SpecialPage::getTitleFor( 'Search' );
$template = $title->escapeFullURL( 'search={searchTerms}' );

$suggest = htmlspecialchars($wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}');


$response = $wgRequest->response();
$response->header( 'Content-type: application/opensearchdescription+xml' );

# Set an Expires header so that squid can cache it for a short time
# Short enough so that the sysadmin barely notices when $wgSitename is changed
$expiryTime = 300; # 5 minutes
$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );

echo <<<EOT
<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>$shortName</ShortName>
<Description>$siteName</Description>
<Image height="16" width="16" type="image/x-icon">$favicon</Image>
<Url type="text/html" method="get" template="$template"/>
<Url type="application/x-suggestions+json" method="GET" template="$suggest"/>
</OpenSearchDescription>
EOT;


?>