* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* implements Special:Search - Run text & title search and display the output
* @ingroup SpecialPage
*/
protected $customCaptions;
+ /**
+ * Search engine configurations.
+ * @var SearchEngineConfig
+ */
+ protected $searchConfig;
+
const NAMESPACES_CURRENT = 'sense';
public function __construct() {
parent::__construct( 'Search' );
+ $this->searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig();
}
/**
$out = $this->getOutput();
$out->allowClickjacking();
$out->addModuleStyles( [
- 'mediawiki.special', 'mediawiki.special.search', 'mediawiki.ui', 'mediawiki.ui.button',
+ 'mediawiki.special', 'mediawiki.special.search.styles', 'mediawiki.ui', 'mediawiki.ui.button',
'mediawiki.ui.input', 'mediawiki.widgets.SearchInputWidget.styles',
] );
$this->addHelpLink( 'Help:Searching' );
$nslist = $this->powerSearch( $request );
if ( !count( $nslist ) ) {
# Fallback to user preference
- $nslist = SearchEngine::userNamespaces( $user );
+ $nslist = $this->searchConfig->userNamespaces( $user );
}
$profile = null;
return;
}
# If there's an exact or very near match, jump right there.
- $title = SearchEngine::getNearMatch( $term );
+ $title = $this->getSearchEngine()
+ ->getNearMatcher( $this->getConfig() )->getNearMatch( $term );
if ( !is_null( $title ) &&
Hooks::run( 'SpecialSearchGoResult', [ $term, $title, &$url ] )
*/
protected function powerSearch( &$request ) {
$arr = [];
- foreach ( SearchEngine::searchableNamespaces() as $ns => $name ) {
+ foreach ( $this->searchConfig->searchableNamespaces() as $ns => $name ) {
if ( $request->getCheck( 'ns' . $ns ) ) {
$arr[] = $ns;
}
$user->setOption( 'searchNs' . $n, true );
}
- $user->saveSettings();
+ DeferredUpdates::addCallableUpdate( function () use ( $user ) {
+ $user->saveSettings();
+ } );
+
return true;
}
// Groups namespaces into rows according to subject
$rows = [];
- foreach ( SearchEngine::searchableNamespaces() as $namespace => $name ) {
+ foreach ( $this->searchConfig->searchableNamespaces() as $namespace => $name ) {
$subject = MWNamespace::getSubject( $namespace );
if ( !array_key_exists( $subject, $rows ) ) {
$rows[$subject] = "";
*/
protected function getSearchProfiles() {
// Builds list of Search Types (profiles)
- $nsAllSet = array_keys( SearchEngine::searchableNamespaces() );
-
+ $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
+ $defaultNs = $this->searchConfig->defaultNamespaces();
$profiles = [
'default' => [
'message' => 'searchprofile-articles',
'tooltip' => 'searchprofile-articles-tooltip',
- 'namespaces' => SearchEngine::defaultNamespaces(),
- 'namespace-messages' => SearchEngine::namespacesAsText(
- SearchEngine::defaultNamespaces()
+ 'namespaces' => $defaultNs,
+ 'namespace-messages' => $this->searchConfig->namespacesAsText(
+ $defaultNs
),
],
'images' => [
'name' => 'search',
'autofocus' => trim( $term ) === '',
'value' => $term,
+ 'dataLocation' => 'content',
+ ] );
+
+ $layout = new OOUI\ActionFieldLayout( $searchWidget, new OOUI\ButtonInputWidget( [
+ 'type' => 'submit',
+ 'label' => $this->msg( 'searchbutton' )->text(),
+ 'flags' => [ 'progressive', 'primary' ],
+ ] ), [
+ 'align' => 'top',
] );
$out =
Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
Html::hidden( 'profile', $this->profile ) .
Html::hidden( 'fulltext', 'Search' ) .
- $searchWidget .
- new OOUI\ButtonInputWidget( [
- 'type' => 'submit',
- 'label' => $this->msg( 'searchbutton' )->text(),
- 'flags' => [ 'progressive', 'primary' ],
- ] );
+ $layout;
// Results-info
if ( $totalNum > 0 && $this->offset < $totalNum ) {
public function getSearchEngine() {
if ( $this->searchEngine === null ) {
$this->searchEngine = $this->searchEngineType ?
- SearchEngine::create( $this->searchEngineType ) : SearchEngine::create();
+ MediaWikiServices::getInstance()->getSearchEngineFactory()->create( $this->searchEngineType ) :
+ MediaWikiServices::getInstance()->newSearchEngine();
}
return $this->searchEngine;