/**
  * @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;
 }
 /**
  * @since 2.0
  *
  * @return SemanticData
  */
 public function getSemanticData(DIWikiPage $subject)
 {
     $requestOptions = new RequestOptions();
     $requestOptions->sort = true;
     $semanticData = new SemanticData($subject);
     $incomingProperties = $this->store->getInProperties($subject, $requestOptions);
     foreach ($incomingProperties as $property) {
         $values = $this->store->getPropertySubjects($property, null);
         foreach ($values as $value) {
             $semanticData->addPropertyObjectValue($property, $value);
         }
     }
     return $semanticData;
 }
 /**
  * @since 1.9.2
  *
  * @return SemanticData
  */
 public function fetchIncomingDataFromStore()
 {
     $requestOptions = new \SMWRequestOptions();
     $requestOptions->sort = true;
     $subject = $this->getPageData()->getSubject();
     $semanticData = new SemanticData($subject);
     $incomingProperties = $this->getStore()->getInProperties($subject, $requestOptions);
     foreach ($incomingProperties as $property) {
         $values = $this->getStore()->getPropertySubjects($property, null);
         foreach ($values as $value) {
             $semanticData->addPropertyObjectValue($property, $value);
         }
     }
     return $semanticData;
 }
 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);
 }
 /**
  * Retrieve a copy of the semantic data for a wiki page, possibly filtering
  * it so that only essential properties are included (in some cases, we only
  * want to export stub information about a page).
  * We make a copy of the object since we may want to add more data later on
  * and we do not want to modify the store's result which may be used for
  * caching purposes elsewhere.
  */
 protected function getSemanticData(SMWDIWikiPage $diWikiPage, $core_props_only)
 {
     // Issue 619
     // Resolve the redirect target and return a container with information
     // about the redirect
     if ($diWikiPage->getTitle() !== null && $diWikiPage->getTitle()->isRedirect()) {
         try {
             $redirectTarget = $this->getDeepRedirectTargetResolver()->findRedirectTargetFor($diWikiPage->getTitle());
         } catch (\Exception $e) {
             $redirectTarget = null;
         }
         // Couldn't resolve the redirect which is most likely caused by a
         // circular redirect therefore we give up
         if ($redirectTarget === null) {
             return null;
         }
         $semData = new SemanticData($diWikiPage);
         $semData->addPropertyObjectValue(new DIProperty('_REDI'), DIWikiPage::newFromTitle($redirectTarget));
         return $semData;
     }
     $semdata = \SMW\StoreFactory::getStore()->getSemanticData($diWikiPage, $core_props_only ? array('__spu', '__typ', '__imp') : false);
     // advise store to retrieve only core things
     if ($core_props_only) {
         // be sure to filter all non-relevant things that may still be present in the retrieved
         $result = new SMWSemanticData($diWikiPage);
         foreach (array('_URI', '_TYPE', '_IMPO') as $propid) {
             $prop = new SMW\DIProperty($propid);
             $values = $semdata->getPropertyValues($prop);
             foreach ($values as $dv) {
                 $result->addPropertyObjectValue($prop, $dv);
             }
         }
     } else {
         $result = clone $semdata;
     }
     return $result;
 }
