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 );
151 $title = Title::newFromText(
$term );
152 if ( !is_null( $title ) ) {
153 Hooks::run(
'SpecialSearchNogomatch', [ &$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'] ) ) {
227 $this->
namespaces = $profiles[$profile][
'namespaces'];
230 $profile =
'default';
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
248 if ( is_null( Title::newFromText(
$term ) ) ) {
251 # If there's an exact or very near match, jump right there.
254 if ( is_null( $title ) ) {
258 if ( !Hooks::run(
'SpecialSearchGoResult', [
$term, $title, &$url ] ) ) {
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 ) ) {
284 if ( !Hooks::run(
'SpecialSearchResultsPrepend', [ $this,
$out,
$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 );
302 $search->prefix = $this->mPrefix;
303 $term = $search->transformSearchTerm(
$term );
305 Hooks::run(
'SpecialSearchSetupEngine', [ $this, $this->profile, $search ] );
306 if ( !Hooks::run(
'SpecialSearchResultsPrepend', [ $this,
$out,
$term ] ) ) {
307 # Hook requested termination
311 $title = Title::newFromText(
$term );
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() ) {
368 $out->addHTML( Html::errorBox(
369 $error->getHTML(
'search-error' )
372 if ( $warning->getErrors() ) {
373 $out->addHTML( Html::warningBox(
374 $warning->getHTML(
'search-warning' )
380 $this->
showCreateLink( $title, $num, $titleMatches, $textMatches );
382 Hooks::run(
'SpecialSearchResults', [
$term, &$titleMatches, &$textMatches ] );
386 $out->wrapWikiMsg(
"<p class=\"mw-search-nonefound\">\n$1</p>", [
387 $hasOtherResults ?
'search-nonefound-thiswiki' :
'search-nonefound',
398 if ( $search->getFeatureData(
'enable-new-crossproject-page' ) !==
false ) {
402 $sidebarResultWidget,
404 MediaWikiServices::getInstance()->getInterwikiLookup(),
405 $search->getFeatureData(
'show-multimedia-search-results' )
411 $sidebarResultWidget,
413 MediaWikiServices::getInstance()->getInterwikiLookup()
419 $out->addHTML( $widget->render(
420 $term, $this->offset, $titleMatches, $textMatches
423 if ( $titleMatches ) {
424 $titleMatches->free();
427 if ( $textMatches ) {
428 $textMatches->free();
431 $out->addHTML(
'<div class="mw-search-visualclear"></div>' );
434 if ( $totalRes > $this->limit || $this->offset ) {
437 if ( $textMatches && $textMatches->getOffset() !==
null ) {
438 $offset = $textMatches->getOffset();
440 $offset = $this->offset;
448 $this->limit + $this->offset >= $totalRes
450 $out->addHTML(
"<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
454 $out->addHTML(
"</div>" );
456 Hooks::run(
'SpecialSearchResultsAppend', [ $this,
$out,
$term ] );
469 if ( is_null( $title ) || $title->getDBkey() ===
''
470 || ( $titleMatches !==
null && $titleMatches->searchContainedSyntax() )
471 || ( $textMatches !==
null && $textMatches->searchContainedSyntax() )
475 $this->
getOutput()->addHTML(
'<p></p>' );
480 $messageName =
'searchmenu-new-nocreate';
481 $linkClass =
'mw-search-createlink';
483 if ( !$title->isExternal() ) {
484 if ( $title->isKnown() ) {
485 $messageName =
'searchmenu-exists';
486 $linkClass =
'mw-search-exists';
487 } elseif ( ContentHandler::getForTitle( $title )->supportsDirectEditing()
488 && $title->quickUserCan(
'create', $this->getUser() )
490 $messageName =
'searchmenu-new';
497 Message::numParam( $num )
499 Hooks::run(
'SpecialSearchCreateLink', [ $title, &
$params ] );
502 if ( $messageName ) {
503 $this->
getOutput()->wrapWikiMsg(
"<p class=\"$linkClass\">\n$1</p>",
$params );
506 $this->
getOutput()->addHTML(
'<p></p>' );
523 $out->allowClickjacking();
526 if ( strval(
$term ) !==
'' ) {
527 $out->setPageTitle( $this->
msg(
'searchresults' ) );
528 $out->setHTMLTitle( $this->
msg(
'pagetitle' )
529 ->plaintextParams( $this->
msg(
'searchresults-title' )->plaintextParams(
$term )->
text() )
530 ->inContentLanguage()->
text()
534 $out->addJsConfigVars( [
'searchTerm' =>
$term ] );
535 $out->addModules(
'mediawiki.special.search' );
536 $out->addModuleStyles( [
537 'mediawiki.special',
'mediawiki.special.search.styles',
'mediawiki.ui',
'mediawiki.ui.button',
538 'mediawiki.ui.input',
'mediawiki.widgets.SearchInputWidget.styles',
548 return $this->profile ===
'advanced';
560 foreach ( $this->searchConfig->searchableNamespaces() as $ns => $name ) {
561 if (
$request->getCheck(
'ns' . $ns ) ) {
583 $opt[
'profile'] = $this->profile;
586 return $opt + $this->extraParams;
598 if ( $user->isLoggedIn() &&
599 $user->matchEditToken(
607 foreach ( MWNamespace::getValidNamespaces() as $n ) {
608 $user->setOption(
'searchNs' . $n,
false );
613 $user->setOption(
'searchNs' . $n,
true );
616 DeferredUpdates::addCallableUpdate(
function () use ( $user ) {
617 $user->saveSettings();
631 $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
632 $defaultNs = $this->searchConfig->defaultNamespaces();
635 'message' =>
'searchprofile-articles',
636 'tooltip' =>
'searchprofile-articles-tooltip',
637 'namespaces' => $defaultNs,
638 'namespace-messages' => $this->searchConfig->namespacesAsText(
643 'message' =>
'searchprofile-images',
644 'tooltip' =>
'searchprofile-images-tooltip',
648 'message' =>
'searchprofile-everything',
649 'tooltip' =>
'searchprofile-everything-tooltip',
650 'namespaces' => $nsAllSet,
653 'message' =>
'searchprofile-advanced',
654 'tooltip' =>
'searchprofile-advanced-tooltip',
655 'namespaces' => self::NAMESPACES_CURRENT,
659 Hooks::run(
'SpecialSearchProfiles', [ &$profiles ] );
661 foreach ( $profiles as &$data ) {
662 if ( !is_array( $data[
'namespaces'] ) ) {
665 sort( $data[
'namespaces'] );
677 if ( $this->searchEngine ===
null ) {
678 $this->searchEngine = $this->searchEngineType ?
679 MediaWikiServices::getInstance()->getSearchEngineFactory()->create( $this->searchEngineType ) :
680 MediaWikiServices::getInstance()->newSearchEngine();
683 return $this->searchEngine;
691 return $this->profile;
712 $this->extraParams[$key] =
$value;
to move a page</td >< td > &*You are moving the page across namespaces
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,...
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.
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 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 local content language as $wgContLang
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
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
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
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
MediaWiki has optional support for a high distributed memory object caching system For general information on but for a larger site with heavy load