mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-24 00:13:27 +00:00
Merge "Inject service RepoGroup in APIPropModules"
This commit is contained in:
commit
421e55b852
|
@ -9,7 +9,12 @@
|
|||
"MediaWiki": ">= 1.41"
|
||||
},
|
||||
"APIPropModules": {
|
||||
"pageimages": "PageImages\\ApiQueryPageImages"
|
||||
"pageimages": {
|
||||
"class": "PageImages\\ApiQueryPageImages",
|
||||
"services": [
|
||||
"RepoGroup"
|
||||
]
|
||||
}
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"PageImages": [
|
||||
|
|
|
@ -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( [
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue