Add final period to API module descriptions
[lhc/web/wiklou.git] / includes / api / ApiQuerySearch.php
index 36b5597..fcaaf10 100644 (file)
@@ -63,6 +63,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                $limit = $params['limit'];
                $query = $params['search'];
                $what = $params['what'];
+               $interwiki = $params['interwiki'];
                $searchInfo = array_flip( $params['info'] );
                $prop = array_flip( $params['prop'] );
 
@@ -112,12 +113,12 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        $totalhits = $matches->getTotalHits();
                        if ( $totalhits !== null ) {
                                $apiResult->addValue( array( 'query', 'searchinfo' ),
-                                               'totalhits', $totalhits );
+                                       'totalhits', $totalhits );
                        }
                }
                if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) {
                        $apiResult->addValue( array( 'query', 'searchinfo' ),
-                                               'suggestion', $matches->getSuggestionQuery() );
+                               'suggestion', $matches->getSuggestionQuery() );
                }
 
                // Add the search results to the result
@@ -127,8 +128,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                $result = $matches->next();
 
                while ( $result ) {
-                       if ( ++ $count > $limit ) {
-                               // We've reached the one extra which shows that there are additional items to be had. Stop here...
+                       if ( ++$count > $limit ) {
+                               // We've reached the one extra which shows that there are
+                               // additional items to be had. Stop here...
                                $this->setContinueEnumParameter( 'offset', $params['offset'] + $params['limit'] );
                                break;
                        }
@@ -184,7 +186,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
 
                                // Add item to results and see whether it fits
                                $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ),
-                                               null, $vals );
+                                       null, $vals );
                                if ( !$fit ) {
                                        $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 );
                                        break;
@@ -196,10 +198,52 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        $result = $matches->next();
                }
 
+               $hasInterwikiResults = false;
+               if ( $interwiki && $resultPageSet === null && $matches->hasInterwikiResults() ) {
+                       $matches = $matches->getInterwikiResults();
+                       $iwprefixes = array();
+                       $hasInterwikiResults = true;
+
+                       // Include number of results if requested
+                       if ( isset( $searchInfo['totalhits'] ) ) {
+                               $totalhits = $matches->getTotalHits();
+                               if ( $totalhits !== null ) {
+                                       $apiResult->addValue( array( 'query', 'interwikisearchinfo' ),
+                                               'totalhits', $totalhits );
+                               }
+                       }
+
+                       $result = $matches->next();
+                       while ( $result ) {
+                               $title = $result->getTitle();
+                               $vals = array(
+                                       'namespace' => $result->getInterwikiNamespaceText(),
+                                       'title' => $title->getText(),
+                                       'url' => $title->getFullUrl(),
+                               );
+
+                               // Add item to results and see whether it fits
+                               $fit = $apiResult->addValue( array( 'query', 'interwiki' . $this->getModuleName(), $result->getInterwikiPrefix()  ),
+                                       null, $vals );
+                               if ( !$fit ) {
+                                       // We hit the limit. We can't really provide any meaningful
+                                       // pagination info so just bail out
+                                       break;
+                               }
+
+                               $result = $matches->next();
+                       }
+               }
+
                if ( is_null( $resultPageSet ) ) {
                        $apiResult->setIndexedTagName_internal( array(
-                                               'query', $this->getModuleName()
-                                       ), 'p' );
+                               'query', $this->getModuleName()
+                       ), 'p' );
+                       if ( $hasInterwikiResults ) {
+                               $apiResult->setIndexedTagName_internal( array(
+                                       'query', 'interwiki' . $this->getModuleName()
+                               ), 'p' );
+                       }
                } else {
                        $resultPageSet->populateFromTitles( $titles );
                }
@@ -263,7 +307,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                ApiBase::PARAM_MIN => 1,
                                ApiBase::PARAM_MAX => ApiBase::LIMIT_SML1,
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_SML2
-                       )
+                       ),
+                       'interwiki' => false,
                );
 
                $alternatives = SearchEngine::getSearchTypes();
@@ -302,7 +347,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        ),
                        'redirects' => 'Include redirect pages in the search',
                        'offset' => 'Use this value to continue paging (return by query)',
-                       'limit' => 'How many total pages to return'
+                       'limit' => 'How many total pages to return',
+                       'interwiki' => 'Include interwiki results in the search, if available'
                );
 
                if ( count( SearchEngine::getSearchTypes() ) > 1 ) {
@@ -370,7 +416,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
        }
 
        public function getDescription() {
-               return 'Perform a full text search';
+               return 'Perform a full text search.';
        }
 
        public function getPossibleErrors() {