57 $allSearchTerms = [ $searchterm ];
59 if (
$lang->hasVariants() ) {
60 $allSearchTerms = array_unique( array_merge(
62 $lang->autoConvertToAllVariants( $searchterm )
67 if ( !Hooks::run(
'SearchGetNearMatchBefore', [ $allSearchTerms, &$titleResult ] ) ) {
71 foreach ( $allSearchTerms as
$term ) {
72 # Exact match? No need to look further.
73 $title = Title::newFromText(
$term );
74 if ( is_null( $title ) ) {
78 # Try files if searching in the Media: namespace
79 if ( $title->getNamespace() ==
NS_MEDIA ) {
80 $title = Title::makeTitle(
NS_FILE, $title->getText() );
83 if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
87 # See if it still otherwise has content is some sane sense
89 if ( $page->hasViewableContent() ) {
93 if ( !Hooks::run(
'SearchAfterNoDirectMatch', [
$term, &$title ] ) ) {
97 # Now try all lower case (i.e. first letter capitalized)
98 $title = Title::newFromText(
$lang->lc(
$term ) );
99 if ( $title && $title->exists() ) {
103 # Now try capitalized string
104 $title = Title::newFromText(
$lang->ucwords(
$term ) );
105 if ( $title && $title->exists() ) {
109 # Now try all upper case
110 $title = Title::newFromText(
$lang->uc(
$term ) );
111 if ( $title && $title->exists() ) {
115 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
116 $title = Title::newFromText(
$lang->ucwordbreaks(
$term ) );
117 if ( $title && $title->exists() ) {
123 if ( !Hooks::run(
'SearchGetNearMatch', [
$term, &$title ] ) ) {
128 $title = Title::newFromText( $searchterm );
130 # Entering an IP address goes to the contributions page
131 if ( $this->config->get(
'EnableSearchContributorsByIP' ) ) {
132 if ( ( $title->getNamespace() == NS_USER && User::isIP( $title->getText() ) )
133 || User::isIP( trim( $searchterm ) ) ) {
138 # Entering a user goes to the user page whether it's there or not
139 if ( $title->getNamespace() == NS_USER ) {
143 # Go to images that exist even if there's no local page.
144 # There may have been a funny upload, or it may be on a shared
145 # file repository such as Wikimedia Commons.
146 if ( $title->getNamespace() ==
NS_FILE ) {
153 # MediaWiki namespace? Page may be "implied" if not customized.
154 # Just return it, with caps forced as the message system likes it.
155 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
156 return Title::makeTitle( NS_MEDIAWIKI,
$lang->ucfirst( $title->getText() ) );
159 # Quoted term? Try without the quotes...
161 if ( preg_match(
'/^"([^"]+)"$/', $searchterm,
$matches ) ) {