15use MediaWiki\MainConfigSchema;
42 private string $favicon;
45 private array $templates;
50 $this->urlUtils = $urlUtils;
54 $ctype = $this->getContentType();
61 $expiryTime = 600; # 10 minutes
62 $response->setHeader(
'Expires', gmdate(
'D, d M Y H:i:s', time() + $expiryTime ) .
' GMT' );
63 $response->setHeader(
'Cache-control',
'max-age=600' );
67 $body->write(
'<?xml version="1.0"?>' );
70 'xmlns' =>
'http://a9.com/-/spec/opensearch/1.1/',
71 'xmlns:moz' =>
'http://www.mozilla.org/2006/browser/search/' ] ) );
83 $fullName =
wfMessage(
'opensearch-desc' )->inContentLanguage()->text();
84 $body->write(
Xml::element(
'ShortName',
null, $fullName ) );
85 $body->write(
Xml::element(
'Description',
null, $fullName ) );
93 'type' =>
'image/x-icon'
95 (
string)$this->urlUtils->expand( $this->favicon,
PROTO_CURRENT )
105 'type' =>
'text/html',
107 'template' => $searchPage->getCanonicalURL(
'search={searchTerms}' ) ];
111 foreach ( $this->templates as $type => $template ) {
120 'template' => $template,
129 foreach ( $urls as $attribs ) {
138 $searchPage->getCanonicalURL() ) );
142 $response->setBody( $body );
153 private function getContentType(): string {
155 if ( $params[
'ctype'] ==
'application/xml' ) {
157 return 'application/xml';
160 $acceptHeader = $this->
getRequest()->getHeader(
'accept' );
162 if ( $acceptHeader ) {
163 $parser =
new HttpAcceptParser();
164 $acceptableTypes = $parser->parseAccept( $acceptHeader[0] );
166 foreach ( $acceptableTypes as $acc ) {
167 if ( $acc[
'type'] ===
'application/xml' ) {
168 return 'application/xml';
173 return 'application/opensearchdescription+xml';
177 $spec = parent::generateResponseSpec( $method );
179 $spec[
'200'][
'content'][
'application/opensearchdescription+xml'][
'schema'][
'type'] =
'string';
188 self::PARAM_SOURCE =>
'query',
189 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()
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,...