示例#1
0
 /**
  * @since 2.0
  */
 public static function clear()
 {
     if (self::$instance !== null) {
         self::$instance->getSettings()->clear();
     }
     self::$instance = null;
 }
 /**
  * @since 2.2
  *
  * @return ConnectionManager
  */
 public function newConnectionManager()
 {
     $connectionManager = new ConnectionManager();
     $repositoryConnectionProvider = new RepositoryConnectionProvider();
     $repositoryConnectionProvider->setHttpVersionTo($this->applicationFactory->getSettings()->get('smwgSparqlRepositoryConnectorForcedHttpVersion'));
     $connectionManager->registerConnectionProvider('sparql', $repositoryConnectionProvider);
     return $connectionManager;
 }
示例#3
0
 /**
  * @note Article purge: In case an article was manually purged/moved
  * the store is updated as well; for all other cases LinksUpdateConstructed
  * will handle the store update
  */
 private function checkForRequestedUpdateByPagePurge($parserData)
 {
     $cache = $this->applicationFactory->getCache();
     $cache->setKey(ArticlePurge::newCacheId($this->parser->getTitle()->getArticleID()));
     if ($cache->get()) {
         $cache->delete();
         $parserData->updateStore();
     }
     return true;
 }
 /**
  * #347 showed that an external process (e.g. RefreshLinksJob) can inject a
  * ParserOutput without/cleared SemanticData which forces the Store updater
  * to create an empty container that will clear all existing data.
  * 
  * To ensure that for a Title and its current revision an empty ParserOutput
  * object is really meant to be "empty" (e.g. delete action initiated by a
  * human) the content is re-parsed in order to fetch the newest available data
  *
  * @note Parsing is expensive but it is more expensive to loose data or to
  * expect that an external process adheres the object contract
  */
 private function refetchSemanticData()
 {
     wfDebug(__METHOD__ . ' Empty SemanticData / re-parsing: ' . $this->linksUpdate->getTitle()->getPrefixedDBkey() . "\n");
     $contentParser = $this->applicationFactory->newContentParser($this->linksUpdate->getTitle());
     $parserOutput = $contentParser->parse()->getOutput();
     if ($parserOutput === null) {
         return null;
     }
     if (method_exists($parserOutput, 'getExtensionData')) {
         return $parserOutput->getExtensionData('smwdata');
     }
     return $parserOutput->mSMWData;
 }
 private function isHiddenCategory($catName)
 {
     if ($this->hiddenCategories === null) {
         $wikipage = $this->applicationFactory->newPageCreator()->createPage($this->getSemanticData()->getSubject()->getTitle());
         $this->hiddenCategories = $wikipage->getHiddenCategories();
     }
     foreach ($this->hiddenCategories as $hiddenCategory) {
         if ($hiddenCategory->getText() === $catName) {
             return true;
         }
     }
     return false;
 }
 /**
  * @see ApiBase::execute
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $propertyListByApiRequest = new PropertyListByApiRequest(ApplicationFactory::getInstance()->getStore());
     $propertyListByApiRequest->setLimit($params['limit']);
     $propertyListByApiRequest->findPropertyListFor($params['property']);
     foreach ($propertyListByApiRequest->getNamespaces() as $ns) {
         $uri = NamespaceUriFinder::getUri($ns);
         if (!$uri) {
             continue;
         }
         $this->getResult()->addValue(null, 'xmlns:' . $ns, $uri);
     }
     $data = $propertyListByApiRequest->getPropertyList();
     // I'm without words for this utter nonsense introduced here
     // because property keys can have a underscore _MDAT or for that matter
     // any other data field can
     // https://www.mediawiki.org/wiki/API:JSON_version_2
     // " ... can indicate that a property beginning with an underscore is not metadata using"
     if (method_exists($this->getResult(), 'setPreserveKeysList')) {
         $this->getResult()->setPreserveKeysList($data, array_keys($data));
     }
     $this->getResult()->addValue(null, 'query', $data);
     $this->getResult()->addValue(null, 'version', 0.1);
     $this->getResult()->addValue(null, 'query-continue-offset', $propertyListByApiRequest->getContinueOffset());
     $this->getResult()->addValue(null, 'meta', $propertyListByApiRequest->getMeta());
 }
 /**
  * @since 2.4
  *
  * @param Store $store
  * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator
  *
  * @return EntityIdListRelevanceDetectionFilter
  */
 public function newEntityIdListRelevanceDetectionFilter(Store $store, CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator)
 {
     $entityIdListRelevanceDetectionFilter = new EntityIdListRelevanceDetectionFilter($store, $compositePropertyTableDiffIterator);
     $entityIdListRelevanceDetectionFilter->setPropertyExemptionlist(ApplicationFactory::getInstance()->getSettings()->get('smwgQueryDependencyPropertyExemptionlist'));
     $entityIdListRelevanceDetectionFilter->setAffiliatePropertyDetectionlist(ApplicationFactory::getInstance()->getSettings()->get('smwgQueryDependencyAffiliatePropertyDetectionlist'));
     return $entityIdListRelevanceDetectionFilter;
 }
 protected function setUp()
 {
     parent::setUp();
     $utilityFactory = UtilityFactory::getInstance();
     $this->fixturesFileProvider = $utilityFactory->newFixturesFactory()->newFixturesFileProvider();
     $this->semanticDataValidator = $utilityFactory->newValidatorFactory()->newSemanticDataValidator();
     $this->pageEditor = $utilityFactory->newPageEditor();
     $this->mwHooksHandler = $utilityFactory->newMwHooksHandler();
     $this->mwHooksHandler->deregisterListedHooks();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $settings = array('smwgPageSpecialProperties' => array('_MEDIA', '_MIME'), 'smwgNamespacesWithSemanticLinks' => array(NS_MAIN => true, NS_FILE => true), 'smwgCacheType' => 'hash');
     foreach ($settings as $key => $value) {
         $this->applicationFactory->getSettings()->set($key, $value);
     }
     //	$this->getStore()->clear();
     //	$this->getStore()->setupStore( false );
     $this->wgEnableUploads = $GLOBALS['wgEnableUploads'];
     $this->wgFileExtensions = $GLOBALS['wgFileExtensions'];
     $this->wgVerifyMimeType = $GLOBALS['wgVerifyMimeType'];
     $this->mwHooksHandler->register('FileUpload', $this->mwHooksHandler->getHookRegistry()->getHandlerFor('FileUpload'));
     $this->mwHooksHandler->register('InternalParseBeforeLinks', $this->mwHooksHandler->getHookRegistry()->getHandlerFor('InternalParseBeforeLinks'));
     $this->mwHooksHandler->register('LinksUpdateConstructed', $this->mwHooksHandler->getHookRegistry()->getHandlerFor('LinksUpdateConstructed'));
     $GLOBALS['wgEnableUploads'] = true;
     $GLOBALS['wgFileExtensions'] = array('txt');
     $GLOBALS['wgVerifyMimeType'] = true;
 }
 /**
  * @since 1.9
  *
  * @return true
  */
 public function process()
 {
     $applicationFactory = ApplicationFactory::getInstance();
     // Delete all data for a non-enabled target NS
     if (!$applicationFactory->getNamespaceExaminer()->isSemanticEnabled($this->newTitle->getNamespace()) || $this->newId == 0) {
         $applicationFactory->getStore()->deleteSubject($this->oldTitle);
     } else {
         // Using a different approach since the hook is not triggered
         // by #REDIRECT which can cause inconsistencies
         // @see 2.3 / StoreUpdater
         //	$applicationFactory->getStore()->changeTitle(
         //		$this->oldTitle,
         //		$this->newTitle,
         //		$this->oldId,
         //		$this->newId
         //	);
     }
     $eventHandler = EventHandler::getInstance();
     $dispatchContext = $eventHandler->newDispatchContext();
     $dispatchContext->set('title', $this->oldTitle);
     $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     $dispatchContext = $eventHandler->newDispatchContext();
     $dispatchContext->set('title', $this->newTitle);
     $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     return true;
 }
 private function createQueryProfile($query, $format, $duration)
 {
     $queryProfileAnnotatorFactory = $this->applicationFactory->newQueryProfileAnnotatorFactory();
     $jointProfileAnnotator = $queryProfileAnnotatorFactory->newJointProfileAnnotator($query, $format, $duration);
     $jointProfileAnnotator->addAnnotation();
     $this->parserData->getSemanticData()->addPropertyObjectValue($jointProfileAnnotator->getProperty(), $jointProfileAnnotator->getContainer());
 }
 /**
  * @since 1.9
  */
 public function smwgNamespacesWithSemanticLinksProvider()
 {
     $provider = array();
     $provider[] = array('GLOBALS', GlobalsProvider::getInstance()->get('smwgNamespacesWithSemanticLinks'));
     $provider[] = array('Settings', ApplicationFactory::getInstance()->getSettings()->get('smwgNamespacesWithSemanticLinks'));
     return $provider;
 }
 protected function tearDown()
 {
     ApplicationFactory::getInstance()->clear();
     $pageDeleter = UtilityFactory::getInstance()->newPageDeleter();
     $pageDeleter->doDeletePoolOfPages($this->importedTitles);
     parent::tearDown();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $settings = Settings::newFromArray(array('smwgFactboxUseCache' => true, 'smwgCacheType' => 'hash'));
     $this->applicationFactory->registerObject('Settings', $settings);
 }
 /**
  * @since 2.0
  *
  * @return true
  */
 public function process()
 {
     $settings = ApplicationFactory::getInstance()->getSettings();
     $deleteSubjectJob = new DeleteSubjectJob($this->wikiPage->getTitle(), array('asDeferredJob' => $settings->get('smwgDeleteSubjectAsDeferredJob'), 'withAssociates' => $settings->get('smwgDeleteSubjectWithAssociatesRefresh')));
     $deleteSubjectJob->execute();
     return true;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $this->applicationFactory->getSettings()->set('smwgEnableUpdateJobs', false);
     $this->applicationFactory->getSettings()->set('smwgDeleteSubjectWithAssociatesRefresh', false);
 }
 /**
  * @dataProvider queryStringProvider
  */
 public function testCreateFromString($queryString, $configuration, $expected)
 {
     $instance = new ConfigurableQueryCreator(ApplicationFactory::getInstance()->getQueryFactory());
     $query = $instance->withConfiguration($configuration)->createFromString($queryString);
     $this->assertInstanceOf('\\SMWQuery', $query);
     $this->assertSame($expected, $query->getAsString());
 }
 /**
  * @since 2.3
  *
  * @return InMemoryPoolCache
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self(ApplicationFactory::getInstance()->newCacheFactory());
     }
     return self::$instance;
 }
示例#18
0
 protected function setUp()
 {
     parent::setUp();
     $this->semanticDataValidator = new SemanticDataValidator();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $this->parserFactory = new ParserFactory();
 }
 /**
  * @since 2.4
  *
  * {@inheritDoc}
  */
 public function validate($dataValue)
 {
     $this->hasConstraintViolation = false;
     if (!$this->canValidate($dataValue)) {
         return $this->hasConstraintViolation;
     }
     $property = $dataValue->getProperty();
     if (!ApplicationFactory::getInstance()->getPropertySpecificationLookup()->hasUniquenessConstraintBy($property)) {
         return $this->hasConstraintViolation;
     }
     $blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore();
     $dataItem = $dataValue->getDataItem();
     $hash = $this->cachedPropertyValuesPrefetcher->createHashFromString($property->getKey() . ':' . $dataItem->getHash());
     $container = $blobStore->read($hash);
     $key = 'PVUC';
     if (!$container->has($key)) {
         $page = $this->tryFindMatchResultFor($hash, $dataValue);
         $container->set($key, $page);
         $blobStore->save($container);
     }
     $wikiPage = $container->get($key);
     // Verify that the contextPage (where the annotation has its origin) is
     // matchable to the request and in case it is not a match inform the user
     // about the origin
     if ($wikiPage instanceof DIWikiPage && !$dataValue->getContextPage()->equals($wikiPage)) {
         $dataValue->addErrorMsg(array('smw-datavalue-uniqueness-constraint-error', $property->getLabel(), $dataValue->getWikiValue(), $wikiPage->getTitle()->getPrefixedText()));
         $this->hasConstraintViolation = true;
     }
 }
