/** * @param mixed[] $settings * * @return SettingsArray */ private function newSettingsArray(array $settings) { $settingsArray = new SettingsArray(); foreach ($settings as $setting => $value) { $settingsArray->setSetting($setting, $value); } return $settingsArray; }
/** * @dataProvider settingsProvider */ public function testDefaults(array $settings, array $wg, $repoIsLocal, $expected) { $this->setMwGlobals($wg); $defaults = (include WBC_DIR . '/config/WikibaseClient.default.php'); $settings = array_merge($defaults, $settings); $settings = new SettingsArray($settings); //NOTE: thisWikiIsTheRepo us used by some "magic" (dynamic) defaults // to decide how to behave. Normally, this is true if and only if // WB_VERSION is defined. $settings->setSetting('thisWikiIsTheRepo', $repoIsLocal); foreach ($expected as $key => $exp) { $actual = $settings->getSetting($key); $this->assertSame($exp, $actual, "Setting {$key}"); } }
/** * @return RestrictedEntityLookup */ public function getRestrictedEntityLookup() { if ($this->restrictedEntityLookup === null) { $this->restrictedEntityLookup = new RestrictedEntityLookup($this->getEntityLookup(), $this->settings->getSetting('entityAccessLimit')); } return $this->restrictedEntityLookup; }
/** * Initializes members from command line options and configuration settings. * * @param string[] $clientWikis A mapping of client wiki site IDs to logical database names. * @param ChangeLookup $changeLookup * @param SettingsArray $settings * * @return ChangeDispatcher */ private function newChangeDispatcher(array $clientWikis, ChangeLookup $changeLookup, SettingsArray $settings) { $repoID = wfWikiID(); $repoDB = $settings->getSetting('changesDatabase'); $batchChunkFactor = $settings->getSetting('dispatchBatchChunkFactor'); $batchCacheFactor = $settings->getSetting('dispatchBatchCacheFactor'); $batchSize = (int) $this->getOption('batch-size', 1000); $maxChunks = (int) $this->getOption('max-chunks', 15); $dispatchInterval = (int) $this->getOption('dispatch-interval', 60); $lockGraceInterval = (int) $this->getOption('lock-grace-interval', 60); $randomness = (int) $this->getOption('randomness', 10); $this->verbose = $this->getOption('verbose', false); $cacheChunkSize = $batchSize * $batchChunkFactor; $cacheSize = $cacheChunkSize * $batchCacheFactor; $changesCache = new ChunkCache($changeLookup, $cacheChunkSize, $cacheSize); $reporter = new ObservableMessageReporter(); $self = $this; // PHP 5.3... $reporter->registerReporterCallback(function ($message) use($self) { $self->log($message); }); $coordinator = new SqlChangeDispatchCoordinator($repoDB, $repoID); $coordinator->setMessageReporter($reporter); $coordinator->setBatchSize($batchSize); $coordinator->setDispatchInterval($dispatchInterval); $coordinator->setLockGraceInterval($lockGraceInterval); $coordinator->setRandomness($randomness); $notificationSender = new JobQueueChangeNotificationSender($repoDB, $clientWikis); $subscriptionLookup = new SqlSubscriptionLookup(wfGetLB()); $dispatcher = new ChangeDispatcher($coordinator, $notificationSender, $changesCache, $subscriptionLookup); $dispatcher->setMessageReporter($reporter); $dispatcher->setExceptionHandler(new ReportingExceptionHandler($reporter)); $dispatcher->setBatchSize($batchSize); $dispatcher->setMaxChunks($maxChunks); $dispatcher->setBatchChunkFactor($batchChunkFactor); $dispatcher->setVerbose($this->verbose); return $dispatcher; }
/** * Initializes members from command line options and configuration settings. * * @param ChangeLookup $changeLookup * @param SettingsArray $settings * * @return ChangeDispatcher * @throws MWException */ private function newChangeDispatcher(ChangeLookup $changeLookup, SettingsArray $settings) { $repoDB = $settings->getSetting('changesDatabase'); $clientWikis = $settings->getSetting('localClientDatabases'); $batchChunkFactor = $settings->getSetting('dispatchBatchChunkFactor'); $batchCacheFactor = $settings->getSetting('dispatchBatchCacheFactor'); $subscriptionLookupMode = $settings->getSetting('subscriptionLookupMode'); $batchSize = (int) $this->getOption('batch-size', 1000); $maxChunks = (int) $this->getOption('max-chunks', 15); $dispatchInterval = (int) $this->getOption('dispatch-interval', 60); $lockGraceInterval = (int) $this->getOption('lock-grace-interval', 60); $randomness = (int) $this->getOption('randomness', 10); $this->verbose = $this->getOption('verbose', false); $cacheChunkSize = $batchSize * $batchChunkFactor; $cacheSize = $cacheChunkSize * $batchCacheFactor; $changesCache = new ChunkCache($changeLookup, $cacheChunkSize, $cacheSize); // make sure we have a mapping from siteId to database name in clientWikis: foreach ($clientWikis as $siteID => $dbName) { if (is_int($siteID)) { unset($clientWikis[$siteID]); $clientWikis[$dbName] = $dbName; } } if (empty($clientWikis)) { throw new MWException("No client wikis configured! Please set \$wgWBRepoSettings['localClientDatabases']."); } $reporter = new ObservableMessageReporter(); $self = $this; // PHP 5.3... $reporter->registerReporterCallback(function ($message) use($self) { $self->log($message); }); $coordinator = new SqlChangeDispatchCoordinator($repoDB, $clientWikis); $coordinator->setMessageReporter($reporter); $coordinator->setBatchSize($batchSize); $coordinator->setDispatchInterval($dispatchInterval); $coordinator->setLockGraceInterval($lockGraceInterval); $coordinator->setRandomness($randomness); $notificationSender = new JobQueueChangeNotificationSender($repoDB, $clientWikis); $subscriptionLookup = $this->getSubscriptionLookup($repoDB, $subscriptionLookupMode); $dispatcher = new ChangeDispatcher($coordinator, $notificationSender, $changesCache, $subscriptionLookup); $dispatcher->setMessageReporter($reporter); $dispatcher->setExceptionHandler(new ReportingExceptionHandler($reporter)); $dispatcher->setBatchSize($batchSize); $dispatcher->setMaxChunks($maxChunks); $dispatcher->setBatchChunkFactor($batchChunkFactor); $dispatcher->setVerbose($this->verbose); return $dispatcher; }
/** * @dataProvider settingProvider */ public function testSetSetting(array $settings) { $settings = new SettingsArray($settings); foreach ($settings as $settingName => $settingValue) { $settings->setSetting($settingName, $settingValue); $this->assertEquals($settingValue, $settings->getSetting($settingName)); } foreach ($settings as $settingName => $settingValue) { $settings->setSetting($settingName, $settingValue); $this->assertEquals($settingValue, $settings->getSetting($settingName)); } if ($settings->count() === 0) { $this->assertTrue(true); } }
public function testExportTransform_neverRecodeNonLegacyFormat() { $settings = new SettingsArray(); $settings->setSetting('transformLegacyFormatOnExport', true); $entity = $this->newEntity(); $currentSerializer = $this->getWikibaseRepo($settings)->getInternalEntitySerializer(); $expected = json_encode($currentSerializer->serialize($entity)); $handler = $this->getHandler($settings); $actual = $handler->exportTransform($expected); $this->assertEquals($expected, $actual); }
/** * @return OtherProjectsSidebarGenerator */ private function newOtherProjectsSidebarGenerator() { return new OtherProjectsSidebarGenerator($this->settings->getSetting('siteGlobalID'), $this->siteLinkLookup, $this->siteStore, $this->settings->getSetting('otherProjectsLinks')); }
/** * @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')); }
/** * @param string $setting * * @return mixed */ public function getSetting($setting) { return $this->settings->getSetting($setting); }
/** * @return string[] */ private function getSpecialSiteLinkGroups() { return $this->settings->getSetting('specialSiteLinkGroups'); }
/** * @return string[] */ private function getRepoUrls() { return array('base' => $this->settings->getSetting('repoUrl'), 'scriptpath' => $this->settings->getSetting('repoScriptPath'), 'articlepath' => $this->settings->getSetting('repoArticlePath')); }