Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / opensearch_desc.php
blob0d6a76c8e7963b321fb8503e53305cac7bf7e9ad
1 <?php
2 /**
3 * Generate an OpenSearch description file.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 require_once __DIR__ . '/includes/WebStart.php';
25 if ( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
26 // Makes testing tweaks about a billion times easier
27 $ctype = 'application/xml';
28 } else {
29 $ctype = 'application/opensearchdescription+xml';
32 $response = $wgRequest->response();
33 $response->header( "Content-type: $ctype" );
35 // Set an Expires header so that squid can cache it for a short time
36 // Short enough so that the sysadmin barely notices when $wgSitename is changed
37 $expiryTime = 600; # 10 minutes
38 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
39 $response->header( 'Cache-control: max-age=600' );
41 print '<?xml version="1.0"?>';
42 print Xml::openElement( 'OpenSearchDescription',
43 array(
44 'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
45 'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ) );
47 /* The spec says the ShortName must be no longer than 16 characters,
48 * but 16 is *realllly* short. In practice, browsers don't appear to care
49 * when we give them a longer string, so we're no longer attempting to trim.
51 * Note: ShortName and the <link title=""> need to match; they are used as
52 * a key for identifying if the search engine has been added already, *and*
53 * as the display name presented to the end-user.
55 * Behavior seems about the same between Firefox and IE 7/8 here.
56 * 'Description' doesn't appear to be used by either.
58 $fullName = wfMessage( 'opensearch-desc' )->inContentLanguage()->text();
59 print Xml::element( 'ShortName', null, $fullName );
60 print Xml::element( 'Description', null, $fullName );
62 // By default we'll use the site favicon.
63 // Double-check if IE supports this properly?
64 print Xml::element( 'Image',
65 array(
66 'height' => 16,
67 'width' => 16,
68 'type' => 'image/x-icon' ),
69 wfExpandUrl( $wgFavicon, PROTO_CURRENT ) );
71 $urls = array();
73 // General search template. Given an input term, this should bring up
74 // search results or a specific found page.
75 // At least Firefox and IE 7 support this.
76 $searchPage = SpecialPage::getTitleFor( 'Search' );
77 $urls[] = array(
78 'type' => 'text/html',
79 'method' => 'get',
80 'template' => $searchPage->getCanonicalURL( 'search={searchTerms}' ) );
82 foreach ( $wgOpenSearchTemplates as $type => $template ) {
83 if ( !$template && $wgEnableAPI ) {
84 $template = ApiOpenSearch::getOpenSearchTemplate( $type );
87 if ( $template ) {
88 $urls[] = array(
89 'type' => $type,
90 'method' => 'get',
91 'template' => $template,
96 // Allow hooks to override the suggestion URL settings in a more
97 // general way than overriding the whole search engine...
98 Hooks::run( 'OpenSearchUrls', array( &$urls ) );
100 foreach ( $urls as $attribs ) {
101 print Xml::element( 'Url', $attribs );
104 // And for good measure, add a link to the straight search form.
105 // This is a custom format extension for Firefox, which otherwise
106 // sends you to the domain root if you hit "enter" with an empty
107 // search box.
108 print Xml::element( 'moz:SearchForm', null,
109 $searchPage->getCanonicalURL() );
111 print '</OpenSearchDescription>';