jenkins-bot has submitted this change and it was merged. Change subject: Check the content model of pages in EntityPerPageBuilder ......................................................................
Check the content model of pages in EntityPerPageBuilder Just to make sure the script isn't going to choke on wikitext pages in the item NS. This commit introduces WikibaseRepo::getContentMappings() which should be made us of. Change-Id: I9e0a5ca212d3ce210d1ca42a4829abf86ae18cde --- M lib/includes/EntityFactory.php M repo/includes/WikibaseRepo.php M repo/includes/content/EntityContentFactory.php M repo/includes/store/sql/EntityPerPageBuilder.php M repo/maintenance/rebuildEntityPerPage.php M repo/tests/phpunit/includes/WikibaseRepoTest.php M repo/tests/phpunit/includes/content/EntityContentFactoryTest.php M repo/tests/phpunit/includes/store/sql/EntityPerPageBuilderTest.php M repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php 9 files changed, 84 insertions(+), 37 deletions(-) Approvals: Aude: Looks good to me, approved WikidataJenkins: Verified jenkins-bot: Verified diff --git a/lib/includes/EntityFactory.php b/lib/includes/EntityFactory.php index f88c6f4..35e1b88 100644 --- a/lib/includes/EntityFactory.php +++ b/lib/includes/EntityFactory.php @@ -24,6 +24,7 @@ * @var array */ protected static $typeMap = array( + // @FIXME: Make use of Wikibase.Repo::getContentModelMappings and don't hard code query Item::ENTITY_TYPE => '\Wikibase\Item', Property::ENTITY_TYPE => '\Wikibase\Property', diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php index 927121a..cc3a04e 100644 --- a/repo/includes/WikibaseRepo.php +++ b/repo/includes/WikibaseRepo.php @@ -12,6 +12,8 @@ use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\DataModel\Entity\DispatchingEntityIdParser; use Wikibase\DataModel\Entity\EntityIdParser; +use Wikibase\DataModel\Entity\Item; +use Wikibase\DataModel\Entity\Property; use Wikibase\EntityContentFactory; use Wikibase\EntityLookup; use Wikibase\i18n\ExceptionLocalizer; @@ -185,11 +187,7 @@ * @return EntityContentFactory */ public function getEntityContentFactory() { - $entityNamespaces = $this->settings->getSetting( 'entityNamespaces' ); - - return new EntityContentFactory( - is_array( $entityNamespaces ) ? array_keys( $entityNamespaces ) : array() - ); + return new EntityContentFactory( $this->getContentModelMappings() ); } /** @@ -640,4 +638,23 @@ $wgLang ); } + + /** + * Get the mapping of entity types => content models + * + * @since 0.5 + * + * @return array + */ + public function getContentModelMappings() { + // @TODO: We should have smth. like this for namespaces too + $map = array( + Item::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_ITEM, + Property::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_PROPERTY + ); + + wfRunHooks( 'WikibaseContentModelMapping', array( &$map ) ); + + return $map; + } } diff --git a/repo/includes/content/EntityContentFactory.php b/repo/includes/content/EntityContentFactory.php index d36325a..107aac7 100644 --- a/repo/includes/content/EntityContentFactory.php +++ b/repo/includes/content/EntityContentFactory.php @@ -20,16 +20,18 @@ */ class EntityContentFactory implements EntityTitleLookup, EntityPermissionChecker { - // TODO: inject this map and allow extensions to somehow extend it - protected static $typeMap = array( - Item::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_ITEM, - Property::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_PROPERTY, - ); + /** + * @since 0.5 + * + * @var array + */ + protected $typeMap; - protected $contentModelIds; - - public function __construct( array $contentModelIds ) { - $this->contentModelIds = $contentModelIds; + /** + * @param array $typeMap Entity type -> content model mapping + */ + public function __construct( array $typeMap ) { + $this->typeMap = $typeMap; } /** @@ -54,7 +56,7 @@ * @return array An array of string content model IDs. */ public function getEntityContentModels() { - return $this->contentModelIds; + return $this->typeMap; } /** @@ -138,7 +140,7 @@ * @return int */ public function getNamespaceForType( $type ) { - return NamespaceUtils::getEntityNamespace( self::$typeMap[$type] ); + return NamespaceUtils::getEntityNamespace( $this->typeMap[$type] ); } /** @@ -188,7 +190,7 @@ /** * @var EntityHandler $handler */ - $handler = \ContentHandler::getForModelID( self::$typeMap[$entity->getType()] ); + $handler = \ContentHandler::getForModelID( $this->typeMap[$entity->getType()] ); return $handler->newContentFromEntity( $entity ); } diff --git a/repo/includes/store/sql/EntityPerPageBuilder.php b/repo/includes/store/sql/EntityPerPageBuilder.php index 66726d8..3aa59d6 100644 --- a/repo/includes/store/sql/EntityPerPageBuilder.php +++ b/repo/includes/store/sql/EntityPerPageBuilder.php @@ -58,15 +58,24 @@ protected $rebuildAll = false; /** + * @since 0.5 + * + * @var array + */ + protected $contentModels; + + /** * @param EntityPerPage $entityPerPageTable * @param EntityContentFactory $entityContentFactory * @param EntityIdParser $entityIdParser + * @param array $contentModels */ public function __construct( EntityPerPage $entityPerPageTable, EntityContentFactory $entityContentFactory, - EntityIdParser $entityIdParser ) { + EntityIdParser $entityIdParser, array $contentModels ) { $this->entityPerPageTable = $entityPerPageTable; $this->entityContentFactory = $entityContentFactory; $this->entityIdParser = $entityIdParser; + $this->contentModels = $contentModels; } /** @@ -141,11 +150,17 @@ * @return array */ protected function getQueryConds( $lastPageSeen ) { + global $wgContentHandlerUseDB; + $conds = array( 'page_namespace' => NamespaceUtils::getEntityNamespaces(), - 'page_id > ' . $lastPageSeen + 'page_id > ' . (int) $lastPageSeen ); + if ( $wgContentHandlerUseDB ) { + $conds['page_content_model'] = $this->contentModels; + } + if ( $this->rebuildAll === false ) { $conds[] = 'epp_page_id IS NULL'; } diff --git a/repo/maintenance/rebuildEntityPerPage.php b/repo/maintenance/rebuildEntityPerPage.php index 0768dad..c33efe6 100644 --- a/repo/maintenance/rebuildEntityPerPage.php +++ b/repo/maintenance/rebuildEntityPerPage.php @@ -49,10 +49,18 @@ ); $entityPerPageTable = StoreFactory::getStore( 'sqlstore' )->newEntityPerPage(); - $entityContentFactory = WikibaseRepo::getDefaultInstance()->getEntityContentFactory(); - $entityIdParser = WikibaseRepo::getDefaultInstance()->getEntityIdParser(); + $wikibaseRepo = WikibaseRepo::getDefaultInstance(); + $entityContentFactory = $wikibaseRepo->getEntityContentFactory(); + $entityIdParser = $wikibaseRepo->getEntityIdParser(); + $contentModels = $wikibaseRepo->getContentModelMappings(); - $builder = new EntityPerPageBuilder( $entityPerPageTable, $entityContentFactory, $entityIdParser ); + $builder = new EntityPerPageBuilder( + $entityPerPageTable, + $entityContentFactory, + $entityIdParser, + $contentModels + ); + $builder->setReporter( $reporter ); $builder->setBatchSize( $batchSize ); diff --git a/repo/tests/phpunit/includes/WikibaseRepoTest.php b/repo/tests/phpunit/includes/WikibaseRepoTest.php index c3d2bd4..c8ad9d4 100644 --- a/repo/tests/phpunit/includes/WikibaseRepoTest.php +++ b/repo/tests/phpunit/includes/WikibaseRepoTest.php @@ -135,6 +135,14 @@ $this->assertInstanceOf( 'Wikibase\ChangeOp\ChangeOpFactory', $returnValue ); } + public function testGetContentModelMappings() { + $array = $this->getDefaultInstance()->getContentModelMappings(); + foreach( $array as $entityType => $contentModel ) { + $this->assertTrue( is_scalar( $entityType ) ); + $this->assertTrue( is_scalar( $contentModel ) ); + } + } + /** * @return WikibaseRepo */ diff --git a/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php b/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php index 7cd6876..5dd745c 100644 --- a/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php +++ b/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php @@ -5,9 +5,9 @@ use InvalidArgumentException; use Wikibase\DataModel\Entity\ItemId; use Wikibase\EntityContentFactory; -use Wikibase\Item; -use Wikibase\Property; use Wikibase\Repo\WikibaseRepo; +use Wikibase\DataModel\Entity\Item; +use Wikibase\DataModel\Entity\Property; /** * @covers Wikibase\EntityContentFactory @@ -41,9 +41,8 @@ $argLists = array(); $argLists[] = array( array() ); - $argLists[] = array( array( 0 ) ); - $argLists[] = array( array( 42, 1337, 9001 ) ); - $argLists[] = array( array( 0, 1, 2, 3, 4, 5, 6, 7 ) ); + $argLists[] = array( array( 'Foo' => 'Bar' ) ); + $argLists[] = array( WikibaseRepo::getDefaultInstance()->getContentModelMappings() ); return $argLists; } @@ -60,7 +59,7 @@ protected function newFactory() { return new EntityContentFactory( - array( 42, 1337, 9001 ) + WikibaseRepo::getDefaultInstance()->getContentModelMappings() ); } diff --git a/repo/tests/phpunit/includes/store/sql/EntityPerPageBuilderTest.php b/repo/tests/phpunit/includes/store/sql/EntityPerPageBuilderTest.php index 18d2558..eec79a7 100644 --- a/repo/tests/phpunit/includes/store/sql/EntityPerPageBuilderTest.php +++ b/repo/tests/phpunit/includes/store/sql/EntityPerPageBuilderTest.php @@ -173,7 +173,8 @@ $builder = new EntityPerPageBuilder( $this->entityPerPageTable, $this->wikibaseRepo->getEntityContentFactory(), - $this->wikibaseRepo->getEntityIdParser() + $this->wikibaseRepo->getEntityIdParser(), + $this->wikibaseRepo->getContentModelMappings() ); $builder->setRebuildAll( true ); @@ -199,7 +200,8 @@ $builder = new EntityPerPageBuilder( $this->entityPerPageTable, $this->wikibaseRepo->getEntityContentFactory(), - $this->wikibaseRepo->getEntityIdParser() + $this->wikibaseRepo->getEntityIdParser(), + $this->wikibaseRepo->getContentModelMappings() ); $builder->rebuild(); diff --git a/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php b/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php index 535f897..eca8922 100644 --- a/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php +++ b/repo/tests/phpunit/includes/store/sql/WikiPageEntityStoreTest.php @@ -5,10 +5,8 @@ use User; use Wikibase\DataModel\Entity\Entity; use Wikibase\DataModel\Entity\Item; -use Wikibase\DataModel\Entity\Property; use Wikibase\EntityContentFactory; -use Wikibase\EntityRevisionLookup; -use Wikibase\store\EntityStore; +use Wikibase\Repo\WikibaseRepo; use Wikibase\store\WikiPageEntityStore; use Wikibase\WikiPageEntityLookup; @@ -33,10 +31,7 @@ //NOTE: we want to test integration of WikiPageEntityLookup and WikiPageEntityStore here! $lookup = new WikiPageEntityLookup( false, CACHE_DB ); - $typeMap = array( - Item::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_ITEM, - Property::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_PROPERTY, - ); + $typeMap = WikibaseRepo::getDefaultInstance()->getContentModelMappings(); $store = new WikiPageEntityStore( new EntityContentFactory( $typeMap ) ); -- To view, visit https://gerrit.wikimedia.org/r/120857 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9e0a5ca212d3ce210d1ca42a4829abf86ae18cde Gerrit-PatchSet: 11 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits