From: Nik Everett Date: Mon, 20 Oct 2014 16:17:15 +0000 (-0400) Subject: Fix exception while bubbling titles X-Git-Tag: 1.31.0-rc.0~13550^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22messagerie%22%29%20.%20%22?a=commitdiff_plain;h=2c121e0f67093c2213000b74a6260cd3fd113660;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 ); + } } } }