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 
83 
87  protected $runSuggestion = true;
88 
93  protected $searchConfig;
94 
99  private $loadStatus;
100 
101  const NAMESPACES_CURRENT = 'sense';
102 
103  public function __construct() {
104  parent::__construct( 'Search' );
105  $this->searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
106  }
107 
113  public function execute( $par ) {
114  $request = $this->getRequest();
115  $out = $this->getOutput();
116 
117  // Fetch the search term
118  $term = str_replace( "\n", " ", $request->getText( 'search' ) );
119 
120  // Historically search terms have been accepted not only in the search query
121  // parameter, but also as part of the primary url. This can have PII implications
122  // in releasing page view data. As such issue a 301 redirect to the correct
123  // URL.
124  if ( $par !== null && $par !== '' && $term === '' ) {
125  $query = $request->getValues();
126  unset( $query['title'] );
127  // Strip underscores from title parameter; most of the time we'll want
128  // text form here. But don't strip underscores from actual text params!
129  $query['search'] = str_replace( '_', ' ', $par );
130  $out->redirect( $this->getPageTitle()->getFullURL( $query ), 301 );
131  return;
132  }
133 
134  // Need to load selected namespaces before handling nsRemember
135  $this->load();
136  // TODO: This performs database actions on GET request, which is going to
137  // be a problem for our multi-datacenter work.
138  if ( $request->getCheck( 'nsRemember' ) ) {
139  $this->saveNamespaces();
140  // Remove the token from the URL to prevent the user from inadvertently
141  // exposing it (e.g. by pasting it into a public wiki page) or undoing
142  // later settings changes (e.g. by reloading the page).
143  $query = $request->getValues();
144  unset( $query['title'], $query['nsRemember'] );
145  $out->redirect( $this->getPageTitle()->getFullURL( $query ) );
146  return;
147  }
148 
149  $this->searchEngineType = $request->getVal( 'srbackend' );
150  if ( !$request->getVal( 'fulltext' ) && !$request->getCheck( 'offset' ) ) {
151  $url = $this->goResult( $term );
152  if ( $url !== null ) {
153  // successful 'go'
154  $out->redirect( $url );
155  return;
156  }
157  // No match. If it could plausibly be a title
158  // run the No go match hook.
160  if ( !is_null( $title ) ) {
161  Hooks::run( 'SpecialSearchNogomatch', [ &$title ] );
162  }
163  }
164 
165  $this->setupPage( $term );
166 
167  if ( $this->getConfig()->get( 'DisableTextSearch' ) ) {
168  $searchForwardUrl = $this->getConfig()->get( 'SearchForwardUrl' );
169  if ( $searchForwardUrl ) {
170  $url = str_replace( '$1', urlencode( $term ), $searchForwardUrl );
171  $out->redirect( $url );
172  } else {
173  $this->showGoogleSearch( $term );
174  }
175 
176  return;
177  }
178 
179  $this->showResults( $term );
180  }
181 
189  private function showGoogleSearch( $term ) {
190  $this->getOutput()->addHTML(
191  "<fieldset>" .
192  "<legend>" .
193  $this->msg( 'search-external' )->escaped() .
194  "</legend>" .
195  "<p class='mw-searchdisabled'>" .
196  $this->msg( 'searchdisabled' )->escaped() .
197  "</p>" .
198  $this->msg( 'googlesearch' )->rawParams(
199  htmlspecialchars( $term ),
200  'UTF-8',
201  $this->msg( 'searchbutton' )->escaped()
202  )->text() .
203  "</fieldset>"
204  );
205  }
206 
212  public function load() {
213  $this->loadStatus = new Status();
214 
215  $request = $this->getRequest();
216  list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, '' );
217  $this->mPrefix = $request->getVal( 'prefix', '' );
218  if ( $this->mPrefix !== '' ) {
219  $this->setExtraParam( 'prefix', $this->mPrefix );
220  }
221 
222  $sort = $request->getVal( 'sort', SearchEngine::DEFAULT_SORT );
223  $validSorts = $this->getSearchEngine()->getValidSorts();
224  if ( !in_array( $sort, $validSorts ) ) {
225  $this->loadStatus->warning( 'search-invalid-sort-order', $sort,
226  implode( ', ', $validSorts ) );
227  } elseif ( $sort !== $this->sort ) {
228  $this->sort = $sort;
229  $this->setExtraParam( 'sort', $this->sort );
230  }
231 
232  $user = $this->getUser();
233 
234  # Extract manually requested namespaces
235  $nslist = $this->powerSearch( $request );
236  if ( $nslist === [] ) {
237  # Fallback to user preference
238  $nslist = $this->searchConfig->userNamespaces( $user );
239  }
240 
241  $profile = null;
242  if ( $nslist === [] ) {
243  $profile = 'default';
244  }
245 
246  $profile = $request->getVal( 'profile', $profile );
247  $profiles = $this->getSearchProfiles();
248  if ( $profile === null ) {
249  // BC with old request format
250  $profile = 'advanced';
251  foreach ( $profiles as $key => $data ) {
252  if ( $nslist === $data['namespaces'] && $key !== 'advanced' ) {
253  $profile = $key;
254  }
255  }
256  $this->namespaces = $nslist;
257  } elseif ( $profile === 'advanced' ) {
258  $this->namespaces = $nslist;
259  } elseif ( isset( $profiles[$profile]['namespaces'] ) ) {
260  $this->namespaces = $profiles[$profile]['namespaces'];
261  } else {
262  // Unknown profile requested
263  $this->loadStatus->warning( 'search-unknown-profile', $profile );
264  $profile = 'default';
265  $this->namespaces = $profiles['default']['namespaces'];
266  }
267 
268  $this->fulltext = $request->getVal( 'fulltext' );
269  $this->runSuggestion = (bool)$request->getVal( 'runsuggestion', true );
270  $this->profile = $profile;
271  }
272 
279  public function goResult( $term ) {
280  # If the string cannot be used to create a title
281  if ( is_null( Title::newFromText( $term ) ) ) {
282  return null;
283  }
284  # If there's an exact or very near match, jump right there.
285  $title = $this->getSearchEngine()
286  ->getNearMatcher( $this->getConfig() )->getNearMatch( $term );
287  if ( is_null( $title ) ) {
288  return null;
289  }
290  $url = null;
291  if ( !Hooks::run( 'SpecialSearchGoResult', [ $term, $title, &$url ] ) ) {
292  return null;
293  }
294 
295  return $url ?? $title->getFullUrlForRedirect();
296  }
297 
301  public function showResults( $term ) {
302  if ( $this->searchEngineType !== null ) {
303  $this->setExtraParam( 'srbackend', $this->searchEngineType );
304  }
305 
306  $out = $this->getOutput();
307  $widgetOptions = $this->getConfig()->get( 'SpecialSearchFormOptions' );
309  $this,
310  $this->searchConfig,
311  $this->getSearchProfiles()
312  );
313  $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
314  getFormattedNsText( NS_FILE ) . ':';
315  if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
316  // Empty query -- straight view of search form
317  if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
318  # Hook requested termination
319  return;
320  }
321  $out->enableOOUI();
322  // The form also contains the 'Showing results 0 - 20 of 1234' so we can
323  // only do the form render here for the empty $term case. Rendering
324  // the form when a search is provided is repeated below.
325  $out->addHTML( $formWidget->render(
326  $this->profile, $term, 0, 0, $this->offset, $this->isPowerSearch(), $widgetOptions
327  ) );
328  return;
329  }
330 
331  $engine = $this->getSearchEngine();
332  $engine->setFeatureData( 'rewrite', $this->runSuggestion );
333  $engine->setLimitOffset( $this->limit, $this->offset );
334  $engine->setNamespaces( $this->namespaces );
335  $engine->setSort( $this->sort );
337 
338  Hooks::run( 'SpecialSearchSetupEngine', [ $this, $this->profile, $engine ] );
339  if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
340  # Hook requested termination
341  return;
342  }
343 
345  $showSuggestion = $title === null || !$title->isKnown();
346  $engine->setShowSuggestion( $showSuggestion );
347 
348  $rewritten = $engine->replacePrefixes( $term );
349  if ( $rewritten !== $term ) {
350  wfDeprecated( 'SearchEngine::replacePrefixes() (overridden by ' .
351  get_class( $engine ) . ')', '1.32' );
352  }
353 
354  // fetch search results
355  $titleMatches = $engine->searchTitle( $rewritten );
356  $textMatches = $engine->searchText( $rewritten );
357 
358  $textStatus = null;
359  if ( $textMatches instanceof Status ) {
360  $textStatus = $textMatches;
361  $textMatches = $textStatus->getValue();
362  }
363 
364  // Get number of results
365  $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
366  if ( $titleMatches ) {
367  $titleMatchesNum = $titleMatches->numRows();
368  $numTitleMatches = $titleMatches->getTotalHits();
369  }
370  if ( $textMatches ) {
371  $textMatchesNum = $textMatches->numRows();
372  $numTextMatches = $textMatches->getTotalHits();
373  if ( $textMatchesNum > 0 ) {
374  $engine->augmentSearchResults( $textMatches );
375  }
376  }
377  $num = $titleMatchesNum + $textMatchesNum;
378  $totalRes = $numTitleMatches + $numTextMatches;
379 
380  // start rendering the page
381  $out->enableOOUI();
382  $out->addHTML( $formWidget->render(
383  $this->profile, $term, $num, $totalRes, $this->offset, $this->isPowerSearch(), $widgetOptions
384  ) );
385 
386  // did you mean... suggestions
387  if ( $textMatches ) {
388  $dymWidget = new MediaWiki\Widget\Search\DidYouMeanWidget( $this );
389  $out->addHTML( $dymWidget->render( $term, $textMatches ) );
390  }
391 
392  $hasSearchErrors = $textStatus && $textStatus->getErrors() !== [];
393  $hasOtherResults = $textMatches &&
394  $textMatches->hasInterwikiResults( ISearchResultSet::INLINE_RESULTS );
395 
396  if ( $textMatches && $textMatches->hasInterwikiResults( ISearchResultSet::SECONDARY_RESULTS ) ) {
397  $out->addHTML( '<div class="searchresults mw-searchresults-has-iw">' );
398  } else {
399  $out->addHTML( '<div class="searchresults">' );
400  }
401 
402  if ( $hasSearchErrors || $this->loadStatus->getErrors() ) {
403  if ( $textStatus === null ) {
404  $textStatus = $this->loadStatus;
405  } else {
406  $textStatus->merge( $this->loadStatus );
407  }
408  list( $error, $warning ) = $textStatus->splitByErrorType();
409  if ( $error->getErrors() ) {
410  $out->addHTML( Html::errorBox(
411  $error->getHTML( 'search-error' )
412  ) );
413  }
414  if ( $warning->getErrors() ) {
415  $out->addHTML( Html::warningBox(
416  $warning->getHTML( 'search-warning' )
417  ) );
418  }
419  }
420 
421  // Show the create link ahead
422  $this->showCreateLink( $title, $num, $titleMatches, $textMatches );
423 
424  Hooks::run( 'SpecialSearchResults', [ $term, &$titleMatches, &$textMatches ] );
425 
426  // If we have no results and have not already displayed an error message
427  if ( $num === 0 && !$hasSearchErrors ) {
428  $out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>", [
429  $hasOtherResults ? 'search-nonefound-thiswiki' : 'search-nonefound',
431  ] );
432  }
433 
434  // Although $num might be 0 there can still be secondary or inline
435  // results to display.
436  $linkRenderer = $this->getLinkRenderer();
437  $mainResultWidget = new FullSearchResultWidget( $this, $linkRenderer );
438 
439  // Default (null) on. Can be explicitly disabled.
440  if ( $engine->getFeatureData( 'enable-new-crossproject-page' ) !== false ) {
441  $sidebarResultWidget = new InterwikiSearchResultWidget( $this, $linkRenderer );
442  $sidebarResultsWidget = new InterwikiSearchResultSetWidget(
443  $this,
444  $sidebarResultWidget,
446  MediaWikiServices::getInstance()->getInterwikiLookup(),
447  $engine->getFeatureData( 'show-multimedia-search-results' )
448  );
449  } else {
450  $sidebarResultWidget = new SimpleSearchResultWidget( $this, $linkRenderer );
451  $sidebarResultsWidget = new SimpleSearchResultSetWidget(
452  $this,
453  $sidebarResultWidget,
455  MediaWikiServices::getInstance()->getInterwikiLookup()
456  );
457  }
458 
459  $widget = new BasicSearchResultSetWidget( $this, $mainResultWidget, $sidebarResultsWidget );
460 
461  $out->addHTML( $widget->render(
462  $term, $this->offset, $titleMatches, $textMatches
463  ) );
464 
465  $out->addHTML( '<div class="mw-search-visualclear"></div>' );
466 
467  // prev/next links
468  if ( $totalRes > $this->limit || $this->offset ) {
469  // Allow matches to define the correct offset, as interleaved
470  // AB testing may require a different next page offset.
471  if ( $textMatches && $textMatches->getOffset() !== null ) {
472  $offset = $textMatches->getOffset();
473  } else {
474  $offset = $this->offset;
475  }
476 
477  $prevNext = $this->buildPrevNextNavigation(
478  $offset,
479  $this->limit,
480  $this->powerSearchOptions() + [ 'search' => $term ],
481  $this->limit + $this->offset >= $totalRes
482  );
483  $out->addHTML( "<p class='mw-search-pager-bottom'>{$prevNext}</p>\n" );
484  }
485 
486  // Close <div class='searchresults'>
487  $out->addHTML( "</div>" );
488 
489  Hooks::run( 'SpecialSearchResultsAppend', [ $this, $out, $term ] );
490  }
491 
498  protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
499  // show direct page/create link if applicable
500 
501  // Check DBkey !== '' in case of fragment link only.
502  if ( is_null( $title ) || $title->getDBkey() === ''
503  || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
504  || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
505  ) {
506  // invalid title
507  // preserve the paragraph for margins etc...
508  $this->getOutput()->addHTML( '<p></p>' );
509 
510  return;
511  }
512 
513  $messageName = 'searchmenu-new-nocreate';
514  $linkClass = 'mw-search-createlink';
515 
516  if ( !$title->isExternal() ) {
517  if ( $title->isKnown() ) {
518  $messageName = 'searchmenu-exists';
519  $linkClass = 'mw-search-exists';
520  } elseif ( ContentHandler::getForTitle( $title )->supportsDirectEditing()
521  && $title->quickUserCan( 'create', $this->getUser() )
522  ) {
523  $messageName = 'searchmenu-new';
524  }
525  }
526 
527  $params = [
528  $messageName,
529  wfEscapeWikiText( $title->getPrefixedText() ),
530  Message::numParam( $num )
531  ];
532  Hooks::run( 'SpecialSearchCreateLink', [ $title, &$params ] );
533 
534  // Extensions using the hook might still return an empty $messageName
535  if ( $messageName ) {
536  $this->getOutput()->wrapWikiMsg( "<p class=\"$linkClass\">\n$1</p>", $params );
537  } else {
538  // preserve the paragraph for margins etc...
539  $this->getOutput()->addHTML( '<p></p>' );
540  }
541  }
542 
549  protected function setupPage( $term ) {
550  $out = $this->getOutput();
551 
552  $this->setHeaders();
553  $this->outputHeader();
554  // TODO: Is this true? The namespace remember uses a user token
555  // on save.
556  $out->allowClickjacking();
557  $this->addHelpLink( 'Help:Searching' );
558 
559  if ( strval( $term ) !== '' ) {
560  $out->setPageTitle( $this->msg( 'searchresults' ) );
561  $out->setHTMLTitle( $this->msg( 'pagetitle' )
562  ->plaintextParams( $this->msg( 'searchresults-title' )->plaintextParams( $term )->text() )
563  ->inContentLanguage()->text()
564  );
565  }
566 
567  if ( $this->mPrefix !== '' ) {
568  $subtitle = $this->msg( 'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
569  $params = $this->powerSearchOptions();
570  unset( $params['prefix'] );
571  $params += [
572  'search' => $term,
573  'fulltext' => 1,
574  ];
575 
576  $subtitle .= ' (';
577  $subtitle .= Xml::element(
578  'a',
579  [
580  'href' => $this->getPageTitle()->getLocalURL( $params ),
581  'title' => $this->msg( 'search-filter-title-prefix-reset' )->text(),
582  ],
583  $this->msg( 'search-filter-title-prefix-reset' )->text()
584  );
585  $subtitle .= ')';
586  $out->setSubtitle( $subtitle );
587  }
588 
589  $out->addJsConfigVars( [ 'searchTerm' => $term ] );
590  $out->addModules( 'mediawiki.special.search' );
591  $out->addModuleStyles( [
592  'mediawiki.special', 'mediawiki.special.search.styles', 'mediawiki.ui', 'mediawiki.ui.button',
593  'mediawiki.ui.input', 'mediawiki.widgets.SearchInputWidget.styles',
594  ] );
595  }
596 
602  protected function isPowerSearch() {
603  return $this->profile === 'advanced';
604  }
605 
613  protected function powerSearch( &$request ) {
614  $arr = [];
615  foreach ( $this->searchConfig->searchableNamespaces() as $ns => $name ) {
616  if ( $request->getCheck( 'ns' . $ns ) ) {
617  $arr[] = $ns;
618  }
619  }
620 
621  return $arr;
622  }
623 
631  public function powerSearchOptions() {
632  $opt = [];
633  if ( $this->isPowerSearch() ) {
634  foreach ( $this->namespaces as $n ) {
635  $opt['ns' . $n] = 1;
636  }
637  } else {
638  $opt['profile'] = $this->profile;
639  }
640 
641  return $opt + $this->extraParams;
642  }
643 
649  protected function saveNamespaces() {
650  $user = $this->getUser();
651  $request = $this->getRequest();
652 
653  if ( $user->isLoggedIn() &&
654  $user->matchEditToken(
655  $request->getVal( 'nsRemember' ),
656  'searchnamespace',
657  $request
658  ) && !wfReadOnly()
659  ) {
660  // Reset namespace preferences: namespaces are not searched
661  // when they're not mentioned in the URL parameters.
662  foreach ( MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces()
663  as $n
664  ) {
665  $user->setOption( 'searchNs' . $n, false );
666  }
667  // The request parameters include all the namespaces to be searched.
668  // Even if they're the same as an existing profile, they're not eaten.
669  foreach ( $this->namespaces as $n ) {
670  $user->setOption( 'searchNs' . $n, true );
671  }
672 
673  DeferredUpdates::addCallableUpdate( function () use ( $user ) {
674  $user->saveSettings();
675  } );
676 
677  return true;
678  }
679 
680  return false;
681  }
682 
686  protected function getSearchProfiles() {
687  // Builds list of Search Types (profiles)
688  $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
689  $defaultNs = $this->searchConfig->defaultNamespaces();
690  $profiles = [
691  'default' => [
692  'message' => 'searchprofile-articles',
693  'tooltip' => 'searchprofile-articles-tooltip',
694  'namespaces' => $defaultNs,
695  'namespace-messages' => $this->searchConfig->namespacesAsText(
696  $defaultNs
697  ),
698  ],
699  'images' => [
700  'message' => 'searchprofile-images',
701  'tooltip' => 'searchprofile-images-tooltip',
702  'namespaces' => [ NS_FILE ],
703  ],
704  'all' => [
705  'message' => 'searchprofile-everything',
706  'tooltip' => 'searchprofile-everything-tooltip',
707  'namespaces' => $nsAllSet,
708  ],
709  'advanced' => [
710  'message' => 'searchprofile-advanced',
711  'tooltip' => 'searchprofile-advanced-tooltip',
712  'namespaces' => self::NAMESPACES_CURRENT,
713  ]
714  ];
715 
716  Hooks::run( 'SpecialSearchProfiles', [ &$profiles ] );
717 
718  foreach ( $profiles as &$data ) {
719  if ( !is_array( $data['namespaces'] ) ) {
720  continue;
721  }
722  sort( $data['namespaces'] );
723  }
724 
725  return $profiles;
726  }
727 
733  public function getSearchEngine() {
734  if ( $this->searchEngine === null ) {
735  $services = MediaWikiServices::getInstance();
736  $this->searchEngine = $this->searchEngineType ?
737  $services->getSearchEngineFactory()->create( $this->searchEngineType ) :
738  $services->newSearchEngine();
739  }
740 
741  return $this->searchEngine;
742  }
743 
748  function getProfile() {
749  return $this->profile;
750  }
751 
756  function getNamespaces() {
757  return $this->namespaces;
758  }
759 
769  public function setExtraParam( $key, $value ) {
770  $this->extraParams[$key] = $value;
771  }
772 
781  public function getPrefix() {
782  return $this->mPrefix;
783  }
784 
785  protected function getGroupName() {
786  return 'pages';
787  }
788 }
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 ISearchResultSets 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.
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used $groups Array of ChangesListFilterGroup objects(added in 1.34) 'FileDeleteComplete' 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:1529
whereas SearchGetNearMatch runs after $term
Definition: hooks.txt:2863
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
const INLINE_RESULTS
Identifier for interwiki results that can be displayed even if no existing main wiki results exist...
getNamespaces()
Current namespaces.
string $searchEngineType
Search engine type, if not default.
static warningBox( $html)
Return a warning box.
Definition: Html.php:724
$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:1051
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:767
Renders one or more ISearchResultSets 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:2205
goResult( $term)
If an exact title match can be found, jump straight ahead to it.
showResults( $term)
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:767
prefix( $name)
Prefix some arbitrary text with the namespace or interwiki prefix of this object. ...
Definition: Title.php:1686
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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:2886
merge( $other, $overwriteValue=false)
Merge another status object into this one.
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:735
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...
const SECONDARY_RESULTS
Identifier for interwiki results that are displayed only together with existing main wiki results...
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:2621
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:1454
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
Status $loadStatus
Holds any parameter validation errors that should be displayed back to the user.
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:322