X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPrefixSearch.php;h=839fedcd1579bd7e6d505c9639f80481e7fa3e36;hb=506358f46007ebc7849d73f63f283bb19958ef66;hp=fe78e230fae1fd5c8f2bb3319dca8d30e809a4c6;hpb=5c115a77890ce370d04eafd89005a028b9de8a40;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index fe78e230fa..839fedcd15 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -60,10 +60,12 @@ abstract class PrefixSearch { $title = Title::newFromText( $search ); if ( $title && !$title->isExternal() ) { $ns = array( $title->getNamespace() ); + $search = $title->getText(); if ( $ns[0] == NS_MAIN ) { $ns = $namespaces; // no explicit prefix, use default namespaces + wfRunHooks( 'PrefixSearchExtractNamespace', array( &$ns, &$search ) ); } - return $this->searchBackend( $ns, $title->getText(), $limit ); + return $this->searchBackend( $ns, $search, $limit ); } // Is this a namespace prefix? @@ -74,6 +76,8 @@ abstract class PrefixSearch { { $namespaces = array( $title->getNamespace() ); $search = ''; + } else { + wfRunHooks( 'PrefixSearchExtractNamespace', array( &$namespaces, &$search ) ); } return $this->searchBackend( $namespaces, $search, $limit ); @@ -159,19 +163,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 ); + } } } }