api: Inject services into ApiQueryFileRepoInfo

Removed self::getInitialisedRepoGroup
RepoGroup class itself should be aware of initalise and
does it in RepoGroup::forEachForeignRepo

Bug: T259960
Change-Id: I5163d02bf345b7922ac4ec8b755c7cf8425a9c37
This commit is contained in:
Umherirrender 2021-07-02 21:55:55 +02:00
parent 15e80ed8b8
commit db3b233e8d
2 changed files with 24 additions and 18 deletions

View file

@ -218,7 +218,12 @@ class ApiQuery extends ApiBase {
'UserGroupManager', 'UserGroupManager',
] ]
], ],
'filerepoinfo' => ApiQueryFileRepoInfo::class, 'filerepoinfo' => [
'class' => ApiQueryFileRepoInfo::class,
'services' => [
'RepoGroup',
]
],
'tokens' => ApiQueryTokens::class, 'tokens' => ApiQueryTokens::class,
'languageinfo' => [ 'languageinfo' => [
'class' => ApiQueryLanguageinfo::class, 'class' => ApiQueryLanguageinfo::class,

View file

@ -21,8 +21,6 @@
* @since 1.22 * @since 1.22
*/ */
use MediaWiki\MediaWikiServices;
/** /**
* A query action to return meta information about the foreign file repos * A query action to return meta information about the foreign file repos
* configured on the wiki. * configured on the wiki.
@ -31,15 +29,21 @@ use MediaWiki\MediaWikiServices;
*/ */
class ApiQueryFileRepoInfo extends ApiQueryBase { class ApiQueryFileRepoInfo extends ApiQueryBase {
public function __construct( ApiQuery $query, $moduleName ) { /** @var RepoGroup */
private $repoGroup;
/**
* @param ApiQuery $query
* @param string $moduleName
* @param RepoGroup $repoGroup
*/
public function __construct(
ApiQuery $query,
$moduleName,
RepoGroup $repoGroup
) {
parent::__construct( $query, $moduleName, 'fri' ); parent::__construct( $query, $moduleName, 'fri' );
} $this->repoGroup = $repoGroup;
protected function getInitialisedRepoGroup() {
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
$repoGroup->initialiseRepos();
return $repoGroup;
} }
public function execute() { public function execute() {
@ -50,10 +54,9 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
$repos = []; $repos = [];
$repoGroup = $this->getInitialisedRepoGroup();
$foreignTargets = $conf->get( 'ForeignUploadTargets' ); $foreignTargets = $conf->get( 'ForeignUploadTargets' );
$repoGroup->forEachForeignRepo( $this->repoGroup->forEachForeignRepo(
static function ( FileRepo $repo ) use ( &$repos, $props, $foreignTargets ) { static function ( FileRepo $repo ) use ( &$repos, $props, $foreignTargets ) {
$repoProps = $repo->getInfo(); $repoProps = $repo->getInfo();
$repoProps['canUpload'] = in_array( $repoProps['name'], $foreignTargets ); $repoProps['canUpload'] = in_array( $repoProps['name'], $foreignTargets );
@ -62,7 +65,7 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
} }
); );
$localInfo = $repoGroup->getLocalRepo()->getInfo(); $localInfo = $this->repoGroup->getLocalRepo()->getInfo();
$localInfo['canUpload'] = $conf->get( 'EnableUploads' ); $localInfo['canUpload'] = $conf->get( 'EnableUploads' );
$repos[] = array_intersect_key( $localInfo, $props ); $repos[] = array_intersect_key( $localInfo, $props );
@ -92,15 +95,13 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
public function getProps() { public function getProps() {
$props = []; $props = [];
$repoGroup = $this->getInitialisedRepoGroup(); $this->repoGroup->forEachForeignRepo( static function ( FileRepo $repo ) use ( &$props ) {
$repoGroup->forEachForeignRepo( static function ( FileRepo $repo ) use ( &$props ) {
$props = array_merge( $props, array_keys( $repo->getInfo() ) ); $props = array_merge( $props, array_keys( $repo->getInfo() ) );
} ); } );
$propValues = array_values( array_unique( array_merge( $propValues = array_values( array_unique( array_merge(
$props, $props,
array_keys( $repoGroup->getLocalRepo()->getInfo() ) array_keys( $this->repoGroup->getLocalRepo()->getInfo() )
) ) ); ) ) );
$propValues[] = 'canUpload'; $propValues[] = 'canUpload';