MediaWiki  1.30.0
opensearch_desc.php
Go to the documentation of this file.
1 <?php
23 // This endpoint is supposed to be independent of request cookies and other
24 // details of the session. Log warnings for violations of the no-session
25 // constraint.
26 define( 'MW_NO_SESSION', 'warn' );
27 
28 require_once __DIR__ . '/includes/WebStart.php';
29 
30 if ( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
31  // Makes testing tweaks about a billion times easier
32  $ctype = 'application/xml';
33 } else {
34  $ctype = 'application/opensearchdescription+xml';
35 }
36 
37 $response = $wgRequest->response();
38 $response->header( "Content-type: $ctype" );
39 
40 // Set an Expires header so that squid can cache it for a short time
41 // Short enough so that the sysadmin barely notices when $wgSitename is changed
42 $expiryTime = 600; # 10 minutes
43 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
44 $response->header( 'Cache-control: max-age=600' );
45 
46 print '<?xml version="1.0"?>';
47 print Xml::openElement( 'OpenSearchDescription',
48  [
49  'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
50  'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ] );
51 
52 /* The spec says the ShortName must be no longer than 16 characters,
53  * but 16 is *realllly* short. In practice, browsers don't appear to care
54  * when we give them a longer string, so we're no longer attempting to trim.
55  *
56  * Note: ShortName and the <link title=""> need to match; they are used as
57  * a key for identifying if the search engine has been added already, *and*
58  * as the display name presented to the end-user.
59  *
60  * Behavior seems about the same between Firefox and IE 7/8 here.
61  * 'Description' doesn't appear to be used by either.
62  */
63 $fullName = wfMessage( 'opensearch-desc' )->inContentLanguage()->text();
64 print Xml::element( 'ShortName', null, $fullName );
65 print Xml::element( 'Description', null, $fullName );
66 
67 // By default we'll use the site favicon.
68 // Double-check if IE supports this properly?
69 print Xml::element( 'Image',
70  [
71  'height' => 16,
72  'width' => 16,
73  'type' => 'image/x-icon' ],
75 
76 $urls = [];
77 
78 // General search template. Given an input term, this should bring up
79 // search results or a specific found page.
80 // At least Firefox and IE 7 support this.
81 $searchPage = SpecialPage::getTitleFor( 'Search' );
82 $urls[] = [
83  'type' => 'text/html',
84  'method' => 'get',
85  'template' => $searchPage->getCanonicalURL( 'search={searchTerms}' ) ];
86 
88  if ( !$template && $wgEnableAPI ) {
90  }
91 
92  if ( $template ) {
93  $urls[] = [
94  'type' => $type,
95  'method' => 'get',
96  'template' => $template,
97  ];
98  }
99 }
100 
101 // Allow hooks to override the suggestion URL settings in a more
102 // general way than overriding the whole search engine...
103 Hooks::run( 'OpenSearchUrls', [ &$urls ] );
104 
105 foreach ( $urls as $attribs ) {
106  print Xml::element( 'Url', $attribs );
107 }
108 
109 // And for good measure, add a link to the straight search form.
110 // This is a custom format extension for Firefox, which otherwise
111 // sends you to the domain root if you hit "enter" with an empty
112 // search box.
113 print Xml::element( 'moz:SearchForm', null,
114  $searchPage->getCanonicalURL() );
115 
116 print '</OpenSearchDescription>';
$template
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping $template
Definition: hooks.txt:781
$response
$response
Definition: opensearch_desc.php:37
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
$wgOpenSearchTemplates
$wgOpenSearchTemplates
Templates for OpenSearch suggestions, defaults to API action=opensearch.
Definition: DefaultSettings.php:6443
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1965
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:223
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
$expiryTime
$expiryTime
Definition: opensearch_desc.php:42
ApiOpenSearch\getOpenSearchTemplate
static getOpenSearchTemplate( $type)
Fetch the template for a type.
Definition: ApiOpenSearch.php:357
$wgFavicon
$wgFavicon
The URL path of the shortcut icon.
Definition: DefaultSettings.php:301
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:662
$wgEnableAPI
$wgEnableAPI
Enable the MediaWiki API for convenient access to machine-readable data via api.php.
Definition: DefaultSettings.php:7952
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:586
$type
$type
Definition: testCompression.php:48