2006-08-20 03:45:47 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2020-02-04 21:44:38 +00:00
|
|
|
* The web entry point for generating an OpenSearch description document.
|
|
|
|
|
*
|
|
|
|
|
* See <http://www.opensearch.org/> for the specification of the OpenSearch
|
|
|
|
|
* "description" document. In a nut shell, this tells browsers how and where
|
|
|
|
|
* to submit submit search queries to get a search results page back,
|
|
|
|
|
* as well as how to get typeahead suggestions (see ApiOpenSearch).
|
2012-05-23 11:41:30 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2020-02-04 21:44:38 +00:00
|
|
|
* @ingroup entrypoint
|
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...
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
Hooks::runner()->onOpenSearchUrls( $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>';
|