Inject service LinkRenderer into CategoryTree

Change-Id: Id70e9b26229332889de009b55837dbab6ecbb163
This commit is contained in:
Fomafix 2023-10-26 20:22:10 +00:00
parent e81f6fe15e
commit e492044e44
5 changed files with 31 additions and 8 deletions

View file

@ -26,6 +26,7 @@
"ConfigFactory",
"DBLoadBalancerFactory",
"LanguageConverterFactory",
"LinkRenderer",
"MainWANObjectCache"
]
}
@ -95,7 +96,8 @@
"class": "MediaWiki\\Extension\\CategoryTree\\Hooks",
"services": [
"CategoryTree.CategoryCache",
"MainConfig"
"MainConfig",
"LinkRenderer"
]
},
"config": {

View file

@ -8,6 +8,7 @@ use FormatJson;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigFactory;
use MediaWiki\Languages\LanguageConverterFactory;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Title\Title;
use WANObjectCache;
use Wikimedia\ParamValidator\ParamValidator;
@ -37,6 +38,9 @@ class ApiCategoryTree extends ApiBase {
/** @var LanguageConverterFactory */
private $languageConverterFactory;
/** @var LinkRenderer */
private $linkRenderer;
/** @var IConnectionProvider */
private $dbProvider;
@ -49,6 +53,7 @@ class ApiCategoryTree extends ApiBase {
* @param ConfigFactory $configFactory
* @param IConnectionProvider $dbProvider
* @param LanguageConverterFactory $languageConverterFactory
* @param LinkRenderer $linkRenderer
* @param WANObjectCache $wanCache
*/
public function __construct(
@ -57,11 +62,13 @@ class ApiCategoryTree extends ApiBase {
ConfigFactory $configFactory,
IConnectionProvider $dbProvider,
LanguageConverterFactory $languageConverterFactory,
LinkRenderer $linkRenderer,
WANObjectCache $wanCache
) {
parent::__construct( $main, $action );
$this->configFactory = $configFactory;
$this->languageConverterFactory = $languageConverterFactory;
$this->linkRenderer = $linkRenderer;
$this->dbProvider = $dbProvider;
$this->wanCache = $wanCache;
}
@ -81,7 +88,7 @@ class ApiCategoryTree extends ApiBase {
$depth = isset( $options['depth'] ) ? (int)$options['depth'] : 1;
$ct = new CategoryTree( $options );
$ct = new CategoryTree( $options, $this->linkRenderer );
$depth = OptionManager::capDepth( $ct->optionManager->getOption( 'mode' ), $depth );
$ctConfig = $this->configFactory->makeConfig( 'categorytree' );
$html = $this->getHTML( $ct, $title, $depth, $ctConfig );

View file

@ -49,10 +49,14 @@ class CategoryTree {
/**
* @param array $options
* @param LinkRenderer $linkRenderer
*/
public function __construct( array $options ) {
public function __construct(
array $options,
LinkRenderer $linkRenderer
) {
$this->optionManager = new OptionManager( $options );
$this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
$this->linkRenderer = $linkRenderer;
}
/**

View file

@ -100,7 +100,7 @@ class CategoryTreePage extends SpecialPage {
$options[$option] = $request->getVal( $option, $default );
}
$this->tree = new CategoryTree( $options );
$this->tree = new CategoryTree( $options, $this->getLinkRenderer() );
$this->getOutput()->addWikiMsg( 'categorytree-header' );

View file

@ -33,6 +33,7 @@ use MediaWiki\Hook\SkinBuildSidebarHook;
use MediaWiki\Hook\SpecialTrackingCategories__generateCatLinkHook;
use MediaWiki\Hook\SpecialTrackingCategories__preprocessHook;
use MediaWiki\Html\Html;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\Output\OutputPage;
use MediaWiki\Parser\Sanitizer;
@ -67,13 +68,22 @@ class Hooks implements
/** @var Config */
private $config;
/** @var LinkRenderer */
private $linkRenderer;
/**
* @param CategoryCache $categoryCache
* @param Config $config
* @param LinkRenderer $linkRenderer
*/
public function __construct( CategoryCache $categoryCache, Config $config ) {
public function __construct(
CategoryCache $categoryCache,
Config $config,
LinkRenderer $linkRenderer
) {
$this->categoryCache = $categoryCache;
$this->config = $config;
$this->linkRenderer = $linkRenderer;
}
/**
@ -193,7 +203,7 @@ class Hooks implements
$parserOutput->addModules( [ 'ext.categoryTree' ] );
}
$ct = new CategoryTree( $argv );
$ct = new CategoryTree( $argv, $this->linkRenderer );
$attr = Sanitizer::validateTagAttributes( $argv, 'div' );
@ -316,7 +326,7 @@ class Hooks implements
if ( $mode !== null ) {
$options['mode'] = $mode;
}
$tree = new CategoryTree( $options );
$tree = new CategoryTree( $options, $this->linkRenderer );
$cat = $this->categoryCache->getCategory( $title );