MediaWiki  master
SpecialSearch.php
Go to the documentation of this file.
1 <?php
33 
38 class SpecialSearch extends SpecialPage {
47  protected $profile;
48 
50  protected $searchEngine;
51 
53  protected $searchEngineType;
54 
56  protected $extraParams = [];
57 
62  protected $mPrefix;
63 
67  protected $limit, $offset;
68 
72  protected $namespaces;
73 
77  protected $fulltext;
78 
82  protected $sort;
83 
87  protected $runSuggestion = true;
88 
93  protected $searchConfig;
94 
95  const NAMESPACES_CURRENT = 'sense';
96 
97  public function __construct() {
98  parent::__construct( 'Search' );
99  $this->searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
100  }
101 
107  public function execute( $par ) {
108  $request = $this->getRequest();
109  $out = $this->getOutput();
110 
111  // Fetch the search term
112  $term = str_replace( "\n", " ", $request->getText( 'search' ) );
113 
114  // Historically search terms have been accepted not only in the search query
115  // parameter, but also as part of the primary url. This can have PII implications
116  // in releasing page view data. As such issue a 301 redirect to the correct
117  // URL.
118  if ( $par !== null && $par !== '' && $term === '' ) {
119  $query = $request->getValues();
120  unset( $query['title'] );
121  // Strip underscores from title parameter; most of the time we'll want
122  // text form here. But don't strip underscores from actual text params!
123  $query['search'] = str_replace( '_', ' ', $par );
124  $out->redirect( $this->getPageTitle()->getFullURL( $query ), 301 );
125  return;
126  }
127 
128  // Need to load selected namespaces before handling nsRemember
129  $this->load();
130  // TODO: This performs database actions on GET request, which is going to
131  // be a problem for our multi-datacenter work.
132  if ( $request->getCheck( 'nsRemember' ) ) {
133  $this->saveNamespaces();
134  // Remove the token from the URL to prevent the user from inadvertently
135  // exposing it (e.g. by pasting it into a public wiki page) or undoing
136  // later settings changes (e.g. by reloading the page).
137  $query = $request->getValues();
138  unset( $query['title'], $query['nsRemember'] );
139  $out->redirect( $this->getPageTitle()->getFullURL( $query ) );
140  return;
141  }
142 
143  $this->searchEngineType = $request->getVal( 'srbackend' );
144  if ( !$request->getVal( 'fulltext' ) && !$request->getCheck( 'offset' ) ) {
145  $url = $this->goResult( $term );
146  if ( $url !== null ) {
147  // successful 'go'
148  $out->redirect( $url );
149  return;
150  }
151  // No match. If it could plausibly be a title
152  // run the No go match hook.
154  if ( !is_null( $title ) ) {
155  Hooks::run( 'SpecialSearchNogomatch', [ &$title ] );
156  }
157  }
158 
159  $this->setupPage( $term );
160 
161  if ( $this->getConfig()->get( 'DisableTextSearch' ) ) {
162  $searchForwardUrl = $this->getConfig()->get( 'SearchForwardUrl' );
163  if ( $searchForwardUrl ) {
164  $url = str_replace( '$1', urlencode( $term ), $searchForwardUrl );
165  $out->redirect( $url );
166  } else {
167  $this->showGoogleSearch( $term );
168  }
169 
170  return;
171  }
172 
173  $this->showResults( $term );
174  }
175 
183  private function showGoogleSearch( $term ) {
184  $this->getOutput()->addHTML(
185  "<fieldset>" .
186  "<legend>" .
187  $this->msg( 'search-external' )->escaped() .
188  "</legend>" .
189  "<p class='mw-searchdisabled'>" .
190  $this->msg( 'searchdisabled' )->escaped() .
191  "</p>" .
192  $this->msg( 'googlesearch' )->rawParams(
193  htmlspecialchars( $term ),
194  'UTF-8',
195  $this->msg( 'searchbutton' )->escaped()
196  )->text() .
197  "</fieldset>"
198  );
199  }
200 
206  public function load() {
207  $request = $this->getRequest();
208  list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, '' );
209  $this->mPrefix = $request->getVal( 'prefix', '' );
210  if ( $this->mPrefix !== '' ) {
211  $this->setExtraParam( 'prefix', $this->mPrefix );
212  }
213 
214  $this->sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT );
215  if ( $this->sort !== SearchEngine::DEFAULT_SORT ) {
216  $this->setExtraParam( 'sort', $this->sort );
217  }
218 
219  $user = $this->getUser();
220 
221  # Extract manually requested namespaces
222  $nslist = $this->powerSearch( $request );
223  if ( $nslist === [] ) {
224  # Fallback to user preference
225  $nslist = $this->searchConfig->userNamespaces( $user );
226  }
227 
228  $profile = null;
229  if ( $nslist === [] ) {
230  $profile = 'default';
231  }
232 
233  $profile = $request->getVal( 'profile', $profile );
234  $profiles = $this->getSearchProfiles();
235  if ( $profile === null ) {
236  // BC with old request format
237  $profile = 'advanced';
238  foreach ( $profiles as $key => $data ) {
239  if ( $nslist === $data['namespaces'] && $key !== 'advanced' ) {
240  $profile = $key;
241  }
242  }
243  $this->namespaces = $nslist;
244  } elseif ( $profile === 'advanced' ) {
245  $this->namespaces = $nslist;
246  } elseif ( isset( $profiles[$profile]['namespaces'] ) ) {
247  $this->namespaces = $profiles[$profile]['namespaces'];
248  } else {
249  // Unknown profile requested
250  $profile = 'default';
251  $this->namespaces = $profiles['default']['namespaces'];
252  }
253 
254  $this->fulltext = $request->getVal( 'fulltext' );
255  $this->runSuggestion = (bool)$request->getVal( 'runsuggestion', true );
256  $this->profile = $profile;
257  }
258 
265  public function goResult( $term ) {
266  # If the string cannot be used to create a title
267  if ( is_null( Title::newFromText( $term ) ) ) {
268  return null;
269  }
270  # If there's an exact or very near match, jump right there.
271  $title = $this->getSearchEngine()
272  ->getNearMatcher( $this->getConfig() )->getNearMatch( $term );
273  if ( is_null( $title ) ) {
274  return null;
275  }
276  $url = null;
277  if ( !Hooks::run( 'SpecialSearchGoResult', [ $term, $title, &$url ] ) ) {
278  return null;
279  }
280 
281  return $url ?? $title->getFullUrlForRedirect();
282  }
283 
287  public function showResults( $term ) {
288  if ( $this->searchEngineType !== null ) {
289  $this->setExtraParam( 'srbackend', $this->searchEngineType );
290  }
291 
292  $out = $this->getOutput();
293  $widgetOptions = $this->getConfig()->get( 'SpecialSearchFormOptions' );
295  $this,
296  $this->searchConfig,
297  $this->getSearchProfiles()
298  );
299  $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
300  getFormattedNsText( NS_FILE ) . ':';
301  if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
302  // Empty query -- straight view of search form
303  if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
304  # Hook requested termination
305  return;
306  }
307  $out->enableOOUI();
308  // The form also contains the 'Showing results 0 - 20 of 1234' so we can
309  // only do the form render here for the empty $term case. Rendering
310  // the form when a search is provided is repeated below.
311  $out->addHTML( $formWidget->render(
312  $this->profile, $term, 0, 0, $this->offset, $this->isPowerSearch(), $widgetOptions
313  ) );
314  return;
315  }
316 
317  $engine = $this->getSearchEngine();
318  $engine->setFeatureData( 'rewrite', $this->runSuggestion );
319  $engine->setLimitOffset( $this->limit, $this->offset );
320  $engine->setNamespaces( $this->namespaces );
321  $engine->setSort( $this->sort );
323 
324  Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $engine ] );
325  if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
326  # Hook requested termination
327  return;
328  }
329 
331  $showSuggestion = $title === null || !$title->isKnown();
332  $engine->setShowSuggestion( $showSuggestion );
333 
334  $rewritten = $engine->replacePrefixes( $term );
335  if ( $rewritten !== $term ) {
336  wfDeprecated( 'SearchEngine::replacePrefixes() (overridden by ' .
337  get_class( $engine ) . ')', '1.32' );
338  }
339 
340  // fetch search results
341  $titleMatches = $engine->searchTitle( $rewritten );
342  $textMatches = $engine->searchText( $rewritten );
343 
344  $textStatus = null;
345  if ( $textMatches instanceof Status ) {
346  $textStatus = $textMatches;
347  $textMatches = $textStatus->getValue();
348  }
349 
350  // Get number of results
351  $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
352  if ( $titleMatches ) {
353  $titleMatchesNum = $titleMatches->numRows();
354  $numTitleMatches = $titleMatches->getTotalHits();
355  }
356  if ( $textMatches ) {
357  $textMatchesNum = $textMatches->numRows();
358  $numTextMatches = $textMatches->getTotalHits();
359  if ( $textMatchesNum > 0 ) {
360  $engine->augmentSearchResults( $textMatches );
361  }
362  }
363  $num = $titleMatchesNum + $textMatchesNum;
364  $totalRes = $numTitleMatches + $numTextMatches;
365 
366  // start rendering the page
367  $out->enableOOUI();
368  $out->addHTML( $formWidget->render(
369  $this->profile, $term, $num, $totalRes, $this->offset, $this->isPowerSearch(), $widgetOptions
370  ) );
371 
372  // did you mean... suggestions
373  if ( $textMatches ) {
374  $dymWidget = new MediaWiki\Widget\Search\DidYouMeanWidget( $this );
375  $out->addHTML( $dymWidget->render( $term, $textMatches ) );
376  }
377 
378  $hasErrors = $textStatus && $textStatus->getErrors() !== [];
379  $hasOtherResults = $textMatches &&
380  $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS );
381 
382  if ( $textMatches && $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) {
383  $out->addHTML( '<div class="searchresults mw-searchresults-has-iw">' );
384  } else {
385  $out->addHTML( '<div class="searchresults">' );
386  }
387 
388  if ( $hasErrors ) {
389  list( $error, $warning ) = $textStatus->splitByErrorType();
390  if ( $error->getErrors() ) {
391  $out->addHTML( Html::errorBox(
392  $error->getHTML( 'search-error' )
393  ) );
394  }
395  if ( $warning->getErrors() ) {
396  $out->addHTML( Html::warningBox(
397  $warning->getHTML( 'search-warning' )
398  ) );
399  }
400  }
401 
402  // Show the create link ahead
403  $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
404 
405  Hooks::run( 'SpecialSearchResults', [ $term, &$titleMatches, &$textMatches ] );
406 
407  // If we have no results and have not already displayed an error message
408  if ( $num === 0 && !$hasErrors ) {
409  $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", [
410  $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
412  ] );
413  }
414 
415  // Although $num might be 0 there can still be secondary or inline
416  // results to display.
417  $linkRenderer = $this->getLinkRenderer();
418  $mainResultWidget = new FullSearchResultWidget( $this, $linkRenderer );
419 
420  // Default (null) on. Can be explicitly disabled.
421  if ( $engine->getFeatureData( 'enable-new-crossproject-page' ) !== false ) {
422  $sidebarResultWidget = new InterwikiSearchResultWidget( $this, $linkRenderer );
423  $sidebarResultsWidget = new InterwikiSearchResultSetWidget(
424  $this,
425  $sidebarResultWidget,
427  MediaWikiServices::getInstance()->getInterwikiLookup(),
428  $engine->getFeatureData( 'show-multimedia-search-results' )
429  );
430  } else {
431  $sidebarResultWidget = new SimpleSearchResultWidget( $this, $linkRenderer );
432  $sidebarResultsWidget = new SimpleSearchResultSetWidget(
433  $this,
434  $sidebarResultWidget,
436  MediaWikiServices::getInstance()->getInterwikiLookup()
437  );
438  }
439 
440  $widget = new BasicSearchResultSetWidget( $this, $mainResultWidget, $sidebarResultsWidget );
441 
442  $out->addHTML( $widget->render(
443  $term, $this->offset, $titleMatches, $textMatches
444  ) );
445 
446  if ( $titleMatches ) {
447  $titleMatches->free();
448  }
449 
450  if ( $textMatches ) {
451  $textMatches->free();
452  }
453 
454  $out->addHTML( '<div class="mw-search-visualclear"></div>' );
455 
456  // prev/next links
457  if ( $totalRes > $this->limit || $this->offset ) {
458  // Allow matches to define the correct offset, as interleaved
459  // AB testing may require a different next page offset.
460  if ( $textMatches && $textMatches->getOffset() !== null ) {
461  $offset = $textMatches->getOffset();
462  } else {
463  $offset = $this->offset;
464  }
465 
466  $prevNext = $this->buildPrevNextNavigation(
467  $offset,
468  $this->limit,
469  $this->powerSearchOptions() + [ 'search' => $term ],
470  $this->limit + $this->offset >= $totalRes
471  );
472  $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevNext}</p>\n" );
473  }
474 
475  // Close <div class='searchresults'>
476  $out->addHTML( "</div>" );
477 
478  Hooks::run( 'SpecialSearchResultsAppend', [ $this, $out, $term ] );
479  }
480 
487  protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
488  // show direct page/create link if applicable
489 
490  // Check DBkey !== '' in case of fragment link only.
491  if ( is_null( $title ) || $title->getDBkey() === ''
492  || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
493  || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
494  ) {
495  // invalid title
496  // preserve the paragraph for margins etc...
497  $this->getOutput()->addHTML( '<p></p>' );
498 
499  return;
500  }
501 
502  $messageName = 'searchmenu-new-nocreate';
503  $linkClass = 'mw-search-createlink';
504 
505  if ( !$title->isExternal() ) {
506  if ( $title->isKnown() ) {
507  $messageName = 'searchmenu-exists';
508  $linkClass = 'mw-search-exists';
509  } elseif ( ContentHandler::getForTitle( $title )->supportsDirectEditing()
510  && $title->quickUserCan( 'create', $this->getUser() )
511  ) {
512  $messageName = 'searchmenu-new';
513  }
514  }
515 
516  $params = [
517  $messageName,
518  wfEscapeWikiText( $title->getPrefixedText() ),
519  Message::numParam( $num )
520  ];
521  Hooks::run( 'SpecialSearchCreateLink', [ $title, &$params ] );
522 
523  // Extensions using the hook might still return an empty $messageName
524  if ( $messageName ) {
525  $this->getOutput()->wrapWikiMsg( "<p class=\"$linkClass\">\n$1</p>", $params );
526  } else {
527  // preserve the paragraph for margins etc...
528  $this->getOutput()->addHTML( '<p></p>' );
529  }
530  }
531 
538  protected function setupPage( $term ) {
539  $out = $this->getOutput();
540 
541  $this->setHeaders();
542  $this->outputHeader();
543  // TODO: Is this true? The namespace remember uses a user token
544  // on save.
545  $out->allowClickjacking();
546  $this->addHelpLink( 'Help:Searching' );
547 
548  if ( strval( $term ) !== '' ) {
549  $out->setPageTitle( $this->msg( 'searchresults' ) );
550  $out->setHTMLTitle( $this->msg( 'pagetitle' )
551  ->plaintextParams( $this->msg( 'searchresults-title' )->plaintextParams( $term )->text() )
552  ->inContentLanguage()->text()
553  );
554  }
555 
556  if ( $this->mPrefix !== '' ) {
557  $subtitle = $this->msg( 'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
558  $params = $this->powerSearchOptions();
559  unset( $params['prefix'] );
560  $params += [
561  'search' => $term,
562  'fulltext' => 1,
563  ];
564 
565  $subtitle .= ' (';
566  $subtitle .= Xml::element(
567  'a',
568  [
569  'href' => $this->getPageTitle()->getLocalURL( $params ),
570  'title' => $this->msg( 'search-filter-title-prefix-reset' )->text(),
571  ],
572  $this->msg( 'search-filter-title-prefix-reset' )->text()
573  );
574  $subtitle .= ')';
575  $out->setSubtitle( $subtitle );
576  }
577 
578  $out->addJsConfigVars( [ 'searchTerm' => $term ] );
579  $out->addModules( 'mediawiki.special.search' );
580  $out->addModuleStyles( [
581  'mediawiki.special', 'mediawiki.special.search.styles', 'mediawiki.ui', 'mediawiki.ui.button',
582  'mediawiki.ui.input', 'mediawiki.widgets.SearchInputWidget.styles',
583  ] );
584  }
585 
591  protected function isPowerSearch() {
592  return $this->profile === 'advanced';
593  }
594 
602  protected function powerSearch( &$request ) {
603  $arr = [];
604  foreach ( $this->searchConfig->searchableNamespaces() as $ns => $name ) {
605  if ( $request->getCheck( 'ns' . $ns ) ) {
606  $arr[] = $ns;
607  }
608  }
609 
610  return $arr;
611  }
612 
620  public function powerSearchOptions() {
621  $opt = [];
622  if ( $this->isPowerSearch() ) {
623  foreach ( $this->namespaces as $n ) {
624  $opt['ns' . $n] = 1;
625  }
626  } else {
627  $opt['profile'] = $this->profile;
628  }
629 
630  return $opt + $this->extraParams;
631  }
632 
638  protected function saveNamespaces() {
639  $user = $this->getUser();
640  $request = $this->getRequest();
641 
642  if ( $user->isLoggedIn() &&
643  $user->matchEditToken(
644  $request->getVal( 'nsRemember' ),
645  'searchnamespace',
646  $request
647  ) && !wfReadOnly()
648  ) {
649  // Reset namespace preferences: namespaces are not searched
650  // when they're not mentioned in the URL parameters.
651  foreach ( MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces()
652  as $n
653  ) {
654  $user->setOption( 'searchNs' . $n, false );
655  }
656  // The request parameters include all the namespaces to be searched.
657  // Even if they're the same as an existing profile, they're not eaten.
658  foreach ( $this->namespaces as $n ) {
659  $user->setOption( 'searchNs' . $n, true );
660  }
661 
662  DeferredUpdates::addCallableUpdate( function () use ( $user ) {
663  $user->saveSettings();
664  } );
665 
666  return true;
667  }
668 
669  return false;
670  }
671 
675  protected function getSearchProfiles() {
676  // Builds list of Search Types (profiles)
677  $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
678  $defaultNs = $this->searchConfig->defaultNamespaces();
679  $profiles = [
680  'default' => [
681  'message' => 'searchprofile-articles',
682  'tooltip' => 'searchprofile-articles-tooltip',
683  'namespaces' => $defaultNs,
684  'namespace-messages' => $this->searchConfig->namespacesAsText(
685  $defaultNs
686  ),
687  ],
688  'images' => [
689  'message' => 'searchprofile-images',
690  'tooltip' => 'searchprofile-images-tooltip',
691  'namespaces' => [ NS_FILE ],
692  ],
693  'all' => [
694  'message' => 'searchprofile-everything',
695  'tooltip' => 'searchprofile-everything-tooltip',
696  'namespaces' => $nsAllSet,
697  ],
698  'advanced' => [
699  'message' => 'searchprofile-advanced',
700  'tooltip' => 'searchprofile-advanced-tooltip',
701  'namespaces' => self::NAMESPACES_CURRENT,
702  ]
703  ];
704 
705  Hooks::run( 'SpecialSearchProfiles', [ &$profiles ] );
706 
707  foreach ( $profiles as &$data ) {
708  if ( !is_array( $data['namespaces'] ) ) {
709  continue;
710  }
711  sort( $data['namespaces'] );
712  }
713 
714  return $profiles;
715  }
716 
722  public function getSearchEngine() {
723  if ( $this->searchEngine === null ) {
724  $services = MediaWikiServices::getInstance();
725  $this->searchEngine = $this->searchEngineType ?
726  $services->getSearchEngineFactory()->create( $this->searchEngineType ) :
727  $services->newSearchEngine();
728  }
729 
730  return $this->searchEngine;
731  }
732 
737  function getProfile() {
738  return $this->profile;
739  }
740 
745  function getNamespaces() {
746  return $this->namespaces;
747  }
748 
758  public function setExtraParam( $key, $value ) {
759  $this->extraParams[$key] = $value;
760  }
761 
770  public function getPrefix() {
771  return $this->mPrefix;
772  }
773 
774  protected function getGroupName() {
775  return 'pages';
776  }
777 }
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Renders one or more SearchResultSets into a sidebar grouped by interwiki prefix.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
setupPage( $term)
Sets up everything for the HTML output page including styles, javascript, page title, etc.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1585
whereas SearchGetNearMatch runs after $term
Definition: hooks.txt:2875
SearchEngineConfig $searchConfig
Search engine configurations.
to move a page</td >< td > &*You are moving the page across namespaces
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getNamespaces()
Current namespaces.
string $searchEngineType
Search engine type, if not default.
static warningBox( $html)
Return a warning box.
Definition: Html.php:725
$value
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
saveNamespaces()
Save namespace preferences when we&#39;re supposed to.
getOutput()
Get the OutputPage being used for this instance.
static numParam( $num)
Definition: Message.php:1049
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
Renders one or more SearchResultSets into a sidebar grouped by interwiki prefix.
buildPrevNextNavigation( $offset, $limit, array $query=[], $atend=false, $subpage=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
isPowerSearch()
Return true if current search is a power (advanced) search.
Renders a &#39;full&#39; multi-line search result with metadata.
getProfile()
Current search profile.
wfReadOnly()
Check whether the wiki is in read-only mode.
array $extraParams
For links.
const NAMESPACES_CURRENT
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2217
goResult( $term)
If an exact title match can be found, jump straight ahead to it.
showResults( $term)
const SECONDARY_RESULTS
Identifier for interwiki results that are displayed only together with existing main wiki results...
load()
Set up basic search parameters from the request and user settings.
$params
string $mPrefix
The prefix url parameter.
showGoogleSearch( $term)
Output a google search form if search is disabled.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
const DEFAULT_SORT
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object. ...
Definition: Title.php:1658
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
const NS_FILE
Definition: Defines.php:66
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2898
powerSearchOptions()
Reconstruct the &#39;power search&#39; options for links TODO: Instead of exposing this publicly, could we instead expose a function for creating search links?
static errorBox( $html, $heading='')
Return an error box.
Definition: Html.php:736
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
setExtraParam( $key, $value)
Users of hook SpecialSearchSetupEngine can use this to add more params to links to not lose selection...
getUser()
Shortcut to get the User executing this instance.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getConfig()
Shortcut to get main config object.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
getPrefix()
The prefix value send to Special:Search using the &#39;prefix&#39; URI param It means that the user is willin...
msg( $key)
Wrapper around wfMessage that sets the current context.
null string $profile
Current search profile.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
getRequest()
Get the WebRequest being used for this instance.
SearchEngine $searchEngine
Search engine.
execute( $par)
Entry point.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2633
Renders a suggested search for the user, or tells the user a suggested search was run instead of the ...
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getPageTitle( $subpage=false)
Get a self-referential title object.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
const INLINE_RESULTS
Identifier for interwiki results that can be displayed even if no existing main wiki results exist...
powerSearch(&$request)
Extract "power search" namespace settings from the request object, returning a list of index numbers ...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
showCreateLink( $title, $num, $titleMatches, $textMatches)
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319