Merge "Use new hook OutputPageRenderCategoryLink"

This commit is contained in:
jenkins-bot 2024-09-05 20:51:09 +00:00 committed by Gerrit Code Review
commit 63fb60b3e4
2 changed files with 28 additions and 16 deletions

View file

@ -86,7 +86,8 @@
"CategoryTree.CategoryCache", "CategoryTree.CategoryCache",
"MainConfig", "MainConfig",
"DBLoadBalancerFactory", "DBLoadBalancerFactory",
"LinkRenderer" "LinkRenderer",
"TitleFormatter"
] ]
}, },
"config": { "config": {
@ -100,7 +101,7 @@
"SkinAfterPortlet": "default", "SkinAfterPortlet": "default",
"SkinBuildSidebar": "default", "SkinBuildSidebar": "default",
"ParserFirstCallInit": "default", "ParserFirstCallInit": "default",
"OutputPageMakeCategoryLinks": "default", "OutputPageRenderCategoryLink": "default",
"CategoryViewer::doCategoryQuery": "default", "CategoryViewer::doCategoryQuery": "default",
"CategoryViewer::generateLink": "default" "CategoryViewer::generateLink": "default"
}, },

View file

@ -35,13 +35,15 @@ use MediaWiki\Hook\SpecialTrackingCategories__preprocessHook;
use MediaWiki\Html\Html; use MediaWiki\Html\Html;
use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkTarget; use MediaWiki\Linker\LinkTarget;
use MediaWiki\Output\Hook\OutputPageMakeCategoryLinksHook; use MediaWiki\Output\Hook\OutputPageRenderCategoryLinkHook;
use MediaWiki\Output\OutputPage; use MediaWiki\Output\OutputPage;
use MediaWiki\Page\ProperPageIdentity;
use MediaWiki\Parser\Parser; use MediaWiki\Parser\Parser;
use MediaWiki\Parser\Sanitizer; use MediaWiki\Parser\Sanitizer;
use MediaWiki\ResourceLoader as RL; use MediaWiki\ResourceLoader as RL;
use MediaWiki\SpecialPage\SpecialPage; use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\Title\Title; use MediaWiki\Title\Title;
use MediaWiki\Title\TitleFormatter;
use PPFrame; use PPFrame;
use Skin; use Skin;
use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\Rdbms\IConnectionProvider;
@ -58,7 +60,7 @@ class Hooks implements
SpecialTrackingCategories__generateCatLinkHook, SpecialTrackingCategories__generateCatLinkHook,
SkinBuildSidebarHook, SkinBuildSidebarHook,
ParserFirstCallInitHook, ParserFirstCallInitHook,
OutputPageMakeCategoryLinksHook, OutputPageRenderCategoryLinkHook,
CategoryViewer__doCategoryQueryHook, CategoryViewer__doCategoryQueryHook,
CategoryViewer__generateLinkHook CategoryViewer__generateLinkHook
{ {
@ -66,17 +68,20 @@ class Hooks implements
private Config $config; private Config $config;
private IConnectionProvider $dbProvider; private IConnectionProvider $dbProvider;
private LinkRenderer $linkRenderer; private LinkRenderer $linkRenderer;
private TitleFormatter $titleFormatter;
public function __construct( public function __construct(
CategoryCache $categoryCache, CategoryCache $categoryCache,
Config $config, Config $config,
IConnectionProvider $dbProvider, IConnectionProvider $dbProvider,
LinkRenderer $linkRenderer LinkRenderer $linkRenderer,
TitleFormatter $titleFormatter
) { ) {
$this->categoryCache = $categoryCache; $this->categoryCache = $categoryCache;
$this->config = $config; $this->config = $config;
$this->dbProvider = $dbProvider; $this->dbProvider = $dbProvider;
$this->linkRenderer = $linkRenderer; $this->linkRenderer = $linkRenderer;
$this->titleFormatter = $titleFormatter;
} }
/** /**
@ -225,25 +230,31 @@ class Hooks implements
} }
/** /**
* OutputPageMakeCategoryLinks hook, override category links * OutputPageRenderCategoryLink hook
* @param OutputPage $out * @param OutputPage $out
* @param array $categories * @param ProperPageIdentity $categoryTitle
* @param array &$links * @param string $text
* @return bool * @param ?string &$link
* @return void
*/ */
public function onOutputPageMakeCategoryLinks( $out, $categories, &$links ) { public function onOutputPageRenderCategoryLink(
OutputPage $out,
ProperPageIdentity $categoryTitle,
string $text,
?string &$link
): void {
if ( !$this->config->get( 'CategoryTreeHijackPageCategories' ) ) { if ( !$this->config->get( 'CategoryTreeHijackPageCategories' ) ) {
// Not enabled, don't do anything // Not enabled, don't do anything
return true; return;
} }
$options = $this->config->get( 'CategoryTreePageCategoryOptions' );
foreach ( $categories as $category => $type ) {
$links[$type][] = $this->parserHook( $category, $options, null, null, true );
}
CategoryTree::setHeaders( $out ); CategoryTree::setHeaders( $out );
return false; $options = $this->config->get( 'CategoryTreePageCategoryOptions' );
$link = $this->parserHook(
$this->titleFormatter->getPrefixedText( $categoryTitle ),
$options, null, null, true
);
} }
/** /**