From bf876f5c1909b54f4765f00dad3266632b682d27 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Fri, 12 Mar 2021 21:34:50 +0100 Subject: [PATCH] Inject services into SpecialCategoryTree Bug: T259960 Change-Id: Ie2a3156f1be52074f28b24507815aef7a746f083 --- extension.json | 7 ++++++- includes/CategoryTreePage.php | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/extension.json b/extension.json index 80cb14a5..1ca58252 100644 --- a/extension.json +++ b/extension.json @@ -15,7 +15,12 @@ "CategoryTreeHooks::initialize" ], "SpecialPages": { - "CategoryTree": "CategoryTreePage" + "CategoryTree": { + "class": "CategoryTreePage", + "services": [ + "SearchEngineFactory" + ] + } }, "APIModules": { "categorytree": "ApiCategoryTree" diff --git a/includes/CategoryTreePage.php b/includes/CategoryTreePage.php index fa4ca4aa..46d4b419 100644 --- a/includes/CategoryTreePage.php +++ b/includes/CategoryTreePage.php @@ -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 ] );