Inject services into SpecialMathWikibase

Change-Id: I1a887a522be3227600f8261dc59cd67ac9b3ea7d
This commit is contained in:
Fomafix 2024-07-24 16:39:21 +00:00
parent 3f905c2747
commit 5f0100872d
2 changed files with 14 additions and 9 deletions

View file

@ -372,7 +372,12 @@
"Math.RendererFactory"
]
},
"MathWikibase": "MediaWiki\\Extension\\Math\\SpecialMathWikibase"
"MathWikibase": {
"class": "MediaWiki\\Extension\\Math\\SpecialMathWikibase",
"services": [
"Math.WikibaseConnector"
]
}
},
"TrackingCategories": [
"math-tracking-category-error",

View file

@ -7,7 +7,7 @@ use InvalidArgumentException;
use MediaWiki\Extension\Math\Widget\WikibaseEntitySelector;
use MediaWiki\Html\Html;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\MainConfigNames;
use MediaWiki\Message\Message;
use MediaWiki\Output\OutputPage;
use MediaWiki\SpecialPage\SpecialPage;
@ -23,16 +23,19 @@ class SpecialMathWikibase extends SpecialPage {
/**
* @var MathWikibaseConnector Wikibase connection
*/
private $wikibase;
private MathWikibaseConnector $wikibase;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
public function __construct() {
public function __construct(
MathWikibaseConnector $wikibase
) {
parent::__construct( 'MathWikibase' );
$this->wikibase = $wikibase;
$this->logger = LoggerFactory::getInstance( 'Math' );
}
@ -40,10 +43,6 @@ class SpecialMathWikibase extends SpecialPage {
* @inheritDoc
*/
public function execute( $par ) {
global $wgLanguageCode;
$this->wikibase = MediaWikiServices::getInstance()->get( 'Math.WikibaseConnector' );
$request = $this->getRequest();
$output = $this->getOutput();
$output->enableOOUI();
@ -63,8 +62,9 @@ class SpecialMathWikibase extends SpecialPage {
$this->showForm();
} else {
$this->logger->debug( "Request qID: " . $requestId );
$languageCode = $this->getConfig()->get( MainConfigNames::LanguageCode );
try {
$info = $this->wikibase->fetchWikibaseFromId( $requestId, $wgLanguageCode );
$info = $this->wikibase->fetchWikibaseFromId( $requestId, $languageCode );
$this->logger->debug( "Successfully fetched information for qID: " . $requestId );
$this->buildPageRepresentation( $info, $requestId, $output );
} catch ( Exception $e ) {