diff --git a/extension.json b/extension.json index 1cf2cf2..ea803b0 100644 --- a/extension.json +++ b/extension.json @@ -37,6 +37,7 @@ "main": { "class": "PageImages\\PageImages", "services": [ + "RepoGroup", "UserOptionsLookup" ] }, diff --git a/includes/PageImages.php b/includes/PageImages.php index 2d0d998..2eff956 100644 --- a/includes/PageImages.php +++ b/includes/PageImages.php @@ -16,6 +16,7 @@ use MediaWiki\Request\FauxRequest; use MediaWiki\Title\Title; use MediaWiki\User\UserOptionsLookup; use OutputPage; +use RepoGroup; use Skin; /** @@ -58,6 +59,9 @@ class PageImages implements */ public const PROP_NAME_FREE = 'page_image_free'; + /** @var RepoGroup */ + private $repoGroup; + /** @var UserOptionsLookup */ private $userOptionsLookup; @@ -68,15 +72,22 @@ class PageImages implements * @return PageImages */ private static function factory() { + $services = MediaWikiServices::getInstance(); return new self( - MediaWikiServices::getInstance()->getUserOptionsLookup() + $services->getRepoGroup(), + $services->getUserOptionsLookup() ); } /** + * @param RepoGroup $repoGroup * @param UserOptionsLookup $userOptionsLookup */ - public function __construct( UserOptionsLookup $userOptionsLookup ) { + public function __construct( + RepoGroup $repoGroup, + UserOptionsLookup $userOptionsLookup + ) { + $this->repoGroup = $repoGroup; $this->userOptionsLookup = $userOptionsLookup; } @@ -149,7 +160,7 @@ class PageImages implements } if ( $title->inNamespace( NS_FILE ) ) { - return MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ); + return $this->repoGroup->findFile( $title ); } $pageId = $title->getArticleID(); @@ -174,7 +185,7 @@ class PageImages implements return false; } - return MediaWikiServices::getInstance()->getRepoGroup()->findFile( $fileName ); + return $this->repoGroup->findFile( $fileName ); } /** diff --git a/tests/phpunit/PageImagesTest.php b/tests/phpunit/PageImagesTest.php index 6e8f938..b54e376 100644 --- a/tests/phpunit/PageImagesTest.php +++ b/tests/phpunit/PageImagesTest.php @@ -22,8 +22,10 @@ use SkinTemplate; class PageImagesTest extends MediaWikiIntegrationTestCase { private function newPageImages() { + $services = $this->getServiceContainer(); return new PageImages( - $this->getServiceContainer()->getUserOptionsLookup() + $services->getRepoGroup(), + $services->getUserOptionsLookup() ); }