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' );
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 ( $nslist === [] ) {
216 # Fallback to user preference 217 $nslist = $this->searchConfig->userNamespaces(
$user );
221 if ( $nslist === [] ) {
230 foreach ( $profiles
as $key => $data ) {
231 if ( $nslist === $data[
'namespaces'] && $key !==
'advanced' ) {
236 } elseif (
$profile ===
'advanced' ) {
239 if ( isset( $profiles[
$profile][
'namespaces'] ) ) {
243 $profile =
'default';
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 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';
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',
700 'namespaces' => self::NAMESPACES_CURRENT,
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;
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
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
whereas SearchGetNearMatch runs after $term
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
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.
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
saveNamespaces()
Save namespace preferences when we're supposed to.
getOutput()
Get the OutputPage being used for this instance.
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
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
isPowerSearch()
Return true if current search is a power (advanced) search.
getProfile()
Current search profile.
wfReadOnly()
Check whether the wiki is in read-only mode.
array $extraParams
For links.
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
goResult( $term)
If an exact title match can be found, jump straight ahead to it.
load()
Set up basic search parameters from the request and user settings.
string $mPrefix
The prefix url parameter.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
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
namespace and then decline to actually register it file or subcat img or subcat $title
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
powerSearchOptions()
Reconstruct the 'power search' 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.
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
setExtraParam( $key, $value)
Users of hook SpecialSearchSetupEngine can use this to add more params to links to not lose selection...
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 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
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.
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...
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
getRequest()
Get the WebRequest being used for this instance.
SearchEngine $searchEngine
Search engine.
execute( $par)
Entry point.
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
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
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
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.
showCreateLink( $title, $num, $titleMatches, $textMatches)
MediaWiki Linker LinkRenderer null $linkRenderer
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.