summaryrefslogtreecommitdiff
path: root/includes/api/ApiQuerySearch.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/api/ApiQuerySearch.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/api/ApiQuerySearch.php')
-rw-r--r--includes/api/ApiQuerySearch.php165
1 files changed, 74 insertions, 91 deletions
diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index 36b55979..b7dcd0ed 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -39,7 +39,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
*/
const BACKEND_NULL_PARAM = 'database-backed';
- public function __construct( $query, $moduleName ) {
+ public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'sr' );
}
@@ -52,7 +52,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
}
/**
- * @param $resultPageSet ApiPageSet
+ * @param ApiPageSet $resultPageSet
* @return void
*/
private function run( $resultPageSet = null ) {
@@ -63,15 +63,25 @@ 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'] );
+ // Deprecated parameters
+ if ( isset( $prop['hasrelated'] ) ) {
+ $this->logFeatureUsage( 'action=search&srprop=hasrelated' );
+ $this->setWarning( 'srprop=hasrelated has been deprecated' );
+ }
+ if ( isset( $prop['score'] ) ) {
+ $this->logFeatureUsage( 'action=search&srprop=score' );
+ $this->setWarning( 'srprop=score has been deprecated' );
+ }
+
// Create search engine instance and set options
$search = isset( $params['backend'] ) && $params['backend'] != self::BACKEND_NULL_PARAM ?
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 );
@@ -112,12 +122,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 +137,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;
}
@@ -156,9 +167,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
if ( isset( $prop['timestamp'] ) ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $result->getTimestamp() );
}
- if ( !is_null( $result->getScore() ) && isset( $prop['score'] ) ) {
- $vals['score'] = $result->getScore();
- }
if ( isset( $prop['titlesnippet'] ) ) {
$vals['titlesnippet'] = $result->getTitleSnippet( $terms );
}
@@ -178,13 +186,10 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
$vals['sectionsnippet'] = $result->getSectionSnippet();
}
}
- if ( isset( $prop['hasrelated'] ) && $result->hasRelated() ) {
- $vals['hasrelated'] = '';
- }
// 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 +201,55 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
$result = $matches->next();
}
+ $hasInterwikiResults = false;
+ if ( $interwiki && $resultPageSet === null && $matches->hasInterwikiResults() ) {
+ $matches = $matches->getInterwikiResults();
+ $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 );
}
@@ -210,8 +260,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
}
public function getAllowedParams() {
- global $wgSearchType;
-
$params = array(
'search' => array(
ApiBase::PARAM_TYPE => 'string',
@@ -255,7 +303,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
),
ApiBase::PARAM_ISMULTI => true,
),
- 'redirects' => false,
'offset' => 0,
'limit' => array(
ApiBase::PARAM_DFLT => 10,
@@ -263,7 +310,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();
@@ -272,7 +320,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
$alternatives[0] = self::BACKEND_NULL_PARAM;
}
$params['backend'] = array(
- ApiBase::PARAM_DFLT => $wgSearchType,
+ ApiBase::PARAM_DFLT => $this->getConfig()->get( 'SearchType' ),
ApiBase::PARAM_TYPE => $alternatives,
);
}
@@ -291,18 +339,18 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
' size - Adds the size of the page in bytes',
' wordcount - Adds the word count of the page',
' timestamp - Adds the timestamp of when the page was last edited',
- ' score - Adds the score (if any) from the search engine',
+ ' score - DEPRECATED and IGNORED',
' snippet - Adds a parsed snippet of the page',
' titlesnippet - Adds a parsed snippet of the page title',
' redirectsnippet - Adds a parsed snippet of the redirect title',
' redirecttitle - Adds the title of the matching redirect',
' sectionsnippet - Adds a parsed snippet of the matching section title',
' sectiontitle - Adds the title of the matching section',
- ' hasrelated - Indicates whether a related search is available',
+ ' hasrelated - DEPRECATED and IGNORED',
),
- '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 ) {
@@ -312,73 +360,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
return $descriptions;
}
- public function getResultProperties() {
- return array(
- '' => array(
- 'ns' => 'namespace',
- 'title' => 'string'
- ),
- 'snippet' => array(
- 'snippet' => 'string'
- ),
- 'size' => array(
- 'size' => 'integer'
- ),
- 'wordcount' => array(
- 'wordcount' => 'integer'
- ),
- 'timestamp' => array(
- 'timestamp' => 'timestamp'
- ),
- 'score' => array(
- 'score' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'titlesnippet' => array(
- 'titlesnippet' => 'string'
- ),
- 'redirecttitle' => array(
- 'redirecttitle' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'redirectsnippet' => array(
- 'redirectsnippet' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'sectiontitle' => array(
- 'sectiontitle' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'sectionsnippet' => array(
- 'sectionsnippet' => array(
- ApiBase::PROP_TYPE => 'string',
- ApiBase::PROP_NULLABLE => true
- )
- ),
- 'hasrelated' => array(
- 'hasrelated' => 'boolean'
- )
- );
- }
-
public function getDescription() {
- return 'Perform a full text search';
- }
-
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'code' => 'search-text-disabled', 'info' => 'text search is disabled' ),
- array( 'code' => 'search-title-disabled', 'info' => 'title search is disabled' ),
- array( 'code' => 'search-error', 'info' => 'search error has occurred' ),
- ) );
+ return 'Perform a full text search.';
}
public function getExamples() {