Merge "Fix exception while bubbling titles"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 20 Oct 2014 22:41:25 +0000 (22:41 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 20 Oct 2014 22:41:25 +0000 (22:41 +0000)
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 );
+                                       }
                                }
                        }
                }