jenkins-bot has submitted this change and it was merged.

Change subject: Fix prefix search for special pages
......................................................................


Fix prefix search for special pages

Prefix search for special pages was returning only the first match.

Change-Id: I5849696de76ca588f7e626d7da319b8bddb3dce9
---
M docs/hooks.txt
M includes/api/ApiOpenSearch.php
2 files changed, 20 insertions(+), 4 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docs/hooks.txt b/docs/hooks.txt
index 0644536..369ad9f 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -409,7 +409,8 @@
 
 'ApiOpenSearchSuggest': Called when constructing the OpenSearch results. Hooks
 can alter or append to the array.
-&$results: array of associative arrays. Keys are:
+&$results: array with integer keys to associative arrays. Keys in associative
+array:
   - title: Title object.
   - redirect from: Title or null.
   - extract: Description for this result.
diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php
index f4b99ae..af09656 100644
--- a/includes/api/ApiOpenSearch.php
+++ b/includes/api/ApiOpenSearch.php
@@ -118,7 +118,7 @@
         * @param int $limit Maximum items to return
         * @param array $namespaces Namespaces to search
         * @param bool $resolveRedir Whether to resolve redirects
-        * @param array &$results Put results here
+        * @param array &$results Put results here. Keys have to be integers.
         */
        protected function search( $search, $limit, $namespaces, $resolveRedir, 
&$results ) {
                // Find matching titles as Title objects
@@ -127,6 +127,11 @@
                if ( !$titles ) {
                        return;
                }
+
+               // Special pages need unique integer ids in the return list, so 
we just
+               // assign them negative numbers because those won't clash with 
the
+               // always positive articleIds that non-special pages get.
+               $nextSpecialPageId = -1;
 
                if ( $resolveRedir ) {
                        // Query for redirects
@@ -161,7 +166,12 @@
                                }
                                if ( !isset( $seen[$ns][$dbkey] ) ) {
                                        $seen[$ns][$dbkey] = true;
-                                       $results[$title->getArticleId()] = 
array(
+                                       $resultId = $title->getArticleId();
+                                       if ( $resultId === 0 ) {
+                                               $resultId = $nextSpecialPageId;
+                                               $nextSpecialPageId -= 1;
+                                       }
+                                       $results[$resultId] = array(
                                                'title' => $title,
                                                'redirect from' => $from,
                                                'extract' => false,
@@ -173,7 +183,12 @@
                        }
                } else {
                        foreach ( $titles as $title ) {
-                               $results[$title->getArticleId()] = array(
+                               $resultId = $title->getArticleId();
+                               if ( $resultId === 0 ) {
+                                       $resultId = $nextSpecialPageId;
+                                       $nextSpecialPageId -= 1;
+                               }
+                               $results[$resultId] = array(
                                        'title' => $title,
                                        'redirect from' => null,
                                        'extract' => false,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5849696de76ca588f7e626d7da319b8bddb3dce9
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Bartosz DziewoƄski <matma....@gmail.com>
Gerrit-Reviewer: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: MZMcBride <w...@mzmcbride.com>
Gerrit-Reviewer: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: PiRSquared17 <pirsquare...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to