Smalyshev has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/324652

Change subject: [WIP] Enable supplying inline interwiki results
......................................................................

[WIP] Enable supplying inline interwiki results

Bug: T142795
Change-Id: I1c14179ee4fb72b6b84772074b6d231d1129ac14
---
M includes/api/ApiQuerySearch.php
1 file changed, 52 insertions(+), 41 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/52/324652/1

diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index 9962d5e..609ee81 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -230,50 +230,20 @@
                        $result = $matches->next();
                }
 
+               // Interwiki results
                $hasInterwikiResults = false;
-               $totalhits = null;
-               if ( $interwiki && $resultPageSet === null && 
$matches->hasInterwikiResults() ) {
-                       foreach ( $matches->getInterwikiResults() as 
$interwikiMatches ) {
-                               $hasInterwikiResults = true;
-
-                               // Include number of results if requested
-                               if ( $resultPageSet === null && isset( 
$searchInfo['totalhits'] ) ) {
-                                       $totalhits += 
$interwikiMatches->getTotalHits();
-                               }
-
-                               $result = $interwikiMatches->next();
-                               while ( $result ) {
-                                       $title = $result->getTitle();
-
-                                       if ( $resultPageSet === null ) {
-                                               $vals = [
-                                                       'namespace' => 
$result->getInterwikiNamespaceText(),
-                                                       'title' => 
$title->getText(),
-                                                       'url' => 
$title->getFullURL(),
-                                               ];
-
-                                               // Add item to results and see 
whether it fits
-                                               $fit = $apiResult->addValue(
-                                                       [ '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;
-                                               }
-                                       } else {
-                                               $titles[] = $title;
-                                       }
-
-                                       $result = $interwikiMatches->next();
+               if ( $interwiki && $resultPageSet === null ) {
+                       if ( $params['enablerewrites'] ) {
+                               $totalhits = $this->addInterwikiResults( 
$matches, $apiResult,
+                                       SearchResultSet::INLINE_RESULTS );
+                               if ( $totalhits ) {
+                                       $hasInterwikiResults = true;
                                }
                        }
-                       if ( $totalhits !== null ) {
-                               $apiResult->addValue( [ 'query', 
'interwikisearchinfo' ],
-                                       'totalhits', $totalhits );
+                       $totalhits = $this->addInterwikiResults( $matches, 
$apiResult,
+                                       SearchResultSet::SECONDARY_RESULTS );
+                       if ( $totalhits ) {
+                               $hasInterwikiResults = true;
                        }
                }
 
@@ -301,6 +271,47 @@
                }
        }
 
+       private function addInterwikiResults( SearchResultSet $matches, 
ApiResult $apiResult,
+                                             $type = 
SearchResultSet::SECONDARY_RESULTS ) {
+               $totalhits = null;
+               if ( $matches->hasInterwikiResults( $type ) ) {
+                       foreach ( $matches->getInterwikiResults( $type ) as 
$interwikiMatches ) {
+                               // Include number of results if requested
+                               $totalhits += $interwikiMatches->getTotalHits();
+
+                               $result = $interwikiMatches->next();
+                               while ( $result ) {
+                                       $title = $result->getTitle();
+
+                                       $vals = [
+                                               'namespace' => 
$result->getInterwikiNamespaceText(),
+                                               'title' => $title->getText(),
+                                               'url' => $title->getFullURL(),
+                                       ];
+
+                                       // Add item to results and see whether 
it fits
+                                       $fit = $apiResult->addValue( [
+                                                       '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 = $interwikiMatches->next();
+                               }
+                       }
+                       if ( $totalhits !== null ) {
+                               $apiResult->addValue( [ 'query', 
'interwikisearchinfo' ], 'totalhits', $totalhits );
+                       }
+               }
+               return $totalhits;
+       }
+
        public function getCacheMode( $params ) {
                return 'public';
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/324652
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c14179ee4fb72b6b84772074b6d231d1129ac14
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <smalys...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to