Inject services into SpecialCategoryTree

Bug: T259960
Change-Id: Ie2a3156f1be52074f28b24507815aef7a746f083
This commit is contained in:
Umherirrender 2021-03-12 21:34:50 +01:00
parent 63b9527d9c
commit bf876f5c19
2 changed files with 17 additions and 5 deletions

View file

@ -15,7 +15,12 @@
"CategoryTreeHooks::initialize"
],
"SpecialPages": {
"CategoryTree": "CategoryTreePage"
"CategoryTree": {
"class": "CategoryTreePage",
"services": [
"SearchEngineFactory"
]
}
},
"APIModules": {
"categorytree": "ApiCategoryTree"

View file

@ -22,8 +22,6 @@
* @author Daniel Kinzler, brightbyte.de
*/
use MediaWiki\MediaWikiServices;
/**
* Special page for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
@ -31,13 +29,22 @@ use MediaWiki\MediaWikiServices;
class CategoryTreePage extends SpecialPage {
public $target = '';
/** @var SearchEngineFactory */
private $searchEngineFactory;
/**
* @var CategoryTree
*/
public $tree = null;
public function __construct() {
/**
* @param SearchEngineFactory $searchEngineFactory
*/
public function __construct(
SearchEngineFactory $searchEngineFactory
) {
parent::__construct( 'CategoryTree' );
$this->searchEngineFactory = $searchEngineFactory;
}
/**
@ -199,7 +206,7 @@ class CategoryTreePage extends SpecialPage {
// No prefix suggestion outside of category namespace
return [];
}
$searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
$searchEngine = $this->searchEngineFactory->create();
$searchEngine->setLimitOffset( $limit, $offset );
// Autocomplete subpage the same as a normal search, but just for categories
$searchEngine->setNamespaces( [ NS_CATEGORY ] );