/**
  * @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 testAddAnnotationOnMockShortUrl()
 {
     $title = Title::newFromText(__METHOD__);
     $semanticData = new SemanticData(DIWikiPage::newFromTitle($title));
     $instance = $this->getMock('\\SESP\\Annotator\\ShortUrlAnnotator', array('hasShortUrlUtils', 'getShortUrl'), array($semanticData));
     $instance->expects($this->once())->method('hasShortUrlUtils')->will($this->returnValue(true));
     $instance->expects($this->once())->method('getShortUrl')->with($this->equalTo($title))->will($this->returnValue('example.org'));
     $instance->setShortUrlPrefix('foo');
     $instance->addAnnotation();
     $this->assertArrayHasKey(PropertyRegistry::getInstance()->getPropertyId('_SHORTURL'), $semanticData->getProperties());
 }
 private function registerCallbackHandlers($configuration)
 {
     $propertyRegistry = PropertyRegistry::getInstance();
     $this->handlers['smwInitProperties'] = function () use($propertyRegistry) {
         return $propertyRegistry->registerPropertiesAndAliases();
     };
     $this->handlers['SMW::SQLStore::updatePropertyTableDefinitions'] = function (&$propertyTableDefinitions) use($propertyRegistry, $configuration) {
         return $propertyRegistry->registerAsFixedTables($propertyTableDefinitions, $configuration);
     };
     $this->handlers['SMWStore::updateDataBefore'] = function ($store, $semanticData) use($configuration) {
         $appFactory = new AppFactory($configuration['wgShortUrlPrefix']);
         $propertyAnnotator = new ExtraPropertyAnnotator($semanticData, $appFactory, $configuration);
         return $propertyAnnotator->addAnnotation();
     };
 }
 public function testPropertyAnnotation_USERREG()
 {
     $title = Title::newFromText('Foo', NS_USER);
     $page = $this->getMockBuilder('WikiPage')->disableOriginalConstructor()->getMock();
     $page->expects($this->atLeastOnce())->method('getTitle')->will($this->returnValue($title));
     $this->appFactory->expects($this->once())->method('newWikiPage')->will($this->returnValue($page));
     $user = $this->getMockBuilder('\\User')->disableOriginalConstructor()->getMock();
     $this->appFactory->expects($this->once())->method('newUserFromTitle')->will($this->returnValue($user));
     $propertyId = PropertyRegistry::getInstance()->getPropertyId('_USERREG');
     $property = new DIProperty($propertyId);
     $instance = $this->newExtraPropertyAnnotatorInstanceFor('_USERREG');
     $semanticData = $instance->getSemanticData();
     $this->assertEmpty($semanticData->getProperties());
     $this->assertTrue($instance->addAnnotation());
     $this->assertArrayHasKey($propertyId, $semanticData->getProperties());
     foreach ($semanticData->getPropertyValues($property) as $value) {
         $this->assertInstanceOf('SMWDITime', $value);
     }
 }
 public function testPropertyAnnotationWithNumberValue()
 {
     $semanticData = $this->getSemanticDataForExifDataAnnotatorBy(array('Foo' => 'ABC'), array('getWidth' => 1000, 'getHeight' => 9999));
     $this->assertArrayHasKey(PropertyRegistry::getInstance()->getPropertyId('ImageWidth'), $semanticData->findSubSemanticData('_EXIFDATA')->getProperties());
     $this->assertArrayHasKey(PropertyRegistry::getInstance()->getPropertyId('ImageLength'), $semanticData->findSubSemanticData('_EXIFDATA')->getProperties());
 }
 private function addPropertyValuesForMIMEAndMediaType()
 {
     if ($this->isFilePage()) {
         $file = $this->getWikiPage()->getFile();
         $mimetype = $file->getMimeType();
         $mediaType = \MimeMagic::singleton()->findMediaType($mimetype);
         list($mimetypemajor, $mimetypeminor) = $file->splitMime($mimetype);
         $this->getSemanticData()->addPropertyObjectValue(new DIProperty(PropertyRegistry::getInstance()->getPropertyId('_MIMETYPE')), new DIBlob($mimetypeminor));
         $this->getSemanticData()->addPropertyObjectValue(new DIProperty(PropertyRegistry::getInstance()->getPropertyId('_MEDIATYPE')), new DIBlob($mediaType));
     }
 }
 protected function addPropertyValuesFromExifData($rawExif)
 {
     $formattedExif = FormatMetadata::getFormattedData($rawExif);
     foreach ($formattedExif as $key => $value) {
         $dataItem = null;
         $propertyId = PropertyRegistry::getInstance()->getPropertyId($key);
         if ($propertyId === null) {
             continue;
         }
         $dataItemType = PropertyRegistry::getInstance()->getPropertyType($key);
         switch ($dataItemType) {
             case DataItem::TYPE_NUMBER:
                 $dataItem = is_numeric($rawExif[$key]) ? new DINumber($rawExif[$key]) : null;
                 break;
             case DataItem::TYPE_BLOB:
                 $dataItem = new DIBlob($value);
                 break;
             case DataItem::TYPE_TIME:
                 $dataItem = $this->makeDataItemTime($rawExif[$key]);
         }
         if ($dataItem !== null) {
             $this->subobject->getSemanticData()->addPropertyObjectValue(new DIProperty($propertyId), $dataItem);
         }
     }
 }
 protected function registerPropertyIdWithDefinition($id, $propertydefinition)
 {
     $instance = PropertyRegistry::getInstance();
     $reflector = new ReflectionClass('\\SESP\\PropertyRegistry');
     $definitions = $reflector->getProperty('definitions');
     $definitions->setAccessible(true);
     $definitions->setValue($instance, $propertydefinition);
     $this->assertTrue($instance->registerPropertiesAndAliases());
     $propertyId = $instance->getPropertyId($id);
     $instance->clear();
     return $propertyId;
 }