Merge "api: Inject services into ApiOpenSearch"

This commit is contained in:
jenkins-bot 2021-06-30 01:11:28 +00:00 committed by Gerrit Code Review
commit c4eaeb329b
3 changed files with 26 additions and 4 deletions

View file

@ -129,7 +129,12 @@ class ApiMain extends ApiBase {
'WikiPageFactory',
]
],
'opensearch' => ApiOpenSearch::class,
'opensearch' => [
'class' => ApiOpenSearch::class,
'services' => [
'LinkBatchFactory',
]
],
'feedcontributions' => [
'class' => ApiFeedContributions::class,
'services' => [

View file

@ -22,6 +22,7 @@
* @file
*/
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\MediaWikiServices;
/**
@ -36,6 +37,23 @@ class ApiOpenSearch extends ApiBase {
/** @var array list of api allowed params */
private $allowedParams = null;
/** @var LinkBatchFactory */
private $linkBatchFactory;
/**
* @param ApiMain $mainModule
* @param string $moduleName
* @param LinkBatchFactory $linkBatchFactory
*/
public function __construct(
ApiMain $mainModule,
$moduleName,
LinkBatchFactory $linkBatchFactory
) {
parent::__construct( $mainModule, $moduleName );
$this->linkBatchFactory = $linkBatchFactory;
}
/**
* Get the output format
*
@ -137,8 +155,7 @@ class ApiOpenSearch extends ApiBase {
if ( $resolveRedir ) {
// Query for redirects
$redirects = [];
$linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
$lb = $linkBatchFactory->newLinkBatch( $titles );
$lb = $this->linkBatchFactory->newLinkBatch( $titles );
if ( !$lb->isEmpty() ) {
$db = $this->getDB();
$res = $db->select(

View file

@ -59,6 +59,6 @@ class ApiOpenSearchTest extends MediaWikiIntegrationTestCase {
private function createApi() {
$ctx = new RequestContext();
$apiMain = new ApiMain( $ctx );
return new ApiOpenSearch( $apiMain, 'opensearch', '' );
return new ApiOpenSearch( $apiMain, 'opensearch', $this->getServiceContainer()->getLinkBatchFactory() );
}
}