[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/ -> opensearch_desc.php (source)

   1  <?php
   2  /**
   3   * Generate an OpenSearch description file.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   */
  22  
  23  require_once  __DIR__ . '/includes/WebStart.php';
  24  
  25  if ( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
  26      // Makes testing tweaks about a billion times easier
  27      $ctype = 'application/xml';
  28  } else {
  29      $ctype = 'application/opensearchdescription+xml';
  30  }
  31  
  32  $response = $wgRequest->response();
  33  $response->header( "Content-type: $ctype" );
  34  
  35  // Set an Expires header so that squid can cache it for a short time
  36  // Short enough so that the sysadmin barely notices when $wgSitename is changed
  37  $expiryTime = 600; # 10 minutes
  38  $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
  39  $response->header( 'Cache-control: max-age=600' );
  40  
  41  print '<?xml version="1.0"?>';
  42  print Xml::openElement( 'OpenSearchDescription',
  43      array(
  44          'xmlns' => 'http://a9.com/-/spec/opensearch/1.1/',
  45          'xmlns:moz' => 'http://www.mozilla.org/2006/browser/search/' ) );
  46  
  47  // The spec says the ShortName must be no longer than 16 characters,
  48  // but 16 is *realllly* short. In practice, browsers don't appear to care
  49  // when we give them a longer string, so we're no longer attempting to trim.
  50  //
  51  // Note: ShortName and the <link title=""> need to match; they are used as
  52  // a key for identifying if the search engine has been added already, *and*
  53  // as the display name presented to the end-user.
  54  //
  55  // Behavior seems about the same between Firefox and IE 7/8 here.
  56  // 'Description' doesn't appear to be used by either.
  57  $fullName = wfMessage( 'opensearch-desc' )->inContentLanguage()->text();
  58  print Xml::element( 'ShortName', null, $fullName );
  59  print Xml::element( 'Description', null, $fullName );
  60  
  61  // By default we'll use the site favicon.
  62  // Double-check if IE supports this properly?
  63  print Xml::element( 'Image',
  64      array(
  65          'height' => 16,
  66          'width' => 16,
  67          'type' => 'image/x-icon' ),
  68      wfExpandUrl( $wgFavicon, PROTO_CURRENT ) );
  69  
  70  $urls = array();
  71  
  72  // General search template. Given an input term, this should bring up
  73  // search results or a specific found page.
  74  // At least Firefox and IE 7 support this.
  75  $searchPage = SpecialPage::getTitleFor( 'Search' );
  76  $urls[] = array(
  77      'type' => 'text/html',
  78      'method' => 'get',
  79      'template' => $searchPage->getCanonicalURL( 'search={searchTerms}' ) );
  80  
  81  if ( $wgEnableAPI ) {
  82      // JSON interface for search suggestions.
  83      // Supported in Firefox 2 and later.
  84      $urls[] = array(
  85          'type' => 'application/x-suggestions+json',
  86          'method' => 'get',
  87          'template' => SearchEngine::getOpenSearchTemplate() );
  88  }
  89  
  90  // Allow hooks to override the suggestion URL settings in a more
  91  // general way than overriding the whole search engine...
  92  wfRunHooks( 'OpenSearchUrls', array( &$urls ) );
  93  
  94  foreach ( $urls as $attribs ) {
  95      print Xml::element( 'Url', $attribs );
  96  }
  97  
  98  // And for good measure, add a link to the straight search form.
  99  // This is a custom format extension for Firefox, which otherwise
 100  // sends you to the domain root if you hit "enter" with an empty
 101  // search box.
 102  print Xml::element( 'moz:SearchForm', null,
 103      $searchPage->getCanonicalURL() );
 104  
 105  print '</OpenSearchDescription>';


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1