58 $allSearchTerms = [ $searchterm ];
60 if (
$lang->hasVariants() ) {
61 $allSearchTerms = array_unique( array_merge(
63 $lang->autoConvertToAllVariants( $searchterm )
68 if ( !Hooks::run(
'SearchGetNearMatchBefore', [ $allSearchTerms, &$titleResult ] ) ) {
75 if ( $searchterm ===
'' || $searchterm[0] ===
'#' ) {
79 foreach ( $allSearchTerms as $term ) {
80 # Exact match? No need to look further.
81 $title = Title::newFromText( $term );
86 # Try files if searching in the Media: namespace
95 # See if it still otherwise has content is some sane sense
96 $page = WikiPage::factory(
$title );
97 if ( $page->hasViewableContent() ) {
101 if ( !Hooks::run(
'SearchAfterNoDirectMatch', [ $term, &
$title ] ) ) {
105 # Now try all lower case (i.e. first letter capitalized)
111 # Now try capitalized string
112 $title = Title::newFromText(
$lang->ucwords( $term ) );
117 # Now try all upper case
123 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
124 $title = Title::newFromText(
$lang->ucwordbreaks( $term ) );
131 if ( !Hooks::run(
'SearchGetNearMatch', [ $term, &
$title ] ) ) {
136 $title = Title::newFromText( $searchterm );
138 # Entering an IP address goes to the contributions page
139 if ( $this->config->get(
'EnableSearchContributorsByIP' ) ) {
141 || User::isIP( trim( $searchterm ) ) ) {
142 return SpecialPage::getTitleFor(
'Contributions',
$title->getDBkey() );
146 # Entering a user goes to the user page whether it's there or not
151 # Go to images that exist even if there's no local page.
152 # There may have been a funny upload, or it may be on a shared
153 # file repository such as Wikimedia Commons.
155 $image = MediaWikiServices::getInstance()->getRepoGroup()->findFile(
$title );
161 # MediaWiki namespace? Page may be "implied" if not customized.
162 # Just return it, with caps forced as the message system likes it.
167 # Quoted term? Try without the quotes...
169 if ( preg_match(
'/^"([^"]+)"$/', $searchterm,
$matches ) ) {