* @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();
}
/**
$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->newSearchEngine()->
+ 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;
}
// 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' => [
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;