/**
  * #1416 create container manually to avoid any issues that may arise from
  * a failed Title::makeTitleSafe.
  */
 private function newDIContainer(Query $query)
 {
     $subject = $query->getContextPage();
     if ($subject === null) {
         $containerSemanticData = ContainerSemanticData::makeAnonymousContainer();
     } else {
         $subject = new DIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $query->getQueryId());
         $containerSemanticData = new ContainerSemanticData($subject);
     }
     return new DIContainer($containerSemanticData);
 }
 protected function parseUserValue($value)
 {
     if ($value === '') {
         $this->addError(wfMessage('smw_novalues')->text());
         return;
     }
     if (is_null($this->m_contextPage)) {
         $semanticData = SMWContainerSemanticData::makeAnonymousContainer();
     } else {
         $subobjectName = '_' . hash('md4', $value, false);
         // md4 is probably fastest of PHP's hashes
         $subject = new SMWDIWikiPage($this->m_contextPage->getDBkey(), $this->m_contextPage->getNamespace(), $this->m_contextPage->getInterwiki(), $subobjectName);
         $semanticData = new SMWContainerSemanticData($subject);
     }
     $values = $this->getValuesFromString($value);
     $valueIndex = 0;
     // index in value array
     $propertyIndex = 0;
     // index in property list
     $empty = true;
     foreach ($this->getPropertyDataItems() as $diProperty) {
         if (!array_key_exists($valueIndex, $values) || $this->getErrors() !== array()) {
             break;
             // stop if there are no values left
         }
         $values[$valueIndex] = str_replace("-3B", ";", $values[$valueIndex]);
         // generating the DVs:
         if ($values[$valueIndex] === '' || $values[$valueIndex] == '?') {
             // explicit omission
             $valueIndex++;
         } else {
             $dataValue = \SMW\DataValueFactory::getInstance()->newPropertyObjectValue($diProperty, $values[$valueIndex]);
             if ($dataValue->isValid()) {
                 // valid DV: keep
                 $semanticData->addPropertyObjectValue($diProperty, $dataValue->getDataItem());
                 $valueIndex++;
                 $empty = false;
             } elseif (count($values) - $valueIndex == count($this->m_diProperties) - $propertyIndex) {
                 $semanticData->addPropertyObjectValue($diProperty, $dataValue->getDataItem());
                 $this->addError($dataValue->getErrors());
                 ++$valueIndex;
             }
         }
         ++$propertyIndex;
     }
     if ($empty && $this->getErrors() === array()) {
         $this->addError(wfMessage('smw_novalues')->text());
     }
     $this->m_dataitem = new SMWDIContainer($semanticData);
 }
 protected function parseUserValueOrQuery($value, $queryMode)
 {
     if ($value === '') {
         $this->addError(wfMessage('smw_novalues')->text());
         if ($queryMode) {
             return new SMWThingDescription();
         } else {
             return;
         }
     }
     if ($queryMode) {
         $subdescriptions = array();
     } elseif (is_null($this->m_contextPage)) {
         $semanticData = SMWContainerSemanticData::makeAnonymousContainer();
     } else {
         $subobjectName = '_' . hash('md4', $value, false);
         // md4 is probably fastest of PHP's hashes
         $subject = new SMWDIWikiPage($this->m_contextPage->getDBkey(), $this->m_contextPage->getNamespace(), $this->m_contextPage->getInterwiki(), $subobjectName);
         $semanticData = new SMWContainerSemanticData($subject);
     }
     // #664 / T17732
     $value = str_replace("\\;", "-3B", $value);
     // Bug 21926 / T23926
     // Values that use html entities are encoded with a semicolon
     $value = htmlspecialchars_decode($value, ENT_QUOTES);
     $values = preg_split('/[\\s]*;[\\s]*/u', trim($value));
     $valueIndex = 0;
     // index in value array
     $propertyIndex = 0;
     // index in property list
     $empty = true;
     foreach ($this->getPropertyDataItems() as $diProperty) {
         if (!array_key_exists($valueIndex, $values)) {
             break;
             // stop if there are no values left
         }
         $values[$valueIndex] = str_replace("-3B", ";", $values[$valueIndex]);
         if ($queryMode) {
             // special handling for supporting query parsing
             $comparator = SMW_CMP_EQ;
             self::prepareValue($values[$valueIndex], $comparator);
         }
         // generating the DVs:
         if ($values[$valueIndex] === '' || $values[$valueIndex] == '?') {
             // explicit omission
             $valueIndex++;
         } else {
             $dataValue = \SMW\DataValueFactory::getInstance()->newPropertyObjectValue($diProperty, $values[$valueIndex]);
             if ($dataValue->isValid()) {
                 // valid DV: keep
                 if ($queryMode) {
                     $subdescriptions[] = new SMWSomeProperty($diProperty, new SMWValueDescription($dataValue->getDataItem(), $dataValue->getProperty(), $comparator));
                 } else {
                     $semanticData->addPropertyObjectValue($diProperty, $dataValue->getDataItem());
                 }
                 $valueIndex++;
                 $empty = false;
             } elseif (count($values) - $valueIndex == count($this->m_diProperties) - $propertyIndex) {
                 // too many errors: keep this one to have enough slots left
                 if (!$queryMode) {
                     $semanticData->addPropertyObjectValue($diProperty, $dataValue->getDataItem());
                 }
                 $this->addError($dataValue->getErrors());
                 ++$valueIndex;
             }
         }
         ++$propertyIndex;
     }
     if ($empty) {
         $this->addError(wfMessage('smw_novalues')->text());
     }
     if ($queryMode) {
         switch (count($subdescriptions)) {
             case 0:
                 return new SMWThingDescription();
             case 1:
                 return reset($subdescriptions);
             default:
                 return new SMWConjunction($subdescriptions);
         }
     } else {
         $this->m_dataitem = new SMWDIContainer($semanticData);
     }
 }
