/** * @since 1.0 * * @return WikiPage */ public function getWikiPage() { if ($this->page === null) { $this->page = $this->appFactory->newWikiPage($this->semanticData->getSubject()->getTitle()); //$this->loadRegisteredObject( 'WikiPage' ); } return $this->page; }
/** * @since 1.0 * * @return boolean */ public function addAnnotation() { if (!$this->hasShortUrlUtils()) { throw new RuntimeException('Expected class ShortUrlUtils to be available'); } $shortURL = $this->getShortUrl($this->semanticData->getSubject()->getTitle()); if ($shortURL !== null) { $this->semanticData->addPropertyObjectValue(new DIProperty(PropertyRegistry::getInstance()->getPropertyId('_SHORTURL')), new DIUri('http', $shortURL, '', '')); } return true; }
public function testGetPropertyValues() { $instance = new SemanticData(DIWikiPage::newFromTitle(Title::newFromText(__METHOD__))); $this->assertInstanceOf('SMW\\DIWikiPage', $instance->getSubject()); $this->assertEmpty($instance->getPropertyValues(new DIProperty('Foo', true))); $this->assertEmpty($instance->getPropertyValues(new DIProperty('Foo'))); }
/** * @see SMWStore::deleteSubject * * @since 1.8 * @param Title $title */ public function deleteSubject(Title $title) { // @deprecated since 2.1, use 'SMW::SQLStore::BeforeDeleteSubjectComplete' wfRunHooks('SMWSQLStore3::deleteSubjectBefore', array($this->store, $title)); wfRunHooks('SMW::SQLStore::BeforeDeleteSubjectComplete', array($this->store, $title)); $id = $this->store->getObjectIds()->getSMWPageID($title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), '', false); $emptySemanticData = new SemanticData(DIWikiPage::newFromTitle($title)); $subobjects = $this->getSubobjects($emptySemanticData->getSubject()); $this->doDataUpdate($emptySemanticData); if ($title->getNamespace() === SMW_NS_CONCEPT) { // make sure to clear caches $db = $this->store->getConnection(); $db->delete('smw_fpt_conc', array('s_id' => $id), 'SMW::deleteSubject::Conc'); $db->delete(SMWSQLStore3::CONCEPT_CACHE_TABLE, array('o_id' => $id), 'SMW::deleteSubject::Conccache'); } // Mark subject/subobjects with a special IW, the final removal is being // triggered by the `ByIdDataRebuildDispatcher` $this->store->getObjectIds()->updateInterwikiField($id, $emptySemanticData->getSubject(), SMW_SQL3_SMWDELETEIW); foreach ($subobjects as $smw_id => $subobject) { $this->store->getObjectIds()->updateInterwikiField($smw_id, $subobject, SMW_SQL3_SMWDELETEIW); } // 1.9.0.1 // The update of possible associative entities is handled by DeleteSubjectJob which is invoked during // the ArticleDelete hook // @deprecated since 2.1, use 'SMW::SQLStore::AfterDeleteSubjectComplete' wfRunHooks('SMWSQLStore3::deleteSubjectAfter', array($this->store, $title)); wfRunHooks('SMW::SQLStore::AfterDeleteSubjectComplete', array($this->store, $title)); }
public function testGetHash() { $instance = new SemanticData(DIWikiPage::newFromText(__METHOD__)); $instance->addDataValue(DataValueFactory::getInstance()->newDataValueByText('Has fooQuex', 'Bar')); $subobject = $this->newSubobject($instance->getSubject()->getTitle()); $instance->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer()); $this->assertInternalType('string', $instance->getHash()); }
private function doSerialize(SemanticData $semanticData) { $data = array('subject' => $semanticData->getSubject()->getSerialization(), 'data' => $this->serializeProperty($semanticData)); $subobjects = $this->serializeSubobject($semanticData->getSubSemanticData()); if ($subobjects !== array()) { $data['sobj'] = $subobjects; } return $data; }
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; } }
private function doRealUpdate() { $this->store->setUpdateJobsEnabledState($this->updateJobsEnabledState); if ($this->processSemantics) { $this->store->updateData($this->semanticData); } else { $this->store->clearData($this->semanticData->getSubject()); } return true; }
public function testDoSparqlDataUpdateOnMockBaseStore() { $semanticData = new SemanticData(new DIWikiPage(__METHOD__, NS_MAIN)); $semanticData->addPropertyObjectValue(new DIProperty('Foo'), $semanticData->getSubject()); $repositoryResult = $this->getMockBuilder('\\SMW\\SPARQLStore\\QueryEngine\\RepositoryResult')->disableOriginalConstructor()->getMock(); $baseStore = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $sparqlDatabase = $this->getMockBuilder('\\SMWSparqlDatabase')->disableOriginalConstructor()->getMock(); $sparqlDatabase->expects($this->atLeastOnce())->method('select')->will($this->returnValue($repositoryResult)); $sparqlDatabase->expects($this->once())->method('insertData'); $connectionManager = $this->getMockBuilder('\\SMW\\ConnectionManager')->disableOriginalConstructor()->getMock(); $connectionManager->expects($this->any())->method('getConnection')->will($this->returnValue($sparqlDatabase)); $instance = new SPARQLStore($baseStore); $instance->setConnectionManager($connectionManager); $instance->doSparqlDataUpdate($semanticData); }
/** * @since 2.4 * * @param SemanticData $semanticData * * @return string */ public static function createFromSemanticData(SemanticData $semanticData) { $hash = array(); $hash[] = $semanticData->getSubject()->getSerialization(); foreach ($semanticData->getProperties() as $property) { $hash[] = $property->getKey(); foreach ($semanticData->getPropertyValues($property) as $di) { $hash[] = $di->getSerialization(); } } foreach ($semanticData->getSubSemanticData() as $data) { $hash[] = $data->getHash(); } sort($hash); return md5(implode('#', $hash)); }
/** * @see SMWStore::deleteSubject * * @since 1.8 * @param Title $title */ public function deleteSubject(Title $title) { // @deprecated since 2.1, use 'SMW::SQLStore::BeforeDeleteSubjectComplete' \Hooks::run('SMWSQLStore3::deleteSubjectBefore', array($this->store, $title)); \Hooks::run('SMW::SQLStore::BeforeDeleteSubjectComplete', array($this->store, $title)); // Fetch all possible matches (including any duplicates created by // incomplete rollback or DB deadlock) $ids = $this->store->getObjectIds()->getListOfIdMatchesFor($title->getDBkey(), $title->getNamespace(), $title->getInterwiki()); $subject = DIWikiPage::newFromTitle($title); $emptySemanticData = new SemanticData($subject); $this->entitySubobjectListIterator->setSubject($emptySemanticData->getSubject()); $subobjects = $this->entitySubobjectListIterator->getIterator(); $this->doDataUpdate($emptySemanticData); foreach ($ids as $id) { $this->doDelete($id, $subject, $subobjects); } // @deprecated since 2.1, use 'SMW::SQLStore::AfterDeleteSubjectComplete' \Hooks::run('SMWSQLStore3::deleteSubjectAfter', array($this->store, $title)); \Hooks::run('SMW::SQLStore::AfterDeleteSubjectComplete', array($this->store, $title)); }
/** * @see SMWStore::deleteSubject * * @since 1.8 * @param Title $title */ public function deleteSubject(Title $title) { // @deprecated since 2.1, use 'SMW::SQLStore::BeforeDeleteSubjectComplete' \Hooks::run('SMWSQLStore3::deleteSubjectBefore', array($this->store, $title)); \Hooks::run('SMW::SQLStore::BeforeDeleteSubjectComplete', array($this->store, $title)); // Fetch all possible matches (including any duplicates created by // incomplete rollback or DB deadlock) $ids = $this->store->getObjectIds()->getListOfIdMatchesFor($title->getDBkey(), $title->getNamespace(), $title->getInterwiki()); $subject = DIWikiPage::newFromTitle($title); $emptySemanticData = new SemanticData($subject); $subobjects = $this->getSubobjects($emptySemanticData->getSubject()); $this->doDataUpdate($emptySemanticData); foreach ($ids as $id) { $this->doDeleteReferencesFor($id, $subject, $subobjects); } // 1.9.0.1 // The update of possible associative entities is handled by DeleteSubjectJob which is invoked during // the ArticleDelete hook // @deprecated since 2.1, use 'SMW::SQLStore::AfterDeleteSubjectComplete' \Hooks::run('SMWSQLStore3::deleteSubjectAfter', array($this->store, $title)); \Hooks::run('SMW::SQLStore::AfterDeleteSubjectComplete', array($this->store, $title)); }
/** * Create an array of rows to insert into property tables in order to * store the given SMWSemanticData. The given $sid (subject page id) is * used directly and must belong to the subject of the data container. * Sortkeys are ignored since they are not stored in a property table * but in the ID table. * * The returned array uses property table names as keys and arrays of * table rows as values. Each table row is an array mapping column * names to values. * * @note Property tables that do not use ids as subjects are ignored. * This just excludes redirects that are handled differently anyway; * it would not make a difference to include them here. * * @since 1.8 * * @param integer $sid * @param SemanticData $semanticData * * @return array */ private function mapToInsertValueFormat($sid, SemanticData $semanticData) { $updates = array(); $subject = $semanticData->getSubject(); $propertyTables = $this->store->getPropertyTables(); foreach ($semanticData->getProperties() as $property) { $tableId = $this->store->findPropertyTableID($property); // not stored in a property table, e.g., sortkeys if ($tableId === null) { continue; } // "Notice: Undefined index" if (!isset($propertyTables[$tableId])) { throw new RuntimeException("Unable to find a property table for " . $property->getKey()); } $propertyTable = $propertyTables[$tableId]; // not using subject ids, e.g., redirects if (!$propertyTable->usesIdSubject()) { continue; } $insertValues = array('s_id' => $sid); if (!$propertyTable->isFixedPropertyTable()) { $insertValues['p_id'] = $this->store->getObjectIds()->makeSMWPropertyID($property); } foreach ($semanticData->getPropertyValues($property) as $dataItem) { if ($dataItem instanceof DIError) { // ignore error values continue; } if (!array_key_exists($propertyTable->getName(), $updates)) { $updates[$propertyTable->getName()] = array(); } $dataItemValues = $this->store->getDataItemHandlerForDIType($dataItem->getDIType())->getInsertValues($dataItem); // Ensure that the sortkey is a string if (isset($dataItemValues['o_sortkey'])) { $dataItemValues['o_sortkey'] = (string) $dataItemValues['o_sortkey']; } // Make sure to build a unique set without duplicates which could happen // if an annotation is made to a property that has a redirect pointing // to the same p_id $insertValues = array_merge($insertValues, $dataItemValues); $insertValuesHash = md5(implode('#', $insertValues)); $updates[$propertyTable->getName()][$insertValuesHash] = $insertValues; } } // Special handling of Concepts if ($subject->getNamespace() === SMW_NS_CONCEPT && $subject->getSubobjectName() == '') { $this->fetchConceptTableInserts($sid, $updates); } return $updates; }
/** * Remove data about a subobject. * If the removed data is not about a subobject of this object, * it will silently be ignored (nothing to remove). Likewise, * removing data that is not present does not change anything. * * @since 1.8 * @param SMWSemanticData */ public function removeSubSemanticData(SemanticData $semanticData) { if ($semanticData->getSubject()->getDBkey() !== $this->getSubject()->getDBkey()) { return; } $subobjectName = $semanticData->getSubject()->getSubobjectName(); if ($this->hasSubSemanticData($subobjectName)) { $this->subSemanticData[$subobjectName]->removeDataFrom($semanticData); if ($this->subSemanticData[$subobjectName]->isEmpty()) { unset($this->subSemanticData[$subobjectName]); } } }
/** * 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) { /** * @since 1.6 */ wfRunHooks('SMWStore::updateDataBefore', array($this, $semanticData)); // Invalidate the page, so data stored on it gets displayed immediately in queries. $pageUpdater = ApplicationFactory::getInstance()->newMwCollaboratorFactory()->newPageUpdater(); if ($GLOBALS['smwgAutoRefreshSubject'] && $pageUpdater->canUpdate()) { $pageUpdater->addPage($semanticData->getSubject()->getTitle()); $pageUpdater->doPurgeParserCache(); $pageUpdater->doPurgeHtmlCache(); } $this->doDataUpdate($semanticData); /** * @since 1.6 */ wfRunHooks('SMWStore::updateDataAfter', array($this, $semanticData)); }
protected function doDataUpdate(SemanticData $semanticData) { $this->getEntityLookup()->resetCacheBy($semanticData->getSubject()); $this->getWriter()->doDataUpdate($semanticData); $this->doDeferredCachedListLookupUpdate($semanticData->getSubject()); }
/** * Update the Sparql back-end, without taking any subobject data into account. * * @param SemanticData $semanticData */ private function doSparqlFlatDataUpdate(SemanticData $semanticData) { $turtleTriplesBuilder = new TurtleTriplesBuilder($semanticData, new RedirectLookup($this->getConnection())); $turtleTriplesBuilder->setTriplesChunkSize(80); if (!$turtleTriplesBuilder->hasTriplesForUpdate()) { return; } if ($semanticData->getSubject()->getSubobjectName() === '') { $this->doSparqlDataDelete($semanticData->getSubject()); } foreach ($turtleTriplesBuilder->getChunkedTriples() as $chunkedTriples) { $this->getConnection()->insertData($chunkedTriples, $turtleTriplesBuilder->getPrefixes()); } }
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; }
/** * Returns a formatted factbox table * * @since 1.9 * * @param SMWSemanticData $semanticData * * @return string|null */ protected function createTable(SemanticData $semanticData) { Profiler::In(__METHOD__); $this->tableBuilder = $this->applicationFactory->newMwCollaboratorFactory()->newHtmlTableBuilder(); $text = ''; // Hook deprecated with SMW 1.9 and will vanish with SMW 1.11 wfRunHooks('smwShowFactbox', array(&$text, $semanticData)); // Hook since 1.9 if (wfRunHooks('SMW::Factbox::BeforeContentGeneration', array(&$text, $semanticData))) { $this->getTableHeader($semanticData->getSubject()); $this->getTableContent($semanticData); $text .= Html::rawElement('div', array('class' => 'smwfact'), $this->tableBuilder->getHeaderItems() . $this->tableBuilder->getHtml(array('class' => 'smwfacttable'))); } Profiler::Out(__METHOD__); return $text; }
/** * 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); }
protected function doDataUpdate(SemanticData $semanticData) { $this->cachedValueLookupStore->deleteFor($semanticData->getSubject()); $this->getWriter()->doDataUpdate($semanticData); $this->tryToInvalidateCachedListLookupEntryFor($semanticData->getSubject()); }
/** * Returns a formatted factbox table * * @since 1.9 * * @param SMWSemanticData $semanticData * * @return string|null */ protected function createTable(SemanticData $semanticData) { $this->htmlTableRenderer = $this->applicationFactory->newMwCollaboratorFactory()->newHtmlTableRenderer(); $text = ''; // Hook deprecated with SMW 1.9 and will vanish with SMW 1.11 \Hooks::run('smwShowFactbox', array(&$text, $semanticData)); // Hook since 1.9 if (\Hooks::run('SMW::Factbox::BeforeContentGeneration', array(&$text, $semanticData))) { $this->getTableHeader($semanticData->getSubject()); $this->getTableContent($semanticData); $text .= Html::rawElement('div', array('class' => 'smwfact'), $this->htmlTableRenderer->getHeaderItems() . $this->htmlTableRenderer->getHtml(array('class' => 'smwfacttable', 'cellspacing' => "0", 'cellpadding' => "2"))); } return $text; }