56 $allSearchTerms = [ $searchterm ];
58 if (
$lang->hasVariants() ) {
59 $allSearchTerms = array_unique( array_merge(
61 $lang->autoConvertToAllVariants( $searchterm )
66 if ( !Hooks::run(
'SearchGetNearMatchBefore', [ $allSearchTerms, &$titleResult ] ) ) {
73 if ( $searchterm ===
'' || $searchterm[0] ===
'#' ) {
77 foreach ( $allSearchTerms as
$term ) {
78 # Exact match? No need to look further.
79 $title = Title::newFromText(
$term );
80 if ( is_null( $title ) ) {
84 # Try files if searching in the Media: namespace
85 if ( $title->getNamespace() ==
NS_MEDIA ) {
86 $title = Title::makeTitle(
NS_FILE, $title->getText() );
89 if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
93 # See if it still otherwise has content is some sane sense
94 $page = WikiPage::factory( $title );
95 if ( $page->hasViewableContent() ) {
99 if ( !Hooks::run(
'SearchAfterNoDirectMatch', [
$term, &$title ] ) ) {
103 # Now try all lower case (i.e. first letter capitalized)
104 $title = Title::newFromText(
$lang->lc(
$term ) );
105 if ( $title && $title->exists() ) {
109 # Now try capitalized string
110 $title = Title::newFromText(
$lang->ucwords(
$term ) );
111 if ( $title && $title->exists() ) {
115 # Now try all upper case
116 $title = Title::newFromText(
$lang->uc(
$term ) );
117 if ( $title && $title->exists() ) {
121 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
122 $title = Title::newFromText(
$lang->ucwordbreaks(
$term ) );
123 if ( $title && $title->exists() ) {
129 if ( !Hooks::run(
'SearchGetNearMatch', [
$term, &$title ] ) ) {
134 $title = Title::newFromText( $searchterm );
136 # Entering an IP address goes to the contributions page
137 if ( $this->config->get(
'EnableSearchContributorsByIP' ) ) {
138 if ( ( $title->getNamespace() == NS_USER &&
User::isIP( $title->getText() ) )
140 return SpecialPage::getTitleFor(
'Contributions', $title->getDBkey() );
144 # Entering a user goes to the user page whether it's there or not
145 if ( $title->getNamespace() == NS_USER ) {
149 # Go to images that exist even if there's no local page.
150 # There may have been a funny upload, or it may be on a shared
151 # file repository such as Wikimedia Commons.
152 if ( $title->getNamespace() ==
NS_FILE ) {
159 # MediaWiki namespace? Page may be "implied" if not customized.
160 # Just return it, with caps forced as the message system likes it.
161 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
162 return Title::makeTitle( NS_MEDIAWIKI,
$lang->ucfirst( $title->getText() ) );
165 # Quoted term? Try without the quotes...
167 if ( preg_match(
'/^"([^"]+)"$/', $searchterm,
$matches ) ) {