Chad has uploaded a new change for review.

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

Change subject: Fix up interwiki search results in API
......................................................................

Fix up interwiki search results in API

getInterwikiResults() returns an array of result objects, not
just a single result object

Change-Id: I4ea3f814c276e6fb9fd2b86ea405047aa3783fc7
---
M includes/api/ApiQuerySearch.php
1 file changed, 39 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/22/176022/1

diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index 66ef8db..c6999df 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -204,47 +204,50 @@
                }
 
                $hasInterwikiResults = false;
+               $totalhits = null;
                if ( $interwiki && $resultPageSet === null && 
$matches->hasInterwikiResults() ) {
-                       $matches = $matches->getInterwikiResults();
-                       $hasInterwikiResults = true;
+                       foreach( $matches->getInterwikiResults() as $matches ) {
+                               $matches = $matches->getInterwikiResults();
+                               $hasInterwikiResults = true;
 
-                       // Include number of results if requested
-                       if ( $resultPageSet === null && isset( 
$searchInfo['totalhits'] ) ) {
-                               $totalhits = $matches->getTotalHits();
-                               if ( $totalhits !== null ) {
-                                       $apiResult->addValue( array( 'query', 
'interwikisearchinfo' ),
-                                               'totalhits', $totalhits );
-                               }
-                       }
-
-                       $result = $matches->next();
-                       while ( $result ) {
-                               $title = $result->getTitle();
-
-                               if ( $resultPageSet === null ) {
-                                       $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;
-                                       }
-                               } else {
-                                       $titles[] = $title;
+                               // Include number of results if requested
+                               if ( $resultPageSet === null && isset( 
$searchInfo['totalhits'] ) ) {
+                                       $totalhits += $matches->getTotalHits();
                                }
 
                                $result = $matches->next();
+                               while ( $result ) {
+                                       $title = $result->getTitle();
+
+                                       if ( $resultPageSet === null ) {
+                                               $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;
+                                               }
+                                       } else {
+                                               $titles[] = $title;
+                                       }
+
+                                       $result = $matches->next();
+                               }
+                       }
+                       if ( $totalhits !== null ) {
+                               $apiResult->addValue( array( 'query', 
'interwikisearchinfo' ),
+                                       'totalhits', $totalhits );
                        }
                }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4ea3f814c276e6fb9fd2b86ea405047aa3783fc7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to