Convert SearchResultSet to typical iteration
[lhc/web/wiklou.git] / includes / api / ApiQuerySearch.php
index f0c4180..87913e6 100644 (file)
@@ -1,9 +1,5 @@
 <?php
 /**
- *
- *
- * Created on July 30, 2007
- *
  * Copyright © 2007 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
@@ -146,10 +142,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
                $titles = [];
                $count = 0;
-               $result = $matches->next();
                $limit = $params['limit'];
 
-               while ( $result ) {
+               foreach ( $matches as $result ) {
                        if ( ++$count > $limit ) {
                                // We've reached the one extra which shows that there are
                                // additional items to be had. Stop here...
@@ -159,7 +154,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
 
                        // Silently skip broken and missing titles
                        if ( $result->isBrokenTitle() || $result->isMissingRevision() ) {
-                               $result = $matches->next();
                                continue;
                        }
 
@@ -176,8 +170,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        } else {
                                $titles[] = $result->getTitle();
                        }
-
-                       $result = $matches->next();
                }
 
                // Here we assume interwiki results do not count with
@@ -272,6 +264,16 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                if ( isset( $prop['isfilematch'] ) ) {
                        $vals['isfilematch'] = $result->isFileMatch();
                }
+
+               if ( isset( $prop['extensiondata'] ) ) {
+                       $extra = $result->getExtensionData();
+                       // Add augmented data to the result. The data would be organized as a map:
+                       // augmentorName => data
+                       if ( $extra ) {
+                               $vals['extensiondata'] = ApiResult::addMetadataToResultVars( $extra );
+                       }
+               }
+
                return $vals;
        }
 
@@ -295,8 +297,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                // Include number of results if requested
                                $totalhits += $interwikiMatches->getTotalHits();
 
-                               $result = $interwikiMatches->next();
-                               while ( $result ) {
+                               foreach ( $interwikiMatches as $result ) {
                                        $title = $result->getTitle();
                                        $vals = $this->getSearchResultData( $result, $prop, $terms );
 
@@ -316,8 +317,6 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                                // pagination info so just bail out
                                                break;
                                        }
-
-                                       $result = $interwikiMatches->next();
                                }
                        }
                        if ( $totalhits !== null ) {
@@ -372,6 +371,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                        'categorysnippet',
                                        'score', // deprecated
                                        'hasrelated', // deprecated
+                                       'extensiondata',
                                ],
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_HELP_MSG_PER_VALUE => [],