Merge "Inject service RepoGroup in APIPropModules"

This commit is contained in:
jenkins-bot 2023-10-16 03:18:32 +00:00 committed by Gerrit Code Review
commit 421e55b852
3 changed files with 20 additions and 5 deletions

View file

@ -9,7 +9,12 @@
"MediaWiki": ">= 1.41"
},
"APIPropModules": {
"pageimages": "PageImages\\ApiQueryPageImages"
"pageimages": {
"class": "PageImages\\ApiQueryPageImages",
"services": [
"RepoGroup"
]
}
},
"MessagesDirs": {
"PageImages": [

View file

@ -5,8 +5,8 @@ namespace PageImages;
use ApiBase;
use ApiQuery;
use ApiQueryBase;
use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title;
use RepoGroup;
use Wikimedia\ParamValidator\ParamValidator;
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
@ -22,12 +22,21 @@ use Wikimedia\ParamValidator\TypeDef\IntegerDef;
* @author Sam Smith
*/
class ApiQueryPageImages extends ApiQueryBase {
/** @var RepoGroup */
private $repoGroup;
/**
* @param ApiQuery $query API query module
* @param string $moduleName Name of this query module
* @param RepoGroup $repoGroup
*/
public function __construct( ApiQuery $query, $moduleName ) {
public function __construct(
ApiQuery $query,
$moduleName,
RepoGroup $repoGroup
) {
parent::__construct( $query, $moduleName, 'pi' );
$this->repoGroup = $repoGroup;
}
/**
@ -168,7 +177,7 @@ class ApiQueryPageImages extends ApiQueryBase {
protected function setResultValues( array $prop, $pageId, $fileName, $size, $lang ) {
$vals = [];
if ( isset( $prop['thumbnail'] ) || isset( $prop['original'] ) ) {
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $fileName );
$file = $this->repoGroup->findFile( $fileName );
if ( $file ) {
if ( isset( $prop['thumbnail'] ) ) {
$thumb = $file->transform( [

View file

@ -2,6 +2,7 @@
namespace PageImages\Tests;
use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title;
use PageImages\ApiQueryPageImages;
use PageImages\PageImages;
@ -46,7 +47,7 @@ class ApiQueryPageImagesTest extends TestCase {
->method( 'getMain' )
->willReturn( $main );
return new ApiQueryPageImages( $query, '' );
return new ApiQueryPageImages( $query, '', MediaWikiServices::getInstance()->getRepoGroup() );
}
public function testConstructor() {