示例#20
0
 protected function setUp()
 {
     parent::setUp();
     $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $this->applicationFactory->getSettings()->set('smwgQueryDurationEnabled', false);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $settings = Settings::newFromArray(array('smwgShowFactbox' => SMW_FACTBOX_NONEMPTY, 'smwgFactboxUseCache' => true, 'smwgCacheType' => 'hash', 'smwgLinksInValues' => false, 'smwgInlineErrors' => true));
     $this->applicationFactory->registerObject('Settings', $settings);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->mwHooksHandler = UtilityFactory::getInstance()->newMwHooksHandler();
     $this->mwHooksHandler->deregisterListedHooks();
     $this->applicationFactory = ApplicationFactory::getInstance();
 }
 /**
  * @since  1.9
  */
 protected function loadAtInstantiation()
 {
     /**
      * Settings object definition
      *
      * @since  1.9
      *
      * @return Settings
      */
     $this->registerObject('Settings', function () {
         return Settings::newFromGlobals();
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * Store object definition
      *
      * @since  1.9
      *
      * @return Store
      */
     $this->registerObject('Store', function (DependencyBuilder $builder) {
         return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore'));
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * @since  1.9
      *
      * @return Cache
      */
     $this->registerObject('Cache', function (DependencyBuilder $builder) {
         return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache();
     }, DependencyObject::SCOPE_SINGLETON);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->applicationFactory->registerObject('Store', $store);
 }
 /**
  * Based on the CHUNK_SIZE, target links are purged in an instant if those
  * selected entities are < CHUNK_SIZE which should be enough for most
  * common queries that only share a limited amount of dependencies, yet for
  * queries that expect a large subject/dependency pool, doing an online update
  * for all at once is not feasible hence the iterative process of creating
  * batches that run through the job scheduler.
  *
  * @param array|string $idList
  */
 private function findEmbeddedQueryTargetLinksBatches($idList)
 {
     if (is_string($idList) && strpos($idList, '|') !== false) {
         $idList = explode('|', $idList);
     }
     if ($idList === array()) {
         return true;
     }
     $queryDependencyLinksStoreFactory = new QueryDependencyLinksStoreFactory();
     $queryDependencyLinksStore = $queryDependencyLinksStoreFactory->newQueryDependencyLinksStore($this->store);
     $requestOptions = new RequestOptions();
     // +1 to look ahead
     $requestOptions->setLimit($this->limit + 1);
     $requestOptions->setOffset($this->offset);
     $hashList = $queryDependencyLinksStore->findEmbeddedQueryTargetLinksHashListFor($idList, $requestOptions);
     if ($hashList === array()) {
         return true;
     }
     $countedHashListEntries = count($hashList);
     // If more results are available then use an iterative increase to fetch
     // the remaining updates by creating successive jobs
     if ($countedHashListEntries > $this->limit) {
         $job = new self($this->getTitle(), array('idlist' => $idList, 'limit' => $this->limit, 'offset' => $this->offset + self::CHUNK_SIZE));
         $job->run();
     }
     wfDebugLog('smw', __METHOD__ . " counted: {$countedHashListEntries} | offset: {$this->offset}  for " . $this->getTitle()->getPrefixedDBKey() . "\n");
     list($hashList, $queryList) = $this->doBuildUniqueTargetLinksHashList($hashList);
     $this->applicationFactory->singleton('CachedQueryResultPrefetcher')->resetCacheBy($queryList);
     $this->addPagesToUpdater($hashList);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->applicationFactory = ApplicationFactory::getInstance();
     $settings = Settings::newFromArray(array('smwgDeclarationProperties' => array('_PVAL'), 'smwgCacheType' => 'hash', 'smwgEnableUpdateJobs' => false));
     $this->applicationFactory->registerObject('Settings', $settings);
 }
 /**
  * @since 2.0
  *
  * @param ParserData $parserData
  * @param IContextSource $context
  *
  * @return Factbox
  */
 public function newFactbox(ParserData $parserData, IContextSource $context)
 {
     $applicationFactory = ApplicationFactory::getInstance();
     $messageBuilder = $applicationFactory->newMwCollaboratorFactory()->newMessageBuilder();
     $messageBuilder->setLanguageFromContext($context);
     return new Factbox($applicationFactory->getStore(), $parserData, $messageBuilder);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory();
     $this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator();
     $this->applicationFactory = ApplicationFactory::getInstance();
 }
 /**
  * @since 2.2
  *
  * @param Store $store
  * @param Callable|null $reporterCallback
  *
  * @return ConceptCacheRebuilder
  */
 public function newConceptCacheRebuilder(Store $store, $reporterCallback = null)
 {
     $messageReporter = MessageReporterFactory::getInstance()->newObservableMessageReporter();
     $messageReporter->registerReporterCallback($reporterCallback);
     $conceptCacheRebuilder = new ConceptCacheRebuilder($store, ApplicationFactory::getInstance()->getSettings());
     $conceptCacheRebuilder->setMessageReporter($messageReporter);
     return $conceptCacheRebuilder;
 }
 /**
  * @see Job::run
  *
  * @since  2.5
  */
 public function run()
 {
     $fulltextSearchTableFactory = new FulltextSearchTableFactory();
     $textByChangeUpdater = $fulltextSearchTableFactory->newTextByChangeUpdater(ApplicationFactory::getInstance()->getStore('\\SMW\\SQLStore\\SQLStore'));
     $textByChangeUpdater->pushUpdatesFromJobParameters($this->params);
     Hooks::run('SMW::Job::AfterSearchTableUpdateComplete', array($this));
     return true;
 }