From 2c121e0f67093c2213000b74a6260cd3fd113660 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 20 Oct 2014 12:17:15 -0400 Subject: [PATCH] Fix exception while bubbling titles 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 | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index fe78e230fa..5df0ce715b 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -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 ); + } } } } -- 2.20.1