Skip to content

Commit

Permalink
Merge "Better dependency injection in ListSubscribers"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 7, 2017
2 parents c9b3161 + bd2ac45 commit e541d7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions repo/Wikibase.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@
$wgAPIListModules['wbsubscribers'] = [
'class' => Wikibase\Repo\Api\ListSubscribers::class,
'factory' => function( $mainModule, $moduleName, $modulePrefix = 'wbls' ) {
/** @var ApiQuery $mainModule */
$wikibaseRepo = \Wikibase\Repo\WikibaseRepo::getDefaultInstance();
$mediaWikiServices = \MediaWiki\MediaWikiServices::getInstance();
$apiHelper = $wikibaseRepo->getApiHelperFactory( $mainModule->getContext() );
return new Wikibase\Repo\Api\ListSubscribers(
$mainModule,
$moduleName,
$modulePrefix,
$apiHelper->getErrorReporter( $mainModule ),
$wikibaseRepo->getEntityIdParser(),
$mediaWikiServices->getSiteLookup()
);
Expand Down
7 changes: 3 additions & 4 deletions repo/includes/Api/ListSubscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use stdClass;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\DataModel\Entity\EntityIdParsingException;
use Wikibase\Repo\WikibaseRepo;

/**
* API module for getting wikis subscribed to changes to given entities.
Expand Down Expand Up @@ -42,6 +41,7 @@ class ListSubscribers extends ApiQueryBase {
* @param ApiQuery $mainModule
* @param string $moduleName
* @param string $modulePrefix
* @param ApiErrorReporter $errorReporter
* @param EntityIdParser $idParser
* @param SiteLookup $siteLookup
*
Expand All @@ -51,14 +51,13 @@ public function __construct(
ApiQuery $mainModule,
$moduleName,
$modulePrefix,
ApiErrorReporter $errorReporter,
EntityIdParser $idParser,
SiteLookup $siteLookup
) {
parent::__construct( $mainModule, $moduleName, $modulePrefix );

$wikibaseRepo = WikibaseRepo::getDefaultInstance();
$this->errorReporter = $wikibaseRepo->getApiHelperFactory( $this->getContext() )
->getErrorReporter( $this );
$this->errorReporter = $errorReporter;
$this->idParser = $idParser;
$this->siteLookup = $siteLookup;
}
Expand Down
16 changes: 11 additions & 5 deletions repo/tests/phpunit/includes/Api/ListSubscribersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
use ApiMain;
use ApiQuery;
use FauxRequest;
use MediaWiki\MediaWikiServices;
use HashSiteStore;
use MediaWikiLangTestCase;
use RequestContext;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\Repo\Api\ListSubscribers;
use Wikibase\Repo\WikibaseRepo;

Expand Down Expand Up @@ -86,13 +87,18 @@ private function getQueryModule( array $params ) {
*/
private function callApiModule( array $params ) {
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
$mediaWikiServices = MediaWikiServices::getInstance();
$apiMain = $this->getQueryModule( $params );
$errorReporter = $wikibaseRepo->getApiHelperFactory( $apiMain->getContext() )
->getErrorReporter( $apiMain );
$idParser = new BasicEntityIdParser();
$siteLokup = new HashSiteStore();
$module = new ListSubscribers(
$this->getQueryModule( $params ),
$apiMain,
'subscribers',
'wbls',
$wikibaseRepo->getEntityIdParser(),
$mediaWikiServices->getSiteLookup()
$errorReporter,
$idParser,
$siteLokup
);

$module->execute();
Expand Down

0 comments on commit e541d7c

Please sign in to comment.