public function testAddCallbackListenerForAdhocRegistration()
 {
     $eventDispatcher = $this->getMockBuilder('\\Onoi\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $eventDispatcher->expects($this->once())->method('addListener')->with($this->equalTo('foo'), $this->anything());
     $instance = new EventHandler($eventDispatcher);
     $instance->addCallbackListener('foo', function () {
     });
 }
 protected function setUp()
 {
     parent::setUp();
     $validatorFactory = $this->testEnvironment->getUtilityFactory()->newValidatorFactory();
     $stringValidator = $validatorFactory->newStringValidator();
     $semanticDataValidator = $validatorFactory->newSemanticDataValidator();
     $queryResultValidator = $validatorFactory->newQueryResultValidator();
     $this->queryTestCaseProcessor = new QueryTestCaseProcessor($this->getStore(), $queryResultValidator, $stringValidator);
     $this->rdfTestCaseProcessor = new RdfTestCaseProcessor($this->getStore(), $stringValidator);
     $this->parserTestCaseProcessor = new ParserTestCaseProcessor($this->getStore(), $semanticDataValidator, $stringValidator);
     $this->specialPageTestCaseProcessor = new SpecialPageTestCaseProcessor($this->getStore(), $stringValidator);
     $this->eventDispatcher = EventHandler::getInstance()->getEventDispatcher();
     // This ensures that if content is created in the NS_MEDIAWIKI namespace
     // and an object relies on the MediaWikiNsContentReader then it uses the DB
     ApplicationFactory::getInstance()->getMediaWikiNsContentReader()->skipMessageCache();
     DataValueFactory::getInstance()->clear();
     // Reset the Title/TitleParser otherwise a singleton instance holds an outdated
     // content language reference
     $this->testEnvironment->resetMediaWikiService('_MediaWikiTitleCodec');
     $this->testEnvironment->resetMediaWikiService('TitleParser');
     $this->testEnvironment->resetPoolCacheFor(PropertySpecificationLookup::POOLCACHE_ID);
     // Make sure LocalSettings don't interfere with the default settings
     $GLOBALS['smwgDVFeatures'] = $GLOBALS['smwgDVFeatures'] & ~SMW_DV_NUMV_USPACE;
     $this->testEnvironment->addConfiguration('smwgQueryResultCacheType', false);
 }
 /**
  * @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;
 }
 protected function setUp()
 {
     parent::setUp();
     $validatorFactory = UtilityFactory::getInstance()->newValidatorFactory();
     $stringValidator = $validatorFactory->newStringValidator();
     $semanticDataValidator = $validatorFactory->newSemanticDataValidator();
     $queryResultValidator = $validatorFactory->newQueryResultValidator();
     $this->queryTestCaseProcessor = new QueryTestCaseProcessor($this->getStore(), $queryResultValidator, $stringValidator);
     $this->rdfTestCaseProcessor = new RdfTestCaseProcessor($this->getStore(), $stringValidator);
     $this->parserTestCaseProcessor = new ParserTestCaseProcessor($this->getStore(), $semanticDataValidator, $stringValidator);
     $this->eventDispatcher = EventHandler::getInstance()->getEventDispatcher();
 }
 /**
  * @since 1.9
  *
  * @return boolean
  */
 public function process()
 {
     $parserOutput = $this->fetchParserOutputFromEditInfo();
     if (!$parserOutput instanceof ParserOutput) {
         return true;
     }
     $this->doExtendParserOutput($parserOutput);
     $title = $this->wikiPage->getTitle();
     $dispatchContext = EventHandler::getInstance()->newDispatchContext();
     $dispatchContext->set('title', $title);
     EventHandler::getInstance()->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     // If the concept was altered make sure to delete the cache
     if ($title->getNamespace() === SMW_NS_CONCEPT) {
         ApplicationFactory::getInstance()->getStore()->deleteConceptCache($title);
     }
     return true;
 }
 protected function setUp()
 {
     parent::setUp();
     if (version_compare($GLOBALS['wgVersion'], '1.20', '<')) {
         $this->markTestSkipped("Skipping this test, MW 1.19 doesn't clean-up the title cache correctly.");
     }
     $this->runnerFactory = UtilityFactory::getInstance()->newRunnerFactory();
     $this->titleValidator = UtilityFactory::getInstance()->newValidatorFactory()->newTitleValidator();
     $this->stringValidator = UtilityFactory::getInstance()->newValidatorFactory()->newStringValidator();
     ApplicationFactory::getInstance()->getSettings()->set('smwgExportBCAuxiliaryUse', true);
     EventHandler::getInstance()->getEventDispatcher()->dispatch('exporter.reset');
     $importRunner = $this->runnerFactory->newXmlImportRunner(__DIR__ . '/../Fixtures/' . 'GenericLoremIpsumTest-Mw-1-19-7.xml');
     if (!$importRunner->setVerbose(true)->run()) {
         $importRunner->reportFailedImport();
         $this->markTestIncomplete('Test was marked as incomplete because the data import failed');
     }
 }
 /**
  * @see ByJsonTestCaseProvider::runTestCaseFile
  *
  * @param JsonTestCaseFileHandler $jsonTestCaseFileHandler
  */
 protected function runTestCaseFile(JsonTestCaseFileHandler $jsonTestCaseFileHandler)
 {
     $this->checkEnvironmentToSkipCurrentTest($jsonTestCaseFileHandler);
     $permittedSettings = array('smwgNamespace', 'smwgNamespacesWithSemanticLinks', 'wgLanguageCode', 'wgContLang');
     foreach ($permittedSettings as $key) {
         $this->changeGlobalSettingTo($key, $jsonTestCaseFileHandler->getSettingsFor($key));
     }
     $this->createPagesFor($jsonTestCaseFileHandler->getListOfProperties(), SMW_NS_PROPERTY);
     $this->createPagesFor($jsonTestCaseFileHandler->getListOfSubjects(), NS_MAIN);
     // For some reason there are some random failures where
     // the instance hasn't reset the cache in time to fetch the
     // property definition which only happens for the SPARQLStore
     // This should not be necessary because the resetcache event
     // is triggered
     EventHandler::getInstance()->getEventDispatcher()->dispatch('exporter.reset');
     foreach ($jsonTestCaseFileHandler->findTestCasesFor('rdf-testcases') as $case) {
         $this->assertRdfOutputForCase($case, $jsonTestCaseFileHandler->getDebugMode());
     }
 }
Пример #8
0
 /**
  * @since 2.0
  *
  * @return true
  */
 public function process()
 {
     $applicationFactory = ApplicationFactory::getInstance();
     $eventHandler = EventHandler::getInstance();
     $title = $this->wikiPage->getTitle();
     $store = $applicationFactory->getStore();
     $semanticDataSerializer = $applicationFactory->newSerializerFactory()->newSemanticDataSerializer();
     $jobFactory = $applicationFactory->newJobFactory();
     $deferredCallableUpdate = $applicationFactory->newDeferredCallableUpdate(function () use($store, $title, $semanticDataSerializer, $jobFactory, $eventHandler) {
         $subject = DIWikiPage::newFromTitle($title);
         wfDebugLog('smw', 'DeferredCallableUpdate on delete for ' . $subject->getHash());
         $parameters['semanticData'] = $semanticDataSerializer->serialize($store->getSemanticData($subject));
         $jobFactory->newUpdateDispatcherJob($title, $parameters)->insert();
         // Do we want this?
         /*
         $properties = $store->getInProperties( $subject );
         $jobList = array();
         
         foreach ( $properties as $property ) {
         	$propertySubjects = $store->getPropertySubjects( $property, $subject );
         	foreach ( $propertySubjects as $sub ) {
         		$jobList[$sub->getHash()] = true;
         	}
         }
         
         $jobFactory->newUpdateDispatcherJob( $title, array( 'job-list' => $jobList ) )->insert();
         */
         $store->deleteSubject($title);
         $dispatchContext = $eventHandler->newDispatchContext();
         $dispatchContext->set('title', $title);
         $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     });
     $deferredCallableUpdate->setOrigin(__METHOD__);
     $deferredCallableUpdate->pushToUpdateQueue();
     return true;
 }
Пример #9
0
 private function updateStore($parserData)
 {
     $dispatchContext = EventHandler::getInstance()->newDispatchContext();
     $dispatchContext->set('title', $this->getTitle());
     EventHandler::getInstance()->getEventDispatcher()->dispatch('factbox.cache.delete', $dispatchContext);
     // TODO
     // Rebuild the factbox
     $parserData->disableBackgroundUpdateJobs();
     $parserData->updateStore();
     return true;
 }
 private function triggerResetCacheEventBy($id)
 {
     $subject = $this->store->getObjectIds()->getDataItemById($id);
     if (!$subject instanceof DIWikiPage) {
         return;
     }
     $eventHandler = EventHandler::getInstance();
     $dispatchContext = $eventHandler->newDispatchContext();
     $dispatchContext->set('subject', $subject);
     $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     $eventHandler->getEventDispatcher()->dispatch('property.specification.change', $dispatchContext);
     $eventHandler->getEventDispatcher()->dispatch('factbox.cache.delete', $dispatchContext);
 }
Пример #11
0
 private function handleYetUnknownRedirectTarget(SemanticData $semanticData, DIWikiPage $target)
 {
     // Only keep the reference to safeguard that even in case of a text keeping
     // its annotations there are removed from the Store. A redirect is not
     // expected to contain any other annotation other than that of the redirect
     // target
     $subject = $semanticData->getSubject();
     $semanticData = new SemanticData($subject);
     $semanticData->addPropertyObjectValue(new DIProperty('_REDI'), $target);
     // Force a manual changeTitle before the general update otherwise
     // #redirect can cause an inconsistent data container as observed in #895
     $this->store->changeTitle($subject->getTitle(), $target->getTitle(), $subject->getTitle()->getArticleID(), $target->getTitle()->getArticleID());
     $dispatchContext = EventHandler::getInstance()->newDispatchContext();
     $dispatchContext->set('title', $subject->getTitle());
     EventHandler::getInstance()->getEventDispatcher()->dispatch('factbox.cache.delete', $dispatchContext);
     return $semanticData;
 }
Пример #12
0
 private function addCallbackHandlers($basePath, $globalVars)
 {
     $eventHandler = EventHandler::getInstance();
     $applicationFactory = ApplicationFactory::getInstance();
     $propertyHierarchyLookup = new PropertyHierarchyLookup($applicationFactory->getStore(), $applicationFactory->newCacheFactory()->newFixedInMemoryCache(500));
     $propertyHierarchyLookup->setSubcategoryDepth($applicationFactory->getSettings()->get('smwgQSubcategoryDepth'));
     $propertyHierarchyLookup->setSubpropertyDepth($applicationFactory->getSettings()->get('smwgQSubpropertyDepth'));
     /**
      * Hook: ParserAfterTidy to add some final processing to the fully-rendered page output
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy
      */
     $this->handlers['ParserAfterTidy'] = function (&$parser, &$text) {
         $parserAfterTidy = new ParserAfterTidy($parser, $text);
         return $parserAfterTidy->process();
     };
     /**
      * Hook: Called by BaseTemplate when building the toolbox array and
      * returning it for the skin to output.
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/BaseTemplateToolbox
      */
     $this->handlers['BaseTemplateToolbox'] = function ($skinTemplate, &$toolbox) {
         $baseTemplateToolbox = new BaseTemplateToolbox($skinTemplate, $toolbox);
         return $baseTemplateToolbox->process();
     };
     /**
      * Hook: Allows extensions to add text after the page content and article
      * metadata.
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinAfterContent
      */
     $this->handlers['SkinAfterContent'] = function (&$data, $skin = null) {
         $skinAfterContent = new SkinAfterContent($data, $skin);
         return $skinAfterContent->process();
     };
     /**
      * Hook: Called after parse, before the HTML is added to the output
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageParserOutput
      */
     $this->handlers['OutputPageParserOutput'] = function (&$outputPage, $parserOutput) {
         $outputPageParserOutput = new OutputPageParserOutput($outputPage, $parserOutput);
         return $outputPageParserOutput->process();
     };
     /**
      * Hook: Add changes to the output page, e.g. adding of CSS or JavaScript
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
      */
     $this->handlers['BeforePageDisplay'] = function (&$outputPage, &$skin) {
         $beforePageDisplay = new BeforePageDisplay($outputPage, $skin);
         return $beforePageDisplay->process();
     };
     /**
      * Hook: InternalParseBeforeLinks is used to process the expanded wiki
      * code after <nowiki>, HTML-comments, and templates have been treated.
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/InternalParseBeforeLinks
      */
     $this->handlers['InternalParseBeforeLinks'] = function (&$parser, &$text) {
         $internalParseBeforeLinks = new InternalParseBeforeLinks($parser, $text);
         return $internalParseBeforeLinks->process();
     };
     /**
      * Hook: NewRevisionFromEditComplete called when a revision was inserted
      * due to an edit
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/NewRevisionFromEditComplete
      */
     $this->handlers['NewRevisionFromEditComplete'] = function ($wikiPage, $revision, $baseId, $user) {
         $newRevisionFromEditComplete = new NewRevisionFromEditComplete($wikiPage, $revision, $baseId, $user);
         return $newRevisionFromEditComplete->process();
     };
     /**
      * Hook: TitleMoveComplete occurs whenever a request to move an article
      * is completed
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete
      */
     $this->handlers['TitleMoveComplete'] = function (&$oldTitle, &$newTitle, &$user, $oldId, $newId) {
         $titleMoveComplete = new TitleMoveComplete($oldTitle, $newTitle, $user, $oldId, $newId);
         return $titleMoveComplete->process();
     };
     /**
      * Hook: ArticlePurge executes before running "&action=purge"
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticlePurge
      */
     $this->handlers['ArticlePurge'] = function (&$wikiPage) {
         $articlePurge = new ArticlePurge();
         return $articlePurge->process($wikiPage);
     };
     /**
      * Hook: ArticleDelete occurs whenever the software receives a request
      * to delete an article
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDelete
      */
     $this->handlers['ArticleDelete'] = function (&$wikiPage, &$user, &$reason, &$error) {
         $articleDelete = new ArticleDelete($wikiPage, $user, $reason, $error);
         return $articleDelete->process();
     };
     /**
      * Hook: LinksUpdateConstructed called at the end of LinksUpdate() construction
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateConstructed
      */
     $this->handlers['LinksUpdateConstructed'] = function ($linksUpdate) {
         $linksUpdateConstructed = new LinksUpdateConstructed($linksUpdate);
         return $linksUpdateConstructed->process();
     };
     /**
      * Hook: Add extra statistic at the end of Special:Statistics
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialStatsAddExtra
      */
     $this->handlers['SpecialStatsAddExtra'] = function (&$extraStats) use($globalVars) {
         $specialStatsAddExtra = new SpecialStatsAddExtra($extraStats, $globalVars['wgVersion'], $globalVars['wgLang']);
         return $specialStatsAddExtra->process();
     };
     /**
      * Hook: For extensions adding their own namespaces or altering the defaults
      *
      * @Bug 34383
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/CanonicalNamespaces
      */
     $this->handlers['CanonicalNamespaces'] = function (&$list) {
         $list = $list + NamespaceManager::getCanonicalNames();
         return true;
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/FileUpload
      *
      * @since 1.9.1
      */
     $this->handlers['FileUpload'] = function ($file, $reupload) {
         $fileUpload = new FileUpload($file, $reupload);
         return $fileUpload->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
      */
     $this->handlers['ResourceLoaderGetConfigVars'] = function (&$vars) {
         $resourceLoaderGetConfigVars = new ResourceLoaderGetConfigVars($vars);
         return $resourceLoaderGetConfigVars->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
      */
     $this->handlers['GetPreferences'] = function ($user, &$preferences) {
         $getPreferences = new GetPreferences($user, $preferences);
         return $getPreferences->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation
      */
     $this->handlers['SkinTemplateNavigation'] = function (&$skinTemplate, &$links) {
         $skinTemplateNavigation = new SkinTemplateNavigation($skinTemplate, $links);
         return $skinTemplateNavigation->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates
      */
     $this->handlers['LoadExtensionSchemaUpdates'] = function ($databaseUpdater) {
         $extensionSchemaUpdates = new ExtensionSchemaUpdates($databaseUpdater);
         return $extensionSchemaUpdates->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
      */
     $this->handlers['ResourceLoaderTestModules'] = function (&$testModules, &$resourceLoader) use($basePath, $globalVars) {
         $resourceLoaderTestModules = new ResourceLoaderTestModules($resourceLoader, $testModules, $basePath, $globalVars['IP']);
         return $resourceLoaderTestModules->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ExtensionTypes
      */
     $this->handlers['ExtensionTypes'] = function (&$extTypes) {
         $extensionTypes = new ExtensionTypes($extTypes);
         return $extensionTypes->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleIsAlwaysKnown
      */
     $this->handlers['TitleIsAlwaysKnown'] = function ($title, &$result) {
         $titleIsAlwaysKnown = new TitleIsAlwaysKnown($title, $result);
         return $titleIsAlwaysKnown->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeDisplayNoArticleText
      */
     $this->handlers['BeforeDisplayNoArticleText'] = function ($article) {
         $beforeDisplayNoArticleText = new BeforeDisplayNoArticleText($article);
         return $beforeDisplayNoArticleText->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleFromTitle
      */
     $this->handlers['ArticleFromTitle'] = function (&$title, &$article) {
         $articleFromTitle = new ArticleFromTitle($title, $article);
         return $articleFromTitle->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleIsMovable
      */
     $this->handlers['TitleIsMovable'] = function ($title, &$isMovable) {
         $titleIsMovable = new TitleIsMovable($title, $isMovable);
         return $titleIsMovable->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/EditPage::showEditForm:initial
      */
     $this->handlers['EditPage::showEditForm:initial'] = function ($editPage, $output = null) use($applicationFactory) {
         // 1.19 hook interface is missing the output object
         if (!$output instanceof \OutputPage) {
             $output = $GLOBALS['wgOut'];
         }
         $htmlFormRenderer = $applicationFactory->newMwCollaboratorFactory()->newHtmlFormRenderer($editPage->getTitle(), $output->getLanguage());
         $editPageForm = new EditPageForm($editPage, $htmlFormRenderer);
         return $editPageForm->process();
     };
     $this->handlers['SMW::Store::dropTables'] = function ($verbose) use($eventHandler) {
         $eventHandler->getEventDispatcher()->dispatch('blobstore.drop');
         return true;
     };
     $this->handlers['SMW::SQLStore::AfterDataUpdateComplete'] = function ($store, $semanticData, $compositePropertyTableDiffIterator) use($applicationFactory) {
         $embeddedQueryDependencyLinksStore = new EmbeddedQueryDependencyLinksStore($store);
         $embeddedQueryDependencyLinksStore->setEnabledState($applicationFactory->getSettings()->get('smwgEnabledQueryDependencyLinksStore'));
         $embeddedQueryDependencyLinksStore->pruneOutdatedTargetLinks($compositePropertyTableDiffIterator);
         $httpRequestFactory = new HttpRequestFactory();
         $deferredRequestDispatchManager = new DeferredRequestDispatchManager($httpRequestFactory->newSocketRequest());
         $deferredRequestDispatchManager->setEnabledHttpDeferredJobRequestState($applicationFactory->getSettings()->get('smwgEnabledHttpDeferredJobRequest'));
         $deferredRequestDispatchManager->dispatchJobRequestFor('SMW\\ParserCachePurgeJob', $semanticData->getSubject()->getTitle(), $embeddedQueryDependencyLinksStore->buildParserCachePurgeJobParametersFrom($compositePropertyTableDiffIterator));
         return true;
     };
     $this->handlers['SMW::Store::AfterQueryResultLookupComplete'] = function ($store, &$result) use($applicationFactory, $propertyHierarchyLookup) {
         $embeddedQueryDependencyListResolver = new EmbeddedQueryDependencyListResolver($store, $propertyHierarchyLookup);
         $embeddedQueryDependencyListResolver->setQueryResult($result);
         $embeddedQueryDependencyListResolver->setPropertyDependencyDetectionBlacklist($applicationFactory->getSettings()->get('smwgPropertyDependencyDetectionBlacklist'));
         $embeddedQueryDependencyLinksStore = new EmbeddedQueryDependencyLinksStore($store);
         $embeddedQueryDependencyLinksStore->setEnabledState($applicationFactory->getSettings()->get('smwgEnabledQueryDependencyLinksStore'));
         $embeddedQueryDependencyLinksStore->addDependencyList($embeddedQueryDependencyListResolver);
         return true;
     };
     $this->registerParserFunctionHooks($applicationFactory);
 }
Пример #13
0
 public function testCanConstructDispatchContext()
 {
     $eventDispatcher = $this->getMockBuilder('\\Onoi\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock();
     $instance = new EventHandler($eventDispatcher);
     $this->assertInstanceOf('\\Onoi\\EventDispatcher\\DispatchContext', $instance->newDispatchContext());
 }
 private function notifyDispatcher($addJob = true)
 {
     if ($addJob && !$this->hasDiff) {
         $dispatchContext = EventHandler::getInstance()->newDispatchContext();
         $dispatchContext->set('subject', $this->semanticData->getSubject());
         EventHandler::getInstance()->getEventDispatcher()->dispatch('property.specification.change', $dispatchContext);
         $this->hasDiff = true;
     }
 }
 /**
  * This method is called from the `SMW::Store::AfterQueryResultLookupComplete` hook
  * to resolve and update dependencies fetched fro an embedded query and its
  * QueryResult object.
  *
  * @since 2.3
  *
  * @param EmbeddedQueryDependencyListResolver $embeddedQueryDependencyListResolver
  */
 public function addDependencyList(EmbeddedQueryDependencyListResolver $embeddedQueryDependencyListResolver)
 {
     if (!$this->isEnabled() || $embeddedQueryDependencyListResolver->getSubject() === null) {
         return null;
     }
     $subject = $embeddedQueryDependencyListResolver->getSubject();
     $hash = $embeddedQueryDependencyListResolver->getQueryId();
     $sid = $this->getIdForSubject($subject, $hash);
     if ($this->canSuppressUpdateOnSkewFactorFor($sid, $subject)) {
         return wfDebugLog('smw', __METHOD__ . " suppressed (skewed time) for SID " . $sid . "\n");
     }
     $dependencyList = $embeddedQueryDependencyListResolver->getQueryDependencySubjectList();
     if ($dependencyList === array()) {
         return null;
     }
     if ($sid > 0) {
         return $this->updateDependencyList($sid, $dependencyList);
     }
     // SID == 0 means the storage update/process has not been finalized
     // (new object hasn't been registered) hence an event is registered to
     // update the list after the update process has been completed
     // PHP 5.3 compatibility
     $embeddedQueryResultLinksUpdater = $this;
     EventHandler::getInstance()->addCallbackListener('deferred.embedded.query.dep.update', function () use($embeddedQueryResultLinksUpdater, $dependencyList, $subject, $hash) {
         wfDebugLog('smw', __METHOD__ . ' deferred.embedded.query.dep.update for ' . $hash . "\n");
         $embeddedQueryResultLinksUpdater->updateDependencyList($embeddedQueryResultLinksUpdater->getIdForSubject($subject, $hash), $dependencyList);
     });
 }
Пример #16
0
 private function updateStore($parserData)
 {
     $eventHandler = EventHandler::getInstance();
     $dispatchContext = $eventHandler->newDispatchContext();
     $dispatchContext->set('title', $this->getTitle());
     $eventHandler->getEventDispatcher()->dispatch('factbox.cache.delete', $dispatchContext);
     $eventHandler->getEventDispatcher()->dispatch('cached.propertyvalues.prefetcher.reset', $dispatchContext);
     // TODO
     // Rebuild the factbox
     // Signal to succeeding processes that the update was
     // run from the CommandLine/JobQueue
     $this->applicationFactory->getStore()->getOptions()->set('isCommandLineMode', true);
     $this->applicationFactory->getStore()->getOptions()->set('isFromJob', true);
     $parserData->disableBackgroundUpdateJobs();
     $parserData->updateStore();
     return true;
 }
Пример #17
0
 private function getListOfFunctionHookDefinitions()
 {
     $functionHookDefinition = array();
     $globalVars = $this->globalVars;
     $basePath = $this->directory;
     $eventHandler = EventHandler::getInstance();
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
      */
     $listOfParserFunctions = $this->getListOfParserFunctionDefinitions();
     $functionHookDefinition['ParserFirstCallInit'] = function (Parser &$parser) use($listOfParserFunctions) {
         foreach ($listOfParserFunctions as $parserFunctionName => $parserDefinition) {
             $parserflag = $parserFunctionName === 'declare' ? SFH_OBJECT_ARGS : 0;
             $parser->setFunctionHook($parserFunctionName, $parserDefinition, $parserflag);
         }
         return true;
     };
     /**
      * Hook: ParserAfterTidy to add some final processing to the fully-rendered page output
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserAfterTidy
      */
     $functionHookDefinition['ParserAfterTidy'] = function (&$parser, &$text) {
         $parserAfterTidy = new ParserAfterTidy($parser, $text);
         return $parserAfterTidy->process();
     };
     /**
      * Hook: Called by BaseTemplate when building the toolbox array and
      * returning it for the skin to output.
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/BaseTemplateToolbox
      */
     $functionHookDefinition['BaseTemplateToolbox'] = function ($skinTemplate, &$toolbox) {
         $baseTemplateToolbox = new BaseTemplateToolbox($skinTemplate, $toolbox);
         return $baseTemplateToolbox->process();
     };
     /**
      * Hook: Allows extensions to add text after the page content and article
      * metadata.
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinAfterContent
      */
     $functionHookDefinition['SkinAfterContent'] = function (&$data, $skin = null) {
         $skinAfterContent = new SkinAfterContent($data, $skin);
         return $skinAfterContent->process();
     };
     /**
      * Hook: Called after parse, before the HTML is added to the output
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageParserOutput
      */
     $functionHookDefinition['OutputPageParserOutput'] = function (&$outputPage, $parserOutput) {
         $outputPageParserOutput = new OutputPageParserOutput($outputPage, $parserOutput);
         return $outputPageParserOutput->process();
     };
     /**
      * Hook: Add changes to the output page, e.g. adding of CSS or JavaScript
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
      */
     $functionHookDefinition['BeforePageDisplay'] = function (&$outputPage, &$skin) {
         $beforePageDisplay = new BeforePageDisplay($outputPage, $skin);
         return $beforePageDisplay->process();
     };
     /**
      * Hook: InternalParseBeforeLinks is used to process the expanded wiki
      * code after <nowiki>, HTML-comments, and templates have been treated.
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/InternalParseBeforeLinks
      */
     $functionHookDefinition['InternalParseBeforeLinks'] = function (&$parser, &$text) {
         $internalParseBeforeLinks = new InternalParseBeforeLinks($parser, $text);
         return $internalParseBeforeLinks->process();
     };
     /**
      * Hook: NewRevisionFromEditComplete called when a revision was inserted
      * due to an edit
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/NewRevisionFromEditComplete
      */
     $functionHookDefinition['NewRevisionFromEditComplete'] = function ($wikiPage, $revision, $baseId, $user) {
         $newRevisionFromEditComplete = new NewRevisionFromEditComplete($wikiPage, $revision, $baseId, $user);
         return $newRevisionFromEditComplete->process();
     };
     /**
      * Hook: TitleMoveComplete occurs whenever a request to move an article
      * is completed
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete
      */
     $functionHookDefinition['TitleMoveComplete'] = function (&$oldTitle, &$newTitle, &$user, $oldId, $newId) {
         $titleMoveComplete = new TitleMoveComplete($oldTitle, $newTitle, $user, $oldId, $newId);
         return $titleMoveComplete->process();
     };
     /**
      * Hook: ArticlePurge executes before running "&action=purge"
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticlePurge
      */
     $functionHookDefinition['ArticlePurge'] = function (&$wikiPage) {
         $articlePurge = new ArticlePurge();
         return $articlePurge->process($wikiPage);
     };
     /**
      * Hook: ArticleDelete occurs whenever the software receives a request
      * to delete an article
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDelete
      */
     $functionHookDefinition['ArticleDelete'] = function (&$wikiPage, &$user, &$reason, &$error) {
         $articleDelete = new ArticleDelete($wikiPage, $user, $reason, $error);
         return $articleDelete->process();
     };
     /**
      * Hook: LinksUpdateConstructed called at the end of LinksUpdate() construction
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateConstructed
      */
     $functionHookDefinition['LinksUpdateConstructed'] = function ($linksUpdate) {
         $linksUpdateConstructed = new LinksUpdateConstructed($linksUpdate);
         return $linksUpdateConstructed->process();
     };
     /**
      * Hook: Add extra statistic at the end of Special:Statistics
      *
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/SpecialStatsAddExtra
      */
     $functionHookDefinition['SpecialStatsAddExtra'] = function (&$extraStats) use($globalVars) {
         $specialStatsAddExtra = new SpecialStatsAddExtra($extraStats, $globalVars['wgVersion'], $globalVars['wgLang']);
         return $specialStatsAddExtra->process();
     };
     /**
      * Hook: For extensions adding their own namespaces or altering the defaults
      *
      * @Bug 34383
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/CanonicalNamespaces
      */
     $functionHookDefinition['CanonicalNamespaces'] = function (&$list) {
         $list = $list + NamespaceManager::getCanonicalNames();
         return true;
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/FileUpload
      *
      * @since 1.9.1
      */
     $functionHookDefinition['FileUpload'] = function ($file, $reupload) {
         $fileUpload = new FileUpload($file, $reupload);
         return $fileUpload->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
      */
     $functionHookDefinition['ResourceLoaderGetConfigVars'] = function (&$vars) {
         $resourceLoaderGetConfigVars = new ResourceLoaderGetConfigVars($vars);
         return $resourceLoaderGetConfigVars->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
      */
     $functionHookDefinition['GetPreferences'] = function ($user, &$preferences) {
         $getPreferences = new GetPreferences($user, $preferences);
         return $getPreferences->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation
      */
     $functionHookDefinition['SkinTemplateNavigation'] = function (&$skinTemplate, &$links) {
         $skinTemplateNavigation = new SkinTemplateNavigation($skinTemplate, $links);
         return $skinTemplateNavigation->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates
      */
     $functionHookDefinition['LoadExtensionSchemaUpdates'] = function ($databaseUpdater) {
         $extensionSchemaUpdates = new ExtensionSchemaUpdates($databaseUpdater);
         return $extensionSchemaUpdates->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
      */
     $functionHookDefinition['ResourceLoaderTestModules'] = function (&$testModules, &$resourceLoader) use($basePath, $globalVars) {
         $installPath = $globalVars['IP'];
         $resourceLoaderTestModules = new ResourceLoaderTestModules($resourceLoader, $testModules, $basePath, $installPath);
         return $resourceLoaderTestModules->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ExtensionTypes
      */
     $functionHookDefinition['ExtensionTypes'] = function (&$extTypes) {
         $extensionTypes = new ExtensionTypes($extTypes);
         return $extensionTypes->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleIsAlwaysKnown
      */
     $functionHookDefinition['TitleIsAlwaysKnown'] = function ($title, &$result) {
         $titleIsAlwaysKnown = new TitleIsAlwaysKnown($title, $result);
         return $titleIsAlwaysKnown->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeDisplayNoArticleText
      */
     $functionHookDefinition['BeforeDisplayNoArticleText'] = function ($article) {
         $beforeDisplayNoArticleText = new BeforeDisplayNoArticleText($article);
         return $beforeDisplayNoArticleText->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/ArticleFromTitle
      */
     $functionHookDefinition['ArticleFromTitle'] = function (&$title, &$article) {
         $articleFromTitle = new ArticleFromTitle($title, $article);
         return $articleFromTitle->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/TitleIsMovable
      */
     $functionHookDefinition['TitleIsMovable'] = function ($title, &$isMovable) {
         $titleIsMovable = new TitleIsMovable($title, $isMovable);
         return $titleIsMovable->process();
     };
     /**
      * @see https://www.mediawiki.org/wiki/Manual:Hooks/EditPage::showEditForm:initial
      */
     $functionHookDefinition['EditPage::showEditForm:initial'] = function ($editPage, $output) {
         $mwCollaboratorFactory = ApplicationFactory::getInstance()->newMwCollaboratorFactory();
         $htmlFormRenderer = $mwCollaboratorFactory->newHtmlFormRenderer($editPage->getTitle(), $output->getLanguage());
         $editPageForm = new EditPageForm($editPage, $htmlFormRenderer);
         return $editPageForm->process();
     };
     $functionHookDefinition['SMW::Store::dropTables'] = function ($verbose) use($eventHandler) {
         $eventHandler->getEventDispatcher()->dispatch('blobstore.drop');
         return true;
     };
     return $functionHookDefinition;
 }
Пример #18
0
 /**
  * Update the semantic data stored for some individual. The data is
  * given as a SemanticData object, which contains all semantic data
  * for one particular subject.
  *
  * @param SemanticData $semanticData
  */
 public function updateData(SemanticData $semanticData)
 {
     if (!ApplicationFactory::getInstance()->getSettings()->get('smwgSemanticsEnabled')) {
         return;
     }
     $subject = $semanticData->getSubject();
     $dispatchContext = EventHandler::getInstance()->newDispatchContext();
     $dispatchContext->set('subject', $subject);
     EventHandler::getInstance()->getEventDispatcher()->dispatch('on.before.semanticdata.update.complete', $dispatchContext);
     /**
      * @since 1.6
      */
     \Hooks::run('SMWStore::updateDataBefore', array($this, $semanticData));
     $this->doDataUpdate($semanticData);
     /**
      * @since 1.6
      */
     \Hooks::run('SMWStore::updateDataAfter', array($this, $semanticData));
     EventHandler::getInstance()->getEventDispatcher()->dispatch('on.after.semanticdata.update.complete', $dispatchContext);
 }