Ejemplo n.º 4
0
 private function newContainerSemanticData($value)
 {
     if ($this->m_contextPage === null) {
         $containerSemanticData = ContainerSemanticData::makeAnonymousContainer();
         $containerSemanticData->skipAnonymousCheck();
     } else {
         $subobjectName = '_REF' . md5($value);
         $subject = new DIWikiPage($this->m_contextPage->getDBkey(), $this->m_contextPage->getNamespace(), $this->m_contextPage->getInterwiki(), $subobjectName);
         $containerSemanticData = new ContainerSemanticData($subject);
     }
     return $containerSemanticData;
 }
Ejemplo n.º 5
0
 /**
  * Method to create a dataitem from a type ID and array of DB keys.
  * Throws SMWDataItemException if problems occur, to get our callers
  * used to it.
  *
  * @param $typeid string id for the given type
  * @param $dbkeys array of mixed
  *
  * @return SMWDataItem
  */
 public static function dataItemFromDBKeys($typeid, $dbkeys)
 {
     switch (SMWDataValueFactory::getDataItemId($typeid)) {
         case SMWDataItem::TYPE_ERROR:
         case SMWDataItem::TYPE_NOTYPE:
             break;
         case SMWDataItem::TYPE_NUMBER:
             return SMWDINumber::doUnserialize($dbkeys[0]);
         case SMWDataItem::TYPE_STRING:
             return new SMWDIString($dbkeys[0]);
         case SMWDataItem::TYPE_BLOB:
             return new SMWDIBlob($dbkeys[0]);
         case SMWDataItem::TYPE_BOOLEAN:
             return new SMWDIBoolean($dbkeys[0] == '1');
         case SMWDataItem::TYPE_URI:
             if ($typeid == '__typ' && $dbkeys[0][0] == '_') {
                 // b/c: old data stored as type ids
                 return SMWTypesValue::getTypeUriFromTypeId($dbkeys[0]);
             } else {
                 return SMWDIUri::doUnserialize($dbkeys[0]);
             }
         case SMWDataItem::TYPE_TIME:
             $timedate = explode('T', $dbkeys[0], 2);
             if (count($dbkeys) == 2 && count($timedate) == 2) {
                 $date = reset($timedate);
                 $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false;
                 if (end($timedate) === '' || SMWTimeValue::parseTimeString(end($timedate), $hours, $minutes, $seconds, $timeoffset) == true) {
                     $d = explode('/', $date, 3);
                     if (count($d) == 3) {
                         list($year, $month, $day) = $d;
                     } elseif (count($d) == 2) {
                         list($year, $month) = $d;
                     } elseif (count($d) == 1) {
                         list($year) = $d;
                     }
                     if ($month === '') {
                         $month = false;
                     }
                     if ($day === '') {
                         $day = false;
                     }
                     $calendarmodel = SMWDITime::CM_GREGORIAN;
                     return new SMWDITime($calendarmodel, $year, $month, $day, $hours, $minutes, $seconds);
                 }
             }
             break;
         case SMWDataItem::TYPE_GEO:
             return new SMWDIGeoCoord(array('lat' => (double) $dbkeys[0], 'lon' => (double) $dbkeys[1]));
         case SMWDataItem::TYPE_CONTAINER:
             // provided for backwards compatibility only;
             // today containers are read from the store as substructures,
             // not retrieved as single complex values
             $semanticData = SMWContainerSemanticData::makeAnonymousContainer();
             foreach (reset($dbkeys) as $value) {
                 if (is_array($value) && count($value) == 2) {
                     $diP = new SMWDIProperty(reset($value), false);
                     $diV = self::dataItemFromDBKeys($diP->findPropertyTypeID(), end($value));
                     $semanticData->addPropertyObjectValue($diP, $diV);
                 }
             }
             return new SMWDIContainer($semanticData);
         case SMWDataItem::TYPE_WIKIPAGE:
             if ($typeid == '__spf') {
                 $pagedbkey = str_replace(' ', '_', $dbkeys[0]);
                 return new SMWDIWikiPage($pagedbkey, SF_NS_FORM, '');
             } elseif (count($dbkeys) >= 5) {
                 // with subobject name (and sortkey)
                 return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2], $dbkeys[4]);
             } elseif (count($dbkeys) >= 3) {
                 // without subobject name (just for b/c)
                 return new SMWDIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2]);
             }
             break;
         case SMWDataItem::TYPE_CONCEPT:
             if (count($dbkeys) >= 5) {
                 return new SMWDIConcept($dbkeys[0], smwfXMLContentEncode($dbkeys[1]), $dbkeys[2], $dbkeys[3], $dbkeys[4]);
             }
             break;
         case SMWDataItem::TYPE_PROPERTY:
             return new SMWDIProperty($dbkeys[0], false);
     }
     throw new SMWDataItemException('Failed to create data item from DB keys.');
 }
 public function testTryToGetLocalPropertyDescriptionForUserdefinedProperty()
 {
     $property = $this->dataItemFactory->newDIProperty('Foo');
     $pdesc = $this->dataItemFactory->newDIProperty('_PDESC');
     $pdesc->setPropertyTypeId('_mlt_rec');
     $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock();
     $this->blobStore->expects($this->once())->method('read')->will($this->returnValue($container));
     $this->cachedPropertyValuesPrefetcher->expects($this->once())->method('getPropertyValues')->with($this->equalTo($property->getDiWikiPage()), $this->anything(), $this->anything())->will($this->returnValue(array($this->dataItemFactory->newDIContainer(ContainerSemanticData::makeAnonymousContainer()))));
     $this->cachedPropertyValuesPrefetcher->expects($this->once())->method('getBlobStore')->will($this->returnValue($this->blobStore));
     $instance = new PropertySpecificationLookup($this->cachedPropertyValuesPrefetcher, $this->intermediaryMemoryCache);
     $this->assertInternalType('string', $instance->getPropertyDescriptionBy($property));
 }
Ejemplo n.º 7
0
 private function newContainerSemanticData($value)
 {
     if ($this->m_contextPage === null) {
         $containerSemanticData = ContainerSemanticData::makeAnonymousContainer();
         $containerSemanticData->skipAnonymousCheck();
     } else {
         $subobjectName = '_' . hash('md4', $value, false);
         // md4 is probably fastest of PHP's hashes
         $subject = new DIWikiPage($this->m_contextPage->getDBkey(), $this->m_contextPage->getNamespace(), $this->m_contextPage->getInterwiki(), $subobjectName);
         $containerSemanticData = new ContainerSemanticData($subject);
     }
     return $containerSemanticData;
 }