MediaWiki  master
SpecialSearch.php
Go to the documentation of this file.
1 <?php
36 
41 class SpecialSearch extends SpecialPage {
50  protected $profile;
51 
53  protected $searchEngine;
54 
56  protected $searchEngineType = null;
57 
59  protected $extraParams = [];
60 
65  protected $mPrefix;
66 
70  protected $limit, $offset;
71 
75  protected $namespaces;
76 
80  protected $fulltext;
81 
86 
90  protected $runSuggestion = true;
91 
96  protected $searchConfig;
97 
100 
102  private $nsInfo;
103 
106 
109 
111  private $readOnlyMode;
112 
115 
118 
123  private $loadStatus;
124 
125  private const NAMESPACES_CURRENT = 'sense';
126 
137  public function __construct(
146  ) {
147  parent::__construct( 'Search' );
148  $this->searchConfig = $searchConfig;
149  $this->searchEngineFactory = $searchEngineFactory;
150  $this->nsInfo = $nsInfo;
151  $this->contentHandlerFactory = $contentHandlerFactory;
152  $this->interwikiLookup = $interwikiLookup;
153  $this->readOnlyMode = $readOnlyMode;
154  $this->userOptionsManager = $userOptionsManager;
155  $this->languageConverterFactory = $languageConverterFactory;
156  }
157 
163  public function execute( $par ) {
164  $request = $this->getRequest();
165  $out = $this->getOutput();
166 
167  // Fetch the search term
168  $term = str_replace( "\n", " ", $request->getText( 'search' ) );
169 
170  // Historically search terms have been accepted not only in the search query
171  // parameter, but also as part of the primary url. This can have PII implications
172  // in releasing page view data. As such issue a 301 redirect to the correct
173  // URL.
174  if ( $par !== null && $par !== '' && $term === '' ) {
175  $query = $request->getValues();
176  unset( $query['title'] );
177  // Strip underscores from title parameter; most of the time we'll want
178  // text form here. But don't strip underscores from actual text params!
179  $query['search'] = str_replace( '_', ' ', $par );
180  $out->redirect( $this->getPageTitle()->getFullURL( $query ), 301 );
181  return;
182  }
183 
184  // Need to load selected namespaces before handling nsRemember
185  $this->load();
186  // TODO: This performs database actions on GET request, which is going to
187  // be a problem for our multi-datacenter work.
188  if ( $request->getCheck( 'nsRemember' ) ) {
189  $this->saveNamespaces();
190  // Remove the token from the URL to prevent the user from inadvertently
191  // exposing it (e.g. by pasting it into a public wiki page) or undoing
192  // later settings changes (e.g. by reloading the page).
193  $query = $request->getValues();
194  unset( $query['title'], $query['nsRemember'] );
195  $out->redirect( $this->getPageTitle()->getFullURL( $query ) );
196  return;
197  }
198 
199  if ( !$request->getVal( 'fulltext' ) && !$request->getCheck( 'offset' ) ) {
200  $url = $this->goResult( $term );
201  if ( $url !== null ) {
202  // successful 'go'
203  $out->redirect( $url );
204  return;
205  }
206  // No match. If it could plausibly be a title
207  // run the No go match hook.
208  $title = Title::newFromText( $term );
209  if ( $title !== null ) {
210  $this->getHookRunner()->onSpecialSearchNogomatch( $title );
211  }
212  }
213 
214  $this->setupPage( $term );
215 
216  if ( $this->getConfig()->get( 'DisableTextSearch' ) ) {
217  $searchForwardUrl = $this->getConfig()->get( 'SearchForwardUrl' );
218  if ( $searchForwardUrl ) {
219  $url = str_replace( '$1', urlencode( $term ), $searchForwardUrl );
220  $out->redirect( $url );
221  } else {
222  $out->addHTML( $this->showGoogleSearch( $term ) );
223  }
224 
225  return;
226  }
227 
228  $this->showResults( $term );
229  }
230 
239  private function showGoogleSearch( $term ) {
240  return "<fieldset>" .
241  "<legend>" .
242  $this->msg( 'search-external' )->escaped() .
243  "</legend>" .
244  "<p class='mw-searchdisabled'>" .
245  $this->msg( 'searchdisabled' )->escaped() .
246  "</p>" .
247  // googlesearch is part of $wgRawHtmlMessages and safe to use as is here
248  $this->msg( 'googlesearch' )->rawParams(
249  htmlspecialchars( $term ),
250  'UTF-8',
251  $this->msg( 'searchbutton' )->escaped()
252  )->text() .
253  "</fieldset>";
254  }
255 
261  public function load() {
262  $this->loadStatus = new Status();
263 
264  $request = $this->getRequest();
265  $this->searchEngineType = $request->getVal( 'srbackend' );
266 
267  list( $this->limit, $this->offset ) = $request->getLimitOffsetForUser(
268  $this->getUser(),
269  20,
270  ''
271  );
272  $this->mPrefix = $request->getVal( 'prefix', '' );
273  if ( $this->mPrefix !== '' ) {
274  $this->setExtraParam( 'prefix', $this->mPrefix );
275  }
276 
277  $sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT );
278  $validSorts = $this->getSearchEngine()->getValidSorts();
279  if ( !in_array( $sort, $validSorts ) ) {
280  $this->loadStatus->warning( 'search-invalid-sort-order', $sort,
281  implode( ', ', $validSorts ) );
282  } elseif ( $sort !== $this->sort ) {
283  $this->sort = $sort;
284  $this->setExtraParam( 'sort', $this->sort );
285  }
286 
287  $user = $this->getUser();
288 
289  # Extract manually requested namespaces
290  $nslist = $this->powerSearch( $request );
291  if ( $nslist === [] ) {
292  # Fallback to user preference
293  $nslist = $this->searchConfig->userNamespaces( $user );
294  }
295 
296  $profile = null;
297  if ( $nslist === [] ) {
298  $profile = 'default';
299  }
300 
301  $profile = $request->getVal( 'profile', $profile );
302  $profiles = $this->getSearchProfiles();
303  if ( $profile === null ) {
304  // BC with old request format
305  $profile = 'advanced';
306  foreach ( $profiles as $key => $data ) {
307  if ( $nslist === $data['namespaces'] && $key !== 'advanced' ) {
308  $profile = $key;
309  }
310  }
311  $this->namespaces = $nslist;
312  } elseif ( $profile === 'advanced' ) {
313  $this->namespaces = $nslist;
314  } elseif ( isset( $profiles[$profile]['namespaces'] ) ) {
315  $this->namespaces = $profiles[$profile]['namespaces'];
316  } else {
317  // Unknown profile requested
318  $this->loadStatus->warning( 'search-unknown-profile', $profile );
319  $profile = 'default';
320  $this->namespaces = $profiles['default']['namespaces'];
321  }
322 
323  $this->fulltext = $request->getVal( 'fulltext' );
324  $this->runSuggestion = (bool)$request->getVal( 'runsuggestion', true );
325  $this->profile = $profile;
326  }
327 
334  public function goResult( $term ) {
335  # If the string cannot be used to create a title
336  if ( Title::newFromText( $term ) === null ) {
337  return null;
338  }
339  # If there's an exact or very near match, jump right there.
340  $title = $this->getSearchEngine()
341  ->getNearMatcher( $this->getConfig() )->getNearMatch( $term );
342  if ( $title === null ) {
343  return null;
344  }
345  $url = null;
346  if ( !$this->getHookRunner()->onSpecialSearchGoResult( $term, $title, $url ) ) {
347  return null;
348  }
349 
350  if (
351  // If there is a preference set to NOT redirect on exact page match
352  // then return null (which prevents direction)
353  !$this->redirectOnExactMatch()
354  // BUT ...
355  // ... ignore no-redirect preference if the exact page match is an interwiki link
356  && !$title->isExternal()
357  // ... ignore no-redirect preference if the exact page match is NOT in the main
358  // namespace AND there's a namespace in the search string
359  && !( $title->getNamespace() !== NS_MAIN && strpos( $term, ':' ) > 0 )
360  ) {
361  return null;
362  }
363 
364  return $url ?? $title->getFullUrlForRedirect();
365  }
366 
367  private function redirectOnExactMatch() {
370  // If the preference for whether to redirect is disabled, use the default setting
371  $defaultOptions = $this->userOptionsManager->getDefaultOptions();
372  return $defaultOptions['search-match-redirect'];
373  } else {
374  // Otherwise use the user's preference
375  return $this->userOptionsManager->getOption( $this->getUser(), 'search-match-redirect' );
376  }
377  }
378 
382  public function showResults( $term ) {
383  if ( $this->searchEngineType !== null ) {
384  $this->setExtraParam( 'srbackend', $this->searchEngineType );
385  }
386 
387  $out = $this->getOutput();
388  $widgetOptions = $this->getConfig()->get( 'SpecialSearchFormOptions' );
390  $this,
391  $this->searchConfig,
392  $this->getHookContainer(),
393  $this->getSearchProfiles()
394  );
395  $filePrefix = $this->getContentLanguage()->getFormattedNsText( NS_FILE ) . ':';
396  if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
397  // Empty query -- straight view of search form
398  if ( !$this->getHookRunner()->onSpecialSearchResultsPrepend( $this, $out, $term ) ) {
399  # Hook requested termination
400  return;
401  }
402  $out->enableOOUI();
403  // The form also contains the 'Showing results 0 - 20 of 1234' so we can
404  // only do the form render here for the empty $term case. Rendering
405  // the form when a search is provided is repeated below.
406  $out->addHTML( $formWidget->render(
407  $this->profile, $term, 0, 0, $this->offset, $this->isPowerSearch(), $widgetOptions
408  ) );
409  return;
410  }
411 
412  $engine = $this->getSearchEngine();
413  $engine->setFeatureData( 'rewrite', $this->runSuggestion );
414  $engine->setLimitOffset( $this->limit, $this->offset );
415  $engine->setNamespaces( $this->namespaces );
416  $engine->setSort( $this->sort );
417  $engine->prefix = $this->mPrefix;
418 
419  $this->getHookRunner()->onSpecialSearchSetupEngine( $this, $this->profile, $engine );
420  if ( !$this->getHookRunner()->onSpecialSearchResultsPrepend( $this, $out, $term ) ) {
421  # Hook requested termination
422  return;
423  }
424 
425  $title = Title::newFromText( $term );
426  $languageConverter = $this->languageConverterFactory->getLanguageConverter();
427  if ( $languageConverter->hasVariants() ) {
428  // findVariantLink will replace the link arg as well but we want to keep our original
429  // search string, use a copy in the $variantTerm var so that $term remains intact.
430  $variantTerm = $term;
431  $languageConverter->findVariantLink( $variantTerm, $title );
432  }
433 
434  $showSuggestion = $title === null || !$title->isKnown();
435  $engine->setShowSuggestion( $showSuggestion );
436 
437  $rewritten = $engine->replacePrefixes( $term );
438  if ( $rewritten !== $term ) {
439  wfDeprecatedMsg( 'SearchEngine::replacePrefixes() was overridden by ' .
440  get_class( $engine ) . ', this is deprecated since MediaWiki 1.32',
441  '1.32', false, false );
442  }
443 
444  // fetch search results
445  $titleMatches = $engine->searchTitle( $rewritten );
446  $textMatches = $engine->searchText( $rewritten );
447 
448  $textStatus = null;
449  if ( $textMatches instanceof Status ) {
450  $textStatus = $textMatches;
451  $textMatches = $textStatus->getValue();
452  }
453 
454  // Get number of results
455  $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
456  if ( $titleMatches ) {
457  $titleMatchesNum = $titleMatches->numRows();
458  $numTitleMatches = $titleMatches->getTotalHits();
459  }
460  if ( $textMatches ) {
461  $textMatchesNum = $textMatches->numRows();
462  $numTextMatches = $textMatches->getTotalHits();
463  if ( $textMatchesNum > 0 ) {
464  $engine->augmentSearchResults( $textMatches );
465  }
466  }
467  $num = $titleMatchesNum + $textMatchesNum;
468  $totalRes = $numTitleMatches + $numTextMatches;
469 
470  // start rendering the page
471  $out->enableOOUI();
472  $out->addHTML( $formWidget->render(
473  $this->profile, $term, $num, $totalRes, $this->offset, $this->isPowerSearch(), $widgetOptions
474  ) );
475 
476  // did you mean... suggestions
477  if ( $textMatches ) {
478  $dymWidget = new MediaWiki\Search\SearchWidgets\DidYouMeanWidget( $this );
479  $out->addHTML( $dymWidget->render( $term, $textMatches ) );
480  }
481 
482  $hasSearchErrors = $textStatus && $textStatus->getErrors() !== [];
483  $hasOtherResults = $textMatches &&
484  $textMatches->hasInterwikiResults( ISearchResultSet::INLINE_RESULTS );
485 
486  if ( $textMatches && $textMatches->hasInterwikiResults( ISearchResultSet::SECONDARY_RESULTS ) ) {
487  $out->addHTML( '<div class="searchresults mw-searchresults-has-iw">' );
488  } else {
489  $out->addHTML( '<div class="searchresults">' );
490  }
491 
492  if ( $hasSearchErrors || $this->loadStatus->getErrors() ) {
493  if ( $textStatus === null ) {
494  $textStatus = $this->loadStatus;
495  } else {
496  $textStatus->merge( $this->loadStatus );
497  }
498  list( $error, $warning ) = $textStatus->splitByErrorType();
499  if ( $error->getErrors() ) {
500  $out->addHTML( Html::errorBox(
501  $error->getHTML( 'search-error' )
502  ) );
503  }
504  if ( $warning->getErrors() ) {
505  $out->addHTML( Html::warningBox(
506  $warning->getHTML( 'search-warning' )
507  ) );
508  }
509  }
510 
511  // Show the create link ahead
512  $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
513 
514  $this->getHookRunner()->onSpecialSearchResults( $term, $titleMatches, $textMatches );
515 
516  // If we have no results and have not already displayed an error message
517  if ( $num === 0 && !$hasSearchErrors ) {
518  $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", [
519  $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
520  wfEscapeWikiText( $term ),
521  $term,
522  ] );
523  }
524 
525  // Although $num might be 0 there can still be secondary or inline
526  // results to display.
527  $linkRenderer = $this->getLinkRenderer();
528  $mainResultWidget = new FullSearchResultWidget(
529  $this, $linkRenderer, $this->getHookContainer() );
530 
531  // Default (null) on. Can be explicitly disabled.
532  if ( $engine->getFeatureData( 'enable-new-crossproject-page' ) !== false ) {
533  $sidebarResultWidget = new InterwikiSearchResultWidget( $this, $linkRenderer );
534  $sidebarResultsWidget = new InterwikiSearchResultSetWidget(
535  $this,
536  $sidebarResultWidget,
538  $this->interwikiLookup,
539  $engine->getFeatureData( 'show-multimedia-search-results' )
540  );
541  } else {
542  $sidebarResultWidget = new SimpleSearchResultWidget( $this, $linkRenderer );
543  $sidebarResultsWidget = new SimpleSearchResultSetWidget(
544  $this,
545  $sidebarResultWidget,
547  $this->interwikiLookup
548  );
549  }
550 
551  $widget = new BasicSearchResultSetWidget( $this, $mainResultWidget, $sidebarResultsWidget );
552 
553  $out->addHTML( $widget->render(
554  $term, $this->offset, $titleMatches, $textMatches
555  ) );
556 
557  $out->addHTML( '<div class="mw-search-visualclear"></div>' );
558  $this->prevNextLinks( $totalRes, $textMatches, $term, $out );
559 
560  // Close <div class='searchresults'>
561  $out->addHTML( "</div>" );
562 
563  $this->getHookRunner()->onSpecialSearchResultsAppend( $this, $out, $term );
564  }
565 
572  protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
573  // show direct page/create link if applicable
574 
575  // Check DBkey !== '' in case of fragment link only.
576  if ( $title === null || $title->getDBkey() === ''
577  || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
578  || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
579  ) {
580  // invalid title
581  // preserve the paragraph for margins etc...
582  $this->getOutput()->addHTML( '<p></p>' );
583 
584  return;
585  }
586 
587  $messageName = 'searchmenu-new-nocreate';
588  $linkClass = 'mw-search-createlink';
589 
590  if ( !$title->isExternal() ) {
591  if ( $title->isKnown() ) {
592  $messageName = 'searchmenu-exists';
593  $linkClass = 'mw-search-exists';
594  } elseif (
595  $this->contentHandlerFactory->getContentHandler( $title->getContentModel() )
596  ->supportsDirectEditing()
597  && $this->getAuthority()->probablyCan( 'create', $title )
598  && $this->getAuthority()->probablyCan( 'edit', $title )
599  ) {
600  $messageName = 'searchmenu-new';
601  }
602  }
603 
604  $params = [
605  $messageName,
606  wfEscapeWikiText( $title->getPrefixedText() ),
607  Message::numParam( $num )
608  ];
609  $this->getHookRunner()->onSpecialSearchCreateLink( $title, $params );
610 
611  // Extensions using the hook might still return an empty $messageName
612  // @phan-suppress-next-line PhanRedundantCondition Set by hook
613  if ( $messageName ) {
614  $this->getOutput()->wrapWikiMsg( "<p class=\"$linkClass\">\n$1</p>", $params );
615  } else {
616  // preserve the paragraph for margins etc...
617  $this->getOutput()->addHTML( '<p></p>' );
618  }
619  }
620 
627  protected function setupPage( $term ) {
628  $out = $this->getOutput();
629 
630  $this->setHeaders();
631  $this->outputHeader();
632  // TODO: Is this true? The namespace remember uses a user token
633  // on save.
634  $out->allowClickjacking();
635  $this->addHelpLink( 'Help:Searching' );
636 
637  if ( strval( $term ) !== '' ) {
638  $out->setPageTitle( $this->msg( 'searchresults' ) );
639  $out->setHTMLTitle( $this->msg( 'pagetitle' )
640  ->plaintextParams( $this->msg( 'searchresults-title' )->plaintextParams( $term )->text() )
641  ->inContentLanguage()->text()
642  );
643  }
644 
645  if ( $this->mPrefix !== '' ) {
646  $subtitle = $this->msg( 'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
647  $params = $this->powerSearchOptions();
648  unset( $params['prefix'] );
649  $params += [
650  'search' => $term,
651  'fulltext' => 1,
652  ];
653 
654  $subtitle .= ' (';
655  $subtitle .= Xml::element(
656  'a',
657  [
658  'href' => $this->getPageTitle()->getLocalURL( $params ),
659  'title' => $this->msg( 'search-filter-title-prefix-reset' )->text(),
660  ],
661  $this->msg( 'search-filter-title-prefix-reset' )->text()
662  );
663  $subtitle .= ')';
664  $out->setSubtitle( $subtitle );
665  }
666 
667  $out->addJsConfigVars( [ 'searchTerm' => $term ] );
668  $out->addModules( 'mediawiki.special.search' );
669  $out->addModuleStyles( [
670  'mediawiki.special', 'mediawiki.special.search.styles', 'mediawiki.ui', 'mediawiki.ui.button',
671  'mediawiki.ui.input', 'mediawiki.widgets.SearchInputWidget.styles',
672  ] );
673  }
674 
680  protected function isPowerSearch() {
681  return $this->profile === 'advanced';
682  }
683 
691  protected function powerSearch( &$request ) {
692  $arr = [];
693  foreach ( $this->searchConfig->searchableNamespaces() as $ns => $name ) {
694  if ( $request->getCheck( 'ns' . $ns ) ) {
695  $arr[] = $ns;
696  }
697  }
698 
699  return $arr;
700  }
701 
709  public function powerSearchOptions() {
710  $opt = [];
711  if ( $this->isPowerSearch() ) {
712  foreach ( $this->namespaces as $n ) {
713  $opt['ns' . $n] = 1;
714  }
715  } else {
716  $opt['profile'] = $this->profile;
717  }
718 
719  return $opt + $this->extraParams;
720  }
721 
727  protected function saveNamespaces() {
728  $user = $this->getUser();
729  $request = $this->getRequest();
730 
731  if ( $user->isRegistered() &&
732  $user->matchEditToken(
733  $request->getVal( 'nsRemember' ),
734  'searchnamespace',
735  $request
736  ) && !$this->readOnlyMode->isReadOnly()
737  ) {
738  // Reset namespace preferences: namespaces are not searched
739  // when they're not mentioned in the URL parameters.
740  foreach ( $this->nsInfo->getValidNamespaces() as $n ) {
741  $this->userOptionsManager->setOption( $user, 'searchNs' . $n, false );
742  }
743  // The request parameters include all the namespaces to be searched.
744  // Even if they're the same as an existing profile, they're not eaten.
745  foreach ( $this->namespaces as $n ) {
746  $this->userOptionsManager->setOption( $user, 'searchNs' . $n, true );
747  }
748 
749  DeferredUpdates::addCallableUpdate( static function () use ( $user ) {
750  $user->saveSettings();
751  } );
752 
753  return true;
754  }
755 
756  return false;
757  }
758 
763  protected function getSearchProfiles() {
764  // Builds list of Search Types (profiles)
765  $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
766  $defaultNs = $this->searchConfig->defaultNamespaces();
767  $profiles = [
768  'default' => [
769  'message' => 'searchprofile-articles',
770  'tooltip' => 'searchprofile-articles-tooltip',
771  'namespaces' => $defaultNs,
772  'namespace-messages' => $this->searchConfig->namespacesAsText(
773  $defaultNs
774  ),
775  ],
776  'images' => [
777  'message' => 'searchprofile-images',
778  'tooltip' => 'searchprofile-images-tooltip',
779  'namespaces' => [ NS_FILE ],
780  ],
781  'all' => [
782  'message' => 'searchprofile-everything',
783  'tooltip' => 'searchprofile-everything-tooltip',
784  'namespaces' => $nsAllSet,
785  ],
786  'advanced' => [
787  'message' => 'searchprofile-advanced',
788  'tooltip' => 'searchprofile-advanced-tooltip',
789  'namespaces' => self::NAMESPACES_CURRENT,
790  ]
791  ];
792 
793  $this->getHookRunner()->onSpecialSearchProfiles( $profiles );
794 
795  foreach ( $profiles as &$data ) {
796  if ( !is_array( $data['namespaces'] ) ) {
797  continue;
798  }
799  sort( $data['namespaces'] );
800  }
801 
802  return $profiles;
803  }
804 
810  public function getSearchEngine() {
811  if ( $this->searchEngine === null ) {
812  $this->searchEngine = $this->searchEngineFactory->create( $this->searchEngineType );
813  }
814 
815  return $this->searchEngine;
816  }
817 
822  public function getProfile() {
823  return $this->profile;
824  }
825 
830  public function getNamespaces() {
831  return $this->namespaces;
832  }
833 
843  public function setExtraParam( $key, $value ) {
844  $this->extraParams[$key] = $value;
845  }
846 
855  public function getPrefix() {
856  return $this->mPrefix;
857  }
858 
865  private function prevNextLinks( ?int $totalRes, ?ISearchResultSet $textMatches, string $term,
866  OutputPage $out ) {
867  if ( $totalRes > $this->limit || $this->offset ) {
868  // Allow matches to define the correct offset, as interleaved
869  // AB testing may require a different next page offset.
870  if ( $textMatches && $textMatches->getOffset() !== null ) {
871  $offset = $textMatches->getOffset();
872  } else {
874  }
875 
876  // use the rewritten search term for subsequent page searches
877  $newSearchTerm = $term;
878  if ( $textMatches && $textMatches->hasRewrittenQuery() ) {
879  $newSearchTerm = $textMatches->getQueryAfterRewrite();
880  }
881 
882  $prevNext =
883  $this->buildPrevNextNavigation( $offset, $this->limit,
884  $this->powerSearchOptions() + [ 'search' => $newSearchTerm ],
885  $this->limit + $this->offset >= $totalRes );
886  $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevNext}</p>\n" );
887  }
888  }
889 
890  protected function getGroupName() {
891  return 'pages';
892  }
893 }
MediaWiki\Search\SearchWidgets\DidYouMeanWidget
Renders a suggested search for the user, or tells the user a suggested search was run instead of the ...
Definition: DidYouMeanWidget.php:12
SpecialPage\$linkRenderer
LinkRenderer null $linkRenderer
Definition: SpecialPage.php:80
SpecialSearch\getNamespaces
getNamespaces()
Current namespaces.
Definition: SpecialSearch.php:830
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:743
Message\numParam
static numParam( $num)
Definition: Message.php:1038
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:911
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:363
ISearchResultSet\hasRewrittenQuery
hasRewrittenQuery()
Some search modes will run an alternative query that it thinks gives a better result than the provide...
MediaWiki\Search\SearchWidgets\SearchFormWidget
Definition: SearchFormWidget.php:14
SpecialSearch\$fulltext
string $fulltext
Definition: SpecialSearch.php:80
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:789
SpecialSearch\$sort
string $sort
Definition: SpecialSearch.php:85
MediaWiki\Search\SearchWidgets\InterwikiSearchResultSetWidget
Renders one or more ISearchResultSets into a sidebar grouped by interwiki prefix.
Definition: InterwikiSearchResultSetWidget.php:18
SpecialSearch\$limit
int $limit
Definition: SpecialSearch.php:70
MediaWiki\Search\SearchWidgets\InterwikiSearchResultWidget
Renders an enhanced interwiki result.
Definition: InterwikiSearchResultWidget.php:14
ReadOnlyMode
A service class for fetching the wiki's current read-only mode.
Definition: ReadOnlyMode.php:11
SearchEngineFactory
Factory class for SearchEngine.
Definition: SearchEngineFactory.php:13
SpecialSearch\$loadStatus
Status $loadStatus
Holds any parameter validation errors that should be displayed back to the user.
Definition: SpecialSearch.php:123
SpecialPage\getHookContainer
getHookContainer()
Definition: SpecialPage.php:1081
Html\warningBox
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:729
ISearchResultSet\getQueryAfterRewrite
getQueryAfterRewrite()
SpecialSearch\getPrefix
getPrefix()
The prefix value send to Special:Search using the 'prefix' URI param It means that the user is willin...
Definition: SpecialSearch.php:855
MediaWiki\Languages\LanguageConverterFactory
An interface for creating language converters.
Definition: LanguageConverterFactory.php:46
SpecialSearch\isPowerSearch
isPowerSearch()
Return true if current search is a power (advanced) search.
Definition: SpecialSearch.php:680
SpecialSearch\setupPage
setupPage( $term)
Sets up everything for the HTML output page including styles, javascript, page title,...
Definition: SpecialSearch.php:627
OutputPage\addHTML
addHTML( $text)
Append $text to the body HTML.
Definition: OutputPage.php:1617
SpecialSearch\getSearchProfiles
getSearchProfiles()
Definition: SpecialSearch.php:763
SpecialSearch\__construct
__construct(SearchEngineConfig $searchConfig, SearchEngineFactory $searchEngineFactory, NamespaceInfo $nsInfo, IContentHandlerFactory $contentHandlerFactory, InterwikiLookup $interwikiLookup, ReadOnlyMode $readOnlyMode, UserOptionsManager $userOptionsManager, LanguageConverterFactory $languageConverterFactory)
Definition: SpecialSearch.php:137
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
SearchEngine\DEFAULT_SORT
const DEFAULT_SORT
Definition: SearchEngine.php:38
SpecialSearch\NAMESPACES_CURRENT
const NAMESPACES_CURRENT
Definition: SpecialSearch.php:125
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:947
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1066
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1094
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:877
SpecialSearch\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialSearch.php:890
SpecialSearch\$runSuggestion
bool $runSuggestion
Definition: SpecialSearch.php:90
MediaWiki\Interwiki\InterwikiLookup
Service interface for looking up Interwiki records.
Definition: InterwikiLookup.php:32
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
StatusValue\merge
merge( $other, $overwriteValue=false)
Merge another status object into this one.
Definition: StatusValue.php:268
MediaWiki\Search\SearchWidgets\BasicSearchResultSetWidget
Renders the search result area.
Definition: BasicSearchResultSetWidget.php:15
$title
$title
Definition: testCompression.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:617
SpecialSearch\$offset
int $offset
Definition: SpecialSearch.php:70
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:799
SpecialSearch\saveNamespaces
saveNamespaces()
Save namespace preferences when we're supposed to.
Definition: SpecialSearch.php:727
SpecialSearch\$interwikiLookup
InterwikiLookup $interwikiLookup
Definition: SpecialSearch.php:108
ISearchResultSet
A set of SearchEngine results.
Definition: ISearchResultSet.php:12
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:50
Html\errorBox
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition: Html.php:742
SpecialSearch\$searchConfig
SearchEngineConfig $searchConfig
Search engine configurations.
Definition: SpecialSearch.php:96
ISearchResultSet\INLINE_RESULTS
const INLINE_RESULTS
Identifier for interwiki results that can be displayed even if no existing main wiki results exist.
Definition: ISearchResultSet.php:23
SpecialSearch\showGoogleSearch
showGoogleSearch( $term)
Output a google search form if search is disabled.
Definition: SpecialSearch.php:239
SpecialSearch\$searchEngine
SearchEngine $searchEngine
Search engine.
Definition: SpecialSearch.php:53
SpecialSearch\execute
execute( $par)
Entry point.
Definition: SpecialSearch.php:163
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:43
SpecialPage\buildPrevNextNavigation
buildPrevNextNavigation( $offset, $limit, array $query=[], $atend=false, $subpage=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
Definition: SpecialPage.php:1054
SpecialSearch
implements Special:Search - Run text & title search and display the output
Definition: SpecialSearch.php:41
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:779
SpecialSearch\$profile
null string $profile
Current search profile.
Definition: SpecialSearch.php:50
SpecialSearch\powerSearch
powerSearch(&$request)
Extract "power search" namespace settings from the request object, returning a list of index numbers ...
Definition: SpecialSearch.php:691
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1505
ISearchResultSet\getOffset
getOffset()
SpecialSearch\getProfile
getProfile()
Current search profile.
Definition: SpecialSearch.php:822
MediaWiki\Search\SearchWidgets\SimpleSearchResultSetWidget
Renders one or more ISearchResultSets into a sidebar grouped by interwiki prefix.
Definition: SimpleSearchResultSetWidget.php:19
MediaWiki\Search\SearchWidgets\SimpleSearchResultWidget
Renders a simple one-line result.
Definition: SimpleSearchResultWidget.php:15
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:37
SpecialSearch\$contentHandlerFactory
IContentHandlerFactory $contentHandlerFactory
Definition: SpecialSearch.php:105
MediaWiki\User\UserOptionsManager
A service class to control user options.
Definition: UserOptionsManager.php:44
SpecialSearch\$extraParams
array $extraParams
For links.
Definition: SpecialSearch.php:59
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1027
SpecialSearch\$userOptionsManager
UserOptionsManager $userOptionsManager
Definition: SpecialSearch.php:114
SpecialSearch\powerSearchOptions
powerSearchOptions()
Reconstruct the 'power search' options for links TODO: Instead of exposing this publicly,...
Definition: SpecialSearch.php:709
SpecialSearch\goResult
goResult( $term)
If an exact title match can be found, jump straight ahead to it.
Definition: SpecialSearch.php:334
SpecialSearch\$namespaces
array $namespaces
Definition: SpecialSearch.php:75
SpecialSearch\$nsInfo
NamespaceInfo $nsInfo
Definition: SpecialSearch.php:102
SpecialSearch\getSearchEngine
getSearchEngine()
Definition: SpecialSearch.php:810
SpecialSearch\setExtraParam
setExtraParam( $key, $value)
Users of hook SpecialSearchSetupEngine can use this to add more params to links to not lose selection...
Definition: SpecialSearch.php:843
SpecialSearch\load
load()
Set up basic search parameters from the request and user settings.
Definition: SpecialSearch.php:261
ISearchResultSet\SECONDARY_RESULTS
const SECONDARY_RESULTS
Identifier for interwiki results that are displayed only together with existing main wiki results.
Definition: ISearchResultSet.php:17
SpecialSearch\$readOnlyMode
ReadOnlyMode $readOnlyMode
Definition: SpecialSearch.php:111
SearchEngineConfig
Configuration handling class for SearchEngine.
Definition: SearchEngineConfig.php:12
SpecialSearch\$mPrefix
string $mPrefix
The prefix url parameter.
Definition: SpecialSearch.php:65
SpecialSearch\showCreateLink
showCreateLink( $title, $num, $titleMatches, $textMatches)
Definition: SpecialSearch.php:572
NamespaceInfo
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Definition: NamespaceInfo.php:35
SpecialPage\getContentLanguage
getContentLanguage()
Shortcut to get content language.
Definition: SpecialPage.php:839
NS_FILE
const NS_FILE
Definition: Defines.php:70
SpecialSearch\$searchEngineFactory
SearchEngineFactory $searchEngineFactory
Definition: SpecialSearch.php:99
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add an update to the pending update queue that invokes the specified callback when run.
Definition: DeferredUpdates.php:145
SpecialSearch\showResults
showResults( $term)
Definition: SpecialSearch.php:382
$wgSearchMatchRedirectPreference
bool $wgSearchMatchRedirectPreference
Set true to allow logged-in users to set a preference whether or not matches in search results should...
Definition: DefaultSettings.php:9630
SpecialSearch\$languageConverterFactory
LanguageConverterFactory $languageConverterFactory
Definition: SpecialSearch.php:117
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:708
SpecialSearch\redirectOnExactMatch
redirectOnExactMatch()
Definition: SpecialSearch.php:367
MediaWiki\Search\SearchWidgets\FullSearchResultWidget
Renders a 'full' multi-line search result with metadata.
Definition: FullSearchResultWidget.php:22
SpecialSearch\prevNextLinks
prevNextLinks(?int $totalRes, ?ISearchResultSet $textMatches, string $term, OutputPage $out)
Definition: SpecialSearch.php:865
SpecialSearch\$searchEngineType
string null $searchEngineType
Search engine type, if not default.
Definition: SpecialSearch.php:56