Fix exception while bubbling titles
authorNik Everett <neverett@wikimedia.org>
Mon, 20 Oct 2014 16:17:15 +0000 (12:17 -0400)
committerNik Everett <neverett@wikimedia.org>
Mon, 20 Oct 2014 16:32:36 +0000 (12:32 -0400)
In prefix search if the search text is actually a title we make sure it is at
the top of the results.  But if it isn't a valid title we shouldn't blow up
because blowing up is bad.

Bug: 72260
Change-Id: I5bd795df447a33bb003a38ec2068dc184379a813

includes/PrefixSearch.php

index fe78e23..5df0ce7 100644 (file)
@@ -159,19 +159,21 @@ abstract class PrefixSearch {
                        // Pick namespace (based on PrefixSearch::defaultSearchBackend)
                        $ns = in_array( NS_MAIN, $namespaces ) ? NS_MAIN : $namespaces[0];
                        $t = Title::newFromText( $search, $ns );
-                       $string = $t->getPrefixedText();
-
-                       $key = array_search( $string, $srchres );
-                       if ( $key !== false ) {
-                               // Move it to the front
-                               $cut = array_splice( $srchres, $key, 1 );
-                               array_unshift( $srchres, $cut[0] );
-                       } elseif ( $t->exists() ) {
-                               // Add it in front
-                               array_unshift( $srchres, $string );
-
-                               if ( count( $srchres ) > $limit ) {
-                                       array_pop( $srchres );
+                       if ( $t ) {
+                               // If text is a valid title and is in the search results
+                               $string = $t->getPrefixedText();
+                               $key = array_search( $string, $srchres );
+                               if ( $key !== false ) {
+                                       // Move it to the front
+                                       $cut = array_splice( $srchres, $key, 1 );
+                                       array_unshift( $srchres, $cut[0] );
+                               } elseif ( $t->exists() ) {
+                                       // Add it in front
+                                       array_unshift( $srchres, $string );
+
+                                       if ( count( $srchres ) > $limit ) {
+                                               array_pop( $srchres );
+                                       }
                                }
                        }
                }