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