Merge "Add configuration for running etsy/phan against core"
[lhc/web/wiklou.git] / includes / api / ApiQuerySearch.php
index f46b5d2..64bc43f 100644 (file)
@@ -24,8 +24,6 @@
  * @file
  */
 
-use MediaWiki\MediaWikiServices;
-
 /**
  * Query module to perform full text search within wiki titles and content
  *
@@ -66,17 +64,20 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
 
                // Deprecated parameters
                if ( isset( $prop['hasrelated'] ) ) {
-                       $this->logFeatureUsage( 'action=search&srprop=hasrelated' );
-                       $this->setWarning( 'srprop=hasrelated has been deprecated' );
+                       $this->addDeprecation(
+                               [ 'apiwarn-deprecation-parameter', 'srprop=hasrelated' ], 'action=search&srprop=hasrelated'
+                       );
                }
                if ( isset( $prop['score'] ) ) {
-                       $this->logFeatureUsage( 'action=search&srprop=score' );
-                       $this->setWarning( 'srprop=score has been deprecated' );
+                       $this->addDeprecation(
+                               [ 'apiwarn-deprecation-parameter', 'srprop=score' ], 'action=search&srprop=score'
+                       );
                }
 
                // Create search engine instance and set options
                $search = $this->buildSearchEngine( $params );
                $search->setFeatureData( 'rewrite', (bool)$params['enablerewrites'] );
+               $search->setFeatureData( 'interwiki', (bool)$interwiki );
 
                $query = $search->transformSearchTerm( $query );
                $query = $search->replacePrefixes( $query );
@@ -108,10 +109,25 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                $matches = $search->searchText( $query );
                        }
                }
-               if ( is_null( $matches ) ) {
-                       $this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" );
-               } elseif ( $matches instanceof Status && !$matches->isGood() ) {
-                       $this->dieUsage( $matches->getWikiText( false, false, 'en' ), 'search-error' );
+
+               if ( $matches instanceof Status ) {
+                       $status = $matches;
+                       $matches = $status->getValue();
+               } else {
+                       $status = null;
+               }
+
+               if ( $status ) {
+                       if ( $status->isOK() ) {
+                               $this->getMain()->getErrorFormatter()->addMessagesFromStatus(
+                                       $this->getModuleName(),
+                                       $status
+                               );
+                       } else {
+                               $this->dieStatus( $status );
+                       }
+               } elseif ( is_null( $matches ) ) {
+                       $this->dieWithError( [ 'apierror-searchdisabled', $what ], "search-{$what}-disabled" );
                }
 
                if ( $resultPageSet === null ) {
@@ -235,7 +251,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                                $vals = [
                                                        'namespace' => $result->getInterwikiNamespaceText(),
                                                        'title' => $title->getText(),
-                                                       'url' => $title->getFullUrl(),
+                                                       'url' => $title->getFullURL(),
                                                ];
 
                                                // Add item to results and see whether it fits