54 private string $favicon;
57 private array $templates;
62 $this->urlUtils = $urlUtils;
66 $ctype = $this->getContentType();
73 $expiryTime = 600; # 10 minutes
74 $response->setHeader(
'Expires', gmdate(
'D, d M Y H:i:s', time() + $expiryTime ) .
' GMT' );
75 $response->setHeader(
'Cache-control',
'max-age=600' );
79 $body->write(
'<?xml version="1.0"?>' );
82 'xmlns' =>
'http://a9.com/-/spec/opensearch/1.1/',
83 'xmlns:moz' =>
'http://www.mozilla.org/2006/browser/search/' ] ) );
95 $fullName =
wfMessage(
'opensearch-desc' )->inContentLanguage()->text();
96 $body->write(
Xml::element(
'ShortName',
null, $fullName ) );
97 $body->write(
Xml::element(
'Description',
null, $fullName ) );
105 'type' =>
'image/x-icon'
107 (
string)$this->urlUtils->expand( $this->favicon,
PROTO_CURRENT )
117 'type' =>
'text/html',
119 'template' => $searchPage->getCanonicalURL(
'search={searchTerms}' ) ];
123 foreach ( $this->templates as $type => $template ) {
132 'template' => $template,
141 foreach ( $urls as $attribs ) {
150 $searchPage->getCanonicalURL() ) );
154 $response->setBody( $body );
165 private function getContentType(): string {
167 if ( $params[
'ctype'] ==
'application/xml' ) {
169 return 'application/xml';
172 $acceptHeader = $this->
getRequest()->getHeader(
'accept' );
174 if ( $acceptHeader ) {
175 $parser =
new HttpAcceptParser();
176 $acceptableTypes = $parser->parseAccept( $acceptHeader[0] );
178 foreach ( $acceptableTypes as $acc ) {
179 if ( $acc[
'type'] ===
'application/xml' ) {
180 return 'application/xml';
185 return 'application/opensearchdescription+xml';
189 $spec = parent::generateResponseSpec( $method );
191 $spec[
'200'][
'content'][
'application/opensearchdescription+xml'][
'schema'][
'type'] =
'string';
199 self::PARAM_SOURCE =>
'query',
200 Handler::PARAM_DESCRIPTION =>
new MessageValue(
'rest-param-desc-opensearch-ctype' ),
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
A class containing constants representing the names of configuration variables.
const OpenSearchTemplates
Name constant for the OpenSearchTemplates setting, for use with Config::get()
const Favicon
Name constant for the Favicon setting, for use with Config::get()
This class contains schema declarations for all configuration variables known to MediaWiki core.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...