Go to the documentation of this file.
98 parent::__construct(
'Search' );
99 $this->searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
112 $term = str_replace(
"\n",
" ",
$request->getText(
'search' ) );
118 if ( strlen( $par ) && !strlen(
$term ) ) {
123 $query[
'search'] = str_replace(
'_',
' ', $par );
132 if ( !is_null(
$request->getVal(
'nsRemember' ) ) ) {
143 $this->searchEngineType =
$request->getVal(
'srbackend' );
146 $request->getVal(
'offset' ) === null
149 if ( $url !==
null ) {
151 $out->redirect( $url );
157 if ( !is_null(
$title ) ) {
164 if ( $this->
getConfig()->
get(
'DisableTextSearch' ) ) {
165 $searchForwardUrl = $this->
getConfig()->get(
'SearchForwardUrl' );
166 if ( $searchForwardUrl ) {
167 $url = str_replace(
'$1', urlencode(
$term ), $searchForwardUrl );
168 $out->redirect( $url );
173 $this->
msg(
'search-external' )->escaped() .
175 "<p class='mw-searchdisabled'>" .
176 $this->
msg(
'searchdisabled' )->escaped() .
178 $this->
msg(
'googlesearch' )->rawParams(
179 htmlspecialchars(
$term ),
181 $this->
msg(
'searchbutton' )->escaped()
200 list( $this->limit, $this->offset ) =
$request->getLimitOffset( 20,
'' );
201 $this->mPrefix =
$request->getVal(
'prefix',
'' );
202 if ( $this->mPrefix !==
'' ) {
213 # Extract manually requested namespaces
215 if ( !
count( $nslist ) ) {
216 # Fallback to user preference
217 $nslist = $this->searchConfig->userNamespaces(
$user );
221 if ( !
count( $nslist ) ) {
230 foreach ( $profiles
as $key => $data ) {
231 if ( $nslist === $data[
'namespaces'] && $key !==
'advanced' ) {
236 } elseif (
$profile ===
'advanced' ) {
239 if ( isset( $profiles[
$profile][
'namespaces'] ) ) {
244 $this->
namespaces = $profiles[
'default'][
'namespaces'];
248 $this->fulltext =
$request->getVal(
'fulltext' );
249 $this->runSuggestion = (bool)
$request->getVal(
'runsuggestion',
true );
260 # If the string cannot be used to create a title
264 # If there's an exact or very near match, jump right there.
267 if ( is_null(
$title ) ) {
275 return $url ??
$title->getFullUrlForRedirect();
282 if ( $this->searchEngineType !==
null ) {
283 $this->
setExtraParam(
'srbackend', $this->searchEngineType );
292 $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
293 getFormattedNsText(
NS_FILE ) .
':';
294 if ( trim(
$term ) ===
'' || $filePrefix === trim(
$term ) ) {
297 # Hook requested termination
304 $out->addHTML( $formWidget->render(
305 $this->profile,
$term, 0, 0, $this->offset, $this->isPowerSearch()
311 $search->setFeatureData(
'rewrite', $this->runSuggestion );
312 $search->setLimitOffset( $this->limit, $this->offset );
314 $search->setSort( $this->sort );
317 Hooks::run(
'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
319 # Hook requested termination
324 $showSuggestion =
$title ===
null || !
$title->isKnown();
325 $search->setShowSuggestion( $showSuggestion );
327 $rewritten = $search->transformSearchTerm(
$term );
328 if ( $rewritten !==
$term ) {
330 wfDeprecated(
'SearchEngine::transformSearchTerm() (overridden by ' .
331 get_class( $search ) .
')',
'1.32' );
334 $rewritten = $search->replacePrefixes(
$term );
335 if ( $rewritten !==
$term ) {
336 wfDeprecated(
'SearchEngine::replacePrefixes() (overridden by ' .
337 get_class( $search ) .
')',
'1.32' );
341 $titleMatches = $search->searchTitle( $rewritten );
342 $textMatches = $search->searchText( $rewritten );
345 if ( $textMatches instanceof
Status ) {
346 $textStatus = $textMatches;
347 $textMatches = $textStatus->getValue();
351 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
352 if ( $titleMatches ) {
353 $titleMatchesNum = $titleMatches->numRows();
354 $numTitleMatches = $titleMatches->getTotalHits();
356 if ( $textMatches ) {
357 $textMatchesNum = $textMatches->numRows();
358 $numTextMatches = $textMatches->getTotalHits();
359 if ( $textMatchesNum > 0 ) {
360 $search->augmentSearchResults( $textMatches );
363 $num = $titleMatchesNum + $textMatchesNum;
364 $totalRes = $numTitleMatches + $numTextMatches;
368 $out->addHTML( $formWidget->render(
369 $this->profile,
$term, $num, $totalRes, $this->offset, $this->isPowerSearch()
373 if ( $textMatches ) {
375 $out->addHTML( $dymWidget->render(
$term, $textMatches ) );
378 $hasErrors = $textStatus && $textStatus->getErrors() !== [];
379 $hasOtherResults = $textMatches &&
380 $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS );
382 if ( $textMatches && $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) {
383 $out->addHTML(
'<div class="searchresults mw-searchresults-has-iw">' );
385 $out->addHTML(
'<div class="searchresults">' );
389 list( $error, $warning ) = $textStatus->splitByErrorType();
390 if ( $error->getErrors() ) {
392 $error->getHTML(
'search-error' )
395 if ( $warning->getErrors() ) {
397 $warning->getHTML(
'search-warning' )
405 Hooks::run(
'SpecialSearchResults', [
$term, &$titleMatches, &$textMatches ] );
409 $out->wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
410 $hasOtherResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
421 if ( $search->getFeatureData(
'enable-new-crossproject-page' ) !==
false ) {
425 $sidebarResultWidget,
427 MediaWikiServices::getInstance()->getInterwikiLookup(),
428 $search->getFeatureData(
'show-multimedia-search-results' )
434 $sidebarResultWidget,
436 MediaWikiServices::getInstance()->getInterwikiLookup()
442 $out->addHTML( $widget->render(
443 $term, $this->offset, $titleMatches, $textMatches
446 if ( $titleMatches ) {
447 $titleMatches->free();
450 if ( $textMatches ) {
451 $textMatches->free();
454 $out->addHTML(
'<div class="mw-search-visualclear"></div>' );
457 if ( $totalRes > $this->limit || $this->offset ) {
460 if ( $textMatches && $textMatches->getOffset() !== null ) {
461 $offset = $textMatches->getOffset();
471 $this->limit + $this->offset >= $totalRes
473 $out->addHTML(
"<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
477 $out->addHTML(
"</div>" );
493 || ( $titleMatches !==
null && $titleMatches->searchContainedSyntax() )
494 || ( $textMatches !==
null && $textMatches->searchContainedSyntax() )
498 $this->
getOutput()->addHTML(
'<p></p>' );
503 $messageName =
'searchmenu-new-nocreate';
504 $linkClass =
'mw-search-createlink';
506 if ( !
$title->isExternal() ) {
507 if (
$title->isKnown() ) {
508 $messageName =
'searchmenu-exists';
509 $linkClass =
'mw-search-exists';
511 &&
$title->quickUserCan(
'create', $this->getUser() )
513 $messageName =
'searchmenu-new';
520 Message::numParam( $num )
525 if ( $messageName ) {
526 $this->
getOutput()->wrapWikiMsg(
"<p class=\"$linkClass\">\n$1</p>",
$params );
529 $this->
getOutput()->addHTML(
'<p></p>' );
546 $out->allowClickjacking();
549 if ( strval(
$term ) !==
'' ) {
550 $out->setPageTitle( $this->
msg(
'searchresults' ) );
551 $out->setHTMLTitle( $this->
msg(
'pagetitle' )
552 ->plaintextParams( $this->
msg(
'searchresults-title' )->plaintextParams(
$term )->
text() )
553 ->inContentLanguage()->
text()
557 if ( $this->mPrefix !==
'' ) {
558 $subtitle = $this->
msg(
'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
571 'title' => $this->
msg(
'search-filter-title-prefix-reset' )->
text(),
573 $this->
msg(
'search-filter-title-prefix-reset' )->
text()
576 $out->setSubtitle( $subtitle );
579 $out->addJsConfigVars( [
'searchTerm' =>
$term ] );
580 $out->addModules(
'mediawiki.special.search' );
581 $out->addModuleStyles( [
582 'mediawiki.special',
'mediawiki.special.search.styles',
'mediawiki.ui',
'mediawiki.ui.button',
583 'mediawiki.ui.input',
'mediawiki.widgets.SearchInputWidget.styles',
593 return $this->profile ===
'advanced';
605 foreach ( $this->searchConfig->searchableNamespaces()
as $ns =>
$name ) {
606 if (
$request->getCheck(
'ns' . $ns ) ) {
643 if (
$user->isLoggedIn() &&
644 $user->matchEditToken(
653 $user->setOption(
'searchNs' . $n,
false );
658 $user->setOption(
'searchNs' . $n,
true );
662 $user->saveSettings();
676 $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
677 $defaultNs = $this->searchConfig->defaultNamespaces();
680 'message' =>
'searchprofile-articles',
681 'tooltip' =>
'searchprofile-articles-tooltip',
682 'namespaces' => $defaultNs,
683 'namespace-messages' => $this->searchConfig->namespacesAsText(
688 'message' =>
'searchprofile-images',
689 'tooltip' =>
'searchprofile-images-tooltip',
693 'message' =>
'searchprofile-everything',
694 'tooltip' =>
'searchprofile-everything-tooltip',
695 'namespaces' => $nsAllSet,
698 'message' =>
'searchprofile-advanced',
699 'tooltip' =>
'searchprofile-advanced-tooltip',
704 Hooks::run(
'SpecialSearchProfiles', [ &$profiles ] );
706 foreach ( $profiles
as &$data ) {
707 if ( !is_array( $data[
'namespaces'] ) ) {
710 sort( $data[
'namespaces'] );
722 if ( $this->searchEngine ===
null ) {
723 $services = MediaWikiServices::getInstance();
724 $this->searchEngine = $this->searchEngineType ?
725 $services->getSearchEngineFactory()->create( $this->searchEngineType ) :
758 $this->extraParams[$key] =
$value;
getNamespaces()
Current namespaces.
getPageTitle( $subpage=false)
Get a self-referential title object.
static errorBox( $html, $heading='')
Return an error box.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
For QUnit the mediawiki tests qunit testrunner dependency will be added to any module whereas SearchGetNearMatch runs after $term
msg( $key)
Wrapper around wfMessage that sets the current context.
processing should stop and the error should be shown to the user * false
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
getOutput()
Get the OutputPage being used for this instance.
wfReadOnly()
Check whether the wiki is in read-only mode.
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
getLanguage()
Shortcut to get user's language.
getPrefix()
The prefix value send to Special:Search using the 'prefix' URI param It means that the user is willin...
isPowerSearch()
Return true if current search is a power (advanced) search.
setupPage( $term)
Sets up everything for the HTML output page including styles, javascript, page title,...
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
Generic operation result class Has warning/error list, boolean status and arbitrary value.
null for the 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
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
to move a page</td >< td > &*You are moving the page across namespaces
getConfig()
Shortcut to get main config object.
namespace and then decline to actually register it file or subcat img or subcat $title
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
string $searchEngineType
Search engine type, if not default.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
saveNamespaces()
Save namespace preferences when we're supposed to.
static warningBox( $html)
Return a warning box.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
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
SearchEngineConfig $searchConfig
Search engine configurations.
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
Allows to change the fields on the form that will be generated $name
SearchEngine $searchEngine
Search engine.
execute( $par)
Entry point.
Parent class for all special pages.
implements Special:Search - Run text & title search and display the output
getRequest()
Get the WebRequest being used for this instance.
null string $profile
Current search profile.
powerSearch(&$request)
Extract "power search" namespace settings from the request object, returning a list of index numbers ...
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getProfile()
Current search profile.
Contain a class for special pages.
array $extraParams
For links.
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
powerSearchOptions()
Reconstruct the 'power search' options for links TODO: Instead of exposing this publicly,...
goResult( $term)
If an exact title match can be found, jump straight ahead to it.
setExtraParam( $key, $value)
Users of hook SpecialSearchSetupEngine can use this to add more params to links to not lose selection...
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
load()
Set up basic search parameters from the request and user settings.
Configuration handling class for SearchEngine.
string $mPrefix
The prefix url parameter.
showCreateLink( $title, $num, $titleMatches, $textMatches)
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
MediaWiki Linker LinkRenderer null $linkRenderer
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
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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