private function newRequestHandler()
 {
     $mockRepository = EntityDataTestProvider::getMockRepository();
     $titleLookup = $this->getMock('Wikibase\\Lib\\Store\\EntityTitleLookup');
     $titleLookup->expects($this->any())->method('getTitleForId')->will($this->returnCallback(function (EntityId $id) {
         return Title::newFromText($id->getEntityType() . ':' . $id->getSerialization());
     }));
     $dataTypeLookup = $this->getMock('Wikibase\\DataModel\\Services\\Lookup\\PropertyDataTypeLookup');
     $dataTypeLookup->expects($this->any())->method('getDataTypeIdForProperty')->will($this->returnValue('string'));
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $serializerFactory = new SerializerFactory(new DataValueSerializer(), SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH + SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH);
     // Note: We are testing with the actual RDF bindings. These should not change for well
     // known data types. Mocking the bindings would be nice, but is complex and not needed.
     $rdfBuilder = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $serializationService = new EntityDataSerializationService(self::URI_BASE, self::URI_DATA, $mockRepository, $titleLookup, $dataTypeLookup, $rdfBuilder, new SiteList(), $entityDataFormatProvider, $serializerFactory, new HashSiteStore());
     $formats = array('json', 'rdfxml', 'ntriples');
     $entityDataFormatProvider->setFormatWhiteList($formats);
     $defaultFormat = 'rdf';
     $supportedExtensions = array_combine($formats, $formats);
     $title = SpecialPage::getTitleFor('EntityData');
     $uriManager = new EntityDataUriManager($title, $supportedExtensions, $titleLookup);
     $useSquid = false;
     $apiFrameOptions = 'DENY';
     return new EntityDataRequestHandler($uriManager, $titleLookup, new BasicEntityIdParser(), $mockRepository, $mockRepository, $serializationService, $entityDataFormatProvider, $defaultFormat, 0, $useSquid, $apiFrameOptions);
 }
 /**
  * Creates a EntityDataRequestHandler based on global defaults.
  *
  * @return EntityDataRequestHandler
  */
 private function newDefaultRequestHandler()
 {
     global $wgUseSquid, $wgApiFrameOptions;
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $entityRevisionLookup = $wikibaseRepo->getEntityRevisionLookup();
     $entityRedirectLookup = $wikibaseRepo->getStore()->getEntityRedirectLookup();
     $titleLookup = $wikibaseRepo->getEntityTitleLookup();
     $entityIdParser = $wikibaseRepo->getEntityIdParser();
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $serializerFactory = new SerializerFactory(new DataValueSerializer(), SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH + SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH);
     $languageCodes = array_merge($GLOBALS['wgDummyLanguageCodes'], $wikibaseRepo->getSettings()->getSetting('canonicalLanguageCodes'));
     $serializationService = new EntityDataSerializationService($wikibaseRepo->getSettings()->getSetting('conceptBaseUri'), $this->getPageTitle()->getCanonicalURL() . '/', $wikibaseRepo->getStore()->getEntityLookup(), $titleLookup, $wikibaseRepo->getPropertyDataTypeLookup(), $wikibaseRepo->getValueSnakRdfBuilderFactory(), $wikibaseRepo->getSiteStore()->getSites(), $entityDataFormatProvider, $serializerFactory, $wikibaseRepo->getSiteStore(), $languageCodes);
     $maxAge = $wikibaseRepo->getSettings()->getSetting('dataSquidMaxage');
     $formats = $wikibaseRepo->getSettings()->getSetting('entityDataFormats');
     $entityDataFormatProvider->setFormatWhiteList($formats);
     $defaultFormat = empty($formats) ? 'html' : $formats[0];
     // build a mapping of formats to file extensions and include HTML
     $supportedExtensions = array();
     $supportedExtensions['html'] = 'html';
     foreach ($entityDataFormatProvider->getSupportedFormats() as $format) {
         $ext = $entityDataFormatProvider->getExtension($format);
         if ($ext !== null) {
             $supportedExtensions[$format] = $ext;
         }
     }
     $uriManager = new EntityDataUriManager($this->getPageTitle(), $supportedExtensions, $titleLookup);
     return new EntityDataRequestHandler($uriManager, $titleLookup, $entityIdParser, $entityRevisionLookup, $entityRedirectLookup, $serializationService, $entityDataFormatProvider, $defaultFormat, $maxAge, $wgUseSquid, $wgApiFrameOptions);
 }
 private function newEntityParserOutputGenerator()
 {
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $formats = array('json', 'ntriples');
     $entityDataFormatProvider->setFormatWhiteList($formats);
     $entityTitleLookup = $this->getEntityTitleLookupMock();
     $propertyDataTypeMatcher = new PropertyDataTypeMatcher($this->getPropertyDataTypeLookup());
     $dataUpdaters = array(new ExternalLinksDataUpdater($propertyDataTypeMatcher), new ImageLinksDataUpdater($propertyDataTypeMatcher), new ReferencedEntitiesDataUpdater($entityTitleLookup, new BasicEntityIdParser()));
     return new EntityParserOutputGenerator($this->getEntityViewFactory(), $this->getConfigBuilderMock(), $entityTitleLookup, new SqlEntityInfoBuilderFactory(), $this->newLanguageFallbackChain(), TemplateFactory::getDefaultInstance(), $entityDataFormatProvider, $dataUpdaters, 'en');
 }
 /**
  * @return EntityDataRequestHandler
  */
 protected function newHandler()
 {
     $mockRepository = EntityDataTestProvider::getMockRepository();
     $idParser = new BasicEntityIdParser();
     // we only test for items and properties here.
     $dataTypeLookup = $this->getMock('Wikibase\\DataModel\\Services\\Lookup\\PropertyDataTypeLookup');
     $dataTypeLookup->expects($this->any())->method('getDataTypeIdForProperty')->will($this->returnValue('string'));
     $titleLookup = $this->getMock('Wikibase\\Lib\\Store\\EntityTitleLookup');
     $titleLookup->expects($this->any())->method('getTitleForId')->will($this->returnCallback(function (EntityId $id) {
         return Title::newFromText($id->getEntityType() . ':' . $id->getSerialization());
     }));
     $propertyLookup = $this->getMock('Wikibase\\DataModel\\Services\\Lookup\\PropertyDataTypeLookup');
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $serializerFactory = new SerializerFactory(new DataValueSerializer(), SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH + SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH);
     // Note: We are testing with the actual RDF bindings. These should not change for well
     // known data types. Mocking the bindings would be nice, but is complex and not needed.
     $rdfBuilder = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $service = new EntityDataSerializationService(EntityDataSerializationServiceTest::URI_BASE, EntityDataSerializationServiceTest::URI_DATA, $mockRepository, $titleLookup, $propertyLookup, $rdfBuilder, new SiteList(), $entityDataFormatProvider, $serializerFactory, new MockSiteStore());
     $entityDataFormatProvider->setFormatWhiteList(array('json', 'php', 'rdfxml', 'n3', 'turtle', 'ntriples'));
     $extensions = array('json' => 'json', 'php' => 'php', 'rdfxml' => 'rdf', 'n3' => 'n3', 'turtle' => 'ttl', 'ntriples' => 'n3');
     $uriManager = new EntityDataUriManager($this->interfaceTitle, $extensions, $titleLookup);
     $handler = new EntityDataRequestHandler($uriManager, $titleLookup, $idParser, $mockRepository, $mockRepository, $service, $entityDataFormatProvider, 'json', 1800, false, null);
     return $handler;
 }
