X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQuerySearch.php;h=a2a15e0fb54cc9164511d1b3ee401e1909d19809;hb=63ba8bca85ccb953fccfc5cb54c68df83793654d;hp=4fedebce6799e16d2a8477f248f2b62b99edd1d4;hpb=aa3499760344aca3d5f75800628104afc1cd65e8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 4fedebce67..a2a15e0fb5 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -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'] ); @@ -71,7 +72,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { SearchEngine::create( $params['backend'] ) : SearchEngine::create(); $search->setLimitOffset( $limit + 1, $params['offset'] ); $search->setNamespaces( $params['namespace'] ); - $search->showRedirects = $params['redirects']; $query = $search->transformSearchTerm( $query ); $query = $search->replacePrefixes( $query ); @@ -197,10 +197,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' ); + if ( $hasInterwikiResults ) { + $apiResult->setIndexedTagName_internal( array( + 'query', 'interwiki' . $this->getModuleName() + ), 'p' ); + } } else { $resultPageSet->populateFromTitles( $titles ); } @@ -256,7 +298,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ), ApiBase::PARAM_ISMULTI => true, ), - 'redirects' => false, 'offset' => 0, 'limit' => array( ApiBase::PARAM_DFLT => 10, @@ -264,7 +305,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(); @@ -301,9 +343,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ' sectiontitle - Adds the title of the matching section', ' hasrelated - Indicates whether a related search is available', ), - '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 ) { @@ -371,7 +413,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } public function getDescription() { - return 'Perform a full text search'; + return 'Perform a full text search.'; } public function getPossibleErrors() {