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 ) ) {
158 Hooks::run(
'SpecialSearchNogomatch', [ &
$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 !==
'' ) {
206 $this->sort =
$request->getVal(
'sort', SearchEngine::DEFAULT_SORT );
207 if ( $this->sort !== SearchEngine::DEFAULT_SORT ) {
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'] ) ) {
240 $this->
namespaces = $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
261 if ( is_null( Title::newFromText(
$term ) ) ) {
264 # If there's an exact or very near match, jump right there.
267 if ( is_null(
$title ) ) {
271 if ( !Hooks::run(
'SpecialSearchGoResult', [
$term,
$title, &$url ] ) ) {
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 ) ) {
296 if ( !Hooks::run(
'SpecialSearchResultsPrepend', [ $this,
$out,
$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 );
315 $search->prefix = $this->mPrefix;
317 Hooks::run(
'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
318 if ( !Hooks::run(
'SpecialSearchResultsPrepend', [ $this,
$out,
$term ] ) ) {
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() ) {
391 $out->addHTML( Html::errorBox(
392 $error->getHTML(
'search-error' )
395 if ( $warning->getErrors() ) {
396 $out->addHTML( Html::warningBox(
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();
463 $offset = $this->offset;
471 $this->limit + $this->offset >= $totalRes
473 $out->addHTML(
"<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
477 $out->addHTML(
"</div>" );
479 Hooks::run(
'SpecialSearchResultsAppend', [ $this,
$out,
$term ] );
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';
510 } elseif ( ContentHandler::getForTitle(
$title )->supportsDirectEditing()
511 &&
$title->quickUserCan(
'create', $this->getUser() )
513 $messageName =
'searchmenu-new';
520 Message::numParam( $num )
522 Hooks::run(
'SpecialSearchCreateLink', [
$title, &
$params ] );
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 );
567 $subtitle .= Xml::element(
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 ) ) {
628 $opt[
'profile'] = $this->profile;
631 return $opt + $this->extraParams;
643 if (
$user->isLoggedIn() &&
644 $user->matchEditToken(
652 foreach ( MWNamespace::getValidNamespaces()
as $n ) {
653 $user->setOption(
'searchNs' . $n,
false );
658 $user->setOption(
'searchNs' . $n,
true );
661 DeferredUpdates::addCallableUpdate(
function ()
use (
$user ) {
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 ) :
729 return $this->searchEngine;
737 return $this->profile;
758 $this->extraParams[$key] =
$value;
770 return $this->mPrefix;
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
to move a page</td >< td > &*You are moving the page across namespaces
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
wfReadOnly()
Check whether the wiki is in read-only mode.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Configuration handling class for SearchEngine.
Contain a class for special pages.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
implements Special:Search - Run text & title search and display the output
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...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
string $mPrefix
The prefix url parameter.
null string $profile
Current search profile.
load()
Set up basic search parameters from the request and user settings.
SearchEngineConfig $searchConfig
Search engine configurations.
getPrefix()
The prefix value send to Special:Search using the 'prefix' URI param It means that the user is willin...
saveNamespaces()
Save namespace preferences when we're supposed to.
getProfile()
Current search profile.
SearchEngine $searchEngine
Search engine.
isPowerSearch()
Return true if current search is a power (advanced) search.
getNamespaces()
Current namespaces.
powerSearchOptions()
Reconstruct the 'power search' options for links TODO: Instead of exposing this publicly,...
string $searchEngineType
Search engine type, if not default.
powerSearch(&$request)
Extract "power search" namespace settings from the request object, returning a list of index numbers ...
array $extraParams
For links.
execute( $par)
Entry point.
setupPage( $term)
Sets up everything for the HTML output page including styles, javascript, page title,...
showCreateLink( $title, $num, $titleMatches, $textMatches)
Generic operation result class Has warning/error list, boolean status and arbitrary 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
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
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
namespace and then decline to actually register it & $namespaces
For QUnit the mediawiki tests qunit testrunner dependency will be added to any module whereas SearchGetNearMatch runs after $term
namespace and then decline to actually register it file or subcat img or subcat $title
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
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
Allows to change the fields on the form that will be generated $name
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
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
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 local account $user
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
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))
MediaWiki has optional support for a high distributed memory object caching system For general information on but for a larger site with heavy load