Example #5
0
 /**
  * @return EntityParserOutputGeneratorFactory
  */
 public function getEntityParserOutputGeneratorFactory()
 {
     $templateFactory = TemplateFactory::getDefaultInstance();
     $dataTypeLookup = $this->getPropertyDataTypeLookup();
     $statementGrouperBuilder = new StatementGrouperBuilder($this->settings->getSetting('statementSections'), $dataTypeLookup);
     $entityViewFactory = new EntityViewFactory($this->getEntityIdHtmlLinkFormatterFactory(), new EntityIdLabelFormatterFactory(), $this->getHtmlSnakFormatterFactory(), $statementGrouperBuilder->getStatementGrouper(), $this->getSiteStore(), $this->getDataTypeFactory(), $templateFactory, new LanguageNameLookup(), $this->settings->getSetting('siteLinkGroups'), $this->settings->getSetting('specialSiteLinkGroups'), $this->settings->getSetting('badgeItems'));
     $entityDataFormatProvider = new EntityDataFormatProvider();
     $formats = $this->getSettings()->getSetting('entityDataFormats');
     $entityDataFormatProvider->setFormatWhiteList($formats);
     return new EntityParserOutputGeneratorFactory($entityViewFactory, $this->getStore()->getEntityInfoBuilderFactory(), $this->getEntityContentFactory(), $this->getLanguageFallbackChainFactory(), $templateFactory, $entityDataFormatProvider, $dataTypeLookup, $this->getLocalEntityUriParser(), $this->settings->getSetting('preferredGeoDataProperties'), $this->settings->getSetting('preferredPageImagesProperties'), $this->settings->getSetting('globeUris'));
 }
 /**
  * @return EntityDataFormatProvider
  */
 private function getProvider()
 {
     $provider = new EntityDataFormatProvider();
     $provider->setFormatWhiteList(array('json', 'php', 'rdfxml', 'n3', 'turtle', 'ntriples'));
     return $provider;
 }