Go to the documentation of this file.
93 parent::__construct(
'Search' );
94 $this->searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
107 $term = str_replace(
"\n",
" ",
$request->getText(
'search' ) );
113 if ( strlen( $par ) && !strlen(
$term ) ) {
118 $query[
'search'] = str_replace(
'_',
' ', $par );
127 if ( !is_null(
$request->getVal(
'nsRemember' ) ) ) {
138 $this->searchEngineType =
$request->getVal(
'srbackend' );
141 $request->getVal(
'offset' ) === null
144 if ( $url !==
null ) {
146 $out->redirect( $url );
152 if ( !is_null(
$title ) ) {
159 if ( $this->
getConfig()->
get(
'DisableTextSearch' ) ) {
160 $searchForwardUrl = $this->
getConfig()->get(
'SearchForwardUrl' );
161 if ( $searchForwardUrl ) {
162 $url = str_replace(
'$1', urlencode(
$term ), $searchForwardUrl );
163 $out->redirect( $url );
168 $this->
msg(
'search-external' )->escaped() .
170 "<p class='mw-searchdisabled'>" .
171 $this->
msg(
'searchdisabled' )->escaped() .
173 $this->
msg(
'googlesearch' )->rawParams(
174 htmlspecialchars(
$term ),
176 $this->
msg(
'searchbutton' )->escaped()
195 list( $this->limit, $this->offset ) =
$request->getLimitOffset( 20,
'' );
196 $this->mPrefix =
$request->getVal(
'prefix',
'' );
200 # Extract manually requested namespaces
202 if ( !
count( $nslist ) ) {
203 # Fallback to user preference
204 $nslist = $this->searchConfig->userNamespaces(
$user );
208 if ( !
count( $nslist ) ) {
217 foreach ( $profiles
as $key => $data ) {
218 if ( $nslist === $data[
'namespaces'] && $key !==
'advanced' ) {
223 } elseif (
$profile ===
'advanced' ) {
226 if ( isset( $profiles[
$profile][
'namespaces'] ) ) {
231 $this->
namespaces = $profiles[
'default'][
'namespaces'];
235 $this->fulltext =
$request->getVal(
'fulltext' );
236 $this->runSuggestion = (bool)
$request->getVal(
'runsuggestion',
true );
247 # If the string cannot be used to create a title
251 # If there's an exact or very near match, jump right there.
254 if ( is_null(
$title ) ) {
262 return $url ===
null ?
$title->getFullUrlForRedirect() : $url;
271 if ( $this->searchEngineType !==
null ) {
272 $this->
setExtraParam(
'srbackend', $this->searchEngineType );
282 if ( trim(
$term ) ===
'' || $filePrefix === trim(
$term ) ) {
285 # Hook requested termination
292 $out->addHTML( $formWidget->render(
293 $this->profile,
$term, 0, 0, $this->offset, $this->isPowerSearch()
299 $search->setFeatureData(
'rewrite', $this->runSuggestion );
300 $search->setLimitOffset( $this->limit, $this->offset );
303 $term = $search->transformSearchTerm(
$term );
305 Hooks::run(
'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
307 # Hook requested termination
312 $showSuggestion =
$title ===
null || !
$title->isKnown();
313 $search->setShowSuggestion( $showSuggestion );
316 $rewritten = $search->replacePrefixes(
$term );
318 $titleMatches = $search->searchTitle( $rewritten );
319 $textMatches = $search->searchText( $rewritten );
322 if ( $textMatches instanceof
Status ) {
323 $textStatus = $textMatches;
324 $textMatches = $textStatus->getValue();
328 $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
329 if ( $titleMatches ) {
330 $titleMatchesNum = $titleMatches->numRows();
331 $numTitleMatches = $titleMatches->getTotalHits();
333 if ( $textMatches ) {
334 $textMatchesNum = $textMatches->numRows();
335 $numTextMatches = $textMatches->getTotalHits();
336 if ( $textMatchesNum > 0 ) {
337 $search->augmentSearchResults( $textMatches );
340 $num = $titleMatchesNum + $textMatchesNum;
341 $totalRes = $numTitleMatches + $numTextMatches;
345 $out->addHTML( $formWidget->render(
346 $this->profile,
$term, $num, $totalRes, $this->offset, $this->isPowerSearch()
350 if ( $textMatches ) {
352 $out->addHTML( $dymWidget->render(
$term, $textMatches ) );
355 $hasErrors = $textStatus && $textStatus->getErrors() !== [];
356 $hasOtherResults = $textMatches &&
357 $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS );
359 if ( $textMatches && $textMatches->hasInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) ) {
360 $out->addHTML(
'<div class="searchresults mw-searchresults-has-iw">' );
362 $out->addHTML(
'<div class="searchresults">' );
366 list( $error, $warning ) = $textStatus->splitByErrorType();
367 if ( $error->getErrors() ) {
370 [
'class' =>
'errorbox' ],
371 $error->getHTML(
'search-error' )
374 if ( $warning->getErrors() ) {
377 [
'class' =>
'warningbox' ],
378 $warning->getHTML(
'search-warning' )
386 Hooks::run(
'SpecialSearchResults', [
$term, &$titleMatches, &$textMatches ] );
390 $out->wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
391 $hasOtherResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
401 if ( $search->getFeatureData(
'enable-new-crossproject-page' ) ) {
405 $sidebarResultWidget,
407 MediaWikiServices::getInstance()->getInterwikiLookup(),
408 $search->getFeatureData(
'show-multimedia-search-results' )
414 $sidebarResultWidget,
416 MediaWikiServices::getInstance()->getInterwikiLookup()
422 $out->addHTML( $widget->render(
423 $term, $this->offset, $titleMatches, $textMatches
426 if ( $titleMatches ) {
427 $titleMatches->free();
430 if ( $textMatches ) {
431 $textMatches->free();
434 $out->addHTML(
'<div class="mw-search-visualclear"></div>' );
437 if ( $totalRes > $this->limit || $this->offset ) {
440 if ( $textMatches && $textMatches->getOffset() !== null ) {
441 $offset = $textMatches->getOffset();
451 $this->limit + $this->offset >= $totalRes
453 $out->addHTML(
"<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
457 $out->addHTML(
"</div>" );
473 || ( $titleMatches !==
null && $titleMatches->searchContainedSyntax() )
474 || ( $textMatches !==
null && $textMatches->searchContainedSyntax() )
478 $this->
getOutput()->addHTML(
'<p></p>' );
483 $messageName =
'searchmenu-new-nocreate';
484 $linkClass =
'mw-search-createlink';
486 if ( !
$title->isExternal() ) {
487 if (
$title->isKnown() ) {
488 $messageName =
'searchmenu-exists';
489 $linkClass =
'mw-search-exists';
491 &&
$title->quickUserCan(
'create', $this->getUser() )
493 $messageName =
'searchmenu-new';
500 Message::numParam( $num )
505 if ( $messageName ) {
506 $this->
getOutput()->wrapWikiMsg(
"<p class=\"$linkClass\">\n$1</p>",
$params );
509 $this->
getOutput()->addHTML(
'<p></p>' );
526 $out->allowClickjacking();
529 if ( strval(
$term ) !==
'' ) {
530 $out->setPageTitle( $this->
msg(
'searchresults' ) );
531 $out->setHTMLTitle( $this->
msg(
'pagetitle' )
532 ->rawParams( $this->
msg(
'searchresults-title' )->rawParams(
$term )->
text() )
533 ->inContentLanguage()->
text()
537 $out->addJsConfigVars( [
'searchTerm' =>
$term ] );
538 $out->addModules(
'mediawiki.special.search' );
539 $out->addModuleStyles( [
540 'mediawiki.special',
'mediawiki.special.search.styles',
'mediawiki.ui',
'mediawiki.ui.button',
541 'mediawiki.ui.input',
'mediawiki.widgets.SearchInputWidget.styles',
551 return $this->profile ===
'advanced';
563 foreach ( $this->searchConfig->searchableNamespaces()
as $ns =>
$name ) {
564 if (
$request->getCheck(
'ns' . $ns ) ) {
601 if (
$user->isLoggedIn() &&
602 $user->matchEditToken(
611 $user->setOption(
'searchNs' . $n,
false );
616 $user->setOption(
'searchNs' . $n,
true );
620 $user->saveSettings();
634 $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
635 $defaultNs = $this->searchConfig->defaultNamespaces();
638 'message' =>
'searchprofile-articles',
639 'tooltip' =>
'searchprofile-articles-tooltip',
640 'namespaces' => $defaultNs,
641 'namespace-messages' => $this->searchConfig->namespacesAsText(
646 'message' =>
'searchprofile-images',
647 'tooltip' =>
'searchprofile-images-tooltip',
651 'message' =>
'searchprofile-everything',
652 'tooltip' =>
'searchprofile-everything-tooltip',
653 'namespaces' => $nsAllSet,
656 'message' =>
'searchprofile-advanced',
657 'tooltip' =>
'searchprofile-advanced-tooltip',
662 Hooks::run(
'SpecialSearchProfiles', [ &$profiles ] );
664 foreach ( $profiles
as &$data ) {
665 if ( !is_array( $data[
'namespaces'] ) ) {
668 sort( $data[
'namespaces'] );
680 if ( $this->searchEngine ===
null ) {
681 $this->searchEngine = $this->searchEngineType ?
682 MediaWikiServices::getInstance()->getSearchEngineFactory()->create( $this->searchEngineType ) :
683 MediaWikiServices::getInstance()->newSearchEngine();
715 $this->extraParams[$key] =
$value;
getNamespaces()
Current namespaces.
getPageTitle( $subpage=false)
Get a self-referential title object.
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.
msg( $key)
Wrapper around wfMessage that sets the current context.
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.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
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
wfReadOnly()
Check whether the wiki is in read-only mode.
external whereas SearchGetNearMatch runs after $term
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
Allows to change the fields on the form that will be generated $name
getLanguage()
Shortcut to get user's language.
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
static addCallableUpdate( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
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...
string $searchEngineType
Search engine type, if not default.
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.
when a variable name is used in a it is silently declared as a new masking the global
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
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.
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.
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Configuration handling class for SearchEngine.
string $mPrefix
The prefix url parameter.
showCreateLink( $title, $num, $titleMatches, $textMatches)
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 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...
the array() calling protocol came about after MediaWiki 1.4rc1.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
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