X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPrefixSearch.php;h=718750f58ccf497d4a13418084ff3a36f0ba3ac1;hb=d607e6a70bb0250aad5a899aa14b663eb3404766;hp=c5dd698940ac46159ff9b32ac7b9b433e8aedf81;hpb=2e040b99eda6c99cf472b3896f62d2f21315e808;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index c5dd698940..718750f58c 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -29,7 +29,7 @@ abstract class PrefixSearch { /** * Do a prefix search of titles and return a list of matching page names. - * @deprecated: Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes + * @deprecated Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes * * @param string $search * @param int $limit @@ -121,7 +121,7 @@ abstract class PrefixSearch { * @param array $titles * @return array */ - protected abstract function titles( array $titles ); + abstract protected function titles( array $titles ); /** * When implemented in a descendant class, receives an array of titles as strings and returns @@ -131,7 +131,7 @@ abstract class PrefixSearch { * * @return array */ - protected abstract function strings( array $strings ); + abstract protected function strings( array $strings ); /** * Do a prefix search of titles and return a list of matching page names. @@ -166,20 +166,41 @@ abstract class PrefixSearch { protected function specialSearch( $search, $limit ) { global $wgContLang; - # normalize searchKey, so aliases with spaces can be found - bug 25675 - $search = str_replace( ' ', '_', $search ); + $searchParts = explode( '/', $search, 2 ); + $searchKey = $searchParts[0]; + $subpageSearch = isset( $searchParts[1] ) ? $searchParts[1] : null; + + // Handle subpage search separately. + 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 ); + return array_map( function ( $sub ) use ( $specialTitle ) { + return $specialTitle->getSubpage( $sub ); + }, $subpages ); + } else { + return array(); + } + } - $searchKey = $wgContLang->caseFold( $search ); + # normalize searchKey, so aliases with spaces can be found - bug 25675 + $searchKey = str_replace( ' ', '_', $searchKey ); + $searchKey = $wgContLang->caseFold( $searchKey ); // 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; } @@ -296,7 +317,9 @@ class TitlePrefixSearch extends PrefixSearch { class StringPrefixSearch extends PrefixSearch { protected function titles( array $titles ) { - return array_map( function( Title $t ) { return $t->getPrefixedText(); }, $titles ); + return array_map( function ( Title $t ) { + return $t->getPrefixedText(); + }, $titles ); } protected function strings( array $strings ) {