Hoo man has uploaded a new change for review. https://gerrit.wikimedia.org/r/133179
Change subject: Avoid SiteSQLStore::newInstance and the deprecated Sites class ...................................................................... Avoid SiteSQLStore::newInstance and the deprecated Sites class Due to the fact that the SiteStore which is used by most of the production code is being cached now, just using TestSites::insertIntoDb wont work anymore as that doesn't affect the cache of the other SiteStore instances. Bug: 64743 Change-Id: Ifed24937ee5af3cc723451621ddfc6a272b737df --- M client/WikibaseClient.hooks.php M client/includes/ChangeHandler.php M client/includes/WikibaseClient.php M client/includes/modules/SiteModule.php M client/includes/parserhooks/NoLangLinkHandler.php M client/includes/store/sql/DirectSqlStore.php M client/tests/phpunit/includes/ChangeHandlerTest.php M lib/includes/Utils.php M lib/includes/modules/SitesModule.php M lib/includes/serializers/ItemSerializer.php M lib/includes/serializers/SerializerFactory.php M lib/tests/phpunit/serializers/ItemSerializerTest.php M repo/includes/EntityContentDiffView.php M repo/includes/ItemView.php M repo/includes/UpdateRepoOnMoveJob.php M repo/includes/WikibaseRepo.php M repo/includes/actions/EditEntityAction.php M repo/includes/api/GetEntities.php M repo/includes/api/LinkTitles.php M repo/includes/api/ModifyEntity.php M repo/includes/specials/SpecialEntityData.php M repo/includes/specials/SpecialNewItem.php M repo/includes/specials/SpecialSetSiteLink.php M repo/includes/specials/SpecialWikibaseRepoPage.php M repo/tests/phpunit/includes/ItemMoveTest.php M repo/tests/phpunit/includes/actions/ActionTestCase.php M repo/tests/phpunit/includes/actions/EditEntityActionTest.php M repo/tests/phpunit/includes/api/IndependentWikibaseApiTestCase.php M repo/tests/phpunit/includes/api/IntegrationApiTest.php M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php M repo/tests/phpunit/includes/content/EntityContentTest.php M repo/tests/phpunit/includes/content/ItemContentTest.php M repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php M repo/tests/phpunit/includes/updates/ItemDeletionUpdateTest.php M repo/tests/phpunit/includes/updates/ItemModificationUpdateTest.php 35 files changed, 125 insertions(+), 125 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/79/133179/1 diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php index e8cdde8..b17de43 100644 --- a/client/WikibaseClient.hooks.php +++ b/client/WikibaseClient.hooks.php @@ -21,8 +21,6 @@ use RuntimeException; use SpecialWatchlist; use SplFileInfo; -use Sites; -use SiteSQLStore; use Skin; use SpecialRecentChanges; use StripState; @@ -368,7 +366,7 @@ $settings->getSetting( 'siteGlobalID' ), $wikibaseClient->getNamespaceChecker(), $wikibaseClient->getStore()->getSiteLinkTable(), - Sites::singleton(), + $wikibaseClient->getSiteStore(), $wikibaseClient->getLangLinkSiteGroup() ); @@ -587,7 +585,7 @@ $generator = new OtherProjectsSidebarGenerator( $settings->getSetting( 'siteGlobalID' ), WikibaseClient::getDefaultInstance()->getStore()->getSiteLinkTable(), - SiteSQLStore::newInstance(), + WikibaseClient::getDefaultInstance()->getSiteStore(), $siteIdsToOutput ); diff --git a/client/includes/ChangeHandler.php b/client/includes/ChangeHandler.php index f12c541..7bb0220 100644 --- a/client/includes/ChangeHandler.php +++ b/client/includes/ChangeHandler.php @@ -5,7 +5,6 @@ use MWException; use Site; use SiteList; -use Sites; use Title; use Wikibase\Client\WikibaseClient; @@ -109,7 +108,7 @@ $settings = $wikibaseClient->getSettings(); if ( $sites === null ) { - $sites = Sites::singleton()->getSites(); + $sites = $wikibaseClient->getSiteStore()->getSites(); } $this->sites = $sites; diff --git a/client/includes/WikibaseClient.php b/client/includes/WikibaseClient.php index db4db48..b293e8a 100644 --- a/client/includes/WikibaseClient.php +++ b/client/includes/WikibaseClient.php @@ -8,7 +8,6 @@ use MediaWikiSite; use MWException; use Site; -use Sites; use SiteSQLStore; use SiteStore; use ValueFormatters\FormatterOptions; @@ -19,7 +18,6 @@ use Wikibase\EntityLookup; use Wikibase\LangLinkHandler; use Wikibase\LanguageFallbackChainFactory; -use Wikibase\Lib\EntityIdFormatter; use Wikibase\Lib\EntityIdLabelFormatter; use Wikibase\Lib\EntityRetrievingDataTypeLookup; use Wikibase\Lib\OutputFormatSnakFormatterFactory; @@ -371,7 +369,7 @@ * This is taken from the siteGlobalID setting, which defaults * to the wiki's database name. * - * If the configured site ID is not found in the Sites list, a + * If the configured site ID is not found in the sites table, a * new Site object is constructed from the configured ID. * * @throws MWException @@ -382,8 +380,7 @@ $globalId = $this->settings->getSetting( 'siteGlobalID' ); $localId = $this->settings->getSetting( 'siteLocalID' ); - $sites = Sites::singleton(); - $this->site = $sites->getSite( $globalId ); + $this->site = $this->getSiteStore()->getSite( $globalId ); if ( !$this->site ) { wfDebugLog( __CLASS__, __FUNCTION__ . ": Unable to resolve site ID '{$globalId}'!" ); @@ -433,10 +430,7 @@ if ( !$siteGroup ) { $siteId = $this->settings->getSetting( 'siteGlobalID' ); - $siteStore = $this->siteStore !== null - ? $this->siteStore : SiteSQLStore::newInstance(); - - $site = $siteStore->getSite( $siteId ); + $site = $this->getSiteStore()->getSite( $siteId ); if ( !$site ) { wfWarn( 'Cannot find site ' . $siteId . ' in sites table' ); @@ -550,7 +544,7 @@ $settings->getSetting( 'siteGlobalID' ), $this->getNamespaceChecker(), $this->getStore()->getSiteLinkTable(), - Sites::singleton(), + $this->getSiteStore(), $this->getLangLinkSiteGroup() ); } @@ -558,4 +552,16 @@ return $this->langLinkHandler; } + /** + * @since 0.5 + * + * @return SiteStore + */ + public function getSiteStore() { + if ( !$this->siteStore ) { + $this->siteStore = SiteSQLStore::newInstance(); + } + + return $this->siteStore; + } } diff --git a/client/includes/modules/SiteModule.php b/client/includes/modules/SiteModule.php index 8fa9b19..6b0b6d7 100644 --- a/client/includes/modules/SiteModule.php +++ b/client/includes/modules/SiteModule.php @@ -5,7 +5,6 @@ use ResourceLoaderModule; use ResourceLoaderContext; use MediaWikiSite; -use SiteSQLStore; use Wikibase\Client\WikibaseClient; /** @@ -31,11 +30,10 @@ public function getScript( ResourceLoaderContext $context ) { $wikibaseClient = WikibaseClient::getDefaultInstance(); - $siteId = $wikibaseClient->getSettings()->getSetting( 'siteGlobalID' ); /** * @var MediaWikiSite $site */ - $site = SiteSQLStore::newInstance()->getSite( $siteId ); + $site = $wikibaseClient->getSite(); $currentSite = array(); if ( $site ) { diff --git a/client/includes/parserhooks/NoLangLinkHandler.php b/client/includes/parserhooks/NoLangLinkHandler.php index 29001d2..277281a 100644 --- a/client/includes/parserhooks/NoLangLinkHandler.php +++ b/client/includes/parserhooks/NoLangLinkHandler.php @@ -44,7 +44,7 @@ $settings->getSetting( 'siteGlobalID' ), $namespaceChecker, $wikibaseClient->getStore()->getSiteLinkTable(), - \Sites::singleton(), + $wikibaseClient->getSiteStore(), $wikibaseClient->getLangLinkSiteGroup() ); diff --git a/client/includes/store/sql/DirectSqlStore.php b/client/includes/store/sql/DirectSqlStore.php index f2daeaa..ab0eb7a 100644 --- a/client/includes/store/sql/DirectSqlStore.php +++ b/client/includes/store/sql/DirectSqlStore.php @@ -137,14 +137,12 @@ /** * Returns the site object representing the local wiki. * - * @return null|\Site + * @return Site */ private function getSite() { // @FIXME: inject the site if ( $this->site === null ) { - $this->site = \Sites::singleton()->getSite( - WikibaseClient::getDefaultInstance()->getSettings()->getSetting( 'siteGlobalID' ) - ); + $this->site = WikibaseClient::getDefaultInstance()->getSite(); } return $this->site; diff --git a/client/tests/phpunit/includes/ChangeHandlerTest.php b/client/tests/phpunit/includes/ChangeHandlerTest.php index bcd9469..249c681 100644 --- a/client/tests/phpunit/includes/ChangeHandlerTest.php +++ b/client/tests/phpunit/includes/ChangeHandlerTest.php @@ -168,16 +168,6 @@ return $change; } - /* - public static function makeSiteLink( $siteId, $page ) { - $site = \Sites::singleton()->getSite( $siteId ); - - $link = new SiteLink( $site, $page ); - - return $link; - } - */ - public static function makeDiff( $type, $before, $after ) { $differ = new \Diff\MapDiffer( true ); diff --git a/lib/includes/Utils.php b/lib/includes/Utils.php index 6bcc9db..666fa63 100644 --- a/lib/includes/Utils.php +++ b/lib/includes/Utils.php @@ -7,7 +7,6 @@ use Language; use MWException; use SiteSQLStore; -use Sites; /** * Utility functions for Wikibase. @@ -79,7 +78,7 @@ * @since 0.1 */ public static function insertDefaultSites( $updater = null ) { - if ( Sites::singleton()->getSites()->count() > 0 ) { + if ( SiteSQLStore::newInstance()->getSites()->count() > 0 ) { return; } diff --git a/lib/includes/modules/SitesModule.php b/lib/includes/modules/SitesModule.php index cfe0485..3810e7f 100644 --- a/lib/includes/modules/SitesModule.php +++ b/lib/includes/modules/SitesModule.php @@ -1,7 +1,11 @@ <?php namespace Wikibase; -use ResourceLoaderModule, ResourceLoaderContext, MediaWikiSite, Site; +use ResourceLoaderModule; +use ResourceLoaderContext; +use MediaWikiSite; +use Site; +use SiteSQLStore; /** * @@ -34,7 +38,7 @@ /** * @var MediaWikiSite $site */ - foreach ( \SiteSQLStore::newInstance()->getSites() as $site ) { + foreach ( SiteSQLStore::newInstance()->getSites() as $site ) { $group = $site->getGroup(); if ( $site->getType() === Site::TYPE_MEDIAWIKI && in_array( $group, $groups ) ) { diff --git a/lib/includes/serializers/ItemSerializer.php b/lib/includes/serializers/ItemSerializer.php index a0847da..f76cd4f 100644 --- a/lib/includes/serializers/ItemSerializer.php +++ b/lib/includes/serializers/ItemSerializer.php @@ -2,7 +2,6 @@ namespace Wikibase\Lib\Serializers; use InvalidArgumentException; -use SiteSQLStore; use SiteStore; use Wikibase\Entity; use Wikibase\EntityFactory; @@ -36,19 +35,21 @@ * @since 0.4 * * @param ClaimSerializer $claimSerializer - * @param SerializationOptions $options - * @param EntityFactory $entityFactory * @param SiteStore $siteStore + * @param SerializationOptions|null $options + * @param EntityFactory|null $entityFactory * * @todo: make $entityFactory required * @todo: make $siteStore required (resp. inject a SiteLinkSerializer instead) */ - public function __construct( ClaimSerializer $claimSerializer, SerializationOptions $options = null, EntityFactory $entityFactory = null, SiteStore $siteStore = null ) { - if ( $siteStore === null ) { - $this->siteStore = SiteSQLStore::newInstance(); - } else { - $this->siteStore = $siteStore; - } + public function __construct( + ClaimSerializer $claimSerializer, + SiteStore $siteStore, + SerializationOptions $options = null, + EntityFactory $entityFactory = null + ) { + $this->siteStore = $siteStore; + parent::__construct( $claimSerializer, $options, $entityFactory ); } diff --git a/lib/includes/serializers/SerializerFactory.php b/lib/includes/serializers/SerializerFactory.php index cc05596..8cf7af9 100644 --- a/lib/includes/serializers/SerializerFactory.php +++ b/lib/includes/serializers/SerializerFactory.php @@ -233,7 +233,7 @@ * @return Serializer */ public function newItemSerializer( SerializationOptions $options ) { - return new ItemSerializer( $this->newClaimSerializer( $options ), $options, $this->entityFactory, $this->siteStore ); + return new ItemSerializer( $this->newClaimSerializer( $options ), $this->siteStore, $options, $this->entityFactory ); } /** diff --git a/lib/tests/phpunit/serializers/ItemSerializerTest.php b/lib/tests/phpunit/serializers/ItemSerializerTest.php index 3330d5a..81ccc3d 100644 --- a/lib/tests/phpunit/serializers/ItemSerializerTest.php +++ b/lib/tests/phpunit/serializers/ItemSerializerTest.php @@ -2,6 +2,7 @@ namespace Wikibase\Test; +use SiteSQLStore; use Wikibase\Item; use Wikibase\Lib\Serializers\ClaimSerializer; use Wikibase\Lib\Serializers\ItemSerializer; @@ -35,7 +36,7 @@ */ protected function getInstance() { $class = $this->getClass(); - return new $class( new ClaimSerializer( new SnakSerializer() ) ); + return new $class( new ClaimSerializer( new SnakSerializer() ), SiteSQLStore::newInstance() ); } /** diff --git a/repo/includes/EntityContentDiffView.php b/repo/includes/EntityContentDiffView.php index 5816ed2..2a95cb5 100644 --- a/repo/includes/EntityContentDiffView.php +++ b/repo/includes/EntityContentDiffView.php @@ -12,7 +12,6 @@ use ParserOptions; use ParserOutput; use Revision; -use SiteSQLStore; use ValueFormatters\FormatterOptions; use ValueFormatters\ValueFormatter; use Wikibase\Lib\EntityIdLabelFormatter; @@ -76,7 +75,8 @@ $labelFormatter = new EntityIdLabelFormatter( $options, WikibaseRepo::getDefaultInstance()->getEntityLookup() ); $this->propertyNameFormatter = new EscapingValueFormatter( $labelFormatter, 'htmlspecialchars' ); - $formatterFactory = WikibaseRepo::getDefaultInstance()->getSnakFormatterFactory(); + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + $formatterFactory = $wikibaseRepo->getSnakFormatterFactory(); $this->detailedSnakFormatter = $formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML_DIFF, $options ); $this->terseSnakFormatter = $formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML, $options ); @@ -85,7 +85,7 @@ $this->getContext(), new ClaimDiffer( new OrderedListDiffer( new ComparableComparer() ) ), new ClaimDifferenceVisualizer( $this->propertyNameFormatter, $this->detailedSnakFormatter, $this->terseSnakFormatter, $langCode ), - SiteSQLStore::newInstance() + $wikibaseRepo->getSiteStore() ); } diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php index 2cb5efd..1c8d59b 100644 --- a/repo/includes/ItemView.php +++ b/repo/includes/ItemView.php @@ -2,7 +2,6 @@ namespace Wikibase; -use SiteSQLStore; use Wikibase\DataModel\SimpleSiteLink; use Wikibase\Repo\WikibaseRepo; @@ -98,9 +97,12 @@ * @return string */ public function getHtmlForSiteLinkGroup( Item $item, $group, $editable = true ) { + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + // @todo inject into constructor - $sites = SiteSQLStore::newInstance()->getSites(); - $specialGroups = WikibaseRepo::getDefaultInstance()->getSettings()->getSetting( "specialSiteLinkGroups" ); + $sites = $wikibaseRepo->getSiteStore()->getSites(); + + $specialGroups = $wikibaseRepo->getSettings()->getSetting( "specialSiteLinkGroups" ); $allSiteLinks = $item->getSiteLinks(); $siteLinks = array(); // site links of the currently handled site group diff --git a/repo/includes/UpdateRepoOnMoveJob.php b/repo/includes/UpdateRepoOnMoveJob.php index b57b837..eb86423 100644 --- a/repo/includes/UpdateRepoOnMoveJob.php +++ b/repo/includes/UpdateRepoOnMoveJob.php @@ -2,6 +2,7 @@ namespace Wikibase; +use Site; use User; use Wikibase\DataModel\SimpleSiteLink; use Wikibase\Repo\WikibaseRepo; @@ -88,11 +89,11 @@ * * @param string $globalId * - * @return \Site + * @return Site */ protected function getSite( $globalId ) { - $sitesTable = \SiteSQLStore::newInstance(); - return $sitesTable->getSite( $globalId ); + $sitesStore = WikibaseRepo::getDefaultInstance()->getSiteStore(); + return $sitesStore->getSite( $globalId ); } /** diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 099acc3..c968e7a 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -121,6 +121,11 @@ private $exceptionLocalizer; /** + * @var SiteStore + */ + private $siteStore; + + /** * Returns the default instance constructed using newInstance(). * IMPORTANT: Use only when it is not feasible to inject an instance properly. * @@ -615,7 +620,11 @@ * @return SiteStore */ public function getSiteStore() { - return SiteSQLStore::newInstance(); + if ( !$this->siteStore ) { + $this->siteStore = SiteSQLStore::newInstance(); + } + + return $this->siteStore; } /** diff --git a/repo/includes/actions/EditEntityAction.php b/repo/includes/actions/EditEntityAction.php index 4700f96..74c29bc 100644 --- a/repo/includes/actions/EditEntityAction.php +++ b/repo/includes/actions/EditEntityAction.php @@ -9,7 +9,6 @@ use Linker; use MWException; use Page; -use SiteSQLStore; use Status; use Revision; use ValueFormatters\FormatterOptions; @@ -67,7 +66,8 @@ $labelFormatter = new EntityIdLabelFormatter( $options, WikibaseRepo::getDefaultInstance()->getEntityLookup() ); $this->propertyNameFormatter = new EscapingValueFormatter( $labelFormatter, 'htmlspecialchars' ); - $formatterFactory = WikibaseRepo::getDefaultInstance()->getSnakFormatterFactory(); + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + $formatterFactory = $wikibaseRepo->getSnakFormatterFactory(); $this->detailedSnakFormatter = $formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML_DIFF, $options ); $this->terseSnakFormatter = $formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML, $options ); @@ -75,7 +75,7 @@ $this->getContext(), new ClaimDiffer( new OrderedListDiffer( new ComparableComparer() ) ), new ClaimDifferenceVisualizer( $this->propertyNameFormatter, $this->detailedSnakFormatter, $this->terseSnakFormatter, $langCode ), - SiteSQLStore::newInstance() + $wikibaseRepo->getSiteStore() ); } diff --git a/repo/includes/api/GetEntities.php b/repo/includes/api/GetEntities.php index 9c433d4..fe6f9e7 100644 --- a/repo/includes/api/GetEntities.php +++ b/repo/includes/api/GetEntities.php @@ -64,7 +64,7 @@ $this->stringNormalizer = $wikibaseRepo->getStringNormalizer(); $this->languageFallbackChainFactory = $wikibaseRepo->getLanguageFallbackChainFactory(); - $this->siteLinkTargetProvider = new SiteLinkTargetProvider( SiteSQLStore::newInstance() ); + $this->siteLinkTargetProvider = new SiteLinkTargetProvider( $wikibaseRepo->getSiteStore() ); $this->siteLinkGroups = $wikibaseRepo->getSettings()->getSetting( 'siteLinkGroups' ); } @@ -151,7 +151,7 @@ */ private function getItemByTitleHelper() { $siteLinkCache = StoreFactory::getStore()->newSiteLinkCache(); - $siteStore = SiteSQLStore::newInstance(); + $siteStore = WikibaseRepo::getDefaultInstance()->getSiteStore(); return new ItemByTitleHelper( $this->getResultBuilder(), $siteLinkCache, diff --git a/repo/includes/api/LinkTitles.php b/repo/includes/api/LinkTitles.php index 1085ce7..77014e9 100644 --- a/repo/includes/api/LinkTitles.php +++ b/repo/includes/api/LinkTitles.php @@ -4,11 +4,8 @@ use ApiBase; use ApiMain; -use SiteSQLStore; use Status; -use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\Item; -use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\SiteLink; use Wikibase\Repo\WikibaseRepo; use Wikibase\StoreFactory; @@ -46,9 +43,10 @@ */ public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) { parent::__construct( $mainModule, $moduleName, $modulePrefix ); - $this->siteLinkTargetProvider = new SiteLinkTargetProvider( SiteSQLStore::newInstance() ); - $this->siteLinkGroups = WikibaseRepo::getDefaultInstance()-> - getSettings()->getSetting( 'siteLinkGroups' ); + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + + $this->siteLinkTargetProvider = new SiteLinkTargetProvider( $wikibaseRepo->getSiteStore() ); + $this->siteLinkGroups = $wikibaseRepo->getSettings()->getSetting( 'siteLinkGroups' ); } /** diff --git a/repo/includes/api/ModifyEntity.php b/repo/includes/api/ModifyEntity.php index ddc8608..efea2c5 100644 --- a/repo/includes/api/ModifyEntity.php +++ b/repo/includes/api/ModifyEntity.php @@ -5,7 +5,6 @@ use ApiBase; use ApiMain; use LogicException; -use SiteSQLStore; use Status; use UsageException; use Wikibase\ChangeOp\ChangeOp; @@ -73,7 +72,7 @@ //TODO: provide a mechanism to override the services $this->stringNormalizer = $repo->getStringNormalizer(); - $this->siteLinkTargetProvider = new SiteLinkTargetProvider( SiteSQLStore::newInstance() ); + $this->siteLinkTargetProvider = new SiteLinkTargetProvider( $repo->getSiteStore() ); $this->siteLinkGroups = $repo->getSettings()->getSetting( 'siteLinkGroups' ); $this->siteLinkLookup = $repo->getStore()->newSiteLinkCache(); diff --git a/repo/includes/specials/SpecialEntityData.php b/repo/includes/specials/SpecialEntityData.php index 109c3cd..486999e 100644 --- a/repo/includes/specials/SpecialEntityData.php +++ b/repo/includes/specials/SpecialEntityData.php @@ -96,7 +96,7 @@ $repo->getStore()->getEntityLookup(), $titleLookup, $serializerFactory, - SiteSQLStore::newInstance()->getSites() + $repo->getSiteStore()->getSites() ); $maxAge = $repo->getSettings()->getSetting( 'dataSquidMaxage' ); diff --git a/repo/includes/specials/SpecialNewItem.php b/repo/includes/specials/SpecialNewItem.php index fad52fc..6abb68d 100644 --- a/repo/includes/specials/SpecialNewItem.php +++ b/repo/includes/specials/SpecialNewItem.php @@ -70,7 +70,7 @@ $status = parent::modifyEntity( $item ); if ( $this->site !== null && $this->page !== null ) { - $site = \SiteSQLStore::newInstance()->getSite( $this->site ); + $site = $this->siteStore->getSite( $this->site ); if ( $site === null ) { $status->error( 'wikibase-newitem-not-recognized-siteid' ); diff --git a/repo/includes/specials/SpecialSetSiteLink.php b/repo/includes/specials/SpecialSetSiteLink.php index ba41fa4..1df7c0d 100644 --- a/repo/includes/specials/SpecialSetSiteLink.php +++ b/repo/includes/specials/SpecialSetSiteLink.php @@ -4,7 +4,6 @@ use Html; use OutOfBoundsException; -use SiteSQLStore; use Status; use ValueParsers\ParseException; use Wikibase\ChangeOp\ChangeOpException; @@ -203,7 +202,7 @@ * @return bool */ private function isValidSiteId( $siteId ) { - return $siteId !== null && SiteSQLStore::newInstance()->getSite( $siteId ) !== null; + return $siteId !== null && $this->siteStore->getSite( $siteId ) !== null; } /** @@ -256,7 +255,7 @@ ); } - $site = SiteSQLStore::newInstance()->getSite( $this->site ); + $site = $this->siteStore->getSite( $this->site ); if ( $entity !== null && $this->site !== null && $site !== null ) { return Html::rawElement( @@ -430,7 +429,7 @@ */ protected function setSiteLink( Item $item, $siteId, $pageName, $badges, &$summary ) { $status = Status::newGood(); - $site = SiteSQLStore::newInstance()->getSite( $siteId ); + $site = $this->siteStore->getSite( $siteId ); if ( $site === null ) { $status->fatal( 'wikibase-setsitelink-invalid-site', $siteId ); diff --git a/repo/includes/specials/SpecialWikibaseRepoPage.php b/repo/includes/specials/SpecialWikibaseRepoPage.php index 9347737..1c25f4d 100644 --- a/repo/includes/specials/SpecialWikibaseRepoPage.php +++ b/repo/includes/specials/SpecialWikibaseRepoPage.php @@ -4,6 +4,7 @@ use MWException; use RuntimeException; +use SiteStore; use Status; use Title; use UserInputException; @@ -56,6 +57,11 @@ private $permissionChecker; /** + * @var SiteStore + */ + protected $siteStore; + + /** * @since 0.5 * * @param string $title The title of the special page @@ -63,13 +69,15 @@ */ public function __construct( $title, $restriction ) { parent::__construct( $title, $restriction ); + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); //TODO: allow overriding services for testing - $this->summaryFormatter = WikibaseRepo::getDefaultInstance()->getSummaryFormatter(); - $this->entityLookup = WikibaseRepo::getDefaultInstance()->getEntityRevisionLookup( 'uncached' ); - $this->titleLookup = WikibaseRepo::getDefaultInstance()->getEntityTitleLookup(); - $this->entityStore = WikibaseRepo::getDefaultInstance()->getEntityStore(); - $this->permissionChecker = WikibaseRepo::getDefaultInstance()->getEntityPermissionChecker(); + $this->summaryFormatter = $wikibaseRepo->getSummaryFormatter(); + $this->entityLookup = $wikibaseRepo->getEntityRevisionLookup( 'uncached' ); + $this->titleLookup = $wikibaseRepo->getEntityTitleLookup(); + $this->entityStore = $wikibaseRepo->getEntityStore(); + $this->permissionChecker = $wikibaseRepo->getEntityPermissionChecker(); + $this->siteStore = $wikibaseRepo->getSiteStore(); } /** diff --git a/repo/tests/phpunit/includes/ItemMoveTest.php b/repo/tests/phpunit/includes/ItemMoveTest.php index 01ceeba..e769dba 100644 --- a/repo/tests/phpunit/includes/ItemMoveTest.php +++ b/repo/tests/phpunit/includes/ItemMoveTest.php @@ -56,7 +56,9 @@ static $hasSites = false; if ( !$hasSites ) { - \TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); $hasSites = true; } diff --git a/repo/tests/phpunit/includes/actions/ActionTestCase.php b/repo/tests/phpunit/includes/actions/ActionTestCase.php index 70c98b1..d8e3ca9 100644 --- a/repo/tests/phpunit/includes/actions/ActionTestCase.php +++ b/repo/tests/phpunit/includes/actions/ActionTestCase.php @@ -14,10 +14,7 @@ use RequestContext; use Title; use User; -use Wikibase\Entity; -use Wikibase\EntityRevision; use Wikibase\Item; -use Wikibase\ItemContent; use Wikibase\Repo\WikibaseRepo; use WikiPage; use TestSites; @@ -45,7 +42,9 @@ static $setUp = false; if ( !$setUp ) { - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); $setUp = true; } diff --git a/repo/tests/phpunit/includes/actions/EditEntityActionTest.php b/repo/tests/phpunit/includes/actions/EditEntityActionTest.php index f6c0119..7a25776 100644 --- a/repo/tests/phpunit/includes/actions/EditEntityActionTest.php +++ b/repo/tests/phpunit/includes/actions/EditEntityActionTest.php @@ -8,6 +8,7 @@ use WikiPage; use Title; use TestSites; +use Wikibase\Repo\WikibaseRepo; /** * @covers Wikibase\EditEntityAction @@ -37,7 +38,9 @@ static $hasTitles = false; if ( !$hasTitles ) { - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); $hasTitles = true; } diff --git a/repo/tests/phpunit/includes/api/IndependentWikibaseApiTestCase.php b/repo/tests/phpunit/includes/api/IndependentWikibaseApiTestCase.php index b26977c..1223110 100644 --- a/repo/tests/phpunit/includes/api/IndependentWikibaseApiTestCase.php +++ b/repo/tests/phpunit/includes/api/IndependentWikibaseApiTestCase.php @@ -11,6 +11,7 @@ use TestSites; use TestUser; use UsageException; +use Wikibase\Repo\WikibaseRepo; /** * This class can be used instead of the Mediawiki Api TestCase. @@ -39,7 +40,9 @@ if ( !$isSetup ) { //TODO remove me once everything that needs this is overridden - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); $isSetup = true; } } diff --git a/repo/tests/phpunit/includes/api/IntegrationApiTest.php b/repo/tests/phpunit/includes/api/IntegrationApiTest.php index d4d6529..c36efcf 100644 --- a/repo/tests/phpunit/includes/api/IntegrationApiTest.php +++ b/repo/tests/phpunit/includes/api/IntegrationApiTest.php @@ -4,6 +4,7 @@ use ApiTestCase; use TestSites; +use Wikibase\Repo\WikibaseRepo; /** * This class holds simple integration tests for Wikibase API modules @@ -22,7 +23,9 @@ public function setUp() { parent::setUp(); - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); } public function apiRequestProvider() { diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php index 056be2a..7dfe8d4 100644 --- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php +++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php @@ -9,6 +9,7 @@ use UsageException; use User; use Wikibase\EntityFactory; +use Wikibase\Repo\WikibaseRepo; /** * Base class for test classes that test the API modules that derive from ApiWikibaseModifyItem. @@ -38,7 +39,9 @@ $this->setMwGlobals( 'wgUser', self::$users['wbeditor']->user ); if ( !$isSetup ) { - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); $this->login(); diff --git a/repo/tests/phpunit/includes/content/EntityContentTest.php b/repo/tests/phpunit/includes/content/EntityContentTest.php index 90dbfce..01d3814 100644 --- a/repo/tests/phpunit/includes/content/EntityContentTest.php +++ b/repo/tests/phpunit/includes/content/EntityContentTest.php @@ -6,16 +6,11 @@ use MediaWikiTestCase; use ParserOptions; use RequestContext; -use Revision; -use Status; use Title; -use User; use Wikibase\EntityContent; -use Wikibase\EntityRevision; use Wikibase\LanguageFallbackChain; use Wikibase\LanguageWithConversion; use Wikibase\Repo\WikibaseRepo; -use Wikibase\StorageException; use Wikibase\store\EntityStore; /** @@ -46,8 +41,6 @@ $this->permissions = $wgGroupPermissions; $this->old_user = $wgUser; - - \TestSites::insertIntoDb(); $this->entityStore = WikibaseRepo::getDefaultInstance()->getEntityStore(); } diff --git a/repo/tests/phpunit/includes/content/ItemContentTest.php b/repo/tests/phpunit/includes/content/ItemContentTest.php index 6795b3d..4ab6fbd 100644 --- a/repo/tests/phpunit/includes/content/ItemContentTest.php +++ b/repo/tests/phpunit/includes/content/ItemContentTest.php @@ -2,8 +2,6 @@ namespace Wikibase\Test; -use MediaWikiSite; -use SiteSQLStore; use Wikibase\DataModel\SimpleSiteLink; use Wikibase\EntityContent; use Wikibase\ItemContent; @@ -27,14 +25,6 @@ public function setUp() { parent::setUp(); - - $site = new MediaWikiSite(); - $site->setGlobalId( 'nlwiki' ); - $site->setPath( MediaWikiSite::PATH_PAGE, "https://nl.wikipedia.org/wiki/$1" ); - - $sitesTable = SiteSQLStore::newInstance(); - $sitesTable->clear(); - $sitesTable->saveSites( array( $site ) ); } /** @@ -42,19 +32,6 @@ */ protected function getContentClass() { return '\Wikibase\ItemContent'; - } - - public function siteLinkConflictProvider() { - $prefix = get_class( $this ) . '/'; - - $siteLink = new SimpleSiteLink( 'nlwiki', $prefix . 'Pelecanus' ); - - return array( - array( - $siteLink, - 'Site link [https://nl.wikipedia.org/wiki/Pelecanus Pelecanus] already used by item [[$1]].' - ) - ); } public function provideEquals() { diff --git a/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php b/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php index c56bb3a..8ff66a2 100644 --- a/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php +++ b/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php @@ -84,7 +84,9 @@ parent::setUp(); if ( !self::$badgeId ) { - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); $this->createItems(); diff --git a/repo/tests/phpunit/includes/updates/ItemDeletionUpdateTest.php b/repo/tests/phpunit/includes/updates/ItemDeletionUpdateTest.php index 903a903..30701fe 100644 --- a/repo/tests/phpunit/includes/updates/ItemDeletionUpdateTest.php +++ b/repo/tests/phpunit/includes/updates/ItemDeletionUpdateTest.php @@ -27,7 +27,9 @@ public function setUp() { parent::setUp(); - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); } public function testConstruct() { diff --git a/repo/tests/phpunit/includes/updates/ItemModificationUpdateTest.php b/repo/tests/phpunit/includes/updates/ItemModificationUpdateTest.php index f524d2a..8f19a64 100644 --- a/repo/tests/phpunit/includes/updates/ItemModificationUpdateTest.php +++ b/repo/tests/phpunit/includes/updates/ItemModificationUpdateTest.php @@ -47,7 +47,10 @@ * @param ItemContent $itemContent */ public function testDoUpdate( ItemContent $itemContent ) { - TestSites::insertIntoDb(); + $sitesTable = WikibaseRepo::getDefaultInstance()->getSiteStore(); + $sitesTable->clear(); + $sitesTable->saveSites( TestSites::getSites() ); + $linkLookup = StoreFactory::getStore()->newSiteLinkCache(); $store = WikibaseRepo::getDefaultInstance()->getEntityStore(); -- To view, visit https://gerrit.wikimedia.org/r/133179 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifed24937ee5af3cc723451621ddfc6a272b737df Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits