MediaWiki
REL1_19
|
00001 <?php 00002 00009 require_once( dirname(__FILE__) . '/includes/WebStart.php' ); 00010 00011 if( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) { 00012 // Makes testing tweaks about a billion times easier 00013 $ctype = 'application/xml'; 00014 } else { 00015 $ctype = 'application/opensearchdescription+xml'; 00016 } 00017 00018 $response = $wgRequest->response(); 00019 $response->header( "Content-type: $ctype" ); 00020 00021 // Set an Expires header so that squid can cache it for a short time 00022 // Short enough so that the sysadmin barely notices when $wgSitename is changed 00023 $expiryTime = 600; # 10 minutes 00024 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' ); 00025 $response->header( 'Cache-control: max-age=600' ); 00026 00027 print '<?xml version="1.0"?>'; 00028 print Xml::openElement( 'OpenSearchDescription', 00029 array( 00030 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/', 00031 'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ) ); 00032 00033 // The spec says the ShortName must be no longer than 16 characters, 00034 // but 16 is *realllly* short. In practice, browsers don't appear to care 00035 // when we give them a longer string, so we're no longer attempting to trim. 00036 // 00037 // Note: ShortName and the <link title=""> need to match; they are used as 00038 // a key for identifying if the search engine has been added already, *and* 00039 // as the display name presented to the end-user. 00040 // 00041 // Behavior seems about the same between Firefox and IE 7/8 here. 00042 // 'Description' doesn't appear to be used by either. 00043 $fullName = wfMsgForContent( 'opensearch-desc' ); 00044 print Xml::element( 'ShortName', null, $fullName ); 00045 print Xml::element( 'Description', null, $fullName ); 00046 00047 // By default we'll use the site favicon. 00048 // Double-check if IE supports this properly? 00049 print Xml::element( 'Image', 00050 array( 00051 'height' => 16, 00052 'width' => 16, 00053 'type' => 'image/x-icon' ), 00054 wfExpandUrl( $wgFavicon , PROTO_CURRENT ) ); 00055 00056 $urls = array(); 00057 00058 // General search template. Given an input term, this should bring up 00059 // search results or a specific found page. 00060 // At least Firefox and IE 7 support this. 00061 $searchPage = SpecialPage::getTitleFor( 'Search' ); 00062 $urls[] = array( 00063 'type' => 'text/html', 00064 'method' => 'get', 00065 'template' => $searchPage->getCanonicalURL( 'search={searchTerms}' ) ); 00066 00067 if( $wgEnableAPI ) { 00068 // JSON interface for search suggestions. 00069 // Supported in Firefox 2 and later. 00070 $urls[] = array( 00071 'type' => 'application/x-suggestions+json', 00072 'method' => 'get', 00073 'template' => SearchEngine::getOpenSearchTemplate() ); 00074 } 00075 00076 // Allow hooks to override the suggestion URL settings in a more 00077 // general way than overriding the whole search engine... 00078 wfRunHooks( 'OpenSearchUrls', array( &$urls ) ); 00079 00080 foreach( $urls as $attribs ) { 00081 print Xml::element( 'Url', $attribs ); 00082 } 00083 00084 // And for good measure, add a link to the straight search form. 00085 // This is a custom format extension for Firefox, which otherwise 00086 // sends you to the domain root if you hit "enter" with an empty 00087 // search box. 00088 print Xml::element( 'moz:SearchForm', null, 00089 $searchPage->getCanonicalURL() ); 00090 00091 print '</OpenSearchDescription>';