/**
  * @since 2.4
  *
  * @param DIWikiPage $subject
  * @param DIProperty $property
  * @param RequestOptions|null $requestOptions
  *
  * @return array
  */
 public function getPropertyValues(DIWikiPage $subject, DIProperty $property, RequestOptions $requestOptions = null)
 {
     $key = $property->getKey() . ':' . $subject->getSubobjectName() . ':' . ($requestOptions !== null ? $requestOptions->getHash() : null);
     $container = $this->blobStore->read($this->getRootHashFrom($subject));
     if ($container->has($key)) {
         return $container->get($key);
     }
     $dataItems = $this->store->getPropertyValues($subject, $property, $requestOptions);
     $container->set($key, $dataItems);
     $this->blobStore->save($container);
     return $dataItems;
 }
 /**
  * Create an ExpElement for some internal resource, given by an
  * DIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param DIWikiPage $diWikiPage
  * @param boolean $markForAuxiliaryUsage
  *
  * @return ExpResource
  */
 public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $markForAuxiliaryUsage = false)
 {
     $modifier = $markForAuxiliaryUsage ? self::AUX_MARKER : '';
     $hash = $this->cachePrefix . $diWikiPage->getHash() . $modifier;
     // If a persistent cache is injected use the ExpElement serializer because
     // not all cache layers support object de/serialization
     // ExpElement::newFromSerialization
     if ($this->cache->contains($hash)) {
         return $this->cache->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     $importDataItem = $this->tryToFindImportDataItem($diWikiPage, $modifier);
     if ($importDataItem instanceof DataItem) {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForImportDataItem($importDataItem);
     } else {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForDiWikiPage($diWikiPage, $modifier);
     }
     $resource = new ExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
     $this->cache->save($hash, $resource);
     return $resource;
 }
 /**
  * @see Store::getProperties
  *
  * @param DIWikiPage $subject
  * @param SMWRequestOptions|null $requestOptions
  *
  * @return SMWDataItem[]
  */
 public function getProperties(DIWikiPage $subject, SMWRequestOptions $requestOptions = null)
 {
     $sid = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName());
     if ($sid == 0) {
         // no id, no page, no properties
         return array();
     }
     $db = $this->store->getConnection();
     $result = array();
     // potentially need to get more results, since options apply to union
     if ($requestOptions !== null) {
         $suboptions = clone $requestOptions;
         $suboptions->limit = $requestOptions->limit + $requestOptions->offset;
         $suboptions->offset = 0;
     } else {
         $suboptions = null;
     }
     foreach ($this->store->getPropertyTables() as $propertyTable) {
         if ($propertyTable->usesIdSubject()) {
             $where = 's_id=' . $db->addQuotes($sid);
         } elseif ($subject->getInterwiki() === '') {
             $where = 's_title=' . $db->addQuotes($subject->getDBkey()) . ' AND s_namespace=' . $db->addQuotes($subject->getNamespace());
         } else {
             // subjects with non-emtpy interwiki cannot have properties
             continue;
         }
         if ($propertyTable->isFixedPropertyTable()) {
             // just check if subject occurs in table
             $res = $db->select($propertyTable->getName(), '*', $where, __METHOD__, array('LIMIT' => 1));
             if ($db->numRows($res) > 0) {
                 $result[] = new SMW\DIProperty($propertyTable->getFixedProperty());
             }
         } else {
             // select all properties
             $from = $db->tableName($propertyTable->getName());
             $from .= " INNER JOIN " . $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " ON smw_id=p_id";
             $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey', $where . $this->store->getSQLConditions($suboptions, 'smw_sortkey', 'smw_sortkey'), __METHOD__, $this->store->getSQLOptions($suboptions, 'smw_sortkey'));
             foreach ($res as $row) {
                 $result[] = new SMW\DIProperty($row->smw_title);
             }
         }
         $db->freeResult($res);
     }
     // apply options to overall result
     $result = $this->store->applyRequestOptions($result, $requestOptions);
     return $result;
 }
 /**
  * @since  2.1
  *
  * @param integer $sid
  * @param DIWikiPage $subject
  * @param integer|string|null $interWiki
  */
 public function updateInterwikiField($sid, DIWikiPage $subject, $interWiki = null)
 {
     $this->store->getConnection()->update(self::tableName, array('smw_iw' => $interWiki !== null ? $interWiki : $subject->getInterWiki()), array('smw_id' => $sid), __METHOD__);
     $this->setCache($subject->getDBKey(), $subject->getNamespace(), $subject->getInterWiki(), $subject->getSubobjectName(), $sid, $subject->getSortKey());
 }
 /**
  * Store a value for a property identified by its SMWDataItem object.
  *
  * @note There is no check whether the type of the given data item
  * agrees with the type of the property. Since property types can
  * change, all parts of SMW are prepared to handle mismatched data item
  * types anyway.
  *
  * @param $property DIProperty
  * @param $dataItem SMWDataItem
  */
 public function addPropertyObjectValue(DIProperty $property, SMWDataItem $dataItem)
 {
     $this->hash = null;
     if ($dataItem instanceof SMWDIContainer) {
         $this->addSubSemanticData($dataItem->getSemanticData());
         $dataItem = $dataItem->getSemanticData()->getSubject();
     }
     if ($property->isInverse()) {
         // inverse properties cannot be used for annotation
         return;
     }
     if (!array_key_exists($property->getKey(), $this->mPropVals)) {
         $this->mPropVals[$property->getKey()] = array();
         $this->mProperties[$property->getKey()] = $property;
     }
     if ($this->mNoDuplicates) {
         $this->mPropVals[$property->getKey()][$dataItem->getHash()] = $dataItem;
     } else {
         $this->mPropVals[$property->getKey()][] = $dataItem;
     }
     if (!$property->isUserDefined()) {
         if ($property->isShown()) {
             $this->mHasVisibleSpecs = true;
             $this->mHasVisibleProps = true;
         }
     } else {
         $this->mHasVisibleProps = true;
     }
     // Inherit the sortkey from the root if not explicitly given
     if ($this->mSubject->getSubobjectName() === '' && $property->getKey() === DIProperty::TYPE_SORTKEY) {
         foreach ($this->subSemanticData as $subSemanticData) {
             if (!$subSemanticData->hasProperty($property)) {
                 $subSemanticData->addPropertyObjectValue($property, $dataItem);
             }
         }
     }
 }
 /**
  * Create an ExpElement for some internal resource, given by an
  * DIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param DIWikiPage $diWikiPage
  * @param boolean $useAuxiliaryModifier
  *
  * @return ExpResource
  */
 public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $useAuxiliaryModifier = false)
 {
     $modifier = $useAuxiliaryModifier ? self::AUX_MARKER : '';
     $hash = $diWikiPage->getHash() . $modifier;
     $poolCache = $this->inMemoryPoolCache->getPoolCacheFor('exporter.dataitem.resource.encoder');
     if ($poolCache->contains($hash)) {
         return $poolCache->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     $importDataItem = $this->tryToFindImportDataItem($diWikiPage, $modifier);
     if ($importDataItem instanceof DataItem) {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForImportDataItem($importDataItem);
     } else {
         list($localName, $namespace, $namespaceId) = $this->defineElementsForDiWikiPage($diWikiPage, $modifier);
     }
     $resource = new ExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
     $poolCache->save($hash, $resource);
     return $resource;
 }
 /**
  * @since 2.1
  *
  * @param DIWikiPage $dataItem
  *
  * @return string
  */
 public static function getHashIdForDiWikiPage(DIWikiPage $dataItem)
 {
     return self::createFromSegments($dataItem->getDBKey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSubobjectName());
 }
 /**
  * Create an ExpElement for some internal resource, given by an
  * DIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param DIWikiPage $diWikiPage
  * @param boolean $useAuxiliaryModifier
  *
  * @return ExpResource
  */
 public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $useAuxiliaryModifier = false)
 {
     $modifier = $useAuxiliaryModifier ? self::AUX_MARKER : '';
     $hash = $diWikiPage->getHash() . $modifier;
     $poolCache = $this->inMemoryPoolCache->getPoolCacheFor('exporter.dataitem.resource.encoder');
     if ($poolCache->contains($hash)) {
         return $poolCache->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     $resource = $this->newExpNsResource($diWikiPage, $modifier);
     $poolCache->save($hash, $resource);
     return $resource;
 }