92 $this->options = $options;
94 $this->language = $contentLanguage;
96 $this->hookRunner =
new HookRunner( $hookContainer );
97 $this->wikiPageFactory = $wikiPageFactory;
98 $this->userNameUtils = $userNameUtils;
99 $this->repoGroup = $repoGroup;
100 $this->titleFactory = $titleFactory;
134 $allSearchTerms = [ $searchterm ];
136 if ( $this->languageConverter->hasVariants() ) {
137 $allSearchTerms = array_unique( array_merge(
139 $this->languageConverter->autoConvertToAllVariants( $searchterm )
144 if ( !$this->hookRunner->onSearchGetNearMatchBefore( $allSearchTerms, $titleResult ) ) {
151 if ( $searchterm ===
'' || $searchterm[0] ===
'#' ) {
155 foreach ( $allSearchTerms as $term ) {
156 # Exact match? No need to look further.
157 $title = $this->titleFactory->newFromText( $term );
158 if ( $title ===
null ) {
162 # Try files if searching in the Media: namespace
163 if ( $title->getNamespace() ===
NS_MEDIA ) {
164 $title = Title::makeTitle(
NS_FILE, $title->getText() );
167 if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
171 # See if it still otherwise has content is some sensible sense
172 if ( $title->canExist() ) {
173 $page = $this->wikiPageFactory->newFromTitle( $title );
174 if ( $page->hasViewableContent() ) {
179 if ( !$this->hookRunner->onSearchAfterNoDirectMatch( $term, $title ) ) {
183 # Now try all lower case (i.e. first letter capitalized)
184 $title = $this->titleFactory->newFromText( $this->language->lc( $term ) );
185 if ( $title && $title->exists() ) {
189 # Now try capitalized string
190 $title = $this->titleFactory->newFromText( $this->language->ucwords( $term ) );
191 if ( $title && $title->exists() ) {
195 # Now try all upper case
196 $title = $this->titleFactory->newFromText( $this->language->uc( $term ) );
197 if ( $title && $title->exists() ) {
201 # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc
202 $title = $this->titleFactory->newFromText( $this->language->ucwordbreaks( $term ) );
203 if ( $title && $title->exists() ) {
210 if ( !$this->hookRunner->onSearchGetNearMatch( $term, $title ) ) {
215 $title = $this->titleFactory->newFromTextThrow( $searchterm );
217 # Entering an IP address goes to the contributions page
219 if ( ( $title->getNamespace() ===
NS_USER && $this->userNameUtils->isIP( $title->getText() ) )
220 || $this->userNameUtils->isIP( trim( $searchterm ) ) ) {
225 # Entering a user goes to the user page whether it's there or not
226 if ( $title->getNamespace() ===
NS_USER ) {
230 # Go to images that exist even if there's no local page.
231 # There may have been a funny upload, or it may be on a shared
232 # file repository such as Wikimedia Commons.
233 if ( $title->getNamespace() ===
NS_FILE ) {
234 $image = $this->repoGroup->findFile( $title );
240 # MediaWiki namespace? Page may be "implied" if not customized.
241 # Just return it, with caps forced as the message system likes it.
243 return Title::makeTitle(
NS_MEDIAWIKI, $this->language->ucfirst( $title->getText() ) );
246 # Quoted term? Try without the quotes...
248 if ( preg_match(
'/^"([^"]+)"$/', $searchterm,
$matches ) ) {