X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPrefixSearch.php;h=7bc7a084a5ee1896fd1f9cfbf864acd28f7b9941;hb=62c36e82cf424f6ef51b524b2da41ff798111d83;hp=63a4d9c620fec048f75af9d9100c50c356fd2540;hpb=1655c86faf49196f41aca75c8df80c0c4fa4fb90;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index 63a4d9c620..7bc7a084a5 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * Handles searching prefixes of titles and finding any page * names that match. Used largely by the OpenSearch implementation. @@ -81,9 +83,8 @@ abstract class PrefixSearch { // if the content language has variants, try to retrieve fallback results $fallbackLimit = $limit - count( $searches ); if ( $fallbackLimit > 0 ) { - global $wgContLang; - - $fallbackSearches = $wgContLang->autoConvertToAllVariants( $search ); + $fallbackSearches = MediaWikiServices::getInstance()->getContentLanguage()-> + autoConvertToAllVariants( $search ); $fallbackSearches = array_diff( array_unique( $fallbackSearches ), [ $search ] ); foreach ( $fallbackSearches as $fbs ) { @@ -167,20 +168,19 @@ abstract class PrefixSearch { * @return array */ protected function specialSearch( $search, $limit, $offset ) { - global $wgContLang; - $searchParts = explode( '/', $search, 2 ); $searchKey = $searchParts[0]; $subpageSearch = $searchParts[1] ?? null; // Handle subpage search separately. + $spFactory = MediaWikiServices::getInstance()->getSpecialPageFactory(); if ( $subpageSearch !== null ) { // Try matching the full search string as a page name $specialTitle = Title::makeTitleSafe( NS_SPECIAL, $searchKey ); if ( !$specialTitle ) { return []; } - $special = SpecialPageFactory::getPage( $specialTitle->getText() ); + $special = $spFactory->getPage( $specialTitle->getText() ); if ( $special ) { $subpages = $special->prefixSearchSubpages( $subpageSearch, $limit, $offset ); return array_map( function ( $sub ) use ( $specialTitle ) { @@ -192,23 +192,24 @@ abstract class PrefixSearch { } # normalize searchKey, so aliases with spaces can be found - T27675 + $contLang = MediaWikiServices::getInstance()->getContentLanguage(); $searchKey = str_replace( ' ', '_', $searchKey ); - $searchKey = $wgContLang->caseFold( $searchKey ); + $searchKey = $contLang->caseFold( $searchKey ); // Unlike SpecialPage itself, we want the canonical forms of both // canonical and alias title forms... $keys = []; - foreach ( SpecialPageFactory::getNames() as $page ) { - $keys[$wgContLang->caseFold( $page )] = [ 'page' => $page, 'rank' => 0 ]; + foreach ( $spFactory->getNames() as $page ) { + $keys[$contLang->caseFold( $page )] = [ 'page' => $page, 'rank' => 0 ]; } - foreach ( $wgContLang->getSpecialPageAliases() as $page => $aliases ) { - if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# T22885 + foreach ( $contLang->getSpecialPageAliases() as $page => $aliases ) { + if ( !in_array( $page, $spFactory->getNames() ) ) {# T22885 continue; } foreach ( $aliases as $key => $alias ) { - $keys[$wgContLang->caseFold( $alias )] = [ 'page' => $alias, 'rank' => $key ]; + $keys[$contLang->caseFold( $alias )] = [ 'page' => $alias, 'rank' => $key ]; } } ksort( $keys ); @@ -307,10 +308,8 @@ abstract class PrefixSearch { * @return array (default: contains only NS_MAIN) */ protected function validateNamespaces( $namespaces ) { - global $wgContLang; - - // We will look at each given namespace against wgContLang namespaces - $validNamespaces = $wgContLang->getNamespaces(); + // We will look at each given namespace against content language namespaces + $validNamespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces(); if ( is_array( $namespaces ) && count( $namespaces ) > 0 ) { $valid = []; foreach ( $namespaces as $ns ) {