Inject service LinkCache

Change-Id: I254a4a20bac60eb505c30ddbf0fd1f5aea9bdd04
This commit is contained in:
Fomafix 2023-11-01 20:20:45 +00:00
parent 4cf0a84ebd
commit 0f4984dc86
3 changed files with 14 additions and 3 deletions

View file

@ -40,6 +40,7 @@
"class": "MediaWiki\\Extension\\ParserFunctions\\Hooks", "class": "MediaWiki\\Extension\\ParserFunctions\\Hooks",
"services": [ "services": [
"MainConfig", "MainConfig",
"LinkCache",
"RepoGroup", "RepoGroup",
"SpecialPageFactory" "SpecialPageFactory"
] ]

View file

@ -3,6 +3,7 @@
namespace MediaWiki\Extension\ParserFunctions; namespace MediaWiki\Extension\ParserFunctions;
use Config; use Config;
use LinkCache;
use MediaWiki\SpecialPage\SpecialPageFactory; use MediaWiki\SpecialPage\SpecialPageFactory;
use Parser; use Parser;
use RepoGroup; use RepoGroup;
@ -20,17 +21,20 @@ class Hooks implements
/** /**
* @param Config $config * @param Config $config
* @param LinkCache $linkCache
* @param RepoGroup $repoGroup * @param RepoGroup $repoGroup
* @param SpecialPageFactory $specialPageFactory * @param SpecialPageFactory $specialPageFactory
*/ */
public function __construct( public function __construct(
Config $config, Config $config,
LinkCache $linkCache,
RepoGroup $repoGroup, RepoGroup $repoGroup,
SpecialPageFactory $specialPageFactory SpecialPageFactory $specialPageFactory
) { ) {
$this->config = $config; $this->config = $config;
$this->parserFunctions = new ParserFunctions( $this->parserFunctions = new ParserFunctions(
$config, $config,
$linkCache,
$repoGroup, $repoGroup,
$specialPageFactory $specialPageFactory
); );

View file

@ -8,6 +8,7 @@ use DateTimeZone;
use Exception; use Exception;
use ILanguageConverter; use ILanguageConverter;
use Language; use Language;
use LinkCache;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\SpecialPage\SpecialPageFactory; use MediaWiki\SpecialPage\SpecialPageFactory;
use MWTimestamp; use MWTimestamp;
@ -37,6 +38,9 @@ class ParserFunctions {
/** @var Config */ /** @var Config */
private $config; private $config;
/** @var LinkCache */
private $linkCache;
/** @var RepoGroup */ /** @var RepoGroup */
private $repoGroup; private $repoGroup;
@ -45,15 +49,18 @@ class ParserFunctions {
/** /**
* @param Config $config * @param Config $config
* @param LinkCache $linkCache
* @param RepoGroup $repoGroup * @param RepoGroup $repoGroup
* @param SpecialPageFactory $specialPageFactory * @param SpecialPageFactory $specialPageFactory
*/ */
public function __construct( public function __construct(
Config $config, Config $config,
LinkCache $linkCache,
RepoGroup $repoGroup, RepoGroup $repoGroup,
SpecialPageFactory $specialPageFactory SpecialPageFactory $specialPageFactory
) { ) {
$this->config = $config; $this->config = $config;
$this->linkCache = $linkCache;
$this->repoGroup = $repoGroup; $this->repoGroup = $repoGroup;
$this->specialPageFactory = $specialPageFactory; $this->specialPageFactory = $specialPageFactory;
} }
@ -383,12 +390,11 @@ class ParserFunctions {
return false; return false;
} else { } else {
$pdbk = $title->getPrefixedDBkey(); $pdbk = $title->getPrefixedDBkey();
$lc = MediaWikiServices::getInstance()->getLinkCache(); $id = $this->linkCache->getGoodLinkID( $pdbk );
$id = $lc->getGoodLinkID( $pdbk );
if ( $id !== 0 ) { if ( $id !== 0 ) {
$parser->getOutput()->addLink( $title, $id ); $parser->getOutput()->addLink( $title, $id );
return true; return true;
} elseif ( $lc->isBadLink( $pdbk ) ) { } elseif ( $this->linkCache->isBadLink( $pdbk ) ) {
$parser->getOutput()->addLink( $title, 0 ); $parser->getOutput()->addLink( $title, 0 );
return false; return false;
} }