2006-08-20 03:45:47 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-05-23 11:41:30 +00:00
|
|
|
* Generate an OpenSearch description file.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2009-03-21 16:48:09 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2006-08-20 03:45:47 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-05-05 15:35:10 +00:00
|
|
|
// This endpoint is supposed to be independent of request cookies and other
|
2018-10-03 19:07:24 +00:00
|
|
|
// details of the session. Enforce this constraint with respect to session use.
|
|
|
|
|
define( 'MW_NO_SESSION', 1 );
|
2016-05-05 15:35:10 +00:00
|
|
|
|
2019-09-02 23:55:00 +00:00
|
|
|
define( 'MW_ENTRY_POINT', 'opensearch_desc' );
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/includes/WebStart.php';
|
2006-10-16 02:31:28 +00:00
|
|
|
|
2013-02-13 18:38:32 +00:00
|
|
|
if ( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
|
2008-02-27 04:53:24 +00:00
|
|
|
// Makes testing tweaks about a billion times easier
|
|
|
|
|
$ctype = 'application/xml';
|
|
|
|
|
} else {
|
|
|
|
|
$ctype = 'application/opensearchdescription+xml';
|
|
|
|
|
}
|
2008-07-01 23:31:24 +00:00
|
|
|
|
|
|
|
|
$response = $wgRequest->response();
|
2008-02-27 04:53:24 +00:00
|
|
|
$response->header( "Content-type: $ctype" );
|
2006-08-20 03:45:47 +00:00
|
|
|
|
2017-11-01 20:55:24 +00:00
|
|
|
// Set an Expires header so that CDN can cache it for a short time
|
2008-07-01 23:31:24 +00:00
|
|
|
// Short enough so that the sysadmin barely notices when $wgSitename is changed
|
2008-01-29 00:26:13 +00:00
|
|
|
$expiryTime = 600; # 10 minutes
|
2006-08-20 03:45:47 +00:00
|
|
|
$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
|
2008-01-29 00:26:13 +00:00
|
|
|
$response->header( 'Cache-control: max-age=600' );
|
2006-08-20 03:45:47 +00:00
|
|
|
|
2008-07-01 23:31:24 +00:00
|
|
|
print '<?xml version="1.0"?>';
|
|
|
|
|
print Xml::openElement( 'OpenSearchDescription',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2018-06-07 16:48:39 +00:00
|
|
|
'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
|
|
|
|
|
'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ] );
|
2008-07-01 23:31:24 +00:00
|
|
|
|
2019-07-08 20:24:45 +00:00
|
|
|
// The spec says the ShortName must be no longer than 16 characters,
|
|
|
|
|
// but 16 is *realllly* short. In practice, browsers don't appear to care
|
|
|
|
|
// when we give them a longer string, so we're no longer attempting to trim.
|
|
|
|
|
//
|
|
|
|
|
// Note: ShortName and the <link title=""> need to match; they are used as
|
|
|
|
|
// a key for identifying if the search engine has been added already, *and*
|
|
|
|
|
// as the display name presented to the end-user.
|
|
|
|
|
//
|
|
|
|
|
// Behavior seems about the same between Firefox and IE 7/8 here.
|
|
|
|
|
// 'Description' doesn't appear to be used by either.
|
2012-07-24 01:04:15 +00:00
|
|
|
$fullName = wfMessage( 'opensearch-desc' )->inContentLanguage()->text();
|
2008-07-01 23:31:24 +00:00
|
|
|
print Xml::element( 'ShortName', null, $fullName );
|
|
|
|
|
print Xml::element( 'Description', null, $fullName );
|
|
|
|
|
|
|
|
|
|
// By default we'll use the site favicon.
|
|
|
|
|
// Double-check if IE supports this properly?
|
|
|
|
|
print Xml::element( 'Image',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2008-07-01 23:31:24 +00:00
|
|
|
'height' => 16,
|
|
|
|
|
'width' => 16,
|
2016-02-17 09:09:32 +00:00
|
|
|
'type' => 'image/x-icon' ],
|
2013-01-30 14:03:58 +00:00
|
|
|
wfExpandUrl( $wgFavicon, PROTO_CURRENT ) );
|
2008-07-01 23:31:24 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$urls = [];
|
2008-07-01 23:31:24 +00:00
|
|
|
|
|
|
|
|
// General search template. Given an input term, this should bring up
|
|
|
|
|
// search results or a specific found page.
|
|
|
|
|
// At least Firefox and IE 7 support this.
|
|
|
|
|
$searchPage = SpecialPage::getTitleFor( 'Search' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$urls[] = [
|
2008-07-07 18:59:49 +00:00
|
|
|
'type' => 'text/html',
|
2008-07-01 23:31:24 +00:00
|
|
|
'method' => 'get',
|
2016-02-17 09:09:32 +00:00
|
|
|
'template' => $searchPage->getCanonicalURL( 'search={searchTerms}' ) ];
|
2008-07-01 23:31:24 +00:00
|
|
|
|
2014-11-05 22:16:43 +00:00
|
|
|
foreach ( $wgOpenSearchTemplates as $type => $template ) {
|
2017-11-20 23:50:22 +00:00
|
|
|
if ( !$template ) {
|
2014-11-05 22:16:43 +00:00
|
|
|
$template = ApiOpenSearch::getOpenSearchTemplate( $type );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $template ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$urls[] = [
|
2014-11-05 22:16:43 +00:00
|
|
|
'type' => $type,
|
|
|
|
|
'method' => 'get',
|
|
|
|
|
'template' => $template,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-11-05 22:16:43 +00:00
|
|
|
}
|
2008-07-01 23:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Allow hooks to override the suggestion URL settings in a more
|
|
|
|
|
// general way than overriding the whole search engine...
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'OpenSearchUrls', [ &$urls ] );
|
2008-07-01 23:31:24 +00:00
|
|
|
|
2013-02-13 18:38:32 +00:00
|
|
|
foreach ( $urls as $attribs ) {
|
2008-07-01 23:31:24 +00:00
|
|
|
print Xml::element( 'Url', $attribs );
|
|
|
|
|
}
|
2006-08-20 03:45:47 +00:00
|
|
|
|
2008-07-01 23:31:24 +00:00
|
|
|
// And for good measure, add a link to the straight search form.
|
|
|
|
|
// This is a custom format extension for Firefox, which otherwise
|
|
|
|
|
// sends you to the domain root if you hit "enter" with an empty
|
|
|
|
|
// search box.
|
|
|
|
|
print Xml::element( 'moz:SearchForm', null,
|
2011-08-19 14:39:37 +00:00
|
|
|
$searchPage->getCanonicalURL() );
|
2006-10-09 19:43:20 +00:00
|
|
|
|
2008-07-01 23:31:24 +00:00
|
|
|
print '</OpenSearchDescription>';
|