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 ( $par !==
null && $par !==
'' &&
$term ===
'' ) {
123 $query[
'search'] = str_replace(
'_',
' ', $par );
132 if (
$request->getCheck(
'nsRemember' ) ) {
143 $this->searchEngineType =
$request->getVal(
'srbackend' );
146 if ( $url !==
null ) {
148 $out->redirect( $url );
154 if ( !is_null(
$title ) ) {
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 );
187 $this->
msg(
'search-external' )->escaped() .
189 "<p class='mw-searchdisabled'>" .
190 $this->
msg(
'searchdisabled' )->escaped() .
192 $this->
msg(
'googlesearch' )->rawParams(
193 htmlspecialchars(
$term ),
195 $this->
msg(
'searchbutton' )->escaped()
208 list( $this->limit, $this->offset ) =
$request->getLimitOffset( 20,
'' );
209 $this->mPrefix =
$request->getVal(
'prefix',
'' );
210 if ( $this->mPrefix !==
'' ) {
221 # Extract manually requested namespaces
223 if ( $nslist === [] ) {
224 # Fallback to user preference
225 $nslist = $this->searchConfig->userNamespaces(
$user );
229 if ( $nslist === [] ) {
238 foreach ( $profiles
as $key =>
$data ) {
239 if ( $nslist ===
$data[
'namespaces'] && $key !==
'advanced' ) {
244 } elseif (
$profile ===
'advanced' ) {
246 } elseif ( isset( $profiles[
$profile][
'namespaces'] ) ) {
251 $this->
namespaces = $profiles[
'default'][
'namespaces'];
254 $this->fulltext =
$request->getVal(
'fulltext' );
255 $this->runSuggestion = (bool)
$request->getVal(
'runsuggestion',
true );
266 # If the string cannot be used to create a title
270 # If there's an exact or very near match, jump right there.
273 if ( is_null(
$title ) ) {
281 return $url ??
$title->getFullUrlForRedirect();
288 if ( $this->searchEngineType !==
null ) {
289 $this->
setExtraParam(
'srbackend', $this->searchEngineType );
298 $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
299 getFormattedNsText(
NS_FILE ) .
':';
300 if ( trim(
$term ) ===
'' || $filePrefix === trim(
$term ) ) {
303 # Hook requested termination
310 $out->addHTML( $formWidget->render(
311 $this->profile,
$term, 0, 0, $this->offset, $this->isPowerSearch()
317 $search->setFeatureData(
'rewrite', $this->runSuggestion );
318 $search->setLimitOffset( $this->limit, $this->offset );
320 $search->setSort( $this->sort );
323 Hooks::run(
'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
325 # Hook requested termination
330 $showSuggestion =
$title ===
null || !
$title->isKnown();
331 $search->setShowSuggestion( $showSuggestion );
333 $rewritten = $search->transformSearchTerm(
$term );
334 if ( $rewritten !==
$term ) {
336 wfDeprecated(
'SearchEngine::transformSearchTerm() (overridden by ' .
337 get_class( $search ) .
')',
'1.32' );
340 $rewritten = $search->replacePrefixes(
$term );
341 if ( $rewritten !==
$term ) {
342 wfDeprecated(
'SearchEngine::replacePrefixes() (overridden by ' .
343 get_class( $search ) .
')',
'1.32' );
347 $titleMatches = $search->searchTitle( $rewritten );
348 $textMatches = $search->searchText( $rewritten );
351 if ( $textMatches instanceof
Status ) {
352 $textStatus = $textMatches;
353 $textMatches = $textStatus->getValue();
357 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
358 if ( $titleMatches ) {
359 $titleMatchesNum = $titleMatches->numRows();
360 $numTitleMatches = $titleMatches->getTotalHits();
362 if ( $textMatches ) {
363 $textMatchesNum = $textMatches->numRows();
364 $numTextMatches = $textMatches->getTotalHits();
365 if ( $textMatchesNum > 0 ) {
366 $search->augmentSearchResults( $textMatches );
369 $num = $titleMatchesNum + $textMatchesNum;
370 $totalRes = $numTitleMatches + $numTextMatches;
374 $out->addHTML( $formWidget->render(
375 $this->profile,
$term, $num, $totalRes, $this->offset, $this->isPowerSearch()
379 if ( $textMatches ) {
381 $out->addHTML( $dymWidget->render(
$term, $textMatches ) );
384 $hasErrors = $textStatus && $textStatus->getErrors() !== [];
385 $hasOtherResults = $textMatches &&
386 $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS );
388 if ( $textMatches && $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) {
389 $out->addHTML(
'<div class="searchresults mw-searchresults-has-iw">' );
391 $out->addHTML(
'<div class="searchresults">' );
395 list( $error, $warning ) = $textStatus->splitByErrorType();
396 if ( $error->getErrors() ) {
397 $out->addHTML( Html::errorBox(
398 $error->getHTML(
'search-error' )
401 if ( $warning->getErrors() ) {
402 $out->addHTML( Html::warningBox(
403 $warning->getHTML(
'search-warning' )
411 Hooks::run(
'SpecialSearchResults', [
$term, &$titleMatches, &$textMatches ] );
415 $out->wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
416 $hasOtherResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
427 if ( $search->getFeatureData(
'enable-new-crossproject-page' ) !==
false ) {
431 $sidebarResultWidget,
433 MediaWikiServices::getInstance()->getInterwikiLookup(),
434 $search->getFeatureData(
'show-multimedia-search-results' )
440 $sidebarResultWidget,
442 MediaWikiServices::getInstance()->getInterwikiLookup()
448 $out->addHTML( $widget->render(
449 $term, $this->offset, $titleMatches, $textMatches
452 if ( $titleMatches ) {
453 $titleMatches->free();
456 if ( $textMatches ) {
457 $textMatches->free();
460 $out->addHTML(
'<div class="mw-search-visualclear"></div>' );
463 if ( $totalRes > $this->limit || $this->offset ) {
466 if ( $textMatches && $textMatches->getOffset() !==
null ) {
467 $offset = $textMatches->getOffset();
476 $this->limit + $this->offset >= $totalRes
478 $out->addHTML(
"<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
482 $out->addHTML(
"</div>" );
498 || ( $titleMatches !==
null && $titleMatches->searchContainedSyntax() )
499 || ( $textMatches !==
null && $textMatches->searchContainedSyntax() )
503 $this->
getOutput()->addHTML(
'<p></p>' );
508 $messageName =
'searchmenu-new-nocreate';
509 $linkClass =
'mw-search-createlink';
511 if ( !
$title->isExternal() ) {
512 if (
$title->isKnown() ) {
513 $messageName =
'searchmenu-exists';
514 $linkClass =
'mw-search-exists';
516 &&
$title->quickUserCan(
'create', $this->getUser() )
518 $messageName =
'searchmenu-new';
525 Message::numParam( $num )
530 if ( $messageName ) {
531 $this->
getOutput()->wrapWikiMsg(
"<p class=\"$linkClass\">\n$1</p>",
$params );
534 $this->
getOutput()->addHTML(
'<p></p>' );
551 $out->allowClickjacking();
554 if ( strval(
$term ) !==
'' ) {
555 $out->setPageTitle( $this->
msg(
'searchresults' ) );
556 $out->setHTMLTitle( $this->
msg(
'pagetitle' )
557 ->plaintextParams( $this->
msg(
'searchresults-title' )->plaintextParams(
$term )->
text() )
558 ->inContentLanguage()->
text()
562 if ( $this->mPrefix !==
'' ) {
563 $subtitle = $this->
msg(
'search-filter-title-prefix' )->plaintextParams( $this->mPrefix );
576 'title' => $this->
msg(
'search-filter-title-prefix-reset' )->
text(),
578 $this->
msg(
'search-filter-title-prefix-reset' )->
text()
581 $out->setSubtitle( $subtitle );
584 $out->addJsConfigVars( [
'searchTerm' =>
$term ] );
585 $out->addModules(
'mediawiki.special.search' );
586 $out->addModuleStyles( [
587 'mediawiki.special',
'mediawiki.special.search.styles',
'mediawiki.ui',
'mediawiki.ui.button',
588 'mediawiki.ui.input',
'mediawiki.widgets.SearchInputWidget.styles',
598 return $this->profile ===
'advanced';
610 foreach ( $this->searchConfig->searchableNamespaces()
as $ns =>
$name ) {
611 if (
$request->getCheck(
'ns' . $ns ) ) {
648 if (
$user->isLoggedIn() &&
649 $user->matchEditToken(
658 $user->setOption(
'searchNs' . $n,
false );
663 $user->setOption(
'searchNs' . $n,
true );
667 $user->saveSettings();
681 $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
682 $defaultNs = $this->searchConfig->defaultNamespaces();
685 'message' =>
'searchprofile-articles',
686 'tooltip' =>
'searchprofile-articles-tooltip',
687 'namespaces' => $defaultNs,
688 'namespace-messages' => $this->searchConfig->namespacesAsText(
693 'message' =>
'searchprofile-images',
694 'tooltip' =>
'searchprofile-images-tooltip',
698 'message' =>
'searchprofile-everything',
699 'tooltip' =>
'searchprofile-everything-tooltip',
700 'namespaces' => $nsAllSet,
703 'message' =>
'searchprofile-advanced',
704 'tooltip' =>
'searchprofile-advanced-tooltip',
709 Hooks::run(
'SpecialSearchProfiles', [ &$profiles ] );
711 foreach ( $profiles
as &
$data ) {
712 if ( !is_array(
$data[
'namespaces'] ) ) {
715 sort(
$data[
'namespaces'] );
727 if ( $this->searchEngine ===
null ) {
728 $services = MediaWikiServices::getInstance();
729 $this->searchEngine = $this->searchEngineType ?
730 $services->getSearchEngineFactory()->create( $this->searchEngineType ) :
763 $this->extraParams[$key] =
$value;
getNamespaces()
Current namespaces.
getPageTitle( $subpage=false)
Get a self-referential title object.
return true to allow those checks to and false if checking is done & $user
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
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.
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
wfReadOnly()
Check whether the wiki is in read-only mode.
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
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
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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.
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
whereas SearchGetNearMatch runs after $term
SearchEngineConfig $searchConfig
Search engine configurations.
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
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
showGoogleSearch( $term)
Output a google search form if search is disabled.
SearchEngine $searchEngine
Search engine.
execute( $par)
Entry point.
Parent class for all special pages.
buildPrevNextNavigation( $offset, $limit, array $query=[], $atend=false, $subpage=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
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...