Experimental OpenSearch description
authorTim Starling <tstarling@users.mediawiki.org>
Sun, 20 Aug 2006 03:45:47 +0000 (03:45 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sun, 20 Aug 2006 03:45:47 +0000 (03:45 +0000)
includes/Skin.php
opensearch_desc.php [new file with mode: 0644]

index 45fca59..69804dc 100644 (file)
@@ -157,7 +157,7 @@ class Skin extends Linker {
        }
 
        function initPage( &$out ) {
-               global $wgFavicon;
+               global $wgFavicon, $wgScriptPath;
 
                $fname = 'Skin::initPage';
                wfProfileIn( $fname );
@@ -166,6 +166,13 @@ class Skin extends Linker {
                        $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
                }
 
+               # OpenSearch description link
+               $out->addLink( array( 
+                       'rel' => 'search', 
+                       'type' => 'application/opensearchdescription+xml',
+                       'href' => "$wgScriptPath/opensearch_desc.php"
+               ));
+
                $this->addMetadataLinks($out);
 
                $this->mRevisionId = $out->mRevisionId;
diff --git a/opensearch_desc.php b/opensearch_desc.php
new file mode 100644 (file)
index 0000000..6aeacc4
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Generate an OpenSearch description file
+ */
+
+require_once( dirname(__FILE__) . '/includes/WebStart.php' );
+$shortName = htmlspecialchars( mb_substr( $wgSitename, 0, 16 ) );
+$siteName = htmlspecialchars( $wgSitename );
+$favicon = htmlspecialchars( $wgFavicon );
+$title = Title::makeTitle( NS_SPECIAL, 'Search' );
+$template = $title->getFullURL( '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"/>
+</OpenSearchDescription>
+EOT;
+
+?>