API: Fixing exception in ApiEditPage
[lhc/web/wiklou.git] / opensearch_desc.php
index 491b05a..a94e3e9 100644 (file)
@@ -5,25 +5,34 @@
  */
 
 require_once( dirname(__FILE__) . '/includes/WebStart.php' );
-$shortName = htmlspecialchars( mb_substr( $wgSitename, 0, 16 ) );
-$siteName = htmlspecialchars( $wgSitename );
+require_once( dirname(__FILE__) . '/languages/Names.php' );
+$fullName = wfMsgForContent( 'opensearch-desc' );
+$shortName = htmlspecialchars( mb_substr( $fullName, 0, 24 ) );
+$siteName = htmlspecialchars( $fullName );
 
-if ( !preg_match( '/^https?:/', $wgFavicon ) ) {
-       $favicon = htmlspecialchars( $wgServer . $wgFavicon );
-} else {
-       $favicon = htmlspecialchars( $wgFavicon );
-}
 
-$title = Title::makeTitle( NS_SPECIAL, 'Search' );
-$template = $title->getFullURL( 'search={searchTerms}' );
+$favicon = htmlspecialchars( wfExpandUrl( $wgFavicon ) );
+
+$title = SpecialPage::getTitleFor( 'Search' );
+$template = $title->escapeFullURL( 'search={searchTerms}' );
+
+$suggest = htmlspecialchars($wgServer . $wgScriptPath . '/api.php?action=opensearch&search={searchTerms}');
+
 
 $response = $wgRequest->response();
-$response->header( 'Content-type: application/opensearchdescription+xml' );
+if( $wgRequest->getVal( 'ctype' ) == 'application/xml' ) {
+       // Makes testing tweaks about a billion times easier
+       $ctype = 'application/xml';
+} else {
+       $ctype = 'application/opensearchdescription+xml';
+}
+$response->header( "Content-type: $ctype" );
 
 # Set an Expires header so that squid can cache it for a short time
 # Short enough so that the sysadmin barely notices when $wgSitename is changed
-$expiryTime = 300; # 5 minutes
+$expiryTime = 600; # 10 minutes
 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
+$response->header( 'Cache-control: max-age=600' );
 
 echo <<<EOT
 <?xml version="1.0"?>
@@ -32,7 +41,9 @@ echo <<<EOT
 <Description>$siteName</Description>
 <Image height="16" width="16" type="image/x-icon">$favicon</Image>
 <Url type="text/html" method="get" template="$template"/>
+<Url type="application/x-suggestions+json" method="GET" template="$suggest"/>
 </OpenSearchDescription>
 EOT;
 
+
 ?>