source: trunk/w/opensearch_desc.php @ 1484

Revision 1484, 3.0 KB checked in by Xiping.Wang, 2 years ago (diff)

[trunk]add mediaiwki 1.16.0beta2 , other directories and files

Line 
1<?php
2
3/**
4 * Generate an OpenSearch description file
5 *
6 * @file
7 */
8
9require_once( dirname(__FILE__) . '/includes/WebStart.php' );
10
11if( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
12        // Makes testing tweaks about a billion times easier
13        $ctype = 'application/xml';
14} else {
15        $ctype = 'application/opensearchdescription+xml';
16}
17
18$response = $wgRequest->response();
19$response->header( "Content-type: $ctype" );
20
21// Set an Expires header so that squid can cache it for a short time
22// Short enough so that the sysadmin barely notices when $wgSitename is changed
23$expiryTime = 600; # 10 minutes
24$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
25$response->header( 'Cache-control: max-age=600' );
26
27print '<?xml version="1.0"?>';
28print Xml::openElement( 'OpenSearchDescription',
29        array(
30                'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
31                'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ) );
32
33// The spec says the ShortName must be no longer than 16 characters,
34// but 16 is *realllly* short. In practice, browsers don't appear to care
35// when we give them a longer string, so we're no longer attempting to trim.
36//
37// Note: ShortName and the <link title=""> need to match; they are used as
38// a key for identifying if the search engine has been added already, *and*
39// as the display name presented to the end-user.
40//
41// Behavior seems about the same between Firefox and IE 7/8 here.
42// 'Description' doesn't appear to be used by either.
43$fullName = wfMsgForContent( 'opensearch-desc' );
44print Xml::element( 'ShortName', null, $fullName );
45print Xml::element( 'Description', null, $fullName );
46
47// By default we'll use the site favicon.
48// Double-check if IE supports this properly?
49print Xml::element( 'Image',
50        array(
51                'height' => 16,
52                'width' => 16,
53                'type' => 'image/x-icon' ),
54        wfExpandUrl( $wgFavicon ) );
55
56$urls = array();
57
58// General search template. Given an input term, this should bring up
59// search results or a specific found page.
60// At least Firefox and IE 7 support this.
61$searchPage = SpecialPage::getTitleFor( 'Search' );
62$urls[] = array(
63        'type' => 'text/html',
64        'method' => 'get',
65        'template' => $searchPage->getFullURL( 'search={searchTerms}' ) );
66
67if( $wgEnableAPI ) {
68        // JSON interface for search suggestions.
69        // Supported in Firefox 2 and later.
70        $urls[] = array(
71                'type' => 'application/x-suggestions+json',
72                'method' => 'get',
73                'template' => SearchEngine::getOpenSearchTemplate() );
74}
75
76// Allow hooks to override the suggestion URL settings in a more
77// general way than overriding the whole search engine...
78wfRunHooks( 'OpenSearchUrls', array( &$urls ) );
79
80foreach( $urls as $attribs ) {
81        print Xml::element( 'Url', $attribs );
82}
83
84// And for good measure, add a link to the straight search form.
85// This is a custom format extension for Firefox, which otherwise
86// sends you to the domain root if you hit "enter" with an empty
87// search box.
88print Xml::element( 'moz:SearchForm', null,
89        $searchPage->getFullUrl() );
90
91print '</OpenSearchDescription>';
Note: See TracBrowser for help on using the repository browser.