Example #6
0
 public function testClear()
 {
     $title = Title::newFromText(__METHOD__);
     $instance = new SemanticData(DIWikiPage::newFromTitle($title));
     $instance->addPropertyObjectValue(new DIProperty('_MDAT'), DITime::newFromTimestamp(1272508903));
     $this->assertFalse($instance->isEmpty());
     $instance->clear();
     $this->assertTrue($instance->isEmpty());
 }
 public function testDeleteFor()
 {
     $subject = new DIWikiPage('Foobar', NS_MAIN, '', 'abc');
     $semanticData = new SemanticData($subject);
     $semanticData->addPropertyObjectValue(new DIProperty('_REDI'), new DIWikiPage('Bar', NS_MAIN));
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->disableOriginalConstructor()->getMock();
     $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock();
     $container->expects($this->at(0))->method('has')->with($this->stringContains('sd:'))->will($this->returnValue(true));
     $container->expects($this->at(1))->method('get')->with($this->stringContains('sd:'))->will($this->returnValue($semanticData));
     $container->expects($this->at(2))->method('has')->with($this->stringContains('list'))->will($this->returnValue(true));
     $container->expects($this->at(3))->method('get')->with($this->stringContains('list'))->will($this->returnValue(array('abc', '123')));
     $blobStore = $this->getMockBuilder('\\Onoi\\BlobStore\\BlobStore')->disableOriginalConstructor()->getMock();
     $blobStore->expects($this->any())->method('canUse')->will($this->returnValue(true));
     $blobStore->expects($this->atLeastOnce())->method('read')->will($this->returnValue($container));
     $blobStore->expects($this->exactly(4))->method('delete');
     $instance = new CachedValueLookupStore($store, $blobStore);
     $instance->setValueLookupFeatures(SMW_VL_SD);
     $instance->deleteFor($subject);
 }
 /**
  * Creates a Semantic Data object with the incoming properties instead of the
  * usual outproperties.
  *
  * @return array(SMWSemanticData, bool)  The semantic data including all inproperties, and if there are more inproperties left
  */
 private function getInData()
 {
     $indata = new SemanticData($this->subject->getDataItem());
     $propRequestOptions = new RequestOptions();
     $propRequestOptions->sort = true;
     $propRequestOptions->limit = $this->incomingPropertiesCount;
     if ($this->offset > 0) {
         $propRequestOptions->offset = $this->offset;
     }
     $incomingProperties = $this->store->getInProperties($this->subject->getDataItem(), $propRequestOptions);
     $more = false;
     if (count($incomingProperties) == $this->incomingPropertiesCount) {
         $more = true;
         array_pop($incomingProperties);
         // drop the last one
     }
     $valRequestOptions = new RequestOptions();
     $valRequestOptions->sort = true;
     $valRequestOptions->limit = $this->incomingValuesCount;
     foreach ($incomingProperties as $property) {
         $values = $this->store->getPropertySubjects($property, $this->subject->getDataItem(), $valRequestOptions);
         foreach ($values as $value) {
             $indata->addPropertyObjectValue($property, $value);
         }
     }
     // Added in 2.3
     // Whether to show a more link or not can be set via
     // SMW::Browse::BeforeIncomingPropertyValuesFurtherLinkCreate
     \Hooks::run('SMW::Browse::AfterIncomingPropertiesLookupComplete', array($this->store, $indata, $valRequestOptions));
     return array($indata, $more);
 }
 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;
 }
 /**
  * @return array
  */
 public function typeChangeSemanticDataProvider()
 {
     $provider = array();
     $title = \Title::newFromText(__METHOD__);
     // #0 Single entry
     $foo = new SemanticData(DIWikiPage::newFromTitle($title));
     $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar'));
     $provider[] = array($foo, 'Has_fooQuex');
     // #1 Single subobject entry
     $foo = new SemanticData(DIWikiPage::newFromTitle($title));
     $subobject = new Subobject($title);
     $subobject->setSemanticData('Foo');
     $subobject->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fomQuex', 'Bam'));
     $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $provider[] = array($foo, 'Has_fomQuex');
     // #2 Combined
     $foo = new SemanticData(DIWikiPage::newFromTitle($title));
     $foo->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Has fooQuex', 'Bar'));
     $foo->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $provider[] = array($foo, 'Has_fomQuex');
     return $provider;
 }
 public function testAddSubobjectToSemanticDataForStorage()
 {
     $this->subjects[] = $subject = DIWikiPage::newFromTitle(Title::newFromText(__METHOD__));
     $semanticData = new SemanticData($subject);
     $subobject = new Subobject($subject->getTitle());
     $subobject->setEmptyContainerForId('SomeSubobject');
     $subobject->getSemanticData()->addDataValue(DataValueFactory::getInstance()->newPropertyValue('Foo', 'Bar'));
     $semanticData->addPropertyObjectValue($subobject->getProperty(), $subobject->getContainer());
     $this->getStore()->updateData($semanticData);
     $expected = array('propertyCount' => 2, 'properties' => array(new DIProperty('Foo'), new DIProperty('_SKEY')), 'propertyValues' => array('Bar', __METHOD__));
     $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $this->getStore()->getSemanticData($subject)->findSubSemanticData('SomeSubobject'));
 }
 public function testForYetUnknownRedirectTarget()
 {
     $revision = $this->getMockBuilder('\\Revision')->disableOriginalConstructor()->getMock();
     $wikiPage = $this->getMockBuilder('\\WikiPage')->disableOriginalConstructor()->getMock();
     $wikiPage->expects($this->atLeastOnce())->method('getRevision')->will($this->returnValue($revision));
     $pageCreator = $this->getMockBuilder('\\SMW\\MediaWiki\\PageCreator')->disableOriginalConstructor()->getMock();
     $pageCreator->expects($this->atLeastOnce())->method('createPage')->will($this->returnValue($wikiPage));
     $this->applicationFactory->registerObject('PageCreator', $pageCreator);
     $subject = new DIWikiPage('Foo', NS_MAIN);
     $target = new DIWikiPage('Bar', NS_MAIN);
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $store->expects($this->once())->method('changeTitle')->with($this->equalTo($subject->getTitle()), $this->equalTo($target->getTitle()), $this->anything(), $this->anything());
     $semanticData = new SemanticData($subject);
     $semanticData->addPropertyObjectValue(new DIProperty('_REDI'), $target);
     $instance = new StoreUpdater($store, $semanticData);
     $instance->setUpdateJobsEnabledState(true);
     $instance->doUpdate();
 }
 /**
  * @since 2.5
  *
  * @param SemanticData $semanticData
  * @param DIContainer|null $container
  */
 public function pushTo(SemanticData $semanticData, DIContainer $container = null)
 {
     if ($container === null) {
         return;
     }
     $semanticData->addPropertyObjectValue(new DIProperty('_ERRC'), $container);
 }
 /**
  * @since 2.5
  *
  * @param SemanticData $semanticData
  */
 public function pushAnnotationsTo(SemanticData $semanticData)
 {
     $this->addAnnotation();
     $semanticData->addPropertyObjectValue($this->profileAnnotator->getProperty(), $this->profileAnnotator->getContainer());
 }