54 $this->language =
$lang;
55 $services = MediaWikiServices::getInstance();
56 $this->languageConverter = $services->getLanguageConverterFactory()
57 ->getLanguageConverter(
$lang );
58 $this->wikiPageFactory = $services->getWikiPageFactory();
59 $this->hookRunner =
new HookRunner( $hookContainer );
60 $this->userNameUtils = $services->getUserNameUtils();
73 $this->hookRunner->onSearchGetNearMatchComplete( $searchterm,
$title );
94 $allSearchTerms = [ $searchterm ];
96 if ( $this->languageConverter->hasVariants() ) {
97 $allSearchTerms = array_unique( array_merge(
99 $this->languageConverter->autoConvertToAllVariants( $searchterm )
104 if ( !$this->hookRunner->onSearchGetNearMatchBefore( $allSearchTerms, $titleResult ) ) {
111 if ( $searchterm ===
'' || $searchterm[0] ===
'#' ) {
115 foreach ( $allSearchTerms as $term ) {
116 # Exact match? No need to look further.
122 # Try files if searching in the Media: namespace
131 # See if it still otherwise has content is some sensible sense
132 if (
$title->canExist() ) {
133 $page = $this->wikiPageFactory->newFromTitle(
$title );
134 if ( $page->hasViewableContent() ) {
139 if ( !$this->hookRunner->onSearchAfterNoDirectMatch( $term,
$title ) ) {
143 # Now try all lower case (i.e. first letter capitalized)
149 # Now try capitalized string
155 # Now try all upper case
161 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
170 if ( !$this->hookRunner->onSearchGetNearMatch( $term,
$title ) ) {
177 # Entering an IP address goes to the contributions page
178 if ( $this->config->get( MainConfigNames::EnableSearchContributorsByIP ) ) {
179 if ( (
$title->getNamespace() ===
NS_USER && $this->userNameUtils->isIP(
$title->getText() ) )
180 || $this->userNameUtils->isIP( trim( $searchterm ) ) ) {
185 # Entering a user goes to the user page whether it's there or not
190 # Go to images that exist even if there's no local page.
191 # There may have been a funny upload, or it may be on a shared
192 # file repository such as Wikimedia Commons.
194 $image = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
$title );
200 # MediaWiki namespace? Page may be "implied" if not customized.
201 # Just return it, with caps forced as the message system likes it.
206 # Quoted term? Try without the quotes...
208 if ( preg_match(
'/^"([^"]+)"$/', $searchterm,
$matches ) ) {
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
A class containing constants representing the names of configuration variables.
Service for creating WikiPage objects.
A ISearchResultSet wrapper for SearchNearMatcher.
Implementation of near match title search.
getNearMatch( $searchterm)
If an exact title match can be found, or a very slightly close match, return the title.
ILanguageConverter $languageConverter
Current language converter.
Language $language
Current language.
UserNameUtils $userNameUtils
getNearMatchInternal( $searchterm)
Really find the title match.
__construct(Config $config, Language $lang, HookContainer $hookContainer)
getNearMatchResultSet( $searchterm)
Do a near match (see SearchEngine::getNearMatch) and wrap it into a ISearchResultSet.
WikiPageFactory $wikiPageFactory
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Interface for configuration instances.
if(!isset( $args[0])) $lang