If the page doesn't exist and the user can't create it, omit the "edit"/"view source"
[mediawiki.git] / opensearch_desc.php
blobb06b7feecf51617d72823837750d20ff46225271
1 <?php
3 /**
4 * Generate an OpenSearch description file
5 */
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 );
13 if ( !preg_match( '/^https?:/', $wgFavicon ) ) {
14 $favicon = htmlspecialchars( $wgServer . $wgFavicon );
15 } else {
16 $favicon = htmlspecialchars( $wgFavicon );
19 $title = SpecialPage::getTitleFor( 'Search' );
20 $template = $title->escapeFullURL( 'search={searchTerms}' );
22 $suggest = htmlspecialchars($wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}');
25 $response = $wgRequest->response();
26 $response->header( 'Content-type: application/opensearchdescription+xml' );
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' );
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;