Merge "Make enhanced recent changes and extended watchlist default"
[lhc/web/wiklou.git] / includes / PrefixSearch.php
index 35be2a9..fe78e23 100644 (file)
@@ -63,8 +63,7 @@ abstract class PrefixSearch {
                        if ( $ns[0] == NS_MAIN ) {
                                $ns = $namespaces; // no explicit prefix, use default namespaces
                        }
-                       return $this->searchBackend(
-                               $ns, $title->getText(), $limit );
+                       return $this->searchBackend( $ns, $title->getText(), $limit );
                }
 
                // Is this a namespace prefix?
@@ -152,7 +151,31 @@ abstract class PrefixSearch {
                $srchres = array();
                if ( wfRunHooks( 'PrefixSearchBackend', array( $namespaces, $search, $limit, &$srchres ) ) ) {
                        return $this->titles( $this->defaultSearchBackend( $namespaces, $search, $limit ) );
+               } else {
+                       // Default search backend does proper prefix searching, but custom backends
+                       // may sort based on other algorythms that may cause the exact title match
+                       // to not be in the results or be lower down the list.
+
+                       // 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 );
+                               }
+                       }
                }
+
                return $this->strings( $srchres );
        }
 
@@ -174,6 +197,9 @@ abstract class PrefixSearch {
                if ( $subpageSearch !== null ) {
                        // Try matching the full search string as a page name
                        $specialTitle = Title::makeTitleSafe( NS_SPECIAL, $searchKey );
+                       if ( !$specialTitle ) {
+                               return array();
+                       }
                        $special = SpecialPageFactory::getPage( $specialTitle->getText() );
                        if ( $special ) {
                                $subpages = $special->prefixSearchSubpages( $subpageSearch, $limit );
@@ -192,12 +218,12 @@ abstract class PrefixSearch {
                // Unlike SpecialPage itself, we want the canonical forms of both
                // canonical and alias title forms...
                $keys = array();
-               foreach ( SpecialPageFactory::getList() as $page => $class ) {
+               foreach ( SpecialPageFactory::getNames() as $page ) {
                        $keys[$wgContLang->caseFold( $page )] = $page;
                }
 
                foreach ( $wgContLang->getSpecialPageAliases() as $page => $aliases ) {
-                       if ( !array_key_exists( $page, SpecialPageFactory::getList() ) ) {# bug 20885
+                       if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# bug 20885
                                continue;
                        }